Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ 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);
}

@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);
}

@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);
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ value 3 continuation
property6.value=value6=value
#
#property7.value=value7
#
#
#property8.value=value!7