List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
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 a va2 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 w w w . j a v a 2 s. com * @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.flatten.model.resolution.ReactorModelPool.java
License:Apache License
public void addProject(MavenProject project) { Coordinates coordinates = new Coordinates(project.getGroupId(), project.getArtifactId(), project.getVersion());/*w w w.java 2 s .c o m*/ models.put(coordinates, project.getFile()); }
From source file:org.codehaus.mojo.license.AbstractDownloadLicensesMojo.java
License:Open Source License
/** * Create a simple DependencyProject object containing the GAV and license info from the Maven Artifact * * @param depMavenProject the dependency maven project * @return DependencyProject with artifact and license info *//* ww w . j a va2 s . co m*/ private ProjectLicenseInfo createDependencyProject(MavenProject depMavenProject) { ProjectLicenseInfo dependencyProject = new ProjectLicenseInfo(depMavenProject.getGroupId(), depMavenProject.getArtifactId(), depMavenProject.getVersion()); List<?> licenses = depMavenProject.getLicenses(); for (Object license : licenses) { dependencyProject.addLicense((License) license); } return dependencyProject; }
From source file:org.codehaus.mojo.license.api.DefaultThirdPartyTool.java
License:Open Source License
/** * @param project not null/*from www . j a va 2s .c o m*/ * @param localRepository not null * @param repositories not null * @return the resolved site descriptor * @throws IOException if any * @throws ArtifactResolutionException if any * @throws ArtifactNotFoundException if any */ private File resolveThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository, List<ArtifactRepository> repositories) throws IOException, ArtifactResolutionException, ArtifactNotFoundException { File result; try { result = resolveArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), DESCRIPTOR_TYPE, DESCRIPTOR_CLASSIFIER, localRepository, repositories); // we use zero length files to avoid re-resolution (see below) if (result.length() == 0) { getLogger().debug("Skipped third party descriptor"); } } catch (ArtifactNotFoundException e) { getLogger().debug("Unable to locate third party files descriptor : " + e); // we can afford to write an empty descriptor here as we don't expect it to turn up later in the remote // repository, because the parent was already released (and snapshots are updated automatically if changed) result = new File(localRepository.getBasedir(), localRepository.pathOf(e.getArtifact())); FileUtil.createNewFile(result); } return result; }
From source file:org.codehaus.mojo.license.ArtifactHelper.java
License:Open Source License
public static String getArtifactName(MavenProject project) { StringBuilder sb = new StringBuilder(); if (project.getName().startsWith("Unnamed -")) { // as in Maven 3, let's use the artifact id sb.append(project.getArtifactId()); } else {//from w ww . ja va 2s. c o m sb.append(project.getName()); } sb.append(" ("); sb.append(project.getGroupId()); sb.append(":"); sb.append(project.getArtifactId()); sb.append(":"); sb.append(project.getVersion()); sb.append(" - "); String url = project.getUrl(); sb.append(url == null ? "no url defined" : url); sb.append(")"); return sb.toString(); }
From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java
License:Educational Community License
protected String getLicense(MavenProject d, Properties mappings) { String groupId = d.getGroupId(); String artifactId = d.getArtifactId(); String version = d.getVersion(); // Exact match String id1 = groupId + "--" + artifactId + "--" + version; // Match on groupId + artifactId String id2 = groupId + "--" + artifactId; // Match on groupId String id3 = groupId;//from ww w . j a va 2s. c om String value1 = mappings.getProperty(id1); String value2 = mappings.getProperty(id2); String value3 = mappings.getProperty(id3); // Return the license, starting with the most specific, progressing to the least specific if (!StringUtils.isBlank(value1)) { return value1; } else if (!StringUtils.isBlank(value2)) { return value2; } else if (!StringUtils.isBlank(value3)) { return value3; } else { return null; } }
From source file:org.codehaus.mojo.license.DefaultThirdPartyTool.java
License:Educational Community License
/** * @param project/* w ww. j a v a2 s . c om*/ * not null * @param localRepository * not null * @param repositories * not null * @return the resolved site descriptor * @throws IOException * if any * @throws ArtifactResolutionException * if any * @throws ArtifactNotFoundException * if any */ private File resolveThirdPartyDescriptor(MavenProject project, ArtifactRepository localRepository, List<ArtifactRepository> repositories) throws IOException, ArtifactResolutionException, ArtifactNotFoundException { File result; // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1? Artifact artifact = artifactFactory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), DESCRIPTOR_TYPE, DESCRIPTOR_CLASSIFIER); try { artifactResolver.resolve(artifact, repositories, localRepository); result = artifact.getFile(); // we use zero length files to avoid re-resolution (see below) if (result.length() == 0) { getLogger().debug("Skipped third party descriptor"); } } catch (ArtifactNotFoundException e) { getLogger().debug("Unable to locate third party files descriptor : " + e); // we can afford to write an empty descriptor here as we don't expect it to turn up later in the remote // repository, because the parent was already released (and snapshots are updated automatically if changed) result = new File(localRepository.getBasedir(), localRepository.pathOf(artifact)); FileUtil.createNewFile(result); } return result; }
From source file:org.codehaus.mojo.nbm.CreateUpdateSiteMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Project antProject = registerNbmAntTasks(); File nbmBuildDirFile = new File(outputDirectory, "netbeans_site"); if (!nbmBuildDirFile.exists()) { nbmBuildDirFile.mkdirs();/*from w w w .jav a 2s .co m*/ } boolean isRepository = false; if ("auto".equals(distBase)) { distBase = null; } ArtifactRepository distRepository = getDeploymentRepository(distBase, container, getLog()); String oldDistBase = null; if (distRepository != null) { isRepository = true; } else { if (distBase != null && !distBase.contains("::")) { oldDistBase = distBase; } } if ("nbm-application".equals(project.getPackaging())) { @SuppressWarnings("unchecked") Set<Artifact> artifacts = project.getArtifacts(); for (Artifact art : artifacts) { if (!matchesIncludes(art)) { continue; } ArtifactResult res = turnJarToNbmFile(art, artifactFactory, artifactResolver, project, localRepository); if (res.hasConvertedArtifact()) { art = res.getConvertedArtifact(); } if (art.getType().equals("nbm-file")) { Copy copyTask = (Copy) antProject.createTask("copy"); copyTask.setOverwrite(true); copyTask.setFile(art.getFile()); if (!isRepository) { copyTask.setFlatten(true); copyTask.setTodir(nbmBuildDirFile); } else { String path = distRepository.pathOf(art); File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar)); copyTask.setTofile(f); } try { copyTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex); } } if (res.isOSGiBundle()) { // TODO check for bundles } } getLog().info("Created NetBeans module cluster(s) at " + nbmBuildDirFile.getAbsoluteFile()); } else if (reactorProjects != null && reactorProjects.size() > 0) { Iterator it = reactorProjects.iterator(); while (it.hasNext()) { MavenProject proj = (MavenProject) it.next(); //TODO how to figure where the the buildDir/nbm directory is File moduleDir = proj.getFile().getParentFile(); if (moduleDir != null && moduleDir.exists()) { Copy copyTask = (Copy) antProject.createTask("copy"); if (!isRepository) { FileSet fs = new FileSet(); File projOutputDirectory = new File(proj.getBuild().getDirectory()); fs.setDir(projOutputDirectory); fs.createInclude().setName("*.nbm"); copyTask.addFileset(fs); copyTask.setOverwrite(true); copyTask.setFlatten(true); copyTask.setTodir(nbmBuildDirFile); } else { File target = new File(proj.getBuild().getDirectory()); boolean has = false; File[] fls = target.listFiles(); if (fls != null) { for (File fl : fls) { if (fl.getName().endsWith(".nbm")) { copyTask.setFile(fl); has = true; break; } } } if (!has) { continue; } Artifact art = artifactFactory.createArtifact(proj.getGroupId(), proj.getArtifactId(), proj.getVersion(), null, "nbm-file"); String path = distRepository.pathOf(art); File f = new File(nbmBuildDirFile, path.replace('/', File.separatorChar)); copyTask.setTofile(f); } try { copyTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot merge nbm files into autoupdate site", ex); } } } } else { throw new MojoExecutionException( "This goal only makes sense on reactor projects or project with 'nbm-application' packaging."); } MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist"); File xmlFile = new File(nbmBuildDirFile, fileName); descTask.setDesc(xmlFile); if (oldDistBase != null) { descTask.setDistBase(oldDistBase); } if (distRepository != null) { descTask.setDistBase(distRepository.getUrl()); } FileSet fs = new FileSet(); fs.setDir(nbmBuildDirFile); fs.createInclude().setName("**/*.nbm"); descTask.addFileset(fs); try { descTask.execute(); } catch (BuildException ex) { throw new MojoExecutionException("Cannot create autoupdate site xml file", ex); } getLog().info("Generated autoupdate site content at " + nbmBuildDirFile.getAbsolutePath()); try { GZipArchiver gz = new GZipArchiver(); gz.addFile(xmlFile, fileName); File gzipped = new File(nbmBuildDirFile, fileName + ".gz"); gz.setDestFile(gzipped); gz.createArchive(); if ("nbm-application".equals(project.getPackaging())) { projectHelper.attachArtifact(project, "xml.gz", "updatesite", gzipped); } } catch (Exception ex) { throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex); } }
From source file:org.codehaus.mojo.pom.DependencyInfo.java
License:Apache License
/** * The constructor from a {@link MavenProject}. *//*from w w w . j a v a 2 s . c o m*/ public DependencyInfo(MavenProject project) { this(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging(), null, null); }