[ 
https://issues.apache.org/jira/browse/MSOURCES-95?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Plamen Totev updated MSOURCES-95:
---------------------------------
    Attachment: reproduce-project.zip

> When one of the source folders is empty the source jar is recreated even when 
> sources not changed
> -------------------------------------------------------------------------------------------------
>
>                 Key: MSOURCES-95
>                 URL: https://issues.apache.org/jira/browse/MSOURCES-95
>             Project: Maven Source Plugin
>          Issue Type: Bug
>            Reporter: Plamen Totev
>            Priority: Minor
>         Attachments: reproduce-project.zip
>
>
> There is issue opened in Plexus Archive project - 
> https://github.com/codehaus-plexus/plexus-archiver/issues/24
> 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 {{\*\*/\*\*}} then the jar 
> will not be rebuilded. 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:
> {code}
> + src
> +--+ main
>    +--+ java
>        +--+ app
>        |  +--+ App.java
>        |
>        +--+ empty_dir
> {code}
> when added to {{JarArchiver}} with prefix "" (empty string) this is how 
> Plexus Archiver "sees" them:
> {code}
> src/main/java -> "" (empty string)
> src/main/java/app -> "app"
> src/main/java/app/App.java -> "app/App.java"
> src/main/java/empty_dir -> "empty_dir"
> {code}
> To decide which entries to add Plexus Archives applies inclusion and 
> exclusion patterns. Internally it uses 
> {{org.codehaus.plexus.util.DirectoryScanner}} 
> (https://github.com/codehaus-plexus/plexus-utils/blob/master/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java).
>  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/App.java", "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
(v6.3.4#6332)

Reply via email to