Skip to content

Commit

Permalink
[highsource#560] add a way to exclude artifacts from xjc classpath re…
Browse files Browse the repository at this point in the history
…solution

no more default value
  • Loading branch information
laurentschoelens authored and mattrpav committed Nov 20, 2024
1 parent 5d21c29 commit 5903cd4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,27 @@ public void setPlugins(Dependency[] plugins) {
this.plugins = plugins;
}

@Component
/**
* <p>
* A list of artifacts to exclude from XJC Plugins resolveTransitively function.
* </p>
* <p>
* If you are using <code>xerces:xercesImpl</code> and / or <code>xml-apis</code>,
* adding them will exclude from the classpath resolution, fixing issue #560.
* </p>
*/
@Parameter
private String[] artifactExcludes = new String[] {};

public String[] getArtifactExcludes() {
return artifactExcludes;
}

public void setArtifactExcludes(String[] artifactExcludes) {
this.artifactExcludes = artifactExcludes;
}

@Component
private RepositorySystem repositorySystem;

@Component
Expand Down Expand Up @@ -1123,6 +1143,7 @@ protected void logConfiguration() throws MojoExecutionException {
+ getScanDependenciesForBindings());
getLog().info("xjcPlugins:" + Arrays.toString(getPlugins()));
getLog().info("episodes:" + Arrays.toString(getEpisodes()));
getLog().info("artifactExcludes:" + Arrays.toString(getArtifactExcludes()));
}

private static final String XML_SCHEMA_CLASS_NAME = "XmlSchema";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ protected void resolveArtifacts() throws MojoExecutionException {
protected void resolveXJCPluginArtifacts()
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException {

this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(getArtifactFactory(), getRepositorySystem(),
getMavenSession().getLocalRepository(), getArtifactMetadataSource(), getPlugins(), getProject());
this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(
getArtifactFactory(), getRepositorySystem(),
getMavenSession().getLocalRepository(), getArtifactMetadataSource(),
getPlugins(), getProject(), getArtifactExcludes());
this.xjcPluginFiles = ArtifactUtils.getFiles(this.xjcPluginArtifacts);
this.xjcPluginURLs = CollectionUtils.apply(this.xjcPluginFiles, IOUtils.GET_URL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
Expand All @@ -27,13 +28,28 @@ public class ArtifactUtils {
private ArtifactUtils() {

}
public static Collection<Artifact> resolveTransitively(
final ArtifactFactory artifactFactory,
final RepositorySystem artifactResolver,
final ArtifactRepository localRepository,
final ArtifactMetadataSource artifactMetadataSource,
final Dependency[] dependencies, final MavenProject project)
throws InvalidDependencyVersionException,
ArtifactResolutionException, ArtifactNotFoundException {
return resolveTransitively(
artifactFactory, artifactResolver,
localRepository, artifactMetadataSource,
dependencies, project,
null);
}

public static Collection<Artifact> resolveTransitively(
final ArtifactFactory artifactFactory,
final RepositorySystem artifactResolver,
final ArtifactRepository localRepository,
final ArtifactMetadataSource artifactMetadataSource,
final Dependency[] dependencies, final MavenProject project)
final Dependency[] dependencies, final MavenProject project,
final String[] artifactExcludes)
throws InvalidDependencyVersionException,
ArtifactResolutionException, ArtifactNotFoundException {
if (dependencies == null) {
Expand All @@ -49,6 +65,10 @@ public static Collection<Artifact> resolveTransitively(
request.setResolveRoot(false);
request.setArtifact(project.getArtifact());
request.setArtifactDependencies(artifacts);
if (artifactExcludes != null && artifactExcludes.length > 0) {
// remove dependencies from resolution
request.setCollectionFilter(new ExclusionSetFilter(artifactExcludes));
}
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
request.setLocalRepository(localRepository);

Expand Down

0 comments on commit 5903cd4

Please sign in to comment.