diff options
author | jonmv <venstad@gmail.com> | 2022-06-14 12:15:06 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-06-14 12:15:06 +0200 |
commit | 0d961d34aa221d43473155148ca5976740549df6 (patch) | |
tree | e6c5c1f5aaccf9d733b10ac44b135020c90feed8 /bundle-plugin | |
parent | e0e3ff465fcec5bb6a7253da2cd6df82f9701066 (diff) |
Handle multiple artifacts with different classifiers
Diffstat (limited to 'bundle-plugin')
4 files changed, 19 insertions, 18 deletions
diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/AssembleTestBundleMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/AssembleTestBundleMojo.java index 117d2cdc87e..acf0950decd 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/AssembleTestBundleMojo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/AssembleTestBundleMojo.java @@ -27,7 +27,7 @@ public class AssembleTestBundleMojo extends AbstractAssembleBundleMojo { @Override public void execute() throws MojoExecutionException { Artifacts.ArtifactSet artifacts = Artifacts.getArtifacts( - project, TestBundleDependencyScopeTranslator.from(project.getArtifactMap(), testBundleScopeOverrides)); + project, TestBundleDependencyScopeTranslator.from(project.getArtifacts(), testBundleScopeOverrides)); JarArchiver archiver = new JarArchiver(); addDirectory(archiver, Paths.get(project.getBuild().getOutputDirectory())); addDirectory(archiver, Paths.get(project.getBuild().getTestOutputDirectory())); diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateTestBundleOsgiManifestMojo.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateTestBundleOsgiManifestMojo.java index 0b10627d396..5708d90f82f 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateTestBundleOsgiManifestMojo.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/mojo/GenerateTestBundleOsgiManifestMojo.java @@ -40,7 +40,7 @@ public class GenerateTestBundleOsgiManifestMojo extends AbstractGenerateOsgiMani public void execute() throws MojoExecutionException { try { Artifacts.ArtifactSet artifactSet = Artifacts.getArtifacts( - project, TestBundleDependencyScopeTranslator.from(project.getArtifactMap(), testBundleScopeOverrides)); + project, TestBundleDependencyScopeTranslator.from(project.getArtifacts(), testBundleScopeOverrides)); List<File> providedJars = artifactSet.getJarArtifactsProvided().stream() .map(Artifact::getFile) diff --git a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslator.java b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslator.java index bd6151aea9f..65606633dee 100644 --- a/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslator.java +++ b/bundle-plugin/src/main/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslator.java @@ -4,13 +4,17 @@ package com.yahoo.container.plugin.util; import org.apache.maven.artifact.Artifact; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Function; import java.util.logging.Logger; +import java.util.stream.Collectors; import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; /** * Translates the scope of dependencies when constructing a test bundle. @@ -40,11 +44,12 @@ public class TestBundleDependencyScopeTranslator implements Artifacts.ScopeTrans return Objects.requireNonNull(dependencyScopes.get(artifact), () -> "Could not lookup scope for " + artifact); } - public static TestBundleDependencyScopeTranslator from(Map<String, Artifact> dependencies, String rawConfig) { + public static TestBundleDependencyScopeTranslator from(Collection<Artifact> dependencies, String rawConfig) { List<DependencyOverride> dependencyOverrides = toDependencyOverrides(rawConfig); Map<Artifact, String> dependencyScopes = new HashMap<>(); - for (Artifact dependency : dependencies.values()) { - dependencyScopes.put(dependency, getScopeForDependency(dependency, dependencyOverrides, dependencies)); + Map<String, Artifact> dependenciesById = dependencies.stream().collect(toMap(Artifact::getId, Function.identity())); + for (Artifact dependency : dependencies) { + dependencyScopes.put(dependency, getScopeForDependency(dependency, dependencyOverrides, dependenciesById)); } return new TestBundleDependencyScopeTranslator(dependencyScopes); } @@ -66,12 +71,6 @@ public class TestBundleDependencyScopeTranslator implements Artifacts.ScopeTrans return new DependencyOverride(elements[0], elements[1], elements[2]); } - private static String stripVersionAndScope(String idInDependencyTrail) { - int firstDelimiter = idInDependencyTrail.indexOf(':'); - int secondDelimiter = idInDependencyTrail.indexOf(':', firstDelimiter + 1); - return idInDependencyTrail.substring(0, secondDelimiter); - } - private static String getScopeForDependency( Artifact dependency, List<DependencyOverride> overrides, Map<String, Artifact> otherArtifacts) { String oldScope = dependency.getScope(); @@ -95,7 +94,7 @@ public class TestBundleDependencyScopeTranslator implements Artifacts.ScopeTrans private static List<Artifact> dependencyTrailOf(Artifact artifact, Map<String, Artifact> otherArtifacts) { return artifact.getDependencyTrail().stream() .skip(1) // Maven project itself is the first entry - .map(parentId -> otherArtifacts.get(stripVersionAndScope(parentId))) + .map(otherArtifacts::get) .filter(Objects::nonNull) .collect(toList()); } diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslatorTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslatorTest.java index d5986b00077..c0f2766b5ed 100644 --- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslatorTest.java +++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/util/TestBundleDependencyScopeTranslatorTest.java @@ -10,7 +10,9 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import static org.junit.Assert.assertEquals; @@ -23,7 +25,7 @@ public class TestBundleDependencyScopeTranslatorTest { @Test public void test_dependencies_are_translated_to_compile_scope_by_default() { - Map<String, Artifact> artifacts = new TreeMap<>(); + Set<Artifact> artifacts = new TreeSet<>(); Artifact a = createArtifact(artifacts, "a", "test", List.of()); Artifact aa = createArtifact(artifacts, "a-a", "test", List.of("a")); Artifact ab = createArtifact(artifacts, "a-b", "test", List.of("a")); @@ -39,7 +41,7 @@ public class TestBundleDependencyScopeTranslatorTest { @Test public void non_test_scope_dependencies_keep_original_scope() { - Map<String, Artifact> artifacts = new TreeMap<>(); + Set<Artifact> artifacts = new TreeSet<>(); Artifact a = createArtifact(artifacts, "a", "provided", List.of()); Artifact aa = createArtifact(artifacts, "a-a", "provided", List.of("a")); Artifact ab = createArtifact(artifacts, "a-b", "provided", List.of("a")); @@ -60,7 +62,7 @@ public class TestBundleDependencyScopeTranslatorTest { @Test public void ordering_in_config_string_determines_translation() { - Map<String, Artifact> artifacts = new TreeMap<>(); + Set<Artifact> artifacts = new TreeSet<>(); Artifact a = createArtifact(artifacts, "a", "test", List.of()); Artifact aa = createArtifact(artifacts, "a-a", "test", List.of("a")); { @@ -83,7 +85,7 @@ public class TestBundleDependencyScopeTranslatorTest { @Test public void transitive_non_test_dependencies_of_test_dependencies_keep_original_scope() { - Map<String, Artifact> artifacts = new TreeMap<>(); + Set<Artifact> artifacts = new TreeSet<>(); Artifact a = createArtifact(artifacts, "a", "test", List.of()); Artifact aa = createArtifact(artifacts, "a-a", "test", List.of("a")); Artifact ab = createArtifact(artifacts, "a-b", "test", List.of("a")); @@ -106,9 +108,9 @@ public class TestBundleDependencyScopeTranslatorTest { } private static Artifact createArtifact( - Map<String, Artifact> artifacts, String artifactId, String scope, List<String> transitiveDependents) { + Set<Artifact> artifacts, String artifactId, String scope, List<String> transitiveDependents) { Artifact artifact = createArtifact(artifactId, scope, transitiveDependents); - artifacts.put(simpleId(artifactId), artifact); + artifacts.add(artifact); return artifact; } |