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.greenpepper.maven.runner.resolver.FileResolver.java

License:Open Source License

/** {@inheritDoc} */
public final File resolve(String value) throws ProjectBuildingException {
    File projectFile = new File(value);
    MavenProject mavenProject = embedder.readProject(projectFile);
    mavenGAV = new ProjectFileResolver.MavenGAV(mavenProject.getGroupId(), mavenProject.getArtifactId(),
            mavenProject.getVersion());//  w ww  . j a  va  2 s  . c o  m
    mavenGAV.setPackaging(mavenProject.getPackaging());
    return projectFile;
}

From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java

License:Apache License

private Collection<String> createManifest() {
    MavenProject project = getProject();

    return Arrays.asList("#appname: " + getEscapedName(), "#publisher: " + getPublisher(project),
            "#url: " + getUrl(project), "#image: " + getIcon(),
            "#appid: " + project.getGroupId() + '.' + project.getArtifactId(),
            "#desc: " + project.getDescription(), "#type: desktop", "#guid: " + UUID.randomUUID(),
            "runtime:" + getSdkVersion(), "app:" + getSdkVersion(), "codec:" + getSdkVersion(),
            "database:" + getSdkVersion(), "filesystem:" + getSdkVersion(), "media:" + getSdkVersion(),
            "monkey:" + getSdkVersion(), "network:" + getSdkVersion(), "platform:" + getSdkVersion(),
            "process:" + getSdkVersion(), "ui:" + getSdkVersion(), "worker:" + getSdkVersion());
}

From source file:com.groupcdg.maven.tidesdk.GenerateMojo.java

License:Apache License

private Collection<String> createXml() {
    return new ArrayList<String>() {
        {// ww  w . j a v  a  2s  .c o  m
            add("<?xml version='1.0' encoding='UTF-8'?>");
            add("<ti:app xmlns:ti='http://ti.appcelerator.org'>");

            MavenProject project = getProject();
            add("<id>" + project.getGroupId() + '.' + project.getArtifactId() + "</id>");
            add("<name>" + getName() + "</name>");
            add("<version>" + project.getVersion() + "</version>");

            String publisher = getPublisher(project);
            if (publisher != null) {
                add("<publisher>" + publisher + "</publisher>");
                add("<copyright>" + Calendar.getInstance().get(Calendar.YEAR) + " " + publisher
                        + "</copyright>");
            }
            String url = getUrl(project);
            if (url != null)
                add("<url>" + url + "</url>");

            String icon = getIcon();
            if (icon != null)
                add("<icon>" + icon + "</icon>");
            addAll(getDisplay().createXml(getName(), getIndex()));

            add("</ti:app>");
        }
    };
}

From source file:com.helger.maven.buildinfo.GenerateBuildInfoMojo.java

License:Apache License

private Map<String, String> _determineBuildInfoProperties() {
    // Get the current time, using the time zone specified in the settings
    final DateTime aDT = PDTFactory.getCurrentDateTime();

    // Build the default properties
    final Map<String, String> aProps = new LinkedHashMap<String, String>();
    // Version 1: initial
    // Version 2: added dependency information; added per build plugin the key
    // property//from  w  ww .jav  a2s  .c om
    aProps.put("buildinfo.version", "2");

    // Project information
    aProps.put("project.groupid", project.getGroupId());
    aProps.put("project.artifactid", project.getArtifactId());
    aProps.put("project.version", project.getVersion());
    aProps.put("project.name", project.getName());
    aProps.put("project.packaging", project.getPackaging());

    // Parent project information (if available)
    final MavenProject aParentProject = project.getParent();
    if (aParentProject != null) {
        aProps.put("parentproject.groupid", aParentProject.getGroupId());
        aProps.put("parentproject.artifactid", aParentProject.getArtifactId());
        aProps.put("parentproject.version", aParentProject.getVersion());
        aProps.put("parentproject.name", aParentProject.getName());
    }

    // All reactor projects (nested projects)
    // Don't emit this, if this is "1" as than only the current project would be
    // listed
    if (reactorProjects != null && reactorProjects.size() != 1) {
        final String sPrefix = "reactorproject.";

        // The number of reactor projects
        aProps.put(sPrefix + "count", Integer.toString(reactorProjects.size()));

        // Show details of all reactor projects, index starting at 0
        int nIndex = 0;
        for (final MavenProject aReactorProject : reactorProjects) {
            aProps.put(sPrefix + nIndex + ".groupid", aReactorProject.getGroupId());
            aProps.put(sPrefix + nIndex + ".artifactid", aReactorProject.getArtifactId());
            aProps.put(sPrefix + nIndex + ".version", aReactorProject.getVersion());
            aProps.put(sPrefix + nIndex + ".name", aReactorProject.getName());
            ++nIndex;
        }
    }

    // Build Plugins
    final List<?> aBuildPlugins = project.getBuildPlugins();
    if (aBuildPlugins != null) {
        final String sPrefix = "build.plugin.";
        // The number of build plugins
        aProps.put(sPrefix + "count", Integer.toString(aBuildPlugins.size()));

        // Show details of all plugins, index starting at 0
        int nIndex = 0;
        for (final Object aObj : aBuildPlugins) {
            final Plugin aPlugin = (Plugin) aObj;
            aProps.put(sPrefix + nIndex + ".groupid", aPlugin.getGroupId());
            aProps.put(sPrefix + nIndex + ".artifactid", aPlugin.getArtifactId());
            aProps.put(sPrefix + nIndex + ".version", aPlugin.getVersion());
            final Object aConfiguration = aPlugin.getConfiguration();
            if (aConfiguration != null) {
                // Will emit an XML structure!
                aProps.put(sPrefix + nIndex + ".configuration", aConfiguration.toString());
            }
            aProps.put(sPrefix + nIndex + ".key", aPlugin.getKey());
            ++nIndex;
        }
    }

    // Build dependencies
    final List<?> aDependencies = project.getDependencies();
    if (aDependencies != null) {
        final String sDepPrefix = "dependency.";
        // The number of build plugins
        aProps.put(sDepPrefix + "count", Integer.toString(aDependencies.size()));

        // Show details of all dependencies, index starting at 0
        int nDepIndex = 0;
        for (final Object aDepObj : aDependencies) {
            final Dependency aDependency = (Dependency) aDepObj;
            aProps.put(sDepPrefix + nDepIndex + ".groupid", aDependency.getGroupId());
            aProps.put(sDepPrefix + nDepIndex + ".artifactid", aDependency.getArtifactId());
            aProps.put(sDepPrefix + nDepIndex + ".version", aDependency.getVersion());
            aProps.put(sDepPrefix + nDepIndex + ".type", aDependency.getType());
            if (aDependency.getClassifier() != null)
                aProps.put(sDepPrefix + nDepIndex + ".classifier", aDependency.getClassifier());
            aProps.put(sDepPrefix + nDepIndex + ".scope", aDependency.getScope());
            if (aDependency.getSystemPath() != null)
                aProps.put(sDepPrefix + nDepIndex + ".systempath", aDependency.getSystemPath());
            aProps.put(sDepPrefix + nDepIndex + ".optional", Boolean.toString(aDependency.isOptional()));
            aProps.put(sDepPrefix + nDepIndex + ".managementkey", aDependency.getManagementKey());

            // Add all exclusions of the current dependency
            final List<?> aExclusions = aDependency.getExclusions();
            if (aExclusions != null) {
                final String sExclusionPrefix = sDepPrefix + nDepIndex + ".exclusion.";
                // The number of build plugins
                aProps.put(sExclusionPrefix + "count", Integer.toString(aExclusions.size()));

                // Show details of all dependencies, index starting at 0
                int nExclusionIndex = 0;
                for (final Object aExclusionObj : aExclusions) {
                    final Exclusion aExclusion = (Exclusion) aExclusionObj;
                    aProps.put(sExclusionPrefix + nExclusionIndex + ".groupid", aExclusion.getGroupId());
                    aProps.put(sExclusionPrefix + nExclusionIndex + ".artifactid", aExclusion.getArtifactId());
                    ++nExclusionIndex;
                }
            }

            ++nDepIndex;
        }
    }

    // Build date and time
    aProps.put("build.datetime", aDT.toString());
    aProps.put("build.datetime.millis", Long.toString(aDT.getMillis()));
    aProps.put("build.datetime.date", aDT.toLocalDate().toString());
    aProps.put("build.datetime.time", aDT.toLocalTime().toString());
    aProps.put("build.datetime.timezone", aDT.getZone().getID());
    final int nOfsMilliSecs = aDT.getZone().getOffset(aDT);
    aProps.put("build.datetime.timezone.offsethours",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_HOUR));
    aProps.put("build.datetime.timezone.offsetmins",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_MINUTE));
    aProps.put("build.datetime.timezone.offsetsecs",
            Long.toString(nOfsMilliSecs / CGlobal.MILLISECONDS_PER_SECOND));
    aProps.put("build.datetime.timezone.offsetmillisecs", Integer.toString(nOfsMilliSecs));

    // Emit system properties?
    if (withAllSystemProperties || CollectionHelper.isNotEmpty(selectedSystemProperties))
        for (final Map.Entry<String, String> aEntry : CollectionHelper
                .getSortedByKey(SystemProperties.getAllProperties()).entrySet()) {
            final String sName = aEntry.getKey();
            if (withAllSystemProperties || _matches(selectedSystemProperties, sName))
                if (!_matches(ignoredSystemProperties, sName))
                    aProps.put("systemproperty." + sName, aEntry.getValue());
        }

    // Emit environment variable?
    if (withAllEnvVars || CollectionHelper.isNotEmpty(selectedEnvVars))
        for (final Map.Entry<String, String> aEntry : CollectionHelper.getSortedByKey(System.getenv())
                .entrySet()) {
            final String sName = aEntry.getKey();
            if (withAllEnvVars || _matches(selectedEnvVars, sName))
                if (!_matches(ignoredEnvVars, sName))
                    aProps.put("envvar." + sName, aEntry.getValue());
        }

    return aProps;
}

From source file:com.kamomileware.maven.plugin.opencms.packaging.ClassesPackagingTask.java

License:Apache License

protected void generateJarArchive(ModulePackagingContext context) throws MojoExecutionException {
    MavenProject project = context.getProject();
    ArtifactFactory factory = context.getArtifactFactory();
    Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(),
            project.getVersion(), "jar");
    String archiveName = null;//from  w w w.  jav a2 s . c  o m
    try {
        archiveName = getArtifactFinalName(context, artifact);
    } catch (InterpolationException e) {
        throw new MojoExecutionException("Could not get the final name of the artifact[" + artifact.getGroupId()
                + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e);
    }
    final String targetFilename = LIB_PATH + archiveName;

    if (context.getModuleStructure().registerFile("currentBuild", targetFilename)) {
        File base = context.getModuleSourceTargetDirectory() == null ? context.getModuleDirectory()
                : new File(context.getModuleDirectory(), context.getModuleSourceTargetDirectory());

        final File libDirectory = new File(base, LIB_PATH);
        final File jarFile = new File(libDirectory, archiveName);
        final ClassesPackager packager = new ClassesPackager();
        packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), project,
                context.getArchive());

    } else {
        context.getLog().warn(
                "Could not generate archive classes file[" + targetFilename + "] has already been copied.");
    }
}

From source file:com.mcleodmoores.mvn.natives.PackageMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().debug("Skipping step");
        return;//from  w  w w .  j  a v a2s.  c  om
    }
    applyDefaults();
    final MavenProject project = (MavenProject) getPluginContext().get("project");
    final File targetDir = new File(project.getBuild().getDirectory());
    targetDir.mkdirs();
    final File targetFile = new File(targetDir, project.getArtifactId() + ".zip");
    getLog().debug("Writing to " + targetFile);
    final OutputStream output;
    try {
        output = getOutputStreams().open(targetFile);
    } catch (final IOException e) {
        throw new MojoFailureException("Can't write to " + targetFile);
    }
    final IOExceptionHandler errorLog = new MojoLoggingErrorCallback(this);
    if ((new IOCallback<OutputStream, Boolean>(output) {

        @Override
        protected Boolean apply(final OutputStream output) throws IOException {
            final byte[] buffer = new byte[4096];
            final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(output));
            for (final Map.Entry<Source, String> sourceInfo : gatherSources().entrySet()) {
                final Source source = sourceInfo.getKey();
                getLog().info("Processing " + source.getPath() + " into " + sourceInfo.getValue() + " ("
                        + source.getPattern() + ")");
                final File folder = new File(source.getPath());
                final String[] files = folder.list(new PatternFilenameFilter(regex(source.getPattern())));
                if (files != null) {
                    for (final String file : files) {
                        getLog().debug("Adding " + file + " to archive");
                        final ZipEntry entry = new ZipEntry(sourceInfo.getValue() + file);
                        zip.putNextEntry(entry);
                        if ((new IOCallback<InputStream, Boolean>(
                                getInputStreams().open(new File(folder, file))) {

                            @Override
                            protected Boolean apply(final InputStream input) throws IOException {
                                int bytes;
                                while ((bytes = input.read(buffer, 0, buffer.length)) > 0) {
                                    zip.write(buffer, 0, bytes);
                                }
                                return Boolean.TRUE;
                            }

                        }).call(errorLog) != Boolean.TRUE) {
                            return Boolean.FALSE;
                        }
                        zip.closeEntry();
                    }
                } else {
                    getLog().debug("Source folder is empty or does not exist");
                }
            }
            zip.close();
            return Boolean.TRUE;
        }

    }).call(errorLog) != Boolean.TRUE) {
        throw new MojoFailureException("Error writing to " + targetFile);
    }
    project.getArtifact().setFile(targetFile);
}

From source file:com.monday_consulting.maven.plugins.fsm.DependencyToXMLMojo.java

License:Apache License

/**
 * Log Projects and their resolved dependencies via MavenProject.getArtifacts().
 *
 * @param reactorProjects MavenProjects in the current reactor
 *//*from  w w w  .ja va2s .c o  m*/
private void checkReactor(final List<MavenProject> reactorProjects) {
    for (final MavenProject reactorProject : reactorProjects) {
        final String msg = "Check resolved Artifacts for: " + "\ngroudId:    " + reactorProject.getGroupId()
                + "\nartifactId: " + reactorProject.getArtifactId() + "\nversion:    "
                + reactorProject.getVersion();
        if (getLog().isDebugEnabled())
            getLog().debug(msg);

        if (reactorProject.getArtifacts() == null || reactorProject.getArtifacts().isEmpty()) {
            if (getLog().isDebugEnabled())
                getLog().debug("+  Dependencies not resolved or Reactor-Project has no dependencies!");
        } else {
            for (final Artifact artifact : reactorProject.getArtifacts()) {
                if (getLog().isDebugEnabled())
                    getLog().debug("  + " + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : "
                            + artifact.getVersion() + " : " + artifact.getType() + " : " + artifact.getFile());
            }
        }
    }
}

From source file:com.monday_consulting.maven.plugins.fsm.util.resolver.MavenGetArtifactsResolver.java

License:Apache License

private MavenProject getMavenProjectViaReactor(final Module module) {
    MavenProject mProject = null;/*from  ww  w. j a v  a  2s  . c om*/
    boolean moduleInReactor = false;

    for (final MavenProject prj : reactorProjects) {
        if ((prj.getArtifactId().equals(module.getArtifactId()))
                && (prj.getGroupId().equals(module.getGroupId()))) {
            if (moduleInReactor) {
                log.error("module " + module.getGroupId() + ":" + module.getArtifactId()
                        + " found twice in reactor!");
            } else {
                log.info("module " + module.getGroupId() + ":" + module.getArtifactId() + " found in reactor!");
                moduleInReactor = true;
                mProject = prj;
            }
        }
    }
    if (!moduleInReactor) {
        log.warn("module " + module.getGroupId() + ":" + module.getArtifactId() + " not found in reactor!");
    }

    return mProject;
}

From source file:com.oracle.istack.maven.ImportPropertiesMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException {
    try {/*from   w  ww. ja v a 2s  .c o  m*/
        projectProperties = project.getProperties();

        MavenProject bomProject = project;
        while (bomProject != null && !bomProject.getArtifactId().endsWith("-bom")) {
            bomProject = bomProject.getParent();
        }

        if (bomProject == null || !bomProject.getArtifactId().endsWith("-bom")) {
            getLog().warn(
                    "No '*-bom' project found in project hierarchy, using this project's pom for import search.");
            bomProject = project;
        }

        getLog().warn("Searching project: " + bomProject.getArtifactId());

        PropertyResolver resolver = new PropertyResolver(new CommonLogger(getLog()), projectProperties,
                repoSession, repoSystem, projectRepos);
        resolver.resolveProperties(bomProject);

    } catch (FileNotFoundException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (XmlPullParserException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.oracle.istack.maven.PropertyResolver.java

License:Open Source License

/**
 *
 * @param project maven project/*ww w  . j  ava  2 s .  c  o m*/
 * @throws FileNotFoundException properties not found
 * @throws IOException IO error
 * @throws XmlPullParserException error parsing xml
 */
public void resolveProperties(MavenProject project)
        throws FileNotFoundException, IOException, XmlPullParserException {
    logger.info("Resolving properties for " + project.getGroupId() + ":" + project.getArtifactId());

    Model model = null;
    FileReader reader;
    try {
        reader = new FileReader(project.getFile());
        model = mavenreader.read(reader);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
    }
    MavenProject loadedProject = new MavenProject(model);

    DependencyManagement dm = loadedProject.getDependencyManagement();
    if (dm == null) {
        logger.warn("No dependency management section found in: " + loadedProject.getGroupId() + ":"
                + loadedProject.getArtifactId());
        return;
    }

    List<Dependency> depList = dm.getDependencies();

    DependencyResult result;
    for (Dependency d : depList) {
        if ("import".equals(d.getScope())) {
            try {
                String version = d.getVersion();
                logger.info("Imported via import-scope: " + d.getGroupId() + ":" + d.getArtifactId() + ":"
                        + version);
                if (version.contains("$")) {
                    version = properties
                            .getProperty(version.substring(version.indexOf('{') + 1, version.lastIndexOf('}')));
                    logger.info("Imported version resolved to: " + version);
                }
                d.setVersion(version);
                d.setType("pom");
                d.setClassifier("pom");
                result = DependencyResolver.resolve(d, pluginRepos, repoSystem, repoSession);
                Artifact a = result.getArtifactResults().get(0).getArtifact();
                reader = new FileReader(a.getFile());
                Model m = mavenreader.read(reader);
                MavenProject p = new MavenProject(m);
                p.setFile(a.getFile());
                for (Map.Entry<Object, Object> e : p.getProperties().entrySet()) {
                    logger.info("Setting property: " + (String) e.getKey() + ":" + (String) e.getValue());
                    properties.setProperty((String) e.getKey(), (String) e.getValue());
                }

                resolveProperties(p);
            } catch (DependencyResolutionException ex) {
                Logger.getLogger(ImportPropertiesMojo.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}