-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from spyrkob/merge_manifests
[SET-679] Add FIRST merge strategy
- Loading branch information
Showing
5 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.wildfly.prospero.extras.manifest.merge; | ||
|
||
import org.wildfly.channel.version.VersionMatcher; | ||
|
||
interface VersionMergeStrategy { | ||
enum Strategies implements VersionMergeStrategy { | ||
LATEST(new LatestMergeStrategy()), | ||
FIRST(new FirstMergeStrategy()); | ||
|
||
private final VersionMergeStrategy mergeStrategy; | ||
|
||
Strategies(VersionMergeStrategy mergeStrategy) { | ||
this.mergeStrategy = mergeStrategy; | ||
} | ||
|
||
public String merge(String v1, String v2) { | ||
return mergeStrategy.merge(v1, v2); | ||
} | ||
} | ||
String merge(String v1, String v2); | ||
} | ||
|
||
class FirstMergeStrategy implements VersionMergeStrategy { | ||
|
||
@Override | ||
public String merge(String v1, String v2) { | ||
return v1; | ||
} | ||
} | ||
|
||
class LatestMergeStrategy implements VersionMergeStrategy { | ||
|
||
@Override | ||
public String merge(String v1, String v2) { | ||
if (VersionMatcher.COMPARATOR.compare(v2, v1) > 0) { | ||
return v2; | ||
} else { | ||
return v1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/java/org/wildfly/prospero/extras/manifest/merge/VersionMergeStrategyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.wildfly.prospero.extras.manifest.merge; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class VersionMergeStrategyTest { | ||
|
||
@Test | ||
public void testLatestVersionMerge() { | ||
final VersionMergeStrategy latest = new LatestMergeStrategy(); | ||
assertEquals("1.2.4", latest.merge("1.2.3", "1.2.4")); | ||
assertEquals("1.2.4", latest.merge("1.2.4", "1.2.3")); | ||
} | ||
|
||
@Test | ||
public void testFirstVersionMerge() { | ||
final VersionMergeStrategy first = new FirstMergeStrategy(); | ||
assertEquals("1.2.3", first.merge("1.2.3", "1.2.4")); | ||
assertEquals("1.2.4", first.merge("1.2.4", "1.2.3")); | ||
} | ||
} |