Search in sources :

Example 11 with Artifact

use of org.apache.maven.artifact.Artifact in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method validateParameters.

/**
   * Initial validation of input parameters and configuration.
   */
private void validateParameters() throws MojoExecutionException {
    // Check for junit dependency on project level.
    Artifact junitArtifact = projectArtifactMap.get(junitArtifactName);
    if (junitArtifact == null) {
        throw new MojoExecutionException("Missing JUnit artifact in project dependencies: " + junitArtifactName);
    }
    checkVersion("JUnit", "[4.10,)", junitArtifact);
    // Fill in complex defaults if not given.
    if (includes == null || includes.isEmpty()) {
        includes = Arrays.asList("**/Test*.class", "**/*Test.class");
    }
    if (excludes == null || excludes.isEmpty()) {
        excludes = Arrays.asList("**/*$*.class");
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 12 with Artifact

use of org.apache.maven.artifact.Artifact in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method resolveArtifact.

/** 
   * Resolve a given artifact given exclusion list. (copied from surefire). 
   */
@SuppressWarnings({ "deprecation" })
private ArtifactResolutionResult resolveArtifact(Artifact artifact, Artifact... filtered) {
    final ArtifactFilter filter;
    if (filtered.length > 0) {
        List<String> exclusions = new ArrayList<>(filtered.length);
        for (Artifact filteredArtifact : filtered) {
            exclusions.add(filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId());
        }
        filter = new ExcludesArtifactFilter(exclusions);
    } else {
        filter = null;
    }
    Artifact originatingArtifact = repositorySystem.createArtifact("dummy", "dummy", "1.0", "jar");
    try {
        return resolver.resolveTransitively(Collections.singleton(artifact), originatingArtifact, session.getLocalRepository(), project.getPluginArtifactRepositories(), metadataSource, filter);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 13 with Artifact

use of org.apache.maven.artifact.Artifact in project spring-boot by spring-projects.

the class IncludeFilterTests method includeGroupIdNoMatch.

@Test
public void includeGroupIdNoMatch() throws ArtifactFilterException {
    IncludeFilter filter = new IncludeFilter(Arrays.asList(createInclude("com.foo", "bar")));
    Artifact artifact = createArtifact("com.baz", "bar");
    Set result = filter.filter(Collections.singleton(artifact));
    assertThat(result).isEmpty();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 14 with Artifact

use of org.apache.maven.artifact.Artifact in project spring-boot by spring-projects.

the class ArtifactsLibrariesTests method renamesDuplicates.

@Test
public void renamesDuplicates() throws Exception {
    Artifact artifact1 = mock(Artifact.class);
    Artifact artifact2 = mock(Artifact.class);
    given(artifact1.getType()).willReturn("jar");
    given(artifact1.getScope()).willReturn("compile");
    given(artifact1.getGroupId()).willReturn("g1");
    given(artifact1.getArtifactId()).willReturn("artifact");
    given(artifact1.getBaseVersion()).willReturn("1.0");
    given(artifact1.getFile()).willReturn(new File("a"));
    given(artifact1.getArtifactHandler()).willReturn(this.artifactHandler);
    given(artifact2.getType()).willReturn("jar");
    given(artifact2.getScope()).willReturn("compile");
    given(artifact2.getGroupId()).willReturn("g2");
    given(artifact2.getArtifactId()).willReturn("artifact");
    given(artifact2.getBaseVersion()).willReturn("1.0");
    given(artifact2.getFile()).willReturn(new File("a"));
    given(artifact2.getArtifactHandler()).willReturn(this.artifactHandler);
    this.artifacts = new LinkedHashSet<>(Arrays.asList(artifact1, artifact2));
    this.libs = new ArtifactsLibraries(this.artifacts, null, mock(Log.class));
    this.libs.doWithLibraries(this.callback);
    verify(this.callback, times(2)).library(this.libraryCaptor.capture());
    assertThat(this.libraryCaptor.getAllValues().get(0).getName()).isEqualTo("g1-artifact-1.0.jar");
    assertThat(this.libraryCaptor.getAllValues().get(1).getName()).isEqualTo("g2-artifact-1.0.jar");
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 15 with Artifact

use of org.apache.maven.artifact.Artifact in project spring-boot by spring-projects.

the class DependencyFilterMojoTests method filterScopeKeepOrder.

@Test
public void filterScopeKeepOrder() throws MojoExecutionException {
    TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.<Exclude>emptyList(), "", "", new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
    Artifact one = createArtifact("com.foo", "one");
    Artifact two = createArtifact("com.foo", "two", Artifact.SCOPE_SYSTEM);
    Artifact three = createArtifact("com.foo", "three", Artifact.SCOPE_RUNTIME);
    Set<Artifact> artifacts = mojo.filterDependencies(one, two, three);
    assertThat(artifacts).containsExactly(one, three);
}
Also used : ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)450 File (java.io.File)175 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)92 ArrayList (java.util.ArrayList)91 MavenProject (org.apache.maven.project.MavenProject)63 IOException (java.io.IOException)50 HashSet (java.util.HashSet)42 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 LinkedHashSet (java.util.LinkedHashSet)29 MojoFailureException (org.apache.maven.plugin.MojoFailureException)24 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 URL (java.net.URL)20 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 MalformedURLException (java.net.MalformedURLException)18 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)16