Skip to content

[MGPG-66] fix handling of excluded files#10

Merged
elharo merged 3 commits intoapache:masterfrom
Syquel:bugfix/MGPG-66
Mar 16, 2021
Merged

[MGPG-66] fix handling of excluded files#10
elharo merged 3 commits intoapache:masterfrom
Syquel:bugfix/MGPG-66

Conversation

@Syquel
Copy link
Copy Markdown
Contributor

@Syquel Syquel commented Feb 26, 2021

Fixes MGPG-66 by adding a check if files match the exclude patterns.

@elharo
Copy link
Copy Markdown
Contributor

elharo commented Mar 10, 2021

@elharo
Copy link
Copy Markdown
Contributor

elharo commented Mar 10, 2021

Many builds failed. might be flaky. Running again.

@Syquel
Copy link
Copy Markdown
Contributor Author

Syquel commented Mar 10, 2021

I was able to reproduce this issue on Linux.

The issue is that org.codehaus.plexus.util.SelectorUtils#matchPath(java.lang.String, java.lang.String) does not match the pattern **/*.asc on the path /tmp/maven-gpg-plugin/target/it/sign-release-with-excludes/target/test-1.0-sources.jar.asc.
On Windows it's working.

I will take a look tomorrow.

//EDIT
Found the following comment on org.codehaus.plexus.util.SelectorUtils#separatorPatternStartSlashMismatch(java.lang.String, java.lang.String, java.lang.String):

// When str starts with a File.separator, pattern has to start with a
// File.separator.
// When pattern starts with a File.separator, str has to start with a
// File.separator.

So while absolute Paths on Windows (usually) start with a drive letter they always start with the file separator char / on Linux.
Either we make the path relative as a workaround or look for another Class which provides ant pattern matching.

The following version would work on both OS, but I would like to hear another opinion first:

protected boolean isExcluded( Artifact artifact )
{
    final Path projectBasePath = project.getBasedir().toPath();
    final Path artifactPath = artifact.getFile().toPath();
    final String relativeArtifactPath = projectBasePath.relativize( artifactPath ).toString();

    for ( String exclude : excludes )
    {
        if ( SelectorUtils.matchPath( exclude, relativeArtifactPath ) )
        {
            return true;
        }
    }
    return false;
}

@elharo
Copy link
Copy Markdown
Contributor

elharo commented Mar 15, 2021

@ghost
Copy link
Copy Markdown

ghost commented Mar 15, 2021

I can confirm this fix is also working on macOS 11.2.3 (Apple Silicon, gpg (GnuPG/MacGPG2) 2.2.24). The test in 4da6921 is successful and was failing before as expected.
Java reports as: OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

@elharo elharo merged commit 12fbd63 into apache:master Mar 16, 2021
This was referenced May 10, 2021
@jira-importer
Copy link
Copy Markdown

Resolve #226

1 similar comment
@jira-importer
Copy link
Copy Markdown

Resolve #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants