本文整理汇总了Java中org.sonatype.aether.collection.CollectRequest类的典型用法代码示例。如果您正苦于以下问题:Java CollectRequest类的具体用法?Java CollectRequest怎么用?Java CollectRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CollectRequest类属于org.sonatype.aether.collection包,在下文中一共展示了CollectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getArtifactsWithDep
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
/**
*
* @param dependency
* @param excludes list of pattern can either be of the form groupId:artifactId
* @return
* @throws Exception
*/
public List<ArtifactResult> getArtifactsWithDep(String dependency,
Collection<String> excludes) throws Exception {
Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );
PatternExclusionsDependencyFilter exclusionFilter =
new PatternExclusionsDependencyFilter(inferScalaVersion(excludes));
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
synchronized (repos) {
for (RemoteRepository repo : repos) {
collectRequest.addRepository(repo);
}
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
DependencyFilterUtils.andFilter(exclusionFilter, classpathFlter));
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
示例2: fetchArtifactWithDep
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
private List<ArtifactResult> fetchArtifactWithDep(Dependency dep)
throws DependencyResolutionException, ArtifactResolutionException {
Artifact artifact = new DefaultArtifact(dep.getGroupArtifactVersion());
DependencyFilter classpathFilter = DependencyFilterUtils
.classpathFilter(JavaScopes.COMPILE);
PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(
dep.getExclusions());
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact,
JavaScopes.COMPILE));
collectRequest.addRepository(mavenCentral);
collectRequest.addRepository(mavenLocal);
for (Repository repo : repositories) {
RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl());
rr.setPolicy(repo.isSnapshot(), null);
collectRequest.addRepository(rr);
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
示例3: getArtifactsWithDep
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
/**
* @param dependency
* @param excludes list of pattern can either be of the form groupId:artifactId
* @return
* @throws Exception
*/
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency,
Collection<String> excludes) throws RepositoryException {
Artifact artifact = new DefaultArtifact(dependency);
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
PatternExclusionsDependencyFilter exclusionFilter =
new PatternExclusionsDependencyFilter(excludes);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
synchronized (repos) {
for (RemoteRepository repo : repos) {
collectRequest.addRepository(repo);
}
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
try {
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
} catch (NullPointerException | DependencyResolutionException ex) {
throw new RepositoryException(
String.format("Cannot fetch dependencies for %s", dependency), ex);
}
}
示例4: getArtifactsWithDep
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
/**
* @param dependency
* @param excludes list of pattern can either be of the form groupId:artifactId
* @return
* @throws Exception
*/
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency,
Collection<String> excludes) throws Exception {
Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
PatternExclusionsDependencyFilter exclusionFilter =
new PatternExclusionsDependencyFilter(inferScalaVersion(excludes));
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
synchronized (repos) {
for (RemoteRepository repo : repos) {
collectRequest.addRepository(repo);
}
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
示例5: testCollectDependencies
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
public void testCollectDependencies()
throws Exception
{
Artifact artifact = new DefaultArtifact( "ut.simple:artifact:extension:classifier:1.0" );
// notice: extension and classifier not really used in this test...
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( new Dependency( artifact, null ) );
collectRequest.addRepository( newTestRepository() );
CollectResult collectResult = system.collectDependencies( session, collectRequest );
List<DependencyNode> nodes = collectResult.getRoot().getChildren();
assertEquals( 2, nodes.size() );
checkUtSimpleArtifactDependencies( nodes.get( 0 ).getDependency(), nodes.get( 1 ).getDependency() );
}
示例6: resolve
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
private void resolve( ResolveRequest resolveRequest )
{
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession( system, resolveRequest.localRepoDir );
org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(
resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version );
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( new Dependency( artifact, "" ) );
// add remote repositories
for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories )
{
collectRequest.addRepository(
new org.sonatype.aether.repository.RemoteRepository( remoteRepository.getId(), "default",
remoteRepository.getUrl() ) );
}
collectRequest.setRequestContext( "project" );
//collectRequest.addRepository( repo );
try
{
CollectResult collectResult = system.collectDependencies( session, collectRequest );
collectResult.getRoot().accept( resolveRequest.dependencyVisitor );
log.debug( "test" );
}
catch ( DependencyCollectionException e )
{
log.error( e.getMessage(), e );
}
}
示例7: createCollectRequestForGAV
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
private CollectRequest createCollectRequestForGAV(String gav) {
DefaultArtifact artifact = new DefaultArtifact(gav);
Dependency dependency = new Dependency(artifact, COMPILE_SCOPE);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
for (RemoteRepository repository : repositories) {
collectRequest.addRepository(repository);
}
return collectRequest;
}
示例8: resolveArtifacts
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
public List<Artifact> resolveArtifacts(Iterable<? extends Artifact> sourceArtifacts)
{
CollectRequest collectRequest = new CollectRequest();
for (Artifact sourceArtifact : sourceArtifacts) {
collectRequest.addDependency(new Dependency(sourceArtifact, JavaScopes.RUNTIME));
}
for (RemoteRepository repository : repositories) {
collectRequest.addRepository(repository);
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
return resolveArtifacts(dependencyRequest);
}
示例9: resolveDependencies
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
/**
* Resolves dependencies transitively from the given jar artifact, with the specified Maven scope
* (compile, runtime, and so on.)
*/
public DependencyResult resolveDependencies(GAV a, String scope) throws DependencyResolutionException {
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(scope);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(new DefaultArtifact(a.toString()), JavaScopes.COMPILE));
collectRequest.setRepositories(remoteRepositories);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
return resolveDependencies(dependencyRequest);
}
示例10: downloadArtifacts
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
private void downloadArtifacts(CollectRequest request)
throws VersionRangeResolutionException, ArtifactNotFoundException {
try {
logger.info("Resolving dependencies");
List<Artifact> artifacts = collectDependenciesIntoArtifacts(request);
final File downloadDir = new File(settings.localDownloadPath());
if (!downloadDir.exists() && !downloadDir.mkdirs()) {
throw new DropshipRuntimeException("Could not create the local download directory " + settings.localDownloadPath());
}
for (Artifact artifact : artifacts) {
logger.info("Copying " + artifact.getFile().getName() + " to " + settings.localDownloadPath());
copy(artifact.getFile(), new File(downloadDir, artifact.getFile().getName()));
}
} catch (Exception e) {
Throwable rootCause = e;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof VersionRangeResolutionException) {
throw ((VersionRangeResolutionException) rootCause);
}
if (rootCause instanceof ArtifactNotFoundException) {
throw ((ArtifactNotFoundException) rootCause);
}
if (e instanceof SecurityException) {
throw ((SecurityException) e);
}
if (e instanceof DropshipRuntimeException) {
throw ((DropshipRuntimeException) e);
}
if (e instanceof RuntimeException) {
throw ((RuntimeException) e);
}
throw new RuntimeException(e);
}
}
示例11: createClassLoader
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
private URLClassLoader createClassLoader(String groupArtifactVersion, CollectRequest request)
throws VersionRangeResolutionException, ArtifactNotFoundException {
try {
logger.info("Resolving dependencies");
List<Artifact> artifacts = collectDependenciesIntoArtifacts(request);
logger.info("Building classpath for %s from %d URLs", groupArtifactVersion, artifacts.size());
List<URL> urls = new ArrayList<URL>();
for (Artifact artifact : artifacts) {
urls.add(artifact.getFile().toURI().toURL());
}
for (String path : settings.additionalClasspathPaths()) {
logger.info("Adding \"%s\" to classpath", path);
urls.add(new File(path).toURI().toURL());
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), SHARE_NOTHING);
} catch (Exception e) {
Throwable rootCause = e;
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
if (rootCause instanceof VersionRangeResolutionException) {
throw ((VersionRangeResolutionException) rootCause);
}
if (rootCause instanceof ArtifactNotFoundException) {
throw ((ArtifactNotFoundException) rootCause);
}
if (e instanceof SecurityException) {
throw ((SecurityException) e);
}
if (e instanceof DropshipRuntimeException) {
throw ((DropshipRuntimeException) e);
}
if (e instanceof RuntimeException) {
throw ((RuntimeException) e);
}
throw new RuntimeException(e);
}
}
示例12: collectDependenciesIntoArtifacts
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
private List<Artifact> collectDependenciesIntoArtifacts(CollectRequest collectRequest)
throws PlexusContainerException, ComponentLookupException, DependencyCollectionException, ArtifactResolutionException, DependencyResolutionException {
RepositorySystem repositorySystem = newRepositorySystem();
RepositorySystemSession session = newSession(repositorySystem);
DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot();
DependencyFilter filter = new ScopeDependencyFilter();
DependencyRequest request = new DependencyRequest(node, filter);
repositorySystem.resolveDependencies(session, request);
// PathRecordingDependencyVisitor will give every path, which may help in building a hierarchical class loader
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
node.accept(nlg);
return nlg.getArtifacts(false);
}
示例13: main
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
public static void main( String[] args )
throws Exception
{
System.out.println( "------------------------------------------------------------" );
System.out.println( ResolveTest.class.getSimpleName() );
RepositorySystem system = Maven.repositorySystem();
RepositorySystemSession session = Maven.repositorySystemSession(system);
Artifact artifact = new DefaultArtifact( "org.springframework:spring-orm:2.5.6" );
Artifact artifact2 = new DefaultArtifact("org.springframework:spring-webmvc:3.2.2.RELEASE");
RemoteRepository repo = Maven.central();
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );
CollectRequest collectRequest = new CollectRequest();
//collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
collectRequest.addDependency(new Dependency(artifact, JavaScopes.COMPILE));
collectRequest.addDependency(new Dependency(artifact2, JavaScopes.COMPILE));
collectRequest.addRepository( repo );
DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter );
DependencyResult result = system.resolveDependencies( session, dependencyRequest );
//List<ArtifactResult> artifactResults = result.getArtifactResults();
//System.out.println(result.getRoot().getClass());
//System.out.println(result.getRoot().getDependency());
//result.getRoot().accept(new TreePrinter());
//PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
//result.getRoot().accept(nlg);
//System.out.println(nlg.getArtifacts(false));
//for ( ArtifactResult artifactResult : artifactResults )
//{
// System.out.println( artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile() );
//}
//new NearestVersionConflictResolver().transformGraph(result.getRoot(), new MyDependencyGraphTransformationContext(session)).accept(new TreePrinter());
new VersionResolver().resolve(result.getRoot());
}
示例14: getClasspathFromMavenProject
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
public static List<String> getClasspathFromMavenProject(File projectPom, File localRepoFolder, boolean isRunwayEnvironment) throws DependencyResolutionException, IOException, XmlPullParserException
{
MavenProject proj = loadProject(projectPom);
PropertyReplacer propReplacer = new PropertyReplacer(proj);
List<Repository> repos = proj.getRepositories();
List<String> classpath = new ArrayList<String>();
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system, localRepoFolder );
RemoteRepository centralRepo = Booter.newCentralRepository();
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );
List<org.apache.maven.model.Dependency> dependencies = proj.getDependencies();
Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
while (it.hasNext()) {
org.apache.maven.model.Dependency depend = it.next();
Artifact artifact = new DefaultArtifact(propReplacer.replace(depend.getGroupId()), propReplacer.replace(depend.getArtifactId()), propReplacer.replace(depend.getClassifier()), propReplacer.replace(depend.getType()), propReplacer.replace(depend.getVersion()));
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
collectRequest.addRepository( centralRepo );
for (Repository repo : repos) {
collectRequest.addRepository(new RemoteRepository(propReplacer.replace(repo.getId()), propReplacer.replace(repo.getLayout()), propReplacer.replace(repo.getUrl())));
}
try {
DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter );
List<ArtifactResult> artifactResults =
system.resolveDependencies( session, dependencyRequest ).getArtifactResults();
for ( ArtifactResult artifactResult : artifactResults )
{
Artifact art = artifactResult.getArtifact();
if (isRunwayEnvironment && art.getGroupId().equals("com.runwaysdk") && (
art.getArtifactId().equals("runwaysdk-client") ||
art.getArtifactId().equals("runwaysdk-common") ||
art.getArtifactId().equals("runwaysdk-server")
)) {
continue;
}
classpath.add(art.getFile().getAbsolutePath());
}
}
catch (DependencyResolutionException e) {
// Is Maven ignoring this? I'm confused.
log.error(e);
e.printStackTrace();
}
}
if (log.isTraceEnabled()) {
String cpath = "";
for (Iterator<String> i = classpath.iterator(); i.hasNext();) {
cpath = cpath + ", " + i.next();
}
log.trace("Resolved pom [" + projectPom.getAbsolutePath() + "] classpath to [" + cpath + "]");
}
return classpath;
}
示例15: collectDependencies
import org.sonatype.aether.collection.CollectRequest; //导入依赖的package包/类
/**
* Collects the transitive dependencies of an artifact and builds a dependency graph. Note that this operation is
* only concerned about determining the coordinates of the transitive dependencies. To also resolve the actual
* artifact files, use {@link #resolveDependencies(DependencyRequest)}.
*
* @param request The collection request, must not be {@code null}
* @return The collection result, never {@code null}.
* @throws org.sonatype.aether.collection.DependencyCollectionException If the dependency tree could not be built.
* @see RepositorySystemSession#getDependencyTraverser()
* @see RepositorySystemSession#getDependencyManager()
* @see RepositorySystemSession#getDependencySelector()
* @see RepositorySystemSession#getDependencyGraphTransformer()
*/
public CollectResult collectDependencies( CollectRequest request ) throws DependencyCollectionException {
return repository.collectDependencies(session, request);
}