Description
hk__lrzy opened MSHADE-452 and commented
We have java path as below
org.apache.demo1
org.apache.demo2
In {}maven-shade-plugin 3.2.1{}, we use relocation to process path and SPI Service file at the same time, and we will follow result.
<relocation>
<pattern>org.apache.demo</pattern>
<shadedPattern>shaded.org.apache.demo</shadedPattern>
</relocation>
META-INF/services/shaded.org.apache.demo
But in maven-shaded-plugin 3.5.0, it can't work as before, alouthght it SPI file name alao could be changed, but the SPI file content will {}have no change{}.
I see the differneces between the maven-shaded-plugin 3.5.0 and maven-shaded-plugin 3.2.1, finally find in maven-shaded-plugin 3.2.1, file content changed by follow code
public String applyToSourceContent( String sourceContent )
{
if ( rawString )
{
return sourceContent;
}
else
{
return sourceContent.replaceAll( "\\b" + pattern, shadedPattern );
}
}
but in {}maven-shaded-plugin 3.5.0{}, ** the code change to
private String shadeSourceWithExcludes( String sourceContent, String patternFrom, String patternTo,
Set<String> excludedPatterns )
{
// 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
for ( String snippet : sourceContent.split( "\\b" + patternFrom.replace( ".", "[.]" + "\\b" ) ) )
{
boolean doExclude = false;
for ( String excludedPattern : excludedPatterns )
{
if ( snippet.startsWith( excludedPattern ) )
{
doExclude = true;
break;
}
}
if ( isFirstSnippet )
{
shadedSourceContent.append( snippet );
isFirstSnippet = false;
}
else
{
shadedSourceContent.append( doExclude ? patternFrom : patternTo ).append( snippet );
}
}
return shadedSourceContent.toString();
}
In my cases, source content is {}org.apache.demo1{}, pattern from is {}org.apache.demo{}, pattern to is shaded.org.apache.demo.
and the code sourceContent.split( "\b" + patternFrom.replace( ".", "[.]" + "\b" ) ) __ will only have one response.
Affects: 3.5.0
Attachments:
- 20230720-205856.png (121.35 kB)
- 20230720-205900.png (77.34 kB)
Remote Links: