Skip to content

Commit 661dd6d

Browse files
committed
Correct the O3 Versions during setup of an instance
1 parent 0285a8c commit 661dd6d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,13 @@ private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelpe
786786
Map<String, String> optionsMap = new LinkedHashMap<>();
787787

788788
{
789-
Artifact artifact = new Artifact("distro-emr-configuration", "3.0.0-SNAPSHOT", "org.openmrs", "zip");
790-
for (ArtifactVersion version : versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE)) {
791-
optionsMap.put(String.format(optionTemplate, version.toString()), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
789+
Artifact artifact = new Artifact("distro-emr-configuration", "3.0.0-beta.21", "org.openmrs", "zip");
790+
List<ArtifactVersion> versionList = versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE);
791+
for (ArtifactVersion version : versionList) {
792+
if (optionsMap.size() < MAX_OPTIONS_SIZE) {
793+
optionsMap.put(String.format(optionTemplate, version.toString()),
794+
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
795+
}
792796
}
793797
}
794798

@@ -797,10 +801,15 @@ private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelpe
797801
}
798802

799803
{
800-
Artifact artifact = new Artifact("referenceapplication-distro", "3.0.0-SNAPSHOT", "org.openmrs.distro", "zip");
801-
for (ArtifactVersion version : versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE)) {
802-
optionsMap.put(String.format(optionTemplate, version.toString()), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
803-
804+
Artifact artifact = new Artifact("referenceapplication-distro", "3.0.0-beta.21", "org.openmrs.distro", "zip");
805+
List<ArtifactVersion> versionList = versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE);
806+
for (ArtifactVersion version : versionList) {
807+
if (optionsMap.size() < MAX_OPTIONS_SIZE) {
808+
optionsMap.put(String.format(optionTemplate, version.toString()),
809+
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
810+
} else {
811+
break;
812+
}
804813
}
805814
}
806815

sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/VersionsHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.maven.artifact.factory.ArtifactFactory;
44
import org.apache.maven.artifact.versioning.ArtifactVersion;
5+
import org.apache.maven.artifact.versioning.ComparableVersion;
56
import org.apache.maven.execution.MavenSession;
67
import org.apache.maven.project.MavenProject;
78
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
@@ -68,14 +69,14 @@ private List<ArtifactVersion> getVersions(Artifact artifact){
6869

6970
public List<ArtifactVersion> getAllVersions(Artifact artifact, int maxSize) {
7071
List<ArtifactVersion> versions = getVersions(artifact);
72+
versions.removeIf(version -> "3.1.0-SNAPSHOT".equals(version.toString()));
73+
versions.removeIf(version -> "3.0.0-SNAPSHOT".equals(version.toString()));
7174
sortDescending(versions);
7275
return versions.subList(0, Math.min(versions.size(), maxSize));
7376
}
7477

75-
@SuppressWarnings("unchecked")
7678
private void sortDescending(List<ArtifactVersion> versions){
77-
Collections.sort(versions);
78-
Collections.reverse(versions);
79+
Collections.sort(versions, (v1, v2) -> new ComparableVersion(v2.toString()).compareTo(new ComparableVersion(v1.toString())));
7980
}
8081

8182
/**

0 commit comments

Comments
 (0)