maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Plamen Totev (JIRA)" <>
Subject [jira] [Created] (MSOURCES-95) When one of the source folders is empty the source jar is recreated even when sources not changed
Date Thu, 03 Mar 2016 06:40:18 GMT
Plamen Totev created MSOURCES-95:

             Summary: When one of the source folders is empty the source jar is recreated
even when sources not changed
                 Key: MSOURCES-95
             Project: Maven Source Plugin
          Issue Type: Bug
            Reporter: Plamen Totev
            Priority: Minor

There is issue opened in Plexus Archive project -

In short if you download the attached zip and build it several times you'll see that the source
jar is build every time no matter that the source are not changed. That's because {{target/generated-sources/annotations}}
is empty. I think the reason for this behavior is that the default inclusion pattern in {{AbstractSourceJarMojo}}
is {{\*\*/\*}}. If it's {{\*\*/\*\*}}. Is there any reason why it's {{\*\*/\*}} and not {{\*\*/\*\*}}

In the next paragraphs I'll try to explain why the second patter work and the first not.

Let's say we have the following directory:

+ src
+--+ main
   +--+ java
       +--+ app
       |  +--+
       +--+ empty_dir

when added to {{JarArchiver}} with prefix "" (empty string) this is how Plexus Archiver "sees"

src/main/java -> "" (empty string)
src/main/java/app -> "app"
src/main/java/app/ -> "app/"
src/main/java/empty_dir -> "empty_dir"

To decide which entries to add Plexus Archives applies inclusion and exclusion patterns. Internally
it uses {{org.codehaus.plexus.util.DirectoryScanner}} (
The JavaDoc contains nice explanation how the patterns are applied but in the next paragraph
I'll try to explain in short what happens.

When the pattern is set to {{\*\*/\*}} will match all but /src/main/java (("", "app", "app/",
"empty_dir")). This is because the pattern matches zero or more path segments, followed by
any path segment. src/main/java is mapped to "" so the pattern will not match it (it's empty
path segment followed by nothing). So far so good. But what if the source directory is empty(src/main/java).
Then nothing will be matched and we'll end with empty resource collection to add to the archive.
And because it's empty there is no way to know when it was last modified so Plexus Archiver
will do the safe thing and recreate the archive. After all when the archive was created the
pattern may have matched something and the archive is not empty so it's outdated.

What if the pattern is set to {{\*\*/\*\*}}. Then it matches zero or more path segments, followed
by zero or more path segments - in other words everything (my understanding is that it's the
same as "\*\*" - match everything). So if /src/main/java is empty we'll end up with collection
containing only "" - file resource with empty name. Because of the empty name it won't be
added to the archive(and that's exactly what we want) but there is at least one resource with
last modification date so now Plexus Archiver knows if the archive is up to date or not. If
there were files in the directory and now there in none then the directory mast modification
date will be newer than the one of the archive.

This message was sent by Atlassian JIRA

View raw message