apache / apache/maven-shade-plugin
[MSHADE-452] Shade plugin can't replace SPI content correct when pattern not end with dot
- Dominant language
- Java
- Stars
- 188
- Forks
- 103
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 4
Description
**[hk__lrzy](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=hk__lrzy)** opened **[MSHADE-452](https://issues.apache.org/jira/browse/MSHADE-452?redirect=false)** 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.
```java
org.apache.demo
shaded.org.apache.demo
```
```java
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
```java
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
```java
private String shadeSourceWithExcludes( String sourceContent, String patternFrom, String patternTo,
Set 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](https://issues.apache.org/jira/secure/attachment/13061472/20230720-205856.png) (_121.35 kB_)
- [20230720-205900.png](https://issues.apache.org/jira/secure/attachment/13061471/20230720-205900.png) (_77.34 kB_)
**Remote Links:**
- [GitHub Pull Request #193
](https://github.com/apache/maven-shade-plugin/pull/193)
- [GitHub PR
](https://github.com/apache/maven-shade-plugin/pull/193)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing applyToSourceContent from Maven Shade Plugin 3.2.1 with shadeSourceWithExcludes in 3.5.0, using the reported org.apache.demo and shaded.org.apache.demo example. Review GitHub PR #193 and verify that the SPI file content is relocated correctly when the pattern does not end with a dot.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100