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.hsc.novelSpider.bundleplugin.BundlePlugin.java

License:Apache License

/**
 * TODO this should return getMaven2Osgi().getBundleFileName( project.getArtifact() )
 *///www  .  j  a  va  2s .c om
protected String getBundleName(MavenProject currentProject) {
    String extension;
    try {
        extension = currentProject.getArtifact().getArtifactHandler().getExtension();
    } catch (Throwable e) {
        extension = currentProject.getArtifact().getType();
    }
    if (StringUtils.isEmpty(extension) || "bundle".equals(extension) || "pom".equals(extension)) {
        extension = "jar"; // just in case maven gets confused
    }
    String finalName = currentProject.getBuild().getFinalName();
    if (null != classifier && classifier.trim().length() > 0) {
        return finalName + '-' + classifier + '.' + extension;
    }
    return finalName + '.' + extension;
}

From source file:org.hsc.novelSpider.obrplugin.ObrUtils.java

License:Apache License

/**
 * @param project current project/*  w  w  w  .  j a  v  a  2 s  .com*/
 * @return URI pointing to correct obr.xml, null if not found
 */
public static URI findObrXml(MavenProject project) {
    File obrFile = new File(project.getBuild().getOutputDirectory(), OBR_XML);
    if (obrFile.exists()) {
        return obrFile.toURI();
    }
    for (Iterator i = project.getResources().iterator(); i.hasNext();) {
        Resource resource = (Resource) i.next();
        obrFile = new File(resource.getDirectory(), OBR_XML);
        if (obrFile.exists()) {
            return obrFile.toURI();
        }
    }
    return null;
}

From source file:org.impalaframework.maven.plugin.MojoUtils.java

License:Apache License

static String getModuleStagingDirectory(Log log, MavenProject project, String moduleStagingDirectory)
        throws MojoExecutionException {

    //FIXME test/*from  ww w.  j a va 2s  .com*/

    String parentName = null;

    if (moduleStagingDirectory == null) {
        MavenProject parent = project.getParent();
        if (parent != null) {
            parentName = parent.getName();
            final String parentOutputDirectory = parent.getBuild().getDirectory();
            if (parentOutputDirectory != null) {
                moduleStagingDirectory = parentOutputDirectory + "/staging";
            }
        }
    }

    if (moduleStagingDirectory == null) {
        throw new MojoExecutionException("Unable to determine module staging directory for project '"
                + project.getName() + "'"
                + (parentName != null ? " from project parent '" + parentName + "'" : " with no project parent")
                + ". Please use 'moduleStagingDirectory' configuration parameter to specify this.");
    }

    log.info("Using module staging directory: " + moduleStagingDirectory);

    return moduleStagingDirectory;
}

From source file:org.jacoco.maven.AggregateReportMojo.java

License:Open Source License

@Override
protected BundleCreator createBundleCreator(final FileFilter fileFilter) {
    final List<File> moduleDirs = new ArrayList<File>();

    for (MavenProject module : getIncludedModules()) {
        final File file = new File(module.getBuild().getOutputDirectory());
        if (file.exists()) {
            moduleDirs.add(file);//from w w  w. j a va 2s . c  o  m
        }
    }

    return new BundleCreator(project, fileFilter, moduleDirs);
}

From source file:org.jacoco.maven.AggregateReportMojo.java

License:Open Source License

private void load(final ExecFileLoader loader) throws MojoExecutionException {
    for (MavenProject module : getIncludedModules()) {
        // TODO: hack to find exec file, isn't quite accurate if it's been moved out of the target directory
        File inputFile = new File(module.getBuild().getDirectory(), dataFile.getName());

        if (inputFile.exists()) {
            try {
                getLog().info("Loading execution data file " + inputFile.getAbsolutePath());
                loader.load(inputFile);//  ww  w  .ja v a 2  s .c o m
            } catch (final IOException e) {
                throw new MojoExecutionException("Unable to read " + inputFile.getAbsolutePath(), e);
            }
        }

    }
}

From source file:org.jacoco.maven.ReportSupport.java

License:Open Source License

private void processProject(final IReportGroupVisitor visitor, final String bundeName,
        final MavenProject project, final List<String> includes, final List<String> excludes,
        final ISourceFileLocator locator) throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final File classesDir = new File(project.getBuild().getOutputDirectory());

    if (classesDir.isDirectory()) {
        final Analyzer analyzer = new Analyzer(loader.getExecutionDataStore(), builder);
        final FileFilter filter = new FileFilter(includes, excludes);
        for (final File file : filter.getFiles(classesDir)) {
            analyzer.analyzeAll(file);//  w ww .java  2 s  .  com
        }
    }

    final IBundleCoverage bundle = builder.getBundle(bundeName);
    logBundleInfo(bundle, builder.getNoMatchClasses());

    visitor.visitBundle(bundle, locator);
}

From source file:org.javagems.core.maven.DebianMojo.java

License:Apache License

/**
 * Copy properties from the maven project to the ant project.
 *
 * @param mavenProject//w w w  .ja v a 2 s. co  m
 * @param antProject
 */
public void copyProperties(MavenProject mavenProject, Project antProject) {
    Properties mavenProps = mavenProject.getProperties();
    Iterator iter = mavenProps.keySet().iterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        antProject.setProperty(key, mavenProps.getProperty(key));
    }

    // Set the POM file as the ant.file for the tasks run directly in Maven.
    antProject.setProperty("ant.file", mavenProject.getFile().getAbsolutePath());

    // Add some of the common maven properties
    getLog().debug("Setting properties with prefix: " + propertyPrefix);
    antProject.setProperty((propertyPrefix + "project.groupId"), mavenProject.getGroupId());
    antProject.setProperty((propertyPrefix + "project.artifactId"), mavenProject.getArtifactId());
    antProject.setProperty((propertyPrefix + "project.name"), mavenProject.getName());
    if (mavenProject.getDescription() != null) {
        antProject.setProperty((propertyPrefix + "project.description"), mavenProject.getDescription());
    }
    antProject.setProperty((propertyPrefix + "project.version"), mavenProject.getVersion());
    antProject.setProperty((propertyPrefix + "project.packaging"), mavenProject.getPackaging());
    antProject.setProperty((propertyPrefix + "project.build.directory"),
            mavenProject.getBuild().getDirectory());
    antProject.setProperty((propertyPrefix + "project.build.outputDirectory"),
            mavenProject.getBuild().getOutputDirectory());
    antProject.setProperty((propertyPrefix + "project.build.testOutputDirectory"),
            mavenProject.getBuild().getTestOutputDirectory());
    antProject.setProperty((propertyPrefix + "project.build.sourceDirectory"),
            mavenProject.getBuild().getSourceDirectory());
    antProject.setProperty((propertyPrefix + "project.build.testSourceDirectory"),
            mavenProject.getBuild().getTestSourceDirectory());
    antProject.setProperty((propertyPrefix + "localRepository"), localRepository.toString());
    antProject.setProperty((propertyPrefix + "settings.localRepository"), localRepository.getBasedir());

    // Add properties for depenedency artifacts
    Set depArtifacts = mavenProject.getArtifacts();
    for (Iterator it = depArtifacts.iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();

        String propName = artifact.getDependencyConflictId();

        antProject.setProperty(propertyPrefix + propName, artifact.getFile().getPath());
    }

    // Add a property containing the list of versions for the mapper
    StringBuffer versionsBuffer = new StringBuffer();
    for (Iterator it = depArtifacts.iterator(); it.hasNext();) {
        Artifact artifact = (Artifact) it.next();

        versionsBuffer.append(artifact.getVersion() + File.pathSeparator);
    }
    antProject.setProperty(versionsPropertyName, versionsBuffer.toString());
}

From source file:org.jboss.maven.plugins.qstools.checkers.FinalNameChecker.java

License:Apache License

@Override
public void checkProject(MavenProject project, Document doc, Map<String, List<Violation>> results)
        throws Exception {
    String packaging = project.getPackaging();
    String expectedFinalName = getConfigurationProvider().getQuickstartsRules(project.getGroupId())
            .getFinalNamePatterns().get(packaging);
    Node finalNameNode = (Node) getxPath().evaluate("//finalName", doc, XPathConstants.NODE);
    String declaredFinalName = finalNameNode == null ? project.getBuild().getFinalName()
            : finalNameNode.getTextContent();
    if (expectedFinalName != null && !expectedFinalName.equals(declaredFinalName)) {
        int lineNumber = finalNameNode == null ? 0 : XMLUtil.getLineNumberFromNode(finalNameNode);
        addViolation(project.getFile(), results, lineNumber,
                ("File doesn't contain <finalName>" + expectedFinalName + "</finalName>"));
    }/*from ww  w.  ja v a2 s  . c  om*/
}

From source file:org.jboss.maven.plugins.qstools.fixers.FinalNameFixer.java

License:Apache License

@Override
public void fixProject(MavenProject project, Document doc) throws Exception {

    String packaging = project.getPackaging();
    String expectedFinalName = getConfigurationProvider().getQuickstartsRules(project.getGroupId())
            .getFinalNamePatterns().get(packaging);

    Node finalNameNode = (Node) getxPath().evaluate("//finalName", doc, XPathConstants.NODE);
    String declaredFinalName = finalNameNode == null ? project.getBuild().getFinalName()
            : finalNameNode.getTextContent();

    if (expectedFinalName != null && !expectedFinalName.equals(declaredFinalName)) {

        Node buildNode = (Node) getxPath().evaluate("/project/build", doc, XPathConstants.NODE);
        if (buildNode == null) {
            buildNode = doc.createElement("build");
            Node projectNode = (Node) getxPath().evaluate("/project", doc, XPathConstants.NODE);
            projectNode.appendChild(doc.createTextNode("    "));
            projectNode.appendChild(buildNode);
        }//from   w  ww .j a  v  a  2s .  c o  m

        finalNameNode = (Node) getxPath().evaluate("/project/build/finalName", doc, XPathConstants.NODE);
        if (finalNameNode == null) {
            finalNameNode = doc.createElement("finalName");
            buildNode.insertBefore(finalNameNode, buildNode.getFirstChild());
        }

        finalNameNode.setTextContent(expectedFinalName);
    }

    XMLUtil.writeXML(doc, project.getFile());
}

From source file:org.jboss.maven.shared.properties.CompositeMavenProjectProperties.java

License:Open Source License

@SuppressWarnings("unchecked")
public CompositeMavenProjectProperties(MavenProject project) {
    this.project = project;
    values = new HashMap(System.getProperties());
    values.putAll(project.getProperties());
    for (Object o : project.getBuild().getFilters()) {
        String filtersfile = (String) o;
        values.putAll(PropertiesHelper.loadPropertyFile(new File(filtersfile)));
    }/*w  w w .java  2 s  .com*/
}