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:com.paulhammant.buildradiatorextension.BuildRadiatorEventSpy.java

License:Open Source License

@Override
public void onEvent(Object event) throws Exception {

    try {// w  ww.  j a  v  a 2  s.  c  o  m

        try {
            if (event instanceof ExecutionEvent) {
                ExecutionEvent executionEvent = (ExecutionEvent) event;
                MavenProject project = executionEvent.getProject();
                String lifecyclePhase = executionEvent.getMojoExecution().getLifecyclePhase();
                String phase = lifecyclePhase.substring(lifecyclePhase.lastIndexOf(':') + 1);
                String execution = executionEvent.getMojoExecution().getExecutionId();

                String currentArtifactId = project.getArtifactId();

                if (!projectPropertiesDone) {
                    this.buildRadiatorInterop.projectProperties(project.getProperties(),
                            project.getArtifactId());
                    projectPropertiesDone = true;
                }

                String status = executionEvent.getType().toString();
                if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) {
                    status = "started";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoFailed) {
                    status = "failed";
                } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded) {
                    status = "passed";
                }

                this.buildRadiatorInterop.executionEvent(phase, execution, currentArtifactId, status);

            }
            if (event instanceof DefaultMavenExecutionResult) {
                DefaultMavenExecutionResult dmer = (DefaultMavenExecutionResult) event;
                this.buildRadiatorInterop.executionResult(
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildSuccess,
                        dmer.getBuildSummary(dmer.getProject()) instanceof BuildFailure);
            }
        } catch (NullPointerException e) {
            // do nothing
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.puppetlabs.geppetto.forge.maven.plugin.Package.java

License:Open Source License

@Override
protected void invoke(Diagnostic result) throws Exception {
    Collection<File> moduleRoots = findModuleRoots();
    if (moduleRoots.isEmpty()) {
        result.addChild(new Diagnostic(ERROR, PACKAGE, "No modules found in repository"));
        return;// www.j  a v  a2s  . c  om
    }

    File buildDir = getBuildDir();
    buildDir.mkdirs();
    if (moduleRoots.size() == 1) {
        MavenProject project = getProject();
        File moduleRoot = moduleRoots.iterator().next();
        Metadata[] resultingMetadata = new Metadata[1];
        byte[][] resultingMD5 = new byte[1][];
        project.getArtifact()
                .setFile(buildForge(moduleRoot, buildDir, resultingMetadata, resultingMD5, result));

        Artifact pmriArtifact = repositorySystem.createArtifact(project.getGroupId(), project.getArtifactId(),
                project.getVersion(), "compile", "pmri");

        PuppetModuleReleaseInfo pmri = new PuppetModuleReleaseInfo();
        pmri.setMetadata(resultingMetadata[0]);
        pmri.populate(moduleRoot);

        File pmriFile = new File(buildDir, "release.pmri");
        OutputStream out = new FileOutputStream(pmriFile);
        try {
            Writer writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8));
            getGson().toJson(pmri, writer);
            writer.flush();
        } finally {
            out.close();
        }
        pmriArtifact.setFile(pmriFile);
        pmriArtifact.setResolved(true);
        project.addAttachedArtifact(pmriArtifact);
    } else {
        File builtModules = new File(buildDir, "builtModules");
        if (!(builtModules.mkdir() || builtModules.isDirectory())) {
            result.addChild(
                    new Diagnostic(ERROR, PACKAGE, "Unable to create directory" + builtModules.getPath()));
            return;
        }
        for (File moduleRoot : moduleRoots)
            buildForge(moduleRoot, builtModules, null, null, result);
    }
}

From source file:com.redhat.rcm.version.mgr.session.ManagedInfo.java

License:Open Source License

void addBOM(final File bom, final MavenProject project) throws VManException {
    final FullProjectKey key = new FullProjectKey(project.getGroupId(), project.getArtifactId(),
            project.getVersion());/*from  w  ww. java2 s  . c o  m*/
    if (bomProjects.containsKey(key)) {
        return;
    }

    bomProjects.put(key, project);

    startBomMap(bom, project.getGroupId(), project.getArtifactId(), project.getVersion());

    if (project.getDependencyManagement() != null
            && project.getDependencyManagement().getDependencies() != null) {
        for (final Dependency dep : project.getDependencyManagement().getDependencies()) {
            mapDependency(bom, dep);
        }
    }

    final Properties properties = project.getProperties();
    if (properties != null) {
        final String relocations = properties.getProperty(RELOCATIONS_KEY);
        logger.info("Got relocations:\n\n" + relocations);
        if (relocations != null) {
            logger.warn("[DEPRECATED] BOM-based coordinate relocations have been replaced by the "
                    + Cli.RELOCATIONS_PROPERTY
                    + " configuration, which specifies a URL to a properties file. Please use this instead.");

            relocatedCoords.addBomRelocations(bom, parseProperties(relocations));
        }

        final String mappings = properties.getProperty(MAPPINGS_KEY);
        logger.info("Got mappings:\n\n" + mappings);
        if (mappings != null) {
            logger.warn("[DEPRECATED] BOM-based property mappings have been replaced by the "
                    + Cli.PROPERTY_MAPPINGS_PROPERTY
                    + " configuration, which specifies a URL to a properties file. Please use this instead.");

            propertyMappings.addBomPropertyMappings(bom, project.getProperties(), parseProperties(mappings));
        }
    }

    logger.info("Updating property mappings from " + project.getId());

    // NOTE: parent properties are inherited into the BOM by the time the MavenProject instance
    // is created, so we don't need to traverse up to the parent; we should have everything here.
    propertyMappings.updateProjectMap(project.getProperties());
}

From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectInfoProvider.java

License:Apache License

public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) {

    // finite set of project properties we expose
    final Map<String, String> props = new LinkedHashMap<String, String>(65);
    props.put("project.id", project.getId());
    props.put("project.groupId", project.getGroupId());
    props.put("project.artifactId", project.getArtifactId());
    props.put("project.version", project.getVersion());
    props.put("project.name", project.getName());
    props.put("project.description", project.getDescription());
    props.put("project.modelVersion", project.getModelVersion());
    props.put("project.inceptionYear", project.getInceptionYear());
    props.put("project.packaging", project.getPackaging());
    props.put("project.url", project.getUrl());
    final MavenProject parent = project.getParent();
    if (parent != null) {
        props.put("project.parent.id", parent.getId());
        props.put("project.parent.groupId", parent.getGroupId());
        props.put("project.parent.artifactId", parent.getArtifactId());
        props.put("project.parent.version", parent.getVersion());
        props.put("project.parent.name", parent.getName());
        props.put("project.parent.description", parent.getDescription());
        props.put("project.parent.modelVersion", parent.getModelVersion());
        props.put("project.parent.inceptionYear", parent.getInceptionYear());
        props.put("project.parent.packaging", parent.getPackaging());
        props.put("project.parent.url", parent.getUrl());
    }//  w ww .  j  a  va 2  s.  co m

    // properties the user wants
    Map<String, String> info = new LinkedHashMap<String, String>();

    for (String propertyName : mojo.getProjectProperties()) {
        String prop = props.get(propertyName);
        if (prop != null) {
            info.put(propertyName, prop);
        }
    }
    info.put("build.time", DateFormatUtils.format(new Date(), "d MMMM yyyy, HH:mm:ss ZZ", Locale.ENGLISH));

    return info;
}

From source file:com.rodiontsev.maven.plugins.buildinfo.providers.ProjectPropertiesProvider.java

License:Apache License

public Map<String, String> getInfo(MavenProject project, BuildInfoMojo mojo) {
    // finite set of project properties we expose
    final Map<String, String> projectProperties = new LinkedHashMap<String, String>(65);
    projectProperties.put("project.id", project.getId());
    projectProperties.put("project.groupId", project.getGroupId());
    projectProperties.put("project.artifactId", project.getArtifactId());
    projectProperties.put("project.version", project.getVersion());
    projectProperties.put("project.name", project.getName());
    projectProperties.put("project.description", project.getDescription());
    projectProperties.put("project.modelVersion", project.getModelVersion());
    projectProperties.put("project.inceptionYear", project.getInceptionYear());
    projectProperties.put("project.packaging", project.getPackaging());
    projectProperties.put("project.url", project.getUrl());

    MavenProject parent = project.getParent();
    if (parent != null) {
        projectProperties.put("project.parent.id", parent.getId());
        projectProperties.put("project.parent.groupId", parent.getGroupId());
        projectProperties.put("project.parent.artifactId", parent.getArtifactId());
        projectProperties.put("project.parent.version", parent.getVersion());
        projectProperties.put("project.parent.name", parent.getName());
        projectProperties.put("project.parent.description", parent.getDescription());
        projectProperties.put("project.parent.modelVersion", parent.getModelVersion());
        projectProperties.put("project.parent.inceptionYear", parent.getInceptionYear());
        projectProperties.put("project.parent.packaging", parent.getPackaging());
        projectProperties.put("project.parent.url", parent.getUrl());
    }/* w w  w  .j a  va 2  s . c  om*/

    Map<String, String> info = new LinkedHashMap<String, String>();

    new InfoWriter().write(info, mojo.getProjectProperties(), new PropertyMapper() {
        @Override
        public String mapProperty(String propertyName) {
            return projectProperties.get(propertyName);
        }
    });

    return info;
}

From source file:com.sap.prd.mobile.ios.mios.PreDeployMojo.java

License:Apache License

/**
 * Returns the unique archive folder for this specific project (containing folders with groupId
 * and artifactId)/*from   w w  w  .j a  v  a 2s .c  o m*/
 * 
 * @param rootArchiveFolder
 * @param project
 * @return
 */
static File getProjectArchiveFolder(File rootArchiveFolder, MavenProject project) {
    return new File(new File(new File(rootArchiveFolder, "artifacts"), project.getGroupId()),
            project.getArtifactId());
}

From source file:com.sap.prd.mobile.ios.mios.XCodePackageManager.java

License:Apache License

private String getBundleReference(MavenProject project, String escapedBundleName) {
    return GAVUtil.toColonNotation(project.getGroupId(), project.getArtifactId(), project.getVersion(),
            ZIPPED_BUNDLE_SUFFIX, escapedBundleName);
}

From source file:com.sap.prd.mobile.ios.mios.XCodePackageManager.java

License:Apache License

static void attachLibrary(final XCodeContext xcodeContext, File buildDir, final MavenProject project,
        final MavenProjectHelper projectHelper) {

    final File fatBinary = XCodeBuildLayout.getBinary(buildDir, xcodeContext.getConfiguration(),
            xcodeContext.getSDK(), project.getArtifactId());

    if (!fatBinary.exists())
        throw new RuntimeException(fatBinary + " should be attached but does not exist.");

    final String classifier = xcodeContext.getConfiguration() + "-" + xcodeContext.getSDK();

    projectHelper.attachArtifact(project, "a", classifier, fatBinary);

    LOGGER.info("Archive file '" + fatBinary + "' attached as side artifact for '" + project.getArtifact()
            + "' with classifier '" + classifier + "'.");
}

From source file:com.serli.maven.plugin.quality.mojo.LicenseMojo.java

License:Open Source License

private PrettyPrintXMLWriter printDependenciesLicense(PrettyPrintXMLWriter writer) {
    writer.startElement("dependenciesLicense");
    if (resultLicenseMap != null && resultLicenseMap.size() > 0) {
        Set<LightLicense> keys = resultLicenseMap.keySet();
        for (LightLicense license : keys) {
            writer.startElement("license");
            String url = license.getUrl();
            String name = license.getName();
            if (StringUtils.isEmpty(name)) {
                name = "Unnamed";
            }// ww  w .ja v  a2 s .  c o  m
            if (StringUtils.isEmpty(url)) {
                url = "unavailable";
            }
            writer.startElement("name");
            writer.writeText(name);
            writer.endElement();
            writer.startElement("url");
            writer.writeText(url);
            writer.endElement();
            SortedSet<MavenProjectComparable> sortedSet = resultLicenseMap.get(license);
            for (MavenProject artifact : sortedSet) {
                writer.startElement("dependency");
                String id = artifact.getModel().getName();
                if (StringUtils.isEmpty(id)) {
                    id = artifact.getArtifactId();
                }
                writer.startElement("name");
                writer.writeText(id);
                writer.endElement();
                writer.endElement();
            }
            writer.endElement();
        }
    }

    writer.startElement("unknownLicense");
    for (MavenProject project : setArtifactNoLicense) {
        writer.startElement("dependency");
        String id = project.getModel().getName();
        if (StringUtils.isEmpty(id)) {
            id = project.getArtifactId();
        }
        writer.startElement("name");
        writer.writeText(id);
        writer.endElement();
        writer.endElement();
    }
    writer.endElement();
    writer.endElement();
    return writer;
}

From source file:com.sixdimensions.wcm.cq.pack.PackageMojo.java

License:Open Source License

public void execute() throws MojoExecutionException {
    this.getLog().info("execute");

    final PackageManagerConfig config = new PackageManagerConfig();
    this.initConfig(config);

    this.getLog().info("Connecting to server: " + config.getHost() + ":" + config.getPort());
    this.getLog().info("Connecting with user: " + config.getUser());

    this.getLog().debug("Retrieving service");
    final PackageManagerService packageMgrSvc = PackageManagerService.Factory.getPackageMgr(config);

    String packagePath = this.path;
    if (config.isUseLegacy()) {
        this.getLog().debug("Checking path: " + packagePath + " for compatibility with legacy API");
        final MavenProject project = (MavenProject) this.getPluginContext().get("project");
        if (this.path
                .equals(project.getArtifactId() + "-" + project.getVersion() + "." + project.getPackaging())) {
            this.getLog().debug("Updating path for legacy API");
            packagePath = project.getArtifactId();
        } else {//from  ww w. j  a  va 2  s.co  m
            this.getLog().debug("Custom path specified, not modifying");
        }
    }
    try {
        if (this.deleteFirst) {
            try {
                packageMgrSvc.delete(packagePath);
            } catch (final Exception e) {
                this.getLog().warn("Exception deleting existing package, continuing with installation.", e);
            }
        }
        packageMgrSvc.upload(packagePath, this.packageFile);
        this.getLog().info("Package upload successful");
        if (!this.uploadOnly) {
            packageMgrSvc.install(packagePath);
            this.getLog().info("Package installation successful");
        }
    } catch (final Exception e) {
        this.getLog().error("Exception uploading/installing package.", e);
        throw new MojoExecutionException("Exception uploading/installing package.", e);
    }
    this.getLog().info("Package Upload/Installation Completed Successfully");
}