List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:org.ops4j.pax.construct.lifecycle.ProvisionMojo.java
License:Apache License
/** * Deploy bundles using the 'classic' Pax-Runner * /*from www . j av a 2s .com*/ * @param mainClass main Pax-Runner class * @param project deployment project * @param repositories comma separated list of Maven repositories * @throws MojoExecutionException */ private void deployRunnerClassic(Class mainClass, MavenProject project, String repositories) throws MojoExecutionException { String workDir = project.getBasedir() + "/runner"; String cachedPomName = project.getArtifactId() + '_' + project.getVersion() + ".pom"; File cachedPomFile = new File(workDir + "/lib/" + cachedPomName); // Force reload of pom cachedPomFile.delete(); if (PomUtils.isEmpty(framework)) { framework = "felix"; } String[] deployAppCmds = { "--dir=" + workDir, "--no-md5", "--platform=" + framework, "--profile=default", "--repository=" + repositories, "--localRepository=" + m_localRepo.getBasedir(), project.getGroupId(), project.getArtifactId(), project.getVersion() }; invokePaxRunner(mainClass, deployAppCmds); }
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * Add bundle as a dependency to the provisioning POM and the local bundle POM, as appropriate * /*from w ww .j a v a2 s. c o m*/ * @param project bundle project */ private void importBundle(MavenProject project) { Dependency dependency = new Dependency(); dependency.setGroupId(project.getGroupId()); dependency.setArtifactId(project.getArtifactId()); dependency.setVersion(project.getVersion()); dependency.setOptional(!deploy); // only add non-local bundles to the provisioning POM if (m_provisionPom != null && project.getFile() == null) { getLog().info("Importing " + project.getName() + " to " + m_provisionPom); m_provisionPom.addDependency(dependency, overwrite); } if (m_localBundlePom != null) { // use provided scope when adding to bundle pom dependency.setScope(Artifact.SCOPE_PROVIDED); getLog().info("Adding " + project.getName() + " as dependency to " + m_localBundlePom); m_localBundlePom.addDependency(dependency, overwrite); } }
From source file:org.ops4j.pax.construct.util.XppPom.java
License:Apache License
/** * {@inheritDoc}//from ww w. j a v a 2 s . c o m */ public void setParent(MavenProject project, String relativePath, boolean overwrite) throws ExistingElementException { if (m_pom.getChild("parent") != null && !overwrite) { throw new ExistingElementException("parent"); } Xpp3DomMap parent = new Xpp3DomMap("parent"); parent.putValue("relativePath", relativePath); parent.putValue("groupId", project.getGroupId()); parent.putValue("artifactId", project.getArtifactId()); parent.putValue("version", project.getVersion()); Xpp3Dom newPom = new Xpp3Dom("project"); newPom.addChild(parent); m_pom = Xpp3DomHelper.mergeXpp3Dom(newPom, m_pom); }
From source file:org.overlord.sramp.integration.java.artifactbuilder.MavenPomArtifactBuilder.java
License:Apache License
@Override public ArtifactBuilder buildArtifacts(BaseArtifactType primaryArtifact, ArtifactContent artifactContent) throws IOException { super.buildArtifacts(primaryArtifact, artifactContent); try {/*from w w w. ja va 2 s . co m*/ Model model = new MavenXpp3Reader().read(getContentStream()); MavenProject project = new MavenProject(model); ((ExtendedDocument) primaryArtifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (primaryArtifact.getDescription() == null) primaryArtifact.setDescription(project.getDescription()); if (primaryArtifact.getName() == null) primaryArtifact.setName(project.getName()); if (primaryArtifact.getVersion() == null) primaryArtifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(primaryArtifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } return this; } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } }
From source file:org.overlord.sramp.integration.java.deriver.MavenPomDeriver.java
License:Apache License
/** * @see org.overlord.sramp.common.derived.ArtifactDeriver#derive(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.BaseArtifactType, java.io.InputStream) *//*w ww .java 2 s . c o m*/ @Override public Collection<BaseArtifactType> derive(BaseArtifactType artifact, InputStream contentStream) throws IOException { List<BaseArtifactType> derivedArtifacts = new ArrayList<BaseArtifactType>(); try { Model model = new MavenXpp3Reader().read(contentStream); MavenProject project = new MavenProject(model); ((ExtendedDocument) artifact).setExtendedType(JavaModel.TYPE_MAVEN_POM_XML); for (String key : project.getProperties().stringPropertyNames()) { String value = project.getProperties().getProperty(key); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PROPERTY + key, value); } //set core properties when not specified on the request if (artifact.getDescription() == null) artifact.setDescription(project.getDescription()); if (artifact.getName() == null) artifact.setName(project.getName()); if (artifact.getVersion() == null) artifact.setVersion(project.getVersion()); //set the GAV and packaging info SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_ARTIFACT_ID, model.getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_GROUP_ID, model.getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_VERSION, model.getVersion()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PACKAGING, model.getPackaging()); //set the parent GAV info if (model.getParent() != null) { SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_ARTIFACT_ID, model.getParent().getArtifactId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_GROUP_ID, model.getParent().getGroupId()); SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_PARENT_VERSION, model.getParent().getVersion()); } } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } return derivedArtifacts; }
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// ww w.j av a 2s .co m * @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;/*from w w w . j a v a 2s . c om*/ 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 w w . j av a 2s. c o m*/ 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); }// w w w .jav a 2s. c om } }
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 w w w .java2 s . c o m return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + version; } }