[ https://issues.apache.org/jira/browse/MSHADE-452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
hk__lrzy updated MSHADE-452: ---------------------------- Summary: Shade plugin can't replace SPI content correct when pattern not end with dot (was: Shade plugin can't replace SPI content with correct) > Shade plugin can't replace SPI content correct when pattern not end with dot > ---------------------------------------------------------------------------- > > Key: MSHADE-452 > URL: https://issues.apache.org/jira/browse/MSHADE-452 > Project: Maven Shade Plugin > Issue Type: Improvement > Affects Versions: 3.5.0 > Reporter: hk__lrzy > Priority: Critical > Attachments: 20230720-205856.png, 20230720-205900.png > > > 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. > {code:java} > <relocation> > <pattern>org.apache.demo</pattern> > <shadedPattern>shaded.org.apache.demo</shadedPattern> > </relocation> {code} > {code:java} > META-INF/services/shaded.org.apache.demo{code} > 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 > > {code:java} > public String applyToSourceContent( String sourceContent ) > { > if ( rawString ) > { > return sourceContent; > } > else > { > return sourceContent.replaceAll( "\\b" + pattern, shadedPattern ); > } > }{code} > but in {_}*maven-shaded-plugin 3.5.0*{_}, _**_ the code change to > {code:java} > 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(); > } {code} > 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. > -- This message was sent by Atlassian Jira (v8.20.10#820010)