Search in sources :

Example 86 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class MinijarFilter method removeSpecificallyIncludedClasses.

private void removeSpecificallyIncludedClasses(MavenProject project, List<SimpleFilter> simpleFilters) throws IOException {
    // remove classes specifically included in filters
    Clazzpath checkCp = new Clazzpath();
    for (Artifact dependency : project.getArtifacts()) {
        File jar = dependency.getFile();
        for (SimpleFilter simpleFilter : simpleFilters) {
            if (simpleFilter.canFilter(jar)) {
                ClazzpathUnit depClazzpathUnit = addDependencyToClasspath(checkCp, dependency);
                if (depClazzpathUnit != null) {
                    Set<Clazz> clazzes = depClazzpathUnit.getClazzes();
                    Iterator<Clazz> j = removable.iterator();
                    while (j.hasNext()) {
                        Clazz clazz = j.next();
                        if (//
                        clazzes.contains(clazz) && simpleFilter.isSpecificallyIncluded(clazz.getName().replace('.', '/'))) {
                            log.info(clazz.getName() + " not removed because it was specifically included");
                            j.remove();
                        }
                    }
                }
            }
        }
    }
}
Also used : Clazzpath(org.vafer.jdependency.Clazzpath) ClazzpathUnit(org.vafer.jdependency.ClazzpathUnit) Clazz(org.vafer.jdependency.Clazz) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 87 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class ShadeMojo method shadedArtifactFileWithClassifier.

private File shadedArtifactFileWithClassifier() {
    Artifact artifact = project.getArtifact();
    final String shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "." + artifact.getArtifactHandler().getExtension();
    return new File(outputDirectory, shadedName);
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 88 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class ShadeMojo method processArtifactSelectors.

private void processArtifactSelectors(Set<File> artifacts, Set<String> artifactIds, Set<File> sourceArtifacts, ArtifactSelector artifactSelector) {
    for (Artifact artifact : project.getArtifacts()) {
        if (!artifactSelector.isSelected(artifact)) {
            getLog().info("Excluding " + artifact.getId() + " from the shaded jar.");
            continue;
        }
        if ("pom".equals(artifact.getType())) {
            getLog().info("Skipping pom dependency " + artifact.getId() + " in the shaded jar.");
            continue;
        }
        getLog().info("Including " + artifact.getId() + " in the shaded jar.");
        artifacts.add(artifact.getFile());
        artifactIds.add(getId(artifact));
        if (createSourcesJar) {
            File file = resolveArtifactSources(artifact);
            if (file != null) {
                sourceArtifacts.add(file);
            }
        }
    }
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 89 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class ShadeMojo method shadedSourceArtifactFileWithClassifier.

private File shadedSourceArtifactFileWithClassifier() {
    Artifact artifact = project.getArtifact();
    final String shadedName = shadedArtifactId + "-" + artifact.getVersion() + "-" + shadedClassifierName + "-sources." + artifact.getArtifactHandler().getExtension();
    return new File(outputDirectory, shadedName);
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 90 with Artifact

use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.

the class AntBuildWriterUtil method writeCopyLib.

/**
     * Write copy tasks in an outputDir for EAR and WAR targets for project depencies without
     * <code>provided</code> or <code>test</code> as scope
     *
     * @param writer                  not null
     * @param project                 not null
     * @param artifactResolverWrapper not null
     * @param outputDir               not null
     */
private static void writeCopyLib(XMLWriter writer, MavenProject project, ArtifactResolverWrapper artifactResolverWrapper, String outputDir) {
    writer.startElement("mkdir");
    writer.addAttribute("dir", outputDir);
    // mkdir
    writer.endElement();
    if (project.getArtifacts() != null) {
        for (Object o : project.getArtifacts()) {
            Artifact artifact = (Artifact) o;
            if (Artifact.SCOPE_COMPILE.equals(artifact.getScope()) || Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) {
                String path = artifactResolverWrapper.getLocalArtifactPath(artifact);
                if (!new File(path).isAbsolute()) {
                    path = "${maven.repo.local}/" + path;
                }
                writer.startElement("copy");
                writer.addAttribute("file", path);
                addWrapAttribute(writer, "copy", "todir", outputDir, 3);
                // copy
                writer.endElement();
            }
        }
    }
}
Also used : File(java.io.File) 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