org.apache.maven.artifact.factory.ArtifactFactory Java Examples

The following examples show how to use org.apache.maven.artifact.factory.ArtifactFactory. 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: DependenciesRenderer.java    From maven-confluence-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param sink
 * @param project
 * @param mavenProjectBuilder
 * @param locale
 * @param listener
 */
public DependenciesRenderer(	Sink sink, 
								MavenProject project, 
								MavenProjectBuilder mavenProjectBuilder,
								ArtifactRepository localRepository,
								ArtifactFactory factory,
								I18N i18n,
								Locale locale, 
								ReportingResolutionListener listener,
								Log log )
{
    super( sink );

    this.project = project;
    this.locale = locale;
    this.listener = listener;
    this.mavenProjectBuilder = mavenProjectBuilder;
    this.localRepository = localRepository;
    this.i18n 	= i18n;
    this.factory = factory;
    this.log = log;
}
 
Example #2
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 #3
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 #4
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 #5
Source File: DependencyTreeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static DependencyNode createDependencyTree(MavenProject project,
        DependencyTreeBuilder dependencyTreeBuilder, ArtifactRepository localRepository,
        ArtifactFactory artifactFactory, ArtifactMetadataSource artifactMetadataSource,
        ArtifactCollector artifactCollector,
        String scope) {
    ArtifactFilter artifactFilter = createResolvingArtifactFilter(scope);

    try {
        // TODO: note that filter does not get applied due to MNG-3236
        return dependencyTreeBuilder.buildDependencyTree(project,
                localRepository, artifactFactory,
                artifactMetadataSource, artifactFilter, artifactCollector);
    } catch (DependencyTreeBuilderException exception) {
    }
    return null;
}
 
Example #6
Source File: RunEpisodesBPlugin.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void setUp() throws Exception {
	super.setUp();

	mavenProjectBuilder = (MavenProjectBuilder) getContainer().lookup(
			MavenProjectBuilder.ROLE);
	ArtifactFactory artifactFactory = (ArtifactFactory) getContainer()
			.lookup(ArtifactFactory.ROLE);

	final Map<String, Mojo> mojos = (Map<String, Mojo>) getContainer()
			.lookupMap(Mojo.ROLE);

	for (Mojo mojo : mojos.values()) {
		if (mojo instanceof Hyperjaxb3Mojo) {
			this.mojo = (Hyperjaxb3Mojo) mojo;
		}
	}

	MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) getContainer()
			.lookup(MavenSettingsBuilder.ROLE);
	ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) getContainer()
			.lookup(ArtifactRepositoryLayout.ROLE, "default");

	Settings settings = settingsBuilder.buildSettings();

	String url = settings.getLocalRepository();

	if (!url.startsWith("file:")) {
		url = "file://" + url;
	}

	localRepository = new DefaultArtifactRepository("local", url,
			new DefaultRepositoryLayout());
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
Source File: CreateEffectivePomTest.java    From flatten-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Tests method to create effective POM.
 *
 * @throws Exception if something goes wrong.
 */
@Test
public void testCreateEffectivePom()
    throws Exception
{

    String magicValue = "magic-value";
    Properties userProperties = new Properties();
    userProperties.setProperty( "cmd.test.property", magicValue );

    File pomFile = new File( "src/test/resources/cmdpropertysubstituion/pom.xml" );
    ArtifactRepository localRepository = new MavenArtifactRepository();
    localRepository.setLayout( new DefaultRepositoryLayout() );
    ArtifactFactory artifactFactory = new DefaultArtifactFactory();
    ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager();
    setDeclaredField( artifactFactory, "artifactHandlerManager", artifactHandlerManager );
    Map<String, ArtifactHandler> artifactHandlers = new HashMap<String, ArtifactHandler>();
    setDeclaredField( artifactHandlerManager, "artifactHandlers", artifactHandlers );
    DefaultDependencyResolver depencencyResolver = new DefaultDependencyResolver();
    DefaultProjectBuildingRequest projectBuildingRequest = new DefaultProjectBuildingRequest();
    FlattenModelResolver resolver = new FlattenModelResolver( localRepository, artifactFactory,
            depencencyResolver, projectBuildingRequest, Collections.<MavenProject>emptyList() );
    ModelBuildingRequest buildingRequest =
        new DefaultModelBuildingRequest().setPomFile( pomFile ).setModelResolver( resolver ).setUserProperties( userProperties );
    setDeclaredField( tested, "modelBuilderThreadSafetyWorkaround", buildModelBuilderThreadSafetyWorkaroundForTest() );
    Model effectivePom = tested.createEffectivePom( buildingRequest, false, FlattenMode.defaults );
    assertThat( effectivePom.getName() ).isEqualTo( magicValue );
}
 
Example #12
Source File: FlattenModelResolver.java    From flatten-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * The constructor.
 * @param localRepository is the local repository.
 * @param artifactFactory is the factory used to create project artifact instances.
 * @param dependencyResolver is the resolver to use for resolving version ranges.
 * @param projectBuildingRequest is the request for resolving version ranges against {@code dependencyResolver}.
 * @param reactorModels is the list of modules of the project being built.
 */
public FlattenModelResolver( ArtifactRepository localRepository, ArtifactFactory artifactFactory,
                            DependencyResolver dependencyResolver,
                            ProjectBuildingRequest projectBuildingRequest, List<MavenProject> reactorModels )
{
    this.localRepository = localRepository;
    this.artifactFactory = artifactFactory;
    this.depencencyResolver = dependencyResolver;
    this.projectBuildingRequest = projectBuildingRequest;
    this.reactorModelPool = new ReactorModelPool();
    reactorModelPool.addProjects( reactorModels );
}
 
Example #13
Source File: SignaturesArtifact.java    From forbidden-apis with Apache License 2.0 5 votes vote down vote up
/** Used by the mojo to fetch the artifact */
Artifact createArtifact(ArtifactFactory artifactFactory) {
  if (groupId == null || artifactId == null || version == null || type == null) {
    throw new NullPointerException("signaturesArtifact is missing some properties. Required are: groupId, artifactId, version, type");
  }
  return artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
}
 
Example #14
Source File: PluginsRenderer.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * @param log
 * @param sink
 * @param locale
 * @param i18n
 * @param plugins
 * @param reports
 * @param project
 * @param mavenProjectBuilder
 * @param artifactFactory
 * @param localRepository
 */
public PluginsRenderer( 
        Log log, 
        Sink sink, 
        Locale locale, 
        I18N i18n, 
        Set<Artifact> plugins, 
        Set<Artifact> reports,
        MavenProject project, 
        MavenProjectBuilder mavenProjectBuilder,
        ArtifactFactory artifactFactory, 
        ArtifactRepository localRepository )
{
    super( sink );

    this.log = log;

    this.locale = locale;

    this.plugins = new ArrayList<>( plugins );

    this.reports = new ArrayList<>( reports );

    this.i18n = i18n;

    this.project = project;

    this.mavenProjectBuilder = mavenProjectBuilder;

    this.artifactFactory = artifactFactory;

    this.localRepository = localRepository;
}
 
Example #15
Source File: DefaultVersionsHelper.java    From versions-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ArtifactFactory getArtifactFactory()
{
    return artifactFactory;
}
 
Example #16
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ArtifactFactory getArtifactFactory() {
	return artifactFactory;
}
 
Example #17
Source File: AbstractXJC2Mojo.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void setArtifactFactory(ArtifactFactory artifactFactory) {
	this.artifactFactory = artifactFactory;
}
 
Example #18
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 #19
Source File: ResolverWrapper.java    From multi-module-maven-release-plugin with MIT License 4 votes vote down vote up
public ArtifactFactory getFactory() {
    return factory;
}
 
Example #20
Source File: MavenParameters.java    From japicmp with Apache License 2.0 4 votes vote down vote up
public ArtifactFactory getArtifactFactory() {
	return artifactFactory;
}
 
Example #21
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 #22
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;
}
 
Example #23
Source File: VersionsHelper.java    From versions-maven-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the artifact factory to use.
 *
 * @return the artifact factory to use.
 * @since 1.0-alpha-3
 */
ArtifactFactory getArtifactFactory();