Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public void downloadArtifact_shouldFailIfNoArtifactIsFound() throws Exception {
artifactHelper.downloadArtifact(artifact, getMavenTestDirectory(), false);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.openmrs.maven.plugins.utility.SDKConstants.REFAPP_2X_PROMPT;
import static org.openmrs.maven.plugins.utility.SDKConstants.REFAPP_3X_PROMPT;
Expand Down Expand Up @@ -73,6 +75,8 @@ public class BuildDistro extends AbstractTask {

private static final String DOCKER_COMPOSE_OVERRIDE_YML = "docker-compose.override.yml";

private static final String MODULE_CONFIG_URI = "omod/src/main/resources/config.xml";

private static final Logger log = LoggerFactory.getLogger(BuildDistro.class);

/**
Expand Down Expand Up @@ -121,6 +125,14 @@ public class BuildDistro extends AbstractTask {
@Parameter(property = "appShellVersion")
private String appShellVersion;

/**
* Comma seperated string of additional modules artefacts in the
* form groupId:artifactId:version or artifactId:version if the
* groupId is either org.openmrs.module or org.openmrs
*/
@Parameter(defaultValue = "org.openmrs.module:legacyui-omod:1.16.0", property = "includeModules")
private String includeModules;

@Override
public void executeTask() throws MojoExecutionException, MojoFailureException {
File buildDirectory = getBuildDirectory();
Expand All @@ -136,6 +148,18 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
wizard.showMessage("Building distribution from the distro file at " + distroFile + "...\n");
distribution = builder.buildFromFile(distroFile);
}
else if (Project.hasProject(userDir) && new File(userDir, MODULE_CONFIG_URI).exists() || StringUtils.isNotBlank(includeModules)) {
List<Artifact> modules = Arrays.stream(includeModules.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(this::parseArtifact)
.collect(Collectors.toList());
if (Project.hasProject(userDir)) {
Project project = Project.loadProject(userDir);
modules.add(new Artifact(project.getArtifactId(), project.getVersion(), project.getGroupId()));
}
distribution = builder.buildFromModuleArtifacts(modules.toArray(new Artifact[0]));
}
else if (Project.hasProject(userDir)) {
wizard.showMessage("Building distribution from the source at " + userDir + "...\n");
Project config = Project.loadProject(userDir);
Expand Down Expand Up @@ -223,8 +247,9 @@ private File getBuildDirectory() throws MojoExecutionException {

private void deleteDistroFiles(File targetDir) {
try {
FileUtils.deleteDirectory(new File(targetDir, "modules"));
new File(targetDir, OPENMRS_WAR).delete();
FileUtils.deleteDirectory(new File(targetDir, "openmrs_modules"));
FileUtils.deleteDirectory(new File(targetDir, "openmrs_core"));
new File(targetDir, "openmrs.war").delete();
new File(targetDir, OPENMRS_DISTRO_PROPERTIES).delete();
}
catch (IOException e) {
Expand Down Expand Up @@ -313,8 +338,20 @@ private String buildDistro(File targetDirectory, Distribution distribution) thro
new File(web, "openmrs.war").renameTo(new File(openmrsCoreDir, "openmrs.war"));
new File(web, "modules").renameTo(new File(web, "openmrs_modules"));
new File(web, "frontend").renameTo(new File(web, "openmrs_spa"));
if (!new File(web, "openmrs_spa").exists()) {
// create it because docker needs it pre-created
new File(web, "openmrs_spa").mkdir();
}
new File(web, "configuration").renameTo(new File(web, "openmrs_config"));
if (!new File(web, "openmrs_config").exists()) {
// create it because docker needs it pre-created
new File(web, "openmrs_config").mkdir();
}
new File(web, "owa").renameTo(new File(web, "openmrs_owas"));
if (!new File(web, "openmrs_owas").exists()) {
// create it because docker needs it pre-created
new File(web, "openmrs_owas").mkdir();
}
}

wizard.showMessage("Creating Docker Compose configuration...\n");
Expand Down Expand Up @@ -550,4 +587,23 @@ public boolean accept(File dir, String name) {
}
}
}

private Artifact parseArtifact(String spec) {
String[] parts = spec.split(":");
String groupId, artifactId, version;

if (parts.length == 3) {
groupId = parts[0];
artifactId = parts[1];
version = parts[2];
} else if (parts.length == 2) {
groupId = Artifact.GROUP_MODULE;
artifactId = parts[0];
version = parts[1];
} else {
throw new IllegalArgumentException("Invalid artifact format: " + spec);
}

return new Artifact(artifactId, version, groupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FROM openmrs/openmrs-core:nightly-amazoncorretto-11
COPY openmrs_core/openmrs.war /openmrs/distribution/openmrs_core/
COPY openmrs-distro.properties /openmrs/distribution/
COPY openmrs_modules /openmrs/distribution/openmrs_modules
RUN rm -rf /openmrs/distribution/openmrs_modules/*
COPY openmrs_owas /openmrs/distribution/openmrs_owas
COPY openmrs_config /openmrs/distribution/openmrs_config
COPY openmrs_spa /openmrs/distribution/openmrs_spa
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FROM openmrs/openmrs-core:nightly-amazoncorretto-8

COPY openmrs_core/openmrs.war /openmrs/distribution/openmrs_core/
COPY openmrs-distro.properties /openmrs/distribution/
RUN rm -rf /openmrs/distribution/openmrs_modules/*
COPY openmrs_modules /openmrs/distribution/openmrs_modules
COPY openmrs_owas /openmrs/distribution/openmrs_owas
COPY openmrs_config /openmrs/distribution/openmrs_config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;
import java.util.Objects;
import java.util.Properties;

Expand Down Expand Up @@ -202,4 +203,12 @@ protected Distribution populateDistributionFromProperties(Distribution distribut
distribution.setEffectiveProperties(new DistroProperties(effectiveProperties));
return distribution;
}

public Distribution buildFromModuleArtifacts(Artifact ...modules) throws MojoExecutionException {
Distribution distribution = new Distribution();
ModuleBasedDistroHelper moduleBasedDistroHelper = new ModuleBasedDistroHelper(mavenEnvironment);
Properties properties = moduleBasedDistroHelper.generateDitributionPropertiesFromModules(modules);
distribution.setEffectiveProperties(new DistroProperties(properties));
return distribution;
}
}
Loading