Search in sources :

Example 6 with Dependency

use of org.apache.maven.model.Dependency in project camel by apache.

the class RunMojo method getAllDependencies.

// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
    List<Artifact> artifacts = new ArrayList<Artifact>();
    for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
        Dependency dependency = (Dependency) dependencies.next();
        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();
        VersionRange versionRange;
        try {
            versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException("unable to parse version", e);
        }
        String type = dependency.getType();
        if (type == null) {
            type = "jar";
        }
        String classifier = dependency.getClassifier();
        boolean optional = dependency.isOptional();
        String scope = dependency.getScope();
        if (scope == null) {
            scope = Artifact.SCOPE_COMPILE;
        }
        Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
        if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
            art.setFile(new File(dependency.getSystemPath()));
        }
        List<String> exclusions = new ArrayList<String>();
        for (Exclusion exclusion : dependency.getExclusions()) {
            exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
        art.setDependencyFilter(newFilter);
        artifacts.add(art);
    }
    return artifacts;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 7 with Dependency

use of org.apache.maven.model.Dependency in project bazel by bazelbuild.

the class Resolver method resolveEffectiveModel.

/**
   * Resolves all dependencies from a given "model source," which could be either a URL or a local
   * file.
   * @return the model.
   */
@Nullable
public Model resolveEffectiveModel(ModelSource modelSource, Set<String> exclusions, Rule parent) {
    Model model = modelResolver.getEffectiveModel(modelSource, handler);
    if (model == null) {
        return null;
    }
    for (Repository repo : model.getRepositories()) {
        modelResolver.addRepository(repo);
    }
    for (Dependency dependency : model.getDependencies()) {
        if (!dependency.getScope().equals(COMPILE_SCOPE)) {
            continue;
        }
        if (dependency.isOptional()) {
            continue;
        }
        if (exclusions.contains(dependency.getGroupId() + ":" + dependency.getArtifactId())) {
            continue;
        }
        try {
            Rule artifactRule = new Rule(getArtifact(dependency), dependency.getExclusions());
            HashSet<String> localDepExclusions = new HashSet<>(exclusions);
            localDepExclusions.addAll(artifactRule.getExclusions());
            boolean isNewDependency = addArtifact(artifactRule, model.toString());
            if (isNewDependency) {
                ModelSource depModelSource = modelResolver.resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
                if (depModelSource != null) {
                    artifactRule.setRepository(depModelSource.getLocation(), handler);
                    artifactRule.setSha1(downloadSha1(artifactRule));
                    resolveEffectiveModel(depModelSource, localDepExclusions, artifactRule);
                } else {
                    handler.handle(Event.error("Could not get a model for " + dependency));
                }
            }
            if (parent != null) {
                parent.addDependency(artifactRule);
                parent.getDependencies().addAll(artifactRule.getDependencies());
            } else {
                addArtifact(artifactRule, modelSource.getLocation());
            }
        } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) {
            handler.handle(Event.error("Could not resolve dependency " + dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() + ": " + e.getMessage()));
        }
    }
    return model;
}
Also used : Repository(org.apache.maven.model.Repository) Model(org.apache.maven.model.Model) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) Dependency(org.apache.maven.model.Dependency) FileModelSource(org.apache.maven.model.building.FileModelSource) ModelSource(org.apache.maven.model.building.ModelSource) HashSet(java.util.HashSet) Nullable(javax.annotation.Nullable)

Example 8 with Dependency

use of org.apache.maven.model.Dependency in project gradle by gradle.

the class DefaultPomDependenciesConverter method convert.

public List<Dependency> convert(Conf2ScopeMappingContainer conf2ScopeMappingContainer, Set<Configuration> configurations) {
    Map<ModuleDependency, Set<Configuration>> dependencyToConfigurations = createDependencyToConfigurationsMap(configurations);
    Map<ModuleDependency, Conf2ScopeMapping> dependenciesMap = createDependencyToScopeMap(conf2ScopeMappingContainer, dependencyToConfigurations);
    Map<Dependency, Integer> dependenciesWithPriorities = new LinkedHashMap<Dependency, Integer>();
    for (ModuleDependency dependency : dependenciesMap.keySet()) {
        Conf2ScopeMapping conf2ScopeMapping = dependenciesMap.get(dependency);
        String scope = conf2ScopeMapping.getScope();
        Integer priority = conf2ScopeMapping.getPriority() == null ? 0 : conf2ScopeMapping.getPriority();
        Set<Configuration> dependencyConfigurations = dependencyToConfigurations.get(dependency);
        if (dependency.getArtifacts().size() == 0) {
            addFromDependencyDescriptor(dependenciesWithPriorities, dependency, scope, priority, dependencyConfigurations);
        } else {
            addFromArtifactDescriptor(dependenciesWithPriorities, dependency, scope, priority, dependencyConfigurations);
        }
    }
    return new ArrayList<Dependency>(dependenciesWithPriorities.keySet());
}
Also used : Dependency(org.apache.maven.model.Dependency) Conf2ScopeMapping(org.gradle.api.artifacts.maven.Conf2ScopeMapping)

Example 9 with Dependency

use of org.apache.maven.model.Dependency in project jangaroo-tools by CoreMedia.

the class PackageApplicationMojo method getDependencies.

private List<String> getDependencies(Artifact artifact) throws ProjectBuildingException {
    MavenProject mp = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
    List<String> deps = new LinkedList<String>();
    for (Dependency dep : getDependencies(mp)) {
        if ("jar".equals(dep.getType()) && (dep.getScope().equals("compile") || dep.getScope().equals("runtime"))) {
            deps.add(getInternalId(dep));
        }
    }
    return deps;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) Dependency(org.apache.maven.model.Dependency) LinkedList(java.util.LinkedList)

Example 10 with Dependency

use of org.apache.maven.model.Dependency in project kotlin by JetBrains.

the class KotlinCompileMojoBase method getCompilerPluginClassPaths.

private List<String> getCompilerPluginClassPaths() {
    ArrayList<String> result = new ArrayList<String>();
    List<File> files = new ArrayList<File>();
    for (Dependency dependency : mojoExecution.getPlugin().getDependencies()) {
        Artifact artifact = system.createDependencyArtifact(dependency);
        ArtifactResolutionResult resolved = system.resolve(new ArtifactResolutionRequest().setArtifact(artifact));
        for (Artifact resolvedArtifact : resolved.getArtifacts()) {
            File file = resolvedArtifact.getFile();
            if (file != null && file.exists()) {
                files.add(file);
            }
        }
    }
    for (File file : files) {
        result.add(file.getAbsolutePath());
    }
    return result;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Dependency(org.apache.maven.model.Dependency) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Dependency (org.apache.maven.model.Dependency)73 ArrayList (java.util.ArrayList)24 Artifact (org.apache.maven.artifact.Artifact)17 File (java.io.File)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 Exclusion (org.apache.maven.model.Exclusion)7 WebappStructure (org.apache.maven.plugins.war.util.WebappStructure)7 MavenProject (org.apache.maven.project.MavenProject)7 IOException (java.io.IOException)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 HashMap (java.util.HashMap)5 Model (org.apache.maven.model.Model)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 DependencyManagement (org.apache.maven.model.DependencyManagement)4 Plugin (org.apache.maven.model.Plugin)4 List (java.util.List)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 Test (org.junit.Test)3 MavenPublishable (com.facebook.buck.jvm.java.MavenPublishable)2