maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject maven-scm git commit: [SCM-825] provide JGitInfoCommand fixes #48
Date Wed, 25 May 2016 11:55:03 GMT
Repository: maven-scm
Updated Branches:
  refs/heads/master 7ca04dedb -> 8b404a9ac


[SCM-825] provide JGitInfoCommand fixes #48

Signed-off-by: olivier lamy <olamy@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/8b404a9a
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/8b404a9a
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/8b404a9a

Branch: refs/heads/master
Commit: 8b404a9aca8adef0d3124b223eccf3ecc70fd08d
Parents: 7ca04de
Author: olivier lamy <olamy@apache.org>
Authored: Wed May 25 21:54:55 2016 +1000
Committer: olivier lamy <olamy@apache.org>
Committed: Wed May 25 21:54:55 2016 +1000

----------------------------------------------------------------------
 .../scm/provider/git/jgit/JGitScmProvider.java  |  3 +-
 .../git/jgit/command/info/JGitInfoCommand.java  | 77 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/8b404a9a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
index 80e06e9..b155dea 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
@@ -34,6 +34,7 @@ import org.apache.maven.scm.provider.git.jgit.command.changelog.JGitChangeLogCom
 import org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand;
 import org.apache.maven.scm.provider.git.jgit.command.checkout.JGitCheckOutCommand;
 import org.apache.maven.scm.provider.git.jgit.command.diff.JGitDiffCommand;
+import org.apache.maven.scm.provider.git.jgit.command.info.JGitInfoCommand;
 import org.apache.maven.scm.provider.git.jgit.command.list.JGitListCommand;
 import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
 import org.apache.maven.scm.provider.git.jgit.command.status.JGitStatusCommand;
@@ -150,7 +151,7 @@ public class JGitScmProvider
      */
     public GitCommand getInfoCommand()
     {
-        throw new UnsupportedOperationException( "getInfoCommand" );
+        return new JGitInfoCommand();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/8b404a9a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java
----------------------------------------------------------------------
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/info/JGitInfoCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java
new file mode 100644
index 0000000..488093e
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java
@@ -0,0 +1,77 @@
+package org.apache.maven.scm.provider.git.jgit.command.info;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.io.File;
+import java.util.Collections;
+
+import org.apache.maven.scm.CommandParameters;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.AbstractCommand;
+import org.apache.maven.scm.command.info.InfoItem;
+import org.apache.maven.scm.command.info.InfoScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.ObjectId;
+
+/**
+ * @since 1.9.5
+ */
+public class JGitInfoCommand
+    extends AbstractCommand
+    implements GitCommand
+{
+    @Override
+    protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
+                                        CommandParameters parameters )
+        throws ScmException
+    {
+        Git git = null;
+        try
+        {
+            File basedir = fileSet.getBasedir();
+
+            git = Git.open( basedir );
+
+            ObjectId objectId = git.getRepository().resolve( "HEAD" );
+
+            InfoItem infoItem = new InfoItem();
+            infoItem.setRevision( StringUtils.trim( objectId.name() ) );
+            infoItem.setURL( basedir.getPath() );
+
+            return new InfoScmResult( Collections.singletonList( infoItem ),
+                                      new ScmResult( "JGit.resolve(HEAD)", "", objectId.toString(),
true ) );
+        }
+        catch ( Exception e )
+        {
+            throw new ScmException( "JGit resolve failure!", e );
+        }
+        finally
+        {
+            JGitUtils.closeRepo( git );
+        }
+    }
+}


Mime
View raw message