Skip to content

[MSHADE-452] Shade plugin can't replace SPI content correct when pattern not end with dot #482

Open
@jira-importer

Description

@jira-importer

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:

Remote Links:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:criticalCrashes, loss of data, severe memory leak

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions