本文整理汇总了Java中org.apache.maven.artifact.resolver.ArtifactResolutionRequest类的典型用法代码示例。如果您正苦于以下问题:Java ArtifactResolutionRequest类的具体用法?Java ArtifactResolutionRequest怎么用?Java ArtifactResolutionRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArtifactResolutionRequest类属于org.apache.maven.artifact.resolver包,在下文中一共展示了ArtifactResolutionRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSourcesDependency
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
private void loadSourcesDependency(JavaProjectBuilder javaDocBuilder, Artifact sourcesArtifact) {
// create request
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(sourcesArtifact);
// resolve deps
ArtifactResolutionResult result = repositorySystem.resolve(request);
// load source file into javadoc builder
result.getArtifacts().forEach(artifact -> {
try {
JarFile jarFile = new JarFile(artifact.getFile());
for (Enumeration entries = jarFile.entries(); entries.hasMoreElements(); ) {
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
if (name.endsWith(".java") && !name.endsWith("/package-info.java")) {
javaDocBuilder.addSource(new URL("jar:" + artifact.getFile().toURI().toURL().toString() + "!/" + name));
}
}
} catch (Exception e) {
getLog().warn("Unable to load jar source " + artifact + " : " + e.getMessage());
}
});
}
示例2: resolveArtifactTransitively
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
private Set<Artifact> resolveArtifactTransitively( final Artifact artifact ) {
final ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( artifact ).setResolveRoot( true ).setResolveTransitively( true )
.setRemoteRepositories( this.remoteArtifactRepositories ).setLocalRepository( this.localRepository );
if( this.excludeOptionalDependencies ){
request.setCollectionFilter( OptionalArtifactFilter.INSTANCE );
}
final ArtifactResolutionResult result = this.resolver.resolve( request );
if( !result.isSuccess() ){
for( Artifact missing : result.getMissingArtifacts() ){
getLog().error( String.format( "Could not resolve artifact: [%s]", missing ) );
}
if( result.hasExceptions() && getLog().isDebugEnabled() ){
for( Exception exception : result.getExceptions() ){
getLog().debug( exception );
}
}
}
final Set<Artifact> dependencies = result.getArtifacts();
return dependencies;
}
示例3: testOneDependencyOneArtifact
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
@Test
public void testOneDependencyOneArtifact() throws MojoExecutionException {
Artifact g1a1 = helper.createArtifact( "g1", "a1" );
List<Artifact> artifacts = asList( helper.fitnesseArtifact, g1a1 );
helper.plugin.addDependency( createDependecy( "g1", "a1" ) );
helper.mojo.pluginDescriptor.setArtifacts( artifacts );
when( helper.artifactResolver.resolve( any( ArtifactResolutionRequest.class ) ) ).thenReturn( helper.createArtifactResolutionResult( helper.fitnesseArtifact ) )
.thenReturn( helper.createArtifactResolutionResult( g1a1 ) );
assertEquals( "\n", helper.mojo.calcWikiFormatClasspath() );
assertEquals( USING_PLUGIN_CONFIG, helper.logStream.toString() );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( helper.fitnesseArtifact ) );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( g1a1 ) );
helper.classRealmAssertions( 2 );
}
示例4: testOneDependencyTwoArtifacts
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
@Test
public void testOneDependencyTwoArtifacts() throws MojoExecutionException {
Artifact g1a1 = helper.createArtifact( "g1", "a1" );
Artifact g1a2 = helper.createArtifact( "g1", "a2" );
List<Artifact> artifacts = asList( helper.fitnesseArtifact, g1a1 );
helper.plugin.addDependency( createDependecy( "g1", "a1" ) );
helper.mojo.pluginDescriptor.setArtifacts( artifacts );
when( helper.artifactResolver.resolve( any( ArtifactResolutionRequest.class ) ) ).thenReturn( helper.createArtifactResolutionResult( helper.fitnesseArtifact ) )
.thenReturn( helper.createArtifactResolutionResult( asList( g1a1, g1a2 ) ) );
assertEquals( "\n", helper.mojo.calcWikiFormatClasspath() );
assertEquals( USING_PLUGIN_CONFIG, helper.logStream.toString() );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( helper.fitnesseArtifact ) );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( g1a1 ) );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( g1a2 ) );
helper.classRealmAssertions( 3 );
}
示例5: testTwoDependenciesTwoArtifacts
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
@Test
public void testTwoDependenciesTwoArtifacts() throws MojoExecutionException {
Artifact g1a1 = helper.createArtifact( "g1", "a1" );
Artifact g2a1 = helper.createArtifact( "g2", "a1" );
List<Artifact> artifacts = asList( helper.fitnesseArtifact, g1a1, g2a1 );
helper.plugin.addDependency( createDependecy( "g1", "a1" ) );
helper.plugin.addDependency( createDependecy( "g2", "a1" ) );
helper.mojo.pluginDescriptor.setArtifacts( artifacts );
when( helper.artifactResolver.resolve( any( ArtifactResolutionRequest.class ) ) ).thenReturn( helper.createArtifactResolutionResult( helper.fitnesseArtifact ) )
.thenReturn( helper.createArtifactResolutionResult( g1a1 ) ).thenReturn( helper.createArtifactResolutionResult( g2a1 ) );
assertEquals( "\n", helper.mojo.calcWikiFormatClasspath() );
assertEquals( USING_PLUGIN_CONFIG, helper.logStream.toString() );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( helper.fitnesseArtifact ) );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( g1a1 ) );
verify( helper.mojo.fitNesseHelper, times( 1 ) ).formatAndAppendClasspathArtifact( any( StringBuilder.class ), eq( g2a1 ) );
helper.classRealmAssertions( 3 );
}
示例6: addDependency
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
private void addDependency( String groupId, String artifactId, String scope, boolean optional ) {
final Artifact artifact = createArtifact( groupId, artifactId );
artifact.setOptional( optional );
artifact.setScope( scope );
if( !optional ){
this.mojo.project.getArtifacts().add( artifact );
}
this.mojo.project.getDependencies().add( createDependecy( groupId, artifactId, scope ) );
this.mojo.project.getDependencyArtifacts().add( artifact );
final ResolutionRequestForArtifact requestMatcher = new ResolutionRequestForArtifact( artifact );
when( this.artifactResolver.resolve( argThat( requestMatcher ) ) ).thenAnswer( new Answer<ArtifactResolutionResult>() {
@Override
public ArtifactResolutionResult answer( InvocationOnMock invocation ) throws Throwable {
ArtifactResolutionRequest request = (ArtifactResolutionRequest) invocation.getArguments()[0];
if( requestMatcher.matches( request ) ){
return createArtifactResolutionResult( artifact, request.getCollectionFilter() );
}
// Should never happen?
return null;
}
} );
}
示例7: resolve
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
public Set<Artifact> resolve(String groupId, String artifactId, String version, final String exclusion)
throws MojoExecutionException {
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setResolveTransitively(true)
.setResolveRoot(true)
.setArtifact(system.createArtifact(groupId, artifactId, version, "jar"))
.setLocalRepository(this.localRepo)
.setRemoteRepositories(remoteRepos).setCollectionFilter(new ArtifactFilter() {
@Override
public boolean include(Artifact artifact) {
if (exclusion != null &&
(artifact.getGroupId() + ":" + artifact.getArtifactId()).equals(exclusion)) {
return false;
}
return artifact.getScope() == null || artifact.getScope().equals("compile") || artifact.getScope().equals("runtime");
}
});
ArtifactResolutionResult result = system.resolve(request);
// TODO error handling
return result.getArtifacts();
}
示例8: getPluginTransitiveDependencies
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
/**
* Read transitive dependencies of given plugin and store them in map.
*
* @param plugin
* plugin to read
* @param map
* map, where founded transitive dependencies will be stored
* @param repoSystem
* repository system
* @param localRepository
* local repository
* @param remoteRepos
* list of remote repositories
*/
private static void getPluginTransitiveDependencies(final Plugin plugin,
final Map<Artifact, Collection<Artifact>> map, final RepositorySystem repoSystem,
final ArtifactRepository localRepository, final List<ArtifactRepository> remoteRepos) {
List<Dependency> pluginDependencies = plugin.getDependencies();
for (Dependency dep : pluginDependencies) {
Artifact artifact = repoSystem.createDependencyArtifact(dep);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveTransitively(true);
request.setLocalRepository(localRepository);
request.setRemoteRepositories(remoteRepos);
ArtifactResolutionResult result = repoSystem.resolve(request);
Set<Artifact> pluginDependencyDependencies = result.getArtifacts();
map.put(artifact, pluginDependencyDependencies);
}
}
示例9: getPomArtifacts
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
/**
* Create Artifact objects for all pom files corresponding to the artifacts that you send in.
*
* @param artifacts
* Set of artifacts to obtain pom's for
*
* @return Artifacts for all the pom files
*/
private Set<Artifact> getPomArtifacts(Set<Artifact> artifacts)
throws MojoExecutionException {
Set<Artifact> poms = new HashSet<>();
for (Artifact artifact : artifacts) {
if (shouldSkipArtifact(artifact)) {
continue;
}
ArtifactResolutionRequest rreq = getArtifactResolutionRequestForPom(artifact);
ArtifactResolutionResult result = repositorySystem.resolve(rreq);
if (result.isSuccess()) {
poms.add(rreq.getArtifact());
} else {
getLog().warn("No pom for " + artifact.getId());
}
}
return poms;
}
示例10: resolveAscArtifact
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
/**
* Retrieves the PGP signature file that corresponds to the given Maven artifact.
*
* @param artifact
* The artifact for which a signature file is desired.
* @return Either a Maven artifact for the signature file, or {@code null} if the signature
* file could not be retrieved.
*
* @throws MojoExecutionException
* If the signature could not be retrieved and the Mojo has been configured to fail
* on a missing signature.
*/
private Artifact resolveAscArtifact(Artifact artifact) throws MojoExecutionException {
Artifact ascArtifact = null;
if (!shouldSkipArtifact(artifact)) {
final ArtifactResolutionRequest ascReq = getArtifactResolutionRequestForAsc(artifact);
final ArtifactResolutionResult ascResult = repositorySystem.resolve(ascReq);
if (ascResult.isSuccess()) {
ascArtifact = ascReq.getArtifact();
getLog().debug(ascArtifact.toString() + " " + ascArtifact.getFile());
} else {
if (failNoSignature) {
getLog().error("No signature for " + artifact.getId());
throw new MojoExecutionException("No signature for " + artifact.getId());
} else {
getLog().warn("No signature for " + artifact.getId());
}
}
}
return ascArtifact;
}
示例11: getArtifactResolutionRequestForAsc
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
/**
* Create ArtifactResolutionRequest for asc file corresponding to artifact.
*
* @param artifact artifact
* @return new ArtifactResolutionRequest
*/
private ArtifactResolutionRequest getArtifactResolutionRequestForAsc(Artifact artifact) {
Artifact aAsc = repositorySystem.createArtifactWithClassifier(
artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
artifact.getType(), artifact.getClassifier());
ArtifactResolutionRequest rreq = new ArtifactResolutionRequest();
aAsc.setArtifactHandler(new AscArtifactHandler(aAsc));
rreq.setArtifact(aAsc);
rreq.setResolveTransitively(false);
rreq.setLocalRepository(localRepository);
rreq.setRemoteRepositories(pomRemoteRepositories);
return rreq;
}
示例12: collect
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
public ArtifactResolutionResult collect( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
{
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
injectSession( request );
return collect( artifacts, originatingArtifact, managedVersions, request, source, filter, listeners,
conflictResolvers );
}
示例13: testSimple
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
@Test
public void testSimple() throws MojoFailureException {
JApiCmpMojo mojo = new JApiCmpMojo();
Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
PluginParameters pluginParameters = new PluginParameters(null, newVersion, oldVersion, new Parameter(), null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "simple").toFile()), Optional.<String>absent(), true, null, null, null, null);
ArtifactResolver artifactResolver = mock(ArtifactResolver.class);
ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class);
Set<Artifact> artifactSet = new HashSet<>();
Artifact resolvedArtifact = mock(Artifact.class);
artifactSet.add(resolvedArtifact);
when(resolvedArtifact.getFile()).thenReturn(Paths.get(System.getProperty("user.dir"), "target", "guava-18.0.jar").toFile());
when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet);
when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult);
ArtifactFactory artifactFactory = mock(ArtifactFactory.class);
when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class));
MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mock(MavenProject.class), mock(MojoExecution.class), "0.0.1", mock(ArtifactMetadataSource.class));
mojo.executeWithParameters(pluginParameters, mavenParameters);
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.diff")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.xml")), is(true));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.html")), is(true));
}
示例14: testIgnoreMissingVersions
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
@Test
public void testIgnoreMissingVersions() throws MojoFailureException, IOException {
JApiCmpMojo mojo = new JApiCmpMojo();
Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
Parameter parameterParam = new Parameter();
parameterParam.setIgnoreMissingNewVersion("true");
parameterParam.setIgnoreMissingOldVersion("true");
PluginParameters pluginParameters = new PluginParameters(null, newVersion, oldVersion, parameterParam, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "simple").toFile()), Optional.<String>absent(), true, null, null, null, null);
ArtifactResolver artifactResolver = mock(ArtifactResolver.class);
ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class);
Set<Artifact> artifactSet = new HashSet<>();
when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet);
when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult);
ArtifactFactory artifactFactory = mock(ArtifactFactory.class);
when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class));
MojoExecution mojoExecution = mock(MojoExecution.class);
String executionId = "ignoreMissingVersions";
when(mojoExecution.getExecutionId()).thenReturn(executionId);
MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mock(MavenProject.class), mojoExecution, "0.0.1", mock(ArtifactMetadataSource.class));
mojo.executeWithParameters(pluginParameters, mavenParameters);
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".diff")), is(false));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".xml")), is(false));
assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".html")), is(false));
}
示例15: resolve
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; //导入依赖的package包/类
public Set<Artifact> resolve(MavenProject project, Artifact artifact) throws MavenExecutionException {
Set<Artifact> artifacts = new HashSet<>();
ArtifactResolutionRequest artifactResolutionRequest = new ArtifactResolutionRequest();
artifactResolutionRequest.setResolveTransitively(true);
artifactResolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
artifactResolutionRequest.setLocalRepository(project.getProjectBuildingRequest().getLocalRepository());
artifactResolutionRequest.setArtifact(artifact);
ArtifactResolutionResult artifactResolutionResult = mavenRepoSystem.resolve(artifactResolutionRequest);
artifactResolutionResult.getArtifacts().stream()
.peek(d -> { if (Flag.verbose()) logger.info("RESOLVED '{}' FROM '{}'", d, artifact); })
.filter(d -> "jar".equals(d.getType()))
.filter(d -> "compile".equals(d.getScope()) || "provided".equals(d.getScope()) || "runtime".equals(d.getScope()))
.forEach(d -> artifacts.add(d));
return artifacts;
}