diff --git a/maven-config-processor-plugin/src/main/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisor.java b/maven-config-processor-plugin/src/main/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisor.java index 7a38609..db13719 100644 --- a/maven-config-processor-plugin/src/main/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisor.java +++ b/maven-config-processor-plugin/src/main/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisor.java @@ -32,15 +32,28 @@ public PropertiesUncommentActionProcessingAdvisor(UncommentAction action, Expres super(expressionResolver); this.action = action; - commentPrefixPattern = Pattern.compile(Comment.PREFIX_1 + "|" + Comment.PREFIX_2); + commentPrefixPattern = Pattern.compile("(\\s*)" + Comment.PREFIX_1 + "|" + Comment.PREFIX_2); } @Override public PropertiesFileItemAdvice process(PropertiesFileItem item) { if (item instanceof Comment) { Comment comment = (Comment) item; - String text = commentPrefixPattern.matcher(comment.getAsText()).replaceAll(""); - text = resolve(text); + String[] parts = comment.getAsText().split(PropertiesActionProcessor.LINE_SEPARATOR); + for(int i = 0; i < parts.length; ++i) + { + Matcher matcher = commentPrefixPattern.matcher(parts[i]); + if (matcher.find()) + { + String replace = matcher.group(1); + if (replace == null) + { + replace = ""; + } + parts[i] = matcher.replaceFirst(replace); + } + } + String text = resolve(StringUtils.join(parts, PropertiesActionProcessor.LINE_SEPARATOR)); if (!StringUtils.isBlank(text)) { PropertyMapping mapping = new PropertyMapping(); diff --git a/maven-config-processor-plugin/src/test/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisorTest.java b/maven-config-processor-plugin/src/test/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisorTest.java index 088dfd1..ebb8198 100644 --- a/maven-config-processor-plugin/src/test/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisorTest.java +++ b/maven-config-processor-plugin/src/test/java/com/google/code/configprocessor/processing/properties/PropertiesUncommentActionProcessingAdvisorTest.java @@ -34,7 +34,7 @@ public void setup() { @Test public void processUncomment() throws Exception { Action action = new UncommentAction("property4.value"); - String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "property4.value=value4 \\" + LINE_SEPARATOR + "value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR; + String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "property4.value=value4 \\" + LINE_SEPARATOR + "value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR + "#property8.value=value!7" + LINE_SEPARATOR; executeTest(action, expected); } @@ -42,7 +42,7 @@ public void processUncomment() throws Exception { @Test public void processUncommentAfterComment() throws Exception { Action action = new UncommentAction("property5.value"); - String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR; + String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR + "#property8.value=value!7" + LINE_SEPARATOR; executeTest(action, expected); } @@ -50,7 +50,7 @@ public void processUncommentAfterComment() throws Exception { @Test public void processUncommentPropertyWithEmptyValue() throws Exception { Action action = new UncommentAction("property2.value"); - String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR; + String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR + "#property8.value=value!7" + LINE_SEPARATOR; executeTest(action, expected); } @@ -62,8 +62,16 @@ public void processUncommentPropertyWithEmptyValue() throws Exception { @Test public void processUncommentPropertyAfterEmptyComment() throws Exception { Action action = new UncommentAction("property7.value"); - String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR; + String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR + "#property8.value=value!7" + LINE_SEPARATOR; executeTest(action, expected); } + + @Test + public void processUncommentPropertyWithCommentCharacterValue() throws Exception { + Action action = new UncommentAction("property8.value"); + String expected = "property1.value=value1" + LINE_SEPARATOR + "property2.value=" + LINE_SEPARATOR + "# Comment" + LINE_SEPARATOR + " property3.value=value3 \\" + LINE_SEPARATOR + "value 3 continuation" + LINE_SEPARATOR + "# property4.value=value4 \\" + LINE_SEPARATOR + "#value 4 continuation" + LINE_SEPARATOR + "#property5.value=value5" + LINE_SEPARATOR + "property6.value=value6=value" + LINE_SEPARATOR + "#" + LINE_SEPARATOR + "#property7.value=value7" + LINE_SEPARATOR + "# " + LINE_SEPARATOR + "property8.value=value!7" + LINE_SEPARATOR; + + executeTest(action, expected); + } } diff --git a/maven-config-processor-plugin/src/test/resources/com/google/code/configprocessor/data/uncomment-properties-target-config.properties b/maven-config-processor-plugin/src/test/resources/com/google/code/configprocessor/data/uncomment-properties-target-config.properties index 020112a..084a142 100644 --- a/maven-config-processor-plugin/src/test/resources/com/google/code/configprocessor/data/uncomment-properties-target-config.properties +++ b/maven-config-processor-plugin/src/test/resources/com/google/code/configprocessor/data/uncomment-properties-target-config.properties @@ -9,4 +9,5 @@ value 3 continuation property6.value=value6=value # #property7.value=value7 -# \ No newline at end of file +# +#property8.value=value!7