[MNG-8106] Fix metadata merge (#1481)

As currently if given metadata serves multiple roles (G, A or V level), data loss occurs.

---

https://issues.apache.org/jira/browse/MNG-8106
This commit is contained in:
Tamas Cservenak 2024-04-25 12:10:21 +02:00 committed by GitHub
parent 31d2dc1815
commit 854589b131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 2 deletions

View File

@ -113,6 +113,11 @@ final class LocalSnapshotMetadata extends MavenMetadata {
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();
}

View File

@ -74,12 +74,16 @@ final class PluginsMetadata extends MavenMetadata {
protected void merge(Metadata recessive) {
List<Plugin> recessivePlugins = recessive.getPlugins();
List<Plugin> plugins = metadata.getPlugins();
if (!plugins.isEmpty()) {
if (!recessivePlugins.isEmpty() || !plugins.isEmpty()) {
LinkedHashMap<String, Plugin> 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

View File

@ -22,6 +22,7 @@ import java.io.File;
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 @@ final class RemoteSnapshotMetadata extends MavenSnapshotMetadata {
}
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) {

View File

@ -90,6 +90,11 @@ final class VersionsMetadata extends MavenMetadata {
}
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() {

View File

@ -114,6 +114,11 @@ final class LocalSnapshotMetadata extends MavenMetadata {
metadata.getVersioning().setSnapshotVersions(new ArrayList<>(versions.values()));
// just carry-on as-is
if (!recessive.getPlugins().isEmpty()) {
metadata.setPlugins(new ArrayList<>(recessive.getPlugins()));
}
artifacts.clear();
}

View File

@ -75,12 +75,17 @@ final class PluginsMetadata extends MavenMetadata {
protected void merge(Metadata recessive) {
List<Plugin> recessivePlugins = recessive.getPlugins();
List<Plugin> plugins = metadata.getPlugins();
if (!plugins.isEmpty()) {
if (!recessivePlugins.isEmpty() || !plugins.isEmpty()) {
LinkedHashMap<String, Plugin> 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

View File

@ -128,6 +128,11 @@ final class RemoteSnapshotMetadata extends MavenSnapshotMetadata {
}
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) {

View File

@ -84,6 +84,11 @@ final class VersionsMetadata extends MavenMetadata {
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() {