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

defaults to xercesImpl and xml-apis
  • Loading branch information
laurentschoelens committed Aug 28, 2024
1 parent 1078f1f commit d368e04
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 left undefined, then <code>xercesImpl</code> and <code>xml-apis</code> will
* be excluded by default from the classpath resolution.
* </p>
*/
@Parameter
private String[] artifactExcludes = new String[] { "xercesImpl", "xml-apis" };

This comment has been minimized.

Copy link
@tmortagne

tmortagne Aug 29, 2024

Might be safer to put the complete ids there (I mean "xerces:xercesImpl" and "xml-apis:xml-apis", ExclusionSetFilter seems to support both formats). Also, you might want to add older related ids like "xerces:xerces-impl" and "xerces:xmlParserAPIs".

This comment has been minimized.

Copy link
@laurentschoelens

laurentschoelens Aug 29, 2024

Author Owner

Changed to xerces:xercesImpl, xml-apis:xml-apis


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 d368e04

Please sign in to comment.