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.mojo.rpm.Dependency.java
License:Apache License
/** * Parse the list of dependencies./*www.j a v a 2 s . c o m*/ * * @param in The list specified in the configuration * @return A list of parsed artifact identifiers * @throws MojoExecutionException if the parse fails */ private List<Artifact> parseList(List<String> in) throws MojoExecutionException { List<Artifact> retval = new ArrayList<Artifact>(); for (String s : in) { String[] parts = s.split(":"); // Make sure we have group and artifact if (parts.length == 0) { throw new MojoExecutionException("Include and exclude must include both group and artifact IDs."); } String groupId = parts[0]; String artifactId = parts[1]; String versionStr = null; String type = ""; String classifier = ""; VersionRange vr = null; if (parts.length > 2) { versionStr = parts[2]; if (parts.length > 3) { type = parts[3]; } if (parts.length > 4) { classifier = parts[4]; } } else { versionStr = "[0,]"; } try { vr = VersionRange.createFromVersionSpec(versionStr); } catch (InvalidVersionSpecificationException ex) { throw new MojoExecutionException("Default version string is invalid!"); } retval.add(new DefaultArtifact(groupId, artifactId, vr, null, type, classifier, null)); } return retval; }
From source file:org.codehaus.mojo.setup.scm.AbstractScmSettingsSetupMojo.java
License:Apache License
/** * {@inheritDoc}//from ww w . j av a 2 s. com * @since 1.0.0 */ @Override protected VersionRange getMavenVersionRange() throws InvalidVersionSpecificationException { return VersionRange.createFromVersionSpec("[2.0.0,)"); }
From source file:org.codehaus.mojo.setup.security.SettingsSecuritySetupMojo.java
License:Apache License
/** * {@inheritDoc}/*from w ww .j av a 2 s .co m*/ * @since 1.0.0 */ @Override protected VersionRange getMavenVersionRange() throws InvalidVersionSpecificationException { return VersionRange.createFromVersionSpec("[2.1.0,)"); }
From source file:org.codehaus.mojo.setup.settings.AbstractSettingsSetupMojo.java
License:Apache License
/** * {@inheritDoc}/*w ww. j av a 2 s .co m*/ * @since 1.0.0 */ @Override protected VersionRange getMavenVersionRange() throws InvalidVersionSpecificationException { return VersionRange.createFromVersionSpec("[3.0,)"); }
From source file:org.codehaus.mojo.sysdeo.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with * the <code>resolved</code> property set to true. * * @return list of projects artifacts// w w w . j av a 2s. co m * @throws MojoExecutionException if unable to parse dependency versions */ private Set getProjectArtifacts() throws MojoExecutionException { // keep it sorted, this should avoid random classpath order in tests Set artifacts = new TreeSet(); for (Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext();) { Dependency dependency = (Dependency) dependencies.next(); String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(Messages.getString("unabletoparseversion", new Object[] { //$NON-NLS-1$ dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(), e.getMessage() }), e); } String type = dependency.getType(); if (type == null) { type = "jar"; //$NON-NLS-1$ } String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); if (scope == null) { scope = Artifact.SCOPE_COMPILE; } Artifact art = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, optional); if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) { art.setFile(new File(dependency.getSystemPath())); } List exclusions = new ArrayList(); for (Iterator j = dependency.getExclusions().iterator(); j.hasNext();) { Exclusion e = (Exclusion) j.next(); exclusions.add(e.getGroupId() + ":" + e.getArtifactId()); //$NON-NLS-1$ } ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions); art.setDependencyFilter(newFilter); artifacts.add(art); } return artifacts; }
From source file:org.codehaus.mojo.sysdeo.ide.AbstractIdeSupportMojo.java
License:Apache License
private Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws MojoExecutionException { Map map;/* w w w. j a va 2 s .co m*/ if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { map = new HashMap(); for (Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext();) { Dependency d = (Dependency) i.next(); try { VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); Artifact artifact = artifactFactory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope(), d.isOptional()); map.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(Messages.getString("unabletoparseversion", new Object[] { //$NON-NLS-1$ projectId, d.getVersion(), d.getManagementKey(), e.getMessage() }), e); } } } else { map = Collections.EMPTY_MAP; } return map; }
From source file:org.codehaus.mojo.versions.AbstractVersionsReportRenderer.java
License:Apache License
private Set<String> getVersionsInRange(Property property, PropertyVersions versions, ArtifactVersion[] artifactVersions) { VersionRange range;// ww w .j a va2 s . com Set<String> rangeVersions = new HashSet<String>(); ArtifactVersion[] tmp; if (property.getVersion() != null) { try { range = VersionRange.createFromVersionSpec(property.getVersion()); tmp = versions.getAllUpdates(range); } catch (InvalidVersionSpecificationException e) { tmp = artifactVersions; } } else { tmp = artifactVersions; } for (int i = 0; i < tmp.length; i++) { rangeVersions.add(tmp[i].toString()); } return rangeVersions; }
From source file:org.codehaus.mojo.versions.api.DefaultVersionsHelper.java
License:Apache License
/** * {@inheritDoc}/*from www . j a v a2s .c om*/ */ public Artifact createDependencyArtifact(Dependency dependency) throws InvalidVersionSpecificationException { return createDependencyArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() == null ? VersionRange.createFromVersionSpec("[0,]") : VersionRange.createFromVersionSpec(dependency.getVersion()), dependency.getType(), dependency.getClassifier(), dependency.getScope(), dependency.isOptional()); }
From source file:org.codehaus.mojo.versions.api.DefaultVersionsHelper.java
License:Apache License
/** * {@inheritDoc}/*from w ww.j a va 2s . com*/ */ public ArtifactVersions lookupDependencyUpdates(Dependency dependency, boolean usePluginRepositories) throws ArtifactMetadataRetrievalException, InvalidVersionSpecificationException { getLog().debug( "Checking " + ArtifactUtils.versionlessKey(dependency.getGroupId(), dependency.getArtifactId()) + " for updates newer than " + dependency.getVersion()); VersionRange versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); return lookupArtifactVersions( createDependencyArtifact(dependency.getGroupId(), dependency.getArtifactId(), versionRange, dependency.getType(), dependency.getClassifier(), dependency.getScope()), usePluginRepositories); }
From source file:org.codehaus.mojo.versions.api.PomHelper.java
License:Apache License
private static VersionRange createVersionRange(String versionOrRange) throws InvalidVersionSpecificationException { VersionRange versionRange = VersionRange.createFromVersionSpec(versionOrRange); if (versionRange.getRecommendedVersion() != null) { versionRange = VersionRange.createFromVersionSpec("[" + versionOrRange + "]"); }//from w w w. j av a 2s. c om return versionRange; }