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 camel by apache.
the class BomGeneratorMojo method getProvidedDependencyManagement.
private Set<String> getProvidedDependencyManagement(String groupId, String artifactId, String version) throws Exception {
Artifact bom = resolveArtifact(groupId, artifactId, version, "pom");
MavenProject bomProject = loadExternalProjectPom(bom.getFile());
Set<String> provided = new HashSet<>();
if (bomProject.getDependencyManagement() != null && bomProject.getDependencyManagement().getDependencies() != null) {
for (Dependency dep : bomProject.getDependencyManagement().getDependencies()) {
provided.add(comparisonKey(dep));
}
}
return provided;
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class BomGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
DependencyManagement mng = project.getDependencyManagement();
List<Dependency> filteredDependencies = enhance(filter(mng.getDependencies()));
Set<String> externallyManagedDependencies = getExternallyManagedDependencies();
checkConflictsWithExternalBoms(filteredDependencies, externallyManagedDependencies);
Document pom = loadBasePom();
// transform
overwriteDependencyManagement(pom, filteredDependencies);
writePom(pom);
} catch (MojoFailureException ex) {
throw ex;
} catch (MojoExecutionException ex) {
throw ex;
} catch (Exception ex) {
throw new MojoExecutionException("Cannot generate the output BOM file", ex);
}
}
use of org.apache.maven.model.Dependency in project camel by apache.
the class BomGeneratorMojo method filter.
private List<Dependency> filter(List<Dependency> dependencyList) {
List<Dependency> outDependencies = new ArrayList<>();
DependencyMatcher inclusions = new DependencyMatcher(dependencies.getIncludes());
DependencyMatcher exclusions = new DependencyMatcher(dependencies.getExcludes());
for (Dependency dep : dependencyList) {
boolean accept = inclusions.matches(dep) && !exclusions.matches(dep);
getLog().debug(dep + (accept ? " included in the BOM" : " excluded from BOM"));
if (accept) {
outDependencies.add(dep);
}
}
Collections.sort(outDependencies, (d1, d2) -> (d1.getGroupId() + ":" + d1.getArtifactId()).compareTo(d2.getGroupId() + ":" + d2.getArtifactId()));
return outDependencies;
}
use of org.apache.maven.model.Dependency in project grails-maven by grails.
the class AbstractGrailsMojo method findArtefactVersionFromPlugin.
private String findArtefactVersionFromPlugin(String group, String name) throws ProjectBuildingException {
MavenProject pluginProject = getPluginProject();
List<Dependency> dependencyArtifacts = pluginProject.getDependencies();
if (dependencyArtifacts != null) {
for (Dependency d : dependencyArtifacts) {
if (d.getArtifactId().equals(name) && d.getGroupId().equals(group)) {
return d.getVersion();
}
}
}
return null;
}
Aggregations