本文整理汇总了Java中org.sonatype.aether.collection.CollectRequest.addRepository方法的典型用法代码示例。如果您正苦于以下问题:Java CollectRequest.addRepository方法的具体用法?Java CollectRequest.addRepository怎么用?Java CollectRequest.addRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonatype.aether.collection.CollectRequest
的用法示例。
在下文中一共展示了CollectRequest.addRepository方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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());
}
示例10: 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;
}