diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.java index 42ea9c91..b6c41a23 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.java @@ -52,11 +52,11 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { DistroProperties parentProperties = distribution.getParent().getEffectiveProperties(); if (StringUtils.isBlank(property)) { List currentExclusions = distribution.getProperties().getExclusions(); - List options = parentProperties.getPropertyNames().stream().filter(prop -> !currentExclusions.contains(prop)).collect(Collectors.toList()); + List options = parentProperties.getAllKeys().stream().filter(prop -> !currentExclusions.contains(prop)).collect(Collectors.toList()); property = wizard.promptForMissingValueWithOptions("Enter the property you want to exclude", null, null, options); } else { - if (!parentProperties.getPropertyNames().contains(property)) { + if (!parentProperties.getAllKeys().contains(property)) { wizard.showWarning(WARNING_PROPERTY_NOT_IN_PARENT); } } diff --git a/maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java b/maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java index 41c35b8a..1e7cde53 100644 --- a/maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java +++ b/maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java @@ -51,7 +51,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException { if (StringUtils.isBlank(property)) { property = wizard.promptForMissingValueWithOptions("Enter the property you want to remove", - null, null, new ArrayList<>(properties.getPropertyNames())); + null, null, new ArrayList<>(properties.getAllKeys())); } if (StringUtils.isNotBlank(property)) { 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 a4d22505..779bfa99 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 @@ -10,9 +10,6 @@ import java.util.Properties; import java.util.Set; -/** - * - */ public abstract class BaseSdkProperties { public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId"; @@ -37,38 +34,6 @@ public abstract class BaseSdkProperties { protected Properties properties; - public Properties getModuleAndWarProperties(List warArtifacts, List moduleArtifacts) { - Properties properties = new Properties(); - for (Artifact artifact : warArtifacts) { - - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_WAR)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - - if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) { - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion()); - } - - for (Artifact artifact : moduleArtifacts) { - stripArtifactId(artifact); - - if (!artifact.getType().equals(TYPE_JAR)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType()); - } - if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) { - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId()); - } - - properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion()); - } - return properties; - } - public String getPlatformVersion(){ return getParam("war.openmrs"); } @@ -95,8 +60,7 @@ public void setName(String name) { public List getModuleArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); + for (String key: getAllKeys()) { String artifactType = getArtifactType(key); if(artifactType.equals(TYPE_OMOD)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod")); @@ -107,8 +71,7 @@ public List getModuleArtifacts() { public List getOwaArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { String artifactType = getArtifactType(key); if(artifactType.equals(TYPE_OWA)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); @@ -119,8 +82,7 @@ public List getOwaArtifacts() { public Map getSpaProperties() { Map spaProperties = new HashMap<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { if (key.startsWith(TYPE_SPA + ".")) { spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key)); } @@ -155,8 +117,7 @@ public List getSpaArtifacts() { public List getWarArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { String artifactType = getArtifactType(key); if(artifactType.equals(TYPE_WAR)) { artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE))); @@ -167,8 +128,7 @@ public List getWarArtifacts() { public List getConfigArtifacts() { List artifactList = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { String artifactType = getArtifactType(key); if (artifactType.equals(TYPE_CONFIG)) { artifactList.add( @@ -181,8 +141,7 @@ public List getConfigArtifacts() { public List getContentArtifacts() { List artifacts = new ArrayList<>(); - for (Object keyObject : getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { String artifactType = getArtifactType(key); if (artifactType.equals(TYPE_CONTENT)) { artifacts.add(new Artifact( @@ -196,14 +155,22 @@ public List getContentArtifacts() { return artifacts; } - protected Set getAllKeys() { - return properties.keySet(); + public Set getAllKeys() { + return properties.stringPropertyNames(); } public Properties getAllProperties() { return properties; } + public void addProperty(String property, String value) { + properties.put(property, value); + } + + public boolean contains(String propertyName) { + return properties.containsKey(propertyName); + } + 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))){ @@ -386,19 +353,19 @@ private void setCustomModuleType(Artifact artifact){ properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType()); } - private void setCustomModuleGroupId(Artifact artifact){ + private void setCustomModuleGroupId(Artifact artifact) { properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId()); } - public void synchronize(BaseSdkProperties other){ - for(Object key: getAllKeys()){ - if (isBaseSdkProperty(key.toString())) { + public void synchronize(BaseSdkProperties other) { + for(String key : getAllKeys()){ + if (isBaseSdkProperty(key)) { other.properties.put(key, properties.get(key)); } } - for(Object key: new ArrayList<>(other.getAllKeys())){ - if(isBaseSdkProperty(key.toString())){ - if(StringUtils.isBlank(getParam(key.toString()))){ + for(String key : new ArrayList<>(other.getAllKeys())) { + if(isBaseSdkProperty(key)){ + if(StringUtils.isBlank(getParam(key))) { other.properties.remove(key); } } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java index adfe1ff9..fee68e35 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java @@ -5,8 +5,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.openmrs.maven.plugins.utility.DistroHelper; import org.openmrs.maven.plugins.utility.PropertiesUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileOutputStream; @@ -20,20 +18,14 @@ import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile; -/** - * - */ public class DistroProperties extends BaseSdkProperties { public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt"; - private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties"; public static final String DISTRO_FILE_NAME = "openmrs-distro.properties"; private static final String DB_SQL = "db.sql"; public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default"; public static final String PROPERTY_KEY = "property.%s"; - private static final Logger log = LoggerFactory.getLogger(DistroProperties.class); - public DistroProperties(String name, String platformVersion){ properties = new Properties(); setName(name); @@ -76,9 +68,9 @@ public String getPropertyValue(String propertyName){ public Set getPropertiesNames(){ Set propertiesNames = new HashSet<>(); - for(Object key: getAllKeys()){ - if(key.toString().startsWith("property.")){ - propertiesNames.add(extractPropertyName(key.toString())); + for(String key : getAllKeys()){ + if(key.startsWith("property.")){ + propertiesNames.add(extractPropertyName(key)); } } return propertiesNames; @@ -113,8 +105,7 @@ private String extractPropertyName(String key) { */ public Artifact getParentDistroArtifact() throws MojoExecutionException { Artifact artifact = null; - for (Object keyObject: getAllKeys()) { - String key = keyObject.toString(); + for (String key : getAllKeys()) { String artifactType = getArtifactType(key); if (artifactType.equals(TYPE_DISTRO)) { String artifactId = checkIfOverwritten(key, ARTIFACT_ID); @@ -166,10 +157,6 @@ public void resolvePlaceholders(Properties projectProperties) throws MojoExecuti PropertiesUtils.resolvePlaceholders(properties, projectProperties); } - public Set getAllKeys() { - return properties.keySet(); - } - public List getExclusions() { String exclusions = getParam("exclusions"); if(exclusions == null) { @@ -178,10 +165,6 @@ public List getExclusions() { return Arrays.asList(exclusions.split(",")); } - public Set getPropertyNames() { - return properties.stringPropertyNames(); - } - public void removeProperty(String property) throws MojoExecutionException { if (!properties.containsKey(property)) { throw new MojoExecutionException("The property " + property + " was not found in the distro"); @@ -198,41 +181,4 @@ public void addExclusion(String exclusion) { properties.setProperty("exclusions", exclusions + "," + exclusion); } - - public void addProperty(String property, String value) throws MojoExecutionException { - properties.put(property, value); - } - - 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); - } - } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java index 6510e647..81754421 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java @@ -581,8 +581,7 @@ public String getArtifactId(String filename) { public void setValuesFromDistroProperties(DistroProperties distroProperties) { if (distroProperties != null) { - for (Object property : distroProperties.getAllKeys()) { - String key = property.toString(); + for (String key : distroProperties.getAllKeys()) { if (distroProperties.isBaseSdkProperty(key)) { this.properties.put(key, distroProperties.getParam(key)); } 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 2536b166..3b12eb83 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 @@ -443,7 +443,7 @@ protected void processContentProperties(Properties contentProperties, DistroProp if (dependency.startsWith("omod.") || dependency.startsWith("owa.") || dependency.startsWith("war") || dependency.startsWith("spa.frontendModule") || dependency.startsWith("content.")) { String versionRange = contentProperties.getProperty(dependency); - String distroVersion = distroProperties.get(dependency); + String distroVersion = distroProperties.getParam(dependency); if (distroVersion == null) { String latestVersion = findLatestMatchingVersion(dependency, versionRange); @@ -451,7 +451,8 @@ protected void processContentProperties(Properties contentProperties, DistroProp throw new MojoExecutionException( "No matching version found for dependency " + dependency + " in " + zipFileName); } - distroProperties.add(dependency, latestVersion); + + distroProperties.addProperty(dependency, latestVersion); } else { checkVersionInRange(dependency, versionRange, distroVersion, contentProperties.getProperty("name")); }