diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java index 175e9d28..2cebb1cd 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Artifact.java @@ -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"; diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java index a843e133..4642d1ce 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java @@ -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"; @@ -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")) { @@ -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 ""; } @@ -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: diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index 04153a69..7a9f0def 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -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"); @@ -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); + } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java index dcc4a648..ca872e5d 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java @@ -781,8 +781,7 @@ private Map getDistroVersionsOptionsMap(Set versions, Ve * @param optionTemplate The template for generating option keys in the map. * @return A LinkedHashMap containing the generated options map. */ - private Map getO3VersionsOptionsMap(VersionsHelper versionsHelper, - String optionTemplate) { + private Map getO3VersionsOptionsMap(VersionsHelper versionsHelper, String optionTemplate) { Map optionsMap = new LinkedHashMap<>(); { diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java index 4e6a4d55..6e21825a 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java @@ -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 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 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); + } + } /** @@ -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.