Search in sources :

Example 61 with Artifact

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

the class AbstractAntTestMavenProjectStub method getTestArtifacts.

/**
     * @see org.apache.maven.project.MavenProject#getTestArtifacts()
     */
public List getTestArtifacts() {
    Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
    junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
    return Collections.singletonList(junit);
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 62 with Artifact

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

the class AbstractAntTestMavenProjectStub method getCompileArtifacts.

/**
     * @see org.apache.maven.project.MavenProject#getCompileArtifacts()
     */
public List getCompileArtifacts() {
    Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
    junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
    return Collections.singletonList(junit);
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 63 with Artifact

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

the class DependencyFilesetsTask method filterArtifacts.

/**
     * Filter a set of artifacts using the scopes and type filters.
     *
     * @param artifacts {@link Artifact} set.
     * @return The set of filtered artifacts.
     */
public Set<Artifact> filterArtifacts(Set<Artifact> artifacts) {
    if (scopes == null) {
        scopes = "";
    }
    if (types == null) {
        types = "";
    }
    if (scopes.equals("") && types.equals("")) {
        return artifacts;
    }
    AndArtifactFilter filter = new AndArtifactFilter();
    if (!scopes.equals("")) {
        filter.add(new SpecificScopesArtifactFilter(getScopes()));
    }
    if (!types.equals("")) {
        filter.add(new TypesArtifactFilter(getTypes()));
    }
    Set<Artifact> artifactsResult = new LinkedHashSet<Artifact>();
    for (Artifact artifact : artifacts) {
        if (filter.include(artifact)) {
            artifactsResult.add(artifact);
        }
    }
    return artifactsResult;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TypesArtifactFilter(org.apache.maven.ant.tasks.support.TypesArtifactFilter) SpecificScopesArtifactFilter(org.apache.maven.ant.tasks.support.SpecificScopesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 64 with Artifact

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

the class AddDependencySetsTask method resolveDependencyArtifacts.

Set<Artifact> resolveDependencyArtifacts(final DependencySet dependencySet) throws InvalidAssemblerConfigurationException {
    final Set<Artifact> dependencyArtifacts = new LinkedHashSet<Artifact>();
    if (resolvedArtifacts != null) {
        dependencyArtifacts.addAll(resolvedArtifacts);
    }
    if (dependencySet.isUseProjectArtifact()) {
        final Artifact projectArtifact = project.getArtifact();
        if ((projectArtifact != null) && (projectArtifact.getFile() != null)) {
            dependencyArtifacts.add(projectArtifact);
        } else {
            logger.warn("Cannot include project artifact: " + projectArtifact + "; it doesn't have an associated file or directory.");
        }
    }
    if (dependencySet.isUseProjectAttachments()) {
        final List<Artifact> attachments = project.getAttachedArtifacts();
        if (attachments != null) {
            for (final Artifact attachment : attachments) {
                if (attachment.getFile() != null) {
                    dependencyArtifacts.add(attachment);
                } else {
                    logger.warn("Cannot include attached artifact: " + project.getId() + " for project: " + project.getId() + "; it doesn't have an associated file or directory.");
                }
            }
        }
    }
    if (dependencySet.isUseTransitiveFiltering()) {
        logger.debug("Filtering dependency artifacts USING transitive dependency path information.");
    } else {
        logger.debug("Filtering dependency artifacts WITHOUT transitive dependency path information.");
    }
    final ScopeFilter scopeFilter = FilterUtils.newScopeFilter(dependencySet.getScope());
    final ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(scopeFilter);
    FilterUtils.filterArtifacts(dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(), dependencySet.isUseStrictFiltering(), dependencySet.isUseTransitiveFiltering(), logger, filter);
    return dependencyArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeFilter(org.apache.maven.shared.artifact.filter.resolve.ScopeFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) Artifact(org.apache.maven.artifact.Artifact)

Example 65 with Artifact

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

the class DefaultDependencyResolver method resolveNonTransitively.

Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
    final List<Artifact> missing = new ArrayList<Artifact>();
    final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
    for (final Artifact depArtifact : dependencyArtifacts) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setLocalRepository(configSource.getLocalRepository());
        req.setRemoteRepositories(repos);
        req.setArtifact(depArtifact);
        ArtifactResolutionResult resolve = resolver.resolve(req);
        if (resolve.hasExceptions()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
            }
            missing.add(depArtifact);
        } else {
            resolved.add(depArtifact);
        }
    }
    if (!missing.isEmpty()) {
        final MavenProject project = configSource.getProject();
        final Artifact rootArtifact = project.getArtifact();
        final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
        throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
    }
    return resolved;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)474 File (java.io.File)190 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)104 ArrayList (java.util.ArrayList)102 MavenProject (org.apache.maven.project.MavenProject)66 IOException (java.io.IOException)54 HashSet (java.util.HashSet)42 LinkedHashSet (java.util.LinkedHashSet)36 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)32 MojoFailureException (org.apache.maven.plugin.MojoFailureException)26 URL (java.net.URL)24 HashMap (java.util.HashMap)24 MalformedURLException (java.net.MalformedURLException)22 Set (java.util.Set)22 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)22 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)21 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 Test (org.junit.Test)20 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)17 Dependency (org.apache.maven.model.Dependency)17