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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations