Skip to content

Commit 1a30407

Browse files
committed
(refactor) Clean up unused and duplicate methods
1 parent 611db9f commit 1a30407

File tree

6 files changed

+34
-121
lines changed

6 files changed

+34
-121
lines changed

maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
5252
DistroProperties parentProperties = distribution.getParent().getEffectiveProperties();
5353
if (StringUtils.isBlank(property)) {
5454
List<String> currentExclusions = distribution.getProperties().getExclusions();
55-
List<String> options = parentProperties.getPropertyNames().stream().filter(prop -> !currentExclusions.contains(prop)).collect(Collectors.toList());
55+
List<String> options = parentProperties.getAllKeys().stream().filter(prop -> !currentExclusions.contains(prop)).collect(Collectors.toList());
5656
property = wizard.promptForMissingValueWithOptions("Enter the property you want to exclude", null, null, options);
5757
}
5858
else {
59-
if (!parentProperties.getPropertyNames().contains(property)) {
59+
if (!parentProperties.getAllKeys().contains(property)) {
6060
wizard.showWarning(WARNING_PROPERTY_NOT_IN_PARENT);
6161
}
6262
}

maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
5151

5252
if (StringUtils.isBlank(property)) {
5353
property = wizard.promptForMissingValueWithOptions("Enter the property you want to remove",
54-
null, null, new ArrayList<>(properties.getPropertyNames()));
54+
null, null, new ArrayList<>(properties.getAllKeys()));
5555
}
5656

5757
if (StringUtils.isNotBlank(property)) {

sdk-commons/src/main/java/org/openmrs/maven/plugins/model/BaseSdkProperties.java

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import java.util.Properties;
1111
import java.util.Set;
1212

13-
/**
14-
*
15-
*/
1613
public abstract class BaseSdkProperties {
1714

1815
public static final String PROPERTY_DISTRO_ARTIFACT_ID = "distro.artifactId";
@@ -37,38 +34,6 @@ public abstract class BaseSdkProperties {
3734

3835
protected Properties properties;
3936

40-
public Properties getModuleAndWarProperties(List<Artifact> warArtifacts, List<Artifact> moduleArtifacts) {
41-
Properties properties = new Properties();
42-
for (Artifact artifact : warArtifacts) {
43-
44-
stripArtifactId(artifact);
45-
46-
if (!artifact.getType().equals(TYPE_WAR)) {
47-
properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType());
48-
}
49-
50-
if (!artifact.getGroupId().equals(Artifact.GROUP_WEB)) {
51-
properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId());
52-
}
53-
54-
properties.setProperty(TYPE_WAR + "." + artifact.getArtifactId(), artifact.getVersion());
55-
}
56-
57-
for (Artifact artifact : moduleArtifacts) {
58-
stripArtifactId(artifact);
59-
60-
if (!artifact.getType().equals(TYPE_JAR)) {
61-
properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + TYPE, artifact.getType());
62-
}
63-
if (!artifact.getGroupId().equals(Artifact.GROUP_MODULE)) {
64-
properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId() + "." + GROUP_ID, artifact.getGroupId());
65-
}
66-
67-
properties.setProperty(TYPE_OMOD + "." + artifact.getArtifactId(), artifact.getVersion());
68-
}
69-
return properties;
70-
}
71-
7237
public String getPlatformVersion(){
7338
return getParam("war.openmrs");
7439
}
@@ -95,8 +60,7 @@ public void setName(String name) {
9560

9661
public List<Artifact> getModuleArtifacts() {
9762
List<Artifact> artifactList = new ArrayList<>();
98-
for (Object keyObject: getAllKeys()) {
99-
String key = keyObject.toString();
63+
for (String key: getAllKeys()) {
10064
String artifactType = getArtifactType(key);
10165
if(artifactType.equals(TYPE_OMOD)) {
10266
artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE), "omod"));
@@ -107,8 +71,7 @@ public List<Artifact> getModuleArtifacts() {
10771

10872
public List<Artifact> getOwaArtifacts() {
10973
List<Artifact> artifactList = new ArrayList<>();
110-
for (Object keyObject: getAllKeys()) {
111-
String key = keyObject.toString();
74+
for (String key : getAllKeys()) {
11275
String artifactType = getArtifactType(key);
11376
if(artifactType.equals(TYPE_OWA)) {
11477
artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)));
@@ -119,8 +82,7 @@ public List<Artifact> getOwaArtifacts() {
11982

12083
public Map<String, String> getSpaProperties() {
12184
Map<String, String> spaProperties = new HashMap<>();
122-
for (Object keyObject: getAllKeys()) {
123-
String key = keyObject.toString();
85+
for (String key : getAllKeys()) {
12486
if (key.startsWith(TYPE_SPA + ".")) {
12587
spaProperties.put(key.substring(TYPE_SPA.length() + 1), getParam(key));
12688
}
@@ -155,8 +117,7 @@ public List<Artifact> getSpaArtifacts() {
155117

156118
public List<Artifact> getWarArtifacts() {
157119
List<Artifact> artifactList = new ArrayList<>();
158-
for (Object keyObject: getAllKeys()) {
159-
String key = keyObject.toString();
120+
for (String key : getAllKeys()) {
160121
String artifactType = getArtifactType(key);
161122
if(artifactType.equals(TYPE_WAR)) {
162123
artifactList.add(new Artifact(checkIfOverwritten(key, ARTIFACT_ID), getParam(key), checkIfOverwritten(key, GROUP_ID), checkIfOverwritten(key, TYPE)));
@@ -167,8 +128,7 @@ public List<Artifact> getWarArtifacts() {
167128

168129
public List<Artifact> getConfigArtifacts() {
169130
List<Artifact> artifactList = new ArrayList<>();
170-
for (Object keyObject : getAllKeys()) {
171-
String key = keyObject.toString();
131+
for (String key : getAllKeys()) {
172132
String artifactType = getArtifactType(key);
173133
if (artifactType.equals(TYPE_CONFIG)) {
174134
artifactList.add(
@@ -181,8 +141,7 @@ public List<Artifact> getConfigArtifacts() {
181141

182142
public List<Artifact> getContentArtifacts() {
183143
List<Artifact> artifacts = new ArrayList<>();
184-
for (Object keyObject : getAllKeys()) {
185-
String key = keyObject.toString();
144+
for (String key : getAllKeys()) {
186145
String artifactType = getArtifactType(key);
187146
if (artifactType.equals(TYPE_CONTENT)) {
188147
artifacts.add(new Artifact(
@@ -196,14 +155,22 @@ public List<Artifact> getContentArtifacts() {
196155
return artifacts;
197156
}
198157

199-
protected Set<Object> getAllKeys() {
200-
return properties.keySet();
158+
public Set<String> getAllKeys() {
159+
return properties.stringPropertyNames();
201160
}
202161

203162
public Properties getAllProperties() {
204163
return properties;
205164
}
206165

166+
public void addProperty(String property, String value) {
167+
properties.put(property, value);
168+
}
169+
170+
public boolean contains(String propertyName) {
171+
return properties.containsKey(propertyName);
172+
}
173+
207174
protected String getArtifactType(String key) {
208175
String[] wordsArray = key.split("\\.");
209176
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){
386353
properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+TYPE, artifact.getType());
387354
}
388355

389-
private void setCustomModuleGroupId(Artifact artifact){
356+
private void setCustomModuleGroupId(Artifact artifact) {
390357
properties.setProperty(TYPE_OMOD+"."+artifact.getArtifactId()+"."+GROUP_ID, artifact.getGroupId());
391358
}
392359

393-
public void synchronize(BaseSdkProperties other){
394-
for(Object key: getAllKeys()){
395-
if (isBaseSdkProperty(key.toString())) {
360+
public void synchronize(BaseSdkProperties other) {
361+
for(String key : getAllKeys()){
362+
if (isBaseSdkProperty(key)) {
396363
other.properties.put(key, properties.get(key));
397364
}
398365
}
399-
for(Object key: new ArrayList<>(other.getAllKeys())){
400-
if(isBaseSdkProperty(key.toString())){
401-
if(StringUtils.isBlank(getParam(key.toString()))){
366+
for(String key : new ArrayList<>(other.getAllKeys())) {
367+
if(isBaseSdkProperty(key)){
368+
if(StringUtils.isBlank(getParam(key))) {
402369
other.properties.remove(key);
403370
}
404371
}

sdk-commons/src/main/java/org/openmrs/maven/plugins/model/DistroProperties.java

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.apache.maven.plugin.MojoExecutionException;
66
import org.openmrs.maven.plugins.utility.DistroHelper;
77
import org.openmrs.maven.plugins.utility.PropertiesUtils;
8-
import org.slf4j.Logger;
9-
import org.slf4j.LoggerFactory;
108

119
import java.io.File;
1210
import java.io.FileOutputStream;
@@ -20,20 +18,14 @@
2018

2119
import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;
2220

23-
/**
24-
*
25-
*/
2621
public class DistroProperties extends BaseSdkProperties {
2722

2823
public static final String PROPERTY_PROMPT_KEY = "property.%s.prompt";
29-
private static final String DEAFAULT_FILE_NAME = "openmrs-distro-%s.properties";
3024
public static final String DISTRO_FILE_NAME = "openmrs-distro.properties";
3125
private static final String DB_SQL = "db.sql";
3226
public static final String PROPERTY_DEFAULT_VALUE_KEY = "property.%s.default";
3327
public static final String PROPERTY_KEY = "property.%s";
3428

35-
private static final Logger log = LoggerFactory.getLogger(DistroProperties.class);
36-
3729
public DistroProperties(String name, String platformVersion){
3830
properties = new Properties();
3931
setName(name);
@@ -76,9 +68,9 @@ public String getPropertyValue(String propertyName){
7668

7769
public Set<String> getPropertiesNames(){
7870
Set<String> propertiesNames = new HashSet<>();
79-
for(Object key: getAllKeys()){
80-
if(key.toString().startsWith("property.")){
81-
propertiesNames.add(extractPropertyName(key.toString()));
71+
for(String key : getAllKeys()){
72+
if(key.startsWith("property.")){
73+
propertiesNames.add(extractPropertyName(key));
8274
}
8375
}
8476
return propertiesNames;
@@ -113,8 +105,7 @@ private String extractPropertyName(String key) {
113105
*/
114106
public Artifact getParentDistroArtifact() throws MojoExecutionException {
115107
Artifact artifact = null;
116-
for (Object keyObject: getAllKeys()) {
117-
String key = keyObject.toString();
108+
for (String key : getAllKeys()) {
118109
String artifactType = getArtifactType(key);
119110
if (artifactType.equals(TYPE_DISTRO)) {
120111
String artifactId = checkIfOverwritten(key, ARTIFACT_ID);
@@ -166,10 +157,6 @@ public void resolvePlaceholders(Properties projectProperties) throws MojoExecuti
166157
PropertiesUtils.resolvePlaceholders(properties, projectProperties);
167158
}
168159

169-
public Set<Object> getAllKeys() {
170-
return properties.keySet();
171-
}
172-
173160
public List<String> getExclusions() {
174161
String exclusions = getParam("exclusions");
175162
if(exclusions == null) {
@@ -178,10 +165,6 @@ public List<String> getExclusions() {
178165
return Arrays.asList(exclusions.split(","));
179166
}
180167

181-
public Set<String> getPropertyNames() {
182-
return properties.stringPropertyNames();
183-
}
184-
185168
public void removeProperty(String property) throws MojoExecutionException {
186169
if (!properties.containsKey(property)) {
187170
throw new MojoExecutionException("The property " + property + " was not found in the distro");
@@ -198,41 +181,4 @@ public void addExclusion(String exclusion) {
198181

199182
properties.setProperty("exclusions", exclusions + "," + exclusion);
200183
}
201-
202-
public void addProperty(String property, String value) throws MojoExecutionException {
203-
properties.put(property, value);
204-
}
205-
206-
public boolean contains(String propertyName) {
207-
return properties.containsKey(propertyName);
208-
}
209-
210-
/**
211-
* Adds a dependency with the specified version to the properties.
212-
*
213-
* @param dependency The name of the dependency.
214-
* @param version The version of the dependency.
215-
*/
216-
public void add(String dependency, String version) {
217-
if (StringUtils.isBlank(dependency) || StringUtils.isBlank(version)) {
218-
log.error("Dependency name or version cannot be blank");
219-
return;
220-
}
221-
222-
if (dependency.startsWith("omod.") || dependency.startsWith("owa.") || dependency.startsWith("war")
223-
|| dependency.startsWith("spa.frontendModule")) {
224-
properties.setProperty(dependency, version);
225-
log.info("Added dependency: {} with version: {}", dependency, version);
226-
}
227-
}
228-
229-
public String get(String contentDependencyKey) {
230-
return properties.getProperty(contentDependencyKey);
231-
}
232-
233-
@Override
234-
public String checkIfOverwritten(String key, String param) {
235-
return super.checkIfOverwritten(key, param);
236-
}
237-
238184
}

sdk-commons/src/main/java/org/openmrs/maven/plugins/model/Server.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ public String getArtifactId(String filename) {
581581

582582
public void setValuesFromDistroProperties(DistroProperties distroProperties) {
583583
if (distroProperties != null) {
584-
for (Object property : distroProperties.getAllKeys()) {
585-
String key = property.toString();
584+
for (String key : distroProperties.getAllKeys()) {
586585
if (distroProperties.isBaseSdkProperty(key)) {
587586
this.properties.put(key, distroProperties.getParam(key));
588587
}

sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DistroHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,16 @@ protected void processContentProperties(Properties contentProperties, DistroProp
443443
if (dependency.startsWith("omod.") || dependency.startsWith("owa.") || dependency.startsWith("war")
444444
|| dependency.startsWith("spa.frontendModule") || dependency.startsWith("content.")) {
445445
String versionRange = contentProperties.getProperty(dependency);
446-
String distroVersion = distroProperties.get(dependency);
446+
String distroVersion = distroProperties.getParam(dependency);
447447

448448
if (distroVersion == null) {
449449
String latestVersion = findLatestMatchingVersion(dependency, versionRange);
450450
if (latestVersion == null) {
451451
throw new MojoExecutionException(
452452
"No matching version found for dependency " + dependency + " in " + zipFileName);
453453
}
454-
distroProperties.add(dependency, latestVersion);
454+
455+
distroProperties.addProperty(dependency, latestVersion);
455456
} else {
456457
checkVersionInRange(dependency, versionRange, distroVersion, contentProperties.getProperty("name"));
457458
}

0 commit comments

Comments
 (0)