org.apache.maven.artifact.resolver.ArtifactResolver Java Examples

The following examples show how to use org.apache.maven.artifact.resolver.ArtifactResolver. 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: JApiCmpMojoTest.java    From japicmp with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws MojoFailureException, MojoExecutionException {
	JApiCmpMojo mojo = new JApiCmpMojo();
	Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
	Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
	PluginParameters pluginParameters = new PluginParameters(false, 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));
	MavenProject mavenProject = mock(MavenProject.class);
	when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class));
	MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, 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));
}
 
Example #2
Source File: DefaultArtifactDownloader.java    From opoopress with Apache License 2.0 6 votes vote down vote up
public DefaultArtifactDownloader(Log log,
                                 ArtifactFactory artifactFactory,
                                 ArtifactResolver artifactResolver,
                                 ArtifactRepository localRepository,
                                 List<ArtifactRepository> remoteArtifactRepositories,
                                 String remoteRepositories,
                                 Map<String, ArtifactRepositoryLayout> repositoryLayouts,
                                 ArtifactRepositoryFactory artifactRepositoryFactory,
                                 ArtifactMetadataSource artifactMetadataSource,
                                 boolean enableOpooPressRepos) {
    this.artifactFactory = artifactFactory;
    this.artifactResolver = artifactResolver;
    this.localRepository = localRepository;
    this.remoteArtifactRepositories = remoteArtifactRepositories;
    this.remoteRepositories = remoteRepositories;
    this.repositoryLayouts = repositoryLayouts;
    this.artifactRepositoryFactory = artifactRepositoryFactory;
    this.artifactMetadataSource = artifactMetadataSource;
    this.enableOpooPressRepos = enableOpooPressRepos;
    this.log = log;
}
 
Example #3
Source File: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Collection<Artifact> resolve(
		final ArtifactFactory artifactFactory,
		final ArtifactResolver artifactResolver,
		final ArtifactRepository localRepository,
		final ArtifactMetadataSource artifactMetadataSource,
		final Dependency[] dependencies, final MavenProject project)
		throws InvalidDependencyVersionException,
		ArtifactResolutionException, ArtifactNotFoundException {
	if (dependencies == null) {
		return Collections.emptyList();
	}

	@SuppressWarnings("unchecked")
	final Set<Artifact> artifacts = MavenMetadataSource.createArtifacts(
			artifactFactory, Arrays.asList(dependencies), "runtime", null,
			project);

	for (Artifact artifact : artifacts) {
		artifactResolver.resolve(artifact,

		project.getRemoteArtifactRepositories(), localRepository);
	}

	final Set<Artifact> resolvedArtifacts = artifacts;
	return resolvedArtifacts;
}
 
Example #4
Source File: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Collection<Artifact> resolveTransitively(
		final ArtifactFactory artifactFactory,
		final ArtifactResolver artifactResolver,
		final ArtifactRepository localRepository,
		final ArtifactMetadataSource artifactMetadataSource,
		final Dependency[] dependencies, final MavenProject project)
		throws InvalidDependencyVersionException,
		ArtifactResolutionException, ArtifactNotFoundException {
	if (dependencies == null) {
		return Collections.emptyList();
	}

	@SuppressWarnings("unchecked")
	final Set<Artifact> artifacts = MavenMetadataSource.createArtifacts(
			artifactFactory, Arrays.asList(dependencies), "runtime", null,
			project);

	final ArtifactResolutionResult artifactResolutionResult = artifactResolver
			.resolveTransitively(artifacts,

			project.getArtifact(),

			project.getRemoteArtifactRepositories(), localRepository,
					artifactMetadataSource);

	@SuppressWarnings("unchecked")
	final Set<Artifact> resolvedArtifacts = artifactResolutionResult
			.getArtifacts();

	return resolvedArtifacts;
}
 
Example #5
Source File: JApiCmpMojoTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnoreMissingVersions() throws MojoFailureException, IOException, MojoExecutionException {
	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(false, 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);
	MavenProject mavenProject = mock(MavenProject.class);
	when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class));
	MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, 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));
}
 
Example #6
Source File: JApiCmpMojoTest.java    From japicmp with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoXmlAndNoHtmlNoDiffReport() throws MojoFailureException, MojoExecutionException {
	JApiCmpMojo mojo = new JApiCmpMojo();
	Version oldVersion = createVersion("groupId", "artifactId", "0.1.0");
	Version newVersion = createVersion("groupId", "artifactId", "0.1.1");
	Parameter parameter = new Parameter();
	parameter.setSkipHtmlReport(true);
	parameter.setSkipXmlReport(true);
	parameter.setSkipDiffReport(true);
	String reportDir = "noXmlAndNoHtmlNoDiffReport";
	PluginParameters pluginParameters = new PluginParameters(false, newVersion, oldVersion, parameter, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", reportDir).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));
	MavenProject mavenProject = mock(MavenProject.class);
	when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class));
	MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, mock(MojoExecution.class), "0.0.1", mock(ArtifactMetadataSource.class));
	mojo.executeWithParameters(pluginParameters, mavenParameters);
	assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.diff")), is(false));
	assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.xml")), is(false));
	assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.html")), is(false));
}
 
Example #7
Source File: MavenParameters.java    From japicmp with Apache License 2.0 5 votes vote down vote up
public MavenParameters(List<ArtifactRepository> artifactRepositories, ArtifactFactory artifactFactory, ArtifactRepository localRepository,
					   ArtifactResolver artifactResolver, MavenProject mavenProject, MojoExecution mojoExecution, String versionRangeWithProjectVersion, ArtifactMetadataSource metadataSource) {
	this.artifactRepositories = artifactRepositories;
	this.artifactFactory = artifactFactory;
	this.localRepository = localRepository;
	this.artifactResolver = artifactResolver;
	this.mavenProject = mavenProject;
	this.mojoExecution = mojoExecution;
	this.versionRangeWithProjectVersion = versionRangeWithProjectVersion;
	this.metadataSource = metadataSource;
}
 
Example #8
Source File: AbstractGeneratorTask.java    From gradle-plugins with MIT License 5 votes vote down vote up
private MojoScanner getMojoScanner() {
    Map<String, MojoDescriptorExtractor> extractors = new TreeMap<>();
    JavaAnnotationsMojoDescriptorExtractor mojoDescriptorExtractor = new JavaAnnotationsMojoDescriptorExtractor();

    DefaultMojoAnnotationsScanner delegate = new DefaultMojoAnnotationsScanner();
    delegate.enableLogging(new PlexusLoggerWrapper(getLogger()));
    MojoAnnotationScannerWrapper mojoAnnotationsScanner = new MojoAnnotationScannerWrapper(delegate);
    mojoAnnotationsScanner.setSourceDirectories(sourceDirectories);
    mojoAnnotationsScanner.setClassesDirectories(classesDirectories);

    ArtifactResolver artifactResolver = new DefaultArtifactResolver();
    DefaultArtifactFactory artifactFactory = new DefaultArtifactFactory();
    ArchiverManager archiverManager = new DefaultArchiverManager();

    Map<String, Object> values = new HashMap<>();
    values.put("mojoAnnotationsScanner", mojoAnnotationsScanner);
    values.put("artifactResolver", artifactResolver);
    values.put("artifactFactory", artifactFactory);
    values.put("archiverManager", archiverManager);

    try {
        Class<JavaAnnotationsMojoDescriptorExtractor> clazz = JavaAnnotationsMojoDescriptorExtractor.class;
        for (Map.Entry<String, Object> entry : values.entrySet()) {
            Field declaredField = clazz.getDeclaredField(entry.getKey());
            declaredField.setAccessible(true);
            declaredField.set(mojoDescriptorExtractor, entry.getValue());
        }
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new RuntimeException(e);
    }

    extractors.put("java-annotations", mojoDescriptorExtractor);
    DefaultMojoScanner defaultMojoScanner = new DefaultMojoScanner(extractors);
    defaultMojoScanner.enableLogging(new PlexusLoggerWrapper(getLogger()));
    return defaultMojoScanner;
}
 
Example #9
Source File: AbstractGeneratorTask.java    From gradle-plugins with MIT License 5 votes vote down vote up
private MojoScanner getMojoScanner() {
    Map<String, MojoDescriptorExtractor> extractors = new TreeMap<>();
    JavaAnnotationsMojoDescriptorExtractor mojoDescriptorExtractor = new JavaAnnotationsMojoDescriptorExtractor();

    DefaultMojoAnnotationsScanner delegate = new DefaultMojoAnnotationsScanner();
    delegate.enableLogging(new PlexusLoggerWrapper(getLogger()));
    MojoAnnotationScannerWrapper mojoAnnotationsScanner = new MojoAnnotationScannerWrapper(delegate);
    mojoAnnotationsScanner.setSourceDirectories(sourceDirectories);
    mojoAnnotationsScanner.setClassesDirectories(classesDirectories);

    ArtifactResolver artifactResolver = new DefaultArtifactResolver();
    DefaultArtifactFactory artifactFactory = new DefaultArtifactFactory();
    ArchiverManager archiverManager = new DefaultArchiverManager();

    Map<String, Object> values = new HashMap<>();
    values.put("mojoAnnotationsScanner", mojoAnnotationsScanner);
    values.put("artifactResolver", artifactResolver);
    values.put("artifactFactory", artifactFactory);
    values.put("archiverManager", archiverManager);

    try {
        Class<JavaAnnotationsMojoDescriptorExtractor> clazz = JavaAnnotationsMojoDescriptorExtractor.class;
        for (Map.Entry<String, Object> entry : values.entrySet()) {
            Field declaredField = clazz.getDeclaredField(entry.getKey());
            declaredField.setAccessible(true);
            declaredField.set(mojoDescriptorExtractor, entry.getValue());
        }
    } catch (IllegalAccessException | NoSuchFieldException e) {
        throw new RuntimeException(e);
    }

    extractors.put("java-annotations", mojoDescriptorExtractor);
    DefaultMojoScanner defaultMojoScanner = new DefaultMojoScanner(extractors);
    defaultMojoScanner.enableLogging(new PlexusLoggerWrapper(getLogger()));
    return defaultMojoScanner;
}
 
Example #10
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setArtifactResolver(ArtifactResolver artifactResolver) {
	this.artifactResolver = artifactResolver;
}
 
Example #11
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactResolver getArtifactResolver() {
	return artifactResolver;
}
 
Example #12
Source File: ExtensionClassLoaderFactory.java    From nifi-maven with Apache License 2.0 4 votes vote down vote up
public Builder artifactResolver(final ArtifactResolver resolver) {
    this.artifactResolver = resolver;
    return this;
}
 
Example #13
Source File: DefaultVersionsHelper.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a new {@link DefaultVersionsHelper}.
 *
 * @param artifactFactory The artifact factory.
 * @param artifactResolver Artifact resolver
 * @param artifactMetadataSource The artifact metadata source to use.
 * @param remoteArtifactRepositories The remote artifact repositories to consult.
 * @param remotePluginRepositories The remote plugin repositories to consult.
 * @param localRepository The local repository to consult.
 * @param wagonManager The wagon manager (used if rules need to be retrieved).
 * @param settings The settings (used to provide proxy information to the wagon manager).
 * @param serverId The serverId hint for the wagon manager.
 * @param rulesUri The URL to retrieve the versioning rules from.
 * @param log The {@link org.apache.maven.plugin.logging.Log} to send log messages to.
 * @param mavenSession The maven session information.
 * @param pathTranslator The path translator component. @throws org.apache.maven.plugin.MojoExecutionException If
 *            things go wrong.
 * @throws MojoExecutionException if something goes wrong.
 * @since 1.0-alpha-3
 */
public DefaultVersionsHelper( ArtifactFactory artifactFactory, ArtifactResolver artifactResolver,
                              ArtifactMetadataSource artifactMetadataSource, List remoteArtifactRepositories,
                              List remotePluginRepositories, ArtifactRepository localRepository,
                              WagonManager wagonManager, Settings settings, String serverId, String rulesUri,
                              Log log, MavenSession mavenSession, PathTranslator pathTranslator )
    throws MojoExecutionException
{
    this.artifactFactory = artifactFactory;
    this.artifactResolver = artifactResolver;
    this.mavenSession = mavenSession;
    this.pathTranslator = pathTranslator;
    this.ruleSet = loadRuleSet( serverId, settings, wagonManager, rulesUri, log );
    this.artifactMetadataSource = artifactMetadataSource;
    this.localRepository = localRepository;
    this.remoteArtifactRepositories = remoteArtifactRepositories;
    this.remotePluginRepositories = remotePluginRepositories;
    this.log = log;
}
 
Example #14
Source File: AbstractVersionsReport.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
public ArtifactResolver getResolver()
{
    return resolver;
}
 
Example #15
Source File: MavenParameters.java    From japicmp with Apache License 2.0 4 votes vote down vote up
public ArtifactResolver getArtifactResolver() {
	return artifactResolver;
}
 
Example #16
Source File: SkipModuleStrategyTest.java    From japicmp with Apache License 2.0 4 votes vote down vote up
private MavenParameters createMavenParameters() {
	return new MavenParameters(new ArrayList<ArtifactRepository>(), mock(ArtifactFactory.class), mock(ArtifactRepository.class),
		mock(ArtifactResolver.class), new MavenProject(), mock(MojoExecution.class), "", mock(ArtifactMetadataSource.class));
}
 
Example #17
Source File: ResolverWrapper.java    From multi-module-maven-release-plugin with MIT License 4 votes vote down vote up
public ArtifactResolver getArtifactResolver() {
    return artifactResolver;
}
 
Example #18
Source File: ResolverWrapper.java    From multi-module-maven-release-plugin with MIT License 4 votes vote down vote up
public ResolverWrapper(ArtifactFactory factory, ArtifactResolver artifactResolver, List remoteRepositories, ArtifactRepository localRepository) {
    this.factory = factory;
    this.artifactResolver = artifactResolver;
    this.remoteRepositories = remoteRepositories;
    this.localRepository = localRepository;
}