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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Create new POM (based on the root POM) which lists the deployed bundles as dependencies
 * /*w w  w  .  jav  a 2 s .c  om*/
 * @param bundles list of bundles to be deployed
 * @return deployment project
 * @throws MojoExecutionException
 */
private MavenProject createDeploymentProject(List bundles) throws MojoExecutionException {
    MavenProject deployProject;

    if (null == m_project.getFile()) {
        deployProject = new MavenProject();
        deployProject.setGroupId("examples");
        deployProject.setArtifactId("pax-provision");
        deployProject.setVersion("1.0-SNAPSHOT");
    } else {
        deployProject = new MavenProject(m_project);
    }

    String internalId = PomUtils.getCompoundId(deployProject.getGroupId(), deployProject.getArtifactId());
    deployProject.setGroupId(internalId + ".build");
    deployProject.setArtifactId("deployment");

    // remove unnecessary cruft
    deployProject.setPackaging("pom");
    deployProject.getModel().setModules(null);
    deployProject.getModel().setDependencies(bundles);
    deployProject.getModel().setPluginRepositories(null);
    deployProject.getModel().setReporting(null);
    deployProject.setBuild(null);

    File deployFile = new File(deployProject.getBasedir(), "runner/deploy-pom.xml");

    deployFile.getParentFile().mkdirs();
    deployProject.setFile(deployFile);

    try {
        Writer writer = StreamFactory.newXmlWriter(deployFile);
        deployProject.writeModel(writer);
        IOUtil.close(writer);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to write deployment POM " + deployFile);
    }

    return deployProject;
}

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Install deployment POM in the local Maven repository
 * // w  w  w .  j a v  a  2s  .co  m
 * @param project deployment project
 * @throws MojoExecutionException
 */
private void installDeploymentPom(MavenProject project) throws MojoExecutionException {
    String groupId = project.getGroupId();
    String artifactId = project.getArtifactId();
    String version = project.getVersion();

    Artifact pomArtifact = m_factory.createProjectArtifact(groupId, artifactId, version);

    try {
        m_installer.install(project.getFile(), pomArtifact, m_localRepo);
    } catch (ArtifactInstallationException e) {
        throw new MojoExecutionException("Unable to install deployment POM " + pomArtifact);
    }
}

From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java

License:Apache License

/**
 * Deploy bundles using the 'classic' Pax-Runner
 * /*w  ww. jav a  2 s. c  om*/
 * @param mainClass main Pax-Runner class
 * @param project deployment project
 * @param repositories comma separated list of Maven repositories
 * @throws MojoExecutionException
 */
private void deployRunnerClassic(Class mainClass, MavenProject project, String repositories)
        throws MojoExecutionException {
    String workDir = project.getBasedir() + "/runner";

    String cachedPomName = project.getArtifactId() + '_' + project.getVersion() + ".pom";
    File cachedPomFile = new File(workDir + "/lib/" + cachedPomName);

    // Force reload of pom
    cachedPomFile.delete();

    if (PomUtils.isEmpty(framework)) {
        framework = "felix";
    }

    String[] deployAppCmds = { "--dir=" + workDir, "--no-md5", "--platform=" + framework, "--profile=default",
            "--repository=" + repositories, "--localRepository=" + m_localRepo.getBasedir(),
            project.getGroupId(), project.getArtifactId(), project.getVersion() };

    invokePaxRunner(mainClass, deployAppCmds);
}

From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java

License:Apache License

/**
 * Add bundle as a dependency to the provisioning POM and the local bundle POM, as appropriate
 * // w w  w.  j  a v a 2  s  . co  m
 * @param project bundle project
 */
private void importBundle(MavenProject project) {
    Dependency dependency = new Dependency();

    dependency.setGroupId(project.getGroupId());
    dependency.setArtifactId(project.getArtifactId());
    dependency.setVersion(project.getVersion());
    dependency.setOptional(!deploy);

    // only add non-local bundles to the provisioning POM
    if (m_provisionPom != null && project.getFile() == null) {
        getLog().info("Importing " + project.getName() + " to " + m_provisionPom);
        m_provisionPom.addDependency(dependency, overwrite);
    }

    if (m_localBundlePom != null) {
        // use provided scope when adding to bundle pom
        dependency.setScope(Artifact.SCOPE_PROVIDED);

        getLog().info("Adding " + project.getName() + " as dependency to " + m_localBundlePom);
        m_localBundlePom.addDependency(dependency, overwrite);
    }
}

From source file:org.ops4j.pax.construct.util.XppPom.java

License:Apache License

/**
 * {@inheritDoc}//from w  ww.ja v  a2s. c  om
 */
public void setParent(MavenProject project, String relativePath, boolean overwrite)
        throws ExistingElementException {
    if (m_pom.getChild("parent") != null && !overwrite) {
        throw new ExistingElementException("parent");
    }

    Xpp3DomMap parent = new Xpp3DomMap("parent");
    parent.putValue("relativePath", relativePath);
    parent.putValue("groupId", project.getGroupId());
    parent.putValue("artifactId", project.getArtifactId());
    parent.putValue("version", project.getVersion());

    Xpp3Dom newPom = new Xpp3Dom("project");
    newPom.addChild(parent);

    m_pom = Xpp3DomHelper.mergeXpp3Dom(newPom, m_pom);
}

From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java

License:Apache License

/**
 * Generates the reports for a given dependency-check engine.
 *
 * @param engine a dependency-check engine
 * @param p the Maven project//  w w  w . j  av a2 s  .co m
 * @param outputDir the directory path to write the report(s)
 * @throws ReportException thrown if there is an error writing the report
 */
protected void writeReports(Engine engine, MavenProject p, File outputDir) throws ReportException {
    DatabaseProperties prop = null;
    try (CveDB cve = CveDB.getInstance()) {
        prop = cve.getDatabaseProperties();
    } catch (DatabaseException ex) {
        //TODO shouldn't this throw an exception?
        if (getLog().isDebugEnabled()) {
            getLog().debug("Unable to retrieve DB Properties", ex);
        }
    }
    final ReportGenerator r = new ReportGenerator(p.getName(), p.getVersion(), p.getArtifactId(),
            p.getGroupId(), engine.getDependencies(), engine.getAnalyzers(), prop);
    try {
        r.generateReports(outputDir.getAbsolutePath(), format);
    } catch (ReportException ex) {
        final String msg = String.format("Error generating the report for %s", p.getName());
        throw new ReportException(msg, ex);
    }

}

From source file:org.owasp.dependencycheck.maven.Engine.java

License:Apache License

/**
 * Runs the analyzers against all of the dependencies.
 *///from  w ww . j  a v a  2s  .co m
@Override
public void analyzeDependencies() {
    final MavenProject root = getExecutionRoot();
    if (root != null) {
        LOGGER.debug("Checking root project, {}, if updates have already been completed", root.getArtifactId());
    } else {
        LOGGER.debug("Checking root project, null, if updates have already been completed");
    }
    if (root != null && root.getContextValue(UPDATE_EXECUTED_FLAG) != null) {
        System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString());
    }
    super.analyzeDependencies();
    if (root != null) {
        root.setContextValue(UPDATE_EXECUTED_FLAG, Boolean.TRUE);
    }
}

From source file:org.owasp.dependencycheck.maven.MavenEngine.java

License:Apache License

/**
 * Runs the analyzers against all of the dependencies.
 *
 * @throws ExceptionCollection thrown if an exception occurred; contains a
 * collection of exceptions that occurred during analysis.
 *//*w ww . ja  v a 2  s.c  o  m*/
@Override
public void analyzeDependencies() throws ExceptionCollection {
    final MavenProject root = getExecutionRoot();
    if (root != null) {
        LOGGER.debug("Checking root project, {}, if updates have already been completed", root.getArtifactId());
    } else {
        LOGGER.debug("Checking root project, null, if updates have already been completed");
    }
    if (root != null && root.getContextValue(UPDATE_EXECUTED_FLAG) != null) {
        System.setProperty(Settings.KEYS.AUTO_UPDATE, Boolean.FALSE.toString());
    }
    super.analyzeDependencies();
    if (root != null) {
        root.setContextValue(UPDATE_EXECUTED_FLAG, Boolean.TRUE);
    }
}

From source file:org.phpmaven.plugin.pear.DefaultMojo.java

License:Apache License

protected String getPackageKey(final MavenProject prj) {
    final String prop = prj.getProperties().getProperty("flow3.ns");
    if (prop != null)
        return prop;
    return "F3." + prj.getArtifactId();
}

From source file:org.piraso.maven.AbstractWarMojo.java

License:Apache License

/**
 * Builds the webapp for the specified project with the new packaging task
 * thingy//from   w  w  w  .ja v a2  s .  com
 * <p/>
 * Classes, libraries and tld files are copied to
 * the <tt>webappDirectory</tt> during this phase.
 *
 * @param project         the maven project
 * @param webappDirectory the target directory
 * @throws org.apache.maven.plugin.MojoExecutionException if an error occurred while packaging the webapp
 * @throws org.apache.maven.plugin.MojoFailureException   if an unexpected error occurred while packaging the webapp
 * @throws java.io.IOException            if an error occurred while copying the files
 */
@SuppressWarnings("unchecked")
public void buildWebapp(MavenProject project, File webappDirectory)
        throws MojoExecutionException, MojoFailureException, IOException {

    WebappStructure cache;
    if (useCache && cacheFile.exists()) {
        cache = new WebappStructure(project.getDependencies(), webappStructureSerialier.fromXml(cacheFile));
    } else {
        cache = new WebappStructure(project.getDependencies(), null);
    }

    final long startTime = System.currentTimeMillis();
    getLog().info("Assembling webapp [" + project.getArtifactId() + "] in [" + webappDirectory + "]");

    final OverlayManager overlayManager = new OverlayManager(overlays, project, dependentWarIncludes,
            dependentWarExcludes, currentProjectOverlay);
    final List<WarPackagingTask> packagingTasks = getPackagingTasks(overlayManager);
    List<FileUtils.FilterWrapper> defaultFilterWrappers = null;
    try {
        MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
        mavenResourcesExecution.setEscapeString(escapeString);

        defaultFilterWrappers = mavenFileFilter.getDefaultFilterWrappers(project, filters,
                escapedBackslashesInFilePath, this.session, mavenResourcesExecution);

    } catch (MavenFilteringException e) {
        getLog().error("fail to build filering wrappers " + e.getMessage());
        throw new MojoExecutionException(e.getMessage(), e);
    }

    final WarPackagingContext context = new DefaultWarPackagingContext(webappDirectory, cache, overlayManager,
            defaultFilterWrappers, getNonFilteredFileExtensions(), filteringDeploymentDescriptors,
            this.artifactFactory, resourceEncoding);
    for (WarPackagingTask warPackagingTask : packagingTasks) {
        warPackagingTask.performPackaging(context);
    }

    // Post packaging
    final List<WarPostPackagingTask> postPackagingTasks = getPostPackagingTasks();
    for (WarPostPackagingTask task : postPackagingTasks) {
        task.performPostPackaging(context);
    }
    getLog().info("Webapp assembled in [" + (System.currentTimeMillis() - startTime) + " msecs]");

}