Skip to content

Commit b98fd4d

Browse files
[#582] enhance resolution artifact process if not success
1 parent 696f37c commit b98fd4d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJCMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ protected void resolveXJCPluginArtifacts()
397397
this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(
398398
getArtifactFactory(), getRepositorySystem(),
399399
getMavenSession().getLocalRepository(), getArtifactMetadataSource(),
400-
getPlugins(), getProject(), getArtifactExcludes());
400+
getPlugins(), getProject(), getLog(), getArtifactExcludes());
401401
this.xjcPluginFiles = ArtifactUtils.getFiles(this.xjcPluginArtifacts);
402402
this.xjcPluginURLs = CollectionUtils.apply(this.xjcPluginFiles, IOUtils.GET_URL);
403403
}

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/util/ArtifactUtils.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
1818
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
1919
import org.apache.maven.model.Dependency;
20+
import org.apache.maven.plugin.logging.Log;
21+
import org.apache.maven.plugin.logging.SystemStreamLog;
2022
import org.apache.maven.project.MavenProject;
2123
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
2224
import org.apache.maven.project.artifact.MavenMetadataSource;
@@ -40,6 +42,7 @@ public static Collection<Artifact> resolveTransitively(
4042
artifactFactory, artifactResolver,
4143
localRepository, artifactMetadataSource,
4244
dependencies, project,
45+
new SystemStreamLog(),
4346
null);
4447
}
4548

@@ -49,10 +52,11 @@ public static Collection<Artifact> resolveTransitively(
4952
final ArtifactRepository localRepository,
5053
final ArtifactMetadataSource artifactMetadataSource,
5154
final Dependency[] dependencies, final MavenProject project,
55+
final Log log,
5256
final String[] artifactExcludes)
5357
throws InvalidDependencyVersionException,
5458
ArtifactResolutionException, ArtifactNotFoundException {
55-
if (dependencies == null) {
59+
if (dependencies == null || dependencies.length == 0) {
5660
return Collections.emptyList();
5761
}
5862

@@ -74,9 +78,18 @@ public static Collection<Artifact> resolveTransitively(
7478

7579
final ArtifactResolutionResult artifactResolutionResult = artifactResolver.resolve(request);
7680

77-
final Set<Artifact> resolvedArtifacts = artifactResolutionResult.getArtifacts();
78-
79-
return resolvedArtifacts;
81+
if (!artifactResolutionResult.isSuccess()) {
82+
if (artifactResolutionResult.hasMissingArtifacts()) {
83+
log.error("artifactResolutionResult has missing artifacts : " + artifactResolutionResult.getMissingArtifacts());
84+
throw new RuntimeException("Artifacts - missing artifacts");
85+
} else if (artifactResolutionResult.hasExceptions()) {
86+
log.error("artifactResolutionResult has exceptions : " + artifactResolutionResult.getExceptions());
87+
throw new RuntimeException("Artifacts - exceptions", artifactResolutionResult.getExceptions().get(0));
88+
} else {
89+
log.error("artifactResolutionResult status is not success");
90+
} throw new RuntimeException("Artifacts - not in success");
91+
}
92+
return artifactResolutionResult.getArtifacts();
8093
}
8194

8295
public static Collection<Artifact> resolve(
@@ -87,7 +100,7 @@ public static Collection<Artifact> resolve(
87100
final Dependency[] dependencies, final MavenProject project)
88101
throws InvalidDependencyVersionException,
89102
ArtifactResolutionException, ArtifactNotFoundException {
90-
if (dependencies == null) {
103+
if (dependencies == null || dependencies.length == 0) {
91104
return Collections.emptyList();
92105
}
93106

0 commit comments

Comments
 (0)