Skip to content

Commit

Permalink
fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Aug 28, 2024
1 parent 9a60300 commit 747e26f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Artifact {
public static final String GROUP_OPENMRS = "org.openmrs";
public static final String GROUP_H2 = "com.h2database";
public static final String GROUP_DISTRO = "org.openmrs.distro";
public static final String GROUP_CONTENT = "org.openmrs.content";
public static final String TYPE_OMOD = "omod";
public static final String TYPE_WAR = "war";
public static final String TYPE_JAR = "jar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ public abstract class BaseSdkProperties {

public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId";
public static final String PROPERTY_DISTRO_GROUP_ID = "distro.groupId";
protected static final String ARTIFACT_ID = "artifactId";
public static final String ARTIFACT_ID = "artifactId";
protected static final String TYPE = "type";
protected static final String GROUP_ID = "groupId";
public static final String GROUP_ID = "groupId";
protected static final String TYPE_OMOD = "omod";
protected static final String TYPE_WAR = "war";
protected static final String TYPE_JAR = "jar";
protected static final String NAME = "name";
protected static final String VERSION = "version";
protected static final String TYPE_DISTRO = "distro";
protected static final String TYPE_CONTENT = "content";
protected static final String TYPE_OWA = "owa";
protected static final String TYPE_SPA = "spa";
protected static final String TYPE_CONFIG = "config";
Expand Down Expand Up @@ -167,7 +168,7 @@ protected String getArtifactType(String key){
}

protected String checkIfOverwritten(String key, String param) {
String newKey = key + "." + param;
String newKey = key + "." + param; //content.hiv
if (getParam(newKey) != null) {
String setting = getParam(newKey);
if (setting.equals("referenceapplication")) {
Expand All @@ -189,6 +190,8 @@ protected String checkIfOverwritten(String key, String param) {
case TYPE_DISTRO:
case TYPE_CONFIG:
return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO);
case TYPE_CONTENT:
return properties.getProperty(param + ".groupId",Artifact.GROUP_CONTENT);
default:
return "";
}
Expand All @@ -200,6 +203,7 @@ protected String checkIfOverwritten(String key, String param) {
return TYPE_JAR;
case TYPE_WAR:
return TYPE_WAR;
case TYPE_CONTENT:
case TYPE_CONFIG:
return TYPE_ZIP;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public Artifact getDistroArtifact() {
return null;
}

public Artifact getContentArtifact() {
for (Object keyObject: getAllKeys()) {
String key = keyObject.toString();
String artifactType = getArtifactType(key);
if(artifactType.equals(TYPE_CONTENT)) {
return new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "zip");
}
}
return null;
}

public Artifact getParentArtifact() {
String parentArtifactId = getParam("parent.artifactId");
String parentGroupId = getParam("parent.groupId");
Expand Down Expand Up @@ -319,4 +330,8 @@ public String get(String contentDependencyKey) {
return properties.getProperty(contentDependencyKey);
}

@Override
public String checkIfOverwritten(String key, String param) {
return super.checkIfOverwritten(key, param);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,7 @@ private Map<String, String> getDistroVersionsOptionsMap(Set<String> versions, Ve
* @param optionTemplate The template for generating option keys in the map.
* @return A LinkedHashMap containing the generated options map.
*/
private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelper,
String optionTemplate) {
private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelper, String optionTemplate) {
Map<String, String> optionsMap = new LinkedHashMap<>();

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,66 +637,54 @@ public void parseContentProperties(DistroProperties distroProperties) throws Moj
* such as missing or invalid {@code content.properties} files, or any IO issues.
*/
public void downloadContentPackages(File contentPackageZipFile, DistroProperties distroProperties)
throws MojoExecutionException {
throws MojoExecutionException {
Properties contentProperties = new Properties();

for (Object key : distroProperties.getAllKeys()) {
String keyOb = key.toString();
if (!keyOb.startsWith(CONTENT_PREFIX)) {
continue;
}

String version = distroProperties.get(keyOb);
String zipFileName = keyOb.replace(CONTENT_PREFIX, "") + "-" + version + ".zip";
String artifactId = keyOb.replace(CONTENT_PREFIX, "");
String groupId = checkIfOverwritten(keyOb, distroProperties);

Artifact artifact = new Artifact(artifactId, version, groupId, "zip");
File zipFile = downloadDistro(contentPackageZipFile, artifact, zipFileName);

if (zipFile == null) {
log.warn("ZIP file not found for content package: {}", keyOb);
continue;
}

try (ZipFile zip = new ZipFile(zipFile)) {
boolean foundContentProperties = false;
Enumeration<? extends ZipEntry> entries = zip.entries();

while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
if (zipEntry.getName().equals(CONTENT_PROPERTIES)) {
foundContentProperties = true;

try (InputStream inputStream = zip.getInputStream(zipEntry)) {
contentProperties.load(inputStream);
log.info("content.properties file found in {} and parsed successfully.",
contentPackageZipFile.getName());

if (contentProperties.getProperty("name") == null
|| contentProperties.getProperty("version") == null) {
throw new MojoExecutionException(
"Content package name or version not specified in content.properties in "
+ contentPackageZipFile.getName());
}

processContentProperties(contentProperties, distroProperties, contentPackageZipFile.getName());
Artifact artifact = distroProperties.getContentArtifact();
String zipFileName = artifact.getArtifactId().replace(CONTENT_PREFIX, "") + "-" + artifact.getVersion() + ".zip";

File zipFile = downloadDistro(contentPackageZipFile, artifact, zipFileName);
if (zipFile == null) {
return;
}

try (ZipFile zip = new ZipFile(zipFile)) {
boolean foundContentProperties = false;
Enumeration<? extends ZipEntry> entries = zip.entries();

while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
if (zipEntry.getName().equals(CONTENT_PROPERTIES)) {
foundContentProperties = true;

try (InputStream inputStream = zip.getInputStream(zipEntry)) {
contentProperties.load(inputStream);
log.info("content.properties file found in {} and parsed successfully.",
contentPackageZipFile.getName());

if (contentProperties.getProperty("name") == null
|| contentProperties.getProperty("version") == null) {
throw new MojoExecutionException(
"Content package name or version not specified in content.properties in "
+ contentPackageZipFile.getName());
}
break;

processContentProperties(contentProperties, distroProperties, contentPackageZipFile.getName());
}
break;
}

if (!foundContentProperties) {
throw new MojoExecutionException(
"No content.properties file found in ZIP file: " + contentPackageZipFile.getName());
}

}
catch (IOException e) {
throw new MojoExecutionException("Error reading content.properties from ZIP file: "
+ contentPackageZipFile.getName() + ": " + e.getMessage(), e);

if (!foundContentProperties) {
throw new MojoExecutionException(
"No content.properties file found in ZIP file: " + contentPackageZipFile.getName());
}

}
catch (IOException e) {
throw new MojoExecutionException("Error reading content.properties from ZIP file: "
+ contentPackageZipFile.getName() + ": " + e.getMessage(), e);
}

}

/**
Expand Down Expand Up @@ -748,18 +736,6 @@ protected void processContentProperties(Properties contentProperties, DistroProp
}
}

/**
* Checks if the groupId for a given dependency is overwritten in the distro properties.
*
* @param dependencyKey The key of the dependency.
* @param distroProperties The distro properties file.
* @return The groupId to use for this dependency.
*/
private static String checkIfOverwritten(String dependencyKey, DistroProperties distroProperties) {
String groupId = distroProperties.get(dependencyKey + ".groupId");
return groupId != null ? groupId : "org.openmrs.content";
}

/**
* Checks if the version from distro.properties satisfies the range specified in content.properties.
* Throws an exception if there is a mismatch.
Expand Down

0 comments on commit 747e26f

Please sign in to comment.