Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
ROO-3702: Showing all related properties on Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jcagarcia committed Feb 11, 2016
1 parent 309f28d commit 81327fd
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -435,6 +436,9 @@ public Object nextElement() {
}

boolean saveNeeded = false;
boolean needForce = false;
List<String> overwriteProperties = new ArrayList<String>();

for (final Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();

Expand All @@ -450,13 +454,33 @@ public Object nextElement() {
props.setProperty(key, newValue);
saveNeeded = true;
}else if(!existingValue.equals(newValue) && !force){
// ROO-3702: Show error when tries to update some property that
// ROO-3702: Show error when tries to update some properties that
// already exists and --force global param is false.
String msg = String.format("WARNING: Property '%s' already exists. "
+ "Use --force param to overwrite it.", key);
throw new RuntimeException(msg);
needForce = true;
overwriteProperties.add(key);
}
}

// ROO-3702: Show error when tries to update some properties that
// already exists and --force global param is false.
if (needForce) {
String propertyCount = overwriteProperties.size() > 1 ? "Properties"
: "Property";

String propertyLists = "";
for (String property : overwriteProperties) {
propertyLists = propertyLists.concat("'").concat(property)
.concat("', ");
}

String msg = String.format(
"WARNING: %s %s already exists on '%s'. "
+ "Use --force parameter to overwrite it.",
propertyCount,
propertyLists.substring(0, propertyLists.length() - 2),
propertyFilename);
throw new RuntimeException(msg);
}

if (saveNeeded) {
storeProps(props, mutableFile.getOutputStream(),
Expand Down

0 comments on commit 81327fd

Please sign in to comment.