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

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

Introduction

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

Prototype

public Build getBuild() 

Source Link

Usage

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static File getOutputDir(@NotNull MavenProject project) {
    final String path = project.getBuild().getOutputDirectory(); // getBuild never returns null
    return getDirInProject(project, path);
}

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static File getTestOutputDir(@NotNull MavenProject project) {
    final String path = project.getBuild().getTestOutputDirectory(); // getBuild never returns null
    return getDirInProject(project, path);
}

From source file:org.sourcepit.maven.bootstrap.internal.core.ReactorReader.java

License:Apache License

private File find(MavenProject project, Artifact artifact) {
    if ("pom".equals(artifact.getExtension())) {
        return project.getFile();
    }//from w w w.j  a  va2  s .co m

    org.apache.maven.artifact.Artifact projectArtifact = findMatchingArtifact(project, artifact);

    if (hasArtifactFileFromPackagePhase(projectArtifact)) {
        return projectArtifact.getFile();
    } else if (!hasBeenPackaged(project)) {
        // fallback to loose class files only if artifacts haven't been packaged yet

        if (isTestArtifact(artifact)) {
            if (project.hasLifecyclePhase("test-compile")) {
                return new File(project.getBuild().getTestOutputDirectory());
            }
        } else {
            if (project.hasLifecyclePhase("compile")) {
                return new File(project.getBuild().getOutputDirectory());
            }
        }
    }

    // The fall-through indicates that the artifact cannot be found;
    // for instance if package produced nothing or classifier problems.
    return null;
}

From source file:org.sourcepit.osgifier.maven.GenerateManifestMojo.java

License:Apache License

private Artifact newProjectArtifact(final MavenProject project, String classifier, String type) {
    org.eclipse.aether.artifact.Artifact artifact = artifactFactory
            .createArtifact(RepositoryUtils.toArtifact(project.getArtifact()), classifier, type);

    final String buildDir = project.getBuild().getDirectory();

    final String finalName = project.getBuild().getFinalName();

    final String sourceFinalName = finalName + "-" + artifact.getClassifier();

    final File file = new File(buildDir + "/" + sourceFinalName + "." + artifact.getExtension());

    artifact = artifact.setFile(file);//from   ww w  .j a  v a 2  s .  c o m

    return MavenArtifactUtils.toArtifact(artifact);
}

From source file:org.sourcepit.tpmp.AbstractTargetPlatformMojo.java

License:Apache License

protected String getFinalName(MavenProject project) {
    String finalName = project.getBuild().getFinalName();
    if (finalName == null) {
        finalName = project.getArtifactId() + "-" + project.getVersion();
    }//from   w w w  .  j  a v a2s .co m
    return finalName;
}

From source file:org.springframework.ide.vscode.commons.maven.java.MavenProjectClasspath.java

License:Open Source License

private ImmutableList<CPE> resolveClasspathEntries(MavenProject project) throws Exception {
    LinkedHashSet<CPE> entries = new LinkedHashSet<>();
    safe(() -> maven.getJreLibs().forEach(path -> safe(() -> {
        CPE cpe = CPE.binary(path.toString());
        String javaVersion = maven.getJavaRuntimeMinorVersion();
        if (javaVersion == null) {
            javaVersion = "8";
        }/*from  w w w  .  j  av a  2  s  .  co  m*/
        cpe.setJavadocContainerUrl(new URL("https://docs.oracle.com/javase/" + javaVersion + "/docs/api/"));
        cpe.setSystem(true);
        entries.add(cpe);
        // Add at the end, not critical if throws exception, but the CPE needs to be around regardless if the below throws
        Path sources = JavaUtils.jreSources(path);
        if (sources != null) {
            cpe.setSourceContainerUrl(sources.toUri().toURL());
        }
    })));
    //Add jar dependencies...
    for (Artifact a : projectDependencies(project)) {
        File f = a.getFile();
        if (f != null) {
            CPE cpe = CPE.binary(a.getFile().toPath().toString());
            safe(() -> { //add javadoc
                Artifact jdoc = maven.getJavadoc(a, project.getRemoteArtifactRepositories());
                if (jdoc != null) {
                    cpe.setJavadocContainerUrl(jdoc.getFile().toURI().toURL());
                }
            });
            safe(() -> { //add source
                Artifact source = maven.getSources(a, project.getRemoteArtifactRepositories());
                if (source != null) {
                    cpe.setSourceContainerUrl(source.getFile().toURI().toURL());
                }
            });
            entries.add(cpe);
        }
    }
    //Add source folders...
    { //main/java
        File sourceFolder = new File(project.getBuild().getSourceDirectory());
        File outputFolder = new File(project.getBuild().getOutputDirectory());
        CPE cpe = CPE.source(sourceFolder, outputFolder);
        cpe.setOwn(true);
        safe(() -> {
            String reportingDir = project.getModel().getReporting().getOutputDirectory();
            if (reportingDir != null) {
                File apidocs = new File(new File(reportingDir), "apidocs");
                cpe.setJavadocContainerUrl(apidocs.toURI().toURL());
            }
        });
        entries.add(cpe);
    }
    { //main/resources
        for (Resource resource : project.getBuild().getResources()) {
            File sourceFolder = new File(resource.getDirectory());
            String targetPath = resource.getTargetPath();
            if (targetPath == null) {
                targetPath = project.getBuild().getOutputDirectory();
            }
            CPE cpe = CPE.source(sourceFolder, new File(targetPath));
            cpe.setOwn(true);
            entries.add(cpe);
        }
    }
    { //test/resources
        for (Resource resource : project.getBuild().getTestResources()) {
            File sourceFolder = new File(resource.getDirectory());
            String targetPath = resource.getTargetPath();
            if (targetPath == null) {
                targetPath = project.getBuild().getTestOutputDirectory();
            }
            CPE cpe = CPE.source(sourceFolder, targetPath == null ? null : new File(targetPath));
            cpe.setOwn(true);
            entries.add(cpe);
        }
    }
    { //test/java
        File sourceFolder = new File(project.getBuild().getTestSourceDirectory());
        File outputFolder = new File(project.getBuild().getTestOutputDirectory());
        CPE cpe = CPE.source(sourceFolder, outputFolder);
        cpe.setOwn(true);
        safe(() -> {
            String reportingDir = project.getModel().getReporting().getOutputDirectory();
            if (reportingDir != null) {
                File apidocs = new File(new File(reportingDir), "apidocs");
                cpe.setJavadocContainerUrl(apidocs.toURI().toURL());
            }
        });
        entries.add(cpe);
    }
    return ImmutableList.copyOf(entries);
}

From source file:org.springframework.ide.vscode.commons.maven.java.MavenProjectClasspath.java

License:Open Source License

private List<File> projectOutput(MavenProject project) {
    if (project == null) {
        return Collections.emptyList();
    } else {//w  w w  . j a v  a 2  s  .  c  o  m
        return Arrays.asList(new File(project.getBuild().getOutputDirectory()),
                new File(project.getBuild().getTestOutputDirectory()));
    }
}

From source file:org.switchyard.tools.ui.M2EUtils.java

License:Open Source License

/**
 * Returns the generated switchyard.xml file. By default, this is
 * target/class/META-INF/switchyard.xml.
 * /*from  ww  w  .j a v  a 2  s  .c o  m*/
 * @param project the project
 * @return the location of the generated switchyard.xml file.
 */
public static File getSwitchYardOutputFile(MavenProject project) {
    if (project == null) {
        return null;
    }
    Plugin plugin = findSwitchYardPlugin(project.getModel());
    if (plugin == null) {
        return null;
    }
    Xpp3Dom configuration = findSwitchYardPluginConfiguration(plugin);
    if (configuration != null) {
        Xpp3Dom node = configuration.getChild("outputFile"); //$NON-NLS-1$
        if (node != null && node.getValue() != null) {
            return new File(project.getBasedir(), node.getValue());
        }
        node = configuration.getChild("outputDirectory"); //$NON-NLS-1$
        if (node != null && node.getValue() != null) {
            return new File(new File(project.getBasedir(), node.getValue()), "META-INF/switchyard.xml"); //$NON-NLS-1$
        }
    }
    return new File(project.getBuild().getOutputDirectory(), "META-INF/switchyard.xml"); //$NON-NLS-1$
}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project/* ww w  .  j  av  a  2  s  .co m*/
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.project.nature.AnalyticsProjectNature.java

License:Open Source License

private void updatePom() {
    // TODO update the pom with the relavant packaging types & maven pligins
    File mavenProjectPomLocation = getProject().getFile("pom.xml").getLocation().toFile();
    try {/*w w w  .  ja v a 2s . c o m*/
        MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
        //Adding typrLidt property
        MavenUtils.updateMavenProjectWithCAppType(mavenProject, CAPP_TYPE);
        //Setting the directory
        mavenProject.getBuild().setDirectory("target/capp");
        //         Adding maven test skip property
        MavenUtils.updateMavenProjectWithSkipTests(mavenProject);

        //Adding maven exec plugin entry
        Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.codehaus.mojo", "exec-maven-plugin",
                "1.2", true);
        {
            PluginExecution pluginExecution = new PluginExecution();
            pluginExecution.setId(AnalyticsMavenConstants.PACKAGE_PHASE);
            pluginExecution.addGoal(AnalyticsMavenConstants.EXEC_GOAL);
            pluginExecution.setPhase(AnalyticsMavenConstants.PACKAGE_PHASE);

            Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
            Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.EXECUTABLE_TAG);
            executableNode.setValue(AnalyticsMavenConstants.EXECUTABLE_VALUE);
            Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.WORKING_DIRECTORY_TAG);
            workingDirectoryNode.setValue(AnalyticsMavenConstants.WORKING_DIRECTORY_VALUE);
            Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.ARGUMENTS_TAG);
            Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            cleanArgumentNode.setValue(AnalyticsMavenConstants.ARGUMENT_VALUE_CLEAN);
            Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            installArgumentNode.setValue(AnalyticsMavenConstants.PACKAGE_PHASE);
            Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            testSkipArgumentNode.setValue(AnalyticsMavenConstants.ARGUMENT_VALUE_SKIP_TESTS);

            pluginExecution.setConfiguration(configurationNode);

            plugin.addExecution(pluginExecution);
        }
        {
            PluginExecution pluginExecution = new PluginExecution();
            pluginExecution.setId(AnalyticsMavenConstants.INSTALL_PHASE);
            pluginExecution.addGoal(AnalyticsMavenConstants.EXEC_GOAL);
            pluginExecution.setPhase(AnalyticsMavenConstants.INSTALL_PHASE);

            Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
            Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.EXECUTABLE_TAG);
            executableNode.setValue(AnalyticsMavenConstants.EXECUTABLE_VALUE);
            Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.WORKING_DIRECTORY_TAG);
            workingDirectoryNode.setValue(AnalyticsMavenConstants.WORKING_DIRECTORY_VALUE);
            Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.ARGUMENTS_TAG);
            Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            cleanArgumentNode.setValue(AnalyticsMavenConstants.ARGUMENT_VALUE_CLEAN);
            Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            installArgumentNode.setValue(AnalyticsMavenConstants.INSTALL_PHASE);
            Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            testSkipArgumentNode.setValue(AnalyticsMavenConstants.ARGUMENT_VALUE_SKIP_TESTS);

            pluginExecution.setConfiguration(configurationNode);

            plugin.addExecution(pluginExecution);
        }
        {
            PluginExecution pluginExecution = new PluginExecution();
            pluginExecution.setId(AnalyticsMavenConstants.DEPLOY_PHASE);
            pluginExecution.addGoal(AnalyticsMavenConstants.EXEC_GOAL);
            pluginExecution.setPhase(AnalyticsMavenConstants.DEPLOY_PHASE);

            Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
            Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.EXECUTABLE_TAG);
            executableNode.setValue(AnalyticsMavenConstants.EXECUTABLE_VALUE);
            Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.WORKING_DIRECTORY_TAG);
            workingDirectoryNode.setValue(AnalyticsMavenConstants.WORKING_DIRECTORY_VALUE);
            Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode,
                    AnalyticsMavenConstants.ARGUMENTS_TAG);
            Xpp3Dom deployArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            deployArgumentNode.setValue(AnalyticsMavenConstants.DEPLOY_PHASE);
            Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode,
                    AnalyticsMavenConstants.ARGUMENT_TAG);
            testSkipArgumentNode.setValue(AnalyticsMavenConstants.ARGUMENT_VALUE_SKIP_TESTS);

            pluginExecution.setConfiguration(configurationNode);

            plugin.addExecution(pluginExecution);
        }
        MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);

    } catch (Exception e) {
        log.error("Exception: " + e.getMessage(), e);
    }

    try {
        getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (CoreException e) {
        log.error("Core Exception: " + e.getMessage(), e);
    }
}