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

The following examples show how to use org.eclipse.aether.artifact.Artifact#getVersion() . 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: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private String ScopeConflict( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    List<String> scopes = Arrays.asList( "compile", "provided", "runtime", "test", "system" );

    for( String scope:scopes )
    {
        String coordinate = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
                artifact.getExtension() + ":" + artifact.getVersion() + ":" + scope;
        if( coordinateStrings.contains( coordinate ) )
        {
            return scope;
        }
    }
    // check for scopeless, this probably can't happen
    return null;
}
 
Example 2
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 3
Source File: PomXmlUtils.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
/**
 * Read group, artifact, version from nodes:
 * <groupId></groupId>, <artifactId></artifactId>, <version></version>
 * If presents parent node group and artifact takes from parent node
 * @param pomXml pom.xml for read
 * @return {@link Artifact} with group, artifact, version
 */
Artifact readGroupArtifactVersionInPomXml(Path pomXml) {
    String groupExpression    = String.format("/%s/%s", PROJECT, GROUP);
    String artifactExpression = String.format("/%s/%s", PROJECT, ARTIFACT);
    String versionExpression  = String.format("/%s/%s", PROJECT, VERSION);
    Document doc = readDocumentFromFile(pomXml);
    NodeList group = executeExpression(groupExpression, doc);
    NodeList artifact = executeExpression(artifactExpression, doc);
    NodeList version = executeExpression(versionExpression, doc);

    Artifact parent = readParentGAVInPomXml(pomXml);
    String groupId = (group != null && group.getLength() > 0) ? group.item(0).getTextContent() : (parent != null ? parent.getGroupId() : null);
    String artifactId = (artifact != null && artifact.getLength() > 0) ? artifact.item(0).getTextContent() : null;
    String versionId = (version != null && version.getLength() > 0) ? version.item(0).getTextContent() : (parent != null ? parent.getVersion() : null);

    
    return (groupId != null && artifactId != null && versionId != null) 
        ? (Artifact) new DefaultArtifact(getGAV(groupId, artifactId, versionId))
        : null;
}
 
Example 4
Source File: ArtifactRetriever.java    From maven-repository-tools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Iterate through the provided artifact coordinates to retrieve and pull additional artifact such as
 * jar for bundle packaging, jar for aar packaging and so on as required. And get them even if not specified.
 * @param artifactCoordinates
 */
private void getAdditionalArtifactsForRequest( List<String> artifactCoordinates )
{
  List<Artifact> artifacts = new ArrayList<Artifact>();
  for ( String artifactCoordinate : artifactCoordinates )
  {
      artifacts.add( new DefaultArtifact( artifactCoordinate ) );
  }
  for ( Artifact artifact : artifacts )
  {
    String extension = artifact.getExtension();
    if ( MavenConstants.packagingUsesJar( extension ) )
    {
      Gav gav = new Gav( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
          artifact.getExtension() );
      getJar( gav );
    }
  }
}
 
Example 5
Source File: ExtraArtifactsHandler.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
    Artifact original = n.getArtifact();
    Artifact withExtension =
            new DefaultArtifact(original.getGroupId(),
                    original.getArtifactId(),
                    classifier.orElse(original.getClassifier()),
                    extension.orElse(original.getExtension()),
                    original.getVersion(),
                    original.getProperties(),
                    (File) null);

    DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));

    return nodeWithClassifier;
}
 
Example 6
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);
    }
}
 
Example 7
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private Prebuilt resolveLib(Artifact artifact, Path project)
    throws ArtifactResolutionException, IOException {
  Artifact jar =
      new DefaultArtifact(
          artifact.getGroupId(), artifact.getArtifactId(), "jar", artifact.getVersion());

  Path relativePath = resolveArtifact(jar, project);

  Prebuilt library = new Prebuilt(jar.getArtifactId(), jar.toString(), relativePath);

  downloadSources(jar, project, library);
  return library;
}
 
Example 8
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private Dependency getChangedDependency(Artifact artifact) {

        String groupId = artifact.getGroupId();
        String artifactId = artifact.getArtifactId();
        String versionId = artifact.getVersion();
        Artifact newArtifact = new DefaultArtifact(
                String.format(ARTIFACT_TEMPLATE, groupId, artifactId, JAR_EXTENSION, versionId));
        Dependency dependency = new Dependency(newArtifact, "");

        return dependency;
    }
 
Example 9
Source File: AutoDiscoverDeployService.java    From vertx-deploy-tools with Apache License 2.0 5 votes vote down vote up
private Artifact checkWithModel(Model model, Artifact artifact, Map<String, String> properties) {
    Optional<org.apache.maven.model.Dependency> result = model.getDependencies().stream()
            .filter(d -> d.getGroupId().equals(artifact.getGroupId()))
            .filter(d -> d.getArtifactId().equals(artifact.getArtifactId()))
            .filter(d -> d.getClassifier() != null && properties.containsKey(d.getClassifier().substring(2, d.getClassifier().length() - 1)))
            .findFirst();
    return result.isPresent() ?
            new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), properties.get(result.get().getClassifier().substring(2, result.get().getClassifier().length() - 1)), artifact.getExtension(), artifact.getVersion(), artifact.getProperties(), artifact.getFile())
            : artifact;
}
 
Example 10
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultArtifact makeOtherExtension ( final Artifact main, final String extension )
{
    if ( main.getClassifier () != null && !main.getClassifier ().isEmpty () )
    {
        // we only change main artifacts
        return null;
    }

    return new DefaultArtifact ( main.getGroupId (), main.getArtifactId (), null, extension, main.getVersion () );
}
 
Example 11
Source File: AetherImporter.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static DefaultArtifact makeOtherClassifier ( final Artifact main, final String classifier )
{
    if ( main.getClassifier () != null && !main.getClassifier ().isEmpty () )
    {
        // we only change main artifacts
        return null;
    }

    return new DefaultArtifact ( main.getGroupId (), main.getArtifactId (), classifier, main.getExtension (), main.getVersion () );
}
 
Example 12
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getDependencyCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    String scope = node.getDependency().getScope();
    String coords = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
            artifact.getExtension() + ":" + artifact.getVersion();

    if( scope != null && !scope.isEmpty() )
    {
        coords = coords.concat( ":" + scope );
    }
    return coords;
}
 
Example 13
Source File: MavenUtils.java    From syndesis with Apache License 2.0 5 votes vote down vote up
static String toGav(final Artifact artifact) {
    // <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>
    return artifact.getGroupId()
        + ":" + artifact.getArtifactId()
        + (artifact.getExtension() == null ? "" : ":" + artifact.getExtension())
        + (artifact.getClassifier() == null ? "" : ":" + artifact.getClassifier())
        + ":" + artifact.getVersion();
}
 
Example 14
Source File: Rule.java    From migration-tooling with Apache License 2.0 5 votes vote down vote up
public Rule(Artifact artifact, String alias) {
  this.artifact = artifact;
  this.version = artifact.getVersion();
  this.parents = Sets.newHashSet();
  this.dependencies = Sets.newTreeSet();
  this.exclusions = Sets.newHashSet();
  this.repository = MAVEN_CENTRAL_URL;
  this.alias = alias;
}
 
Example 15
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static AppArtifact toAppArtifact(Artifact artifact) {
    final AppArtifact appArtifact = new AppArtifact(artifact.getGroupId(), artifact.getArtifactId(),
            artifact.getClassifier(), artifact.getExtension(), artifact.getVersion());
    final File file = artifact.getFile();
    if (file != null) {
        appArtifact.setPaths(PathsCollection.of(file.toPath()));
    }
    return appArtifact;
}
 
Example 16
Source File: PluginSettings.java    From gyro with Apache License 2.0 5 votes vote down vote up
public void putArtifactIfNewer(Artifact artifact) throws MalformedURLException {
    String id = artifact.getGroupId() + "/" + artifact.getArtifactId();
    VersionUrl versionUrl = new VersionUrl(artifact.getVersion(), artifact.getFile().toURI().toURL());

    if (!VERSIONED_URLS.containsKey(id) || versionUrl.compareTo(VERSIONED_URLS.get(id)) > 0) {
        VERSIONED_URLS.put(id, versionUrl);
    }
}
 
Example 17
Source File: BomTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String buildMavenCentralUrl(Artifact artifact) {
  return "https://repo1.maven.org/maven2/"
      + artifact.getGroupId().replace('.', '/')
      + "/"
      + artifact.getArtifactId()
      + "/"
      + artifact.getVersion()
      + "/";
}
 
Example 18
Source File: NbArtifactFixer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override File resolve(Artifact artifact) {
    if (!artifact.getExtension().equals(NbMavenProject.TYPE_POM)) {
        return null;
    }
    if (!artifact.getClassifier().isEmpty()) {
        return null;
    }
    ArtifactRepository local = EmbedderFactory.getProjectEmbedder().getLocalRepository();
    if (local.getLayout() != null) { // #189807: for unknown reasons, there is no layout when running inside MavenCommandLineExecutor.run
        
        //the special snapshot handling is important in case of SNAPSHOT or x-SNAPSHOT versions, for some reason aether has slightly different
        //handling of baseversion compared to maven artifact. we need to manually set the baseversion here..
        boolean isSnapshot = artifact.isSnapshot();
        DefaultArtifact art = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null, artifact.getExtension(), artifact.getClassifier(), new DefaultArtifactHandler(artifact.getExtension()));
        if (isSnapshot) {
            art.setBaseVersion(artifact.getBaseVersion());
        }
        String path = local.pathOf(art);
        if (new File(local.getBasedir(), path).exists()) {
            return null; // for now, we prefer the repository version when available
        }
    }
    //#234586
    Set<String> gavSet = gav.get();
    if (gavSet == null) {
        gavSet = new HashSet<String>();
        gav.set(gavSet);
    }
    String id = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();

    if (!gavSet.contains(id)) {
        try {
            gavSet.add(id); //#234586
            File pom = MavenFileOwnerQueryImpl.getInstance().getOwnerPOM(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
            if (pom != null) {
                //instead of workarounds down the road, we set the artifact's file here.
                // some stacktraces to maven/aether do set it after querying our code, but some don't for reasons unknown to me.
                artifact.setFile(pom);
                return pom;
            }
        } finally {
            gavSet.remove(id); //#234586
            if (gavSet.isEmpty()) {
                gav.remove();
            }
        }
    } else {
        LOG.log(Level.INFO, "Cycle in NbArtifactFixer resolution (issue #234586): {0}", Arrays.toString(gavSet.toArray()));
    }
    
    try {
        File f = createFallbackPOM(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
        //instead of workarounds down the road, we set the artifact's file here.
        // some stacktraces to maven/aether do set it after querying our code, but some don't for reasons unknown to me.
        artifact.setFile(f);
        return f;
    } catch (IOException x) {
        Exceptions.printStackTrace(x);
        return null;
    }
}
 
Example 19
Source File: PluginBundleManager.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
private void loadDependencies(String pluginBundleVersion, boolean strictDependencyChecking, Model model,
			DelegatingClassLoader delegatingClassLoader)
			throws DependencyCollectionException, InvalidVersionSpecificationException, Exception {
		if (model.getRepositories() != null) {
			for (Repository repository : model.getRepositories()) {
				mavenPluginRepository.addRepository(repository.getId(), "default", repository.getUrl());
			}
		}

		List<Dependency> dependenciesToResolve = new ArrayList<>();
		for (org.apache.maven.model.Dependency dependency2 : model.getDependencies()) {
			String scope = dependency2.getScope();
			if (scope != null && (scope.contentEquals("test"))) {
				// Skip
				continue;
			}
			Dependency d = new Dependency(new DefaultArtifact(dependency2.getGroupId(), dependency2.getArtifactId(), dependency2.getType(), dependency2.getVersion()), dependency2.getScope());
			Set<Exclusion> exclusions = new HashSet<>();
			d.setExclusions(exclusions);
			exclusions.add(new Exclusion("org.opensourcebim", "pluginbase", null, "jar"));
			exclusions.add(new Exclusion("org.opensourcebim", "shared", null, "jar"));
			exclusions.add(new Exclusion("org.opensourcebim", "ifcplugins", null, "jar"));
			dependenciesToResolve.add(d);
		}
		CollectRequest collectRequest = new CollectRequest(dependenciesToResolve, null, null);
		collectRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
		CollectResult collectDependencies = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
		PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
		DependencyNode rootDep = collectDependencies.getRoot();
		rootDep.accept(nlg);
		
		for (Dependency dependency : nlg.getDependencies(true)) {
			if (dependency.getScope().contentEquals("test")) {
				continue;
			}
//			LOGGER.info(dependency.getArtifact().getGroupId() + "." + dependency.getArtifact().getArtifactId());
			Artifact dependencyArtifact = dependency.getArtifact();
			PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
			if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
				if (strictDependencyChecking) {
					String version = dependencyArtifact.getVersion();
					if (!version.contains("[") && !version.contains("(")) {
						version = "[" + version + "]";
					}
					VersionRange versionRange = VersionRange.createFromVersionSpec(version);
					// String version =
					// pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
					ArtifactVersion artifactVersion = new DefaultArtifactVersion(pluginBundleVersion);
					if (versionRange.containsVersion(artifactVersion)) {
						// OK
					} else {
						throw new Exception(
								"Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + pluginBundleVersion + ") does not comply to the required version (" + dependencyArtifact.getVersion() + ")");
					}
				} else {
					LOGGER.info("Skipping strict dependency checking for dependency " + dependencyArtifact.getArtifactId());
				}
			} else {
				try {
					if (dependencyArtifact.getGroupId().contentEquals("com.sun.xml.ws")) {
						continue;
					}
					MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId());
					if (dependencyArtifact.getExtension().contentEquals("jar")) {
						Path depJarFile = mavenPluginLocation.getVersionJar(dependencyArtifact.getVersion());
						
						FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile);
						jarClassLoaders.add(jarClassLoader);
						delegatingClassLoader.add(jarClassLoader);
					}
				} catch (Exception e) {
					e.printStackTrace();
					throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
				}
			}
		}
	}
 
Example 20
Source File: Artifacts.java    From cloud-opensource-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the artifact's Maven coordinates in the form groupId:artifactId:version. Repo and
 * packaging are not included.
 */
public static String toCoordinates(Artifact artifact) {
  return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
}