Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 16, 2021
Merged

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

merged 3 commits into from
Mar 16, 2021

Conversation

Syquel
Copy link
Contributor

@Syquel Syquel commented Feb 26, 2021

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

@elharo
Copy link
Contributor

elharo commented Mar 10, 2021

@elharo
Copy link
Contributor

elharo commented Mar 10, 2021

Many builds failed. might be flaky. Running again.

@Syquel
Copy link
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
Contributor

elharo commented Mar 15, 2021

@ghost
Copy link

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
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.

2 participants