Search in sources :

Example 16 with Artifact

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

the class AbstractRunMojo method addDependencies.

private void addDependencies(List<URL> urls) throws MalformedURLException, MojoExecutionException {
    FilterArtifacts filters = this.useTestClasspath ? getFilters() : getFilters(new TestArtifactFilter());
    Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), filters);
    for (Artifact artifact : artifacts) {
        if (artifact.getFile() != null) {
            urls.add(artifact.getFile().toURI().toURL());
        }
    }
}
Also used : FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Artifact(org.apache.maven.artifact.Artifact)

Example 17 with Artifact

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

the class ArtifactsLibraries method doWithLibraries.

@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
    Set<String> duplicates = getDuplicates(this.artifacts);
    for (Artifact artifact : this.artifacts) {
        LibraryScope scope = SCOPES.get(artifact.getScope());
        if (scope != null && artifact.getFile() != null) {
            String name = getFileName(artifact);
            if (duplicates.contains(name)) {
                this.log.debug("Duplicate found: " + name);
                name = artifact.getGroupId() + "-" + name;
                this.log.debug("Renamed to: " + name);
            }
            callback.library(new Library(name, artifact.getFile(), scope, isUnpackRequired(artifact)));
        }
    }
}
Also used : Library(org.springframework.boot.loader.tools.Library) LibraryScope(org.springframework.boot.loader.tools.LibraryScope) Artifact(org.apache.maven.artifact.Artifact)

Example 18 with Artifact

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

the class DependencyFilterMojoTests method filterGroupIdKeepOrder.

@Test
public void filterGroupIdKeepOrder() throws MojoExecutionException {
    TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.<Exclude>emptyList(), "com.foo", "");
    Artifact one = createArtifact("com.foo", "one");
    Artifact two = createArtifact("com.bar", "two");
    Artifact three = createArtifact("com.bar", "three");
    Artifact four = createArtifact("com.foo", "four");
    Set<Artifact> artifacts = mojo.filterDependencies(one, two, three, four);
    assertThat(artifacts).containsExactly(two, three);
}
Also used : Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 19 with Artifact

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

the class ExcludeFilterTests method excludeGroupIdNoMatch.

@Test
public void excludeGroupIdNoMatch() throws ArtifactFilterException {
    ExcludeFilter filter = new ExcludeFilter(Arrays.asList(createExclude("com.foo", "bar")));
    Artifact artifact = createArtifact("com.baz", "bar");
    Set result = filter.filter(Collections.singleton(artifact));
    assertThat(result).hasSize(1);
    assertThat(result.iterator().next()).isSameAs(artifact);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 20 with Artifact

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

the class IncludeFilterTests method createArtifact.

private Artifact createArtifact(String groupId, String artifactId, String classifier) {
    Artifact a = mock(Artifact.class);
    given(a.getGroupId()).willReturn(groupId);
    given(a.getArtifactId()).willReturn(artifactId);
    given(a.getClassifier()).willReturn(classifier);
    return a;
}
Also used : Artifact(org.apache.maven.artifact.Artifact)

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