[ 
https://issues.apache.org/jira/browse/MSHADE-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17848873#comment-17848873
 ] 

ASF GitHub Bot commented on MSHADE-452:
---------------------------------------

hk-lrzy commented on PR #193:
URL: 
https://github.com/apache/maven-shade-plugin/pull/193#issuecomment-2126515899

   > Hi @hk-lrzy , sorry for the delay (guess the PR popped during holidays). 
From my window this PR has the risk to revert some of the fixes done before. 
Long story short shade mixing the same API (relocation) for sources (variables, 
classes, packages), paths and other things, there is always a such a risk so 
ultimately I think a safer fix would make the relocated file more contextual 
(`if (filePath ~ META-INF/services/xxxxxx` then use relocateSPIFile()` to share 
the idea).
   > 
   > Hope it makes sense.
   
   Thanks for reply, i will recheck the logical follow your suggestion and 
commit it later.




> 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: Bug
>    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)

Reply via email to