List of usage examples for org.apache.maven.project MavenProject getGroupId
public String getGroupId()
From source file:org.owasp.dependencycheck.maven.BaseDependencyCheckMojo.java
License:Apache License
/** * Generates the reports for a given dependency-check engine. * * @param engine a dependency-check engine * @param p the Maven project/*from w w w .j a v a 2 s . c om*/ * @param outputDir the directory path to write the report(s) * @throws ReportException thrown if there is an error writing the report */ protected void writeReports(Engine engine, MavenProject p, File outputDir) throws ReportException { DatabaseProperties prop = null; try (CveDB cve = CveDB.getInstance()) { prop = cve.getDatabaseProperties(); } catch (DatabaseException ex) { //TODO shouldn't this throw an exception? if (getLog().isDebugEnabled()) { getLog().debug("Unable to retrieve DB Properties", ex); } } final ReportGenerator r = new ReportGenerator(p.getName(), p.getVersion(), p.getArtifactId(), p.getGroupId(), engine.getDependencies(), engine.getAnalyzers(), prop); try { r.generateReports(outputDir.getAbsolutePath(), format); } catch (ReportException ex) { final String msg = String.format("Error generating the report for %s", p.getName()); throw new ReportException(msg, ex); } }
From source file:org.piraso.maven.packaging.ClassesPackagingTask.java
License:Apache License
protected void generateJarArchive(WarPackagingContext context) throws MojoExecutionException { MavenProject project = context.getProject(); ArtifactFactory factory = context.getArtifactFactory(); Artifact artifact = factory.createBuildArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "jar"); String archiveName = null;// ww w. j a v a 2 s.co m try { archiveName = getArtifactFinalName(context, artifact); } catch (InterpolationException e) { throw new MojoExecutionException("Could not get the final name of the artifact [" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + "]", e); } final String targetFilename = LIB_PATH + archiveName; if (context.getWebappStructure().registerFile(currentProjectOverlay.getId(), targetFilename)) { final File libDirectory = new File(context.getWebappDirectory(), LIB_PATH); final File jarFile = new File(libDirectory, archiveName); final ClassesPackager packager = new ClassesPackager(); packager.packageClasses(context.getClassesDirectory(), jarFile, context.getJarArchiver(), context.getSession(), project, context.getArchive()); } else { context.getLog().warn( "Could not generate archive classes file [" + targetFilename + "] has already been copied."); } }
From source file:org.pitest.maven.MojoToReportOptionsConverter.java
License:Apache License
private void useHistoryFileInTempDir(final ReportOptions data) { String tempDir = System.getProperty("java.io.tmpdir"); MavenProject project = this.mojo.project; String name = project.getGroupId() + "." + project.getArtifactId() + "." + project.getVersion() + "_pitest_history.bin"; File historyFile = new File(tempDir, name); log.info("Will read and write history at " + historyFile); if (this.mojo.getHistoryInputFile() == null) { data.setHistoryInputLocation(historyFile); }//from w ww.j a va2 s. com if (this.mojo.getHistoryOutputFile() == null) { data.setHistoryOutputLocation(historyFile); } }
From source file:org.rapidoid.plugin.app.AbstractRapidoidMojo.java
License:Apache License
private void addJarManifest(String uberJar, MavenProject project, String mainClass) throws IOException { Path path = Paths.get(uberJar); URI uri = URI.create("jar:" + path.toUri()); String user = System.getProperty("user.name"); String manifestContent = IO.load("manifest-template.mf").replace("$user", user) .replace("$java", Msc.javaVersion()).replace("$name", project.getName()) .replace("$version", project.getVersion()).replace("$groupId", project.getGroupId()) .replace("$organization", project.getOrganization() != null ? U.or(project.getOrganization().getName(), "?") : "?") .replace("$url", U.or(project.getUrl(), "?")).replace("$main", U.safe(mainClass)); try (FileSystem fs = FileSystems.newFileSystem(uri, U.<String, Object>map())) { Path manifest = fs.getPath("META-INF/MANIFEST.MF"); try (Writer writer = Files.newBufferedWriter(manifest, StandardCharsets.UTF_8, StandardOpenOption.CREATE)) { writer.write(manifestContent); }/*from ww w . j a v a2 s .c om*/ } }
From source file:org.rapidoid.plugin.app.AbstractRapidoidMojo.java
License:Apache License
private String pickMainClass(List<String> mainClasses, MavenProject project) { // the.group.id.Main String byGroupId = project.getGroupId() + ".Main"; if (mainClasses.contains(byGroupId)) return byGroupId; List<String> namedMain = U.list(); List<String> withGroupIdPkg = U.list(); for (String name : mainClasses) { if (name.equals("Main")) return "Main"; if (name.endsWith(".Main")) { namedMain.add(name);/*ww w . j a v a 2 s . c o m*/ } if (name.startsWith(project.getGroupId() + ".")) { withGroupIdPkg.add(name); } } // the.group.id.foo.bar.Main getLog().info("Candidates by group ID: " + withGroupIdPkg); if (withGroupIdPkg.size() == 1) return U.single(withGroupIdPkg); // foo.bar.Main getLog().info("Candidates named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); namedMain.retainAll(withGroupIdPkg); getLog().info("Candidates by group ID - named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); // the.group.id.foo.bar.Main (the shortest name) Collections.sort(withGroupIdPkg, new Comparator<String>() { @Override public int compare(String s1, String s2) { return s1.length() - s2.length(); } }); getLog().info("Candidates by group ID - picking one with the shortest name: " + withGroupIdPkg); return U.first(withGroupIdPkg); }
From source file:org.renjin.maven.MavenBuildContext.java
License:Open Source License
public MavenBuildContext(MavenProject project, Collection<Artifact> pluginDependencies, Log log) throws MojoExecutionException { this.project = project; this.logger = new MavenBuildLogger(log); this.buildDir = new File(project.getBuild().getDirectory()); this.outputDir = new File(project.getBuild().getOutputDirectory()); this.packageOuputDir = new File(project.getBuild().getOutputDirectory() + File.separator + project.getGroupId().replace('.', File.separatorChar) + File.separator + project.getArtifactId()); this.pluginDependencies = pluginDependencies; this.homeDir = new File(buildDir, "gnur"); this.pluginFile = new File(buildDir, "bridge.so"); this.unpackedIncludeDir = new File(buildDir, "include"); this.classpath = buildClassPath(); ensureDirExists(outputDir);//from ww w . j a v a 2 s. co m ensureDirExists(packageOuputDir); ensureDirExists(getGnuRHomeDir()); ensureDirExists(unpackedIncludeDir); classloader = new URLClassLoader(classpath, getClass().getClassLoader()); packageLoader = new ClasspathPackageLoader(classloader); }
From source file:org.revapi.maven.Analyzer.java
License:Apache License
public static String getProjectArtifactCoordinates(MavenProject project, RepositorySystemSession session, String versionOverride) { org.apache.maven.artifact.Artifact artifact = project.getArtifact(); String extension = session.getArtifactTypeRegistry().get(artifact.getType()).getExtension(); String version = versionOverride == null ? project.getVersion() : versionOverride; if (artifact.hasClassifier()) { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + artifact.getClassifier() + ":" + version; } else {/*from ww w . j av a2 s . c om*/ return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + version; } }
From source file:org.revapi.maven.UpdateReleasePropertiesMojo.java
License:Apache License
@Override void updateProjectVersion(MavenProject project, Version version) throws MojoExecutionException { File rpf = getReleasePropertiesFile(); Properties ps = readProperties(rpf); String relProp;//from ww w. ja v a 2 s. c o m String devProp; if (isSingleVersionForAllModules()) { relProp = "project.rel." + project.getGroupId() + ":" + project.getArtifactId(); devProp = "project.dev." + project.getGroupId() + ":" + project.getArtifactId(); } else { relProp = "releaseVersion"; devProp = "developmentVersion"; } ps.setProperty(relProp, version.toString()); Version dev = version.clone(); dev.setPatch(dev.getPatch() + 1); dev.setSuffix(releaseVersionSuffix == null ? "SNAPSHOT" : releaseVersionSuffix + "-SNAPSHOT"); ps.setProperty(devProp, dev.toString()); try (FileOutputStream out = new FileOutputStream(rpf)) { ps.store(out, null); } catch (IOException e) { throw new MojoExecutionException("Failed to write to the release.properties file.", e); } }
From source file:org.seasar.kvasir.plust.KvasirPlugin.java
@SuppressWarnings("unchecked") public void resolveClasspathEntries(Set<IClasspathEntry> libraryEntries, Set<String> moduleArtifacts, IFile pomFile, boolean recursive, boolean downloadSources, IProgressMonitor monitor) { monitor.beginTask("Reading " + pomFile.getLocation(), IProgressMonitor.UNKNOWN); try {/*w w w .j a v a2 s . com*/ if (monitor.isCanceled()) { throw new OperationCanceledException(); } final MavenProject mavenProject = getMavenProject(pomFile, new SubProgressMonitor(monitor, 1)); if (mavenProject == null) { return; } deleteMarkers(pomFile); // TODO use version? moduleArtifacts.add(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()); Set artifacts = mavenProject.getArtifacts(); for (Iterator it = artifacts.iterator(); it.hasNext();) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } final Artifact a = (Artifact) it.next(); monitor.subTask("Processing " + a.getId()); if (!"jar".equals(a.getType())) { continue; } // TODO use version? if (!moduleArtifacts.contains(a.getGroupId() + ":" + a.getArtifactId()) && // TODO verify if there is an Eclipse API to check that archive is acceptable ("jar".equals(a.getType()) || "zip".equals(a.getType()))) { String artifactLocation = a.getFile().getAbsolutePath(); // TODO add a lookup through workspace projects Path srcPath = null; File srcFile = new File( artifactLocation.substring(0, artifactLocation.length() - 4) + "-sources.jar"); if (srcFile.exists()) { // XXX ugly hack to do not download any sources srcPath = new Path(srcFile.getAbsolutePath()); } else if (downloadSources && !isSourceChecked(a)) { srcPath = (Path) executeInEmbedder(new MavenEmbedderCallback() { public Object run(MavenEmbedder mavenEmbedder, IProgressMonitor monitor) { monitor.beginTask("Resolve sources " + a.getId(), IProgressMonitor.UNKNOWN); try { Artifact src = mavenEmbedder.createArtifactWithClassifier(a.getGroupId(), a.getArtifactId(), a.getVersion(), "java-source", "sources"); if (src != null) { mavenEmbedder.resolve(src, mavenProject.getRemoteArtifactRepositories(), mavenEmbedder.getLocalRepository()); return new Path(src.getFile().getAbsolutePath()); } } catch (AbstractArtifactResolutionException ex) { String name = ex.getGroupId() + ":" + ex.getArtifactId() + "-" + ex.getVersion() + "." + ex.getType(); getConsole().logMessage(ex.getOriginalMessage() + " " + name); } finally { monitor.done(); } return null; } }, new SubProgressMonitor(monitor, 1)); setSourceChecked(a); } libraryEntries.add(JavaCore.newLibraryEntry(new Path(artifactLocation), srcPath, null)); } } if (recursive) { IContainer parent = pomFile.getParent(); List modules = mavenProject.getModules(); for (Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled();) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } String module = (String) it.next(); IResource memberPom = parent.findMember(module + "/" + IKvasirProject.POM_FILE_NAME); if (memberPom != null && memberPom.getType() == IResource.FILE) { resolveClasspathEntries(libraryEntries, moduleArtifacts, (IFile) memberPom, true, downloadSources, new SubProgressMonitor(monitor, 1)); } } } } catch (OperationCanceledException ex) { throw ex; } catch (InvalidArtifactRTException ex) { addMarker(pomFile, ex.getBaseMessage(), 1, IMarker.SEVERITY_ERROR); } catch (Throwable ex) { addMarker(pomFile, ex.toString(), 1, IMarker.SEVERITY_ERROR); } finally { monitor.done(); } }
From source file:org.semver.enforcer.AbstractEnforcerRule.java
License:Apache License
@Override public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException { final MavenProject project = getMavenProject(helper); if (shouldSkipRuleExecution(project)) { helper.getLog().debug("Skipping non " + AbstractEnforcerRule.JAR_ARTIFACT_TYPE + " or " + BUNDLE_ARTIFACT_TYPE + " artifact."); return;/*from w ww. ja v a2s. c o m*/ } final Artifact previousArtifact; final Artifact currentArtifact = validateArtifact(project.getArtifact()); final Version current = Version.parse(currentArtifact.getVersion()); try { final ArtifactRepository localRepository = (ArtifactRepository) helper.evaluate("${localRepository}"); final String version; if (this.previousVersion != null) { version = this.previousVersion; helper.getLog().info("Version specified as <" + version + ">"); } else { final ArtifactMetadataSource artifactMetadataSource = (ArtifactMetadataSource) helper .getComponent(ArtifactMetadataSource.class); final List<ArtifactVersion> availableVersions = getAvailableReleasedVersions(artifactMetadataSource, project, localRepository); final List<ArtifactVersion> availablePreviousVersions = filterNonPreviousVersions(availableVersions, current); if (availablePreviousVersions.isEmpty()) { helper.getLog() .warn("No previously released version. Backward compatibility check not performed."); return; } version = availablePreviousVersions.iterator().next().toString(); helper.getLog().info("Version deduced as <" + version + "> (among all availables: " + availablePreviousVersions + ")"); } final ArtifactFactory artifactFactory = (ArtifactFactory) helper.getComponent(ArtifactFactory.class); previousArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), version, null, project.getArtifact().getType()); final ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class); resolver.resolve(previousArtifact, project.getRemoteArtifactRepositories(), localRepository); validateArtifact(previousArtifact); } catch (Exception e) { helper.getLog().warn("Exception while accessing artifacts; skipping check.", e); return; } final Version previous = Version.parse(previousArtifact.getVersion()); final File previousJar = previousArtifact.getFile(); final File currentJar = currentArtifact.getFile(); compareJars(helper, previous, previousJar, current, currentJar); }