Java Code Examples for org.apache.maven.artifact.Artifact#getVersion()
The following examples show how to use
org.apache.maven.artifact.Artifact#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: BarMojo.java From incubator-batchee with Apache License 2.0 | 6 votes |
private static String artifactPath(final Artifact artifact) { final StringBuilder sb = new StringBuilder(); sb.append(artifact.getArtifactId()); sb.append("-"); if (artifact.hasClassifier()) { sb.append(artifact.getClassifier()); sb.append("-"); } if (artifact.getBaseVersion() != null) { sb.append(artifact.getBaseVersion()); } else if (artifact.getVersion() != null) { sb.append(artifact.getVersion()); } else { sb.append(artifact.getVersionRange().toString()); } sb.append('.').append(artifact.getType()); return sb.toString(); }
Example 2
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 5 votes |
/** Validate the version of the SARL compiler in the Maven configuration. * * @return the SARL bundle. * @throws CoreException if internal error occurs. */ protected Bundle validateSARLCompilerPlugin() throws CoreException { final Map<String, Artifact> plugins = getMavenProjectFacade().getMavenProject().getPluginArtifactMap(); final Artifact pluginArtifact = plugins.get(ArtifactUtils.versionlessKey(SARL_PLUGIN_GROUP_ID, SARL_PLUGIN_ARTIFACT_ID)); if (pluginArtifact == null) { getBuildContext().addMessage( getMavenProjectFacade().getPomFile(), -1, -1, Messages.SARLProjectConfigurator_5, BuildContext.SEVERITY_ERROR, null); } else { final String version = pluginArtifact.getVersion(); if (Strings.isNullOrEmpty(version)) { getBuildContext().addMessage( getMavenProjectFacade().getPomFile(), -1, -1, Messages.SARLProjectConfigurator_5, BuildContext.SEVERITY_ERROR, null); } else { return validateSARLVersion( SARL_PLUGIN_GROUP_ID, SARL_PLUGIN_ARTIFACT_ID, version); } } return null; }
Example 3
Source File: ExtensionClassLoader.java From nifi-maven with Apache License 2.0 | 5 votes |
public String getNiFiApiVersion() { final Collection<Artifact> artifacts = getAllArtifacts(); for (final Artifact artifact : artifacts) { if (artifact.getArtifactId().equals("nifi-api") && artifact.getGroupId().equals("org.apache.nifi")) { return artifact.getVersion(); } } final ClassLoader parent = getParent(); if (parent instanceof ExtensionClassLoader) { return ((ExtensionClassLoader) parent).getNiFiApiVersion(); } return null; }
Example 4
Source File: UnlockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void unlockParentSnapshot( ModifiedPomXMLEventReader pom, MavenProject parent ) throws XMLStreamException, MojoExecutionException { if ( parent == null ) { getLog().info( "Project does not have a parent" ); return; } if ( reactorProjects.contains( parent ) ) { getLog().info( "Project's parent is part of the reactor" ); return; } Artifact parentArtifact = parent.getArtifact(); String parentVersion = parentArtifact.getVersion(); Matcher versionMatcher = matchSnapshotRegex.matcher( parentVersion ); if ( versionMatcher.find() && versionMatcher.end() == parentVersion.length() ) { String unlockedParentVersion = versionMatcher.replaceFirst( "-SNAPSHOT" ); if ( PomHelper.setProjectParentVersion( pom, unlockedParentVersion ) ) { getLog().info( "Unlocked parent " + parentArtifact.toString() + " to version " + unlockedParentVersion ); } } }
Example 5
Source File: JUnitOutputListenerProvider.java From netbeans with Apache License 2.0 | 5 votes |
private String getJUnitVersion(MavenProject prj) { String juVersion = ""; for (Artifact a : prj.getArtifacts()) { if ("junit".equals(a.getGroupId()) && ("junit".equals(a.getArtifactId()) || "junit-dep".equals(a.getArtifactId()))) { //junit-dep see #214238 String version = a.getVersion(); if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("4.8")) >= 0) { return "JUNIT4"; //NOI18N } if (version != null && new ComparableVersion(version).compareTo(new ComparableVersion("3.8")) >= 0) { return "JUNIT3"; //NOI18N } } } return juVersion; }
Example 6
Source File: AgentDependencies.java From promagent with Apache License 2.0 | 5 votes |
private static void failOnVersionConflict(Artifact artifact, List<Artifact> knownArtifacts, String pluginArtifactId) throws MojoExecutionException { Optional<String> conflictingVersion = knownArtifacts.stream() .filter(artifactMatcherWithoutVersion(artifact)) .filter(artifactMatcherWithVersion(artifact).negate()) // same version -> not conflicting .findFirst() .map(Artifact::getVersion); if (conflictingVersion.isPresent()) { String artifactName = artifact.getGroupId() + artifact.getArtifactId(); throw new MojoExecutionException("version conflict in " + pluginArtifactId + ": " + artifactName + " found in version " + artifact.getVersion() + " and version " + conflictingVersion.get()); } }
Example 7
Source File: ArtifactVersions.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Creates a new {@link ArtifactVersions} instance. * * @param artifact The artifact. * @param versions The versions. * @param versionComparator The version comparison rule. * @since 1.0-alpha-3 */ public ArtifactVersions( Artifact artifact, List<ArtifactVersion> versions, VersionComparator versionComparator ) { this.artifact = artifact; this.versionComparator = versionComparator; this.versions = new TreeSet<ArtifactVersion>( versionComparator ); this.versions.addAll( versions ); if ( artifact.getVersion() != null ) { setCurrentVersion( artifact.getVersion() ); } }
Example 8
Source File: FingerprintMojo.java From java-specialagent with Apache License 2.0 | 5 votes |
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (isRunning) return; isRunning = true; if (isSkip()) { getLog().info("Skipping plugin execution"); return; } if ("pom".equalsIgnoreCase(getProject().getPackaging())) { getLog().info("Skipping for \"pom\" module."); return; } try { for (final Artifact artifact : getProject().getDependencyArtifacts()) { if ("io.opentracing".equals(artifact.getGroupId()) && "opentracing-api".equals(artifact.getArtifactId())) { apiVersion = artifact.getVersion(); break; } } createDependenciesTgf(); createFingerprintBin(); createLocalRepoFile(); createPluginName(); } catch (final DependencyResolutionException | IOException | LifecycleExecutionException e) { throw new MojoFailureException(e.getMessage(), e); } finally { isRunning = false; } }
Example 9
Source File: ExampleGraphMojo.java From depgraph-maven-plugin with Apache License 2.0 | 5 votes |
private static DependencyNode createConflict(Artifact artifact, String winningVersion) { org.eclipse.aether.artifact.DefaultArtifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), artifact.getVersion()); org.eclipse.aether.artifact.DefaultArtifact winnerArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getType(), winningVersion); DefaultDependencyNode dependencyNode = new DefaultDependencyNode(new Dependency(aetherArtifact, artifact.getScope())); dependencyNode.setData(NODE_DATA_WINNER, new DefaultDependencyNode(new Dependency(winnerArtifact, "compile"))); return new DependencyNode(dependencyNode); }
Example 10
Source File: ResolveRangesMojo.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
private void resolveRanges( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { for ( Dependency dep : dependencies ) { if ( isExcludeReactor() && isProducedByReactor( dep ) ) { continue; } if ( isHandledByProperty( dep ) ) { getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) ); continue; } Matcher versionMatcher = matchRangeRegex.matcher( dep.getVersion() ); if ( versionMatcher.find() ) { Artifact artifact = this.toArtifact( dep ); if ( artifact != null && isIncluded( artifact ) ) { getLog().debug( "Resolving version range for dependency: " + artifact ); String artifactVersion = artifact.getVersion(); if ( artifactVersion == null ) { ArtifactVersion latestVersion = findLatestVersion( artifact, artifact.getVersionRange(), allowSnapshots, false ); if ( latestVersion != null ) { artifactVersion = latestVersion.toString(); } else { getLog().warn( "Not updating version " + artifact + " : could not resolve any versions" ); } } if ( artifactVersion != null ) { if ( PomHelper.setDependencyVersion( pom, artifact.getGroupId(), artifact.getArtifactId(), dep.getVersion(), artifactVersion, getProject().getModel() ) ) { getLog().debug( "Version set to " + artifactVersion + " for dependency: " + artifact ); } else { getLog().debug( "Could not find the version tag for dependency " + artifact + " in project " + getProject().getId() + " so unable to set version to " + artifactVersion ); } } } } } }
Example 11
Source File: OpenSourceLicenseCheckMojo.java From license-check with MIT License | 4 votes |
String toCoordinates(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 12
Source File: ProvisionStateMojo.java From galleon with Apache License 2.0 | 4 votes |
private Path resolveMaven(ArtifactCoordinate coordinate, MavenRepoManager resolver) throws MavenUniverseException, MojoExecutionException { final MavenArtifact artifact = new MavenArtifact(); artifact.setGroupId(coordinate.getGroupId()); artifact.setArtifactId(coordinate.getArtifactId()); String version = coordinate.getVersion(); if(isEmptyOrNull(version)) { // first, we are looking for the artifact among the project deps // direct dependencies may override the managed versions for(Artifact a : project.getArtifacts()) { if(coordinate.getArtifactId().equals(a.getArtifactId()) && coordinate.getGroupId().equals(a.getGroupId()) && coordinate.getExtension().equals(a.getType()) && (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()) .equals(a.getClassifier() == null ? "" : a.getClassifier())) { version = a.getVersion(); break; } } if(isEmptyOrNull(version)) { // Now we are going to look for for among the managed dependencies for (Dependency d : project.getDependencyManagement().getDependencies()) { if (coordinate.getArtifactId().equals(d.getArtifactId()) && coordinate.getGroupId().equals(d.getGroupId()) && coordinate.getExtension().equals(d.getType()) && (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()) .equals(d.getClassifier() == null ? "" : d.getClassifier())) { version = d.getVersion(); break; } } if (isEmptyOrNull(version)) { throw new MojoExecutionException(coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":" + (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()) + ":" + coordinate.getExtension() + " was found among neither the project's dependencies nor the managed dependencies." + " To proceed, please, add the desired version of the feature-pack to the provisioning configuration" + " or the project dependencies, or the dependency management section of the Maven project"); } } } artifact.setVersion(version); artifact.setExtension(coordinate.getExtension()); artifact.setClassifier(coordinate.getClassifier()); resolver.resolve(artifact); return artifact.getPath(); }
Example 13
Source File: Java2WSMojo.java From cxf with Apache License 2.0 | 4 votes |
public void execute() throws MojoExecutionException { boolean requiresModules = JavaUtils.isJava9Compatible(); if (requiresModules) { // Since JEP 261 ("Jigsaw"), access to some packages must be granted fork = true; boolean skipXmlWsModule = JavaUtils.isJava11Compatible(); // additionalJvmArgs = "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED " + "--add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED " + (skipXmlWsModule ? "" : "--add-opens java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED ") + "--add-opens java.base/java.security=ALL-UNNAMED " + "--add-opens java.base/java.net=ALL-UNNAMED " + "--add-opens java.base/java.lang=ALL-UNNAMED " + "--add-opens java.base/java.util=ALL-UNNAMED " + "--add-opens java.base/java.util.concurrent=ALL-UNNAMED " + (additionalJvmArgs == null ? "" : additionalJvmArgs); } if (fork && SystemUtils.IS_OS_WINDOWS) { // Windows does not allow for very long command lines, // so by default CLASSPATH environment variable is used. classpathAsEnvVar = true; } System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true"); if (skip) { getLog().info("Skipping Java2WS execution"); return; } ClassLoaderSwitcher classLoaderSwitcher = new ClassLoaderSwitcher(getLog()); try { String cp = classLoaderSwitcher.switchClassLoader(project, false, classpath, classpathElements); if (fork) { List<String> artifactsPath = new ArrayList<>(pluginArtifacts.size()); for (Artifact a : pluginArtifacts) { File file = a.getFile(); if (file == null) { throw new MojoExecutionException("Unable to find file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); } artifactsPath.add(file.getPath()); } cp = StringUtils.join(artifactsPath.iterator(), File.pathSeparator) + File.pathSeparator + cp; } List<String> args = initArgs(classpathAsEnvVar ? null : cp); processJavaClass(args, classpathAsEnvVar ? cp : null); } finally { classLoaderSwitcher.restoreClassLoader(); } if (!skipGarbageCollection) { System.gc(); } }
Example 14
Source File: ArtifactMultiViewFactory.java From netbeans with Apache License 2.0 | 4 votes |
private static String getTcId(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 15
Source File: ResolveRangesMojo.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
private void resolveRangesInParent( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, ArtifactMetadataRetrievalException, XMLStreamException { Matcher versionMatcher = matchRangeRegex.matcher( getProject().getModel().getParent().getVersion() ); if ( versionMatcher.find() ) { Artifact artifact = this.toArtifact( getProject().getModel().getParent() ); if ( artifact != null && isIncluded( artifact ) ) { getLog().debug( "Resolving version range for parent: " + artifact ); String artifactVersion = artifact.getVersion(); if ( artifactVersion == null ) { ArtifactVersion latestVersion = findLatestVersion( artifact, artifact.getVersionRange(), allowSnapshots, false ); if ( latestVersion != null ) { artifactVersion = latestVersion.toString(); } else { getLog().warn( "Not updating version " + artifact + " : could not resolve any versions" ); } } if ( artifactVersion != null ) { if ( PomHelper.setProjectParentVersion( pom, artifactVersion ) ) { getLog().debug( "Version set to " + artifactVersion + " for parent: " + artifact ); } else { getLog().warn( "Could not find the version tag for parent " + artifact + " in project " + getProject().getId() + " so unable to set version to " + artifactVersion ); } } } } }
Example 16
Source File: ScopeFilter.java From sundrio with Apache License 2.0 | 4 votes |
public Artifact apply(Artifact artifact) { return artifact == null ? null : new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() != null ? artifact.getScope() : Artifact.SCOPE_COMPILE, artifact.getType(), artifact.getClassifier(), artifact.getArtifactHandler()); }
Example 17
Source File: DependencyNode.java From depgraph-maven-plugin with Apache License 2.0 | 4 votes |
public DependencyNode(Artifact artifact) { this(artifact, determineNodeResolution(artifact), artifact.getVersion()); }
Example 18
Source File: JApiCmpMojo.java From japicmp with Apache License 2.0 | 4 votes |
private String toDescriptor(Artifact artifact) { return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); }
Example 19
Source File: AbstractScanMojo.java From LicenseScout with Apache License 2.0 | 2 votes |
/** * Obtains an artifact description for use in an attach operation. * * <p>The returned object has group ID, artifact ID, version and type set from the current project. * The classifier is set from the Maven parameter {@link #attachReportsClassifier}.</p> * @return an artifact description to attach */ private LSArtifact getAttachArtifact() { final Artifact artifact = mavenProject.getArtifact(); return new LSArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), attachReportsClassifier); }
Example 20
Source File: Utils.java From deadcode4j with Apache License 2.0 | 2 votes |
/** * Returns <i>groupId:artifactId:version</i> for the specified artifact. * * @since 2.0.0 */ @Nonnull public static String getVersionedKeyFor(@Nonnull Artifact artifact) { return getKeyFor(artifact) + ":" + artifact.getVersion(); }