[MGPG-66] fix handling of excluded files by Syquel · Pull Request #10 · apache/maven-gpg-plugin (original) (raw)

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;
}