本文整理匯總了Java中org.eclipse.aether.collection.CollectRequest.setRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java CollectRequest.setRoot方法的具體用法?Java CollectRequest.setRoot怎麽用?Java CollectRequest.setRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.aether.collection.CollectRequest
的用法示例。
在下文中一共展示了CollectRequest.setRoot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveArtifacts
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private Stream<? extends Artifact> resolveArtifacts(String coordinator) {
log.debug("resolving {}", coordinator);
try {
// build resolve filters
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(new DefaultArtifact(coordinator), JavaScopes.COMPILE));
DependencyRequest dependencyRequest = new DependencyRequest(
collectRequest,
DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME)
);
// resolve
final List<Artifact> artifacts = teslaAether.resolveArtifacts(dependencyRequest);
if (CollectionUtils.isEmpty(artifacts)) {
throw new DependencyResolveException(String.format("cannot resolve %s", coordinator));
}
return artifacts.stream();
} catch (DependencyResolutionException e) {
final String message = String.format("cannot resolve %s : %s", coordinator, e.getLocalizedMessage());
throw new DependencyResolveException(message, e);
}
}
示例2: resolve
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
/**
* Builds the DependencyRequest, calls RepositorySystem.resolveDependencies and checks for any error.
*
* @return DependencyResult the returned result from resolveDependencies
* */
public DependencyResult resolve() throws Exception{
Dependency dependency=settings.getDependency().createDependency();
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
collectRequest.setRepositories(settings.createRepositories());
DependencyRequest dependencyRequest=new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
DependencyResult result=repositorySystem.resolveDependencies(session, dependencyRequest);
if (result.getCollectExceptions()!=null && result.getCollectExceptions().size()>0){
throw result.getCollectExceptions().get(0);//return the first one. TODO: should return an exception wrapping them all
}
return result;
}
示例3: resolveDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private List<Artifact> resolveDependencies(final Artifact artifact) throws DependencyResolutionException {
List<Artifact> result = new ArrayList<Artifact>();
RepositorySystem system = newRepositorySystem();
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new org.eclipse.aether.graph.Dependency(artifact, JavaScopes.COMPILE));
List<ArtifactResult> dependenciesTree = system.resolveDependencies(
session,
new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE))
).getArtifactResults();
for (final ArtifactResult res : dependenciesTree) {
result.add(res.getArtifact());
}
return result;
}
示例4: transitiveDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
public static Set<Artifact> transitiveDependencies(Artifact artifact) {
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.setRepositories(repositories());
CollectResult collectResult = null;
try {
collectResult = system.collectDependencies(session, collectRequest);
} catch (DependencyCollectionException e) {
throw new RuntimeException(e);
}
PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
collectResult.getRoot().accept(visitor);
return ImmutableSet.copyOf(
visitor.getNodes().stream()
.filter(d -> !d.getDependency().isOptional())
.map(DependencyNode::getArtifact)
.collect(Collectors.toList()));
}
示例5: getDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
public List<Artifact> getDependencies(String groupId, String artifactId, String extension, String version) throws Exception {
Artifact artifact = new DefaultArtifact(groupId, artifactId, extension, version);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency( artifact, ""));
collectRequest.setRepositories(Collections.emptyList());
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE));
DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest);
List<Artifact> dependencies = new ArrayList<>();
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
if (!artifactResult.isResolved()) {
throw new Exception("Could not resolve artifact " + artifactResult.getRequest().getArtifact());
}
dependencies.add(artifactResult.getArtifact());
}
return dependencies;
}
示例6: collectDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private CollectResult collectDependencies(final Artifact artifact, final List<RemoteRepository> repositories) throws DependencyCollectionException {
final CollectResult collectResult;
final CollectRequest collectRequest = new CollectRequest();
final Dependency root_dependency = new Dependency(artifact, "");
collectRequest.setRoot(root_dependency);
collectRequest.setRepositories(repositories);
collectResult = REPOSITORY_SYSTEM.collectDependencies(session, collectRequest);
return collectResult;
}
示例7: newCollectRequest
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
/**
*
* @param artifact
* @param scope
* {@link org.eclipse.aether.util.artifact.JavaScopes}
* @return
*/
public CollectRequest newCollectRequest(Artifact artifact, String scope) {
Dependency dependency = new Dependency(artifact, scope);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
this.remoteRepositories.stream().forEach(collectRequest::addRepository);
return collectRequest;
}
示例8: createCollectRequestForGAV
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
protected CollectRequest createCollectRequestForGAV(String gav) {
DefaultArtifact artifact = new DefaultArtifact(gav);
Dependency dependency = new Dependency(artifact, getScope());
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
for (RemoteRepository repository : repositories) {
collectRequest.addRepository(repository);
}
return collectRequest;
}
示例9: buildDependencyRequest
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private static DependencyRequest buildDependencyRequest(List<RemoteRepository> repositories, String identifier, String scope)
{
Artifact artifact = new DefaultArtifact(identifier);
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(scope);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, scope));
collectRequest.setRepositories(repositories);
return new DependencyRequest(collectRequest, classpathFlter);
}
示例10: resolveDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
public DependencyResult resolveDependencies(Artifact artifact) throws DependencyCollectionException, DependencyResolutionException {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.setRepositories(remotes);
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
return repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest);
}
示例11: installDependency
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private void installDependency(String groupId, String artifactId, String version, RepositorySystemSession session) throws DependencyResolutionException{
logger.info("Installing and Loading Dependency : {} - {} - {} ", groupId , artifactId, version);
Dependency dependency = new Dependency( new DefaultArtifact(groupId, artifactId, "", "jar", version ), "compile" );
RemoteRepository central = new RemoteRepository.Builder( "central", "default", "http://central.maven.org/maven2/" ).build();
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( dependency );
collectRequest.addRepository( central );
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest( collectRequest );
system.resolveDependencies(session, dependencyRequest ).getRoot();
}
示例12: resolveArtifacts
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
public List<ArtifactResult> resolveArtifacts() throws MojoFailureException {
CollectRequest collectRequest = new CollectRequest();
final Artifact mainArtifact = new DefaultArtifact(project.getArtifact().getId());
collectRequest.setRoot(new Dependency(mainArtifact, JavaScopes.COMPILE));
collectRequest.setRepositories(projectRepos);
DependencyRequest dependencyRequest = new DependencyRequest().setCollectRequest(collectRequest);
dependencyRequest.setFilter(new DependencyFilter() {
public boolean accept(DependencyNode node,
List<DependencyNode> parents) {
Artifact nodeArtifact = node.getArtifact();
if (nodeArtifact.getGroupId().equals(mainArtifact.getGroupId()) &&
nodeArtifact.getArtifactId().equals(mainArtifact.getArtifactId())) {
return false;
}
return true;
}
});
List<ArtifactResult> resolvedArtifacts;
try {
resolvedArtifacts = repoSystem.resolveDependencies(repoSession, dependencyRequest).getArtifactResults();
} catch (DependencyResolutionException e) {
log.error("Could not resolve dependencies");
log.error(e.getMessage());
throw new MojoFailureException("Could not resolve dependencies");
}
return resolvedArtifacts;
}
示例13: execute
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
@Override
public void execute(DependencyResolveDetails dependencyResolveDetails) {
String group = dependencyResolveDetails.getTarget().getGroup();
String name = dependencyResolveDetails.getTarget().getName();
if (aetherPlugin.getVersionMap().containsKey(group) && aetherPlugin.getVersionMap().get(group).containsKey(name)) {
if (dependencyResolveDetails.getRequested().getVersion().equals(dependencyResolveDetails.getTarget().getVersion())) {
dependencyResolveDetails.useVersion(aetherPlugin.getVersionMap().get(group).get(name));
}
} else {
RepositorySystem system = setupRepositorySystem();
RepositorySystemSession session = setupSession(project, system);
List<RemoteRepository> remoteRepositories = new ArrayList<>();
for (ArtifactRepository artifactRepository : project.getRepositories()) {
if (artifactRepository instanceof MavenArtifactRepository) {
MavenArtifactRepository mavenArtifactRepository = (MavenArtifactRepository) artifactRepository;
remoteRepositories.add(new RemoteRepository.Builder(mavenArtifactRepository.getName(), "default", mavenArtifactRepository.getUrl().toString()).build());
}
}
Artifact artifact = new DefaultArtifact(dependencyResolveDetails.getTarget().getGroup()
+ ":" + dependencyResolveDetails.getTarget().getName()
+ ":" + dependencyResolveDetails.getTarget().getVersion());
CollectRequest collectRequest = new CollectRequest();
String scope;
if (configuration.getName().contains("test")) {
scope = JavaScopes.TEST;
} else if (configuration.getName().contains("runtime")) {
scope = JavaScopes.RUNTIME;
} else if (configuration.getName().equals("providedCompile")
|| configuration.getName().equals("compileOnly")) {
scope = JavaScopes.PROVIDED;
} else
scope = JavaScopes.COMPILE;
collectRequest.setRoot(new Dependency(artifact, scope));
collectRequest.setRepositories(remoteRepositories);
try {
CollectResult collectResult = system.collectDependencies(session, collectRequest);
processDependencyNode(collectResult.getRoot());
} catch (DependencyCollectionException e) {
e.printStackTrace();
}
}
}
示例14: listTransitiveDependencies
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
public static Set<DependencyWrapper> listTransitiveDependencies(Set<DependencyWrapper> dependencySet) {
Set<DependencyWrapper> dependencies = Sets.newHashSet();
for (DependencyWrapper dependency : dependencySet) {
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession(system);
Artifact artifact = new DefaultArtifact(
String.format("%s:%s:%s", dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()));
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
collectRequest.setRepositories(Booter.newRepositories(system, session));
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
List<ArtifactResult> artifactResults = null;
try {
artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
} catch (DependencyResolutionException e) {
continue;
}
for (ArtifactResult artifactResult : artifactResults) {
if (artifactResult.getRepository() == null) {
continue;
}
Artifact artifact1 = artifactResult.getArtifact();
org.apache.maven.model.Dependency dependency1 = new org.apache.maven.model.Dependency();
dependency1.setArtifactId(artifact1.getArtifactId());
dependency1.setGroupId(artifact1.getGroupId());
dependency1.setVersion(artifact1.getVersion());
dependency1.setClassifier(artifact1.getClassifier());
if (!MavenUtils.isDependencyResolvable(dependency1)) {
continue;
}
dependencies
.add(new DependencyWrapper(artifact1.getGroupId(), artifact1.getArtifactId(), artifact1.getVersion()));
}
}
return dependencies;
}
示例15: addDep
import org.eclipse.aether.collection.CollectRequest; //導入方法依賴的package包/類
private void addDep(String groupId, String artifactId, String classifier, String version) throws MojoExecutionException {
getLog().debug("addDep "+groupId+":"+artifactId);
org.eclipse.aether.artifact.Artifact aetherArtifact = new DefaultArtifact(
groupId,
artifactId,
classifier,
"jar",
version);
final org.eclipse.aether.graph.Dependency dependency = new org.eclipse.aether.graph.Dependency( aetherArtifact, JavaScopes.COMPILE );
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRepositories(this.repositories);
collectRequest.setRoot( dependency );
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
dependencyRequest.setFilter(new DependencyFilter(){
@Override
public boolean accept(DependencyNode dep, List<DependencyNode> parents) {
return dep.getArtifact().getClassifier() == null;
}
});
DependencyResult dependencyResult;
try {
dependencyResult = this.repoSystem.resolveDependencies(this.repoSession, dependencyRequest);
} catch (DependencyResolutionException e) {
throw new MojoExecutionException( "Artifact could not be resolved.", e );
}
getLog().debug("Got results: "+dependencyResult.getArtifactResults());
for(ArtifactResult result : dependencyResult.getArtifactResults()){
getLog().debug("Got result: "+result);
File file = result.getArtifact().getFile();
if( file == null || ! file.exists()) {
getLog().warn( "Artifact has no attached file. Its content will not be copied in the target model directory." );
}else if(file.isDirectory()){
getLog().warn( "Artifact is a folder. Its content will not be copied in the target model directory." );
}else{
exportDependency(result.getArtifact().getVersion(), file);
}
}
}