Skip to content
Merged
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 @@ -48,6 +48,8 @@ public class TestFolderPathPattern
TEST_PATH_VALIDATOR = compile("^/?[^/\\*\\(\\)]*" + quote(SRC_PROJECT_VARIABLE) + "[^\\*\\(\\)]*$");
}

private static final Pattern GROUP_PATTERN = Pattern.compile("\\([^\\)]+\\)");

private final String srcPathTemplate;
private final String testPathTemplate;
private final Pattern testProjectPattern;
Expand Down Expand Up @@ -204,6 +206,7 @@ private String resolveGroups(String path, String tplWithGroups, String tplWithRe
List<GroupRef> groupRefs = getGroupRefs(result);
reverse(groupRefs);

StringBuilder resultBuilder = new StringBuilder(result);
for (int i = 0; i < groupRefs.size(); i++)
{
GroupRef ref = groupRefs.get(i);
Expand All @@ -218,8 +221,9 @@ private String resolveGroups(String path, String tplWithGroups, String tplWithRe
throw new DoesNotMatchConfigurationException(analizedPath);
}

result = result.substring(0, ref.startIdx) + groupContent + result.substring(ref.endIdx);
resultBuilder.replace(ref.startIdx, ref.endIdx, groupContent);
}
result = resultBuilder.toString();
}
return result;
}
Expand Down Expand Up @@ -251,6 +255,11 @@ public SourceFolderPath getSrcPathFor(Path testPath) throws DoesNotMatchConfigur

private String replaceGroupsWithRefs(String template, List<GroupRef> groupRefs)
{
if (groupRefs.isEmpty())
{
return template;
}

Map<Integer, Integer> refIndices = new HashMap<Integer, Integer>();
int idx = 1;
for (GroupRef ref : groupRefs)
Expand All @@ -259,12 +268,16 @@ private String replaceGroupsWithRefs(String template, List<GroupRef> groupRefs)
idx++;
}

String result = template;
for (int i = 0; i < groupRefs.size(); i++)
Matcher matcher = GROUP_PATTERN.matcher(template);
StringBuffer sb = new StringBuffer();
int i = 0;
while (matcher.find() && i < groupRefs.size())
{
result = result.replaceFirst("\\([^\\)]+\\)", "\\\\" + refIndices.get(i));
matcher.appendReplacement(sb, Matcher.quoteReplacement("\\" + refIndices.get(i)));
i++;
}
return result;
matcher.appendTail(sb);
return sb.toString();
}

private String getSrcProjectName(String tstProjectName, Path tstPath) throws DoesNotMatchConfigurationException
Expand Down
Loading