From 3edaa528e17c2b815415fb9d9c65ea044656bd8a Mon Sep 17 00:00:00 2001 From: Niels Basjes Date: Thu, 10 Feb 2022 16:26:30 +0100 Subject: [PATCH] [SCM-977] Support for retrieving tags from the changelog --- .../java/org/apache/maven/scm/ChangeSet.java | 67 +++++++ .../org/apache/maven/scm/ChangeSetTest.java | 2 + .../changelog/HgChangeLogConsumer.java | 5 +- .../changelog/HgChangeLogCommandTckTest.java | 7 + .../changelog/GitChangeLogCommand.java | 3 + .../changelog/GitChangeLogConsumer.java | 17 +- .../changelog/GitChangeLogCommandTest.java | 24 +-- .../changelog/GitChangeLogConsumerTest.java | 69 +++++++ .../resources/git/changelog/gitlog3.gitlog | 177 ++++++++++++++++++ .../27/3658439f580b289f86d407d85f60f96b9e1b1f | 2 + .../95/86ea07d625757c5af7fe38f6ca7d4bdae8447b | Bin 128 -> 0 bytes .../resources/linear-changelog/packed-refs | 3 + .../maven-scm-provider-gittest/readme.txt | 3 + .../changelog/GitChangeLogCommandTckTest.java | 20 ++ .../provider/git/jgit/command/JGitUtils.java | 33 +++- .../changelog/JGitChangeLogCommand.java | 20 +- .../27/3658439f580b289f86d407d85f60f96b9e1b1f | 2 + .../95/86ea07d625757c5af7fe38f6ca7d4bdae8447b | Bin 128 -> 0 bytes .../resources/linear-changelog/packed-refs | 3 + .../changelog/ChangeLogCommandTckTest.java | 61 +++++- 20 files changed, 488 insertions(+), 30 deletions(-) create mode 100644 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/changelog/gitlog3.gitlog create mode 100644 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f delete mode 100644 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b create mode 100644 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f delete mode 100644 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b diff --git a/maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java b/maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java index bc22ba2f6..3809ed788 100644 --- a/maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java +++ b/maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java @@ -116,6 +116,11 @@ public class ChangeSet */ private List files; + /** + * List of tags + */ + private List tags; + /** * The SCM revision id for this changeset. * @since 1.3 @@ -414,6 +419,53 @@ public String getTimeFormatted() return TIME_FORMAT.format( getDate() ); } + /** + * Getter for property tags. + * + * @return Value of property author. + */ + public List getTags() + { + if ( tags == null ) + { + return Collections.emptyList(); + } + return tags; + } + + /** + * Setter for property tags. + * + * @param tags New value of property tags. This replaces the existing list (if any). + */ + public void setTags( List tags ) + { + this.tags = tags; + } + + /** + * Setter for property tags. + * + * @param tag New tag to add to the list of tags. + */ + public void addTag( String tag ) + { + if ( tag == null ) + { + return; + } + tag = tag.trim(); + if ( tag.isEmpty() ) + { + return; + } + if ( tags == null ) + { + tags = new ArrayList<>(); + } + tags.add( tag ); + } + /** * @return TODO * @since 1.3 @@ -466,6 +518,11 @@ public String toString() { StringBuilder result = new StringBuilder( author == null ? " null " : author ); result.append( "\n" ).append( date == null ? "null " : date.toString() ).append( "\n" ); + List tags = getTags(); + if ( !tags.isEmpty() ) + { + result.append( "tags:" ).append( tags ).append( "\n" ); + } // parent(s) if ( parentRevision != null ) { @@ -552,6 +609,16 @@ public String toXML() buffer.append( "\t\t\n" ); + List tags = getTags(); + if ( !tags.isEmpty() ) + { + buffer.append( "\t\t\n" ); + for ( String tag: tags ) + { + buffer.append( "\t\t\t" ).append( escapeValue( tag ) ).append( "\n" ); + } + buffer.append( "\t\t\n" ); + } buffer.append( "\t\n" ); return buffer.toString(); diff --git a/maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java b/maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java index 67627dc72..77caae9b8 100644 --- a/maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java +++ b/maven-scm-api/src/test/java/org/apache/maven/scm/ChangeSetTest.java @@ -19,6 +19,7 @@ * under the License. */ +import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -59,6 +60,7 @@ private static ChangeSet createInstance() instance.setAuthor( "dion" ); instance.setComment( "comment" ); instance.setDate( "2002/04/01 00:00:00" ); + instance.setTags( Arrays.asList( "v3.14", "v2.7]]1828", " 0 ); } + public void testGitLogConsumer3() + throws Exception + { + GitChangeLogConsumer consumer = new GitChangeLogConsumer( null ); + + File f = getTestFile( "/src/test/resources/git/changelog/gitlog3.gitlog" ); + + ConsumerUtils.consumeFile( f, consumer ); + + List modifications = consumer.getModifications(); + + assertEquals( 10, modifications.size() ); + + SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss Z" ); + sdf.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); + + ChangeSet first = modifications.get(0); + assertEquals( "Michael Osipov ", first.getAuthor() ); + assertEquals( "2022-01-08 20:02:12 +0000", sdf.format( first.getDate() ) ); + assertEquals( "[maven-release-plugin] prepare for next development iteration", first.getComment() ); + assertEquals( "4fc34cfa14f2e72506187b03a492ce55ed459d4c", first.getRevision() ); + assertEquals( Collections.emptyList(), first.getTags() ); + assertNotNull( first.getFiles() ); + assertFalse( first.getFiles().isEmpty() ); + + ChangeSet second = modifications.get(1); + assertEquals( "Michael Osipov ", second.getAuthor() ); + assertEquals( "2022-01-08 20:02:01 +0000", sdf.format( second.getDate() ) ); + assertEquals( "[maven-release-plugin] prepare release maven-scm-2.0.0-M1", second.getComment() ); + assertEquals( "3a6d9817fe809c43eca588d7c0f4428254eae17c", second.getRevision() ); + assertEquals( Collections.singletonList("maven-scm-2.0.0-M1"), second.getTags() ); + assertNotNull( second.getFiles() ); + assertFalse( second.getFiles().isEmpty() ); + } + + public void testTagAndBranchConsumer() { + String[] lines = { + "commit a6d03ee7bcec7bfd6b0fc890a277f004a1c54077 (HEAD -> main, tag: TestTag, origin/main, origin/HEAD)", + "Author: Niels Basjes ", + "Date: 2022-02-06 16:19:01 +0100", + "", + " This", + " is", + " a", + " multiline", + " comment", + "", + ":100644 100644 2019174 808473f M\tdocumentation/pom.xml", + "" + }; + GitChangeLogConsumer consumer = new GitChangeLogConsumer( null ); + + for ( String line : lines ) { + consumer.consumeLine( line ); + } + + List modifications = consumer.getModifications(); + + assertEquals( 1, modifications.size() ); + ChangeSet changeSet = modifications.get(0); + assertEquals( Collections.singletonList("TestTag"), changeSet.getTags() ); + assertEquals( "This\nis\na\nmultiline\ncomment", changeSet.getComment() ); + List files = changeSet.getFiles(); + assertEquals( 1, files.size() ); + ChangeFile changeFile = files.get(0); + assertEquals( "documentation/pom.xml", changeFile.getName() ); + } + } diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/changelog/gitlog3.gitlog b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/changelog/gitlog3.gitlog new file mode 100644 index 000000000..d6c2045b9 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/changelog/gitlog3.gitlog @@ -0,0 +1,177 @@ +commit 4fc34cfa14f2e72506187b03a492ce55ed459d4c (origin/master, origin/HEAD, master) +Author: Michael Osipov +Date: 2022-01-08 21:02:12 +0100 + + [maven-release-plugin] prepare for next development iteration + +:100644 100644 be8e3e1b a3d92db0 M maven-scm-api/pom.xml +:100644 100644 e5781e29 553ff1d7 M maven-scm-client/pom.xml +:100644 100644 ab1cc646 6548b95c M maven-scm-managers/maven-scm-manager-plexus/pom.xml +:100644 100644 2fd5532b e7570140 M maven-scm-managers/pom.xml +:100644 100644 51cfb787 3cac2d6b M maven-scm-plugin/pom.xml +:100644 100644 75f12fe0 fe860fe0 M maven-scm-providers/maven-scm-provider-hg/pom.xml +:100644 100644 c9f04356 0fb552f9 M maven-scm-providers/maven-scm-provider-local/pom.xml +:100644 100644 3d4b057e 17e1a308 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/pom.xml +:100644 100644 ae5efa48 3cf0b9e3 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml +:100644 100644 54fab957 c7f27883 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/pom.xml +:100644 100644 97c35b97 ce46192b M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml +:100644 100644 589149c6 be12b7d9 M maven-scm-providers/maven-scm-providers-git/pom.xml +:100644 100644 5a22b634 f8dbd96f M maven-scm-providers/maven-scm-providers-standard/pom.xml +:100644 100644 45c963ff 53730cd2 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/pom.xml +:100644 100644 ba3f06b8 13cb5b48 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/pom.xml +:100644 100644 de81e728 e073434e M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/pom.xml +:100644 100644 23ee449e 8b329b0f M maven-scm-providers/maven-scm-providers-svn/pom.xml +:100644 100644 12b67d0b 5f7814a8 M maven-scm-providers/pom.xml +:100644 100644 5468c16f a8315a5e M maven-scm-test/pom.xml +:100644 100644 3221e2c9 03b18176 M pom.xml + +commit 3a6d9817fe809c43eca588d7c0f4428254eae17c (tag: maven-scm-2.0.0-M1) +Author: Michael Osipov +Date: 2022-01-08 21:02:01 +0100 + + [maven-release-plugin] prepare release maven-scm-2.0.0-M1 + +:100644 100644 a845fd86 be8e3e1b M maven-scm-api/pom.xml +:100644 100644 52c4b38b e5781e29 M maven-scm-client/pom.xml +:100644 100644 1425b849 ab1cc646 M maven-scm-managers/maven-scm-manager-plexus/pom.xml +:100644 100644 bd239c1a 2fd5532b M maven-scm-managers/pom.xml +:100644 100644 4779338c 51cfb787 M maven-scm-plugin/pom.xml +:100644 100644 86988f10 75f12fe0 M maven-scm-providers/maven-scm-provider-hg/pom.xml +:100644 100644 9b8b0163 c9f04356 M maven-scm-providers/maven-scm-provider-local/pom.xml +:100644 100644 22d9e17c 3d4b057e M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/pom.xml +:100644 100644 df7d0ba4 ae5efa48 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml +:100644 100644 017b7211 54fab957 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/pom.xml +:100644 100644 04a71865 97c35b97 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml +:100644 100644 c8dbe617 589149c6 M maven-scm-providers/maven-scm-providers-git/pom.xml +:100644 100644 b4e6e76b 5a22b634 M maven-scm-providers/maven-scm-providers-standard/pom.xml +:100644 100644 7a2a4627 45c963ff M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/pom.xml +:100644 100644 d8cf0a9e ba3f06b8 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/pom.xml +:100644 100644 47c24d64 de81e728 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/pom.xml +:100644 100644 e7d1282e 23ee449e M maven-scm-providers/maven-scm-providers-svn/pom.xml +:100644 100644 e7c82f45 12b67d0b M maven-scm-providers/pom.xml +:100644 100644 9975ee65 5468c16f M maven-scm-test/pom.xml +:100644 100644 c383fda5 3221e2c9 M pom.xml + +commit 6cf3ed02e19db47f20d95dac4a24f2c40121e67f +Author: Michael Osipov +Date: 2022-01-08 20:49:53 +0100 + + Use canonical name 'Maven SCM' + +:100644 100644 8838f745 815bbf01 M src/site/apt/guide/index.apt +:100644 100644 1d10177a 603601a0 M src/site/apt/guide/new_provider.apt +:100644 100644 2b9549ea be9af836 M src/site/apt/guide/usage.apt +:100644 100644 d7a51d3a b6a6a153 M src/site/site.xml + +commit 8b64075b41174b581be3606aea08a88f9f06f73c +Author: Michael Osipov +Date: 2022-01-08 20:42:33 +0100 + + Fix issues reported by Checkstyle + +:100644 100644 a2cb04e7 3591ed00 M maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java +:100644 100644 68a22e22 2af52046 M maven-scm-api/src/main/java/org/apache/maven/scm/manager/BasicScmManager.java +:100644 100644 3da92d68 0845ad05 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java +:100644 100644 cc18268f db8fc52a M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java +:100644 100644 75935bf6 d4d87f56 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/util/SvnUtil.java + +commit 95018b3dc06938599fc463ccdc987a22c8662b71 +Author: Michael Osipov +Date: 2022-01-03 21:26:38 +0100 + + [SCM-975] Broken link to Maven SCM plugin Release Notes + +:100644 100644 308b80bd 623dc00d M maven-scm-plugin/src/site/site.xml + +commit 0336f89637fe5eb0ffe3080284d616fdda723c02 +Author: Michael Osipov +Date: 2021-12-28 23:08:40 +0100 + + Fix formatting + +:100644 100644 89ed70ab 122e5707 M src/site/apt/index.apt + +commit 4d475daf2ac407edf6b469c73f1c1c7fa4bb55ad +Author: Michael Osipov +Date: 2021-12-28 22:01:43 +0100 + + Fix Javadoc 8 issues (-Preporting) + +:100644 100644 85ba5388 c383fda5 M pom.xml + +commit 2541e0d2bd87e18bebe612dab07379e6db4fe422 +Author: Michael Osipov +Date: 2021-12-28 20:20:32 +0100 + + Fix Javadoc 8 issues + +:100644 100644 2d4c4e5d e4c40d62 M maven-scm-api/src/main/java/org/apache/maven/scm/ChangeSet.java +:100644 100644 7aa8ae4a 3c71b65f M maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameters.java +:100644 100644 1e861b24 6a3a8720 M maven-scm-api/src/main/java/org/apache/maven/scm/ScmFileStatus.java +:100644 100644 ae1ef0e8 aefd9a55 M maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java +:100644 100644 446fd65b 09fbf4d2 M maven-scm-api/src/main/java/org/apache/maven/scm/command/branch/AbstractBranchCommand.java +:100644 100644 f8723c1c a2cb04e7 M maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java +:100644 100644 e7e83238 7a545df9 M maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogSet.java +:100644 100644 d9a2d491 3a5d8000 M maven-scm-api/src/main/java/org/apache/maven/scm/command/checkin/CheckInScmResult.java +:100644 100644 a9e56487 6e3ae21b M maven-scm-api/src/main/java/org/apache/maven/scm/command/checkout/CheckOutScmResult.java +:100644 100644 a6ee259d e5089a33 M maven-scm-api/src/main/java/org/apache/maven/scm/command/list/AbstractListCommand.java +:100644 100644 a1d0ecbf daa4ac58 M maven-scm-api/src/main/java/org/apache/maven/scm/command/mkdir/AbstractMkdirCommand.java +:100644 100644 c0b4d56e 17188c91 M maven-scm-api/src/main/java/org/apache/maven/scm/command/tag/AbstractTagCommand.java +:100644 100644 996bbcbb 7e06bcdb M maven-scm-api/src/main/java/org/apache/maven/scm/manager/AbstractScmManager.java +:100644 100644 009c5270 f125b9a7 M maven-scm-api/src/main/java/org/apache/maven/scm/manager/ScmManager.java +:100644 100644 dcacd115 de30c6f4 M maven-scm-api/src/main/java/org/apache/maven/scm/provider/AbstractScmProvider.java +:100644 100644 db60ef8d d7e69e97 M maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProvider.java +:100644 100644 39f70b29 a32e76a1 M maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmProviderRepository.java +:100644 100644 e2f6634b e1bef9ee M maven-scm-api/src/main/java/org/apache/maven/scm/provider/ScmUrlUtils.java +:100644 100644 ae6aeab9 1b511797 M maven-scm-api/src/main/java/org/apache/maven/scm/repository/ScmRepository.java +:100644 100644 389d7a43 8069101d M maven-scm-api/src/main/java/org/apache/maven/scm/util/AbstractConsumer.java +:100644 100644 a18ec572 9272ae50 M maven-scm-api/src/main/java/org/apache/maven/scm/util/ConsumerUtils.java +:100644 100644 8030fc3e 907149a8 M maven-scm-api/src/main/java/org/apache/maven/scm/util/FilenameUtils.java +:100644 100644 1923dd0b 1425b849 M maven-scm-managers/maven-scm-manager-plexus/pom.xml +:100644 100644 ecc4dd2d e146b1c6 M maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BootstrapMojo.java +:100644 100644 3648e5c1 c787d8f8 M maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java +:100644 100644 64a6f980 ede3501e M maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommandConstants.java +:100644 100644 d2b9d911 20886cc5 M maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java +:100644 100644 9446b9d3 e7e19840 M maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/metadata/LocalScmMetadataUtils.java +:100644 100644 6553c051 1a242043 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java +:100644 100644 bb1dad11 4f25def9 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java +:100644 100644 7fcda9cc a831e5ba M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitCheckOutCommand.java +:100644 100644 d129ed3e c5a42560 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java +:100644 100644 c5e87c96 d01eb215 M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java +:100644 100644 6ad56ba2 cc18268f M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java +:100644 100644 0ba09b7c 9f77adec M maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java +:100644 100644 d4f1c200 dc5d9a1d M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnCommandUtils.java +:100644 100644 1ebeff4e 6656eb12 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnTagBranchUtils.java +:100644 100644 cd786173 8929635e M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/branch/SvnBranchCommand.java +:100644 100644 f5f7a172 3bcdd82d M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/tag/SvnTagCommand.java +:100644 100644 20ca5dbe 4f2a4029 M maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/list/SvnListCommandTckTest.java +:100644 100644 89471ac1 996a4fe2 M maven-scm-test/src/main/java/org/apache/maven/scm/ScmTckTestCase.java +:100644 100644 69b4d9d2 e7e8e0bd M maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/remoteinfo/AbstractRemoteInfoCommandTckTest.java +:100644 100644 8329ed55 6b07a0c4 M maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/status/StatusCommandTckTest.java +:100644 100644 006a673c 8020bba4 M maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/update/UpdateCommandTckTest.java +:100644 100644 3ea7f80b 85ba5388 M pom.xml + +commit 4c5b1d5f771b34af73b77d9a92fc1afe0b9b58e1 +Author: Michael Osipov +Date: 2021-12-27 23:37:36 +0100 + + [SCM-974] Upgrade Plexus Utils to 3.3.1 + +:100644 100644 93e5f062 3ea7f80b M pom.xml + +commit ceb0e24ffa6095195ab7acd34b7aa5c807105537 +Author: Michael Osipov +Date: 2021-12-27 22:05:17 +0100 + + [SCM-973] GitCheckInCommandNoBranchTest fails with Git 2.34.0+ + + This closes #133 + +:100644 100644 e69de29b e69de29b R100 maven-scm-plugin/src/test/resources/git/hooks/empty.txt maven-scm-plugin/src/test/resources/git/hooks/.gitkeep +:100644 100644 6068d6a5 6068d6a5 R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/info/dotgit/hooks/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/info/dotgit/hooks/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/hooks/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/hooks/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository/hooks/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository/hooks/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/hooks/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/hooks/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/objects/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/objects/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/refs/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/repository_no_branch/refs/.gitkeep +:100644 100644 e69de29b e69de29b R100 maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/hooks/empty.txt maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/hooks/.gitkeep diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f new file mode 100644 index 000000000..3d842f384 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f @@ -0,0 +1,2 @@ +xK +1P9E!tp-i1UQ"oLpq0/h"jWohR$*9V">i;܅m·t6>x)ү`zFu^ {DFLR`H7Q \ No newline at end of file diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b deleted file mode 100644 index afce44472b5513c9c2d685eb48ffb954a3600a54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 128 zcmV-`0Du2@0iBIW3IZ_@06pgweHVsw)*cY?;K^TPX_*l+4Kd>P%^SQG1w|EUZ6AQq zpGIefP#n6ab&jmD!MLKmCm%7Um8j&LW8_+iRQilfIy_`M;4Tc8*QBKi-`>*ryK(2G iNV@`h6N1H{S2$~> README.md git add -u @@ -68,6 +69,8 @@ Creation script export GIT_AUTHOR_DATE="2017-08-01T12:00:00Z" export GIT_COMMITTER_DATE="2017-08-10T12:00:00Z" git commit --amend --no-edit --date "$GIT_AUTHOR_DATE" + git tag "Tag4a" + git tag "Tag4b" echo "- 5" >> README.md git add -u diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java index 6fa3acfa5..759b1c3cc 100644 --- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java @@ -32,6 +32,9 @@ import org.junit.Test; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.hamcrest.CoreMatchers.startsWith; @@ -238,5 +241,22 @@ public void testChangeLogCommandFromVersionToStartOfRepository() assertThat( "bad commit SHA1 retrieved", logEntries.get( 1 ).getRevision(), startsWith( "e3864d9" ) ); assertThat( "bad commit SHA1 retrieved", logEntries.get( 2 ).getRevision(), startsWith( "0f1e817" ) ); assertThat( "bad commit SHA1 retrieved", logEntries.get( 3 ).getRevision(), startsWith( "e75cb5a" ) ); + + List tags4 = Arrays.asList( "Tag4a", "Tag4b" ); + List tags2 = Collections.singletonList( "Tag2" ); + List noTags = Collections.emptyList(); + + assertEquals( "Incorrect tags found", tags4, sorted( logEntries.get( 0 ).getTags() ) ); + assertEquals( "Incorrect tags found", noTags, sorted( logEntries.get( 1 ).getTags() ) ); + assertEquals( "Incorrect tags found", tags2, sorted( logEntries.get( 2 ).getTags() ) ); + assertEquals( "Incorrect tags found", noTags, sorted( logEntries.get( 3 ).getTags() ) ); + } + + private List sorted( List input ) + { + List result = new ArrayList<>( input ); + Collections.sort( result ); + return result; } + } diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java index dde42d764..8bfb2ecfd 100644 --- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java @@ -44,6 +44,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ProgressMonitor; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryBuilder; import org.eclipse.jgit.lib.StoredConfig; @@ -74,8 +75,11 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; +import static org.eclipse.jgit.lib.Constants.R_TAGS; + /** * JGit utility functions. * @@ -462,4 +466,31 @@ public RevFilter clone() } } -} + /** + * Get a list of tags that has been set in the specified commit. + * + * @param repo the repository to work on + * @param commit the commit for which we want the tags + * @return a list of tags, might be empty, and never null + */ + public static List getTags( Repository repo, RevCommit commit ) throws IOException + { + Map refList = repo.getRefDatabase().getRefs( R_TAGS ); + + RevWalk revWalk = new RevWalk( repo ); + + ObjectId commitId = commit.getId(); + List result = new ArrayList<>(); + + for ( Map.Entry refEntry : refList.entrySet() ) + { + ObjectId tagId = refEntry.getValue().getObjectId(); + RevCommit tagCommit = revWalk.parseCommit( tagId ); + if ( tagCommit != null && commitId.equals( tagCommit.getId() ) ) + { + result.add( refEntry.getKey() ); + } + } + return result; + } +} \ No newline at end of file diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java index edef9d969..bf3df71e0 100644 --- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java @@ -43,6 +43,8 @@ import java.util.Date; import java.util.List; +import static org.apache.maven.scm.provider.git.jgit.command.JGitUtils.getTags; + /** * @author Mark Struberg * @author Dominik Bartholdi (imod) @@ -108,8 +110,8 @@ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo boolean versionOnly = startVersion == null && endVersion == null && version != null; - String startRev = null; - String endRev = null; + String startRev; + String endRev; if ( versionOnly ) { @@ -135,6 +137,7 @@ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo scmChange.setComment( change.getBody() ); scmChange.setDate( change.getAuthorDate() ); scmChange.setRevision( change.getCommitHash() ); + scmChange.setTags( change.getTags() ); // X TODO scmChange.setFiles( change.get ) modifications.add( scmChange ); @@ -186,6 +189,7 @@ public List whatchanged( Repository repo, RevSort[] sortings, Strin ce.setCommitHash( c.getId().name() ); ce.setTreeHash( c.getTree().getId().name() ); + ce.setTags( getTags( repo, c ) ); // X TODO missing: file list changes.add( ce ); @@ -220,6 +224,8 @@ public static final class ChangeEntry private String body; private List files; + + private List tags; public String getCommitHash() { @@ -330,5 +336,15 @@ public void setFiles( List files ) { this.files = files; } + + public List getTags() + { + return tags; + } + + public void setTags( List tags ) + { + this.tags = tags; + } } } diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f new file mode 100644 index 000000000..3d842f384 --- /dev/null +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/27/3658439f580b289f86d407d85f60f96b9e1b1f @@ -0,0 +1,2 @@ +xK +1P9E!tp-i1UQ"oLpq0/h"jWohR$*9V">i;܅m·t6>x)ү`zFu^ {DFLR`H7Q \ No newline at end of file diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/resources/linear-changelog/objects/95/86ea07d625757c5af7fe38f6ca7d4bdae8447b deleted file mode 100644 index afce44472b5513c9c2d685eb48ffb954a3600a54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 128 zcmV-`0Du2@0iBIW3IZ_@06pgweHVsw)*cY?;K^TPX_*l+4Kd>P%^SQG1w|EUZ6AQq zpGIefP#n6ab&jmD!MLKmCm%7Um8j&LW8_+iRQilfIy_`M;4Tc8*QBKi-`>*ryK(2G iNV@`h6N1H{S2$~ changeSets = secondResult.getChangeLog().getChangeSets(); + + int expectedChangeSets = firstLogSize + 1; + boolean lastCommitIsCausedByTagging = false; + int lastCodeCommitIndex = 0; + + if ( isTagAnExtraCommit() ) + { + // This is for example Mercurial which creates an extra commit after tagging. + lastCommitIsCausedByTagging = true; + expectedChangeSets += 1; + lastCodeCommitIndex = 1; + } + + assertEquals( expectedChangeSets, changeSets.size() ); + + // Check if the tag has been retrieved again + ChangeSet changeSetWithTag = changeSets.get( lastCodeCommitIndex ); + assertEquals( Collections.singletonList( COMMIT_TAG ), changeSetWithTag.getTags() ); //Now only retrieve the changelog after timeBeforeSecondChangeLog Date currentTime = new Date(); - ChangeLogScmResult thirdResult = provider - .changeLog( getScmRepository(), fileSet, timeBeforeSecond, currentTime, 0, new ScmBranch( "" ) ); + changeLogScmRequest = new ChangeLogScmRequest( getScmRepository(), fileSet ); + changeLogScmRequest.setStartDate( timeBeforeSecond ); + changeLogScmRequest.setEndDate( currentTime ); + changeLogScmRequest.setScmBranch( new ScmBranch( "" ) ); + ChangeLogScmResult thirdResult = provider.changeLog( changeLogScmRequest ); //Thorough assert of the last result assertTrue( thirdResult.getProviderMessage(), thirdResult.isSuccess() ); - assertEquals( 1, thirdResult.getChangeLog().getChangeSets().size() ); - ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get( 0 ); - assertTrue( changeset.getDate().after( timeBeforeSecond ) ); - - assertEquals( COMMIT_MSG, changeset.getComment() ); + List thirdChangeSets = thirdResult.getChangeLog().getChangeSets(); + assertEquals( lastCommitIsCausedByTagging ? 2 : 1, thirdChangeSets.size() ); + ChangeSet changeset = thirdChangeSets.get( lastCodeCommitIndex ); + assertTrue( changeset.getDate().after( timeBeforeSecond ) ); + assertTrue( changeset.getComment().startsWith( COMMIT_MSG ) ); } }