本文整理匯總了Java中org.apache.maven.artifact.versioning.VersionRange類的典型用法代碼示例。如果您正苦於以下問題:Java VersionRange類的具體用法?Java VersionRange怎麽用?Java VersionRange使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
VersionRange類屬於org.apache.maven.artifact.versioning包,在下文中一共展示了VersionRange類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
protected void setUp()
throws Exception
{
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandlerStub( "jar", null );
VersionRange vr = VersionRange.createFromVersion( "1.1" );
release = new DefaultArtifact( "test", "one", vr, Artifact.SCOPE_COMPILE, "jar", "sources", ah, false );
artifacts.add( release );
ah = new DefaultArtifactHandlerStub( "war", null );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
snap = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false );
artifacts.add( snap );
ah = new DefaultArtifactHandlerStub( "war", null );
vr = VersionRange.createFromVersion( "1.1-SNAPSHOT" );
sources = new DefaultArtifact( "test", "two", vr, Artifact.SCOPE_PROVIDED, "sources", "sources", ah, false );
// pick random output location
Random a = new Random();
outputFolder = new File( "target/copy" + a.nextLong() + "/" );
outputFolder.delete();
assertFalse( outputFolder.exists() );
}
示例2: getLatestReleaseVersion
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Returns the latest published release artifact version in the version range,
* or null if there is no such version.
*/
public ArtifactVersion getLatestReleaseVersion(
String groupId, String artifactId, VersionRange range) {
String coordinates = idToKey(groupId, artifactId);
try {
NavigableSet<ArtifactVersion> versions = availableVersions.get(coordinates);
for (ArtifactVersion version : versions.descendingSet()) {
if (isReleased(version)) {
if (range == null || range.containsVersion(version)) {
return version;
}
}
}
} catch (ExecutionException ex) {
logger.log(
Level.WARNING,
"Could not retrieve version for artifact " + coordinates,
ex.getCause());
}
return null;
}
示例3: testVersionRangeFromSpec
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
@Test
public void testVersionRangeFromSpec() {
VersionRange versionRange = majorVersion.getVersionRange();
Restriction restriction = Iterables.getOnlyElement(versionRange.getRestrictions());
assertEquals(majorVersion.getVersionRange(), majorVersion.getVersionRange());
assertTrue(restriction.isLowerBoundInclusive());
assertEquals(majorVersion.getInitialVersion(), restriction.getLowerBound());
assertFalse(restriction.isUpperBoundInclusive());
if (majorVersion.getMaxVersion().toString().trim().isEmpty()) {
assertNull(
"No Upper Bound should be specified if the max version is empty",
restriction.getUpperBound());
} else {
assertEquals(majorVersion.getMaxVersion(), restriction.getUpperBound());
}
}
示例4: testTruncateVersionRange
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
@Test
public void testTruncateVersionRange() {
ArtifactVersion initialVersion = majorVersion.getInitialVersion();
ArtifactVersion newStart =
new DefaultArtifactVersion(
String.format(
"%s.%s.%s",
initialVersion.getMajorVersion(),
initialVersion.getMajorVersion(),
initialVersion.getIncrementalVersion() + 5));
assumeTrue(majorVersion.getMaxVersion().compareTo(newStart) > 0);
VersionRange updatedRange = MajorVersion.truncateAtLatest(newStart, majorVersion.getVersionRange());
assertFalse(updatedRange.containsVersion(majorVersion.getInitialVersion()));
ArtifactVersion afterStart =
new DefaultArtifactVersion(
String.format(
"%s.%s.%s",
initialVersion.getMajorVersion(),
initialVersion.getMajorVersion(),
initialVersion.getIncrementalVersion() + 6));
if (majorVersion.hasStableApi()) {
assertTrue(updatedRange.containsVersion(afterStart));
} else {
assertFalse(updatedRange.containsVersion(afterStart));
}
}
示例5: pinDataflowDependencyToCurrent
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Sets the Dataflow Dependency of this model to the [current latest version, next major version).
*/
public void pinDataflowDependencyToCurrent(IProgressMonitor monitor) throws CoreException {
try {
VersionRange existingVersionRange = dependencyManager.getDataflowVersionRange(project);
ArtifactVersion version =
dependencyManager.getLatestDataflowDependencyInRange(existingVersionRange);
VersionRange newRange = MajorVersion.truncateAtLatest(version, existingVersionRange);
editPom(new SetDataflowDependencyVersion(newRange));
} catch (IOException e) {
throw new CoreException(
new Status(
Status.ERROR,
DataflowCorePlugin.PLUGIN_ID,
"Exception when trying to pin Dataflow Dependency",
e));
} finally {
monitor.done();
}
}
示例6: getDataflowVersionRange
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
public VersionRange getDataflowVersionRange(IProject project) {
Model model = getModelFromProject(project);
if (model != null) {
Dependency dependency = getDataflowDependencyFromModel(model);
if (dependency != null) {
String version = dependency.getVersion();
if (!Strings.isNullOrEmpty(version)) {
try {
return VersionRange.createFromVersionSpec(version);
} catch (InvalidVersionSpecificationException ex) {
String message =
String.format("Could not create version range from existing version %s", version);
throw new IllegalStateException(message, ex);
}
}
}
}
return allVersions();
}
示例7: getArtifact
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException, InvalidVersionSpecificationException {
Artifact artifact;
VersionRange vr = VersionRange.createFromVersionSpec(artifactItem.getVersion());
if (StringUtils.isEmpty(artifactItem.getClassifier())) {
artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
artifactItem.getType(), null, Artifact.SCOPE_COMPILE );
} else {
artifact = factory.createDependencyArtifact( artifactItem.getGroupId(), artifactItem.getArtifactId(), vr,
artifactItem.getType(), artifactItem.getClassifier(),
Artifact.SCOPE_COMPILE );
}
try {
resolver.resolve(artifact, remoteRepos, local);
} catch (ArtifactResolutionException | ArtifactNotFoundException e) {
throw new MojoExecutionException("Error resolving artifact "+artifact, e);
}
return artifact;
}
示例8: ensureEngineIsInstalled
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
private void ensureEngineIsInstalled() throws MojoExecutionException
{
VersionRange ivyVersionRange = getIvyVersionRange();
if (identifyAndGetEngineDirectory() == null)
{
handleNoInstalledEngine();
}
else
{
if (engineDirectoryIsEmpty())
{
getRawEngineDirectory().mkdirs();
}
ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory());
if (installedEngineVersion == null ||
!ivyVersionRange.containsVersion(installedEngineVersion))
{
handleWrongIvyVersion(installedEngineVersion);
}
}
}
示例9: getDependencies
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
private List<File> getDependencies() throws MojoExecutionException {
Set<Artifact> artifacts = new HashSet<>();
String version = props.getProperty("version");
String jettyVersion = props.getProperty("jettyVersion");
getLog().info("Resolving dependencies for version " + version +" of jetty-console-core");
artifacts.add(artifactFactory.createDependencyArtifact("org.simplericity.jettyconsole", "jetty-console-core", VersionRange.createFromVersion(version), "jar", null, "runtime"));
List<File> artifactFiles = new ArrayList<File>();
try {
ArtifactResolutionResult result = resolver.resolveTransitively(artifacts, project.getArtifact(), remoteRepositories, localRepository, artifactMetadataSource);
for(Artifact artifact : (Set<Artifact>) result.getArtifacts()) {
artifactFiles.add(artifact.getFile());
}
return artifactFiles;
} catch (ArtifactResolutionException | ArtifactNotFoundException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
示例10: testMojoLookup
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
public void testMojoLookup()
throws Exception
{
File pluginXml = new File( getBasedir(), "src/test/resources/linker/plugin-config-ranlib.xml" );
NativeRanlibMojo mojo = (NativeRanlibMojo) lookupMojo( "ranlib", pluginXml );
assertNotNull( mojo );
// simulate artifact
ArtifactHandler artifactHandler = new DefaultArtifactHandler();
Artifact artifact =
new DefaultArtifact( "test", "test", VersionRange.createFromVersion( "1.0-SNAPSHOT" ), "compile", "exe",
null, artifactHandler );
mojo.getProject().setArtifact( artifact );
mojo.execute();
}
示例11: resolveSnapshotVersion
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Determine the timestamp version of the snapshot dependency used in the build.
*
* @param dep
* @return The timestamp version if exists, otherwise the original snapshot dependency version is returned.
*/
private String resolveSnapshotVersion( Dependency dep )
{
getLog().debug( "Resolving snapshot version for dependency: " + dep );
String lockedVersion = dep.getVersion();
try
{
Artifact depArtifact =
artifactFactory.createDependencyArtifact( dep.getGroupId(), dep.getArtifactId(),
VersionRange.createFromVersionSpec( dep.getVersion() ),
dep.getType(), dep.getClassifier(), dep.getScope() );
resolver.resolve( depArtifact, getProject().getRemoteArtifactRepositories(), localRepository );
lockedVersion = depArtifact.getVersion();
}
catch ( Exception e )
{
getLog().error( e );
}
return lockedVersion;
}
示例12: findLatestVersion
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Finds the latest version of the specified artifact that matches the version range.
*
* @param artifact The artifact.
* @param versionRange The version range.
* @param allowingSnapshots <code>null</code> for no override, otherwise the local override to apply.
* @param usePluginRepositories
* @return The latest version of the specified artifact that matches the specified version range or
* <code>null</code> if no matching version could be found.
* @throws ArtifactMetadataRetrievalException If the artifact metadata could not be found.
* @since 1.0-alpha-1
*/
protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange,
Boolean allowingSnapshots, boolean usePluginRepositories )
throws ArtifactMetadataRetrievalException, MojoExecutionException
{
boolean includeSnapshots = this.allowSnapshots;
if ( Boolean.TRUE.equals( allowingSnapshots ) )
{
includeSnapshots = true;
}
if ( Boolean.FALSE.equals( allowingSnapshots ) )
{
includeSnapshots = false;
}
final ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( artifact, usePluginRepositories );
return artifactVersions.getNewestVersion( versionRange, includeSnapshots );
}
示例13: findLatestVersion
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Finds the latest version of the specified artifact that matches the version range.
*
* @param artifact The artifact.
* @param versionRange The version range.
* @param allowingSnapshots <code>null</code> for no override, otherwise the local override to apply.
* @return The latest version of the specified artifact that matches the specified version range or
* <code>null</code> if no matching version could be found.
* @throws MojoExecutionException If the artifact metadata could not be found.
* @since 1.0-alpha-1
*/
protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange,
boolean allowingSnapshots, boolean usePluginRepositories )
throws MavenReportException
{
boolean includeSnapshots = this.allowSnapshots;
if ( allowingSnapshots )
{
includeSnapshots = true;
}
if ( allowingSnapshots )
{
includeSnapshots = false;
}
try
{
final ArtifactVersions artifactVersions =
getHelper().lookupArtifactVersions( artifact, usePluginRepositories );
return artifactVersions.getNewestVersion( versionRange, includeSnapshots );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new MavenReportException( e.getMessage(), e );
}
}
示例14: isVersionOverlap
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
/**
* Checks if two versions or ranges have an overlap.
*
* @param leftVersionOrRange the 1st version number or range to test
* @param rightVersionOrRange the 2nd version number or range to test
* @return true if both versions have an overlap
* @throws InvalidVersionSpecificationException if the versions can't be parsed to a range
*/
public static boolean isVersionOverlap( String leftVersionOrRange, String rightVersionOrRange )
throws InvalidVersionSpecificationException
{
VersionRange pomVersionRange = createVersionRange( leftVersionOrRange );
if ( !pomVersionRange.hasRestrictions() )
{
return true;
}
VersionRange oldVersionRange = createVersionRange( rightVersionOrRange );
if ( !oldVersionRange.hasRestrictions() )
{
return true;
}
VersionRange result = oldVersionRange.restrict( pomVersionRange );
return result.hasRestrictions();
}
示例15: filterVersionsWithIncludes
import org.apache.maven.artifact.versioning.VersionRange; //導入依賴的package包/類
private ArtifactVersion[] filterVersionsWithIncludes( ArtifactVersion[] newer, Artifact artifact )
{
List<ArtifactVersion> filteredNewer = new ArrayList<>( newer.length );
for ( int j = 0; j < newer.length; j++ )
{
ArtifactVersion artifactVersion = newer[j];
Artifact artefactWithNewVersion =
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
VersionRange.createFromVersion( artifactVersion.toString() ), artifact.getScope(),
artifact.getType(), null, new DefaultArtifactHandler(), false );
if ( isIncluded( artefactWithNewVersion ) )
{
filteredNewer.add( artifactVersion );
}
}
return filteredNewer.toArray( new ArtifactVersion[filteredNewer.size()] );
}