use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter 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.artifact.resolver.filter.ExcludesArtifactFilter in project xwiki-platform by xwiki.
the class PackageMojo method resolveTransitively.
private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException {
AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"), // for JSX. See https://jira.xwiki.org/browse/XWIKI-6151 for more details.
new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js", "commons-logging:commons-logging", "commons-logging:commons-logging-api", "log4j:log4j"))));
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact()).setArtifactDependencies(artifacts).setCollectionFilter(filter).setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository).setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false);
ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
if (resolutionResult.hasExceptions()) {
throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts, resolutionResult.getExceptions().get(0)));
}
return resolutionResult.getArtifacts();
}
use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter in project randomizedtesting by randomizedtesting.
the class JUnit4Mojo method resolveArtifact.
/**
* Resolve a given artifact given exclusion list. (copied from surefire).
*/
@SuppressWarnings({ "deprecation" })
private ArtifactResolutionResult resolveArtifact(Artifact artifact, Artifact... filtered) {
final ArtifactFilter filter;
if (filtered.length > 0) {
List<String> exclusions = new ArrayList<>(filtered.length);
for (Artifact filteredArtifact : filtered) {
exclusions.add(filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId());
}
filter = new ExcludesArtifactFilter(exclusions);
} else {
filter = null;
}
Artifact originatingArtifact = repositorySystem.createArtifact("dummy", "dummy", "1.0", "jar");
try {
return resolver.resolveTransitively(Collections.singleton(artifact), originatingArtifact, session.getLocalRepository(), project.getPluginArtifactRepositories(), metadataSource, filter);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter 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;
}
Aggregations