Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-332: Correct the O3 Versions displayed during setup of an instance #285

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.openmrs.maven.plugins.utility;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;

import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -52,6 +50,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;

/**
* Class for attribute helper functions
*/
Expand Down Expand Up @@ -782,11 +782,11 @@ private Map<String, String> getDistroVersionsOptionsMap(Set<String> versions, Ve
* @return A LinkedHashMap containing the generated options map.
*/
private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelper,
String optionTemplate) {
String optionTemplate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we undo the change to this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next commit?

Map<String, String> optionsMap = new LinkedHashMap<>();

{
Artifact artifact = new Artifact("distro-emr-configuration", "3.0.0-SNAPSHOT", "org.openmrs", "zip");
Artifact artifact = new Artifact("distro-emr-configuration", "3.0.0", "org.openmrs", "zip");
for (ArtifactVersion version : versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE)) {
optionsMap.put(String.format(optionTemplate, version.toString()), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
}
Expand All @@ -797,10 +797,12 @@ private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelpe
}

{
Artifact artifact = new Artifact("referenceapplication-distro", "3.0.0-SNAPSHOT", "org.openmrs.distro", "zip");
Artifact artifact = new Artifact("referenceapplication-distro", "3.0.0", "org.openmrs.distro", "zip");
for (ArtifactVersion version : versionsHelper.getAllVersions(artifact, MAX_OPTIONS_SIZE)) {
optionsMap.put(String.format(optionTemplate, version.toString()), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);

if (!version.toString().endsWith("-SNAPSHOT") && optionsMap.size() < MAX_OPTIONS_SIZE) {
optionsMap.put(String.format(optionTemplate, version),
artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + version);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
Expand All @@ -11,6 +12,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
* Created by user on 27.05.16.
Expand Down Expand Up @@ -69,13 +71,21 @@ private List<ArtifactVersion> getVersions(Artifact artifact){
public List<ArtifactVersion> getAllVersions(Artifact artifact, int maxSize) {
List<ArtifactVersion> versions = getVersions(artifact);
sortDescending(versions);
Optional<ArtifactVersion> firstNonSnapshotVersion = versions.stream()
.filter(version -> !version.toString().endsWith("-SNAPSHOT"))
.findFirst();

if (firstNonSnapshotVersion.isPresent()) {
ArtifactVersion firstNonSnapshot = firstNonSnapshotVersion.get();
versions.removeIf(version -> version.toString().endsWith("-SNAPSHOT")
&& new ComparableVersion(version.toString()).compareTo(new ComparableVersion(firstNonSnapshot.toString())) < 0);
}

return versions.subList(0, Math.min(versions.size(), maxSize));
}

@SuppressWarnings("unchecked")
private void sortDescending(List<ArtifactVersion> versions){
Collections.sort(versions);
Collections.reverse(versions);
Collections.sort(versions, (v1, v2) -> new ComparableVersion(v2.toString()).compareTo(new ComparableVersion(v1.toString())));
}

/**
Expand Down
Loading