Java Code Examples for org.apache.maven.project.MavenProject#getVersion()
The following examples show how to use
org.apache.maven.project.MavenProject#getVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bom.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
public static Bom readBom(Path pomFile) throws MavenRepositoryException { RepositorySystem system = RepositoryUtility.newRepositorySystem(); RepositorySystemSession session = RepositoryUtility.newSession(system); MavenProject mavenProject = RepositoryUtility.createMavenProject(pomFile, session); String coordinates = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(); DependencyManagement dependencyManagement = mavenProject.getDependencyManagement(); List<org.apache.maven.model.Dependency> dependencies = dependencyManagement.getDependencies(); ArtifactTypeRegistry registry = session.getArtifactTypeRegistry(); ImmutableList<Artifact> artifacts = dependencies.stream() .map(dependency -> RepositoryUtils.toDependency(dependency, registry)) .map(Dependency::getArtifact) .filter(artifact -> !shouldSkipBomMember(artifact)) .collect(ImmutableList.toImmutableList()); Bom bom = new Bom(coordinates, artifacts); return bom; }
Example 2
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
public static String computeOutputName(MavenProject project, String classifier) { String finalName = project.getBuild().getFinalName(); if (finalName != null) { if (finalName.endsWith(".jar")) { finalName = finalName.substring(0, finalName.length() - 4); } if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += ".jar"; return finalName; } else { finalName = project.getArtifactId() + "-" + project.getVersion(); if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += ".jar"; return finalName; } }
Example 3
Source File: Analyzer.java From revapi with Apache License 2.0 | 6 votes |
public static String getProjectArtifactCoordinates(MavenProject project, String versionOverride) { org.apache.maven.artifact.Artifact artifact = project.getArtifact(); String extension = artifact.getArtifactHandler().getExtension(); String version = versionOverride == null ? project.getVersion() : versionOverride; if (artifact.hasClassifier()) { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + artifact.getClassifier() + ":" + version; } else { return project.getGroupId() + ":" + project.getArtifactId() + ":" + extension + ":" + version; } }
Example 4
Source File: MavenExecutorImpl.java From developer-studio with Apache License 2.0 | 6 votes |
public boolean setMavenParent(File mavenProjectLocation, File parentMavenProjectLocation) throws Exception { if (parentMavenProjectLocation==null){ setMavenParent(mavenProjectLocation, (MavenProjectType)null); }else{ File parentProjectPomFile = new File(parentMavenProjectLocation,"pom.xml"); MavenProject parentProject = MavenUtils.getMavenProject(parentProjectPomFile); String relativeLocation = FileUtils.getRelativePath(parentMavenProjectLocation,mavenProjectLocation); if (!parentProject.getModules().contains(relativeLocation)){ parentProject.getModules().add(relativeLocation); } MavenUtils.saveMavenProject(parentProject, parentProjectPomFile); MavenProjectType parentMavenProject=new MavenProjectType(parentProject.getGroupId(),parentProject.getArtifactId(),parentProject.getVersion()); String relativePath = FileUtils.getRelativePath(mavenProjectLocation, parentProjectPomFile).replace('\\', '/'); parentMavenProject.setRelativePath(relativePath); setMavenParent(mavenProjectLocation, parentMavenProject); } return true; }
Example 5
Source File: AbstractVersionsDependencyUpdaterMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
protected String toString( MavenProject project ) { StringBuilder buf = new StringBuilder(); buf.append( project.getGroupId() ); buf.append( ':' ); buf.append( project.getArtifactId() ); if ( project.getVersion() != null && project.getVersion().length() > 0 ) { buf.append( ":" ); buf.append( project.getVersion() ); } return buf.toString(); }
Example 6
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Save the settings for the GWT nature in the application GWT preferences. * * @param project * @param mavenProject * @param mavenConfig * @throws BackingStoreException */ private void persistGwtNatureSettings(IProject project, MavenProject mavenProject, Xpp3Dom mavenConfig) throws BackingStoreException { IPath warOutDir = getWarOutDir(project, mavenProject); WebAppProjectProperties.setWarSrcDir(project, getWarSrcDir(mavenProject, mavenConfig)); // src/main/webapp WebAppProjectProperties.setWarSrcDirIsOutput(project, getLaunchFromHere(mavenConfig)); // false // TODO the extension should be used, from WarArgProcessor WebAppProjectProperties.setLastUsedWarOutLocation(project, warOutDir); WebAppProjectProperties.setGwtMavenModuleName(project, getGwtModuleName(mavenProject)); WebAppProjectProperties.setGwtMavenModuleShortName(project, getGwtModuleShortName(mavenProject)); String message = "MavenProjectConfiguratior Maven: Success with setting up GWT Nature\n"; message += "\tartifactId=" + mavenProject.getArtifactId() + "\n"; message += "\tversion=" + mavenProject.getVersion() + "\n"; message += "\twarOutDir=" + warOutDir; Activator.log(message); }
Example 7
Source File: AbstractGitFlowMojo.java From gitflow-maven-plugin with Apache License 2.0 | 5 votes |
/** * Gets current project version from pom.xml file. * * @return Current project version. * @throws MojoFailureException */ protected String getCurrentProjectVersion() throws MojoFailureException { final MavenProject reloadedProject = reloadProject(mavenSession.getCurrentProject()); if (reloadedProject.getVersion() == null) { throw new MojoFailureException( "Cannot get current project version. This plugin should be executed from the parent project."); } return reloadedProject.getVersion(); }
Example 8
Source File: PackageMojo.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
public static String computeOutputName(Archive archive, MavenProject project, String classifier) { String output = archive.getOutputFileName(); if (!StringUtils.isBlank(output)) { if (! output.endsWith(JAR_EXTENSION)) { output += JAR_EXTENSION; } return output; } String finalName = project.getBuild().getFinalName(); if (finalName != null) { if (finalName.endsWith(JAR_EXTENSION)) { finalName = finalName.substring(0, finalName.length() - JAR_EXTENSION.length()); } if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += JAR_EXTENSION; return finalName; } else { finalName = project.getArtifactId() + "-" + project.getVersion(); if (classifier != null && !classifier.isEmpty()) { finalName += "-" + classifier; } finalName += JAR_EXTENSION; return finalName; } }
Example 9
Source File: MojoToReportOptionsConverter.java From pitest with Apache License 2.0 | 5 votes |
private void useHistoryFileInTempDir(final ReportOptions data) { String tempDir = System.getProperty("java.io.tmpdir"); MavenProject project = this.mojo.getProject(); 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); } if (this.mojo.getHistoryOutputFile() == null) { data.setHistoryOutputLocation(historyFile); } }
Example 10
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
/** * Resolves the gav using the resolver. If the gav corresponds to the project artifact and is an unresolved version * for a RELEASE or LATEST, the gav is resolved such it a release not newer than the project version is found that * optionally corresponds to the provided version regex, if provided. * * <p>If the gav exactly matches the current project, the file of the artifact is found on the filesystem in * target directory and the resolver is ignored. * * @param project the project to restrict by, if applicable * @param gav the gav to resolve * @param versionRegex the optional regex the version must match to be considered. * @param resolver the version resolver to use * @return the resolved artifact matching the criteria. * @throws VersionRangeResolutionException on error * @throws ArtifactResolutionException on error */ static Artifact resolveConstrained(MavenProject project, String gav, Pattern versionRegex, ArtifactResolver resolver) throws VersionRangeResolutionException, ArtifactResolutionException { boolean latest = gav.endsWith(":LATEST"); if (latest || gav.endsWith(":RELEASE")) { Artifact a = new DefaultArtifact(gav); if (latest) { versionRegex = versionRegex == null ? ANY : versionRegex; } else { versionRegex = versionRegex == null ? ANY_NON_SNAPSHOT : versionRegex; } String upTo = project.getGroupId().equals(a.getGroupId()) && project.getArtifactId().equals(a.getArtifactId()) ? project.getVersion() : null; return resolver.resolveNewestMatching(gav, upTo, versionRegex, latest, latest); } else { String projectGav = getProjectArtifactCoordinates(project, null); Artifact ret = null; if (projectGav.equals(gav)) { ret = findProjectArtifact(project); } return ret == null ? resolver.resolveArtifact(gav) : ret; } }
Example 11
Source File: MavenProjectConfigurator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Get the war output directory. * * @param project * @param mavenProject * @return returns the war output path */ private IPath getWarOutDir(IProject project, MavenProject mavenProject) { String artifactId = mavenProject.getArtifactId(); String version = mavenProject.getVersion(); IPath locationOfProject = (project.getRawLocation() != null ? project.getRawLocation() : project.getLocation()); IPath warOut = null; // Default directory target/artifact-version if (locationOfProject != null && artifactId != null && version != null) { warOut = locationOfProject.append("target").append(artifactId + "-" + version); } // Get the GWT Maven plugin 1 <hostedWebapp/> directory if (isGwtMavenPlugin1(mavenProject) && getGwtMavenPluginHostedWebAppDirectory(mavenProject) != null) { warOut = getGwtMavenPluginHostedWebAppDirectory(mavenProject); } // Get the Gwt Maven plugin 1 <webappDirectory/> if (isGwtMavenPlugin2(mavenProject) && getGwtPlugin2WebAppDirectory(mavenProject) != null) { warOut = getGwtPlugin2WebAppDirectory(mavenProject); } // Get the maven war plugin <webappDirectory/> if (getMavenWarPluginWebAppDirectory(mavenProject) != null) { warOut = getMavenWarPluginWebAppDirectory(mavenProject); } // make the directory if it doesn't exist if (warOut != null) { warOut.toFile().mkdirs(); } return warOut; }
Example 12
Source File: SonarBreakMojo.java From sonar-break-maven-plugin with MIT License | 5 votes |
@Override public void execute() throws MojoExecutionException { MavenProject mavenProject = getMavenProject(); if (shouldDelayExecution()) { //TO work with multimodule projects as well getLog().info("Delaying SonarQube break to the end of multi-module project"); return; } if (StringUtils.isEmpty(sonarKey)) { sonarKey = String.format("%s:%s", mavenProject.getGroupId(), mavenProject.getArtifactId()); } if (!StringUtils.isEmpty(sonarBranch)){ sonarKey = String.format("%s:%s", sonarKey, sonarBranch); } final String version = mavenProject.getVersion(); getLog().info("Querying sonar for analysis on " + sonarKey + ", version: " + version); try { Query query = new Query(sonarKey, version); final int sonarLookBackSecondsParsed = parseParam(sonarLookBackSeconds, "sonarLookBackSeconds"); final int waitForProcessingSecondsParsed = parseParam(waitForProcessingSeconds, "waitForProcessingSeconds"); QueryExecutor executor = new QueryExecutor(sonarServer, sonarLookBackSecondsParsed, waitForProcessingSecondsParsed, getLog()); Result result = executor.execute(query); processResult(result); } catch (SonarBreakException | IOException e) { throw new MojoExecutionException("Error while running sonar break", e); } }
Example 13
Source File: GenerateSourcesMojo.java From vespa with Apache License 2.0 | 5 votes |
private String getConfigGenVersion() throws MojoExecutionException { if (configGenVersion != null && !configGenVersion.isEmpty()) { return configGenVersion; } Dependency container = getVespaDependency("container"); if (container != null) return container.getVersion(); Dependency containerDev = getVespaDependency("container-dev"); if (containerDev != null) return containerDev.getVersion(); Dependency docproc = getVespaDependency("docproc"); if (docproc != null) return docproc.getVersion(); MavenProject parent = getVespaParent(); if (parent != null) return parent.getVersion(); String defaultConfigGenVersion = loadDefaultConfigGenVersion(); getLog().warn(String.format( "Did not find either container or container-dev artifact in project dependencies, " + "using default version '%s' of the config class plugin.", defaultConfigGenVersion)); return defaultConfigGenVersion; }
Example 14
Source File: MavenDeployPlugin.java From dew with Apache License 2.0 | 5 votes |
@Override public Resp<String> deployAble(FinalProjectConfig projectConfig) { MavenProject mavenProject = projectConfig.getMavenProject(); String version = mavenProject.getVersion(); if (version.trim().toLowerCase().endsWith("snapshot")) { // 如果快照仓库存在 if (mavenProject.getDistributionManagement() == null || mavenProject.getDistributionManagement().getSnapshotRepository() == null || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl() == null || mavenProject.getDistributionManagement().getSnapshotRepository().getUrl().trim().isEmpty()) { return Resp.forbidden("Maven distribution snapshot repository not found"); } // SNAPSHOT每次都要发 return Resp.success(""); } else if (mavenProject.getDistributionManagement() == null || mavenProject.getDistributionManagement().getRepository() == null || mavenProject.getDistributionManagement().getRepository().getUrl() == null || mavenProject.getDistributionManagement().getRepository().getUrl().trim().isEmpty()) { // 处理非快照版 return Resp.forbidden("Maven distribution repository not found"); } String repoUrl = mavenProject.getDistributionManagement().getRepository().getUrl().trim(); // TODO auth repoUrl = repoUrl.endsWith("/") ? repoUrl : repoUrl + "/"; repoUrl += mavenProject.getGroupId().replaceAll("\\.", "/") + "/" + mavenProject.getArtifactId() + "/" + version + "/maven-metadata.xml"; if ($.http.getWrap(repoUrl).statusCode == 200) { return Resp.forbidden("The current version already exists"); } return Resp.success(""); }
Example 15
Source File: UpdateMojo.java From neoscada with Eclipse Public License 1.0 | 5 votes |
protected String getVersion ( final MavenProject project ) { getLog ().debug ( "Properties: " + project.getProperties () ); if ( !project.getVersion ().endsWith ( "-SNAPSHOT" ) ) { // project version is already qualified return project.getVersion (); } final String version = project.getProperties ().getProperty ( "qualifiedVersion" ); if ( version != null ) { // we do have a direct qualified version return version; } final String q = project.getProperties ().getProperty ( "buildQualifier" ); final String v = project.getProperties ().getProperty ( "unqualifiedVersion" ); if ( q == null || v == null ) { throw new IllegalStateException ( String.format ( "Unable to find qualified version for: %s", project.getArtifactId () ) ); } // just stick it together return v + "." + q; }
Example 16
Source File: MvnPluginReport.java From steady with Apache License 2.0 | 5 votes |
/** * Builds the set of {@link Application}s to be considered in the result report. * * If the given {@link MavenProject} has the packaging type 'POM', applications * corresponding to all its sub-modules will be added to this set. * * Depending on the configuration option {@link CoreConfiguration#REP_OVERRIDE_VER}, * the application version is either taken from the POM or from configuration * setting {@link CoreConfiguration#APP_CTX_VERSI}. * * @param _prj * @param _ids */ private void collectApplicationModules(MavenProject _prj, Set<Application> _ids) { // The version as specified in the POM of the given project final String pom_version = _prj.getVersion(); // The version specified with configuration option {@link CoreConfiguration#APP_CTX_VERSI} final String app_ctx_version = this.goal.getGoalContext().getApplication().getVersion(); // The application module to be added final Application app = new Application(_prj.getGroupId(), _prj.getArtifactId(), pom_version); // Override version found in the respective pom.xml with the version of the application context // This becomes necessary if module scan results are NOT uploaded with the version found in the POM, // but with one specified in other ways, e.g., per -Dvulas.core.appContext.version if(this.vulasConfiguration.getConfiguration().getBoolean(CoreConfiguration.REP_OVERRIDE_VER, false) && !pom_version.equals(app_ctx_version)) { app.setVersion(app_ctx_version); this.getLog().warn("Report will include application version " + app + " rather than version [" + pom_version + "] specified in its POM"); } _ids.add(app); if(_prj.getPackaging().equalsIgnoreCase("pom")) { for(MavenProject module: _prj.getCollectedProjects()) { this.collectApplicationModules(module, _ids); } } }
Example 17
Source File: UseReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
private void useReleases( ModifiedPomXMLEventReader pom, MavenProject project ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { String version = project.getVersion(); Matcher versionMatcher = matchSnapshotRegex.matcher( version ); if ( versionMatcher.matches() ) { String releaseVersion = versionMatcher.group( 1 ); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec( releaseVersion ); } catch ( InvalidVersionSpecificationException e ) { throw new MojoExecutionException( "Invalid version range specification: " + version, e ); } Artifact artifact = artifactFactory.createDependencyArtifact( getProject().getParent().getGroupId(), getProject().getParent().getArtifactId(), versionRange, "pom", null, null ); if ( !isIncluded( artifact ) ) { return; } getLog().debug( "Looking for a release of " + toString( project ) ); // Force releaseVersion version because org.apache.maven.artifact.metadata.MavenMetadataSource does not // retrieve release version if provided snapshot version. artifact.setVersion( releaseVersion ); ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false ); if ( !allowRangeMatching ) // standard behaviour { if ( versions.containsVersion( releaseVersion ) ) { if ( PomHelper.setProjectParentVersion( pom, releaseVersion ) ) { getLog().info( "Updated " + toString( project ) + " to version " + releaseVersion ); } } else if ( failIfNotReplaced ) { throw new NoSuchElementException( "No matching release of " + toString( project ) + " found for update." ); } } else { ArtifactVersion finalVersion = null; for ( ArtifactVersion proposedVersion : versions.getVersions( false ) ) { if ( proposedVersion.toString().startsWith( releaseVersion ) ) { getLog().debug( "Found matching version for " + toString( project ) + " to version " + releaseVersion ); finalVersion = proposedVersion; } } if ( finalVersion != null ) { if ( PomHelper.setProjectParentVersion( pom, finalVersion.toString() ) ) { getLog().info( "Updated " + toString( project ) + " to version " + finalVersion.toString() ); } } else { getLog().info( "No matching release of " + toString( project ) + " to update via rangeMatching." ); if ( failIfNotReplaced ) { throw new NoSuchElementException( "No matching release of " + toString( project ) + " found for update via rangeMatching." ); } } } } }
Example 18
Source File: ReactorModelPool.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
public void addProject( MavenProject project ) { Coordinates coordinates = new Coordinates( project.getGroupId(), project.getArtifactId(), project.getVersion() ); models.put( coordinates, project.getFile() ); }