Example usage for org.apache.maven.project MavenProject getBasedir

List of usage examples for org.apache.maven.project MavenProject getBasedir

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getBasedir.

Prototype

public File getBasedir() 

Source Link

Usage

From source file:org.eclipse.tycho.source.SourcesP2MetadataProvider.java

License:Open Source License

public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession session, MavenProject project,
        List<Map<String, String>> environments, OptionalResolutionAction optionalAction) {
    if (OsgiSourceMojo.isRelevantProjectImpl(project, buildPropertiesParser)) {
        IArtifactFacade sourcesArtifact = new AttachedArtifact(project, project.getBasedir(), "sources");
        return Collections.singletonMap(sourcesArtifact.getClassidier(),
                sourcesGenerator.generateMetadata(sourcesArtifact, null, OptionalResolutionAction.REQUIRE));
    }/* w w w .ja  va  2  s . c  om*/
    return null;
}

From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java

License:Open Source License

protected MavenSession newMavenSession(MavenProject project, List<MavenProject> projects) throws Exception {
    MavenExecutionRequest request = newMavenExecutionRequest(new File(project.getBasedir(), "pom.xml"));
    MavenExecutionResult result = new DefaultMavenExecutionResult();
    DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
    MavenSession session = new MavenSession(getContainer(), repositorySession, request, result);
    session.setCurrentProject(project);//from  ww  w.  ja v  a  2s  .  c  o m
    session.setProjects(projects);
    return session;
}

From source file:org.ensime.maven.plugins.ensime.EnsimeConfigGenerator.java

License:Apache License

private List<String> getSources(final MavenProject module, final String target) {
    Map<String, Plugin> plugins = project.getPluginManagement().getPluginsAsMap();

    Plugin scalacPlugin = plugins.get(SCALA_MAVEN_PLUGIN);

    List<String> sources = Optional.ofNullable(scalacPlugin).map(p -> p.getConfiguration()).flatMap(obj -> {
        if (obj instanceof Xpp3Dom) {
            Xpp3Dom config = (Xpp3Dom) obj;
            return Optional.ofNullable(config.getChild("sources"))
                    .map(c -> Arrays.stream(c.getChildren()).map(v -> v.getValue()).collect(toList()));
        } else/*  w ww .j  a va  2 s  .  c  o m*/
            return Optional.empty();
    }).orElse(new ArrayList());

    if (sources.isEmpty()) {
        sources = Stream
                .of(new File(module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "scala"),
                        new File(
                                module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "java"))
                .map(f -> f.getAbsolutePath()).collect(toList());
    }

    sources.addAll(module.getCompileSourceRoots());

    return sources;
}

From source file:org.exoplatform.maven2.plugin.Utils.java

License:Open Source License

public static void deployProject(File dirJar, File dirWar, MavenProject project, boolean deployDep,
        HashSet<String> ignoreProjects) throws Exception {
    if (!dirJar.exists()) {
        System.out.println("The directory " + dirJar.getParent() + " does not exists !");
        return;//from w  w w .ja va 2 s.  co  m
    }
    if (!dirWar.exists()) {
        System.out.println("The directory " + dirWar.getParent() + " does not exists !");
        return;
    }
    int counter = 0;
    if (deployDep) {
        counter += deployedDependency(dirJar, dirWar, project, ignoreProjects).size();
    }
    deleteFileOnExist(dirWar, project.getBuild().getFinalName());
    if (project.getPackaging().equals("jar")) {
        counter++;
        File moduleFile = new File(project.getBasedir().toString() + "/target/" + project.getArtifactId() + "-"
                + project.getVersion() + "." + project.getPackaging());
        copyFileToDirectory(moduleFile, dirJar);
        printMessage("deploy", "  Deployed file '" + project.getArtifactId() + "' to " + dirJar.getPath());
    } else {
        if (project.getPackaging().equals("war") || project.getPackaging().equals("exo-jcr")
                || project.getPackaging().equals("exo-portal")
                || project.getPackaging().equals("exo-portlet")) {
            File deployWar = new File(
                    project.getBasedir().toString() + "/target/" + project.getBuild().getFinalName() + ".war");
            copyFileToDirectory(deployWar, dirWar);
            printMessage("deploy", "  Deployed file '" + project.getArtifactId() + "' to " + dirWar.getPath());
            counter++;
        }
    }
    printMessage("deploy", "  TOTAL DEPLOY : " + counter + " project");
}

From source file:org.fornax.toolsupport.maven2.JavaTaskBuilder.java

License:Apache License

public JavaTaskBuilder(MavenProject project, ClassRealm realm) {
    this.mvnProject = project;
    this.realm = realm;
    this.javaTask = new Java();

    this.antProject = new ProjectExt(realm);
    antProject.setBaseDir(project.getBasedir());
    antProject.setCoreLoader(realm.getClassLoader());
    javaTask.setProject(antProject);//from ww w .  j a va2  s .c  o m
    javaTask.setLocation(new Location(project.getBasedir().getAbsolutePath()));
    javaTask.setDir(project.getBasedir());
    Target target = new Target();
    antProject.addTarget("run-workflow", target);
    target.addTask(javaTask);
    configureClasspath();
}

From source file:org.fornax.toolsupport.sculptor.maven.plugin.AbstractSculptorMojoTestCase.java

License:Apache License

/**
 * Returns Mojo instance for the given goal. The Mojo instance is
 * initialized with a {@link MavenProject} created from the test projects in
 * <code>"src/test/projects/"</code> by given project name.
 *///  ww  w.java2 s  . c  o  m
protected T createMojo(MavenProject project, String goal) throws Exception {

    // Create mojo
    @SuppressWarnings("unchecked")
    T mojo = (T) lookupMojo(goal, project.getFile());
    assertNotNull(mojo);

    // Set Maven project
    setVariableValueToObject(mojo, "project", project);

    // Set default values on mojo
    setVariableValueToObject(mojo, "outletSrcOnceDir", new File(project.getBasedir(), "src/main/java"));
    setVariableValueToObject(mojo, "outletResOnceDir", new File(project.getBasedir(), "src/main/resources"));
    setVariableValueToObject(mojo, "outletSrcDir", new File(project.getBasedir(), "src/generated/java"));
    setVariableValueToObject(mojo, "outletResDir", new File(project.getBasedir(), "src/generated/resources"));
    setVariableValueToObject(mojo, "outletSrcTestOnceDir", new File(project.getBasedir(), "src/test/java"));
    setVariableValueToObject(mojo, "outletResTestOnceDir",
            new File(project.getBasedir(), "src/test/resources"));
    setVariableValueToObject(mojo, "outletSrcTestDir",
            new File(project.getBasedir(), "src/test/generated/java"));
    setVariableValueToObject(mojo, "outletResTestDir",
            new File(project.getBasedir(), "src/test/generated/resources"));
    setVariableValueToObject(mojo, "statusFile", new File(project.getBasedir(), ".sculptor-status"));
    return mojo;
}

From source file:org.gephi.maven.ManifestUtils.java

License:Apache License

protected void readManifestMetadata(MavenProject proj, PluginMetadata metadata) throws MojoExecutionException {
    Manifest manifest = getManifest(proj);

    // Read branding attributes
    Manifest.Section mainSection = manifest.getMainSection();
    String brandingName = mainSection.getAttributeValue("OpenIDE-Module-Name");
    String brandingShortDescription = mainSection.getAttributeValue("OpenIDE-Module-Short-Description");
    String brandingLongDescrption = mainSection.getAttributeValue("OpenIDE-Module-Long-Description");
    String brandingDisplayCategory = mainSection.getAttributeValue("OpenIDE-Module-Display-Category");

    //Read localized
    if (mainSection.getAttribute("OpenIDE-Module-Localizing-Bundle") != null) {
        File folder = proj.getBasedir();
        String path = mainSection.getAttributeValue("OpenIDE-Module-Localizing-Bundle");
        File bundlerFile = new File(folder, "src" + File.separator + "main" + File.separator + "resources");
        if (!bundlerFile.exists()) {
            throw new MojoExecutionException(
                    "The 'src/main/resources' folder can't be found in '" + folder.getAbsolutePath() + "'");
        }/*from  w w  w .j  a v a2 s  . co  m*/
        bundlerFile = new File(bundlerFile, path.replace('/', File.separatorChar));
        if (!bundlerFile.exists()) {
            throw new MojoExecutionException("The '" + path + "' file can't be found");
        }
        Properties prop = new Properties();
        FileReader bundleReader = null;
        try {
            bundleReader = new FileReader(bundlerFile);
            prop.load(bundleReader);
            brandingName = prop.getProperty("OpenIDE-Module-Name", brandingName);
            brandingDisplayCategory = prop.getProperty("OpenIDE-Module-Display-Category",
                    brandingDisplayCategory);
            brandingShortDescription = prop.getProperty("OpenIDE-Module-Short-Description",
                    brandingShortDescription);
            brandingLongDescrption = prop.getProperty("OpenIDE-Module-Long-Description",
                    brandingLongDescrption);
        } catch (IOException e) {
            throw new MojoExecutionException("Error while reading '" + bundlerFile.getAbsolutePath() + "'", e);
        } finally {
            if (bundleReader != null) {
                try {
                    bundleReader.close();
                } catch (IOException ex) {
                }
            }
        }
    }

    if (brandingName == null || brandingName.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Name' entry");
    }
    if (brandingShortDescription == null || brandingShortDescription.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Short-Description' entry");
    }
    if (brandingLongDescrption == null || brandingLongDescrption.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Long-Description' entry");
    }
    if (brandingDisplayCategory == null || brandingDisplayCategory.isEmpty()) {
        throw new MojoExecutionException("The manifest.mf file for project '" + proj.getName()
                + "' should contain a 'OpenIDE-Module-Display-Category' entry");
    }

    if (!validateCategory(brandingDisplayCategory)) {
        throw new MojoExecutionException("The manifest entry 'OpenIDE-Module-Display-Category' is '"
                + brandingDisplayCategory + "' but should be one of the following values: "
                + Arrays.toString(CATEGORIES).replace("[", "").replace("]", ""));
    }

    metadata.name = brandingName;
    metadata.short_description = brandingShortDescription;
    metadata.long_description = brandingLongDescrption;
    metadata.category = brandingDisplayCategory;
}

From source file:org.gephi.maven.ManifestUtils.java

License:Apache License

/**
 * Find and return the Manifest for the given project.
 *
 * @param proj project//from  w  w  w.ja v a2  s  . co  m
 * @return manifest
 * @throws MojoExecutionException if an error occurs
 */
protected Manifest getManifest(MavenProject proj) throws MojoExecutionException {
    // Read project manifest file
    File manifestFile = new File(proj.getBasedir(), sourceManifestFile);
    if (!manifestFile.exists()) {
        throw new MojoExecutionException("Cannot locate a manifest.mf file at " + manifestFile.getAbsolutePath()
                + " for project " + proj.getName());
    }

    // Check validity
    ExamineManifest examinator = new ExamineManifest(log);
    examinator.setManifestFile(manifestFile);
    examinator.checkFile();

    // Read manifest
    Manifest manifest = null;
    Reader reader = null;
    try {
        reader = new InputStreamReader(new FileInputStream(manifestFile));
        manifest = new Manifest(reader);
    } catch (IOException exc) {
        throw new MojoExecutionException("Error reading manifest at " + manifestFile, exc);
    } catch (ManifestException ex) {
        throw new MojoExecutionException("Error reading manifest at " + manifestFile, ex);
    } finally {
        IOUtil.close(reader);
    }
    return manifest;
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Lookup and return the content of the README.md file for this plugin.
 *
 * @param project project/*from w w  w  .j a  v a 2  s.  co  m*/
 * @param log log
 * @return content of REDME.md file or null if not found
 */
protected static String getReadme(MavenProject project, Log log) {
    File readmePath = new File(project.getBasedir(), "README.md");
    if (readmePath.exists()) {
        log.debug("README.md file has been found: '" + readmePath.getAbsolutePath() + "'");
        try {
            StringBuilder builder = new StringBuilder();
            LineNumberReader fileReader = new LineNumberReader(new FileReader(readmePath));
            String line;
            while ((line = fileReader.readLine()) != null) {
                builder.append(line);
                builder.append("\n");
            }
            log.info("File README.md with " + builder.length() + " characters has been attached to project '"
                    + project.getName() + "'");
            return builder.toString();
        } catch (IOException ex) {
            log.error("Error while reading README.md file", ex);
        }
    }
    return null;
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Use local Git repository configuration to lookup the sourcecode URL.
 *
 * @param project project//from   w ww.j  ava 2 s.com
 * @param log log
 * @return source code url or null
 */
protected static String getSourceCodeUrlFromGit(MavenProject project, Log log) {
    File gitPath = new File(project.getBasedir(), ".git");
    if (gitPath.exists() && gitPath.isDirectory()) {
        File gitPathConfig = new File(gitPath, "config");
        if (gitPathConfig.exists() && gitPathConfig.isFile()) {
            log.debug("Git config gile located at '" + gitPathConfig.getAbsolutePath() + "'");
            try {
                BufferedReader fileReader = new BufferedReader(new FileReader(gitPathConfig));

                Pattern pattern = Pattern.compile("\\s*url = (.*)");
                String line, url = null;
                while ((line = fileReader.readLine()) != null) {
                    Matcher m = pattern.matcher(line);
                    if (m.matches()) {
                        url = m.group(1);
                        break;
                    }
                }
                fileReader.close();

                if (url != null) {
                    log.debug("URL found in .git/config: '" + url + "'");
                    if (url.startsWith("http://")) {
                        return url;
                    } else if (url.startsWith("git@")) {
                        Pattern gitPattern = Pattern.compile("git@([^:]*):([^.]*).git");
                        Matcher gitMatcher = gitPattern.matcher(url);
                        if (gitMatcher.matches()) {
                            String res = "http://" + gitMatcher.group(1) + "/" + gitMatcher.group(2);
                            log.debug("Rewrote URL to '" + res + "'");
                            return res;
                        }
                    } else {
                        log.debug("Couldn't find a pattern in the git URL: " + url);
                    }
                }
            } catch (IOException e) {
                log.error("Error while reading Git config", e);
            }
        }
    } else {
        log.debug("The .git folder couldn't be found at '" + gitPath.getAbsolutePath() + "'");
    }
    return null;
}