From 14de941bf1a91326bb46e21baa40d5a249a46656 Mon Sep 17 00:00:00 2001 From: haoke Date: Thu, 20 Jul 2023 20:56:03 +0800 Subject: [PATCH] [MSGADE-452]Fix ServiceResourceTransformer not correct issue. --- .../maven/plugins/shade/relocation/SimpleRelocator.java | 2 +- .../shade/resource/ServiceResourceTransformerTest.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java index bb31af0a..d078b881 100644 --- a/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java +++ b/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java @@ -222,7 +222,7 @@ private String shadeSourceWithExcludes( StringBuilder shadedSourceContent = new StringBuilder(sourceContent.length() * 11 / 10); boolean isFirstSnippet = true; // 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"); + String[] snippets = sourceContent.split("\\b" + patternFrom.replace(".", "[.]")); for (int i = 0, snippetsLength = snippets.length; i < snippetsLength; i++) { String snippet = snippets[i]; String previousSnippet = isFirstSnippet ? "" : snippets[i - 1]; diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java b/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java index 693ba499..cbdcaf0f 100644 --- a/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java +++ b/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java @@ -54,7 +54,7 @@ public void relocatedClasses() throws Exception { new SimpleRelocator("org.foo", "borg.foo", null, Arrays.asList("org.foo.exclude.*")); relocators.add(relocator); - String content = "org.foo.Service\norg.foo.exclude.OtherService\n"; + String content = "org.foo.Service\norg.foo.exclude.OtherService\norg.fooPart.exclude.OtherService\n"; byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); InputStream contentStream = new ByteArrayInputStream(contentBytes); String contentResource = "META-INF/services/org.foo.something.another"; @@ -76,7 +76,10 @@ public void relocatedClasses() throws Exception { assertNotNull(jarEntry); try (InputStream entryStream = jarFile.getInputStream(jarEntry)) { String xformedContent = IOUtils.toString(entryStream, "utf-8"); - assertEquals("borg.foo.Service" + NEWLINE + "org.foo.exclude.OtherService" + NEWLINE, xformedContent); + assertEquals( + "borg.foo.Service" + NEWLINE + "org.foo.exclude.OtherService" + NEWLINE + + "borg.fooPart.exclude.OtherService" + NEWLINE, + xformedContent); } finally { jarFile.close(); }