Search in sources :

Example 66 with Artifact

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

the class DefaultDependencyResolver method updateModuleSetResolutionRequirements.

void updateModuleSetResolutionRequirements(AssemblyId assemblyId, ModuleSet set, DependencySet dependencySet, final ResolutionManagementInfo requirements, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final ModuleBinaries binaries = set.getBinaries();
    if (binaries != null) {
        Set<MavenProject> projects;
        try {
            projects = ModuleSetAssemblyPhase.getModuleProjects(set, configSource, getLogger());
        } catch (final ArchiveCreationException e) {
            throw new DependencyResolutionException("Error determining project-set for moduleSet with binaries.", e);
        }
        if (!projects.isEmpty()) {
            for (final MavenProject p : projects) {
                requirements.enableProjectResolution(p);
                if (p.getArtifact() == null) {
                    // TODO: such a call in MavenMetadataSource too - packaging not really the intention of
                    // type
                    final Artifact artifact = resolver.createArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), p.getPackaging());
                    p.setArtifact(artifact);
                }
            }
        }
        if (binaries.isIncludeDependencies()) {
            updateDependencySetResolutionRequirements(dependencySet, requirements, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), projects.toArray(new MavenProject[projects.size()]));
        }
    }
}
Also used : ModuleBinaries(org.apache.maven.plugins.assembly.model.ModuleBinaries) MavenProject(org.apache.maven.project.MavenProject) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) Artifact(org.apache.maven.artifact.Artifact)

Example 67 with Artifact

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

the class DefaultDependencyResolver method resolveDependencySets.

@Override
public Map<DependencySet, Set<Artifact>> resolveDependencySets(final Assembly assembly, ModuleSet moduleSet, final AssemblerConfigurationSource configSource, List<DependencySet> dependencySets) throws DependencyResolutionException {
    Map<DependencySet, Set<Artifact>> result = new LinkedHashMap<DependencySet, Set<Artifact>>();
    for (DependencySet dependencySet : dependencySets) {
        final MavenProject currentProject = configSource.getProject();
        final ResolutionManagementInfo info = new ResolutionManagementInfo(currentProject);
        updateRepositoryResolutionRequirements(assembly, info);
        final AssemblyId assemblyId = AssemblyId.createAssemblyId(assembly);
        updateDependencySetResolutionRequirements(dependencySet, info, assemblyId, configSource.getMavenSession().getProjectBuildingRequest(), currentProject);
        updateModuleSetResolutionRequirements(assemblyId, moduleSet, dependencySet, info, configSource);
        resolve(assembly, configSource, result, dependencySet, info);
    }
    return result;
}
Also used : ModuleSet(org.apache.maven.plugins.assembly.model.ModuleSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) MavenProject(org.apache.maven.project.MavenProject) DependencySet(org.apache.maven.plugins.assembly.model.DependencySet) AssemblyId(org.apache.maven.plugins.assembly.resolved.AssemblyId) Artifact(org.apache.maven.artifact.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 68 with Artifact

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

the class DependencyFilesetsTask method execute.

/** {@inheritDoc} */
public void execute() {
    if (this.getProject().getReference(mavenProjectId) == null) {
        throw new BuildException("Maven project reference not found: " + mavenProjectId);
    }
    MavenProject mavenProject = (MavenProject) this.getProject().getReference("maven.project");
    // Add filesets for depenedency artifacts
    Set<Artifact> depArtifacts = filterArtifacts(mavenProject.getArtifacts());
    FileSet dependenciesFileSet = new FileSet();
    dependenciesFileSet.setProject(getProject());
    ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference("maven.local.repository");
    dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
    for (Artifact artifact : depArtifacts) {
        String relativeArtifactPath = localRepository.pathOf(artifact);
        dependenciesFileSet.createInclude().setName(relativeArtifactPath);
        String fileSetName = getPrefix() + artifact.getDependencyConflictId();
        FileSet singleArtifactFileSet = new FileSet();
        singleArtifactFileSet.setProject(getProject());
        singleArtifactFileSet.setFile(artifact.getFile());
        getProject().addReference(fileSetName, singleArtifactFileSet);
    }
    getProject().addReference((getPrefix() + projectDependenciesId), dependenciesFileSet);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) FileSet(org.apache.tools.ant.types.FileSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 69 with Artifact

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

the class AbstractCheckstyleReport method getCheckstylePluginDependenciesAsArtifacts.

private List<Artifact> getCheckstylePluginDependenciesAsArtifacts(Map<String, Plugin> plugins, String hint) {
    List<Artifact> artifacts = new ArrayList<>();
    Plugin checkstylePlugin = plugins.get(plugin.getGroupId() + ":" + plugin.getArtifactId());
    if (checkstylePlugin != null) {
        for (Dependency dep : checkstylePlugin.getDependencies()) {
            // @todo if we can filter on hints, it should be done here...
            String depKey = dep.getGroupId() + ":" + dep.getArtifactId();
            artifacts.add((Artifact) plugin.getArtifactMap().get(depKey));
        }
    }
    return artifacts;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) ReportPlugin(org.apache.maven.model.ReportPlugin) Plugin(org.apache.maven.model.Plugin)

Example 70 with Artifact

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

the class AbstractEarModule method resolveArtifact.

/** {@inheritDoc} */
public void resolveArtifact(Set<Artifact> artifacts) throws EarPluginException, MojoFailureException {
    // If the artifact is already set no need to resolve it
    if (artifact == null) {
        // Make sure that at least the groupId and the artifactId are specified
        if (groupId == null || artifactId == null) {
            throw new MojoFailureException("Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]");
        }
        final ArtifactRepository ar = earExecutionContext.getArtifactRepository();
        artifact = ar.getUniqueArtifact(groupId, artifactId, getType(), classifier);
        // Artifact has not been found
        if (artifact == null) {
            Set<Artifact> candidates = ar.getArtifacts(groupId, artifactId, getType());
            if (candidates.size() > 1) {
                throw new MojoFailureException("Artifact[" + this + "] has " + candidates.size() + " candidates, please provide a classifier.");
            } else {
                throw new MojoFailureException("Artifact[" + this + "] is not a dependency of the project.");
            }
        }
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactRepository(org.apache.maven.plugins.ear.util.ArtifactRepository) 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