You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2024/03/27 17:18:00 UTC

[jira] [Commented] (SCM-914) InfoItem.lastChangedDate is leaky abstraction

    [ https://issues.apache.org/jira/browse/SCM-914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17831474#comment-17831474 ] 

ASF GitHub Bot commented on SCM-914:
------------------------------------

kwin commented on code in PR #193:
URL: https://github.com/apache/maven-scm/pull/193#discussion_r1541522843


##########
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:
##########
@@ -43,31 +49,34 @@ public class GitInfoCommand extends AbstractCommand implements GitCommand {
     protected ScmResult executeCommand(
             ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
 
-        GitInfoConsumer consumer = new GitInfoConsumer(fileSet);
-        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
-
-        Commandline cli = createCommandLine(repository, fileSet, parameters);
+        Commandline baseCli = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "log");
+        baseCli.createArg().setValue("-1"); // only most recent commit matters
+        baseCli.createArg().setValue("--no-merges"); // skip merge commits
+        baseCli.addArg(GitInfoConsumer.getFormatArgument());
 
-        int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr);
-        if (exitCode != 0) {
-            return new InfoScmResult(cli.toString(), "The git rev-parse command failed.", stderr.getOutput(), false);
+        List<InfoItem> infoItems = new LinkedList<>();
+        if (fileSet.getFileList().isEmpty()) {
+            infoItems.add(executeInfoCommand(baseCli, parameters, fileSet.getBasedir()));
+        } else {
+            // iterate over files
+            for (File scmFile : fileSet.getFileList()) {
+                Commandline cliClone = (Commandline) baseCli.clone();
+                cliClone.createArg().setFile(scmFile);
+                infoItems.add(executeInfoCommand(cliClone, parameters, scmFile));
+            }
         }
-        return new InfoScmResult(cli.toString(), consumer.getInfoItems());
+        return new InfoScmResult(baseCli.toString(), infoItems);
     }
 
-    public static Commandline createCommandLine(
-            ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
-        Commandline cli = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "rev-parse");
-        cli.createArg().setValue("--verify");
-        final int revLength = getRevisionLength(parameters);
-        if (revLength > NO_REVISION_LENGTH) // set the --short key only if revision length parameter is passed and
-        // different from -1
-        {
-            cli.createArg().setValue("--short=" + revLength);
+    protected InfoItem executeInfoCommand(Commandline cli, CommandParameters parameters, File scmFile)
+            throws ScmException {
+        GitInfoConsumer consumer = new GitInfoConsumer(scmFile.toPath(), getRevisionLength(parameters));
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+        int exitCode = GitCommandLineUtils.execute(cli, consumer, stderr);
+        if (exitCode != 0) {
+            throw new ScmException("The git log command failed:" + cli.toString() + " returned " + stderr.getOutput());

Review Comment:
   fixed





> InfoItem.lastChangedDate is leaky abstraction
> ---------------------------------------------
>
>                 Key: SCM-914
>                 URL: https://issues.apache.org/jira/browse/SCM-914
>             Project: Maven SCM
>          Issue Type: Bug
>          Components: maven-scm-api
>            Reporter: Tobias Gruetzmacher
>            Assignee: Konrad Windszus
>            Priority: Minor
>
> I was looking into implementing [https://github.com/mojohaus/buildnumber-maven-plugin/pull/16] in a sane way, but had to conclude that InfoItem.lastChangedDate is unfortunately just a string and not a Data, so will leak the console output of different providers to the user.
> Does anybody see a sane way to fix this API and create a sane abstraction for different SCMs? If yes, I would try to go ahead with the following tasks:
>  # Fix InfoItem, so that lastChangedDate is a Date
>  # Fix the current providers filling this field (svnexe and svnjava AFAICS - aside: why is svnjava not part of the maven-scm repository?)
>  # Implement this feature for at least gitexe (and maybe jgit) so I can use it for my usecase
> Ideas, comments?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)