org.eclipse.aether.version.InvalidVersionSpecificationException Java Examples

The following examples show how to use org.eclipse.aether.version.InvalidVersionSpecificationException. 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: RepositoryUtilityTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindHighestVersions()
    throws MavenRepositoryException, InvalidVersionSpecificationException {
  RepositorySystem system = RepositoryUtility.newRepositorySystem();

  // FindHighestVersion should work for both jar and pom (extension:pom) artifacts
  for (String artifactId : ImmutableList.of("guava", "guava-bom")) {
    String guavaHighestVersion =
        RepositoryUtility.findHighestVersion(
            system, RepositoryUtility.newSession(system), "com.google.guava", artifactId);
    Assert.assertNotNull(guavaHighestVersion);

    // Not comparing alphabetically; otherwise "100.0" would be smaller than "28.0"
    VersionScheme versionScheme = new GenericVersionScheme();
    Version highestGuava = versionScheme.parseVersion(guavaHighestVersion);
    Version guava28 = versionScheme.parseVersion("28.0");

    Truth.assertWithMessage("Latest guava release is greater than or equal to 28.0")
        .that(highestGuava)
        .isAtLeast(guava28);
  }
}
 
Example #2
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Turns the list of dependencies into a simple dependency tree
 */
public DependencyResult toDependencyTree(List<Dependency> deps, List<RemoteRepository> mainRepos)
        throws BootstrapMavenException {
    DependencyResult result = new DependencyResult(
            new DependencyRequest().setCollectRequest(new CollectRequest(deps, Collections.emptyList(), mainRepos)));
    DefaultDependencyNode root = new DefaultDependencyNode((Dependency) null);
    result.setRoot(root);
    GenericVersionScheme vs = new GenericVersionScheme();
    for (Dependency i : deps) {
        DefaultDependencyNode node = new DefaultDependencyNode(i);
        try {
            node.setVersionConstraint(vs.parseVersionConstraint(i.getArtifact().getVersion()));
            node.setVersion(vs.parseVersion(i.getArtifact().getVersion()));
        } catch (InvalidVersionSpecificationException e) {
            throw new RuntimeException(e);
        }
        root.getChildren().add(node);
    }
    return result;
}
 
Example #3
Source File: VersionUtils.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
public static void validateRugCompatibility(ArtifactDescriptor artifact,
        List<ArtifactDescriptor> dependencies) {
    Optional<ArtifactDescriptor> rugArtifact = dependencies.stream()
            .filter(f -> f.group().equals(Constants.GROUP)
                    && f.artifact().equals(Constants.RUG_ARTIFACT))
            .findAny();
    if (rugArtifact.isPresent()) {
        try {
            Version version = VERSION_SCHEME.parseVersion(rugArtifact.get().version());
            VersionRange range = VERSION_SCHEME.parseVersionRange(Constants.RUG_VERSION_RANGE);
            if (!range.containsVersion(version)) {
                throw new VersionException(String.format(
                        "Installed version of Rug CLI is not compatible with archive %s.\n\n"
                                + "The archive depends on %s:%s (%s) which is incompatible with Rug CLI (compatible version range %s).\n"
                                + "Please update to a more recent version of Rug CLI or change the Rug archive to use a supported Rug version.",
                        ArtifactDescriptorUtils.coordinates(artifact), Constants.GROUP,
                        Constants.RUG_ARTIFACT, version.toString(), range.toString()));
            }
        }
        catch (InvalidVersionSpecificationException e) {
            // Since we were able to resolve the version it is impossible for this to happen
        }
    }
}
 
Example #4
Source File: Plugin.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean isValid() {
  // we need to ensure parseCreole() has been called before we can know if the
  // valid flag is .... valid
  getResourceInfoList();
  
  //Main.version
  if (Gate.VERSION == null || minGateVersion == null || minGateVersion.isEmpty()) {
    Utils.logOnce(log, Level.DEBUG,
        "unable to check minimum GATE version, plugins may not load or might produce errors");
    return valid;
  }
  
  try {
    Version pluginVersion = versionScheme.parseVersion(minGateVersion);
    
    boolean validGateVersion = Gate.VERSION.compareTo(pluginVersion) >= 0;
    
    if(!validGateVersion) {
      Utils.logOnce(log, Level.WARN,
          getName()
          + " is not compatible with this version of GATE, requires at least GATE"
          + pluginVersion.toString());
    }
    
    valid = valid && validGateVersion; 
  } catch(InvalidVersionSpecificationException e) {
    Utils.logOnce(log, Level.DEBUG,
        "unable to parse minimum GATE version, plugin, " + getName()
            + ", may not load or might produce errors");
  }
  
  return valid;
}
 
Example #5
Source File: VersionUtils.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
public static Optional<String> newerVersion() {
    try {
        VersionScheme scheme = new GenericVersionScheme();
        Version runningVersion = scheme.parseVersion(readVersion().orElse("0.0.0"));
        Version onlineVersion = scheme.parseVersion(readOnlineVersion().orElse("0.0.0"));
        return (onlineVersion.compareTo(runningVersion) > 0
                ? Optional.of(onlineVersion.toString())
                : Optional.empty());
    }
    catch (InvalidVersionSpecificationException e) {
    }
    return Optional.empty();
}
 
Example #6
Source File: VersionUtils.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
public static Version parseVersion(String version) {
    try {
        return VERSION_SCHEME.parseVersion(version);
    }
    catch (InvalidVersionSpecificationException e) {
        throw new CommandException(
                String.format("Unable to parse version number '%s'", version), e);
    }
}
 
Example #7
Source File: MetadataBuilder.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void addBaseVersion(final String baseVersion) {
  checkNotNull(baseVersion);
  try {
    if (baseVersions.add(versionScheme.parseVersion(baseVersion))) {
      log.debug("Added base version {}:{}:{}", groupId, artifactId, baseVersion);
    }
  }
  catch (InvalidVersionSpecificationException e) {
    // According to versionScheme implementation we use, this exception will never happen
    // log + ignore
    log.info("Invalid baseVersion discovered: " + baseVersion, e);
  }
}
 
Example #8
Source File: MetadataBuilder.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
private Version parseVersion(final String version) {
  try {
    return versionScheme.parseVersion(version);
  }
  catch (InvalidVersionSpecificationException e) {
    log.warn("Invalid version: {}", version, e);
    return null;
  }
}
 
Example #9
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 #10
Source File: ExtensionCommand.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
private boolean verifyVersionRange(ArtifactDescriptor extension,
        List<ArtifactDescriptor> dependencies) {
    Optional<ArtifactDescriptor> cliDependency = dependencies.stream().filter(
            d -> d.group().equals(Constants.GROUP) && d.artifact().equals(Constants.ARTIFACT))
            .findFirst();

    if (cliDependency.isPresent()) {
        try {
            VersionScheme scheme = new GenericVersionScheme();
            VersionConstraint constraint = scheme
                    .parseVersionConstraint(cliDependency.get().version());
            Version cliVersion = scheme.parseVersion(VersionUtils.readVersion().get());
            if (constraint.containsVersion(cliVersion)) {
                return true;
            }
            else {
                if (cliVersion.toString().endsWith("-SNAPSHOT")) {
                    Version cliSnapshotVersion = scheme.parseVersion(
                            StringUtils.removeEnd(cliVersion.toString(), "-SNAPSHOT"));
                    if (constraint.containsVersion(cliSnapshotVersion)) {
                        log.warn(
                                "Assuming this CLI SNAPSHOT is compatible with the extension...",
                                extension.group(), extension.artifact(), extension.version(),
                                constraint.toString(), Constants.GROUP, Constants.ARTIFACT,
                                cliVersion);
                        return true;
                    }
                }
                log.warn("Extension %s:%s (%s) requires %s of %s:%s, but current version is %s",
                        extension.group(), extension.artifact(), extension.version(),
                        constraint.toString(), Constants.GROUP, Constants.ARTIFACT, cliVersion);
                return false;

            }
        }
        catch (InvalidVersionSpecificationException e) {
            // This will be captured earlier when resolving the dependencies.
        }
    }
    return true;
}