org.apache.maven.artifact.versioning.ArtifactVersion Java Examples

The following examples show how to use org.apache.maven.artifact.versioning.ArtifactVersion. 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: ArtifactVersions.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
public ArtifactVersion[] getVersions( boolean includeSnapshots )
{
    Set<ArtifactVersion> result;
    if ( includeSnapshots )
    {
        result = versions;
    }
    else
    {
        result = new TreeSet<>( versionComparator );
        for ( ArtifactVersion candidate : versions )
        {
            if ( ArtifactUtils.isSnapshot( candidate.toString() ) )
            {
                continue;
            }
            result.add( candidate );
        }
    }
    return result.toArray( new ArtifactVersion[result.size()] );
}
 
Example #2
Source File: FixVersionConflictPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
FixDescription getResult() {
    FixDescription res = new FixDescription();
    res.isSet = addSetCheck.isSelected();
    res.version2Set = res.isSet ? (ArtifactVersion) versionList.getSelectedValue() : null;
    res.isExclude = excludeCheck.isSelected();
    if (res.isExclude) {
        res.exclusionTargets = new HashSet<Artifact>();
        res.conflictParents = new HashSet<MavenDependencyNode>();
        ListModel lm = excludesList.getModel();
        for (int i = 0; i < lm.getSize(); i++) {
            ExclTargetEntry entry = (ExclTargetEntry) lm.getElementAt(i);
            if (entry.isSelected) {
                res.exclusionTargets.add(entry.artif);
                res.conflictParents.addAll(eTargets.getConflictParents(entry.artif));
            }
        }
    }
    return res;
}
 
Example #3
Source File: AbstractVersionsReport.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 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 Use plugin repositories
 * @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 MavenReportException 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 );
    }
}
 
Example #4
Source File: ArtifactRetriever.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: PropertyVersions.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
private int innerCompare( ArtifactVersion v1, ArtifactVersion v2 )
{
    if ( !isAssociated() )
    {
        throw new IllegalStateException( "Cannot compare versions for a property with no associations" );
    }
    VersionComparator[] comparators = lookupComparators();
    assert comparators.length >= 1 : "we have at least one association => at least one comparator";
    int result = comparators[0].compare( v1, v2 );
    for ( int i = 1; i < comparators.length; i++ )
    {
        int alt = comparators[i].compare( v1, v2 );
        if ( result != alt && ( result >= 0 && alt < 0 ) || ( result <= 0 && alt > 0 ) )
        {
            throw new IllegalStateException( "Property " + name + " is associated with multiple artifacts"
                + " and these artifacts use different version sorting rules and these rules are effectively"
                + " incompatible for the two of versions being compared.\nFirst rule says compare(\"" + v1
                + "\", \"" + v2 + "\") = " + result + "\nSecond rule says compare(\"" + v1 + "\", \"" + v2
                + "\") = " + alt );
        }
    }
    return result;
}
 
Example #6
Source File: AbstractVersionsUpdaterMojo.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
protected void updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property,
                                              PropertyVersions version, String currentVersion,
                                              boolean allowDowngrade, int segment )
    throws MojoExecutionException, XMLStreamException
{
    ArtifactVersion winner =
        version.getNewestVersion( currentVersion, property, this.allowSnapshots, this.reactorProjects,
                                  this.getHelper(), allowDowngrade, segment );

    if ( winner == null || currentVersion.equals( winner.toString() ) )
    {
        getLog().info( "Property ${" + property.getName() + "}: Leaving unchanged as " + currentVersion );
    }
    else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), winner.toString() ) )
    {
        getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner );
    }
}
 
Example #7
Source File: JApiCmpMojo.java    From japicmp with Apache License 2.0 6 votes vote down vote up
private void filterVersionPattern(List<ArtifactVersion> availableVersions, PluginParameters pluginParameters) throws MojoFailureException {
	if (pluginParameters.getParameterParam() != null && pluginParameters.getParameterParam().getOldVersionPattern() != null) {
		String versionPattern = pluginParameters.getParameterParam().getOldVersionPattern();
		Pattern pattern;
		try {
			pattern = Pattern.compile(versionPattern);
		} catch (PatternSyntaxException e) {
			throw new MojoFailureException("Could not compile provided versionPattern '" + versionPattern + "' as regular expression: " + e.getMessage(), e);
		}
		for (Iterator<ArtifactVersion> versionIterator = availableVersions.iterator(); versionIterator.hasNext(); ) {
			ArtifactVersion version = versionIterator.next();
			Matcher matcher = pattern.matcher(version.toString());
			if (!matcher.matches()) {
				versionIterator.remove();
				if (getLog().isDebugEnabled()) {
					getLog().debug("Filtering version '" + version.toString() + "' because it does not match configured versionPattern '" + versionPattern + "'.");
				}
			}
		}
	} else {
		getLog().debug("Parameter <oldVersionPattern> not configured, i.e. no version filtered.");
	}
}
 
Example #8
Source File: MajorMinorIncrementalFilterTest.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void checkFilterWithSnapshotAtSameVersion() {
    ArtifactVersion selectedVersion = version("1.1.1-SNAPSHOT");
    MajorMinorIncrementalFilter filter = new MajorMinorIncrementalFilter(false, false, false);
    ArtifactVersion[] filteredVersions = filter.filter(selectedVersion,
                                                       new ArtifactVersion[] {version("1.1.1")});
    assertThat(filteredVersions, arrayContaining(version("1.1.1")));
}
 
Example #9
Source File: AbstractVersionDetails.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
public final ArtifactVersion getNewestVersion( VersionRange versionRange, ArtifactVersion lowerBound,
                                               ArtifactVersion upperBound, boolean includeSnapshots,
                                               boolean includeLower, boolean includeUpper )
{
    ArtifactVersion latest = null;
    final VersionComparator versionComparator = getVersionComparator();
    for ( ArtifactVersion candidate : getVersions( includeSnapshots ) )
    {
        if ( versionRange != null && !ArtifactVersions.isVersionInRange( candidate, versionRange ) )
        {
            continue;
        }
        int lower = lowerBound == null ? -1 : versionComparator.compare( lowerBound, candidate );
        int upper = upperBound == null ? +1 : versionComparator.compare( upperBound, candidate );
        if ( lower > 0 || upper < 0 )
        {
            continue;
        }
        if ( ( !includeLower && lower == 0 ) || ( !includeUpper && upper == 0 ) )
        {
            continue;
        }
        if ( !includeSnapshots && ArtifactUtils.isSnapshot( candidate.toString() ) )
        {
            continue;
        }
        if ( latest == null )
        {
            latest = candidate;
        }
        else if ( versionComparator.compare( latest, candidate ) < 0 )
        {
            latest = candidate;
        }

    }
    return latest;
}
 
Example #10
Source File: FixVersionConflictPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "FixVersionConflictPanel.addSetCheck.text={0} Direct Dependency",
    "FixVersionConflictPanel.excludeCheck.text=Exclude Transitive Dependency"
})
private void visualizeRecommendations(FixDescription recs) {
    addSetCheck.setText(FixVersionConflictPanel_addSetCheck_text(getSetText()));
    addSetCheck.setSelected(recs.isSet);
    addSetCheckChanged();

    List<ArtifactVersion> versions = getClashingVersions();
    DefaultListModel model = new DefaultListModel();
    for (ArtifactVersion av : versions) {
        model.addElement(av);
    }
    versionList.setModel(model);
    versionList.setSelectedIndex(0);

    if (recs.version2Set != null) {
        versionList.setSelectedValue(recs.version2Set, true);
    }

    excludeCheck.setText(FixVersionConflictPanel_excludeCheck_text());
    excludeCheck.setSelected(recs.isExclude);
    excludeCheckChanged();

    Set<Artifact> exclTargets = eTargets.getAll();
    if (!exclTargets.isEmpty()) {
        DefaultListModel lModel = new DefaultListModel();
        for (Artifact exc : exclTargets) {
            lModel.addElement(new ExclTargetEntry(exc,
                    recs.exclusionTargets != null && recs.exclusionTargets.contains(exc)));
        }
        excludesList.setModel(lModel);
    } else {
        excludeCheck.setEnabled(false);
    }

    updateSummary();
}
 
Example #11
Source File: UpdateScope.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ArtifactVersion getNewestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion,
                                        boolean includeSnapshots )
{
    VersionComparator versionComparator = versionDetails.getVersionComparator();
    return versionComparator.getSegmentCount( currentVersion ) < 3 ? null
                    : versionDetails.getNewestVersion( currentVersion,
                                                       versionComparator.incrementSegment( currentVersion, 2 ),
                                                       includeSnapshots, false, false );
}
 
Example #12
Source File: UpdateScope.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ArtifactVersion getOldestUpdate( VersionDetails versionDetails, ArtifactVersion currentVersion,
                                        boolean includeSnapshots )
{
    VersionComparator versionComparator = versionDetails.getVersionComparator();
    return versionComparator.getSegmentCount( currentVersion ) < 2 ? null
                    : versionDetails.getOldestVersion( versionComparator.incrementSegment( currentVersion, 1 ),
                                                       versionComparator.incrementSegment( currentVersion, 0 ),
                                                       includeSnapshots, true, false );
}
 
Example #13
Source File: DataflowDependencyManagerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDataflowDependencyNoTrackNoVersionInRangeDependsOnMajorVersionRange() {
  when(artifactRetriever.getLatestReleaseVersion(DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID, MajorVersion.TWO.getVersionRange()))
      .thenReturn(null);

  ArtifactVersion version =
      manager.getLatestDataflowDependencyInRange(MajorVersion.TWO.getVersionRange());

  assertNull(version);
}
 
Example #14
Source File: RequiredMavenVersionFinder.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
ArtifactVersion find() {
    ArtifactVersion childMavenVersion = getHighestArtifactVersion(getPrerequisitesMavenVersion(), getEnforcerMavenVersion());

    if (!mavenProject.hasParent()) {
        return childMavenVersion;
    }

    ArtifactVersion parentMavenVersion = new RequiredMavenVersionFinder(mavenProject.getParent()).find();

    return getHighestArtifactVersion(childMavenVersion, parentMavenVersion);
}
 
Example #15
Source File: RequiredMavenVersionFinder.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getPrerequisitesMavenVersion() {
    Prerequisites prerequisites = mavenProject.getPrerequisites();
    if (null == prerequisites) {
        return null;
    }

    String prerequisitesMavenValue = prerequisites.getMaven();
    if (null == prerequisitesMavenValue) {
        return null;
    }

    return new DefaultArtifactVersion(prerequisitesMavenValue);
}
 
Example #16
Source File: ArtifactVersions.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #17
Source File: ArtifactRetrieverIntegrationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetLatestArtifactVersion() {
  ArtifactVersion version = ArtifactRetriever.DEFAULT.getLatestVersion(
      "com.google.cloud", "google-cloud-dns");
  Assert.assertNotNull(version);
  
  // version 0.26 or later
  Assert.assertTrue(version.getMajorVersion() > 0 || version.getMinorVersion() > 25);
}
 
Example #18
Source File: ArtifactRetrieverIntegrationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBestVersion() {
  ArtifactVersion version = ArtifactRetriever.DEFAULT.getBestVersion(
      "com.google.cloud", "google-cloud-dns");
  Assert.assertNotNull(version);
  
  // version 0.26 or later
  Assert.assertTrue(version.getMajorVersion() > 0 || version.getMinorVersion() > 25);
}
 
Example #19
Source File: AbstractVersionDetails.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
public final ArtifactVersion[] getVersions( VersionRange versionRange, ArtifactVersion lowerBound,
                                            ArtifactVersion upperBound, boolean includeSnapshots,
                                            boolean includeLower, boolean includeUpper )
{
    final VersionComparator versionComparator = getVersionComparator();
    Set<ArtifactVersion> result = new TreeSet<>( versionComparator );
    for ( ArtifactVersion candidate : Arrays.asList( getVersions( includeSnapshots ) ) )
    {
        if ( versionRange != null && !ArtifactVersions.isVersionInRange( candidate, versionRange ) )
        {
            continue;
        }
        int lower = lowerBound == null ? -1 : versionComparator.compare( lowerBound, candidate );
        int upper = upperBound == null ? +1 : versionComparator.compare( upperBound, candidate );
        if ( lower > 0 || upper < 0 )
        {
            continue;
        }
        if ( ( !includeLower && lower == 0 ) || ( !includeUpper && upper == 0 ) )
        {
            continue;
        }
        if ( !includeSnapshots && ArtifactUtils.isSnapshot( candidate.toString() ) )
        {
            continue;
        }
        result.add( candidate );
    }
    return result.toArray( new ArtifactVersion[result.size()] );
}
 
Example #20
Source File: MinimumVersionAgentMetadataInspector.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public InspectionReport inspect(@Valid final AgentClientMetadata agentClientMetadata) {

    final String minimumVersionString = this.agentFilterProperties.getMinimumVersion();
    final String agentVersionString = agentClientMetadata.getVersion().orElse(null);

    if (StringUtils.isBlank(minimumVersionString)) {
        return InspectionReport.newAcceptance("Minimum version requirement not set");

    } else if (StringUtils.isBlank(agentVersionString)) {
        return InspectionReport.newRejection("Agent version not set");

    } else {
        final ArtifactVersion minimumVersion = new DefaultArtifactVersion(minimumVersionString);
        final ArtifactVersion agentVersion = new DefaultArtifactVersion(agentVersionString);

        final boolean deprecated = minimumVersion.compareTo(agentVersion) > 0;

        return new InspectionReport(
            deprecated ? InspectionReport.Decision.REJECT : InspectionReport.Decision.ACCEPT,
            String.format(
                "Agent version: %s is %s than minimum: %s",
                agentVersionString,
                deprecated ? "older" : "newer or equal",
                minimumVersionString
            )
        );
    }
}
 
Example #21
Source File: DataflowProjectCreator.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion defaultArchetypeVersion(DataflowProjectArchetype template,
    MajorVersion version) {
  checkArgument(template.getSdkVersions().contains(majorVersion));

  String artifactId = template.getArtifactId();
  ArtifactVersion latestArchetype = ArtifactRetriever.DEFAULT.getLatestReleaseVersion(
      DataflowMavenCoordinates.GROUP_ID, artifactId, majorVersion.getVersionRange());

  return latestArchetype == null ? version.getInitialVersion() : latestArchetype;
}
 
Example #22
Source File: AbstractCompileMojo.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void ensureSARLVersions() throws MojoExecutionException, MojoFailureException {
	final String compilerVersionString = this.mavenHelper.getConfig("plugin.version"); //$NON-NLS-1$
	final ArtifactVersion compilerVersion = new DefaultArtifactVersion(compilerVersionString);
	final ArtifactVersion maxCompilerVersion = new DefaultArtifactVersion(
			compilerVersion.getMajorVersion() + "." //$NON-NLS-1$
			+ (compilerVersion.getMinorVersion() + 1)
			+ ".0"); //$NON-NLS-1$
	getLog().info(MessageFormat.format(Messages.CompileMojo_0, compilerVersionString, maxCompilerVersion));
	final StringBuilder classpath = new StringBuilder();
	final Set<String> foundVersions = findSARLLibrary(compilerVersion, maxCompilerVersion, classpath,
			this.tycho);
	if (foundVersions.isEmpty()) {
		throw new MojoFailureException(MessageFormat.format(Messages.CompileMojo_1, classpath.toString()));
	}
	final StringBuilder versions = new StringBuilder();
	for (final String version : foundVersions) {
		if (versions.length() > 0) {
			versions.append(", "); //$NON-NLS-1$
		}
		versions.append(version);
	}
	if (foundVersions.size() > 1) {
		getLog().info(MessageFormat.format(Messages.CompileMojo_2, versions));
	} else {
		getLog().info(MessageFormat.format(Messages.CompileMojo_3, versions));
	}
}
 
Example #23
Source File: DataflowDependencyManager.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves a dependency on the Dataflow Java SDK or null if there is no version in the range.
 * The version is [Current Version, Next Major Version).
 */
public ArtifactVersion getLatestDataflowDependencyInRange(VersionRange currentVersionRange) {
  return artifactRetriever.getLatestReleaseVersion(
      DataflowMavenCoordinates.GROUP_ID,
      DataflowMavenCoordinates.ARTIFACT_ID,
      currentVersionRange);
}
 
Example #24
Source File: VersionUtil.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static String findNearestVersionTagsBefore(Collection<String> versionTagList, String versionTagNamePart) {

    Map<ArtifactVersion, String> map = new HashMap<ArtifactVersion, String>();

    for (String versionTag : versionTagList) {
        map.put(parseArtifactVersion(versionTag), versionTag);
    }

    ArtifactVersion currentVersion = parseArtifactVersion(versionTagNamePart);

    List<ArtifactVersion> sortedList = new ArrayList<>(map.keySet());

    Collections.sort(sortedList);

    //the index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1).
    int index = Collections.binarySearch(sortedList, currentVersion, null);

    if (index >= 0) {
        return map.get(sortedList.get(index));
    }
    if (sortedList.size() > 0) {
        if (-index-2>=0) {
            return map.get(sortedList.get(-index - 2));
        }
        else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example #25
Source File: DataflowDependencyManager.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the latest version for each provided major version if it is available.
 *
 * <p>For each provided version, if there is an available version within the major version range
 * and {@link MajorVersion#hasStableApi()} returns true, or
 * {@link MajorVersion#getStableVersion()} is not in the list of requested versions, that version
 * will appear in the returned map. Otherwise, if the {@link MajorVersion#hasStableApi()} returns
 * false and there is no available version for {@link MajorVersion#getStableVersion()}, the latest
 * version in the Unstable version range will be returned.
 */
public NavigableMap<ArtifactVersion, MajorVersion> getLatestVersions(
    NavigableSet<MajorVersion> majorVersions) {
  NavigableMap<ArtifactVersion, MajorVersion> result = new TreeMap<>();
  Table<MajorVersion, ArtifactVersion, MajorVersion> unstableVersions = HashBasedTable.create();
  for (MajorVersion majorVersion : majorVersions) {
    ArtifactVersion latestInMajorVersion =
        getLatestDataflowDependencyInRange(majorVersion.getVersionRange());
    if (latestInMajorVersion != null) {
      if (majorVersion.hasStableApi()
          || !majorVersions.contains(majorVersion.getStableVersion())) {
        result.put(latestInMajorVersion, majorVersion);
      } else {
        unstableVersions.put(majorVersion.getStableVersion(), latestInMajorVersion, majorVersion);
      }
    } else {
      // All Major Versions that are unstable and have an associated stable version precede the
      // stable major version with the natural ordering, so we will never get a stable version
      // before the unstable versions
      for (Map.Entry<ArtifactVersion, MajorVersion> unstableVersion :
          unstableVersions.row(majorVersion).entrySet()) {
        result.put(unstableVersion.getKey(), unstableVersion.getValue());
      }
    }
  }
  if (result.isEmpty()) {
    result.put(new DefaultArtifactVersion("LATEST"), MajorVersion.ALL);
  }
  return result;
}
 
Example #26
Source File: UpdateScope.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Classifies the type of update.
 *
 * @param comparator The version comparator to use for classifying.
 * @param from The first version.
 * @param to The second version.
 * @return The update classification.
 */
public static UpdateScope classifyUpdate( VersionComparator comparator, ArtifactVersion from, ArtifactVersion to )
{
    if ( comparator.compare( from, to ) >= 0 )
    {
        throw new IllegalArgumentException( "From version must be less than to version" );
    }
    // the trick here is that incrementing from twice and to once, should give the same version
    int matchSegment = 0;
    for ( int segment =
        Math.min( comparator.getSegmentCount( from ), comparator.getSegmentCount( to ) ); segment > 0; segment-- )
    {
        ArtifactVersion f = comparator.incrementSegment( from, segment - 1 );
        f = comparator.incrementSegment( f, segment - 1 );
        ArtifactVersion t = comparator.incrementSegment( to, segment - 1 );
        if ( f.toString().equals( t.toString() ) )
        {
            matchSegment = segment;
            break;
        }
    }
    switch ( matchSegment )
    {
        case 0:
            return MAJOR;
        case 1:
            return MINOR;
        case 2:
            return INCREMENTAL;
        default:
            return SUBINCREMENTAL;
    }
}
 
Example #27
Source File: VersionUtil.java    From phantomjs-maven-plugin with MIT License 5 votes vote down vote up
private static boolean isWithin(String version, VersionRange versionRange) {
  ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);
  boolean within = false;
  if (versionRange != null) {
    ArtifactVersion recommendedVersion = versionRange.getRecommendedVersion();
    // treat recommended version as minimum version
    within = recommendedVersion != null ?
      VersionUtil.isLessThanOrEqualTo(recommendedVersion, artifactVersion) :
      versionRange.containsVersion(artifactVersion);
  }
  return within;
}
 
Example #28
Source File: AbstractGenerateOsgiManifestMojo.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static PackageTally definedPackages(JarFile jarFile, ArtifactVersion version) throws MojoExecutionException {
    List<ClassFileMetaData> analyzedClasses = new ArrayList<>();
    for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
        JarEntry entry = entries.nextElement();
        if (! entry.isDirectory() && entry.getName().endsWith(".class")) {
            analyzedClasses.add(analyzeClass(jarFile, entry, version));
        }
    }
    return PackageTally.fromAnalyzedClassFiles(analyzedClasses);
}
 
Example #29
Source File: BasicPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ArtifactVersion getCommandLineMavenVersion () {
    synchronized (MAVEN_VERSION_LOCK) {
        if (!askedForVersion) {
            askedForVersion = true;
            // obtain version asynchronously, as it takes some time
            RPgetver.post(this);
        }
        return mavenVersion;
    }
}
 
Example #30
Source File: ArtifactRetrieverIntegrationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGuava() {
  ArtifactVersion guava =
      ArtifactRetriever.DEFAULT.getLatestReleaseVersion("com.google.guava", "guava");
  Assert.assertTrue(guava.getMajorVersion() > 19);
  Assert.assertTrue(guava.getMinorVersion() >= 0);
  Assert.assertNull(guava.getQualifier());
}