Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHADE-443] Fix problems with shadeSourcesContent #185

Merged
merged 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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