Skip to content

Commit

Permalink
[MSHADE-443] Fix problems with shadeSourcesContent (#185)
Browse files Browse the repository at this point in the history
Due to MSHADE-396, some cases which were made to work in MSHADE-252,
started breaking. This change fixes them.
  • Loading branch information
kriegaex committed May 14, 2023
1 parent 06d9058 commit f15f26b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ public class SimpleRelocator implements Relocator {
* Match <ul>
* <li>certain Java keywords + space</li>
* <li>beginning of Javadoc link + optional line breaks and continuations with '*'</li>
* <li>(opening curly brace / opening parenthesis / comma / equals / semicolon) + space</li>
* <li>(closing curly brace / closing multi-line comment) + space</li>
* </ul>
* at end of string
*/
private static final Pattern RX_ENDS_WITH_JAVA_KEYWORD =
Pattern.compile("\\b(import|package|public|protected|private|static|final|synchronized|abstract|volatile) $"
private static final Pattern RX_ENDS_WITH_JAVA_KEYWORD = Pattern.compile(
"\\b(import|package|public|protected|private|static|final|synchronized|abstract|volatile|extends|implements|throws) $"
+ "|"
+ "\\{@link( \\*)* $");
+ "\\{@link( \\*)* $"
+ "|"
+ "([{}(=;,]|\\*/) $");

private final String pattern;

Expand Down Expand Up @@ -217,7 +221,7 @@ private String shadeSourceWithExcludes(
// Usually shading makes package names a bit longer, so make buffer 10% bigger than original source
StringBuilder shadedSourceContent = new StringBuilder(sourceContent.length() * 11 / 10);
boolean isFirstSnippet = true;
// Make sure that search pattern starts at word boundary and we look for literal ".", not regex jokers
// Make sure that search pattern starts at word boundary and that we look for literal ".", not regex jokers
String[] snippets = sourceContent.split("\\b" + patternFrom.replace(".", "[.]") + "\\b");
for (int i = 0, snippetsLength = snippets.length; i < snippetsLength; i++) {
String snippet = snippets[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ public void testRelocateMavenFiles() {
+ " private org.apache.maven.h.H h;\n"
+ " private String ioInput;\n"
+ "\n"
+ " public void doSomething() {\n"
+ " /** Javadoc, followed by default visibility method with fully qualified return type */\n"
+ " org.apache.maven.MyReturnType doSomething( org.apache.maven.Bar bar, org.objectweb.asm.sub.Something something) {\n"
+ " org.apache.maven.Bar bar;\n"
+ " org.objectweb.asm.sub.Something something;\n"
+ " String io, val;\n"
+ " String noRelocation = \"NoWordBoundaryXXXorg.apache.maven.In\";\n"
+ " String relocationPackage = \"org.apache.maven.In\";\n"
Expand Down Expand Up @@ -235,7 +238,10 @@ public void testRelocateMavenFiles() {
+ " private com.acme.maven.h.H h;\n"
+ " private String ioInput;\n"
+ "\n"
+ " public void doSomething() {\n"
+ " /** Javadoc, followed by default visibility method with fully qualified return type */\n"
+ " com.acme.maven.MyReturnType doSomething( com.acme.maven.Bar bar, aj.org.objectweb.asm.sub.Something something) {\n"
+ " com.acme.maven.Bar bar;\n"
+ " aj.org.objectweb.asm.sub.Something something;\n"
+ " String io, val;\n"
+ " String noRelocation = \"NoWordBoundaryXXXorg.apache.maven.In\";\n"
+ " String relocationPackage = \"com.acme.maven.In\";\n"
Expand Down

0 comments on commit f15f26b

Please sign in to comment.