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:ar.com.fluxit.jqa.JQAMavenPlugin.java

License:Open Source License

private String getSourceJavaVersion(MavenProject project) {
    try {/*from  w  w  w .jav  a  2s  .  co m*/
        return ((org.codehaus.plexus.util.xml.Xpp3Dom) ((org.apache.maven.model.Plugin) project.getBuild()
                .getPluginsAsMap().get("org.apache.maven.plugins:maven-compiler-plugin")).getConfiguration())
                        .getChild("source").getValue();
    } catch (Exception e) {
        return null;
    }
}

From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java

License:Apache License

private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project,
        Artifact artifact) throws IOException {
    List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();

    List<String> classifiers = new ArrayList<String>();
    if (config.includeCompileSources()) {
        classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }//from  ww w  .  ja  v a 2s  . co m

    if (config.includeTestSources()) {
        classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }

    for (String classifier : classifiers) {
        File optionsFile = new File(project.getBuild().getDirectory(),
                "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
        if (!optionsFile.exists()) {
            continue;
        }

        FileInputStream stream = null;
        try {
            stream = new FileInputStream(optionsFile);
            JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);

            bundles.add(new JavadocBundle(options,
                    new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
        } catch (XmlPullParserException e) {
            IOException error = new IOException(
                    "Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
            error.initCause(e);

            throw error;
        } finally {
            close(stream);
        }
    }

    return bundles;
}

From source file:ch.ivyteam.ivy.maven.util.SharedFile.java

License:Apache License

public SharedFile(MavenProject project) {
    targetDir = new File(project.getBuild().getDirectory());
}

From source file:cn.org.once.cstack.maven.plugin.mojo.CloudunitMojo.java

License:Open Source License

protected String getAbsolutePathWarFile() {
    MavenProject mavenProject = (MavenProject) getPluginContext().get("project");
    String directory = mavenProject.getBuild().getDirectory();
    String finalName = mavenProject.getBuild().getFinalName();
    String packaging = mavenProject.getPackaging();
    String fullPath = directory + "/" + finalName + "." + packaging;
    getLog().debug("absolutePathWarFile : " + fullPath);
    return fullPath;
}

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java

License:Apache License

public final EclipseSourceDir[] buildDirectoryList(MavenProject project, File basedir,
        File buildOutputDirectory) throws MojoExecutionException {
    File projectBaseDir = project.getFile().getParentFile();

    String mainOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir, buildOutputDirectory, false);

    // If using the standard output location, don't mix the test output into it.
    String testOutput = null;/*from   w ww.  j  a v a  2 s. co  m*/
    boolean useStandardOutputDir = buildOutputDirectory
            .equals(new File(project.getBuild().getOutputDirectory()));
    if (useStandardOutputDir) {
        getLog().debug("testOutput toRelativeAndFixSeparator " + projectBaseDir + " , "
                + project.getBuild().getTestOutputDirectory());
        testOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir,
                new File(project.getBuild().getTestOutputDirectory()), false);
        getLog().debug("testOutput after toRelative : " + testOutput);
    }

    Set mainDirectories = new LinkedHashSet();

    extractSourceDirs(mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null);

    extractResourceDirs(mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false,
            mainOutput);

    Set testDirectories = new LinkedHashSet();

    extractSourceDirs(testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true,
            testOutput);

    extractResourceDirs(testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true,
            testOutput);

    // avoid duplicated entries
    Set directories = new LinkedHashSet();

    // NOTE: Since MNG-3118, test classes come before main classes
    boolean testBeforeMain = isMavenVersion("[2.0.8,)");

    // let users override this if needed, they need to simulate more than the test phase in eclipse
    if (testSourcesLast) {
        testBeforeMain = false;
    }

    if (testBeforeMain) {
        directories.addAll(testDirectories);
        directories.removeAll(mainDirectories);
        directories.addAll(mainDirectories);
    } else {
        directories.addAll(mainDirectories);
        directories.addAll(testDirectories);
    }
    if (ajdt) {
        extractAspectDirs(directories, project, basedir, projectBaseDir, testOutput);
    }
    return (EclipseSourceDir[]) directories.toArray(new EclipseSourceDir[directories.size()]);
}

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.EclipsePlugin.java

License:Apache License

/**
 * @param mavenProject the project to get the projectNameTemplate configuration from
 * @return the projectNameTemplate configuration from the specified MavenProject
 *//*from  w ww.j  av a 2 s.co m*/
private String getProjectNameTemplateForMavenProject(MavenProject mavenProject) {
    String projectNameTemplate = null;
    boolean addVersionToProjectName = false;
    boolean addGroupIdToProjectName = false;

    Build build = mavenProject.getBuild();
    if (build != null) {
        String eclipsePlugin = "org.apache.maven.plugins:maven-eclipse-plugin";
        Plugin plugin = (Plugin) build.getPluginsAsMap().get(eclipsePlugin);
        if (plugin == null && build.getPluginManagement() != null) {
            plugin = (Plugin) build.getPluginManagement().getPluginsAsMap().get(eclipsePlugin);
        }
        if (plugin != null) {
            Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
            if (config != null) {
                Xpp3Dom projectNameTemplateNode = config.getChild("projectNameTemplate");
                if (projectNameTemplateNode != null) {
                    projectNameTemplate = projectNameTemplateNode.getValue();
                }
                Xpp3Dom addVersionToProjectNameNode = config.getChild("addVersionToProjectName");
                addVersionToProjectName = addVersionToProjectNameNode != null;
                Xpp3Dom addGroupIdToProjectNameNode = config.getChild("addGroupIdToProjectName");
                addGroupIdToProjectName = addGroupIdToProjectNameNode != null;
            }
        }
    }
    return IdeUtils.calculateProjectNameTemplate(projectNameTemplate, addVersionToProjectName,
            addGroupIdToProjectName, getLog());
}

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

/**
 * Search for the configuration Xpp3 dom of an other plugin.
 *
 * @param project  the current maven project to get the configuration from.
 * @param pluginId the group id and artifact id of the plugin to search for
 * @return the value of the option configured in the plugin configuration
 * @todo there should be a better way to do this
 *//*from ww w  . jav  a2s.  c o  m*/
public static Xpp3Dom getPluginConfigurationDom(MavenProject project, String pluginId) {

    Plugin plugin = (org.apache.maven.model.Plugin) project.getBuild().getPluginsAsMap().get(pluginId);
    if (plugin != null) {
        // TODO: This may cause ClassCastExceptions eventually, if the dom impls differ.
        return (Xpp3Dom) plugin.getConfiguration();
    }
    return null;
}

From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java

License:Apache License

private static File getClasspathElement(Artifact artifact, MavenProject mavenProject)
        throws MojoExecutionException {
    if (artifact.getClassifier() != null) {
        return artifact.getFile();
    }/*from   ww  w  .j a  va  2s .  c om*/
    String refId = artifact.getGroupId() + ":" + artifact.getArtifactId();
    MavenProject project = (MavenProject) mavenProject.getProjectReferences().get(refId);
    if (project != null) {
        return new File(project.getBuild().getOutputDirectory());
    } else {
        File file = artifact.getFile();
        if ((file == null) || (!file.exists())) {
            throw new MojoExecutionException("Dependency Resolution Required " + artifact);
        }
        return file;
    }
}

From source file:com.citytechinc.cq.component.maven.ComponentMojo.java

License:Apache License

@SuppressWarnings("unchecked")
private List<String> getExcludedDependencyPaths() throws DependencyResolutionRequiredException {
    if (excludeDependencies != null && !excludeDependencies.isEmpty()) {
        getLog().debug("Exclusions Found");

        List<Artifact> compileArtifacts = project.getCompileArtifacts();

        List<String> excludedClasspathElements = new ArrayList<String>();

        Set<String> excludedArtifactIdentifiers = new HashSet<String>();

        for (Dependency curDependency : excludeDependencies) {
            excludedArtifactIdentifiers.add(curDependency.getGroupId() + ":" + curDependency.getArtifactId());
        }/*from  w  ww. ja  v  a 2s . com*/

        for (Artifact curArtifact : compileArtifacts) {
            String referenceIdentifier = curArtifact.getGroupId() + ":" + curArtifact.getArtifactId();

            if (excludedArtifactIdentifiers.contains(referenceIdentifier)) {
                MavenProject identifiedProject = (MavenProject) project.getProjectReferences()
                        .get(referenceIdentifier);
                if (identifiedProject != null) {
                    excludedClasspathElements.add(identifiedProject.getBuild().getOutputDirectory());
                    getLog().debug("Excluding " + identifiedProject.getBuild().getOutputDirectory());
                } else {
                    File file = curArtifact.getFile();
                    if (file == null) {
                        throw new DependencyResolutionRequiredException(curArtifact);
                    }
                    excludedClasspathElements.add(file.getPath());
                    getLog().debug("Excluding " + file.getPath());
                }
            }
        }

        return excludedClasspathElements;
    }

    return null;

}

From source file:com.citytechinc.cq.component.maven.util.ComponentMojoUtil.java

License:Apache License

/**
 * Finds and retrieves the constructed CQ Package archive file for the
 * project/*from  ww  w.  ja  va  2  s .c  o  m*/
 * 
 * @param project
 * @return The archive file found for the project
 */
protected static File getArchiveFileForProject(MavenProject project) {
    File buildDirectory = new File(project.getBuild().getDirectory());

    String zipFileName = project.getArtifactId() + "-" + project.getVersion() + ".zip";

    getLog().debug("Determined ZIP file name to be " + zipFileName);

    return new File(buildDirectory, zipFileName);
}