From 1e65133551820ce2e7318732825c04aa6643ee83 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 8 Nov 2024 12:55:28 -0500 Subject: [PATCH 1/4] SDK-344 - SDK should support including spa from a maven artifact --- .../plugins/utility/ModuleInstaller.java | 46 +++++++ .../maven/plugins/utility/SpaInstaller.java | 118 ++++++++++++------ .../plugins/utility/SpaInstallerTest.java | 48 ++++++- .../plugins/model/BaseSdkProperties.java | 23 ++-- 4 files changed, 181 insertions(+), 54 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index 07b337890..acddf1e49 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -1,6 +1,7 @@ package org.openmrs.maven.plugins.utility; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; @@ -17,6 +18,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.UUID; import static org.twdata.maven.mojoexecutor.MojoExecutor.Element; import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; @@ -56,6 +59,10 @@ public ModuleInstaller(MavenProject mavenProject, this.versionsHelper = versionsHelper; } + public ModuleInstaller(DistroHelper distroHelper) { + this(distroHelper.mavenProject, distroHelper.mavenSession, distroHelper.pluginManager, distroHelper.versionHelper); + } + public void installDefaultModules(Server server) throws MojoExecutionException { boolean isPlatform = server.getVersion() == null; // this might be always true, in which case `getCoreModules` can be simplified List coreModules = SDKConstants.getCoreModules(server.getPlatformVersion(), isPlatform); @@ -92,6 +99,45 @@ public void installModule(Artifact artifact, String outputDir) throws MojoExecut prepareModules(new Artifact[] { artifact }, outputDir, GOAL_COPY); } + /** + * @param artifact the artifact retrieve from Maven + * @param outputDir the directory into which the artifact should be unpacked + * @param include optionally allows limiting the unpacked artifacts to only those specified in the directory that matches this name + * @throws MojoExecutionException + */ + public void installAndUnpackModule(Artifact artifact, File outputDir, String include) throws MojoExecutionException { + if (!outputDir.exists()) { + throw new MojoExecutionException("Output directory does not exist: " + outputDir); + } + if (StringUtils.isBlank(include) || include.equals("/")) { + installAndUnpackModule(artifact, outputDir.getAbsolutePath()); + } + else { + File tempDir = null; + try { + tempDir = Files.createTempDirectory(artifact.getArtifactId() + "-" + UUID.randomUUID()).toFile(); + installAndUnpackModule(artifact, tempDir.getAbsolutePath()); + boolean copied = false; + for (File f : Objects.requireNonNull(tempDir.listFiles())) { + if (f.isDirectory() && f.getName().equals(include)) { + FileUtils.copyDirectory(f, outputDir); + copied = true; + break; + } + } + if (!copied) { + throw new MojoExecutionException("No directory named " + include + " exists in artifact " + artifact); + } + } + catch (IOException e) { + throw new MojoExecutionException("Unable to create temporary directory to install " + artifact); + } + finally { + FileUtils.deleteQuietly(tempDir); + } + } + } + public void installAndUnpackModule(Artifact artifact, String outputDir) throws MojoExecutionException { Path markersDirectory; try { diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java index 8efed9a5e..e1addfe16 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java @@ -5,6 +5,8 @@ import com.google.common.io.RecursiveDeleteOption; import org.apache.commons.lang.StringUtils; import org.apache.maven.plugin.MojoExecutionException; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.BaseSdkProperties; import org.openmrs.maven.plugins.model.DistroProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,13 +42,20 @@ public class SpaInstaller { private final DistroHelper distroHelper; private final ModuleInstaller moduleInstaller; + + private final Wizard wizard; private static final Logger logger = LoggerFactory.getLogger(SpaInstaller.class); public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper) { + this(distroHelper, nodeHelper, new ModuleInstaller(distroHelper), distroHelper.wizard); + } + + public SpaInstaller(DistroHelper distroHelper, NodeHelper nodeHelper, ModuleInstaller moduleInstaller, Wizard wizard) { this.distroHelper = distroHelper; - this.moduleInstaller = new ModuleInstaller(distroHelper.mavenProject, distroHelper.mavenSession, distroHelper.pluginManager, distroHelper.versionHelper); this.nodeHelper = nodeHelper; + this.moduleInstaller = moduleInstaller; + this.wizard = wizard; } /** @@ -65,16 +74,40 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro public void installFromDistroProperties(File appDataDir, DistroProperties distroProperties, boolean ignorePeerDependencies, Boolean overrideReuseNodeCache) throws MojoExecutionException { - // We find all the lines in distro properties beginning with `spa` and convert these - // into a JSON structure. This is passed to the frontend build tool. - // If no SPA elements are present in the distro properties, the SPA is not installed. - Map spaProperties = distroProperties.getSpaProperties(distroHelper, appDataDir); - // Three of these properties are not passed to the build tool, but are used to specify the build execution itself + File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR); + + // Retrieve the properties with a spa. prefix out of the distro properties + Map spaProperties = distroProperties.getSpaProperties(distroHelper, appDataDir); + + // If a maven artifact is defined, then we download the artifact and unpack it + String artifactId = spaProperties.remove(BaseSdkProperties.ARTIFACT_ID); + if (artifactId != null) { + wizard.showMessage("Found spa.artifactId in distro properties: " + artifactId); + String groupId = spaProperties.remove(BaseSdkProperties.GROUP_ID); + String version = spaProperties.remove(BaseSdkProperties.VERSION); + if (groupId == null || version == null) { + throw new MojoExecutionException("If specifying a spa.artifactId, you must also specify a spa.groupId and spa.version property"); + } + String type = spaProperties.remove(BaseSdkProperties.ARTIFACT_ID); + String includeFromArtifact = spaProperties.remove(BaseSdkProperties.INCLUDE); + Artifact artifact = new Artifact(artifactId, version, groupId, (type == null ? BaseSdkProperties.TYPE_ZIP : type)); + wizard.showMessage("Installing SPA from Maven artifact: " + artifact); + if (buildTargetDir.mkdirs()) { + wizard.showMessage("Created " + BUILD_TARGET_DIR + " directory: " + buildTargetDir.getAbsolutePath()); + } + moduleInstaller.installAndUnpackModule(artifact, buildTargetDir, includeFromArtifact); + wizard.showMessage("SPA successfully installed to " + buildTargetDir.getAbsolutePath()); + return; + } + + // If no maven artifact is defined, then check if npm build configuration is defined + + // First pull any optional properties that may be used to specify the core, node, or npm versions + // These properties are not passed to the build tool, but are used to specify the build execution itself String coreVersion = spaProperties.remove("core"); if (coreVersion == null) { coreVersion = "next"; } - String nodeVersion = spaProperties.remove("node"); if (nodeVersion == null) { nodeVersion = NODE_VERSION; @@ -83,43 +116,47 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro if (npmVersion == null) { npmVersion = NPM_VERSION; } - - if (!spaProperties.isEmpty()) { - Map spaConfigJson = convertPropertiesToJSON(spaProperties); - File spaConfigFile = new File(appDataDir, "spa-build-config.json"); - writeJSONObject(spaConfigFile, spaConfigJson); + // If there are no remaining spa properties, then no spa configuration has been provided + if (spaProperties.isEmpty()) { + wizard.showMessage("No spa configuration found in the distro properties"); + return; + } - Properties sdkProperties = getSdkProperties(); - boolean reuseNodeCache = (overrideReuseNodeCache != null) ? overrideReuseNodeCache : Boolean.parseBoolean(sdkProperties.getProperty("reuseNodeCache")); - nodeHelper.installNodeAndNpm(nodeVersion, npmVersion, reuseNodeCache); - File buildTargetDir = new File(appDataDir, BUILD_TARGET_DIR); + // If there are remaining spa properties, then build and install using node + Map spaConfigJson = convertPropertiesToJSON(spaProperties); - String program = "openmrs@" + coreVersion; - String legacyPeerDeps = ignorePeerDependencies ? "--legacy-peer-deps" : ""; - // print frontend tool version number - nodeHelper.runNpx(String.format("%s --version", program), legacyPeerDeps); - - if (distroProperties.getContentArtifacts().isEmpty()) { - nodeHelper.runNpx(String.format("%s assemble --target %s --mode config --config %s", program, buildTargetDir, - spaConfigFile), legacyPeerDeps); - } else { - List configFiles = ContentHelper.collectFrontendConfigs(distroProperties, moduleInstaller); - String assembleCommand = assembleWithFrontendConfig(program, buildTargetDir, configFiles, spaConfigFile); - nodeHelper.runNpx(assembleCommand, legacyPeerDeps); - } - nodeHelper.runNpx( - String.format("%s build --target %s --build-config %s", program, buildTargetDir, spaConfigFile), legacyPeerDeps); - - Path nodeCache = NodeHelper.tempDir; - if (!reuseNodeCache) { - try { - if (nodeCache != null && nodeCache.toFile().exists()) { - MoreFiles.deleteRecursively(nodeCache, RecursiveDeleteOption.ALLOW_INSECURE); - } - } catch (IOException e) { - logger.error("Couldn't delete the temp file", e); + File spaConfigFile = new File(appDataDir, "spa-build-config.json"); + writeJSONObject(spaConfigFile, spaConfigJson); + + Properties sdkProperties = getSdkProperties(); + boolean reuseNodeCache = (overrideReuseNodeCache != null) ? overrideReuseNodeCache : Boolean.parseBoolean(sdkProperties.getProperty("reuseNodeCache")); + nodeHelper.installNodeAndNpm(nodeVersion, npmVersion, reuseNodeCache); + + String program = "openmrs@" + coreVersion; + String legacyPeerDeps = ignorePeerDependencies ? "--legacy-peer-deps" : ""; + // print frontend tool version number + nodeHelper.runNpx(String.format("%s --version", program), legacyPeerDeps); + + if (distroProperties.getContentArtifacts().isEmpty()) { + nodeHelper.runNpx(String.format("%s assemble --target %s --mode config --config %s", program, buildTargetDir, + spaConfigFile), legacyPeerDeps); + } else { + List configFiles = ContentHelper.collectFrontendConfigs(distroProperties, moduleInstaller); + String assembleCommand = assembleWithFrontendConfig(program, buildTargetDir, configFiles, spaConfigFile); + nodeHelper.runNpx(assembleCommand, legacyPeerDeps); + } + nodeHelper.runNpx( + String.format("%s build --target %s --build-config %s", program, buildTargetDir, spaConfigFile), legacyPeerDeps); + + Path nodeCache = NodeHelper.tempDir; + if (!reuseNodeCache) { + try { + if (nodeCache != null && nodeCache.toFile().exists()) { + MoreFiles.deleteRecursively(nodeCache, RecursiveDeleteOption.ALLOW_INSECURE); } + } catch (IOException e) { + logger.error("Couldn't delete the temp file", e); } } } @@ -217,5 +254,4 @@ private static void writeJSONObject(File file, Map jsonObject) t "Exception while writing JSON to \"" + file.getAbsolutePath() + "\" " + e.getMessage(), e); } } - } diff --git a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java index b832d5c63..d87dd60e0 100644 --- a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java +++ b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java @@ -9,8 +9,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.maven.plugins.model.Artifact; +import org.openmrs.maven.plugins.model.BaseSdkProperties; import org.openmrs.maven.plugins.model.DistroProperties; import java.io.File; @@ -18,6 +21,13 @@ import java.nio.charset.StandardCharsets; import java.util.Properties; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; + @RunWith(MockitoJUnitRunner.class) public class SpaInstallerTest { @@ -26,16 +36,22 @@ public class SpaInstallerTest { @Mock DistroHelper distroHelper; + @Mock + ModuleInstaller moduleInstaller; + + @Mock + Wizard wizard; + @Mock NodeHelper nodeHelper; File appDataDir; @Before - public void setup() throws Exception{ + public void setup() throws Exception { appDataDir = new File(ResourceExtractor.simpleExtractResources(getClass(), "/test-tmp"), "server1"); appDataDir.mkdirs(); - spaInstaller = new SpaInstaller(distroHelper, nodeHelper); + spaInstaller = new SpaInstaller(distroHelper, nodeHelper, moduleInstaller, wizard); } @After @@ -62,4 +78,32 @@ public void spaInstall_shouldParseConfigUrlsCorrectly() throws MojoExecutionExce String spaConfig = FileUtils.readFileToString(spaConfigFile, StandardCharsets.UTF_8); Assert.assertThat(spaConfig, Matchers.containsString("\"configUrls\":[\"foo\",\"bar\",\"baz\"]")); } + + @Test + public void spaInstall_shouldSupportConfiguringMavenArtifact() throws MojoExecutionException { + Properties distroProperties = new Properties(); + distroProperties.setProperty("spa.artifactId", "openmrs-frontend-example"); + distroProperties.setProperty("spa.groupId", "org.openmrs.frontend"); + distroProperties.setProperty("spa.version", "1.2.3"); + spaInstaller.installFromDistroProperties(appDataDir, new DistroProperties(distroProperties)); + + String expectedOutputDir = new File(appDataDir, "frontend").getAbsolutePath(); + + ArgumentCaptor wizardMessageCaptor = ArgumentCaptor.forClass(String.class); + verify(wizard, atLeast(3)).showMessage(wizardMessageCaptor.capture()); + + ArgumentCaptor artifactCaptor = ArgumentCaptor.forClass(Artifact.class); + ArgumentCaptor targetDirectoryCaptor = ArgumentCaptor.forClass(File.class); + ArgumentCaptor sourceDirCaptor = ArgumentCaptor.forClass(String.class); + verify(moduleInstaller, times(1)).installAndUnpackModule(artifactCaptor.capture(), targetDirectoryCaptor.capture(), sourceDirCaptor.capture()); + Artifact artifact = artifactCaptor.getValue(); + assertThat(artifact.getArtifactId(), equalTo("openmrs-frontend-example")); + assertThat(artifact.getGroupId(), equalTo("org.openmrs.frontend")); + assertThat(artifact.getVersion(), equalTo("1.2.3")); + assertThat(artifact.getType(), equalTo(BaseSdkProperties.TYPE_ZIP)); + assertThat(targetDirectoryCaptor.getValue().getAbsolutePath(), equalTo(expectedOutputDir)); + + // Validate that the build and install from node process did not run + verifyNoInteractions(nodeHelper); + } } 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 768a36e6f..c5183537a 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 @@ -19,17 +19,18 @@ public abstract class BaseSdkProperties { public static final String ARTIFACT_ID = "artifactId"; public static final String TYPE = "type"; 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_CONTENT = "content"; - protected static final String TYPE_DISTRO = "distro"; - protected static final String TYPE_OWA = "owa"; - protected static final String TYPE_SPA = "spa"; - protected static final String TYPE_CONFIG = "config"; - protected static final String TYPE_ZIP = "zip"; + public static final String TYPE_OMOD = "omod"; + public static final String TYPE_WAR = "war"; + public static final String TYPE_JAR = "jar"; + public static final String NAME = "name"; + public static final String VERSION = "version"; + public static final String TYPE_CONTENT = "content"; + public static final String TYPE_DISTRO = "distro"; + public static final String TYPE_OWA = "owa"; + public static final String TYPE_SPA = "spa"; + public static final String TYPE_CONFIG = "config"; + public static final String TYPE_ZIP = "zip"; + public static final String INCLUDE = "include"; protected Properties properties; From 7c23829b4fc02111e85dd019b36f937bbab2e8b2 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 8 Nov 2024 15:37:28 -0500 Subject: [PATCH 2/4] SDK-344 - Add integration test --- .../plugins/AbstractSdkIntegrationTest.java | 4 ++-- .../maven/plugins/SetupIntegrationTest.java | 18 ++++++++++++++++++ .../openmrs-distro-spa-artifacts.properties | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIntegrationTest.java index e70d48374..3bf40e218 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/AbstractSdkIntegrationTest.java @@ -231,13 +231,13 @@ public void assertFilePresent(String... paths) { assertPathPresent(resolvedPath); } - public void assertFileContains(String regex, String... paths) throws IOException { + public void assertFileContains(String text, String... paths) throws IOException { Path resolvedPath = testDirectoryPath.toAbsolutePath(); for (String path : paths) { resolvedPath = resolvedPath.resolve(path); } String jsContents = new String(Files.readAllBytes(resolvedPath), StandardCharsets.UTF_8); - assertThat(jsContents, Matchers.containsString(regex)); + assertThat(jsContents, Matchers.containsString(text)); } public void assertPathPresent(Path path) { diff --git a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java index aa187d880..cd1a1ae20 100644 --- a/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/maven/plugins/SetupIntegrationTest.java @@ -375,6 +375,24 @@ public void setup_shouldInstallWithParentDistroSpecifiedInDistroProperties() thr assertFileNotPresent(serverId, "modules", "htmlformentry-3.3.0.omod"); } + @Test + public void setup_shouldInstallWithSpaSpecifiedAsMavenArtifacts() throws Exception{ + addTaskParam("distro", testDirectory.toString() + File.separator + "openmrs-distro-spa-artifacts.properties"); + addMockDbSettings(); + + String serverId = UUID.randomUUID().toString(); + addAnswer(serverId); + addAnswer("1044"); + addAnswer("8080"); + + executeTask("setup"); + + assertFilePresent( serverId, "openmrs-2.6.9.war"); + assertModulesInstalled(serverId, "spa-2.0.0.omod"); + assertFilePresent(serverId, "frontend", "index.html"); + assertFileContains("@openmrs/esm-dispensing-app", serverId, "frontend", "importmap.json"); + } + private String readValueFromPropertyKey(File propertiesFile, String key) throws Exception { InputStream in = new FileInputStream(propertiesFile); diff --git a/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties b/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties new file mode 100644 index 000000000..5bf454faf --- /dev/null +++ b/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties @@ -0,0 +1,13 @@ +name=Spa Artifact Example +version=1.0.0-SNAPSHOT + +war.openmrs=2.6.9 + +omod.spa=2.0.0 + +spa.artifactId=openmrs-frontend-zl +spa.groupId=org.pih.openmrs +spa.version=1.3.0 +spa.include=openmrs-frontend-zl-1.3.0 + +db.h2.supported=false From e123955c69bf96b037794143011e56b4963778be Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Mon, 11 Nov 2024 09:04:58 -0500 Subject: [PATCH 3/4] SDK-344 - Update name to includes --- .../integration-test/openmrs-distro-spa-artifacts.properties | 2 +- .../java/org/openmrs/maven/plugins/utility/SpaInstaller.java | 4 ++-- .../org/openmrs/maven/plugins/utility/SpaInstallerTest.java | 4 ++-- .../org/openmrs/maven/plugins/model/BaseSdkProperties.java | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties b/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties index 5bf454faf..0e817316c 100644 --- a/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties +++ b/integration-tests/src/test/resources/integration-test/openmrs-distro-spa-artifacts.properties @@ -8,6 +8,6 @@ omod.spa=2.0.0 spa.artifactId=openmrs-frontend-zl spa.groupId=org.pih.openmrs spa.version=1.3.0 -spa.include=openmrs-frontend-zl-1.3.0 +spa.includes=openmrs-frontend-zl-1.3.0 db.h2.supported=false diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java index e1addfe16..b465d398b 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/SpaInstaller.java @@ -89,13 +89,13 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro throw new MojoExecutionException("If specifying a spa.artifactId, you must also specify a spa.groupId and spa.version property"); } String type = spaProperties.remove(BaseSdkProperties.ARTIFACT_ID); - String includeFromArtifact = spaProperties.remove(BaseSdkProperties.INCLUDE); + String includes = spaProperties.remove(BaseSdkProperties.INCLUDES); Artifact artifact = new Artifact(artifactId, version, groupId, (type == null ? BaseSdkProperties.TYPE_ZIP : type)); wizard.showMessage("Installing SPA from Maven artifact: " + artifact); if (buildTargetDir.mkdirs()) { wizard.showMessage("Created " + BUILD_TARGET_DIR + " directory: " + buildTargetDir.getAbsolutePath()); } - moduleInstaller.installAndUnpackModule(artifact, buildTargetDir, includeFromArtifact); + moduleInstaller.installAndUnpackModule(artifact, buildTargetDir, includes); wizard.showMessage("SPA successfully installed to " + buildTargetDir.getAbsolutePath()); return; } diff --git a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java index d87dd60e0..24457422a 100644 --- a/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java +++ b/maven-plugin/src/test/java/org/openmrs/maven/plugins/utility/SpaInstallerTest.java @@ -94,8 +94,8 @@ public void spaInstall_shouldSupportConfiguringMavenArtifact() throws MojoExecut ArgumentCaptor artifactCaptor = ArgumentCaptor.forClass(Artifact.class); ArgumentCaptor targetDirectoryCaptor = ArgumentCaptor.forClass(File.class); - ArgumentCaptor sourceDirCaptor = ArgumentCaptor.forClass(String.class); - verify(moduleInstaller, times(1)).installAndUnpackModule(artifactCaptor.capture(), targetDirectoryCaptor.capture(), sourceDirCaptor.capture()); + ArgumentCaptor includesCaptor = ArgumentCaptor.forClass(String.class); + verify(moduleInstaller, times(1)).installAndUnpackModule(artifactCaptor.capture(), targetDirectoryCaptor.capture(), includesCaptor.capture()); Artifact artifact = artifactCaptor.getValue(); assertThat(artifact.getArtifactId(), equalTo("openmrs-frontend-example")); assertThat(artifact.getGroupId(), equalTo("org.openmrs.frontend")); 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 c5183537a..2bd8090ce 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 @@ -30,7 +30,7 @@ public abstract class BaseSdkProperties { public static final String TYPE_SPA = "spa"; public static final String TYPE_CONFIG = "config"; public static final String TYPE_ZIP = "zip"; - public static final String INCLUDE = "include"; + public static final String INCLUDES = "includes"; protected Properties properties; From caa1951013c9bca5714aecc3e1129078532a8080 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Mon, 11 Nov 2024 09:08:59 -0500 Subject: [PATCH 4/4] SDK-344 - Update name to includes --- .../openmrs/maven/plugins/utility/ModuleInstaller.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java index acddf1e49..e3aa948a6 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/utility/ModuleInstaller.java @@ -102,14 +102,14 @@ public void installModule(Artifact artifact, String outputDir) throws MojoExecut /** * @param artifact the artifact retrieve from Maven * @param outputDir the directory into which the artifact should be unpacked - * @param include optionally allows limiting the unpacked artifacts to only those specified in the directory that matches this name + * @param includes optionally allows limiting the unpacked artifacts to only those specified in the directory that matches this name * @throws MojoExecutionException */ - public void installAndUnpackModule(Artifact artifact, File outputDir, String include) throws MojoExecutionException { + public void installAndUnpackModule(Artifact artifact, File outputDir, String includes) throws MojoExecutionException { if (!outputDir.exists()) { throw new MojoExecutionException("Output directory does not exist: " + outputDir); } - if (StringUtils.isBlank(include) || include.equals("/")) { + if (StringUtils.isBlank(includes)) { installAndUnpackModule(artifact, outputDir.getAbsolutePath()); } else { @@ -119,14 +119,14 @@ public void installAndUnpackModule(Artifact artifact, File outputDir, String inc installAndUnpackModule(artifact, tempDir.getAbsolutePath()); boolean copied = false; for (File f : Objects.requireNonNull(tempDir.listFiles())) { - if (f.isDirectory() && f.getName().equals(include)) { + if (f.isDirectory() && f.getName().equals(includes)) { FileUtils.copyDirectory(f, outputDir); copied = true; break; } } if (!copied) { - throw new MojoExecutionException("No directory named " + include + " exists in artifact " + artifact); + throw new MojoExecutionException("No directory named " + includes + " exists in artifact " + artifact); } } catch (IOException e) {