Java Code Examples for org.eclipse.aether.graph.Dependency#getArtifact()

The following examples show how to use org.eclipse.aether.graph.Dependency#getArtifact() . 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: BuildDependencyGraphVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void visitLeave(DependencyNode node) {
    final Dependency dep = node.getDependency();
    if (dep == null) {
        return;
    }
    final Artifact artifact = dep.getArtifact();
    if (artifact.getFile() == null) {
        requests.add(new ArtifactRequest(node));
    }
    if (deploymentNode != null) {
        if (runtimeNode == null && !appDeps.contains(new AppArtifactKey(artifact.getGroupId(),
                artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension()))) {
            //we never want optional deps on the deployment CP
            if (!node.getDependency().isOptional()) {
                deploymentDepNodes.add(node);
            }
        } else if (runtimeNode == node) {
            runtimeNode = null;
            runtimeArtifact = null;
        }
        if (deploymentNode == node) {
            deploymentNode = null;
        }
    }
}
 
Example 2
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static org.apache.maven.model.Dependency toDependency(Dependency resolvedDependency) {
  org.apache.maven.model.Dependency dependency = new org.apache.maven.model.Dependency();
  Artifact artifact = resolvedDependency.getArtifact();
  dependency.setArtifactId(artifact.getArtifactId());
  dependency.setGroupId(artifact.getGroupId());
  dependency.setVersion(artifact.getVersion());
  dependency.setOptional(dependency.isOptional());
  dependency.setClassifier(artifact.getClassifier());
  dependency.setExclusions(dependency.getExclusions());
  dependency.setScope(dependency.getScope());
  return dependency;
}
 
Example 3
Source File: FilteringZipDependencySelector.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Override
public boolean selectDependency(Dependency dependency) {
  Artifact artifact = dependency.getArtifact();
  Map<String, String> properties = artifact.getProperties();
  // Because LinkageChecker only checks jar file, zip files are not needed
  return !"zip".equals(properties.get("type"));
}
 
Example 4
Source File: Bom.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the dependencyManagement section of an artifact and returns
 * the artifacts included there.
 *
 * @param mavenRepositoryUrls URLs of Maven repositories to search for BOM members
 */
public static Bom readBom(String coordinates, List<String> mavenRepositoryUrls)
    throws ArtifactDescriptorException {
  Artifact artifact = new DefaultArtifact(coordinates);

  RepositorySystem system = RepositoryUtility.newRepositorySystem();
  RepositorySystemSession session = RepositoryUtility.newSession(system);

  ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();

  for (String repositoryUrl : mavenRepositoryUrls) {
    request.addRepository(RepositoryUtility.mavenRepositoryFromUrl(repositoryUrl));
  }

  request.setArtifact(artifact);

  ArtifactDescriptorResult resolved = system.readArtifactDescriptor(session, request);
  List<Exception> exceptions = resolved.getExceptions();
  if (!exceptions.isEmpty()) {
    throw new ArtifactDescriptorException(resolved, exceptions.get(0).getMessage());
  }
  
  List<Artifact> managedDependencies = new ArrayList<>();
  for (Dependency dependency : resolved.getManagedDependencies()) {
    Artifact managed = dependency.getArtifact();
    if (!shouldSkipBomMember(managed) && !managedDependencies.contains(managed)) {
      managedDependencies.add(managed);
    }
  }
  
  Bom bom = new Bom(coordinates, ImmutableList.copyOf(managedDependencies));
  return bom;
}
 
Example 5
Source File: DependencyResolver.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private List<ArtifactRequest> getArtifactRequests(List<Dependency> dependencies) {
	List<ArtifactRequest> list = new ArrayList<>();
	for (Dependency dependency : dependencies) {
		ArtifactRequest request = new ArtifactRequest(dependency.getArtifact(), null,
				null);
		request.setRepositories(aetherRepositories(new Properties()));
		list.add(request);
	}
	return list;
}
 
Example 6
Source File: Bom.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
static Bom loadBom(String groupId, String artifactId, String version, IProgressMonitor monitor)
    throws CoreException {
  
  Collection<Dependency> dependencies =
      DependencyResolver.getManagedDependencies(groupId, artifactId, version, monitor);
  Map<String, Artifact> artifacts = new HashMap<>();
  for (Dependency dependency : dependencies) {
    Artifact artifact = dependency.getArtifact();
    artifacts.put(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact);

  }
  
  return new Bom(artifacts);
}
 
Example 7
Source File: DependencyResolver.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private List<ArtifactRequest> getArtifactRequests(List<Dependency> dependencies) {
	List<ArtifactRequest> list = new ArrayList<>();
	for (Dependency dependency : dependencies) {
		ArtifactRequest request = new ArtifactRequest(dependency.getArtifact(), null,
				null);
		request.setRepositories(aetherRepositories(new Properties()));
		list.add(request);
	}
	return list;
}
 
Example 8
Source File: AetherUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private Set<Dependency> parseDependencies(Collection<Dependency> unchagedDeps) {
    Set<Dependency> changedDeps = Sets.newHashSet();
    for (Dependency dependency : unchagedDeps) {
        Artifact artifact = dependency.getArtifact();
        String extension = artifact.getExtension();
        if (!extension.equals(JAR_EXTENSION)) {
            dependency = getChangedDependency(artifact);
            changedDeps.add(dependency);
        } else changedDeps.add(dependency);

    }
    return changedDeps;
}
 
Example 9
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private String findDependencyVersion(List<Dependency> dependencies, String groupId, String artifactId)
{
   for (Dependency child : dependencies)
   {
      Artifact childArtifact = child.getArtifact();

      if (groupId.equals(childArtifact.getGroupId())
               && artifactId.equals(childArtifact.getArtifactId()))
      {
         return childArtifact.getBaseVersion();
      }
   }
   return null;
}
 
Example 10
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private MutableDirectedGraph<Artifact> buildDependencyGraph(Map<String, Artifact> knownDeps)
    throws ArtifactDescriptorException {
  MutableDirectedGraph<Artifact> graph;
  graph = new MutableDirectedGraph<>();
  for (Map.Entry<String, Artifact> entry : knownDeps.entrySet()) {
    String key = entry.getKey();
    Artifact artifact = entry.getValue();

    graph.addNode(artifact);

    List<Dependency> dependencies = getDependenciesOf(artifact);

    for (Dependency dependency : dependencies) {
      if (dependency.getArtifact() == null) {
        System.out.println("Skipping because artifact missing: " + dependency);
        continue;
      }

      String depKey = buildKey(dependency.getArtifact());
      Artifact actualDep = knownDeps.get(depKey);
      if (actualDep == null) {
        continue;
      }
      // It's possible that the runtime dep of an artifact is the test time dep of another.
      if (isTestTime(dependency)) {
        continue;
      }

      // TODO(simons): Do we always want optional dependencies?
      //        if (dependency.isOptional()) {
      //          continue;
      //        }

      Objects.requireNonNull(actualDep, key + " -> " + artifact + " in " + knownDeps.keySet());
      graph.addNode(actualDep);
      graph.addEdge(actualDep, artifact);
    }
  }
  return graph;
}
 
Example 11
Source File: RepackageExtensionMojo.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private static ArtifactsFilter newExcludeFilter(final Dependency dependency) {
    final Artifact artifact = dependency.getArtifact();

    return new ExcludeFilter(artifact.getGroupId(), artifact.getArtifactId());
}
 
Example 12
Source File: DependencyResolutionResultHandler.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
@Override
protected boolean _handle(DependencyResolutionResult result) {

    Xpp3Dom root = new Xpp3Dom("DependencyResolutionResult");
    root.setAttribute("class", result.getClass().getName());

    Xpp3Dom dependenciesElt = new Xpp3Dom("resolvedDependencies");
    root.addChild(dependenciesElt);

    for (Dependency dependency : result.getResolvedDependencies()) {
        Artifact artifact = dependency.getArtifact();

        if ( !includedScopes.contains(dependency.getScope())) {
            continue;
        }
        if (!includeSnapshots && artifact.isSnapshot()) {
            continue;
        }
        if(!includeReleases && !artifact.isSnapshot()) {
            continue;
        }

        Xpp3Dom dependencyElt = new Xpp3Dom("dependency");

        dependencyElt.addChild(newElement("file", artifact.getFile().getAbsolutePath()));

        dependencyElt.setAttribute("name", artifact.getFile().getName());

        dependencyElt.setAttribute("groupId", artifact.getGroupId());
        dependencyElt.setAttribute("artifactId", artifact.getArtifactId());
        dependencyElt.setAttribute("version", artifact.getVersion());
        dependencyElt.setAttribute("baseVersion", artifact.getBaseVersion());
        if (artifact.getClassifier() != null) {
            dependencyElt.setAttribute("classifier", artifact.getClassifier());
        }
        dependencyElt.setAttribute("type", artifact.getExtension());
        dependencyElt.setAttribute("id", artifact.getArtifactId());
        dependencyElt.setAttribute("extension", artifact.getExtension());
        dependencyElt.setAttribute("scope", dependency.getScope());
        dependencyElt.setAttribute("optional", Boolean.toString(dependency.isOptional()));
        dependencyElt.setAttribute("snapshot", Boolean.toString(artifact.isSnapshot()));

        dependenciesElt.addChild(dependencyElt);
    }

    reporter.print(root);
    return true;
}
 
Example 13
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");
				}
			}
		}
	}