diff options
author | gjoranv <gv@yahooinc.com> | 2023-06-30 21:39:45 +0200 |
---|---|---|
committer | gjoranv <gv@yahooinc.com> | 2023-07-03 22:37:54 +0200 |
commit | 65a282ad8124f49c9584ab0293481d71f612fe85 (patch) | |
tree | 0aaef9e0c7f8997c8772d6f99f999c09a84f8371 /bundle-plugin/src | |
parent | b79d3e00ebd5d989f085991e75d26578e90ebadd (diff) |
Use a list of allowed artifacts instead of a simple switch.
- Suppress warning for embedding jaxb-api in test bundle.
Diffstat (limited to 'bundle-plugin/src')
-rw-r--r-- | bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java index 38e8acc1303..26010e4974d 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateOsgiManifestMojo.java @@ -78,8 +78,8 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { private boolean suppressWarningPublicApi; @Parameter(defaultValue = "false") private boolean suppressWarningOverlappingPackages; - @Parameter(defaultValue = "false") - private boolean suppressWarningEmbeddedArtifacts; + @Parameter + private List<String> allowEmbeddedArtifacts = List.of(); @Parameter(defaultValue = "false") private boolean failOnWarnings; @@ -244,19 +244,42 @@ public class GenerateOsgiManifestMojo extends AbstractGenerateOsgiManifestMojo { } } - private void logProvidedArtifactsIncluded(List<Artifact> includedArtifacts, List<ArtifactInfo> providedArtifacts) { - if (suppressWarningEmbeddedArtifacts || effectiveBundleType() == BundleType.CORE) return; + private void logProvidedArtifactsIncluded(List<Artifact> includedArtifacts, + List<ArtifactInfo> providedArtifacts) throws MojoExecutionException { + if (effectiveBundleType() == BundleType.CORE) return; Set<ArtifactInfo> included = includedArtifacts.stream().map(ArtifactInfo::new).collect(Collectors.toSet()); Set<ArtifactInfo> providedIncluded = Sets.intersection(included, new HashSet<>(providedArtifacts)); - if (providedIncluded.isEmpty()) return; - List<String> sorted = providedIncluded.stream() + HashSet<ArtifactInfo> allowed = getAllowedEmbeddedArtifacts(providedIncluded); + + List<String> violations = providedIncluded.stream() + .filter(a -> !allowed.contains(a)) .map(ArtifactInfo::stringValue) .sorted().toList(); - // TODO: improve error message - warnOrThrow("Artifacts provided from Jdisc runtime are included in compile scope: " + sorted); + if (! violations.isEmpty()) { + // TODO: improve error message + warnOrThrow("Artifacts provided from Jdisc runtime are included in compile scope: " + violations); + } + } + + private HashSet<ArtifactInfo> getAllowedEmbeddedArtifacts(Set<ArtifactInfo> providedIncluded) throws MojoExecutionException { + if (allowEmbeddedArtifacts.isEmpty()) return new HashSet<>(); + + var allowed = new HashSet<ArtifactInfo>(); + try { + allowEmbeddedArtifacts.stream().map(ArtifactInfo::fromStringValue).forEach(allowed::add); + } catch (Exception e) { + throw new MojoExecutionException("In config parameter 'allowEmbeddedArtifacts': " + e.getMessage(), e); + } + var allowedButUnused = Sets.difference(allowed, providedIncluded); + if (! allowedButUnused.isEmpty()) { + warnOrThrow("'allowEmbeddedArtifacts' contains artifact(s) not used in project: %s" + .formatted(allowedButUnused.stream().map(ArtifactInfo::stringValue).toList())); + } + getLog().info("Ignoring artifacts embedded in bundle: " + allowEmbeddedArtifacts); + return allowed; } private static String trimWhitespace(Optional<String> lines) { |