mathieucarbou / license-maven-plugin

Manage license headers in your source files
https://mathieu.carbou.me/license-maven-plugin/
Apache License 2.0
242 stars 86 forks source link

license-maven-plugin-git fails when using git worktree #158

Open ctubbsii opened 4 years ago

ctubbsii commented 4 years ago

git worktree allows you to check out a branch in a separate directory, so you can have multiple checked out into separate working directories from a single clone at the same time. The license-maven-plugin-git code seems to be trying to check for a folder at the root, called .git/. However, when using git worktree, this is a file that references the main checkout directory, rather than a directory.

The plugin should be able to handle this case, instead of failing.

The problem might be with the version of jgit being used, and updating the dependency may fix the issue. It's not clear to me, as I'm not that familiar with jgit, or this library's code.

mathieucarbou commented 4 years ago

please provide a way to reproduce the issue or unit test or even a PR to fix that. Will close otherwise.

ctubbsii commented 4 years ago

To reproduce:

  1. git worktree add ../someotherdirectory HEAD
  2. cd ../someotherdirectory
  3. add license-maven-plugin-git as a dependency as described in https://github.com/mycila/license-maven-plugin/blob/master/license-maven-plugin-git/README.md
  4. mvn package
  5. observe all the stack traces
Stack Traces (click to expand) ``` [INFO] --- license-maven-plugin:3.0:format (license-headers) @ accumulo-project --- [INFO] Updating license headers... [WARNING] failure occured while calling class com.mycila.maven.plugin.license.git.CopyrightRangeProvider java.lang.RuntimeException: Could not compute the year of the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/.github/workflows/maven.yaml at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader[WARNING] failure occured while calling class com.mycila.maven.plugin.license.git.CopyrightRangeProvider java.lang.RuntimeException: Could not compute the year o[WARNING] failure occured while calling class com.mycila.maven.plugin.license.git.CopyrightRangeProviderf the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/src/site/site.xml at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (java.lang.RuntimeException: mDo[WARNING] failure occured while calling class com.mycilacument.java:85)Co .maven.plugin.license.git.CopyrightRangeProvider uld not compute the year of the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/contrib/scripts/check-tservers.py at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicens eMojo.jav(ataWARNING31mjava.lang.RuntimeException[1mCopyright:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors .RangeProvider.jav: Could not compute the year of the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/.github/workflows/maven-on-demand.yaml at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) ] failure occured while calling class com.mycila.maven.plugin.license.git.CopyrightRangeProvider [WARNING] failure occured while calling class com.mycila.maven.plugin.lica:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) nse.git.CopyrightRangeProvider.license.document.Document.hasHeader (Document.jCaused byjava: java.lang.RuntimeException: Could not compute the year of the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/contrib/Eclipse-Accumulo-Codestyle.xml at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) Caused by: org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getGitLookup (CopyrightRangeProvider.java:138) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.am: org.eclipse.jgit.errors.NoWorkTreeExceptiongva:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) Caused by: org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getGitLookup5) (CopyrightRangeProvider.java:138) [1mat1;31mjava.lang.RuntimeException: Could not compute the year of the last git commit for file /home/christopher/git/apache/accumulo/someotherdirectory/pom.xml at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:95) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) Caused by: org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) Caused by: org.eclipse.jgit.errors.Noat org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getGitLookup (CopyrightRangeProvider.java:138) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at comat com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.con.mycila.maveetA: dditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) n.plugin.license.document.Document.hasHeadercurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) Caused by: org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plorkTreeException: Bare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getGitLookup (CopyrightRangeProvider.java:138) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.loadugin.license.git.CopyrightRangeProvider.getGitLookup (CopyrightRangeProvider.java:138) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (Abstr (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) (Document.java:) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) a[1mat com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergeProperties (Document.java:97) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) 31mBare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getWorkTree (Repository.java:1245) at com.mycila.maven.plugin.license.git.GitLookup. (GitLookup.java:79) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getGitLookup (CopyrightRangeProvider.java:138) at com.mycila.maven.plugin.license.git.CopyrightRangeProvider.getAdditionalProperties (CopyrightRangeProvider.java:84) at com.mycila.maven.plugin.license.AbstractLicenseMojo$1.load (AbstractLicenseMojo.java:360) at com.mycila.maven.plugin.license.document.Document.mergePrctLicenseMojo.opertiesjava:398) at java.util.concurrent.Executors$RunnableAdapter.call (Document.java:97) ( Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) at com.mycila.maven.plugin.license.header.Header.isMatchForText (Header.java:180) at com.mycila.maven.plugin.license.document.Document.hasHeader (Document.java:85) at com.mycila.maven.plugin.license.AbstractLicenseMojo$2.run (AbstractLicenseMojo.java:398) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515) at java.util.concurrent.FutureTask.run (FutureTask.java:264) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628) at java.lang.Thread.run (Thread.java:834) ```
ctubbsii commented 4 years ago

I believe this is an upstream JGit bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475 It may or may not be possible for this plugin to work around that bug. Hopefully upstream fixes it and you can just update to the latest JGit version.

mathieucarbou commented 3 years ago

I wasn't able to reproduce, but I've updated jGit (#231).

ctubbsii commented 2 years ago

@mathieucarbou Thanks for updating jGit. But, it looks like this isn't fixed upstream yet. I have verified that this remains a problem, up through 4.2.rc1. Here's a way you can reproduce using this (license-maven-plugin) repo:

  1. Check out this repo, and use current "master" branch (your branch was at commit 4400a75d509be4df2ed945d656038003f68a5ca8 when I tried)
  2. Add the most recent version of license-maven-plugin-git as a dependency of license-maven-plugin to the pom.xml:
    --- license-maven-plugin/pom.xml
    +++ license-maven-plugin/pom.xml
    @@ -239,6 +239,13 @@ limitations under the License.
             <exclude>docs/**</exclude>
           </excludes>
         </configuration>
    +        <dependencies>
    +          <dependency>
    +            <groupId>com.mycila</groupId>
    +            <artifactId>license-maven-plugin-git</artifactId>
    +            <version>4.2.rc1</version>
    +          </dependency>
    +        </dependencies>
       </plugin>
     </plugins>
    </build>
  3. Save it as a branch, so you can easily switch to it again:
    git checkout -b reproduce-158
    git add pom.xml
    git commit -m "test commit to reproduce issue 158"
  4. Confirm it works from the primary worktree (the one with the .git/ directory):
    mvn clean license:check
  5. Clean up the docs/reports/ directory (timestamps get modified during the build) and switch back to the master branch:
    git restore -- docs/
    git checkout master
  6. Checkout the reproduce-158 branch in a secondary worktree (see https://git-scm.com/docs/git-worktree):
    git worktree add ../reproduce-158 reproduce-158
  7. Try the same build there, and observe the errors where jGit incorrectly believes this to be a "bare" git repo:
    cd ../reproduce-158
    mvn clean license:check

Because this is still a problem, I think this issue should be re-opened. There may still be a way to work around the upstream bug, by changing how jGit is used in this project, but I haven't tried yet.