Skip to content

Commit

Permalink
clean up and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Dec 12, 2023
1 parent 67c15c6 commit d4269d8
Showing 1 changed file with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public abstract class StartDebugMojoSupport extends ServerFeatureSupport {

protected Map<String,String> bootstrapMavenProps = new HashMap<String,String>();
protected Map<String,String> envMavenProps = new HashMap<String,String>();
protected List<String> jvmMavenPropNames = new ArrayList<String>();
protected List<String> jvmMavenPropNames = new ArrayList<String>(); // only used for tracking overriding properties - not included in the generated jvm.options file
protected List<String> jvmMavenPropValues = new ArrayList<String>();
protected Map<String,String> varMavenProps = new HashMap<String,String>();
protected Map<String,String> defaultVarMavenProps = new HashMap<String,String>();
Expand Down Expand Up @@ -821,21 +821,21 @@ private void loadLibertyConfigFromProperties(Properties props) {

getLog().debug("Processing Liberty configuration from property with key "+key+" and value "+value);
switch (propType) {
case ENV: envMavenProps.put(suffix, value);
break;
case BOOTSTRAP: bootstrapMavenProps.put(suffix, value);
break;
case JVM: if (jvmMavenPropNames.contains(suffix)) {
case ENV: envMavenProps.put(suffix, value);
break;
case BOOTSTRAP: bootstrapMavenProps.put(suffix, value);
break;
case JVM: if (jvmMavenPropNames.contains(suffix)) {
int index = jvmMavenPropNames.indexOf(suffix);
getLog().debug("Remove duplicate property with name: "+suffix+" at position: "+index);
jvmMavenPropNames.remove(index);
jvmMavenPropValues.remove(index);
}
jvmMavenPropNames.add(suffix);
jvmMavenPropValues.add(value);
break;
case VAR: varMavenProps.put(suffix, value);
break;
}
jvmMavenPropNames.add(suffix); // need to keep track of names so that a system prop can override a project prop
jvmMavenPropValues.add(value);
break;
case VAR: varMavenProps.put(suffix, value);
break;
case DEFAULTVAR: defaultVarMavenProps.put(suffix, value);
break;
}
Expand Down Expand Up @@ -952,24 +952,21 @@ private void writeServerEnvProperties(File file, Map<String, String> mavenProper
}

// Remove any duplicate entries in the passed in List
protected List<String> getUniqueValues(List<String> options) {
List<String> uniqueOptions = new ArrayList<String> ();
if (options == null) {
return uniqueOptions;
}
if (options.isEmpty()) {
return options;
protected List<String> getUniqueValues(List<String> values) {
List<String> uniqueValues = new ArrayList<String> ();
if (values == null) {
return uniqueValues;
}

for (String nextOption : options) {
// by removing the option first, it ensures this one is last and not a duplicate - nothing happens if the option is not there
if (uniqueOptions.contains(nextOption)) {
getLog().debug("Remove duplicate option: "+nextOption+" at position: "+uniqueOptions.indexOf(nextOption));
for (String nextValue : values) {
// by removing a matching existing value, it ensures there will not be a duplicate and that this current one will appear later in the List
if (uniqueValues.contains(nextValue)) {
getLog().debug("Remove duplicate value: "+nextValue+" at position: "+uniqueValues.indexOf(nextValue));
}
uniqueOptions.remove(nextOption);
uniqueOptions.add(nextOption);
uniqueValues.remove(nextValue); // has no effect if the value is not present
uniqueValues.add(nextValue);
}
return uniqueOptions;
return uniqueValues;
}

// One of the passed in Lists must be not null and not empty
Expand All @@ -982,7 +979,8 @@ private void writeJvmOptions(File file, List<String> options, List<String> maven
combinedJvmOptions = uniqueMavenProps;
} else {
combinedJvmOptions = new ArrayList<String> ();
// add the maven properties first so that they do not take precedence over the options specified with jvmOptions
// add the maven properties (which consist of both project properties and system properties) first,
// so that they do not take precedence over the options specified with jvmOptions config parameter
combinedJvmOptions.addAll(uniqueMavenProps);
combinedJvmOptions.removeAll(uniqueOptions); // remove any exact duplicates before adding all the jvmOptions
combinedJvmOptions.addAll(uniqueOptions);
Expand Down

0 comments on commit d4269d8

Please sign in to comment.