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

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

Introduction

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

Prototype

public String getId() 

Source Link

Usage

From source file:org.linuxstuff.mojo.licensing.AbstractLicensingMojo.java

/**
 * Build a list of artifacts that this project depends on, but resolves them
 * into {@code MavenProject}s so we can look at their {@code License}
 * information. Honours all the include/exclude parameters above.
 * /* w ww . j a v  a2s.c  o  m*/
 * @return Does not return null, will return an empty set.
 */
protected Collection<MavenProject> getProjectDependencies(MavenProject aProject) {

    getLog().debug("Getting dependencies for project: " + aProject.getId());
    Map<String, MavenProject> dependencies = dependenciesTool.loadProjectDependencies(aProject, this,
            localRepository, remoteRepositories, null);
    getLog().debug("Dependencies found for project: " + dependencies.values().size());
    return dependencies.values();

}

From source file:org.linuxstuff.mojo.licensing.AbstractLicensingMojo.java

/**
 * As long as the {@code MavenProject} is under at least one liked license,
 * then it is liked. This method will also consider licensing specified in
 * licensing requirements; but only if the {@code MavenProject} does not
 * have its own {@code License} block. If no licensing at all is found then
 * it is considered disliked.//w  w  w. ja  v a  2 s.c  o  m
 */
protected boolean isDisliked(MavenProject mavenProject) {

    if (!licensingRequirements.containsDislikedLicenses()) {
        return false;
    }

    if (licensingRequirements.isExemptFromDislike(mavenProject.getId())) {
        return false;
    }

    Set<String> licenses = collectLicensesForMavenProject(mavenProject);

    for (String license : licenses) {

        if (!licensingRequirements.isDislikedLicense(license))
            return false;
    }

    return true;
}

From source file:org.linuxstuff.mojo.licensing.AbstractLicensingMojo.java

protected Set<String> collectLicensesForMavenProject(MavenProject mavenProject) {
    Set<String> licenses = new HashSet<String>();

    /**/*from w  w w . j  av a  2s  . c  o m*/
     * If an artifact declares a license, we will use it <b>instead</b> of
     * anything defined in licensing requirements.
     */
    if (mavenProject.getLicenses() != null && mavenProject.getLicenses().size() > 0) {
        getLog().debug("Licensing: " + mavenProject.getId() + " has licensing information in it.");

        List<License> embeddedLicenses = mavenProject.getLicenses();
        for (License license : embeddedLicenses) {
            if (license.getName() != null) {
                licenses.add(licensingRequirements.getCorrectLicenseName(license.getName()));
            }
        }

    } else {
        Set<String> hardcodedLicenses = licensingRequirements.getLicenseNames(mavenProject.getId());
        for (String license : hardcodedLicenses) {
            licenses.add(licensingRequirements.getCorrectLicenseName(license));
        }
    }

    return licenses;

}

From source file:org.linuxstuff.mojo.licensing.CheckMojo.java

protected LicensingReport generateReport(MavenProject project) {

    LicensingReport aReport = new LicensingReport();

    Collection<MavenProject> projects = getProjectDependencies(project);
    for (MavenProject mavenProject : projects) {

        ArtifactWithLicenses entry = new ArtifactWithLicenses();

        entry.setArtifactId(mavenProject.getId());
        entry.setName(mavenProject.getName());

        Set<String> licenses = collectLicensesForMavenProject(mavenProject);

        if (licenses.isEmpty()) {
            getLog().warn("Licensing: The artifact " + mavenProject.getId() + " has no license specified.");
            aReport.addMissingLicense(entry);
        } else {/*from  w  w  w  . j av  a2 s. c o  m*/
            for (String license : licenses) {
                entry.addLicense(license);
            }

            if (isDisliked(mavenProject)) {
                getLog().warn("Licensing: The artifact " + mavenProject.getId()
                        + " is only under a disliked license.");
                aReport.addDislikedArtifact(entry);
            } else {
                aReport.addLicensedArtifact(entry);
            }

        }

    }

    return aReport;
}

From source file:org.mobicents.maven.plugin.EclipseMojo.java

License:Open Source License

/**
 * Collects all projects from all POMs within the current project.
 *
 * @return all applicable Maven project instances.
 *
 * @throws MojoExecutionException//from  w  ww.j  av  a2  s . c  om
 */
private List collectProjects() throws Exception {
    if (projects.isEmpty()) {
        final List poms = this.getPoms();
        for (ListIterator iterator = poms.listIterator(); iterator.hasNext();) {
            final File pom = (File) iterator.next();
            try {
                // - first attempt to get the existing project from the session
                final MavenProject project = ProjectUtils.getProject(this.projectBuilder, this.session, pom,
                        this.getLog());
                if (project != null) {
                    this.getLog().info("found project " + project.getId());
                    projects.add(project);
                } else {
                    if (this.getLog().isWarnEnabled()) {
                        this.getLog().warn("Could not load project from pom: " + pom + " - ignoring");
                    }
                }
            } catch (ProjectBuildingException exception) {
                throw new MojoExecutionException("Error loading " + pom, exception);
            }
        }
    }
    return projects;
}

From source file:org.nuxeo.extractor.ExtractorMojo.java

License:Apache License

protected static boolean isStandaloneProject(MavenProject project) {
    return project.getId().startsWith("org.apache.maven:standalone-pom:");
}

From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java

License:Apache License

private void processModules(Archiver archiver, List moduleSets, boolean includeBaseDirectory)
        throws MojoFailureException, MojoExecutionException {
    for (Iterator i = moduleSets.iterator(); i.hasNext();) {
        ModuleSet moduleSet = (ModuleSet) i.next();

        AndArtifactFilter filter = new AndArtifactFilter();

        if (!moduleSet.getIncludes().isEmpty()) {
            filter.add(new AssemblyIncludesArtifactFilter(moduleSet.getIncludes()));
        }//w  w  w.  j av  a  2s  .  c  om
        if (!moduleSet.getExcludes().isEmpty()) {
            filter.add(new AssemblyExcludesArtifactFilter(moduleSet.getExcludes()));
        }

        Set set = getModulesFromReactor(getExecutedProject());

        List moduleFileSets = new ArrayList();

        for (Iterator j = set.iterator(); j.hasNext();) {
            MavenProject moduleProject = (MavenProject) j.next();

            if (filter.include(moduleProject.getArtifact())) {
                String name = moduleProject.getBuild().getFinalName();

                ModuleSources sources = moduleSet.getSources();

                if (sources != null) {
                    String output = sources.getOutputDirectory();
                    output = getOutputDirectory(output, moduleProject, includeBaseDirectory);

                    FileSet moduleFileSet = new FileSet();

                    moduleFileSet.setDirectory(moduleProject.getBasedir().getAbsolutePath());
                    moduleFileSet.setOutputDirectory(output);

                    List excludesList = new ArrayList();
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getOutputDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getBuild().getTestOutputDirectory()) + "/**");
                    excludesList.add(PathUtils.toRelative(moduleProject.getBasedir(),
                            moduleProject.getReporting().getOutputDirectory()) + "/**");
                    moduleFileSet.setExcludes(excludesList);

                    moduleFileSets.add(moduleFileSet);
                }

                ModuleBinaries binaries = moduleSet.getBinaries();

                if (binaries != null) {
                    Artifact artifact = moduleProject.getArtifact();

                    if (artifact.getFile() == null) {
                        throw new MojoExecutionException("Included module: " + moduleProject.getId()
                                + " does not have an artifact with a file. Please ensure the package phase is run before the assembly is generated.");
                    }

                    String output = binaries.getOutputDirectory();
                    output = getOutputDirectory(output, moduleProject, includeBaseDirectory);

                    archiver.setDefaultDirectoryMode(Integer.parseInt(binaries.getDirectoryMode(), 8));

                    archiver.setDefaultFileMode(Integer.parseInt(binaries.getFileMode(), 8));

                    getLog().debug("ModuleSet[" + output + "]" + " dir perms: "
                            + Integer.toString(archiver.getDefaultDirectoryMode(), 8) + " file perms: "
                            + Integer.toString(archiver.getDefaultFileMode(), 8));

                    if (binaries.isUnpack()) {
                        // TODO: something like zipfileset in plexus-archiver
                        //                        archiver.addJar(  )

                        // TODO refactor into the AbstractUnpackMojo
                        File tempLocation = new File(workDirectory, name);
                        boolean process = false;
                        if (!tempLocation.exists()) {
                            tempLocation.mkdirs();
                            process = true;
                        } else if (artifact.getFile().lastModified() > tempLocation.lastModified()) {
                            process = true;
                        }

                        if (process) {
                            try {
                                unpack(artifact.getFile(), tempLocation);

                                if (binaries.isIncludeDependencies()) {
                                    Set artifactSet = moduleProject.getArtifacts();

                                    for (Iterator artifacts = artifactSet.iterator(); artifacts.hasNext();) {
                                        Artifact dependencyArtifact = (Artifact) artifacts.next();

                                        unpack(dependencyArtifact.getFile(), tempLocation);
                                    }
                                }
                            } catch (NoSuchArchiverException e) {
                                throw new MojoExecutionException(
                                        "Unable to obtain unarchiver: " + e.getMessage(), e);
                            }

                            /*
                            * If the assembly is 'jar-with-dependencies', remove the security files in all dependencies
                            * that will prevent the uberjar to execute.  Please see MASSEMBLY-64 for details.
                            */
                            if (archiver instanceof JarArchiver) {
                                String[] securityFiles = { "*.RSA", "*.DSA", "*.SF", "*.rsa", "*.dsa", "*.sf" };
                                org.apache.maven.shared.model.fileset.FileSet securityFileSet = new org.apache.maven.shared.model.fileset.FileSet();
                                securityFileSet.setDirectory(tempLocation.getAbsolutePath() + "/META-INF/");

                                for (int sfsi = 0; sfsi < securityFiles.length; sfsi++) {
                                    securityFileSet.addInclude(securityFiles[sfsi]);
                                }

                                FileSetManager fsm = new FileSetManager(getLog());
                                try {
                                    fsm.delete(securityFileSet);
                                } catch (IOException e) {
                                    throw new MojoExecutionException(
                                            "Failed to delete security files: " + e.getMessage(), e);
                                }
                            }
                        }

                        addDirectory(archiver, tempLocation, output, null,
                                FileUtils.getDefaultExcludesAsList());
                    } else {
                        try {
                            String outputFileNameMapping = binaries.getOutputFileNameMapping();

                            archiver.addFile(artifact.getFile(),
                                    output + evaluateFileNameMapping(artifact, outputFileNameMapping));

                            if (binaries.isIncludeDependencies()) {
                                Set artifactSet = moduleProject.getArtifacts();

                                for (Iterator artifacts = artifactSet.iterator(); artifacts.hasNext();) {
                                    Artifact dependencyArtifact = (Artifact) artifacts.next();

                                    archiver.addFile(dependencyArtifact.getFile(),
                                            output + evaluateFileNameMapping(dependencyArtifact,
                                                    outputFileNameMapping));
                                }
                            }
                        } catch (ArchiverException e) {
                            throw new MojoExecutionException("Error adding file to archive: " + e.getMessage(),
                                    e);
                        }
                    }
                }

            } else {
                // would be better to have a way to find out when a specified include or exclude
                // is never triggered and warn() it.
                getLog().debug("module: " + moduleProject.getId() + " not included");
            }

            if (!moduleFileSets.isEmpty()) {
                // TODO: includes and excludes
                processFileSets(archiver, moduleFileSets, includeBaseDirectory);
            }
        }
    }
}

From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java

License:Apache License

private Set getModulesFromReactor(MavenProject parent, boolean recurse) {
    Set modules = new HashSet();

    String parentId = parent.getId();

    for (Iterator i = reactorProjects.iterator(); i.hasNext();) {
        MavenProject reactorProject = (MavenProject) i.next();

        if (isProjectModule(parentId, reactorProject, recurse)) {
            modules.add(reactorProject);
        }//w  w w. j a va 2  s .com
    }

    return modules;
}

From source file:org.opennms.maven.plugins.tgz.AbstractAssemblyMojo.java

License:Apache License

private boolean isProjectModule(String parentId, MavenProject reactorProject, boolean recurse) {
    MavenProject parent = reactorProject.getParent();

    if (parent != null) {
        if (parent.getId().equals(parentId)) {
            return true;
        } else if (recurse) {
            isProjectModule(parentId, parent, true);
        }//from  w w w. ja v a  2s  .c o  m
    }

    return false;
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Analyze bundle project and determine if any pax-create-bundle or pax-wrap-jar calls are needed
 * /* w  w w  . j  av  a  2  s .  c  o m*/
 * @param script build script
 * @param project Maven bundle project
 * @throws MojoExecutionException
 */
private void handleBundleProject(PaxScript script, MavenProject project) throws MojoExecutionException {
    PaxCommandBuilder command;
    String bundleName;

    String namespace = findBundleNamespace(project);
    if (null != namespace) {
        bundleName = project.getArtifactId();

        command = script.call(PaxScript.CREATE_BUNDLE);
        command.option('p', namespace);
        if (!bundleName.equals(namespace)) {
            command.option('n', bundleName);
        }
        command.option('v', project.getVersion());
        command.maven().flag("noDeps");
    } else {
        Dependency wrappee = findWrappee(project);
        if (wrappee != null) {
            command = script.call(PaxScript.WRAP_JAR);
            command.option('g', wrappee.getGroupId());
            command.option('a', wrappee.getArtifactId());
            command.option('v', wrappee.getVersion());

            if (repair) {
                // this is expected to be the generated bundle name
                bundleName = PomUtils.getCompoundId(wrappee.getGroupId(), wrappee.getArtifactId());

                // detect if we need to add the version back later on...
                if (project.getArtifactId().endsWith(wrappee.getVersion())) {
                    command.maven().flag("addVersion");
                }
            } else {
                bundleName = project.getArtifactId();

                // need to retain the old name and version settings
                command.maven().option("bundleName", bundleName);
                command.maven().option("bundleVersion", project.getVersion());
            }
        } else {
            getLog().warn("Unable to clone bundle project " + project.getId());
            return;
        }
    }

    Pom customizedPom = null;

    if (repair) {
        // fix references to local bundles by re-importing
        customizedPom = repairBundleImports(script, project);
    } else {
        // need to keep old groupId intact (name is already retained)
        command.maven().option("bundleGroupId", project.getGroupId());
    }

    addFragmentToCommand(command, createBundleArchetype(project, namespace, customizedPom));

    setTargetDirectory(command, project.getBasedir().getParentFile());
    registerProject(project);

    registerBundleName(project, bundleName);
}