List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:org.jboss.tools.releng.NoSnapshotsAllowed.java
License:Open Source License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog();/* w w w .j ava 2 s . c om*/ try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); // MavenSession session = (MavenSession) helper.evaluate( "${session}" ); String target = (String) helper.evaluate("${project.build.directory}"); String artifactId = (String) helper.evaluate("${project.artifactId}"); // defaults if not set if (includePattern == null || includePattern.equals("")) { includePattern = ".*"; } if (excludePattern == null || excludePattern.equals("")) { excludePattern = ""; } log.debug("Search for properties matching " + SNAPSHOT + "..."); Properties projProps = project.getProperties(); Enumeration<?> e = projProps.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); // fetch from parent pom if not passed into the rule config if (buildAlias == null && key.equals("BUILD_ALIAS")) { buildAlias = projProps.getProperty(key); if (buildAlias.matches(buildAliasSearch)) { log.info("Found buildAlias = " + buildAlias + " (for buildAliasSearch = " + buildAliasSearch + ")"); } else { log.debug("Found buildAlias = " + buildAlias + " (for buildAliasSearch = " + buildAliasSearch + ")"); } } else if (key.matches(includePattern) && (excludePattern.equals("") || !key.matches(excludePattern)) && projProps.getProperty(key).indexOf(SNAPSHOT) > -1) { log.error("Found property " + key + " = " + projProps.getProperty(key)); snapshotKey = key; // } else { // log.debug("Property: "+ key + " = " + projProps.getProperty(key)); } } // // retrieve any component out of the session directly // ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); // RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class ); // log.debug( "Retrieved Session: " + session ); // log.debug( "Retrieved Resolver: " + resolver ); // log.debug( "Retrieved RuntimeInfo: " + rti ); log.debug("Retrieved Target Folder: " + target); log.debug("Retrieved ArtifactId: " + artifactId); log.debug("Retrieved Project: " + project); log.debug("Retrieved Project Version: " + project.getVersion()); if (buildAlias.matches(buildAliasSearch) && snapshotKey != null) { throw new EnforcerRuleException("\nWhen buildAlias (" + buildAlias + ") matches /" + buildAliasSearch + "/, cannot include " + SNAPSHOT + " dependencies.\n"); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }
From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.AbstractMavenEventHandler.java
License:Open Source License
public Xpp3Dom newElement(@Nonnull String name, @Nullable final MavenProject project) { Xpp3Dom projectElt = new Xpp3Dom(name); if (project == null) { return projectElt; }/* w w w . j ava 2 s. c om*/ projectElt.setAttribute("name", project.getName()); projectElt.setAttribute("groupId", project.getGroupId()); projectElt.setAttribute("artifactId", project.getArtifactId()); projectElt.setAttribute("version", project.getVersion()); projectElt.setAttribute("packaging", project.getPackaging()); if (project.getBasedir() != null) { try { projectElt.setAttribute("baseDir", project.getBasedir().getCanonicalPath()); } catch (IOException e) { throw new RuntimeIOException(e); } } if (project.getFile() != null) { File projectFile = project.getFile(); String absolutePath; try { absolutePath = projectFile.getCanonicalPath(); } catch (IOException e) { throw new RuntimeIOException(e); } if (absolutePath.endsWith(File.separator + "pom.xml") || absolutePath.endsWith(File.separator + ".flattened-pom.xml")) { // JENKINS-43616: flatten-maven-plugin replaces the original pom as artifact with a .flattened-pom.xml // no tweak } else if (absolutePath.endsWith(File.separator + "dependency-reduced-pom.xml")) { // JENKINS-42302: maven-shade-plugin creates a temporary project file dependency-reduced-pom.xml // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + "dependency-reduced-pom.xml", File.separator + "pom.xml"); } else if (absolutePath.endsWith(File.separator + ".git-versioned-pom.xml")) { // JENKINS-56666 maven-git-versioning-extension causes warnings due to temporary pom.xml file name '.git-versioned-pom.xml' // https://github.com/qoomon/maven-git-versioning-extension/blob/v4.1.0/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java#L39 // TODO see if there is a better way to implement this "workaround" absolutePath = absolutePath.replace(File.separator + ".git-versioned-pom.xml", File.separator + "pom.xml"); } else { String flattenedPomFilename = getMavenFlattenPluginFlattenedPomFilename(project); if (flattenedPomFilename == null) { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } else { if (absolutePath.endsWith(File.separator + flattenedPomFilename)) { absolutePath = absolutePath.replace(File.separator + flattenedPomFilename, File.separator + "pom.xml"); } else { logger.warn("[jenkins-event-spy] Unexpected Maven project file name '" + projectFile.getName() + "', problems may occur"); } } } projectElt.setAttribute("file", absolutePath); } Build build = project.getBuild(); if (build != null) { Xpp3Dom buildElt = new Xpp3Dom("build"); projectElt.addChild(buildElt); if (build.getOutputDirectory() != null) { buildElt.setAttribute("directory", build.getDirectory()); } if (build.getSourceDirectory() != null) { buildElt.setAttribute("sourceDirectory", build.getSourceDirectory()); } } return projectElt; }
From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.ProjectStartedExecutionHandler.java
License:Open Source License
@Override protected void addDetails(@Nonnull ExecutionEvent executionEvent, @Nonnull Xpp3Dom root) { super.addDetails(executionEvent, root); MavenProject parentProject = executionEvent.getProject().getParent(); if (parentProject == null) { // nothing to do } else {// w w w.j a v a 2s. c om Xpp3Dom parentProjectElt = new Xpp3Dom("parentProject"); root.addChild(parentProjectElt); parentProjectElt.setAttribute("name", parentProject.getName()); parentProjectElt.setAttribute("groupId", parentProject.getGroupId()); parentProjectElt.setAttribute("artifactId", parentProject.getArtifactId()); parentProjectElt.setAttribute("version", parentProject.getVersion()); } }
From source file:org.jfrog.build.extractor.maven.BuildInfoRecorder.java
License:Apache License
private void initModule(MavenProject project) { if (project == null) { logger.warn("Skipping Artifactory Build-Info module initialization: Null project."); return;//w w w . j a va 2 s.co m } ModuleBuilder module = new ModuleBuilder(); module.id(getModuleIdString(project.getGroupId(), project.getArtifactId(), project.getVersion())); module.properties(project.getProperties()); currentModule.set(module); currentModuleArtifacts.set(Collections.synchronizedSet(new HashSet<Artifact>())); currentModuleDependencies.set(Collections.synchronizedSet(new HashSet<Artifact>())); }
From source file:org.jfrog.jade.plugins.natives.plugin.NativeCompileMojo.java
License:Open Source License
public MavenProject findInReactorList(Artifact artifact) { for (MavenProject reactorProject : reactorProjects) { if (reactorProject.getGroupId().equals(artifact.getGroupId()) && reactorProject.getArtifactId().equals(artifact.getArtifactId()) && reactorProject.getVersion().equals(artifact.getVersion())) { return reactorProject; }//from w ww . ja va 2 s.c o m } return null; }
From source file:org.johnstonshome.maven.pkgdep.goal.ExportGoal.java
License:Open Source License
/** * {@inheritDoc}/*from w w w. j a v a 2 s . com*/ */ public void execute() throws MojoExecutionException { /* * The list of all discovered packages. */ final List<Package> packages = new LinkedList<Package>(); /* * Copy of the Maven local POM */ final MavenProject project = (MavenProject) this.getPluginContext().get("project"); /* * The default target for any discovered package. */ final Artifact thisBundle = new Artifact(project.getGroupId(), project.getArtifactId(), new VersionNumber(project.getVersion())); /* * The parser for Export-Package decalarations. */ final ImportExportParser parser = new ImportExportParser(); /* * Find any static MANIFEST.MF file(s) */ getLog().info(String.format("Processing %s files...", MANIFEST_FILE)); if (project.getBuild().getResources() != null) { for (final Object resource : project.getBuild().getResources()) { final File resourceDir = new File(((Resource) resource).getDirectory()); final File[] manifests = resourceDir.listFiles(new FilenameFilter() { public boolean accept(final File dir, final String name) { return name.equals(MANIFEST_FILE); } }); for (final File manifest : manifests) { getLog().info(manifest.getPath()); packages.addAll(parser.parseManifestExports(manifest, project.getBuild().getSourceDirectory(), thisBundle)); } } } /* * Look for the felix bundle plugin */ getLog().info(String.format("Processing %s content...", ImportExportParser.PLUGIN_ARTIFACT)); packages.addAll(parser.parsePomExports(project, thisBundle)); final Repository repository = new Repository(); for (final Package found : packages) { getLog().info(found.getName() + ":" + found.getVersions()); final Package local = repository.readPackage(found.getName()); if (local != null) { local.merge(found); repository.writePackage(local); } else { repository.writePackage(found); } } }
From source file:org.jooby.JoobyMojo.java
License:Apache License
@SuppressWarnings("unchecked") private Set<Artifact> references(final MavenProject project) { MavenProject parent = project.getParent(); if (parent != null) { List<String> modules = parent.getModules(); if (modules != null) { Set<Artifact> artifacts = new LinkedHashSet<Artifact>(mavenProject.getArtifacts()); String groupId = project.getGroupId(); String version = project.getVersion(); return artifacts.stream().filter(a -> a.getGroupId().equals(groupId) && a.getVersion().equals(version) && modules.contains(a.getArtifactId())) .collect(Collectors.toSet()); }/* w ww . ja v a 2 s .c o m*/ } return Collections.emptySet(); }
From source file:org.jszip.maven.AbstractJSZipMojo.java
License:Apache License
protected MavenProject findProject(List<MavenProject> projects, Artifact artifact) { for (MavenProject project : projects) { if (StringUtils.equals(artifact.getGroupId(), project.getGroupId()) && StringUtils.equals(artifact.getArtifactId(), project.getArtifactId()) && StringUtils.equals(artifact.getVersion(), project.getVersion())) { return project; }//from www. j a v a 2 s .c o m } return null; }
From source file:org.jszip.maven.RunMojo.java
License:Apache License
private void injectMissingArtifacts(MavenProject destination, MavenProject source) { if (destination.getArtifact().getFile() == null && source.getArtifact().getFile() != null) { getLog().info("Pushing primary artifact from forked execution into current execution"); destination.getArtifact().setFile(source.getArtifact().getFile()); }/* w ww. j a v a2s . c o m*/ for (Artifact executedArtifact : source.getAttachedArtifacts()) { String executedArtifactId = (executedArtifact.getClassifier() == null ? "." : "-" + executedArtifact.getClassifier() + ".") + executedArtifact.getType(); if (StringUtils.equals(executedArtifact.getGroupId(), destination.getGroupId()) && StringUtils.equals(executedArtifact.getArtifactId(), destination.getArtifactId()) && StringUtils.equals(executedArtifact.getVersion(), destination.getVersion())) { boolean found = false; for (Artifact artifact : destination.getAttachedArtifacts()) { if (StringUtils.equals(artifact.getGroupId(), destination.getGroupId()) && StringUtils.equals(artifact.getArtifactId(), destination.getArtifactId()) && StringUtils.equals(artifact.getVersion(), destination.getVersion()) && StringUtils.equals(artifact.getClassifier(), executedArtifact.getClassifier()) && StringUtils.equals(artifact.getType(), executedArtifact.getType())) { if (artifact.getFile() == null) { getLog().info("Pushing " + executedArtifactId + " artifact from forked execution into current execution"); artifact.setFile(executedArtifact.getFile()); } found = true; } } if (!found) { getLog().info("Attaching " + executedArtifactId + " artifact from forked execution into current execution"); projectHelper.attachArtifact(destination, executedArtifact.getType(), executedArtifact.getClassifier(), executedArtifact.getFile()); } } } }
From source file:org.jvnet.hudson.maven3.listeners.MavenProjectInfo.java
License:Apache License
public MavenProjectInfo(MavenProject mavenProject) { this.displayName = mavenProject.getName(); this.groupId = mavenProject.getGroupId(); this.artifactId = mavenProject.getArtifactId(); this.version = mavenProject.getVersion(); }