Skip to content

Commit

Permalink
O3-3424: Distro Inheritance Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith authored Jul 22, 2024
1 parent 45ecd80 commit 59df400
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void initTask() {
moduleInstaller = new ModuleInstaller(mavenProject, mavenSession, pluginManager, versionsHelper);
}
if (distroHelper == null) {
distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard);
distroHelper = new DistroHelper(mavenProject, mavenSession, pluginManager, wizard, versionsHelper);
}
if (owaHelper == null) {
owaHelper = new OwaHelper(mavenSession, mavenProject, pluginManager, wizard);
Expand Down
49 changes: 17 additions & 32 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.openmrs.maven.plugins.model.Artifact;
import org.openmrs.maven.plugins.model.BaseSdkProperties;
import org.openmrs.maven.plugins.model.DistroProperties;
import org.openmrs.maven.plugins.model.Server;
import org.openmrs.maven.plugins.model.Version;
import org.openmrs.maven.plugins.utility.DBConnector;
import org.openmrs.maven.plugins.utility.DistroHelper;
import org.openmrs.maven.plugins.utility.PropertiesUtils;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.openmrs.maven.plugins.utility.ServerHelper;

import static org.openmrs.maven.plugins.model.BaseSdkProperties.PROPERTY_DISTRO_ARTIFACT_ID;
import static org.openmrs.maven.plugins.model.BaseSdkProperties.PROPERTY_DISTRO_GROUP_ID;

/**
* Set up a new instance of OpenMRS server. It can be used for setting up a platform or a distribution. It prompts for any missing, but required parameters.
Expand Down Expand Up @@ -216,38 +212,27 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper);
Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(),
server.getDistroGroupId(), "zip");
Properties frontendProperties;
if (new Version(server.getVersion()).higher(new Version("3.0.0-beta.16"))) {
frontendProperties = distroHelper.getFrontendProperties(server);
} else {
frontendProperties = PropertiesUtils.getFrontendPropertiesFromSpaConfigUrl(
"https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/"+ server.getVersion() +"/frontend/spa-build-config.json");
}

Properties configurationProperties = PropertiesUtils.getConfigurationProperty(artifact);
File file = distroHelper.downloadDistro(server.getServerDirectory(), artifact);
Properties backendProperties = PropertiesUtils.getDistroProperties(file);
Properties spaModuleProperty = PropertiesUtils.getModuleProperty("https://raw.githubusercontent.com/openmrs/openmrs-module-spa/master/pom.xml");

if(appShellVersion != null) {
frontendProperties.setProperty("spa.core", appShellVersion);
}

Properties allProperties = new Properties();
allProperties.putAll(backendProperties);
allProperties.putAll(spaModuleProperty);
allProperties.putAll(frontendProperties);
allProperties.putAll(configurationProperties);
allProperties.put(PROPERTY_DISTRO_GROUP_ID, artifact.getGroupId());
allProperties.put(PROPERTY_DISTRO_ARTIFACT_ID, artifact.getArtifactId());
distroProperties = new DistroProperties(allProperties);
distroProperties = new DistroProperties(distroHelper.getArtifactProperties(artifact, server, appShellVersion));
platformMode = false;
break;

default: // distro properties from current directory
server.setPlatformVersion(
distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory()));
server.setVersion(distroProperties.getVersion());
Artifact distroArtifact = distroProperties.getParentArtifact();
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) {
server.setDistroArtifactId(distroArtifact.getArtifactId());
server.setDistroGroupId(distroArtifact.getGroupId());
server.setVersion(distroArtifact.getVersion());
Properties properties = distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion);
for (Object key : distroProperties.getAllKeys()) {
String keyStr = (String) key;
properties.setProperty(keyStr, distroProperties.getParam(keyStr));
}
distroProperties = new DistroProperties(properties);
} else {
server.setPlatformVersion(
distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory()));
server.setVersion(distroProperties.getVersion());
}
platformMode = false;
}
} else if (platform != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.openmrs.maven.plugins.utility.DistroHelper;
import org.slf4j.Logger;
Expand Down Expand Up @@ -118,6 +119,33 @@ public Artifact getDistroArtifact() {
return null;
}

public Artifact getParentArtifact() {
String parentArtifactId = getParam("parent.artifactId");
String parentGroupId = getParam("parent.groupId");
String parentVersion = getParam("parent.version");

int missingCount = 0;
if (StringUtils.isBlank(parentArtifactId)) {
log.warn("parent.artifactId missing");
missingCount++;
}
if (StringUtils.isBlank(parentGroupId)) {
log.warn("parent.groupId is missing");
missingCount++;
}
if (StringUtils.isBlank(parentVersion)) {
log.warn("parent.version is missing");
missingCount++;
}

// We are only going to throw an error if only one or two parameters are missing
if (missingCount > 0 && missingCount < 3) {
throw new IllegalArgumentException("Missing arguments for the parent");
}

return new Artifact(parentArtifactId, parentVersion, parentGroupId, "zip");
}

public List<Artifact> getModuleArtifacts(DistroHelper distroHelper, File directory) throws MojoExecutionException {
List<Artifact> childArtifacts = getModuleArtifacts();
List<Artifact> parentArtifacts = new ArrayList<>();
Expand Down Expand Up @@ -230,6 +258,10 @@ public void resolvePlaceholders(Properties projectProperties) throws MojoExecuti
}
}

public Set<Object> getAllKeys() {
return properties.keySet();
}

private String getPlaceholderKey(String string){
int startIndex = string.indexOf("${")+2;
int endIndex = string.indexOf("}", startIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import static org.openmrs.maven.plugins.model.BaseSdkProperties.PROPERTY_DISTRO_ARTIFACT_ID;
import static org.openmrs.maven.plugins.model.BaseSdkProperties.PROPERTY_DISTRO_GROUP_ID;
import static org.twdata.maven.mojoexecutor.MojoExecutor.*;

public class DistroHelper {
Expand All @@ -44,12 +46,15 @@ public class DistroHelper {
*/
final Wizard wizard;

final VersionsHelper versionHelper;

public DistroHelper(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager,
Wizard wizard) {
Wizard wizard, VersionsHelper versionHelper) {
this.mavenProject = mavenProject;
this.mavenSession = mavenSession;
this.pluginManager = pluginManager;
this.wizard = wizard;
this.versionHelper = versionHelper;
}

/**
Expand Down Expand Up @@ -488,4 +493,28 @@ public Properties getFrontendProperties(Server server) throws MojoExecutionExcep
return frontendProperties;
}

public Properties getFrontendPropertiesForServer(Server server) throws MojoExecutionException {
if (new Version(server.getVersion()).higher(new Version("3.0.0-beta.16"))) {
return getFrontendProperties(server);
} else {
return PropertiesUtils.getFrontendPropertiesFromSpaConfigUrl(
"https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/" + server.getVersion() + "/frontend/spa-build-config.json");
}
}

public Properties getArtifactProperties(Artifact artifact, Server server, String appShellVersion) throws MojoExecutionException {
File file = downloadDistro(server.getServerDirectory(), artifact);
Properties properties = new Properties();
properties.putAll(PropertiesUtils.getDistroProperties(file));
properties.putAll(getFrontendPropertiesForServer(server));
properties.putAll(PropertiesUtils.getConfigurationProperty(artifact));
properties.put(PROPERTY_DISTRO_GROUP_ID, artifact.getGroupId());
properties.put(PROPERTY_DISTRO_ARTIFACT_ID, artifact.getArtifactId());
if(appShellVersion != null) {
properties.setProperty("spa.core", appShellVersion);
}
properties.setProperty("omod.spa", versionHelper.getLatestSnapshotVersion(new Artifact("spa", "latest")));
return properties;
}

}

0 comments on commit 59df400

Please sign in to comment.