Java Code Examples for org.eclipse.aether.resolution.VersionRangeResult#getVersions()

The following examples show how to use org.eclipse.aether.resolution.VersionRangeResult#getVersions() . 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: UpgradeXGAPP.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Version getDefaultSelection(VersionRangeResult vrr) {
  if(vrr == null) {
    return null;
  }
  List<Version> versions = vrr.getVersions();
  // is the version of GATE we are running a SNAPSHOT?
  boolean isSnapshot = Main.version.toUpperCase().endsWith("-SNAPSHOT");

  int i = versions.size() - 1;

  while(i >= 0 && !isSnapshot) {
    // if GATE isn't a SNAPSHOT then work back through the versions until...
    Version v = versions.get(i);
    if(!v.toString().toUpperCase().endsWith("-SNAPSHOT")) {
      // we find one that isn't a SNAPSHOT
      return v;
    }

    --i;
  }

  // either GATE is a SNAPSHOT release or all the versions are SNAPSHOTS and
  // in either case we just return the latest
  return versions.get(versions.size() - 1);
}
 
Example 2
Source File: SdkResolver.java    From appengine-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static String determineNewestVersion(RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository>[] repos) throws MojoExecutionException {
  String version;VersionRangeRequest rangeRequest = new VersionRangeRequest();
  rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)"));
  for(List<RemoteRepository> repoList : repos) {
    for(RemoteRepository repo : repoList) {
      rangeRequest.addRepository(repo);
    }
  }

  VersionRangeResult rangeResult;
  try {
    rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest);
  } catch (VersionRangeResolutionException e) {
    throw new MojoExecutionException("Could not resolve latest version of the App Engine Java SDK", e);
  }

  List<Version> versions = rangeResult.getVersions();

  Collections.sort(versions);

  Version newest = Iterables.getLast(versions);

  version = newest.toString();
  return version;
}
 
Example 3
Source File: AbstractMavenArtifactRepositoryManager.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAllVersions(MavenArtifact mavenArtifact, Pattern includeVersion, Pattern excludeVersion) throws MavenUniverseException {
    Artifact artifact = new DefaultArtifact(mavenArtifact.getGroupId(),
            mavenArtifact.getArtifactId(), mavenArtifact.getExtension(), mavenArtifact.getVersionRange());
    VersionRangeResult rangeResult = getVersionRange(artifact);
    List<String> versions = new ArrayList<>();
    for (Version v : rangeResult.getVersions()) {
        String vString = v.toString();
        if ((includeVersion == null || includeVersion.matcher(vString).matches())
            && (excludeVersion == null || !excludeVersion.matcher(vString).matches())) {
            versions.add(vString);
        }
    }
    return versions;
}
 
Example 4
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> listLaterVersions(AppArtifact appArtifact, String upToVersion, boolean inclusive)
        throws AppModelResolverException {
    final VersionRangeResult rangeResult = resolveVersionRangeResult(appArtifact, appArtifact.getVersion(), false,
            upToVersion, inclusive);
    final List<Version> resolvedVersions = rangeResult.getVersions();
    final List<String> versions = new ArrayList<>(resolvedVersions.size());
    for (Version v : resolvedVersions) {
        versions.add(v.toString());
    }
    return versions;
}
 
Example 5
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private String getEarliest(final VersionRangeResult rangeResult) {
    final List<Version> versions = rangeResult.getVersions();
    if (versions.isEmpty()) {
        return null;
    }
    Version next = versions.get(0);
    for (int i = 1; i < versions.size(); ++i) {
        final Version candidate = versions.get(i);
        if (next.compareTo(candidate) > 0) {
            next = candidate;
        }
    }
    return next.toString();
}
 
Example 6
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private String getLatest(final VersionRangeResult rangeResult) {
    final List<Version> versions = rangeResult.getVersions();
    if (versions.isEmpty()) {
        return null;
    }
    Version next = versions.get(0);
    for (int i = 1; i < versions.size(); ++i) {
        final Version candidate = versions.get(i);
        if (candidate.compareTo(next) > 0) {
            next = candidate;
        }
    }
    return next.toString();
}
 
Example 7
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  UpgradeXGAPP.UpgradePath path = upgrades.get(rowIndex);
  if(columnIndex == 1) {
    PluginCoordinates coords = (PluginCoordinates)aValue;
    VersionRangeResult vrr = UpgradeXGAPP.getPluginVersions(coords.groupId, coords.artifactId);
    List<Version> versions = (vrr == null ? null : vrr.getVersions());
    if(versions != null && !versions.isEmpty()) {
      path.setGroupID(coords.groupId);
      path.setArtifactID(coords.artifactId);
      path.setVersionRangeResult(vrr);
      path.setUpgradeStrategy(UpgradeXGAPP.UpgradePath.UpgradeStrategy.UPGRADE);
      fireTableCellUpdated(rowIndex, 2);
      if(!versions.contains(path.getSelectedVersion())) {
        path.setSelectedVersion(UpgradeXGAPP.getDefaultSelection(vrr));
        fireTableCellUpdated(rowIndex, 3);
      }
    } else {
      statusLabel.setIcon(warningIcon);
      statusLabel.setText(coords + " is not a valid GATE plugin");
    }
  } else if(columnIndex == 2) {
    path.setUpgradeStrategy((UpgradeXGAPP.UpgradePath.UpgradeStrategy) aValue);
    // may need to re-render the version column
    fireTableCellUpdated(rowIndex, 3);
  } else if(columnIndex == 3) {
    path.setSelectedVersion((Version) aValue);
  }
}
 
Example 8
Source File: ArtifactResolver.java    From revapi with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to find the newest version of the artifact that matches given regular expression.
 * The found version will be older than the {@code upToVersion} or newest available if {@code upToVersion} is null.
 *
 * @param gav the coordinates of the artifact. The version part is ignored
 * @param upToVersion the version up to which the versions will be matched
 * @param versionMatcher the matcher to match the version
 * @param remoteOnly true if only remotely available artifacts should be considered
 * @param upToInclusive whether the {@code upToVersion} should be considered inclusive or exclusive
 * @return the resolved artifact
 */
public Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher,
                                      boolean remoteOnly, boolean upToInclusive)
        throws VersionRangeResolutionException, ArtifactResolutionException {


    Artifact artifact = new DefaultArtifact(gav);
    artifact = artifact.setVersion(upToVersion == null ? "[,)" : "[," + upToVersion + (upToInclusive ? "]" : ")"));
    VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);

    RepositorySystemSession session = remoteOnly ? makeRemoteOnly(this.session) : this.session;

    VersionRangeResult result = repositorySystem.resolveVersionRange(session, rangeRequest);

    List<Version> versions = new ArrayList<>(result.getVersions());
    Collections.reverse(versions);

    for(Version v : versions) {
        if (versionMatcher.matcher(v.toString()).matches()) {
            return resolveArtifact(artifact.setVersion(v.toString()), session);
        }
    }

    throw new VersionRangeResolutionException(result) {
        @Override
        public String getMessage() {
            return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '"
                    + versionMatcher + "'. The versions found were: " + versions;
        }
    };
}
 
Example 9
Source File: SdkResolver.java    From gcloud-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static String determineNewestVersion(RepositorySystem repoSystem,
    RepositorySystemSession repoSession, List<RemoteRepository>[] repos)
    throws MojoExecutionException {
  String version;
  VersionRangeRequest rangeRequest = new VersionRangeRequest();
  rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)"));
  for (List<RemoteRepository> repoList : repos) {
    for (RemoteRepository repo : repoList) {
      rangeRequest.addRepository(repo);
    }
  }

  VersionRangeResult rangeResult;
  try {
    rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest);
  } catch (VersionRangeResolutionException e) {
    throw new MojoExecutionException(
        "Could not resolve latest version of the App Engine Java SDK", e);
  }

  List<Version> versions = rangeResult.getVersions();

  Collections.sort(versions);

  Version newest = Iterables.getLast(versions);

  version = newest.toString();
  return version;
}
 
Example 10
Source File: DependencyResolver.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public List<Version> getVersions(Artifact artifact) throws VersionRangeResolutionException {
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(repositories);

    VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);

    List<Version> versions = new ArrayList<Version>(rangeResult.getVersions());
    Collections.sort(versions);

    return versions;
}
 
Example 11
Source File: UpgradeXGAPP.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<UpgradePath> suggest(Document doc)
    throws IOException, JDOMException {

  List<UpgradePath> upgrades = new ArrayList<UpgradePath>();

  Element root = doc.getRootElement();

  Element pluginList = root.getChild("urlList").getChild("localList");

  List<Element> plugins = pluginList.getChildren();

  Iterator<Element> it = plugins.iterator();
  while(it.hasNext()) {
    Element plugin = it.next();

    VersionRangeResult versions;

    switch(plugin.getName()){
      case "gate.util.persistence.PersistenceManager-URLHolder":
        String urlString = plugin.getChild("urlString").getValue();
        String[] parts = urlString.split("/");

        String oldName = parts[parts.length - 1];
        String newName = mapDirectoryNameToPlugin(oldName);

        versions = getPluginVersions("uk.ac.gate.plugins", newName);

        upgrades
            .add(new UpgradePath(plugin, urlString, (versions == null ? null : "uk.ac.gate.plugins"),
                newName, versions, null, getDefaultSelection(versions)));
        break;

      case "gate.creole.Plugin-Maven":

        String group = plugin.getChild("group").getValue();
        String artifact = plugin.getChild("artifact").getValue();
        String version = plugin.getChild("version").getValue();

        String oldCreoleURI =
            "creole://" + group + ";" + artifact + ";" + version + "/";

        versions = getPluginVersions(group, artifact);

        if(versions != null && versions.getVersions() != null && !versions.getVersions().isEmpty()) {
          Version currentVersion;
          try {
            currentVersion = versionScheme.parseVersion(version);
            upgrades
                .add(new UpgradePath(plugin, oldCreoleURI, group, artifact,
                    versions, currentVersion, getDefaultSelection(versions)));
          } catch(InvalidVersionSpecificationException e) {
            // this should be impossible as the version string comes from an
            // xgapp generated having successfully loaded a plugin
          }
        }

        break;
      default:
        // some unknown plugin type
        break;
    }
  }

  return upgrades;
}
 
Example 12
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Response<AddonId[]> resolveVersions(final String addonName)
{
   String addonNameSplit;
   String version;

   String[] split = addonName.split(",");
   if (split.length == 2)
   {
      addonNameSplit = split[0];
      version = split[1];
   }
   else
   {
      addonNameSplit = addonName;
      version = null;
   }
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   VersionRangeResult versions = getVersions(system, settings, session, repositories, addonNameSplit, version);
   List<Exception> exceptions = versions.getExceptions();
   List<Version> versionsList = versions.getVersions();
   List<AddonId> addons = new ArrayList<AddonId>();
   List<AddonId> snapshots = new ArrayList<AddonId>();
   for (Version artifactVersion : versionsList)
   {
      AddonId addonId = AddonId.from(addonName, artifactVersion.toString());
      if (Versions.isSnapshot(addonId.getVersion()))
      {
         snapshots.add(addonId);
      }
      else
      {
         addons.add(addonId);
      }
   }
   if (addons.isEmpty())
   {
      addons = snapshots;
   }
   return new MavenResponseBuilder<AddonId[]>(addons.toArray(new AddonId[addons.size()])).setExceptions(exceptions);
}