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

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

Introduction

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

Prototype

public List<String> getModules() 

Source Link

Usage

From source file:com.ardoq.mavenImport.ProjectSync.java

/**
 * NB! only modules named the same as the artifact will be synced
 * @param project//from ww w  .  ja v  a  2  s  .  co m
 * @param ardoqProjectComponent
 * @param refTypes
 * @throws DependencyCollectionException
 */
private void syncProjectModules(MavenProject project, Component ardoqProjectComponent,
        Map<String, Integer> refTypes) {
    for (String module : project.getModules()) {
        try {
            String groupId = project.getGroupId();
            String artifactId = module;
            String version = project.getVersion();

            String id = groupId + ":" + artifactId + ":" + version;
            String moduleComponentId = syncProject(id);

            if (moduleComponentId != null) {
                int refType = refTypes.get("Module");
                Reference ref = new Reference(ardoqSync.getWorkspace().getId(), "artifact",
                        ardoqProjectComponent.getId(), moduleComponentId, refType);
                ardoqSync.addReference(ref);
            } else {
                System.err.println("Error adding reference from " + ardoqProjectComponent.getId() + " "
                        + moduleComponentId);
            }

        } catch (ArtifactResolutionException e) {
            System.out.println("***************************************************************");
            System.out.println("* Error syncing Maven module " + module + " of " + project.getName());
            System.out.println("* This tool assumes that the module name equals the artifactId. ");
            System.out.println("* -> ignoring and carrying on.. ");
            System.out.println("***************************************************************");
        }
    }
}

From source file:com.atlassian.maven.plugin.clover.internal.AbstractCloverMojo.java

License:Apache License

/**
 * Returns true if the supplied potentialModule project is a module
 * of the specified parentProject.//from   w  w  w.  ja  va2  s. com
 *
 * @param parentProject   the parent project.
 * @param potentialModule the potential moduleproject.
 * @return true if the potentialModule is indeed a module of the specified
 *         parent project.
 */
protected boolean isModuleOfProject(final MavenProject parentProject, final MavenProject potentialModule) {
    boolean result = false;
    final List<String> modules = parentProject.getModules();

    if (modules != null) {
        final File parentBaseDir = parentProject.getBasedir();

        for (final String module : modules) {
            File moduleBaseDir = new File(parentBaseDir, module);

            try {
                // need these to be canonical paths so we can perform a true equality
                // operation and remember <module> is a path and for flat multimodule project
                // structures they will be like this: <module>../a-project<module>
                final String lhs = potentialModule.getBasedir().getCanonicalPath();
                final String rhs = moduleBaseDir.getCanonicalPath();

                if (lhs.equals(rhs)) {
                    getLog().debug("isModuleOfProject: lhs=" + lhs + " rhs=" + rhs + " MATCH FOUND");
                    result = true;
                    break;
                } else {
                    getLog().debug("isModuleOfProject: lhs=" + lhs + " rhs=" + rhs);
                }
            } catch (IOException e) {
                // suppress the exception (?)
                getLog().error("error encountered trying to resolve canonical module paths");
            }
        }
    }

    return result;
}

From source file:com.datacoper.maven.util.DCProjectUtil.java

private static MavenProject validateAndStartModule(MavenProject parentProjetct, String moduleName)
        throws DcRuntimeException {
    if (!parentProjetct.getModules().contains(moduleName)) {
        throw new DcRuntimeException("Module {0} is not located in parent project {0}", moduleName,
                parentProjetct.getName());
    }//from  ww w  .  j ava 2s . com

    String pathParent = parentProjetct.getBasedir().getPath();

    MavenProject mavenProject = MavenUtil.startNewProject(pathParent.concat("/").concat(moduleName));

    return mavenProject;
}

From source file:com.fengjx.maven.cdn.MyAbstractMojo.java

License:Apache License

@SuppressWarnings({ "unchecked" })
private String[] buildExcludes() {
    List<String> ex = new ArrayList<String>();
    ex.addAll(asList(this.excludes));
    MavenProject project = getProject();
    if (project != null && project.getModules() != null) {
        for (String module : (List<String>) project.getModules()) {
            ex.add(module + "/**");
        }//from  w  ww.j  a v a2 s . c  om
    }
    return ex.toArray(new String[ex.size()]);
}

From source file:com.github.ferstl.depgraph.AggregatingGraphFactory.java

License:Apache License

private boolean isPartOfGraph(MavenProject project) {
    boolean result = this.artifactFilter.include(project.getArtifact());
    // Project is not filtered and is a parent project
    if (result && project.getModules().size() > 0) {
        result = result && this.includeParentProjects;
    }/*from ww  w.  j a v a2 s. c o  m*/

    return result;
}

From source file:com.github.ferstl.depgraph.dependency.AggregatingGraphFactory.java

License:Apache License

private boolean isPartOfGraph(MavenProject project) {
    boolean isIncluded = this.globalFilter.include(project.getArtifact());
    // Project is not filtered and is a parent project
    if (isIncluded && project.getModules().size() > 0) {
        return this.includeParentProjects;
    }//from  w w  w .ja  v  a  2  s  .co m

    return isIncluded;
}

From source file:com.github.ferstl.depgraph.graph.AggregatingGraphFactory.java

License:Apache License

private boolean isPartOfGraph(MavenProject project) {
    boolean result = this.globalFilter.include(project.getArtifact());
    // Project is not filtered and is a parent project
    if (result && project.getModules().size() > 0) {
        result = result && this.includeParentProjects;
    }/*  w  ww .  j ava 2  s.c  o m*/

    return result;
}

From source file:fr.brouillard.oss.jgitver.JGitverExtension.java

License:Apache License

@Override
public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionException {
    MavenProject rootProject = mavenSession.getTopLevelProject();
    List<MavenProject> projects = locateProjects(mavenSession, rootProject.getModules());

    Map<GAV, String> newProjectVersions = new LinkedHashMap<>();

    if (JGitverModelProcessor.class.isAssignableFrom(modelProcessor.getClass())) {
        JGitverModelProcessor jGitverModelProcessor = JGitverModelProcessor.class.cast(modelProcessor);
        JGitverModelProcessorWorkingConfiguration workingConfiguration = jGitverModelProcessor
                .getWorkingConfiguration();

        if (workingConfiguration == null) {
            logger.warn("");
            logger.warn("jgitver has changed!");
            logger.warn("");
            logger.warn(/*from   www  .  j  a v a  2 s  .com*/
                    "it now requires the usage of maven core extensions instead of standard plugin extensions.");
            logger.warn("The plugin must be now declared in a `.mvn/extensions.xml` file.");
            logger.warn("");
            logger.warn("    read https://github.com/jgitver/jgitver-maven-plugin for further information");
            logger.warn("");
            throw new MavenExecutionException("detection of jgitver old setting mechanism",
                    new IllegalStateException("jgitver must now use maven core extensions"));
        }

        newProjectVersions = workingConfiguration.getNewProjectVersions();
    } else {
        logger.info("jgitver-maven-plugin is about to change project(s) version(s)");

        String newVersion = null;
        try {
            newVersion = JGitverUtils
                    .calculateVersionForProject(rootProject, mavenSession.getUserProperties(), logger)
                    .getCalculatedVersion();
        } catch (IOException ex) {
            throw new MavenExecutionException("failure calculating version from git information", ex);
        }

        // Let's modify in memory resolved projects model
        for (MavenProject project : projects) {
            GAV projectGAV = GAV.from(project); // SUPPRESS CHECKSTYLE AbbreviationAsWordInName

            logger.debug("about to change in memory POM for: " + projectGAV);
            // First the project itself
            project.setVersion(newVersion);
            logger.debug("    version set to " + newVersion);
            VersionRange newVersionRange = VersionRange.createFromVersion(newVersion);
            project.getArtifact().setVersionRange(newVersionRange);
            logger.debug("    artifact version range set to " + newVersionRange);
            newProjectVersions.put(projectGAV, newVersion);

            // No need to worry about parent link, because model is in memory
        }

        try {
            JGitverUtils.attachModifiedPomFilesToTheProject(projects, newProjectVersions, mavenSession, logger);
        } catch (IOException | XmlPullParserException ex) {
            throw new MavenExecutionException("cannot attach updated POMs during project execution", ex);
        }
    }

    newProjectVersions.entrySet()
            .forEach(e -> logger.info("    " + e.getKey().toString() + " -> " + e.getValue()));
}

From source file:fr.fastconnect.factory.tibco.bw.maven.builtin.CopyBWSourcesMojo.java

License:Apache License

@Override
protected List<Resource> getResources() {
    List<Resource> result = new ArrayList<Resource>();
    if (resources != null) {
        result.addAll(resources);//from   www  .  jav  a 2s .c om
    }

    if (isContainerEnabled(getProject())) {
        result.clear(); // ignore configuration from Plexus 'components.xml'

        getLog().debug(getProject().getProperties().toString());
        getLog().debug(getProject().getProperties().getProperty("project.build.directory.src"));
        File buildSrcDirectory = new File(
                getProject().getProperties().getProperty("project.build.directory.src"));
        buildSrcDirectory.mkdirs(); // create "target/src" directory

        // define a ".archive" file to merge all ".archive" found in other projects
        String bwProjectArchiveBuilder = getProject().getProperties().getProperty("bw.project.archive.builder");
        File bwProjectArchiveMerged = new File(
                buildSrcDirectory.getAbsolutePath() + File.separator + bwProjectArchiveBuilder);
        getLog().debug(".archive: " + bwProjectArchiveMerged.getAbsolutePath());

        // create an empty Archive Builder (".archive" file)
        ArchiveBuilder mergedArchiveBuilder = new ArchiveBuilder();

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

        MavenProject aggregator = getProject().getParent();
        @SuppressWarnings("unchecked")
        List<String> modules = aggregator.getModules();

        for (String module : modules) {
            getLog().debug(module);
            String pom = aggregator.getBasedir() + File.separator + module + File.separator + "pom.xml";
            File pomFile = new File(pom);

            try {
                projectsToAggregate.add(new MavenProject(POMManager.getModelFromPOM(pomFile, getLog())));
            } catch (Exception e) {
                getLog().debug("Unable to add project from module: " + module);
            }
        }

        List<MavenProject> projects = new ArrayList<MavenProject>();
        projects.addAll(getSession().getProjects());

        for (Iterator<MavenProject> it = projects.iterator(); it.hasNext();) {
            MavenProject p = (MavenProject) it.next();
            if (!isProjectToAggregate(p, projectsToAggregate)) {
                it.remove();
            }
        }

        if (projects.size() > 0) {
            for (MavenProject p : projects) {
                if (p.getPackaging().equals(AbstractBWMojo.BWEAR_TYPE) && !isContainerEnabled(p)) {
                    // initialize project information
                    String basedir = p.getBasedir().getAbsolutePath();
                    String bwProjectLocation = p.getProperties().getProperty("bw.project.location");
                    bwProjectArchiveBuilder = p.getProperties().getProperty("bw.project.archive.builder"); // the ".archive" of the project
                    getLog().debug(basedir);
                    getLog().debug(bwProjectLocation);

                    File bwProjectArchive = new File(basedir + File.separator + bwProjectLocation
                            + File.separator + bwProjectArchiveBuilder);
                    getLog().debug(bwProjectArchive.getAbsolutePath());
                    //

                    mergedArchiveBuilder.merge(bwProjectArchive);

                    // add sources from the project to the container sources
                    File srcDirectory = new File(basedir + File.separator + bwProjectLocation);
                    result.add(addResource(srcDirectory));
                }
            }

            mergedArchiveBuilder.setSharedArchiveAuthor(pluginDescriptor.getArtifactId());
            mergedArchiveBuilder.setEnterpriseArchiveAuthor(pluginDescriptor.getArtifactId());
            mergedArchiveBuilder.setEnterpriseArchiveFileLocationProperty(
                    this.getProject().getArtifactId() + AbstractBWMojo.BWEAR_EXTENSION);
            mergedArchiveBuilder.setEnterpriseArchiveName(enterpriseArchiveName);
            mergedArchiveBuilder.setFirstProcessArchiveName(processArchiveName);
            mergedArchiveBuilder.removeDuplicateProcesses();
            mergedArchiveBuilder.save(bwProjectArchiveMerged);
        }
    }

    return result;
}

From source file:hudson.gridmaven.MavenUtil.java

License:Open Source License

/**
 * @deprecated MavenEmbedder has now a method to read all projects 
 * Recursively resolves module POMs that are referenced from
 * the given {@link MavenProject} and parses them into
 * {@link MavenProject}s.// ww  w.  java2  s .  c  o  m
 *
 * @param rel
 *      Used to compute the relative path. Pass in "" to begin.
 * @param relativePathInfo
 *      Upon the completion of this method, this variable stores the relative path
 *      from the root directory of the given {@link MavenProject} to the root directory
 *      of each of the newly parsed {@link MavenProject}.
 *
 * @throws AbortException
 *      errors will be reported to the listener and the exception thrown.
 * @throws MavenEmbedderException
 */
public static void resolveModules(MavenEmbedder embedder, MavenProject project, String rel,
        Map<MavenProject, String> relativePathInfo, BuildListener listener, boolean nonRecursive)
        throws ProjectBuildingException, AbortException, MavenEmbedderException {

    File basedir = project.getFile().getParentFile();
    relativePathInfo.put(project, rel);

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

    if (!nonRecursive) {
        for (String modulePath : project.getModules()) {
            if (Util.fixEmptyAndTrim(modulePath) != null) {
                File moduleFile = new File(basedir, modulePath);
                if (moduleFile.exists() && moduleFile.isDirectory()) {
                    moduleFile = new File(basedir, modulePath + "/pom.xml");
                }
                if (!moduleFile.exists())
                    throw new AbortException(
                            moduleFile + " is referenced from " + project.getFile() + " but it doesn't exist");

                String relativePath = rel;
                if (relativePath.length() > 0)
                    relativePath += '/';
                relativePath += modulePath;

                MavenProject child = embedder.readProject(moduleFile);
                resolveModules(embedder, child, relativePath, relativePathInfo, listener, nonRecursive);
                modules.add(child);
            }
        }
    }

    project.setCollectedProjects(modules);
}