Search in sources :

Example 11 with Dependency

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

the class SubProject2Stub method getDependencies.

@Override
public List<Dependency> getDependencies() {
    Dependency d = new Dependency();
    d.setGroupId("junit");
    d.setArtifactId("junit");
    d.setVersion("3.8.1");
    d.setScope(Artifact.SCOPE_COMPILE);
    return Collections.singletonList(d);
}
Also used : Dependency(org.apache.maven.model.Dependency)

Example 12 with Dependency

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

the class WebappStructure method analyseDependencies.

/**
     * Analyze the dependencies of the project using the specified callback.
     *
     * @param callback the callback to use to report the result of the analysis
     */
public void analyseDependencies(DependenciesAnalysisCallback callback) {
    if (callback == null) {
        throw new NullPointerException("Callback could not be null.");
    }
    if (cache == null) {
        // Could not analyze dependencies without a cache
        return;
    }
    final List<Dependency> currentDependencies = new ArrayList<Dependency>(getDependencies());
    final List<Dependency> previousDependencies = new ArrayList<Dependency>(cache.getDependencies());
    final Iterator<Dependency> it = currentDependencies.listIterator();
    while (it.hasNext()) {
        Dependency dependency = it.next();
        // Check if the dependency is there "as is"
        final Dependency matchingDependency = matchDependency(previousDependencies, dependency);
        if (matchingDependency != null) {
            callback.unchangedDependency(dependency);
            // Handled so let's remove
            it.remove();
            previousDependencies.remove(matchingDependency);
        } else {
            // Try to get the dependency
            final Dependency previousDep = findDependency(dependency, previousDependencies);
            if (previousDep == null) {
                callback.newDependency(dependency);
                it.remove();
            } else if (!dependency.getVersion().equals(previousDep.getVersion())) {
                callback.updatedVersion(dependency, previousDep.getVersion());
                it.remove();
                previousDependencies.remove(previousDep);
            } else if (!dependency.getScope().equals(previousDep.getScope())) {
                callback.updatedScope(dependency, previousDep.getScope());
                it.remove();
                previousDependencies.remove(previousDep);
            } else if (dependency.isOptional() != previousDep.isOptional()) {
                callback.updatedOptionalFlag(dependency, previousDep.isOptional());
                it.remove();
                previousDependencies.remove(previousDep);
            } else {
                callback.updatedUnknown(dependency, previousDep);
                it.remove();
                previousDependencies.remove(previousDep);
            }
        }
    }
    for (Dependency dependency : previousDependencies) {
        callback.removedDependency(dependency);
    }
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency)

Example 13 with Dependency

use of org.apache.maven.model.Dependency 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 14 with Dependency

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

the class ShadeMojo method createDependency.

private Dependency createDependency(Artifact artifact) {
    Dependency dep = new Dependency();
    dep.setArtifactId(artifact.getArtifactId());
    if (artifact.hasClassifier()) {
        dep.setClassifier(artifact.getClassifier());
    }
    dep.setGroupId(artifact.getGroupId());
    dep.setOptional(artifact.isOptional());
    dep.setScope(artifact.getScope());
    dep.setType(artifact.getType());
    if (useBaseVersion) {
        dep.setVersion(artifact.getBaseVersion());
    } else {
        dep.setVersion(artifact.getVersion());
    }
    return dep;
}
Also used : Dependency(org.apache.maven.model.Dependency)

Example 15 with Dependency

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

the class ShadeMojo method createDependencyReducedPom.

// We need to find the direct dependencies that have been included in the uber JAR so that we can modify the
// POM accordingly.
private void createDependencyReducedPom(Set<String> artifactsToRemove) throws IOException, DependencyGraphBuilderException, ProjectBuildingException {
    List<Dependency> dependencies = new ArrayList<Dependency>();
    boolean modified = false;
    List<Dependency> transitiveDeps = new ArrayList<Dependency>();
    // including the system scoped artifacts with expanded values of properties used.
    for (Artifact artifact : project.getArtifacts()) {
        if ("pom".equals(artifact.getType())) {
            // don't include pom type dependencies in dependency reduced pom
            continue;
        }
        // promote
        Dependency dep = createDependency(artifact);
        // we'll figure out the exclusions in a bit.
        transitiveDeps.add(dep);
    }
    List<Dependency> origDeps = project.getDependencies();
    if (promoteTransitiveDependencies) {
        origDeps = transitiveDeps;
    }
    Model model = project.getOriginalModel();
    // MSHADE-185: We will remove all system scoped dependencies which usually
    // have some kind of property usage. At this time the properties within
    // such things are already evaluated.
    List<Dependency> originalDependencies = model.getDependencies();
    removeSystemScopedDependencies(artifactsToRemove, originalDependencies);
    for (Dependency d : origDeps) {
        dependencies.add(d);
        String id = getId(d);
        if (artifactsToRemove.contains(id)) {
            modified = true;
            if (keepDependenciesWithProvidedScope) {
                d.setScope("provided");
            } else {
                dependencies.remove(d);
            }
        }
    }
    // MSHADE-155
    model.setArtifactId(shadedArtifactId);
    // MSHADE-185: We will add those system scoped dependencies
    // from the non interpolated original pom file. So we keep
    // things like this: <systemPath>${tools.jar}</systemPath> intact.
    addSystemScopedDependencyFromNonInterpolatedPom(dependencies, originalDependencies);
    // Check to see if we have a reduction and if so rewrite the POM.
    rewriteDependencyReducedPomIfWeHaveReduction(dependencies, modified, transitiveDeps, model);
}
Also used : ArrayList(java.util.ArrayList) Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact)

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