diff --git a/src/main/java/org/wildfly/prospero/extras/ProsperoExtras.java b/src/main/java/org/wildfly/prospero/extras/ProsperoExtras.java new file mode 100644 index 0000000..b0597b1 --- /dev/null +++ b/src/main/java/org/wildfly/prospero/extras/ProsperoExtras.java @@ -0,0 +1,11 @@ +package org.wildfly.prospero.extras; + +import org.wildfly.prospero.extras.manifest.ManifestOperations; +import org.wildfly.prospero.extras.manifest.ManifestOperationsFactory; + +public class ProsperoExtras { + + public static ManifestOperations manifestOperations() { + return ManifestOperationsFactory.getNewInstance(); + } +} \ No newline at end of file diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperations.java b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperations.java new file mode 100644 index 0000000..550bfbd --- /dev/null +++ b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperations.java @@ -0,0 +1,39 @@ +package org.wildfly.prospero.extras.manifest; + +import org.wildfly.channel.ChannelManifest; +import org.wildfly.installationmanager.ArtifactChange; +import org.wildfly.prospero.extras.manifest.merge.VersionMergeStrategy; + +import java.util.List; + +public interface ManifestOperations { + + /** + * Merges streams from two manifests. + * + * Creates a manifest containing streams from both input manifests. If the same stream is available in both input + * manifests, the conflict is resolved using a merge strategy. + * + * @param manifestOne - first manifest to merge + * @param manifestTwo - second manifest to merge + * @param mergeStrategy - merging strategy used if the stream is found in both manifests + * @param mergedManifestName - optional name of the generated manifest + * @param mergedManifestId - optional id of the generated manifest + * @return - merged manifest + */ + ChannelManifest merge(ChannelManifest manifestOne, ChannelManifest manifestTwo, + VersionMergeStrategy.Strategies mergeStrategy, + String mergedManifestName, String mergedManifestId); + + /** + * Performs a diff of {@code manifestOne} and {@code manifestTwo}. + * + * @param manifestOne - first manifest to diff + * @param manifestTwo - second manifest to diff + * @return - list of changed streams representes as {@link ArtifactChange}s + */ + List diff(ChannelManifest manifestOne, ChannelManifest manifestTwo); +} diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsFactory.java b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsFactory.java new file mode 100644 index 0000000..ce227cd --- /dev/null +++ b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsFactory.java @@ -0,0 +1,8 @@ +package org.wildfly.prospero.extras.manifest; + +public abstract class ManifestOperationsFactory { + + public static ManifestOperations getNewInstance() { + return new ManifestOperationsImpl(); + } +} diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsImpl.java b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsImpl.java new file mode 100644 index 0000000..d4e8a6a --- /dev/null +++ b/src/main/java/org/wildfly/prospero/extras/manifest/ManifestOperationsImpl.java @@ -0,0 +1,24 @@ +package org.wildfly.prospero.extras.manifest; + +import org.wildfly.channel.ChannelManifest; +import org.wildfly.installationmanager.ArtifactChange; +import org.wildfly.prospero.extras.manifest.diff.ManifestsDiffCommand; +import org.wildfly.prospero.extras.manifest.merge.ManifestMergeCommand; +import org.wildfly.prospero.extras.manifest.merge.VersionMergeStrategy; + +import java.util.List; + +class ManifestOperationsImpl implements ManifestOperations { + + @Override + public ChannelManifest merge(ChannelManifest manifestOne, ChannelManifest manifestTwo, + VersionMergeStrategy.Strategies mergeStrategy, + String mergedManifestName, String mergedManifestId) { + return ManifestMergeCommand.merge(manifestOne, manifestTwo, mergeStrategy, mergedManifestName, mergedManifestId); + } + + @Override + public List diff(ChannelManifest manifestOne, ChannelManifest manifestTwo) { + return ManifestsDiffCommand.manifestDiff(manifestOne, manifestTwo); + } +} diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/diff/ManifestsDiffCommand.java b/src/main/java/org/wildfly/prospero/extras/manifest/diff/ManifestsDiffCommand.java index df6427e..b5acd11 100644 --- a/src/main/java/org/wildfly/prospero/extras/manifest/diff/ManifestsDiffCommand.java +++ b/src/main/java/org/wildfly/prospero/extras/manifest/diff/ManifestsDiffCommand.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; import java.util.concurrent.Callable; @@ -72,6 +73,9 @@ public Integer call() throws Exception { } public static List manifestDiff(ChannelManifest manifestOne, ChannelManifest manifestTwo) { + Objects.requireNonNull(manifestOne); + Objects.requireNonNull(manifestTwo); + Map versionMapOne = streamToMap(manifestOne); Map versionMapTwo = streamToMap(manifestTwo); diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/merge/ManifestMergeCommand.java b/src/main/java/org/wildfly/prospero/extras/manifest/merge/ManifestMergeCommand.java index bfb1dee..cb19354 100644 --- a/src/main/java/org/wildfly/prospero/extras/manifest/merge/ManifestMergeCommand.java +++ b/src/main/java/org/wildfly/prospero/extras/manifest/merge/ManifestMergeCommand.java @@ -3,11 +3,13 @@ import org.wildfly.channel.ChannelManifest; import org.wildfly.channel.ChannelManifestMapper; import org.wildfly.channel.Stream; +import org.wildfly.prospero.extras.ReturnCodes; import picocli.CommandLine; import java.nio.file.Path; import java.util.Collection; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.Callable; @@ -35,10 +37,23 @@ public class ManifestMergeCommand implements Callable { @Override public Integer call() throws Exception { - final ChannelManifest manifestOne = ChannelManifestMapper.from(this.manifestOne.toUri().toURL()); final ChannelManifest manifestTwo = ChannelManifestMapper.from(this.manifestTwo.toUri().toURL()); + final ChannelManifest mergedManifest = merge(manifestOne, manifestTwo, mergeStrategy, mergedManifestName, mergedManifestId); + + System.out.println(ChannelManifestMapper.toYaml(mergedManifest)); + + return ReturnCodes.SUCCESS; + } + + public static ChannelManifest merge(ChannelManifest manifestOne, ChannelManifest manifestTwo, + VersionMergeStrategy.Strategies mergeStrategy, + String mergedManifestName, String mergedManifestId) { + Objects.requireNonNull(manifestOne); + Objects.requireNonNull(manifestTwo); + Objects.requireNonNull(mergeStrategy); + final Collection streamsOne = manifestOne.getStreams(); final Collection streamsTwo = manifestTwo.getStreams(); @@ -58,9 +73,6 @@ public Integer call() throws Exception { } } - final ChannelManifest mergedManifest = new ChannelManifest(mergedManifestName, mergedManifestId, null, merged); - System.out.println(ChannelManifestMapper.toYaml(mergedManifest)); - - return 0; + return new ChannelManifest(mergedManifestName, mergedManifestId, null, merged); } } diff --git a/src/main/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategy.java b/src/main/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategy.java index cdb8453..ee6b6c0 100644 --- a/src/main/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategy.java +++ b/src/main/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategy.java @@ -2,7 +2,7 @@ import org.wildfly.channel.version.VersionMatcher; -interface VersionMergeStrategy { +public interface VersionMergeStrategy { enum Strategies implements VersionMergeStrategy { LATEST(new LatestMergeStrategy()), FIRST(new FirstMergeStrategy());