Search in sources :

Example 6 with ScopeArtifactFilter

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

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeTestScope.

public void testCopyDependenciesMojoIncludeTestScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "test";
    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 7 with ScopeArtifactFilter

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

the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeRuntimeScope.

public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "runtime";
    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 8 with ScopeArtifactFilter

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

the class TestUnpackDependenciesMojo method testIncludeCompileScope.

public void testIncludeCompileScope() throws Exception {
    mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
    mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
    mojo.includeScope = "compile";
    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 9 with ScopeArtifactFilter

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

the class RarMojo method execute.

public void execute() throws MojoExecutionException {
    if (skip) {
        getLog().info("Skipping rar generation.");
        return;
    }
    // Check if jar file is there and if requested, copy it
    try {
        if (includeJar) {
            File generatedJarFile = new File(outputDirectory, finalName + ".jar");
            if (generatedJarFile.exists()) {
                getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
                FileUtils.copyFileToDirectory(generatedJarFile, getBuildDir());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying generated Jar file", e);
    }
    // Copy dependencies
    try {
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
            if (!artifact.isOptional() && filter.include(artifact) && artifact.getArtifactHandler().isAddedToClasspath()) {
                getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
                FileUtils.copyFileToDirectory(artifact.getFile(), getBuildDir());
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying RAR dependencies", e);
    }
    resourceHandling();
    // Include custom manifest if necessary
    try {
        includeCustomRaXmlFile();
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying ra.xml file", e);
    }
    // Check if connector deployment descriptor is there
    File ddFile = new File(getBuildDir(), RA_XML_URI);
    if (!ddFile.exists() && warnOnMissingRaXml) {
        getLog().warn("Connector deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
    }
    File rarFile = getRarFile(outputDirectory, finalName, classifier);
    try {
        MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(rarFile);
        // Include custom manifest if necessary
        includeCustomManifestFile();
        archiver.getArchiver().addDirectory(getBuildDir());
        archiver.createArchive(session, project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling RAR", e);
    }
    if (classifier != null) {
        projectHelper.attachArtifact(project, "rar", classifier, rarFile);
    } else {
        project.getArtifact().setFile(rarFile);
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 10 with ScopeArtifactFilter

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

the class ArtifactsPackagingTask method performPackaging.

/**
     * {@inheritDoc}
     */
public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
    try {
        final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
        final List<String> duplicates = findDuplicates(context, artifacts);
        for (Artifact artifact : artifacts) {
            String targetFileName = getArtifactFinalName(context, artifact);
            context.getLog().debug("Processing: " + targetFileName);
            if (duplicates.contains(targetFileName)) {
                context.getLog().debug("Duplicate found: " + targetFileName);
                targetFileName = artifact.getGroupId() + "-" + targetFileName;
                context.getLog().debug("Renamed to: " + targetFileName);
            }
            context.getWebappStructure().registerTargetFileName(artifact, targetFileName);
            if (!artifact.isOptional() && filter.include(artifact)) {
                try {
                    String type = artifact.getType();
                    if ("tld".equals(type)) {
                        copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName);
                    } else if ("aar".equals(type)) {
                        copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName);
                    } else if ("mar".equals(type)) {
                        copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName);
                    } else if ("xar".equals(type)) {
                        copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName);
                    } else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type) || "test-jar".equals(type) || "bundle".equals(type)) {
                        copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
                    } else if ("par".equals(type)) {
                        targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";
                        copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
                    } else if ("war".equals(type)) {
                        // Nothing to do here, it is an overlay and it's already handled
                        context.getLog().debug("war artifacts are handled as overlays, ignoring [" + artifact + "]");
                    } else if ("zip".equals(type)) {
                        // Nothing to do here, it is an overlay and it's already handled
                        context.getLog().debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]");
                    } else {
                        context.getLog().debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact + "]");
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e);
                }
            }
        }
    } catch (InterpolationException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) 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