List of usage examples for org.apache.maven.artifact.versioning VersionRange createFromVersionSpec
public static VersionRange createFromVersionSpec(String spec) throws InvalidVersionSpecificationException
Create a version range from a string representation
Some spec examples are:1.0
Version 1.0[1.0,2.0)
Versions 1.0 (included) to 2.0 (not included)[1.0,2.0]
Versions 1.0 to 2.0 (both included)[1.5,)
Versions 1.5 and higher(,1.0],[1.2,)
Versions up to 1.0 (included) and 1.2 or higherFrom source file:org.codehaus.gmaven.plugin.MojoSupport.java
License:Apache License
/** * Create a new artifact. If no version is specified, it will be retrieved from the dependency * list or from the DependencyManagement section of the pom. * * @param item The item to create an artifact for * @return An unresolved artifact for the given item. * * @throws MojoExecutionException Failed to create artifact *//* w w w . ja v a 2 s . c o m*/ protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionException { assert item != null; if (item.getVersion() == null) { fillMissingArtifactVersion(item); if (item.getVersion() == null) { throw new MojoExecutionException( "Unable to find artifact version of " + item.getGroupId() + ":" + item.getArtifactId() + " in either dependency list or in project's dependency management."); } } // Convert the string version to a range VersionRange range; try { range = VersionRange.createFromVersionSpec(item.getVersion()); log.trace("Using version range: {}", range); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Could not create range for version: " + item.getVersion(), e); } return artifactFactory.createDependencyArtifact(item.getGroupId(), item.getArtifactId(), range, item.getType(), item.getClassifier(), Artifact.SCOPE_PROVIDED); }
From source file:org.codehaus.mojo.clirr.AbstractClirrMojo.java
License:Apache License
private Artifact getComparisonArtifact() throws MojoFailureException, MojoExecutionException { // Find the previous version JAR and resolve it, and it's dependencies VersionRange range;//w w w.ja va2s.co m try { range = VersionRange.createFromVersionSpec(comparisonVersion); } catch (InvalidVersionSpecificationException e) { throw new MojoFailureException("Invalid comparison version: " + e.getMessage()); } Artifact previousArtifact; try { previousArtifact = factory.createDependencyArtifact(project.getGroupId(), project.getArtifactId(), range, project.getPackaging(), null, Artifact.SCOPE_COMPILE); if (!previousArtifact.getVersionRange().isSelectedVersionKnown(previousArtifact)) { getLog().debug("Searching for versions in range: " + previousArtifact.getVersionRange()); List availableVersions = metadataSource.retrieveAvailableVersions(previousArtifact, localRepository, project.getRemoteArtifactRepositories()); filterSnapshots(availableVersions); ArtifactVersion version = range.matchVersion(availableVersions); if (version != null) { previousArtifact.selectVersion(version.toString()); } } } catch (OverConstrainedVersionException e1) { throw new MojoFailureException("Invalid comparison version: " + e1.getMessage()); } catch (ArtifactMetadataRetrievalException e11) { throw new MojoExecutionException("Error determining previous version: " + e11.getMessage(), e11); } if (previousArtifact.getVersion() == null) { getLog().info("Unable to find a previous version of the project in the repository"); } return previousArtifact; }
From source file:org.codehaus.mojo.clirr.ClirrReport.java
License:Apache License
private File getSkinArtifactFile() throws MojoFailureException, MojoExecutionException { Skin skin = Skin.getDefaultSkin();//from ww w . ja v a2 s. co m String version = skin.getVersion(); Artifact artifact; try { if (version == null) { version = Artifact.RELEASE_VERSION; } VersionRange versionSpec = VersionRange.createFromVersionSpec(version); artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar", null, null); resolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); } catch (InvalidVersionSpecificationException e) { throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage()); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to find skin", e); } catch (ArtifactNotFoundException e) { throw new MojoFailureException("The skin does not exist: " + e.getMessage()); } return artifact.getFile(); }
From source file:org.codehaus.mojo.cobertura.InheritProject.java
License:Apache License
/** * Creates an Artifact object using the already-defined values, along with an optional * classifier and an optional override for type. * * @param classifier The artifact classfier * @param overrideType If given, overrides the type value we already have. * @return An unresolved artifact * * @throws MojoExecutionException Failed to create artifact *//*w ww.ja v a 2 s . c o m*/ private Artifact createArtifact(final String classifier, final String overrideType) throws MojoExecutionException { String argType; if (overrideType != null && !overrideType.equals("")) { argType = overrideType; } else { argType = type; } // Convert the string version to a range VersionRange range; try { range = VersionRange.createFromVersionSpec(version); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Could not create range for version: " + version, e); } return artifactFactory.createDependencyArtifact(groupId, artifactId, range, argType, classifier, Artifact.SCOPE_COMPILE); }
From source file:org.codehaus.mojo.mockrepo.ProxyRepository.java
License:Apache License
public ProxyRepository(RepositoryMetadataManager repositoryMetadataManager, List remoteArtifactRepositories, List remotePluginRepositories, ArtifactRepository localRepository, ArtifactFactory artifactFactory, Log log, ArtifactResolver artifactResolver) throws InvalidVersionSpecificationException { this.repositoryMetadataManager = repositoryMetadataManager; this.remoteArtifactRepositories = remoteArtifactRepositories; this.remotePluginRepositories = remotePluginRepositories; this.localRepository = localRepository; this.artifactFactory = artifactFactory; this.log = log; this.artifactResolver = artifactResolver; remoteRepositories = new ArrayList(); remoteRepositories.addAll(remoteArtifactRepositories); remoteRepositories.addAll(remotePluginRepositories); anyVersion = VersionRange.createFromVersionSpec("[0,]"); }
From source file:org.codehaus.mojo.mrm.maven.ProxyArtifactStore.java
License:Apache License
/** * Creates a new instance.//from w w w . j a va 2 s .c o m * * @param repositoryMetadataManager the {@link RepositoryMetadataManager} to use. * @param remoteArtifactRepositories the repsoitories to use. * @param remotePluginRepositories the plugin repositories to use. * @param localRepository the local repository to use. * @param artifactFactory the {@link ArtifactFactory} to use. * @param artifactResolver the {@link ArtifactResolver} to use. * @param log the {@link Log} to log to. */ public ProxyArtifactStore(RepositoryMetadataManager repositoryMetadataManager, List<ArtifactRepository> remoteArtifactRepositories, List<ArtifactRepository> remotePluginRepositories, ArtifactRepository localRepository, ArtifactFactory artifactFactory, ArtifactResolver artifactResolver, ArchetypeManager archetypeManager, Log log) { this.repositoryMetadataManager = repositoryMetadataManager; this.remotePluginRepositories = remotePluginRepositories; this.localRepository = localRepository; this.artifactFactory = artifactFactory; this.artifactResolver = artifactResolver; this.archetypeManager = archetypeManager; this.log = log; remoteRepositories = new ArrayList<ArtifactRepository>(); remoteRepositories.addAll(remoteArtifactRepositories); remoteRepositories.addAll(remotePluginRepositories); try { anyVersion = VersionRange.createFromVersionSpec("[0,]"); } catch (InvalidVersionSpecificationException e) { // must never happen... so if it does make sure we stop IllegalStateException ise = new IllegalStateException( "[0,] should always be a valid version specification"); ise.initCause(e); throw ise; } }
From source file:org.codehaus.mojo.pluginsupport.dependency.DependencyHelper.java
License:Apache License
public static Map getManagedVersionMap(final MavenProject project, final ArtifactFactory factory) throws ProjectBuildingException { assert project != null; assert factory != null; DependencyManagement dependencyManagement = project.getDependencyManagement(); Map managedVersionMap;//ww w . j a v a2s . co m if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { managedVersionMap = new HashMap(); Iterator iter = dependencyManagement.getDependencies().iterator(); while (iter.hasNext()) { Dependency d = (Dependency) iter.next(); try { VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope()); managedVersionMap.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new ProjectBuildingException(project.getId(), "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e); } } } else { managedVersionMap = Collections.EMPTY_MAP; } return managedVersionMap; }
From source file:org.codehaus.mojo.pluginsupport.MojoSupport.java
License:Apache License
/** * Create a new artifact. If no version is specified, it will be retrieved from the dependency * list or from the DependencyManagement section of the pom. * * @param item The item to create an artifact for * @return An unresolved artifact for the given item. * * @throws MojoExecutionException Failed to create artifact *///from w w w. j ava 2s . com protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionException { assert item != null; if (item.getVersion() == null) { fillMissingArtifactVersion(item); if (item.getVersion() == null) { throw new MojoExecutionException( "Unable to find artifact version of " + item.getGroupId() + ":" + item.getArtifactId() + " in either dependency list or in project's dependency management."); } } // Convert the string version to a range VersionRange range; try { range = VersionRange.createFromVersionSpec(item.getVersion()); if (log.isDebugEnabled()) { log.debug("Using version range: " + range); } } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Could not create range for version: " + item.getVersion(), e); } return getArtifactFactory().createDependencyArtifact(item.getGroupId(), item.getArtifactId(), range, item.getType(), item.getClassifier(), Artifact.SCOPE_PROVIDED); }
From source file:org.codehaus.mojo.pomtools.wrapper.custom.ModelVersionRange.java
License:Apache License
public static ModelVersionRange createFromVersionSpec(String spec) throws InvalidVersionSpecificationException { return new ModelVersionRange(VersionRange.createFromVersionSpec(spec)); }
From source file:org.codehaus.mojo.rat.RatReportMojo.java
License:Apache License
/** * Returns the skins artifact file./*from www . j av a2s . c om*/ * * @throws MojoFailureException * An error in the plugin configuration was detected. * @throws MojoExecutionException * An error occurred while searching for the artifact file. * @return Artifact file */ private File getSkinArtifactFile() throws MojoFailureException, MojoExecutionException { Skin skin = Skin.getDefaultSkin(); String version = skin.getVersion(); Artifact artifact; try { if (version == null) { version = Artifact.RELEASE_VERSION; } VersionRange versionSpec = VersionRange.createFromVersionSpec(version); artifact = factory.createDependencyArtifact(skin.getGroupId(), skin.getArtifactId(), versionSpec, "jar", null, null); resolver.resolve(artifact, getProject().getRemoteArtifactRepositories(), localRepository); } catch (InvalidVersionSpecificationException e) { throw new MojoFailureException("The skin version '" + version + "' is not valid: " + e.getMessage()); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to find skin", e); } catch (ArtifactNotFoundException e) { throw new MojoFailureException("The skin does not exist: " + e.getMessage()); } return artifact.getFile(); }