Search in sources :

Example 66 with Dependency

use of org.apache.maven.model.Dependency in project maven-plugins by apache.

the class DependencyConvergenceReport method toDependency.

/**
     * Convert Artifact to Dependency
     *
     * @param artifact
     * @return Dependency object
     */
private Dependency toDependency(Artifact artifact) {
    Dependency dependency = new Dependency();
    dependency.setGroupId(artifact.getGroupId());
    dependency.setArtifactId(artifact.getArtifactId());
    dependency.setVersion(artifact.getVersion());
    dependency.setClassifier(artifact.getClassifier());
    dependency.setScope(artifact.getScope());
    return dependency;
}
Also used : Dependency(org.apache.maven.model.Dependency)

Example 67 with Dependency

use of org.apache.maven.model.Dependency in project maven-plugins by apache.

the class DefaultRepositoryAssembler method buildRemoteRepository.

public void buildRemoteRepository(File repositoryDirectory, RepositoryInfo repository, RepositoryBuilderConfigSource configSource) throws RepositoryAssemblyException {
    MavenProject project = configSource.getProject();
    ProjectBuildingRequest buildingRequest = configSource.getProjectBuildingRequest();
    Iterable<ArtifactResult> result = null;
    Collection<Dependency> dependencies = project.getDependencies();
    if (dependencies == null) {
        Logger logger = getLogger();
        if (logger.isDebugEnabled()) {
            logger.debug("dependency-artifact set for project: " + project.getId() + " is null. Skipping repository processing.");
        }
        return;
    }
    Collection<Dependency> managedDependencies = null;
    if (project.getDependencyManagement() != null) {
        managedDependencies = project.getDependencyManagement().getDependencies();
    }
    // Older Aether versions use an cache which can't be cleared. So can't delete repoDir and use it again.
    // Instead create a temporary repository, delete it at end (should be in a finally-block)
    File tempRepo = new File(repositoryDirectory.getParentFile(), repositoryDirectory.getName() + "_tmp");
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, tempRepo);
    try {
        result = dependencyResolver.resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
    } catch (DependencyResolverException e) {
        throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
    }
    ArtifactFilter filter = buildRepositoryFilter(repository, project);
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, repositoryDirectory);
    Map<String, GroupVersionAlignment> groupVersionAlignments = createGroupVersionAlignments(repository.getGroupVersionAlignments());
    assembleRepositoryArtifacts(buildingRequest, result, filter, groupVersionAlignments);
    if (repository.isIncludeMetadata()) {
    //            assembleRepositoryMetadata( result, filter, centralRepository, targetRepository );
    }
    try {
        FileUtils.deleteDirectory(tempRepo);
    } catch (IOException e) {
    // noop
    }
}
Also used : DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) Logger(org.codehaus.plexus.logging.Logger) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) MavenProject(org.apache.maven.project.MavenProject) GroupVersionAlignment(org.apache.maven.plugins.assembly.repository.model.GroupVersionAlignment) File(java.io.File)

Example 68 with Dependency

use of org.apache.maven.model.Dependency in project maven-plugins by apache.

the class ShadeMojo method updateExcludesInDeps.

public boolean updateExcludesInDeps(MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps) throws DependencyGraphBuilderException {
    DependencyNode node = dependencyGraphBuilder.buildDependencyGraph(project, null);
    boolean modified = false;
    for (DependencyNode n2 : node.getChildren()) {
        for (DependencyNode n3 : n2.getChildren()) {
            // check if it really isn't in the list of original dependencies. Maven
            // prior to 2.0.8 may grab versions from transients instead of
            // from the direct deps in which case they would be marked included
            // instead of OMITTED_FOR_DUPLICATE
            // also, if not promoting the transitives, level 2's would be included
            boolean found = false;
            for (Dependency dep : transitiveDeps) {
                if (dep.getArtifactId().equals(n3.getArtifact().getArtifactId()) && dep.getGroupId().equals(n3.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n3.getArtifact().getType()))) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                for (Dependency dep : dependencies) {
                    if (dep.getArtifactId().equals(n2.getArtifact().getArtifactId()) && dep.getGroupId().equals(n2.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n2.getArtifact().getType()))) {
                        Exclusion exclusion = new Exclusion();
                        exclusion.setArtifactId(n3.getArtifact().getArtifactId());
                        exclusion.setGroupId(n3.getArtifact().getGroupId());
                        dep.addExclusion(exclusion);
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    return modified;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency)

Example 69 with Dependency

use of org.apache.maven.model.Dependency in project maven-plugins by apache.

the class WebappStructureTest method testDependencyAnalysisWithRemovedDependency.

public void testDependencyAnalysisWithRemovedDependency() {
    final List<Dependency> dependencies = new ArrayList<Dependency>();
    dependencies.add(createDependency("groupTest", "artifactTest", "1.0"));
    final Dependency removedDependency = createDependency("groupTest", "removedDep", "5.2");
    dependencies.add(removedDependency);
    final WebappStructure cache = new WebappStructure(dependencies);
    final List<Dependency> newDependencies = new ArrayList<Dependency>(dependencies);
    newDependencies.remove(removedDependency);
    final WebappStructure webappStructure = new WebappStructure(newDependencies, cache);
    webappStructure.analyseDependencies(new WebappStructure.DependenciesAnalysisCallback() {

        int count = 0;

        public void unchangedDependency(Dependency dependency) {
            if (count == 0) {
                count++;
            } else {
                fail("Should have called unchanged dependency only once");
            }
        }

        public void newDependency(Dependency dependency) {
            fail("Should have failed to trigger this callback");
        }

        public void removedDependency(Dependency dependency) {
            if (!removedDependency.equals(dependency)) {
                fail("Called removed dependency with an unexpected dependency " + dependency);
            }
        }

        public void updatedVersion(Dependency dependency, String previousVersion) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedScope(Dependency dependency, String previousScope) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedOptionalFlag(Dependency dependency, boolean previousOptional) {
            fail("Should have failed to trigger this callback");
        }

        public void updatedUnknown(Dependency dependency, Dependency previousDep) {
            fail("Should have failed to trigger this callback");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Example 70 with Dependency

use of org.apache.maven.model.Dependency in project maven-plugins by apache.

the class WebappStructureTest method testRegisterForced.

public void testRegisterForced() {
    final String path = "WEB-INF/web.xml";
    final WebappStructure structure = new WebappStructure(new ArrayList<Dependency>());
    assertFalse("New file should return false", structure.registerFileForced("overlay1", path));
    assertEquals("overlay1", structure.getOwner(path));
}
Also used : Dependency(org.apache.maven.model.Dependency) WebappStructure(org.apache.maven.plugins.war.util.WebappStructure)

Aggregations

Dependency (org.apache.maven.model.Dependency)78 ArrayList (java.util.ArrayList)24 Artifact (org.apache.maven.artifact.Artifact)18 File (java.io.File)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 MavenProject (org.apache.maven.project.MavenProject)8 IOException (java.io.IOException)7 Exclusion (org.apache.maven.model.Exclusion)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)7 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)7 HashMap (java.util.HashMap)6 DependencyManagement (org.apache.maven.model.DependencyManagement)5 Model (org.apache.maven.model.Model)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Plugin (org.apache.maven.model.Plugin)4 List (java.util.List)3 Properties (java.util.Properties)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3