org.apache.maven.artifact.metadata.ArtifactMetadataSource Java Examples
The following examples show how to use
org.apache.maven.artifact.metadata.ArtifactMetadataSource.
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 |
@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: DefaultVersionsHelperTest.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private DefaultVersionsHelper createHelper( String rulesUri, ArtifactMetadataSource metadataSource ) throws MojoExecutionException { final DefaultWagonManager wagonManager = new DefaultWagonManager() { public Wagon getWagon( Repository repository ) throws UnsupportedProtocolException, WagonConfigurationException { return new FileWagon(); } }; DefaultVersionsHelper helper = new DefaultVersionsHelper( new DefaultArtifactFactory(), new DefaultArtifactResolver(), metadataSource, new ArrayList(), new ArrayList(), new DefaultArtifactRepository( "", "", new DefaultRepositoryLayout() ), wagonManager, new Settings(), "", rulesUri, mock( Log.class ), mock( MavenSession.class ), new DefaultPathTranslator()); return helper; }
Example #3
Source File: DefaultArtifactDownloader.java From opoopress with Apache License 2.0 | 6 votes |
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 |
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 |
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: ArtifactUtils.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 5 votes |
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 #7
Source File: JApiCmpMojoTest.java From japicmp with Apache License 2.0 | 5 votes |
@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 |
@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 |
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: DefaultVersionsHelperTest.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private DefaultVersionsHelper createHelper( ArtifactMetadataSource metadataSource ) throws MojoExecutionException { final String resourcePath = "/" + getClass().getPackage().getName().replace( '.', '/' ) + "/rules.xml"; final String rulesUri = getClass().getResource( resourcePath ).toExternalForm(); DefaultVersionsHelper helper = createHelper( rulesUri, metadataSource ); return helper; }
Example #11
Source File: DefaultVersionsHelperTest.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
@Test public void testGlobalRuleVersionsIgnored() throws Exception { final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class ); final Artifact artifact = mock( Artifact.class ); when( artifact.getGroupId() ).thenReturn( "other.company" ); when( artifact.getArtifactId() ).thenReturn( "artifact-two" ); final List<ArtifactVersion> artifactVersions = new ArrayList<ArtifactVersion>(); final ArtifactVersion one = new DefaultArtifactVersion( "one" ); final ArtifactVersion two = new DefaultArtifactVersion( "two" ); final ArtifactVersion three = new DefaultArtifactVersion( "three" ); artifactVersions.add( one ); artifactVersions.add( two ); artifactVersions.add( new DefaultArtifactVersion( "three-alpha" ) ); artifactVersions.add( new DefaultArtifactVersion( "three-beta" ) ); artifactVersions.add( three ); final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" ); artifactVersions.add( illegal ); when(metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) ) .thenReturn( artifactVersions ); VersionsHelper helper = createHelper( metadataSource ); final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true ); final List<ArtifactVersion> actual = asList( versions.getVersions( true ) ); assertEquals( 4, actual.size() ); assertThat( actual, hasItems( one, two, three, illegal ) ); }
Example #12
Source File: DefaultVersionsHelperTest.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
@Test public void testPerRuleVersionsIgnored() throws Exception { final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class ); final Artifact artifact = mock( Artifact.class ); when( artifact.getGroupId() ).thenReturn( "com.mycompany.maven" ); when( artifact.getArtifactId() ).thenReturn( "artifact-one" ); final List<ArtifactVersion> artifactVersions = new ArrayList<ArtifactVersion>(); artifactVersions.add( new DefaultArtifactVersion( "one" ) ); artifactVersions.add( new DefaultArtifactVersion( "two" ) ); final ArtifactVersion three = new DefaultArtifactVersion( "three" ); artifactVersions.add( three ); final ArtifactVersion oneTwoHundred = new DefaultArtifactVersion( "1.200" ); artifactVersions.add( oneTwoHundred ); final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" ); artifactVersions.add( illegal ); when( metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) ) .thenReturn( artifactVersions ); VersionsHelper helper = createHelper( metadataSource ); final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true ); final List<ArtifactVersion> actual = asList( versions.getVersions( true ) ); assertEquals( 3, actual.size() ); assertThat( actual, hasItems( three, oneTwoHundred, illegal ) ); }
Example #13
Source File: AbstractXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 4 votes |
public void setArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource) { this.artifactMetadataSource = artifactMetadataSource; }
Example #14
Source File: AbstractXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 4 votes |
public ArtifactMetadataSource getArtifactMetadataSource() { return artifactMetadataSource; }
Example #15
Source File: MavenParameters.java From japicmp with Apache License 2.0 | 4 votes |
public ArtifactMetadataSource getMetadataSource() { return metadataSource; }
Example #16
Source File: SkipModuleStrategyTest.java From japicmp with Apache License 2.0 | 4 votes |
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: DefaultVersionsHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
/** * 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; }