From a652a4220dc2002120258a606c5485c9981a73de Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 24 Apr 2024 14:43:04 +0200 Subject: [PATCH] Proper merge Also port to maven-api-impl --- .../internal/impl/resolver/LocalSnapshotMetadata.java | 5 +++++ .../maven/internal/impl/resolver/PluginsMetadata.java | 6 +++++- .../internal/impl/resolver/RemoteSnapshotMetadata.java | 6 ++++++ .../maven/internal/impl/resolver/VersionsMetadata.java | 5 +++++ .../maven/repository/internal/LocalSnapshotMetadata.java | 5 +++++ .../apache/maven/repository/internal/MavenMetadata.java | 2 -- .../apache/maven/repository/internal/PluginsMetadata.java | 7 ++++++- .../maven/repository/internal/RemoteSnapshotMetadata.java | 5 +++++ .../apache/maven/repository/internal/VersionsMetadata.java | 5 +++++ 9 files changed, 42 insertions(+), 4 deletions(-) diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadata.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadata.java index 8ca41fba3447..511a2246b4c2 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadata.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/LocalSnapshotMetadata.java @@ -113,6 +113,11 @@ protected void merge(Metadata recessive) { metadata = metadata.withVersioning(metadata.getVersioning().withSnapshotVersions(versions.values())); + // just carry-on as-is + if (recessive.getPlugins() != null && !recessive.getPlugins().isEmpty()) { + metadata = metadata.withPlugins(new ArrayList<>(recessive.getPlugins())); + } + artifacts.clear(); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadata.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadata.java index 9a424e9765ba..8c9665ba08cb 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadata.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/PluginsMetadata.java @@ -74,12 +74,16 @@ private static Metadata createRepositoryMetadata(PluginInfo pluginInfo) { protected void merge(Metadata recessive) { List recessivePlugins = recessive.getPlugins(); List plugins = metadata.getPlugins(); - if (!plugins.isEmpty()) { + if (!recessivePlugins.isEmpty() || !plugins.isEmpty()) { LinkedHashMap mergedPlugins = new LinkedHashMap<>(); recessivePlugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p)); plugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p)); metadata = metadata.withPlugins(mergedPlugins.values()); } + // just carry-on as-is + if (recessive.getVersioning() != null) { + metadata = metadata.withVersioning(recessive.getVersioning()); + } } @Deprecated diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadata.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadata.java index 9f0a168d5599..2365cb24823b 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadata.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/RemoteSnapshotMetadata.java @@ -22,6 +22,7 @@ import java.nio.file.Path; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; import java.util.LinkedHashMap; @@ -130,6 +131,11 @@ protected void merge(Metadata recessive) { } metadata = metadata.withVersioning(metadata.getVersioning().withSnapshotVersions(versions.values())); + + // just carry-on as-is + if (recessive.getPlugins() != null && !recessive.getPlugins().isEmpty()) { + metadata = metadata.withPlugins(new ArrayList<>(recessive.getPlugins())); + } } private static int getBuildNumber(Metadata metadata) { diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadata.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadata.java index 2ee20677d28b..219550e0bab6 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadata.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/VersionsMetadata.java @@ -90,6 +90,11 @@ protected void merge(Metadata recessive) { } metadata = metadata.withVersioning(versioning.build()); + + // just carry-on as-is + if (recessive.getPlugins() != null && !recessive.getPlugins().isEmpty()) { + metadata = metadata.withPlugins(new ArrayList<>(recessive.getPlugins())); + } } public Object getKey() { diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java index 506a138b0e9f..aea6a0126704 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java @@ -114,6 +114,11 @@ protected void merge(Metadata recessive) { metadata.getVersioning().setSnapshotVersions(new ArrayList<>(versions.values())); + // just carry-on as-is + if (!recessive.getPlugins().isEmpty()) { + metadata.setPlugins(new ArrayList<>(recessive.getPlugins())); + } + artifacts.clear(); } diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java index 9d2dccd3090e..3e7f9dbe63fd 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java @@ -85,8 +85,6 @@ public void merge(File existing, File result) throws RepositoryException { @Override public void merge(Path existing, Path result) throws RepositoryException { Metadata recessive = read(existing); - recessive.merge(metadata); - metadata = recessive; merge(recessive); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java index 46444d55f585..8326f7ae5876 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/PluginsMetadata.java @@ -75,12 +75,17 @@ private static Metadata createRepositoryMetadata(PluginInfo pluginInfo) { protected void merge(Metadata recessive) { List recessivePlugins = recessive.getPlugins(); List plugins = metadata.getPlugins(); - if (!plugins.isEmpty()) { + if (!recessivePlugins.isEmpty() || !plugins.isEmpty()) { LinkedHashMap mergedPlugins = new LinkedHashMap<>(); recessivePlugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p)); plugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p)); metadata.setPlugins(new ArrayList<>(mergedPlugins.values())); } + + // just carry-on as-is + if (recessive.getVersioning() != null) { + metadata.setVersioning(recessive.getVersioning()); + } } @Deprecated diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java index ae6789b9a20c..a543495f7e13 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java @@ -128,6 +128,11 @@ protected void merge(Metadata recessive) { } metadata.getVersioning().setSnapshotVersions(new ArrayList<>(versions.values())); + + // just carry-on as-is + if (!recessive.getPlugins().isEmpty()) { + metadata.setPlugins(new ArrayList<>(recessive.getPlugins())); + } } private static int getBuildNumber(Metadata metadata) { diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java index 2a7737a39535..8cd465fcab4b 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java @@ -84,6 +84,11 @@ protected void merge(Metadata recessive) { versions.addAll(versioning.getVersions()); versioning.setVersions(new ArrayList<>(versions)); } + + // just carry-on as-is + if (!recessive.getPlugins().isEmpty()) { + metadata.setPlugins(new ArrayList<>(recessive.getPlugins())); + } } public Object getKey() {