Search in sources :

Example 71 with Artifact

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

the class MarkerFileFilter method isArtifactIncluded.

@Override
public boolean isArtifactIncluded(ArtifactItem item) throws ArtifactFilterException {
    Artifact artifact = item.getArtifact();
    boolean overWrite = (artifact.isSnapshot() && this.overWriteSnapshots) || (!artifact.isSnapshot() && this.overWriteReleases);
    handler.setArtifact(artifact);
    try {
        return overWrite || !handler.isMarkerSet() || (overWriteIfNewer && handler.isMarkerOlder(artifact));
    } catch (MojoExecutionException e) {
        throw new ArtifactFilterException(e.getMessage(), e);
    }
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 72 with Artifact

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

the class DestFileFilter method isArtifactIncluded.

@Override
public boolean isArtifactIncluded(ArtifactItem item) {
    Artifact artifact = item.getArtifact();
    boolean overWrite = (artifact.isSnapshot() && this.overWriteSnapshots) || (!artifact.isSnapshot() && this.overWriteReleases);
    File destFolder = item.getOutputDirectory();
    if (destFolder == null) {
        destFolder = DependencyUtil.getFormattedOutputDirectory(useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, removeVersion, this.outputFileDirectory, artifact);
    }
    File destFile;
    if (StringUtils.isEmpty(item.getDestFileName())) {
        String formattedFileName = DependencyUtil.getFormattedFileName(artifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier);
        destFile = new File(destFolder, formattedFileName);
    } else {
        destFile = new File(destFolder, item.getDestFileName());
    }
    return overWrite || !destFile.exists() || (overWriteIfNewer && artifact.getFile().lastModified() > destFile.lastModified());
}
Also used : File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 73 with Artifact

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

the class DependencyStatusSets method buildArtifactListOutput.

private StringBuilder buildArtifactListOutput(Set<Artifact> artifacts, boolean outputAbsoluteArtifactFilename, boolean outputScope, boolean sort) {
    StringBuilder sb = new StringBuilder();
    List<String> artifactStringList = new ArrayList<String>();
    for (Artifact artifact : artifacts) {
        String artifactFilename = null;
        if (outputAbsoluteArtifactFilename) {
            try {
                // we want to print the absolute file name here
                artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
            } catch (NullPointerException e) {
                // ignore the null pointer, we'll output a null string
                artifactFilename = null;
            }
        }
        String id = outputScope ? artifact.toString() : artifact.getId();
        String optionalMarker = "";
        if (outputScope && artifact.isOptional()) {
            optionalMarker = " (optional) ";
        }
        String moduleNameMarker = "";
        // dependencies:collect won't download jars
        if (artifact.getFile() != null) {
            ModuleDescriptor moduleDescriptor = getModuleDescriptor(artifact.getFile());
            if (moduleDescriptor != null) {
                moduleNameMarker = " -- module " + moduleDescriptor.name;
                if (moduleDescriptor.automatic) {
                    moduleNameMarker += " (auto)";
                }
            }
        }
        artifactStringList.add("   " + id + (outputAbsoluteArtifactFilename ? ":" + artifactFilename : "") + optionalMarker + moduleNameMarker + "\n");
    }
    if (sort) {
        Collections.sort(artifactStringList);
    }
    for (String artifactString : artifactStringList) {
        sb.append(artifactString);
    }
    return sb;
}
Also used : ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 74 with Artifact

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

the class AbstractAnalyzeMojo method writeScriptableOutput.

private void writeScriptableOutput(Set<Artifact> artifacts) {
    if (!artifacts.isEmpty()) {
        getLog().info("Missing dependencies: ");
        String pomFile = baseDir.getAbsolutePath() + File.separatorChar + "pom.xml";
        StringBuilder buf = new StringBuilder();
        for (Artifact artifact : artifacts) {
            // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
            artifact.isSnapshot();
            buf.append(scriptableFlag).append(":").append(pomFile).append(":").append(artifact.getDependencyConflictId()).append(":").append(artifact.getClassifier()).append(":").append(artifact.getBaseVersion()).append(":").append(artifact.getScope()).append("\n");
        }
        getLog().info("\n" + buf);
    }
}
Also used : Artifact(org.apache.maven.artifact.Artifact)

Example 75 with Artifact

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

the class AbstractAnalyzeMojo method filterDependencies.

private List<Artifact> filterDependencies(Set<Artifact> artifacts, String[] excludes) throws MojoExecutionException {
    ArtifactFilter filter = new StrictPatternExcludesArtifactFilter(Arrays.asList(excludes));
    List<Artifact> result = new ArrayList<Artifact>();
    for (Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) {
        Artifact artifact = it.next();
        if (!filter.include(artifact)) {
            it.remove();
            result.add(artifact);
        }
    }
    return result;
}
Also used : StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) StrictPatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter) ArrayList(java.util.ArrayList) 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