Search in sources :

Example 16 with ScopeArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeCompileScope.

public void testCopyDependenciesMojoIncludeCompileScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "compile";
    mojo.execute();
    ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
    Set<Artifact> artifacts = mojo.getProject().getArtifacts();
    for (Artifact artifact : artifacts) {
        String fileName = DependencyUtil.getFormattedFileName(artifact, false);
        File file = new File(mojo.outputDirectory, fileName);
        assertEquals(saf.include(artifact), file.exists());
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 17 with ScopeArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.

the class TestUnpackDependenciesMojo method testIncludeTestScope.

public void testIncludeTestScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "test";
    mojo.execute();
    ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
    for (Artifact artifact : (Iterable<Artifact>) mojo.getProject().getArtifacts()) {
        assertUnpacked(saf.include(artifact), artifact);
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 18 with ScopeArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.

the class TestUnpackDependenciesMojo method testExcludeRuntimeScope.

public void testExcludeRuntimeScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.excludeScope = "runtime";
    mojo.execute();
    ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.excludeScope);
    for (Artifact artifact : (Iterable<Artifact>) mojo.getProject().getArtifacts()) {
        assertUnpacked(!saf.include(artifact), artifact);
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 19 with ScopeArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.

the class AbstractEarMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
    getLog().debug("Resolving artifact type mappings ...");
    ArtifactTypeMappingService typeMappingService;
    try {
        typeMappingService = new ArtifactTypeMappingService();
        typeMappingService.configure(artifactTypeMappings);
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize artifact type mappings", e);
    } catch (PlexusConfigurationException e) {
        throw new MojoExecutionException("Invalid artifact type mappings configuration", e);
    }
    getLog().debug("Initializing JBoss configuration if necessary ...");
    try {
        initializeJbossConfiguration();
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize JBoss configuration", e);
    }
    getLog().debug("Initializing ear execution context");
    EarExecutionContext earExecutionContext = new EarExecutionContext(project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, fileNameMapping, typeMappingService);
    if (useBaseVersion != null) {
        earExecutionContext.getFileNameMapping().setUseBaseVersion(useBaseVersion);
    }
    getLog().debug("Resolving ear modules ...");
    List<EarModule> allModules = new ArrayList<EarModule>();
    try {
        if (modules != null && modules.length > 0) {
            // Let's validate user-defined modules
            EarModule module;
            for (EarModule module1 : modules) {
                module = module1;
                getLog().debug("Resolving ear module[" + module + "]");
                module.setEarExecutionContext(earExecutionContext);
                module.resolveArtifact(project.getArtifacts());
                allModules.add(module);
            }
        }
        // Let's add other modules
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            // since it's used for transitive deps only.
            if ("pom".equals(artifact.getType())) {
                continue;
            }
            // Artifact is not yet registered and it has not test scope, nor is it optional
            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
            if (!isArtifactRegistered(artifact, allModules) && !artifact.isOptional() && filter.include(artifact)) {
                EarModule module = EarModuleFactory.newEarModule(artifact, javaEEVersion, defaultLibBundleDir, includeLibInApplicationXml, typeMappingService);
                module.setEarExecutionContext(earExecutionContext);
                allModules.add(module);
            }
        }
    } catch (EarPluginException e) {
        throw new MojoExecutionException("Failed to initialize ear modules", e);
    }
    // Now we have everything let's built modules which have not been excluded
    ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
    allJarModules = new ArrayList<JarModule>();
    earModules = new ArrayList<EarModule>();
    for (EarModule earModule : allModules) {
        if (earModule.isExcluded()) {
            getLog().debug("Skipping ear module[" + earModule + "]");
        } else {
            if (earModule instanceof JarModule) {
                allJarModules.add((JarModule) earModule);
            }
            if (filter.include(earModule.getArtifact())) {
                earModules.add(earModule);
            }
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) PlexusConfigurationException(org.codehaus.plexus.configuration.PlexusConfigurationException) ArtifactTypeMappingService(org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)

Example 20 with ScopeArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.

the class OverlayManager method getOverlaysAsArtifacts.

/**
     * Returns a list of WAR {@link org.apache.maven.artifact.Artifact} describing the overlays of the current project.
     *
     * @return the overlays as artifacts objects
     */
private List<Artifact> getOverlaysAsArtifacts() {
    ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
    final Set<Artifact> artifacts = project.getArtifacts();
    final List<Artifact> result = new ArrayList<Artifact>();
    for (Artifact artifact : artifacts) {
        if (!artifact.isOptional() && filter.include(artifact) && ("war".equals(artifact.getType()))) {
            result.add(artifact);
        }
    }
    return result;
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)20 Artifact (org.apache.maven.artifact.Artifact)19 File (java.io.File)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 MavenArchiver (org.apache.maven.archiver.MavenArchiver)1 PomPropertiesUtil (org.apache.maven.archiver.PomPropertiesUtil)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 ArtifactTypeMappingService (org.apache.maven.plugins.ear.util.ArtifactTypeMappingService)1 JavaEEVersion (org.apache.maven.plugins.ear.util.JavaEEVersion)1 MavenProject (org.apache.maven.project.MavenProject)1