Uploaded image for project: 'Maven Source Plugin'
  1. Maven Source Plugin
  2. MSOURCES-95

Source JAR is re-created even if sources are not changed

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2.0
    • Labels:
      None

      Description

      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:

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

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

      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"
      

      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 **/* it 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 **/** it will match "", "app", "app/App.java" and "empty_dir". That's because 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 is none then the directory last modification date will be newer than the one of the archive.

        Attachments

        1. reproduce-project.zip
          2 kB
          Plamen Totev

          Activity

            People

            • Assignee:
              michael-o Michael Osipov
              Reporter:
              plamenttv Plamen Totev
            • Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h