diff --git a/integration-tests/src/test/resources/integration-test/openmrs-distro.properties b/integration-tests/src/test/resources/integration-test/openmrs-distro.properties index 22f41632f..d7e06d215 100644 --- a/integration-tests/src/test/resources/integration-test/openmrs-distro.properties +++ b/integration-tests/src/test/resources/integration-test/openmrs-distro.properties @@ -13,4 +13,6 @@ spa.frontendModules.@openmrs/esm-login-app=5.6.0 spa.frontendModules.@openmrs/esm-patient-chart-app=8.0.0 spa.apiUrl=notopenmrs spa.configUrls=foo +content.hiv.groupId=org.openmrs.content +content.hiv.type=zip content.hiv=1.0.0 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 a75cce6d9..768a36e6f 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 @@ -154,9 +154,14 @@ public List getContentArtifacts() { List artifacts = new ArrayList<>(); for (Object keyObject : getAllKeys()) { String key = keyObject.toString(); - if (key.startsWith(TYPE_CONTENT + ".")) { - artifacts.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), - checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); + String artifactType = getArtifactType(key); + if (artifactType.equals(TYPE_CONTENT)) { + artifacts.add(new Artifact( + checkIfOverwritten(key, ARTIFACT_ID), + getParam(key), + checkIfOverwritten(key, GROUP_ID), + checkIfOverwritten(key, TYPE) + )); } } return artifacts; @@ -166,7 +171,7 @@ protected Set getAllKeys() { return properties.keySet(); } - protected String getArtifactType(String key){ + protected String getArtifactType(String key) { String[] wordsArray = key.split("\\."); if(!(wordsArray[wordsArray.length-1].equals(TYPE) || wordsArray[wordsArray.length-1].equals(ARTIFACT_ID) || wordsArray[wordsArray.length-1].equals(GROUP_ID))){ if(key.contains(".")){ 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 756af6039..7ab9119f8 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 @@ -641,23 +641,16 @@ public void parseContentProperties(DistroProperties distroProperties) throws Moj */ public void downloadContentPackages(File contentPackageZipFile, DistroProperties distroProperties) throws MojoExecutionException { - Properties contentProperties = new Properties(); - for (Object key : distroProperties.getAllKeys()) { - String keyOb = key.toString(); - if (!keyOb.startsWith(CONTENT_PREFIX)) { - continue; - } + Properties contentProperties = new Properties(); - Artifact artifact = new Artifact(distroProperties.checkIfOverwritten(keyOb.replace(CONTENT_PREFIX, ""), ARTIFACT_ID), distroProperties.getParam(keyOb), - distroProperties.checkIfOverwritten(keyOb, GROUP_ID), distroProperties.checkIfOverwritten(keyOb, TYPE)); + for (Artifact artifact : distroProperties.getContentArtifacts()) { - String version = distroProperties.get(keyOb); - String zipFileName = keyOb.replace(CONTENT_PREFIX, "") + "-" + version + ".zip"; + String zipFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + ".zip"; File zipFile = downloadDistro(contentPackageZipFile, artifact, zipFileName); if (zipFile == null) { - log.warn("ZIP file not found for content package: {}", keyOb); + log.warn("ZIP file not found for content package: {}", artifact.getArtifactId()); continue; } diff --git a/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/DistroPropertiesTest.java b/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/DistroPropertiesTest.java index 1888f6abf..d0a7c3cc4 100644 --- a/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/DistroPropertiesTest.java +++ b/sdk-commons/src/test/java/org/openmrs/maven/plugins/model/DistroPropertiesTest.java @@ -8,7 +8,9 @@ import java.util.List; import java.util.Properties; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; @@ -50,6 +52,42 @@ public void resolvePlaceholders_shouldReplaceVersions() throws MojoExecutionExce assertThat(distro.getPlatformVersion(), is("222")); } + @Test + public void shouldGetContentPropertiesWithDefaults() { + Properties properties = new Properties(); + properties.setProperty("content.hiv", "1.0.0"); + properties.setProperty("content.tb", "2.3.4-SNAPSHOT"); + DistroProperties distro = new DistroProperties(properties); + List contentArtifacts = distro.getContentArtifacts(); + assertThat(contentArtifacts, hasSize(2)); + Artifact hiv = findArtifactByArtifactId(contentArtifacts, "hiv"); + assertThat(hiv, notNullValue()); + assertThat(hiv, hasVersion("1.0.0")); + assertThat(hiv.getGroupId(), equalTo(Artifact.GROUP_CONTENT)); + assertThat(hiv.getType(), equalTo(Artifact.TYPE_ZIP)); + Artifact tb = findArtifactByArtifactId(contentArtifacts, "tb"); + assertThat(tb, notNullValue()); + assertThat(tb, hasVersion("2.3.4-SNAPSHOT")); + assertThat(tb.getGroupId(), equalTo(Artifact.GROUP_CONTENT)); + assertThat(tb.getType(), equalTo(Artifact.TYPE_ZIP)); + } + + @Test + public void shouldGetContentPropertiesWithOverrides() { + Properties properties = new Properties(); + properties.setProperty("content.hiv", "1.0.0"); + properties.setProperty("content.hiv.groupId", "org.openmrs.new"); + properties.setProperty("content.hiv.type", "gzip"); + DistroProperties distro = new DistroProperties(properties); + List contentArtifacts = distro.getContentArtifacts(); + assertThat(contentArtifacts, hasSize(1)); + Artifact hiv = findArtifactByArtifactId(contentArtifacts, "hiv"); + assertThat(hiv, notNullValue()); + assertThat(hiv, hasVersion("1.0.0")); + assertThat(hiv.getGroupId(), equalTo("org.openmrs.new")); + assertThat(hiv.getType(), equalTo("gzip")); + } + @Test(expected = MojoExecutionException.class) public void resolvePlaceholders_shouldFailIfNoPropertyForPlaceholderFound() throws MojoExecutionException { Properties properties = new Properties();