Java Code Examples for org.eclipse.aether.artifact.Artifact#setVersion()

The following examples show how to use org.eclipse.aether.artifact.Artifact#setVersion() . 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: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void processPlatformArtifact(DependencyNode node, Path descriptor) throws BootstrapDependencyProcessingException {
    final Properties rtProps = resolveDescriptor(descriptor);
    if (rtProps == null) {
        return;
    }
    final String value = rtProps.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT);
    appBuilder.handleExtensionProperties(rtProps, node.getArtifact().toString());
    if (value == null) {
        return;
    }
    Artifact deploymentArtifact = toArtifact(value);
    if (deploymentArtifact.getVersion() == null || deploymentArtifact.getVersion().isEmpty()) {
        deploymentArtifact = deploymentArtifact.setVersion(node.getArtifact().getVersion());
    }
    node.setData(QUARKUS_DEPLOYMENT_ARTIFACT, deploymentArtifact);
    runtimeNodes.add(node);
    Dependency dependency = new Dependency(node.getArtifact(), JavaScopes.COMPILE);
    runtimeExtensionDeps.add(dependency);
    managedDeps.add(new Dependency(deploymentArtifact, JavaScopes.COMPILE));
}
 
Example 2
Source File: DependencyGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of updates indicating desired updates formatted for a person to read.
 */
public List<Update> findUpdates() {
  List<DependencyPath> paths = findConflicts();
  
  // now generate necessary upgrades
  LinkedHashSet<Update> upgrades = new LinkedHashSet<>();
  for (DependencyPath path : paths) {
    Artifact leaf = path.getLeaf();
    String key = Artifacts.makeKey(leaf);
    String highestVersion = versions.get(key).last();
    if (!leaf.getVersion().equals(highestVersion)) {
      Artifact parent = path.get(path.size() - 2);
      // when the parent is out of date, update the parent instead
      // TODO drop if any ancestor needs an update, instead of just the parent
      // or perhaps we just order the updates from root down, and then rerun after
      // each fix. Maybe even calculate what will be needed postfix
      String lastParentVersion = versions.get(Artifacts.makeKey(parent)).last();
      if (parent.getVersion().equals(lastParentVersion)) {
        
        // setVersion returns a new instance on change
        Artifact updated = leaf.setVersion(highestVersion);
        Update update = Update.builder()
            .setParent(parent)
            .setFrom(leaf)
            .setTo(updated)
            .build();
        
        upgrades.add(update); 
      }
    }
  }
  
  // TODO sort by path by comparing with the graph
  
  return new ArrayList<>(upgrades);
}
 
Example 3
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 4
Source File: AetherResolver.java    From onos with Apache License 2.0 5 votes vote down vote up
private BazelArtifact build(String name, String uri) {
    uri = uri.replaceFirst("mvn:", "");
    Artifact artifact = new DefaultArtifact(uri);
    String originalVersion = artifact.getVersion();
    try {
        artifact = artifact.setVersion(newestVersion(artifact));
        artifact = resolveArtifact(artifact);
        String sha = getSha(artifact);
        boolean osgiReady = isOsgiReady(artifact);

        if (originalVersion.endsWith("-SNAPSHOT")) {
            String url = String.format("%s/%s/%s/%s/%s-%s.%s",
                                       repoUrl,
                                       artifact.getGroupId().replace('.', '/'),
                                       artifact.getArtifactId(),
                                       originalVersion,
                                       artifact.getArtifactId(),
                                       artifact.getVersion(),
                                       artifact.getExtension());
            String mavenCoords = String.format("%s:%s:%s",
                                               artifact.getGroupId(),
                                               artifact.getArtifactId(),
                                               originalVersion);
            return BazelArtifact.getArtifact(name, url, sha, mavenCoords, osgiReady);
        }
        return BazelArtifact.getArtifact(name, artifact, sha, repoUrl, osgiReady);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}