List of usage examples for org.apache.maven.project MavenProject getModules
public List<String> getModules()
From source file:hudson.gridmaven.reporters.AbstractMavenJavadocArchiver.java
License:Open Source License
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { if (!checkIsJavadocMojo(mojo)) return true; File destDir;/*w w w.jav a 2 s . c o m*/ try { aggregated = mojo.getConfigurationValue("aggregate", Boolean.class) || mojo.getGoal().equals("aggregate") || mojo.getGoal().equals("test-aggregate"); if (aggregated && !pom.isExecutionRoot()) return true; // in the aggregated mode, the generation will only happen for the root module destDir = mojo.getConfigurationValue("reportOutputDirectory", File.class); if (destDir == null) destDir = mojo.getConfigurationValue("outputDirectory", File.class); } catch (ComponentConfigurationException e) { e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_NoDestDir())); build.setResult(Result.FAILURE); return true; } if (destDir.exists()) { // javadoc:javadoc just skips itself when the current project is not a java project if (aggregated) { // store at MavenModuleSet level. listener.getLogger().println("[JENKINS] Archiving aggregated javadoc"); target = build.getModuleSetRootDir(); } else { listener.getLogger().println("[JENKINS] Archiving javadoc"); target = build.getProjectRootDir(); } target = target.child(getArchiveTargetPath()); try { new FilePath(destDir).copyRecursiveTo("**/*", target); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_FailedToCopy(destDir, target))); build.setResult(Result.FAILURE); } if (aggregated) build.registerAsAggregatedProjectAction(this); else build.registerAsProjectAction(this); // JENKINS-9202 if project without any module if (pom.getModules() != null && pom.getModules().isEmpty() && pom.isExecutionRoot()) { build.registerAsAggregatedProjectAction(this); } } return true; }
From source file:hudson.maven.reporters.AbstractMavenJavadocArchiver.java
License:Open Source License
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException { if (!checkIsJavadocMojo(mojo)) return true; File destDir;/* w w w .j a va 2s . c o m*/ try { aggregated = mojo.getConfigurationValue("aggregate", Boolean.class, Boolean.FALSE) || mojo.getGoal().equals("aggregate") || mojo.getGoal().equals("test-aggregate"); if (aggregated && !pom.isExecutionRoot()) return true; // in the aggregated mode, the generation will only happen for the root module destDir = mojo.getConfigurationValue("reportOutputDirectory", File.class); if (destDir == null) destDir = mojo.getConfigurationValue("outputDirectory", File.class); } catch (ComponentConfigurationException e) { e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_NoDestDir())); build.setResult(Result.FAILURE); return true; } if (destDir != null && destDir.exists()) { // javadoc:javadoc just skips itself when the current project is not a java project if (aggregated) { // store at MavenModuleSet level. listener.getLogger().println("[JENKINS] Archiving aggregated javadoc"); target = build.getModuleSetRootDir(); } else { listener.getLogger().println("[JENKINS] Archiving javadoc"); target = build.getProjectRootDir(); } target = target.child(getArchiveTargetPath()); try { new FilePath(destDir).copyRecursiveTo("**/*", target); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_FailedToCopy(destDir, target))); build.setResult(Result.FAILURE); } if (aggregated) build.registerAsAggregatedProjectAction(this); else build.registerAsProjectAction(this); // JENKINS-9202 if project without any module if (pom.getModules() != null && pom.getModules().isEmpty() && pom.isExecutionRoot()) { build.registerAsAggregatedProjectAction(this); } } return true; }
From source file:info.mikaelsvensson.devtools.sitesearch.SiteSearchPlugin.java
License:Apache License
private void scanForProjectsInProjectHierarchyWithSiteIndexing(final MavenProject proj, boolean forceEmbed, Set<String> modulePaths) throws IOException { forceEmbed |= isSiteIndexerPluginReferences(proj); if (forceEmbed) { String pathFromProjectRootToOtherProject = getRelativePath(project.getBasedir(), proj.getModel().getPomFile().getParentFile()); modulePaths.add(pathFromProjectRootToOtherProject); }//w w w. j av a 2s. co m for (Object moduleName : proj.getModules()) { try { File pomFile = new File(proj.getFile().getParentFile(), moduleName.toString() + File.separatorChar + "pom.xml"); MavenProject subModuleProj = loadPomFile(pomFile); scanForProjectsInProjectHierarchyWithSiteIndexing(subModuleProj, forceEmbed, modulePaths); } catch (XmlPullParserException e) { getLog().warn("Could not read POM file for module '" + moduleName + "'.", e); } } }
From source file:it.session.maven.plugin.TilesMavenLifecycleParticipant.java
License:Apache License
/** * Invoked after all MavenProject instances have been created. * <p/>/*from w ww . jav a2s . co m*/ * This callback is intended to allow extensions to manipulate MavenProjects * before they are sorted and actual build execution starts. */ public void afterProjectsRead(MavenSession mavenSession) throws MavenExecutionException { final MavenProject topLevelProject = mavenSession.getTopLevelProject(); List<String> subModules = topLevelProject.getModules(); if (subModules != null && subModules.size() > 0) { //We're in a multi-module build, we need to trigger model merging on all sub-modules for (MavenProject subModule : mavenSession.getProjects()) { if (subModule != topLevelProject) { mergeTiles(subModule, mavenSession); } } } else { mergeTiles(topLevelProject, mavenSession); } }
From source file:licenseUtil.LicenseUtil.java
License:Apache License
public static LicensingList processProjectsInFolder(File directory, String currentVersion, Boolean mavenProjectsOnly) throws IOException { LicensingList result = new LicensingList(); File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); File gitDir = new File(directory.getPath() + File.separator + ".git"); File pomFile = new File(directory.getPath() + File.separator + "pom.xml"); if (mavenProjectsOnly) { // check pom.xml if (!pomFile.exists()) { return result; }//w ww . j a va 2s.c o m } else { // check git and update if (gitDir.exists()) { logger.info("update local repository"); Utils.updateRepository(directory.getPath()); } for (File dir : subdirs) { result.addAll(processProjectsInFolder(dir, currentVersion, true)); } //return result; } logger.info("process directory: " + directory.getName()); // check git and update if (gitDir.exists()) { logger.info("update local repository"); Utils.updateRepository(directory.getPath()); } if (pomFile.exists()) { logger.info("build effective-pom"); File pom = new File(directory.getPath() + File.separator + EFFECTIVE_POM_FN); Utils.writeEffectivePom(new File(directory.getPath()), pom.getAbsolutePath()); MavenProject project = null; try { project = Utils.readPom(pom); } catch (Exception e) { logger.warn("Could not read from pom file: \"" + pom.getPath() + "\" because of " + e.getMessage()); return result; } FileUtils.delete(pom); // death first for (String module : project.getModules()) { File subdirectory = new File(directory + File.separator + module); result.addAll(processProjectsInFolder(subdirectory, currentVersion, true)); } // add all licence objects of child modules for (LicensingObject licensingObject : result) { licensingObject.put(project.getArtifactId(), currentVersion); } result.addMavenProject(project, currentVersion); } return result; }
From source file:net.oneandone.stool.stage.Stage.java
License:Apache License
private void warProjects(FileNode pomXml, Properties userProperties, List<String> profiles, List<MavenProject> result) throws IOException { MavenProject root; FileNode modulePom;/*from ww w. j ava 2 s . c o m*/ try { root = maven().loadPom(pomXml, false, userProperties, profiles, null); } catch (ProjectBuildingException | RepositoryException e) { throw new IOException("cannot parse " + pomXml + ": " + e.getMessage(), e); } session.console.verbose.println("loading " + pomXml); if ("war".equals(root.getPackaging())) { result.add(root); } else { for (String module : root.getModules()) { modulePom = session.world.file(root.getBasedir()).join(module); if (modulePom.isDirectory()) { modulePom = modulePom.join("pom.xml"); } warProjects(modulePom, userProperties, profiles, result); } } }
From source file:org.codehaus.cargo.documentation.ConfluenceProjectStructureDocumentationGenerator.java
License:Apache License
/** * Creates the wiki markup for any Modules found for the given MavenProject instance. * @param aProject the current MavenProject we are analyzing for modules. * @param treeIndex the current project level in the source tree. * @return wiki markup for the given MavenProject's modules. *//*from w w w.j a va 2 s. c om*/ private String getModuleTree(MavenProject aProject, int treeIndex) { StringBuilder markup = new StringBuilder(); List<String> modules = aProject.getModules(); int newTreeIndex = modules.size() > 0 ? treeIndex + 1 : treeIndex; for (String moduleArtifactId : modules) { File moduleDirectory = new File(aProject.getFile().getParent(), moduleArtifactId); MavenProject moduleProject = createProjectFromPom(new File(moduleDirectory, POM)); for (int i = 0; i < treeIndex; i++) { markup.append(ASTERISK); } markup.append(getProjectInfo(moduleProject, newTreeIndex)); } return markup.toString(); }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
public DashBoardMavenProject getDashBoardMavenProject(MavenProject project, String dashboardDataFile, Date generatedDate) {/*from ww w .j av a2 s .c o m*/ String projectName = project.getName(); // Fixes MOJO-801. NPE in a particular three level multimodule build this.fillProjectMap(project); DashBoardMavenProject mavenProject; if (project.getModules().size() > 0) { // String artefactId = project.getGroupId() + "." + project.getArtifactId(); mavenProject = new DashBoardMavenProject(project.getArtifactId(), project.getGroupId(), projectName, project.getVersion()); for (int i = 0; i < project.getModules().size(); i++) { String modulename = (String) project.getModules().get(i); MavenProject proj = this.getModuleMavenProject(project, modulename); String key = proj.getGroupId() + "." + proj.getArtifactId(); if (this.projectMap.containsKey(key)) { MavenProject realproj = (MavenProject) this.projectMap.get(key); DashBoardMavenProject subMavenProject = dashBoardUtils.getDashBoardMavenProject(realproj, dashboardDataFile, generatedDate); mavenProject.addModule(subMavenProject); } } } else { mavenProject = new DashBoardMavenProject(project.getArtifactId(), project.getGroupId(), projectName, project.getVersion()); for (Iterator reports = project.getReportPlugins().iterator(); reports.hasNext();) { ReportPlugin report = (ReportPlugin) reports.next(); String artifactId = report.getArtifactId(); AbstractReportBean dashBoardReport = null; if ("maven-checkstyle-plugin".equals(artifactId) || "checkstyle-maven-plugin".equals(artifactId)) { dashBoardReport = this.getCheckstyleReport(project, generatedDate); } else if ("maven-clover-plugin".equals(artifactId)) { dashBoardReport = this.getCloverReport(project, generatedDate); } else if ("maven-surefire-report-plugin".equals(artifactId) || "surefire-report-maven-plugin".equals(artifactId)) { dashBoardReport = this.getSurefireReport(project, generatedDate); } else if ("cobertura-maven-plugin".equals(artifactId) || "maven-cobertura-plugin".equals(artifactId)) { dashBoardReport = this.getCoberturaReport(project, generatedDate); } else if ("maven-pmd-plugin".equals(artifactId) || "pmd-maven-plugin".equals(artifactId)) { dashBoardReport = this.getCpdReport(project, generatedDate); if (dashBoardReport != null) { mavenProject.addReport(dashBoardReport); } dashBoardReport = this.getPmdReport(project, generatedDate); } else if ("maven-findbugs-plugin".equals(artifactId) || "findbugs-maven-plugin".equals(artifactId)) { dashBoardReport = this.getFindBugsReport(project, generatedDate); } else if ("maven-jdepend-plugin".equals(artifactId) || "jdepend-maven-plugin".equals(artifactId)) { if (!this.dbPersist) { dashBoardReport = this.getJDependReport(project, generatedDate); } } else if ("maven-taglist-plugin".equals(artifactId) || "taglist-maven-plugin".equals(artifactId)) { dashBoardReport = this.getTaglistReport(project, generatedDate); } if (dashBoardReport != null) { mavenProject.addReport(dashBoardReport); } } } return mavenProject; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * Fixes MOJO-801. NPE in a particular three level multimodule build * /*from ww w .j a v a2s . c o m*/ * @param project */ private void fillProjectMap(MavenProject project) { if (project.getModules().size() > 0) { Iterator iter = project.getCollectedProjects().iterator(); while (iter.hasNext()) { MavenProject proj = (MavenProject) iter.next(); String key = proj.getGroupId() + "." + proj.getArtifactId(); if (!this.projectMap.containsKey(key)) { this.projectMap.put(key, proj); } } } else { String key = project.getGroupId() + "." + project.getArtifactId(); if (!this.projectMap.containsKey(key)) { this.projectMap.put(key, project); } } }
From source file:org.codehaus.mojo.jsimport.LocalRepositoryCollector.java
License:Apache License
/** * Constructor./*from w ww . j a v a 2 s . c om*/ * * @param project The Maven project to be processed. * @param localRepository The local repository being used by Maven. * @param additionalFolderBases an array containing the locations of additional base folders to be considered. */ public LocalRepositoryCollector(MavenProject project, // ArtifactRepository localRepository, File[] additionalFolderBases) { // The local repo will always be in this list and it is optimal to assume that it will be hit tested the most // outside of here. localRepositoryPaths.add(localRepository.getBasedir()); // Determine the root project String projectArtifactId = project.getArtifactId(); MavenProject parentProject = project.getParent(); while (parentProject != null) { List<?> modules = parentProject.getModules(); if (modules.contains(projectArtifactId)) { projectArtifactId = parentProject.getArtifactId(); String parentProjectPath = parentProject.getBasedir().getAbsolutePath(); localRepositoryPaths.add(parentProjectPath); } else { break; } parentProject = parentProject.getParent(); } // Consider additional folders and their immediate sub folders. for (File additionalFolderBase : additionalFolderBases) { File[] additionalFolders = additionalFolderBase.listFiles(); if (additionalFolders != null) { for (File additionalFolder : additionalFolders) { if (additionalFolder.isDirectory()) { localRepositoryPaths.add(additionalFolder.getAbsolutePath()); } } } } }