Skip to content

Commit

Permalink
O3-3512: SDK should handle reading dependencies from content.properti…
Browse files Browse the repository at this point in the history
…es and ensuring they are part of the distro (#280)
  • Loading branch information
mherman22 authored Sep 6, 2024
1 parent f4aad32 commit 34fc8ae
Show file tree
Hide file tree
Showing 12 changed files with 443 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ spa.frontendModules.@openmrs/esm-login-app=3.3.1
spa.frontendModules.@openmrs/esm-patient-chart-app=3.1.0
spa.apiUrl=notopenmrs
spa.configUrls=foo
content.hiv=1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.openmrs.maven.plugins.model.Artifact;
import org.openmrs.maven.plugins.model.DistroProperties;
import org.openmrs.maven.plugins.model.Project;
import org.openmrs.maven.plugins.model.Server;
import org.openmrs.maven.plugins.model.Version;
import org.openmrs.maven.plugins.utility.DistroHelper;
import org.openmrs.maven.plugins.model.Project;
import org.openmrs.maven.plugins.utility.SDKConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -195,6 +192,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
throw new MojoExecutionException("The distro you specified, '" + distro + "' could not be retrieved");
}

distroHelper.parseContentProperties(distroProperties);
String distroName = buildDistro(buildDirectory, distroArtifact, distroProperties);

wizard.showMessage(
Expand Down Expand Up @@ -510,7 +508,7 @@ private void copyDbDump(File targetDirectory, InputStream stream) throws MojoExe
}

try (FileWriter writer = new FileWriter(dbDump);
BufferedInputStream bis = new BufferedInputStream(stream)) {
BufferedInputStream bis = new BufferedInputStream(stream)) {
writer.write(DUMP_PREFIX);

int c;
Expand Down
39 changes: 20 additions & 19 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package org.openmrs.maven.plugins;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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.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.SDKConstants;
import org.openmrs.maven.plugins.utility.ServerHelper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand All @@ -20,25 +39,6 @@
import java.util.List;
import java.util.Objects;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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.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.SDKConstants;
import org.openmrs.maven.plugins.utility.ServerHelper;


/**
* 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 @@ -276,6 +276,7 @@ public void setup(Server server, DistroProperties distroProperties) throws MojoE
// `setServerVersionsFromDistroProperties`, and `server.setValuesFromDistroPropertiesModules`.
distroHelper.savePropertiesToServer(distroProperties, server);
setServerVersionsFromDistroProperties(server, distroProperties);
distroHelper.parseContentProperties(distroProperties);
moduleInstaller.installModulesForDistro(server, distroProperties, distroHelper);
setConfigFolder(server, distroProperties);
if (spaInstaller != null) {
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@
<version>0.10.2</version>
</dependency>

<dependency>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
<version>5.3.0</version>
</dependency>

<!-- console input and output -->
<dependency>
<groupId>org.jline</groupId>
Expand Down
5 changes: 5 additions & 0 deletions sdk-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>java-semver</artifactId>
</dependency>

<dependency>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
</dependency>

<!-- TODO: Get rid of this... just using for URLBuilder -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Artifact {
public static final String GROUP_MODULE = "org.openmrs.module";
public static final String GROUP_OWA = "org.openmrs.owa";
public static final String GROUP_WEB = "org.openmrs.web";
public static final String GROUP_CONTENT = "org.openmrs.content";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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";
protected static final String TYPE = "type";
protected static final String GROUP_ID = "groupId";
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";
Expand Down Expand Up @@ -179,34 +180,36 @@ protected String checkIfOverwritten(String key, String param) {
} else {
switch (param) {
case ARTIFACT_ID:
return extractArtifactId(key);
return extractArtifactId(key);
case GROUP_ID:
switch (getArtifactType(key)) {
case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId
return Artifact.GROUP_WEB;
case TYPE_OMOD:
return Artifact.GROUP_MODULE;
case TYPE_DISTRO:
case TYPE_CONFIG:
return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO);
default:
return "";
}

switch (getArtifactType(key)) {
case TYPE_WAR: //for openmrs.war use org.openmrs.web groupId
return Artifact.GROUP_WEB;
case TYPE_OMOD:
return Artifact.GROUP_MODULE;
case TYPE_DISTRO:
case TYPE_CONFIG:
return properties.getProperty(PROPERTY_DISTRO_GROUP_ID, Artifact.GROUP_DISTRO);
case TYPE_CONTENT:
return Artifact.GROUP_CONTENT;
default:
return "";
}
case TYPE:
switch (getArtifactType(key)) {
case TYPE_OMOD:
case TYPE_DISTRO:
return TYPE_JAR;
case TYPE_WAR:
return TYPE_WAR;
case TYPE_CONFIG:
return TYPE_ZIP;
default:
return "";
}
switch (getArtifactType(key)) {
case TYPE_OMOD:
case TYPE_DISTRO:
return TYPE_JAR;
case TYPE_WAR:
return TYPE_WAR;
case TYPE_CONFIG:
case TYPE_CONTENT:
return TYPE_ZIP;
default:
return "";
}
default:
return "";
return "";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.openmrs.maven.plugins.model;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;
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;
Expand All @@ -21,6 +18,9 @@
import java.util.Properties;
import java.util.Set;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;
import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource;

/**
*
*/
Expand Down Expand Up @@ -312,4 +312,37 @@ private boolean hasPlaceholder(Object object){
int index = asString.indexOf("{");
return index != -1 && asString.substring(index).contains("}");
}

public boolean contains(String propertyName) {
return properties.containsKey(propertyName);
}

/**
* Adds a dependency with the specified version to the properties.
*
* @param dependency The name of the dependency.
* @param version The version of the dependency.
*/
public void add(String dependency, String version) {
if (StringUtils.isBlank(dependency) || StringUtils.isBlank(version)) {
log.error("Dependency name or version cannot be blank");
return;
}

if (dependency.startsWith("omod.") || dependency.startsWith("owa.") || dependency.startsWith("war")
|| dependency.startsWith("spa.frontendModule")) {
properties.setProperty(dependency, version);
log.info("Added dependency: {} with version: {}", dependency, version);
}
}

public String get(String contentDependencyKey) {
return properties.getProperty(contentDependencyKey);
}

@Override
public String checkIfOverwritten(String key, String param) {
return super.checkIfOverwritten(key, param);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,7 @@ private Map<String, String> getDistroVersionsOptionsMap(Set<String> versions, Ve
* @param optionTemplate The template for generating option keys in the map.
* @return A LinkedHashMap containing the generated options map.
*/
private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelper,
String optionTemplate) {
private Map<String, String> getO3VersionsOptionsMap(VersionsHelper versionsHelper, String optionTemplate) {
Map<String, String> optionsMap = new LinkedHashMap<>();

{
Expand Down
Loading

0 comments on commit 34fc8ae

Please sign in to comment.