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

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

Introduction

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

Prototype

public String getGroupId() 

Source Link

Usage

From source file:com.cloudbees.maven.license.ProcessMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    if (disableCheck)
        return;// ww w  .ja  v a2  s.c o  m

    GroovyShell shell = createShell(LicenseScript.class);

    List<LicenseScript> comp = parseScripts(script, shell);

    if (generateLicenseHtml != null && generateLicenseXml == null) {// we need XML to be able to generate HTML
        try {
            generateLicenseXml = File.createTempFile("license", "xml");
            generateLicenseXml.deleteOnExit();
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to generate a temporary file", e);
        }
    }

    if (generateLicenseXml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("xmlgen.groovy"), "xmlgen.groovy"));

    if (generateLicenseHtml != null)
        comp.add((LicenseScript) shell.parse(getClass().getResourceAsStream("htmlgen.groovy"),
                "htmlgen.groovy"));

    if (inlineScript != null)
        comp.add((LicenseScript) shell.parse(inlineScript, "inlineScript"));

    for (LicenseScript s : comp) {
        s.project = project;
        s.mojo = this;
        s.run(); // setup
    }

    List<MavenProject> dependencies = new ArrayList<MavenProject>();

    // run against the project itself
    for (LicenseScript s : comp) {
        s.runCompleter(new CompleterDelegate(project, project));
    }
    dependencies.add(project);

    try {
        Map<Artifact, MavenProject> models = new HashMap<Artifact, MavenProject>();

        for (Artifact a : (Set<Artifact>) project.getArtifacts()) {
            Artifact pom = artifactFactory.createProjectArtifact(a.getGroupId(), a.getArtifactId(),
                    a.getVersion());
            MavenProject model = projectBuilder.buildFromRepository(pom,
                    project.getRemoteArtifactRepositories(), localRepository);
            models.put(a, model);
        }

        // filter them out
        for (LicenseScript s : comp) {
            s.runFilter(new FilterDelegate(models));
        }

        // filter out optional components
        for (Iterator<Entry<Artifact, MavenProject>> itr = models.entrySet().iterator(); itr.hasNext();) {
            Entry<Artifact, MavenProject> e = itr.next();
            if (e.getKey().isOptional())
                itr.remove();
        }

        for (MavenProject e : models.values()) {
            // let the completion script intercept and process the licenses
            for (LicenseScript s : comp) {
                s.runCompleter(new CompleterDelegate(e, project));
            }
        }

        dependencies.addAll(models.values());
    } catch (ProjectBuildingException e) {
        throw new MojoExecutionException("Failed to parse into dependencies", e);
    }

    if (requireCompleteLicenseInfo) {
        List<MavenProject> missing = new ArrayList<MavenProject>();
        for (MavenProject d : dependencies) {
            if (d.getLicenses().isEmpty())
                missing.add(d);
        }
        if (!missing.isEmpty()) {
            StringBuilder buf = new StringBuilder(
                    "The following dependencies are missing license information:\n");
            for (MavenProject p : missing) {
                buf.append("  " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                for (p = p.getParent(); p != null; p = p.getParent())
                    buf.append(" -> " + p.getGroupId() + ':' + p.getArtifactId() + ':' + p.getVersion());
                buf.append('\n');
            }
            buf.append(
                    "\nAdd/update your completion script to fill them, or run with -Dlicense.disableCheck to bypass the check.");
            throw new MojoExecutionException(buf.toString());
        }
    }

    for (LicenseScript s : comp) {
        s.runGenerator(new GeneratorDelegate(dependencies));
    }

    if (attach) {
        if (generateLicenseXml != null)
            projectHelper.attachArtifact(project, "license.xml", null, generateLicenseXml);
        if (generateLicenseHtml != null)
            projectHelper.attachArtifact(project, "license.html", null, generateLicenseHtml);
    }
}

From source file:com.edugility.liquibase.maven.AssembleChangeLogMojo.java

License:Open Source License

/**
 * Returns a {@link Collection} of {@link URL}s representing the
 * locations of the given {@link Artifact}.
 *
 * <p>This method never returns {@code null}.</p>
 *
 * <h4>Design Notes</h4>// ww  w  . ja  va 2s. com
 *
 * <p>This method returns a {@link Collection} of {@link URL}s
 * instead of a single {@link URL} because an {@link Artifact}
 * representing the {@linkplain #getProject() current project being
 * built} has two conceptual locations for our purposes: the test
 * output directory and the build output directory.  All other
 * {@link Artifact}s have exactly one location, <em>viz.</em> {@link
 * Artifact#getFile()}.</p>
 *
 * @param artifact the {@link Artifact} for which {@link URL}s
 * should be returned; may be {@code null} in which case an
 * {@linkplain Collection#emptySet() empty <code>Collection</code>}
 * will be returned
 *
 * @return a {@link Collection} of {@link URL}s; never {@code null}
 *
 * @exception MalformedURLException if an {@link Artifact}'s
 * {@linkplain Artifact#getFile() associated <code>File</code>}
 * could not be {@linkplain URI#toURL() converted into a
 * <code>URL</code>}
 *
 * @see Artifact#getFile()
 *
 * @see Build#getTestOutputDirectory()
 *
 * @see Build#getOutputDirectory()
 *
 * @see File#toURI()
 *
 * @see URI#toURL()
 */
private final Collection<? extends URL> toURLs(final Artifact artifact) throws MalformedURLException {
    Collection<URL> urls = null;
    if (artifact != null) {

        // If the artifact represents the current project itself, then
        // we need to look in the reactor first (i.e. the
        // project.build.testOutpuDirectory and the
        // project.build.outputDirectory areas), since a .jar file for
        // the project in all likelihood has not yet been created.
        final String groupId = artifact.getGroupId();
        if (groupId != null) {
            final MavenProject project = this.getProject();
            if (project != null && groupId.equals(project.getGroupId())) {
                final String artifactId = artifact.getArtifactId();
                if (artifactId != null && artifactId.equals(project.getArtifactId())) {
                    final Build build = project.getBuild();
                    if (build != null) {
                        urls = new ArrayList<URL>();
                        urls.add(new File(build.getTestOutputDirectory()).toURI().toURL());
                        urls.add(new File(build.getOutputDirectory()).toURI().toURL());
                    }
                }
            }
        }

        // If on the other hand the artifact was just a garden-variety
        // direct or transitive dependency, then just add its file: URL
        // directly.
        if (urls == null) {
            final File file = artifact.getFile();
            if (file != null) {
                final URI uri = file.toURI();
                if (uri != null) {
                    urls = Collections.singleton(uri.toURL());
                }
            }
        }

    }
    if (urls == null) {
        urls = Collections.emptySet();
    }
    return urls;
}

From source file:com.ericsson.tools.cpp.compiler.artifacts.ArtifactManager.java

License:Apache License

public Artifact createProjectArtifact(final MavenProject project) {
    return factory.createProjectArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:com.github.ferstl.maven.pomenforcers.PedanticDependencyManagementLocationEnforcer.java

License:Apache License

private boolean isDependencyManagingProject(MavenProject project) {
    ArtifactModel projectInfo = new ArtifactModel(project.getGroupId(), project.getArtifactId(),
            project.getVersion());/*from   w ww.j  a  v a  2s.  c  om*/
    return this.dependencyManagingPoms.isEmpty() || this.dependencyManagingPoms.contains(projectInfo);

}

From source file:com.github.ferstl.maven.pomenforcers.PedanticPluginManagementLocationEnforcer.java

License:Apache License

private boolean isPluginManagingProject(MavenProject project) {
    ArtifactModel projectInfo = new ArtifactModel(project.getGroupId(), project.getArtifactId(),
            project.getVersion());/*from w w  w  . j  av  a 2 s .  c  o m*/
    return this.pluginManagingPoms.isEmpty() || this.pluginManagingPoms.contains(projectInfo);
}

From source file:com.github.jeluard.maven.ParentEnforcerRule.java

License:Apache License

@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
    final MavenProject project;
    try {/* w w  w . j a  v a 2 s  . com*/
        project = (MavenProject) helper.evaluate("${project}");
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Failed to access ${project} variable", e);
    }

    final String type = project.getArtifact().getType();
    if (!ParentEnforcerRule.POM_ARTIFACT_TYPE.equals(type)) {
        helper.getLog().debug("Skipping non " + ParentEnforcerRule.POM_ARTIFACT_TYPE + " artifact.");

        return;
    }

    final Parent parent = new Parent();
    parent.setGroupId(project.getGroupId());
    parent.setArtifactId(project.getArtifactId());
    parent.setVersion(project.getVersion());
    try {
        validateSubModules(extractRootFolder(project), project.getModel(), parent);
    } catch (IOException e) {
        throw new EnforcerRuleException("Failed to process one of project's module", e);
    }
}

From source file:com.github.jlgrock.javascriptframework.jspreprocessor.processors.FileTimeStamp.java

/**
 * fill this in later...// w w  w .j av a  2  s. com
 * 
 * @param project
 *            asd TODO .
 */
public final void executeFileTimeStamp(final MavenProject project) {
    // TODO add this information to the top of every file
    project.getVersion();
    project.getGroupId();
    project.getArtifactId();
    System.getProperty("java.version");
    System.getProperty("os.name");
    System.getProperty("user.name");
    // getCopyright();
    // getLicense();
}

From source file:com.github.jrh3k5.flume.mojo.plugin.AbstractFlumePluginMojo.java

License:Apache License

/**
 * Format the name of a Maven project.//w  ww  .ja v a 2 s .  c o  m
 * 
 * @param mavenProject
 *            The {@link MavenProject} whose name is to be formatted.
 * @return A formatted identifier of the given {@link MavenProject}.
 */
protected static String formatIdentifier(MavenProject mavenProject) {
    return String.format("%s:%s:%s:%s", mavenProject.getGroupId(), mavenProject.getArtifactId(),
            mavenProject.getVersion(), mavenProject.getPackaging());
}

From source file:com.github.maven_nar.NarLayout20.java

License:Apache License

@Override
public final void prepareNarInfo(final File baseDir, final MavenProject project, final NarInfo narInfo,
        final AbstractNarMojo mojo) throws MojoExecutionException {
    if (getIncludeDirectory(baseDir, project.getArtifactId(), project.getVersion()).exists()) {
        narInfo.setNar(null, "noarch", project.getGroupId() + ":" + project.getArtifactId() + ":"
                + NarConstants.NAR_TYPE + ":" + "noarch");
    }/* w  w w  .j a va 2  s . co m*/

    final String[] binAOL = new File(baseDir, "bin").list();
    for (int i = 0; binAOL != null && i < binAOL.length; i++) {// TODO: chose
                                                               // not to apply
                                                               // new file
                                                               // naming for
                                                               // outfile in
                                                               // case of
                                                               // backwards
                                                               // compatability,
                                                               // may need to
                                                               // reconsider
        narInfo.setNar(null, Library.EXECUTABLE, project.getGroupId() + ":" + project.getArtifactId() + ":"
                + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + Library.EXECUTABLE);
        narInfo.setBinding(new AOL(binAOL[i]), Library.EXECUTABLE);
        narInfo.setBinding(null, Library.EXECUTABLE);
    }

    final File libDir = new File(baseDir, "lib");
    final String[] libAOL = libDir.list();
    for (int i = 0; libAOL != null && i < libAOL.length; i++) {
        String bindingType = null;
        final String[] libType = new File(libDir, libAOL[i]).list();
        for (int j = 0; libType != null && j < libType.length; j++) {
            narInfo.setNar(null, libType[j], project.getGroupId() + ":" + project.getArtifactId() + ":"
                    + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + libType[j]);

            // set if not set or override if SHARED
            if (bindingType == null || libType[j].equals(Library.SHARED)) {
                bindingType = libType[j];
            }
        }

        final AOL aol = new AOL(libAOL[i]);
        if (narInfo.getBinding(aol, null) == null) {
            narInfo.setBinding(aol, bindingType != null ? bindingType : Library.NONE);
        }
        if (narInfo.getBinding(null, null) == null) {
            narInfo.setBinding(null, bindingType != null ? bindingType : Library.NONE);
        }
    }
}

From source file:com.github.maven_nar.NarLayout21.java

License:Apache License

@Override
public final void prepareNarInfo(final File baseDir, final MavenProject project, final NarInfo narInfo,
        final AbstractNarMojo mojo) throws MojoExecutionException {
    if (getNoArchDirectory(baseDir, project.getArtifactId(), project.getVersion()).exists()) {
        narInfo.setNar(null, NarConstants.NAR_NO_ARCH, project.getGroupId() + ":" + project.getArtifactId()
                + ":" + NarConstants.NAR_TYPE + ":" + NarConstants.NAR_NO_ARCH);
    }//from   ww w.  j ava  2 s  .  c o  m

    final String artifactIdVersion = project.getArtifactId() + "-" + project.getVersion();
    // list all directories in basedir, scan them for classifiers
    final String[] subDirs = baseDir.list();
    final ArrayList<String> classifiers = new ArrayList<String>();
    for (int i = 0; subDirs != null && i < subDirs.length; i++) {
        // skip entries not belonging to this project
        if (!subDirs[i].startsWith(artifactIdVersion)) {
            continue;
        }

        final String classifier = subDirs[i].substring(artifactIdVersion.length() + 1);

        // skip noarch here
        if (classifier.equals(NarConstants.NAR_NO_ARCH)) {
            continue;
        }

        classifiers.add(classifier);
    }

    if (!classifiers.isEmpty()) {

        for (final String classifier : classifiers) {
            final int lastDash = classifier.lastIndexOf('-');
            final String type = classifier.substring(lastDash + 1);
            final AOL aol = new AOL(classifier.substring(0, lastDash));

            if (narInfo.getOutput(aol, null) == null) {
                narInfo.setOutput(aol, mojo.getOutput(!Library.EXECUTABLE.equals(type)));
            }

            // We prefer shared to jni/executable/static/none,
            if (type.equals(Library.SHARED)) // overwrite whatever we had
            {
                narInfo.setBinding(aol, type);
                narInfo.setBinding(null, type);
            } else {
                // if the binding is already set, then don't write it for
                // jni/executable/static/none.
                if (narInfo.getBinding(aol, null) == null) {
                    narInfo.setBinding(aol, type);
                }
                if (narInfo.getBinding(null, null) == null) {
                    narInfo.setBinding(null, type);
                }
            }

            narInfo.setNar(null, type, project.getGroupId() + ":" + project.getArtifactId() + ":"
                    + NarConstants.NAR_TYPE + ":" + "${aol}" + "-" + type);

        }

        // setting this first stops the per type config because getOutput check
        // for aol defaults to this generic one...
        if (mojo != null && narInfo.getOutput(null, null) == null) {
            narInfo.setOutput(null, mojo.getOutput(true));
        }
    }
}