You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2013/07/15 13:24:54 UTC
[43/50] [abbrv] git commit: move jgit provider to scm-project
move jgit provider to scm-project
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/e86351f4
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/e86351f4
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/e86351f4
Branch: refs/heads/master
Commit: e86351f4bae7243f2f1c655c2ae0411fdb7b3499
Parents: 4451711
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 12 13:08:55 2013 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 12 13:08:55 2013 +0200
----------------------------------------------------------------------
.gitignore | 3 -
README.md | 103 -----
.../maven-scm-provider-jgit/.gitignore | 3 +
.../maven-scm-provider-jgit/README.md | 103 +++++
.../maven-scm-provider-jgit/pom.xml | 97 +++++
.../scm/provider/git/jgit/JGitScmProvider.java | 193 +++++++++
.../provider/git/jgit/command/JGitUtils.java | 399 +++++++++++++++++++
.../git/jgit/command/add/JGitAddCommand.java | 80 ++++
.../jgit/command/blame/JGitBlameCommand.java | 75 ++++
.../jgit/command/branch/JGitBranchCommand.java | 137 +++++++
.../command/changelog/JGitChangeLogCommand.java | 287 +++++++++++++
.../command/checkin/JGitCheckInCommand.java | 130 ++++++
.../command/checkout/JGitCheckOutCommand.java | 190 +++++++++
.../git/jgit/command/diff/JGitDiffCommand.java | 135 +++++++
.../git/jgit/command/list/JGitListCommand.java | 76 ++++
.../remoteinfo/JGitRemoteInfoCommand.java | 85 ++++
.../jgit/command/status/JGitStatusCommand.java | 84 ++++
.../git/jgit/command/tag/JGitTagCommand.java | 118 ++++++
.../branch/JGitBranchCommandTckTest.java | 38 ++
.../changelog/JGitChangeLogCommandTckTest.java | 39 ++
.../checkin/JGitCheckInCommandTckTest.java | 40 ++
.../checkout/JGitCheckOutCommandTckTest.java | 41 ++
.../JGitRemoteInfoCommandTckTest.java | 42 ++
.../status/JGitStatusCommandTckTest.java | 40 ++
.../jgit/command/tag/JGitTagCommandTckTest.java | 42 ++
.../src/test/resources/repository/HEAD | 1 +
.../src/test/resources/repository/config | 4 +
.../src/test/resources/repository/description | 1 +
.../resources/repository/hooks/applypatch-msg | 15 +
.../repository/hooks/applypatch-msg.sample | 15 +
.../test/resources/repository/hooks/commit-msg | 21 +
.../repository/hooks/commit-msg.sample | 24 ++
.../test/resources/repository/hooks/post-commit | 8 +
.../repository/hooks/post-commit.sample | 8 +
.../resources/repository/hooks/post-receive | 16 +
.../repository/hooks/post-receive.sample | 15 +
.../test/resources/repository/hooks/post-update | 8 +
.../repository/hooks/post-update.sample | 8 +
.../resources/repository/hooks/pre-applypatch | 14 +
.../repository/hooks/pre-applypatch.sample | 14 +
.../test/resources/repository/hooks/pre-commit | 70 ++++
.../repository/hooks/pre-commit.sample | 18 +
.../test/resources/repository/hooks/pre-rebase | 150 +++++++
.../repository/hooks/pre-rebase.sample | 169 ++++++++
.../repository/hooks/prepare-commit-msg.sample | 36 ++
.../src/test/resources/repository/hooks/update | 78 ++++
.../resources/repository/hooks/update.sample | 107 +++++
.../src/test/resources/repository/info/exclude | 6 +
.../src/test/resources/repository/logs/HEAD | 3 +
.../resources/repository/logs/refs/heads/master | 3 +
.../repository/logs/refs/remotes/origin/master | 1 +
.../17/e953589369a48dcb0a0cbad084a76ef852cd11 | Bin 0 -> 37 bytes
.../1d/308c3b92eb0df9c0dc76436d50edfd0ca41d18 | Bin 0 -> 199 bytes
.../3b/459fa9451a94fc1acd10e2e29ab73d93eb816d | Bin 0 -> 75 bytes
.../3b/d305c57c635aead10cf59f7c1dc51af03edaf7 | Bin 0 -> 116 bytes
.../3c/f7bb86c15554148bf5b0b12bfd639e54a77e58 | Bin 0 -> 46 bytes
.../61/4a3fd04313593d67f4154855a06941046326b3 | Bin 0 -> 23 bytes
.../61/a0d22b023d6e31894d736cca8c1a47b6edd822 | Bin 0 -> 45 bytes
.../92/09a983605d6e43e5cf841a1ea18a1914bb7407 | Bin 0 -> 54 bytes
.../92/f139dfec4d1dfb79c3cd2f94e83bf13129668b | 1 +
.../94/d3d586e355f318d67e3da6bb16a91be7aad1a7 | Bin 0 -> 28 bytes
.../9e/131cfc732b0d9f42b9b712a528d0632d9bcca7 | Bin 0 -> 43 bytes
.../b5/3306f849b69ef0459ddf5cccff06b5fbb08c23 | Bin 0 -> 36 bytes
.../ba/a229a9193371fad604444f64c4f26f8ff702f3 | 1 +
.../ba/cd4ee105073117b30e5dcdba5150373b6b53c6 | Bin 0 -> 60 bytes
.../c3/8b0351660113545db270ba6918cc22a9eb17ce | Bin 0 -> 46 bytes
.../c5/1dcd33e7b71897603c203b5e0afc1d75f70051 | Bin 0 -> 147 bytes
.../dc/4204852765c12f398ef4a5fbcabf23cf17a183 | Bin 0 -> 116 bytes
.../f7/1429f9ff9214a546b438c611ae942c9cf5a49e | Bin 0 -> 46 bytes
.../fd/39fa3de0f63bc5c78eca219e74e0a8531bd3e6 | Bin 0 -> 24 bytes
.../fe/a16119a5b4ec0562d4f65b4237314250773bf8 | Bin 0 -> 27 bytes
.../test/resources/repository/refs/heads/master | 1 +
.../repository/refs/remotes/origin/HEAD | 1 +
.../repository/refs/remotes/origin/master | 1 +
pom.xml | 97 -----
.../scm/provider/git/jgit/JGitScmProvider.java | 193 ---------
.../provider/git/jgit/command/JGitUtils.java | 399 -------------------
.../git/jgit/command/add/JGitAddCommand.java | 80 ----
.../jgit/command/blame/JGitBlameCommand.java | 75 ----
.../jgit/command/branch/JGitBranchCommand.java | 137 -------
.../command/changelog/JGitChangeLogCommand.java | 287 -------------
.../command/checkin/JGitCheckInCommand.java | 130 ------
.../command/checkout/JGitCheckOutCommand.java | 190 ---------
.../git/jgit/command/diff/JGitDiffCommand.java | 135 -------
.../git/jgit/command/list/JGitListCommand.java | 76 ----
.../remoteinfo/JGitRemoteInfoCommand.java | 85 ----
.../jgit/command/status/JGitStatusCommand.java | 84 ----
.../git/jgit/command/tag/JGitTagCommand.java | 118 ------
.../branch/JGitBranchCommandTckTest.java | 38 --
.../changelog/JGitChangeLogCommandTckTest.java | 39 --
.../checkin/JGitCheckInCommandTckTest.java | 40 --
.../checkout/JGitCheckOutCommandTckTest.java | 41 --
.../JGitRemoteInfoCommandTckTest.java | 42 --
.../status/JGitStatusCommandTckTest.java | 40 --
.../jgit/command/tag/JGitTagCommandTckTest.java | 42 --
src/test/resources/repository/HEAD | 1 -
src/test/resources/repository/config | 4 -
src/test/resources/repository/description | 1 -
.../resources/repository/hooks/applypatch-msg | 15 -
.../repository/hooks/applypatch-msg.sample | 15 -
src/test/resources/repository/hooks/commit-msg | 21 -
.../repository/hooks/commit-msg.sample | 24 --
src/test/resources/repository/hooks/post-commit | 8 -
.../repository/hooks/post-commit.sample | 8 -
.../resources/repository/hooks/post-receive | 16 -
.../repository/hooks/post-receive.sample | 15 -
src/test/resources/repository/hooks/post-update | 8 -
.../repository/hooks/post-update.sample | 8 -
.../resources/repository/hooks/pre-applypatch | 14 -
.../repository/hooks/pre-applypatch.sample | 14 -
src/test/resources/repository/hooks/pre-commit | 70 ----
.../repository/hooks/pre-commit.sample | 18 -
src/test/resources/repository/hooks/pre-rebase | 150 -------
.../repository/hooks/pre-rebase.sample | 169 --------
.../repository/hooks/prepare-commit-msg.sample | 36 --
src/test/resources/repository/hooks/update | 78 ----
.../resources/repository/hooks/update.sample | 107 -----
src/test/resources/repository/info/exclude | 6 -
src/test/resources/repository/logs/HEAD | 3 -
.../resources/repository/logs/refs/heads/master | 3 -
.../repository/logs/refs/remotes/origin/master | 1 -
.../17/e953589369a48dcb0a0cbad084a76ef852cd11 | Bin 37 -> 0 bytes
.../1d/308c3b92eb0df9c0dc76436d50edfd0ca41d18 | Bin 199 -> 0 bytes
.../3b/459fa9451a94fc1acd10e2e29ab73d93eb816d | Bin 75 -> 0 bytes
.../3b/d305c57c635aead10cf59f7c1dc51af03edaf7 | Bin 116 -> 0 bytes
.../3c/f7bb86c15554148bf5b0b12bfd639e54a77e58 | Bin 46 -> 0 bytes
.../61/4a3fd04313593d67f4154855a06941046326b3 | Bin 23 -> 0 bytes
.../61/a0d22b023d6e31894d736cca8c1a47b6edd822 | Bin 45 -> 0 bytes
.../92/09a983605d6e43e5cf841a1ea18a1914bb7407 | Bin 54 -> 0 bytes
.../92/f139dfec4d1dfb79c3cd2f94e83bf13129668b | 1 -
.../94/d3d586e355f318d67e3da6bb16a91be7aad1a7 | Bin 28 -> 0 bytes
.../9e/131cfc732b0d9f42b9b712a528d0632d9bcca7 | Bin 43 -> 0 bytes
.../b5/3306f849b69ef0459ddf5cccff06b5fbb08c23 | Bin 36 -> 0 bytes
.../ba/a229a9193371fad604444f64c4f26f8ff702f3 | 1 -
.../ba/cd4ee105073117b30e5dcdba5150373b6b53c6 | Bin 60 -> 0 bytes
.../c3/8b0351660113545db270ba6918cc22a9eb17ce | Bin 46 -> 0 bytes
.../c5/1dcd33e7b71897603c203b5e0afc1d75f70051 | Bin 147 -> 0 bytes
.../dc/4204852765c12f398ef4a5fbcabf23cf17a183 | Bin 116 -> 0 bytes
.../f7/1429f9ff9214a546b438c611ae942c9cf5a49e | Bin 46 -> 0 bytes
.../fd/39fa3de0f63bc5c78eca219e74e0a8531bd3e6 | Bin 24 -> 0 bytes
.../fe/a16119a5b4ec0562d4f65b4237314250773bf8 | Bin 27 -> 0 bytes
src/test/resources/repository/refs/heads/master | 1 -
.../repository/refs/remotes/origin/HEAD | 1 -
.../repository/refs/remotes/origin/master | 1 -
144 files changed, 3292 insertions(+), 3292 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 4bfa550..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-.idea/
-*.iml
-target/
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
deleted file mode 100644
index 890b676..0000000
--- a/README.md
+++ /dev/null
@@ -1,103 +0,0 @@
-maven-scm-provider-jgit
-===
-
-This scm provider implementation allows the usage of git with the release and scm plugin without having to install a nativ git client.
-This implementation uses username and password instead of a public/private keys to authenticate the requests to a remote repository like GitHub.
-
-Configuration
----
-
-Usage with the `maven-release-plugin`
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <providerImplementations>
- <git>jgit</git>
- </providerImplementations>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.scm</groupId>
- <artifactId>maven-scm-provider-jgit</artifactId>
- <version>1.8.1</version>
- </dependency>
- </dependencies>
- </plugin>
-
-Usage with the `maven-scm-plugin`
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-scm-plugin</artifactId>
- <version>1.8.1</version>
- <configuration>
- <providerImplementations>
- <git>jgit</git>
- </providerImplementations>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.scm</groupId>
- <artifactId>maven-scm-provider-jgit</artifactId>
- <version>${jgit.provider.version}</version>
- </dependency>
- </dependencies>
- </plugin>
-
-Examples
-____
-changelog
-
- mvn org.apache.maven.plugins:maven-scm-plugin:1.8.1:changelog
-
-release
-
- mvn release:prepare release:perform -Dresume=false -Dusername=XXX -Dpassword=XXX
-
-
-
-
-
-Features
----
-
-this is a brief list of the supported maven-scm-provider-jgit's integration status with regard to some core maven plugins
-
-
-maven-scm-plugin
----
-
-| goal | implemented?|
-| ------------- |:-------------:|
-| scm:list | yes |
-| scm:tag | yes |
-| scm:bootstrap | no |
-| scm:export | no |
-| scm:update | no |
-| scm:status | yes |
-| scm:edit | no |
-| scm:changelog | yes |
-| scm:add | yes |
-| scm:unedit | no |
-| scm:validate | yes |
-| scm:branch | yes |
-| scm:checkin | yes |
-| scm:checkout | yes |
-| scm:diff | yes |
-| scm:blame | yes |
-| scm:remoteinfo | yes |
-
-maven-release-plugin
----
-
-| goal | implemented?|
-| ------------- |:-------------:|
-| release:clean | yes |
-| release:prepare | yes |
-| release:rollback | no |
-| release:perform | yes |
-| release:stage | no |
-| release:branch | yes |
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/.gitignore
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/.gitignore b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/.gitignore
new file mode 100644
index 0000000..4bfa550
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/.gitignore
@@ -0,0 +1,3 @@
+.idea/
+*.iml
+target/
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/README.md
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/README.md b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/README.md
new file mode 100644
index 0000000..890b676
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/README.md
@@ -0,0 +1,103 @@
+maven-scm-provider-jgit
+===
+
+This scm provider implementation allows the usage of git with the release and scm plugin without having to install a nativ git client.
+This implementation uses username and password instead of a public/private keys to authenticate the requests to a remote repository like GitHub.
+
+Configuration
+---
+
+Usage with the `maven-release-plugin`
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <providerImplementations>
+ <git>jgit</git>
+ </providerImplementations>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-jgit</artifactId>
+ <version>1.8.1</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+Usage with the `maven-scm-plugin`
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-plugin</artifactId>
+ <version>1.8.1</version>
+ <configuration>
+ <providerImplementations>
+ <git>jgit</git>
+ </providerImplementations>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-jgit</artifactId>
+ <version>${jgit.provider.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+Examples
+____
+changelog
+
+ mvn org.apache.maven.plugins:maven-scm-plugin:1.8.1:changelog
+
+release
+
+ mvn release:prepare release:perform -Dresume=false -Dusername=XXX -Dpassword=XXX
+
+
+
+
+
+Features
+---
+
+this is a brief list of the supported maven-scm-provider-jgit's integration status with regard to some core maven plugins
+
+
+maven-scm-plugin
+---
+
+| goal | implemented?|
+| ------------- |:-------------:|
+| scm:list | yes |
+| scm:tag | yes |
+| scm:bootstrap | no |
+| scm:export | no |
+| scm:update | no |
+| scm:status | yes |
+| scm:edit | no |
+| scm:changelog | yes |
+| scm:add | yes |
+| scm:unedit | no |
+| scm:validate | yes |
+| scm:branch | yes |
+| scm:checkin | yes |
+| scm:checkout | yes |
+| scm:diff | yes |
+| scm:blame | yes |
+| scm:remoteinfo | yes |
+
+maven-release-plugin
+---
+
+| goal | implemented?|
+| ------------- |:-------------:|
+| release:clean | yes |
+| release:prepare | yes |
+| release:rollback | no |
+| release:perform | yes |
+| release:stage | no |
+| release:branch | yes |
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml
new file mode 100644
index 0000000..6a0e2f4
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-providers-git</artifactId>
+ <version>1.9-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>maven-scm-provider-jgit</artifactId>
+
+ <name>Maven SCM Git Provider - JGit Impl.</name>
+ <description>
+ JGIT implementation for SCM Git Provider.
+ see http://repo.or.cz/w/jgit.git
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>regexp</groupId>
+ <artifactId>regexp</artifactId>
+ </dependency>
+
+ <!-- Test -->
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-git-commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-gittest</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jgit</groupId>
+ <artifactId>org.eclipse.jgit</artifactId>
+ <version>2.3.1.201302201838-r</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-metadata</artifactId>
+ <executions>
+ <execution>
+ <id>create-component-descriptor</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>generate-metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>nothing</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/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
new file mode 100644
index 0000000..2e1f3ab
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java
@@ -0,0 +1,193 @@
+package org.apache.maven.scm.provider.git.jgit;
+
+/*
+ * 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 org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.info.InfoScmResult;
+import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.command.info.GitInfoItem;
+import org.apache.maven.scm.provider.git.jgit.command.add.JGitAddCommand;
+import org.apache.maven.scm.provider.git.jgit.command.blame.JGitBlameCommand;
+import org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
+import org.apache.maven.scm.provider.git.jgit.command.changelog.JGitChangeLogCommand;
+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.list.JGitListCommand;
+import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
+import org.apache.maven.scm.provider.git.jgit.command.status.JGitStatusCommand;
+import org.apache.maven.scm.provider.git.jgit.command.tag.JGitTagCommand;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitScmProvider.java 894145 2009-12-28 10:13:39Z struberg $
+ * @plexus.component role="org.apache.maven.scm.provider.ScmProvider"
+ * role-hint="jgit"
+ */
+public class JGitScmProvider
+ extends AbstractGitScmProvider
+{
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getAddCommand()
+ {
+ return new JGitAddCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getBranchCommand()
+ {
+ return new JGitBranchCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getChangeLogCommand()
+ {
+ return new JGitChangeLogCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getCheckInCommand()
+ {
+ return new JGitCheckInCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getCheckOutCommand()
+ {
+ return new JGitCheckOutCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getDiffCommand()
+ {
+ return new JGitDiffCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getExportCommand()
+ {
+ throw new UnsupportedOperationException( "getExportCommand" );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getRemoveCommand()
+ {
+ throw new UnsupportedOperationException( "getRemoveCommand" );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getStatusCommand()
+ {
+ return new JGitStatusCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getTagCommand()
+ {
+ return new JGitTagCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getUpdateCommand()
+ {
+ throw new UnsupportedOperationException( "getUpdateCommand" );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getListCommand()
+ {
+ return new JGitListCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public GitCommand getInfoCommand()
+ {
+ throw new UnsupportedOperationException( "getInfoCommand" );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String getRepositoryURL( File path )
+ throws ScmException
+ {
+ // Note: I need to supply just 1 absolute path, but ScmFileSet won't let
+ // me without
+ // a basedir (which isn't used here anyway), so use a dummy file.
+ InfoScmResult result = info( null, new ScmFileSet( new File( "" ), path ), null );
+
+ if ( result.getInfoItems().size() != 1 )
+ {
+ throw new ScmRepositoryException(
+ "Cannot find URL: " + ( result.getInfoItems().size() == 0 ? "no" : "multiple" )
+ + " items returned by the info command" );
+ }
+
+ return ( (GitInfoItem) result.getInfoItems().get( 0 ) ).getURL();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getBlameCommand()
+ {
+ return new JGitBlameCommand();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected GitCommand getRemoteInfoCommand()
+ {
+ return new JGitRemoteInfoCommand();
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.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/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
new file mode 100644
index 0000000..f6aa328
--- /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/JGitUtils.java
@@ -0,0 +1,399 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.jgit.api.AddCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.InvalidRemoteException;
+import org.eclipse.jgit.api.errors.NoFilepatternException;
+import org.eclipse.jgit.api.errors.TransportException;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.eclipse.jgit.diff.DiffFormatter;
+import org.eclipse.jgit.diff.RawTextComparator;
+import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.lib.TextProgressMonitor;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevFlag;
+import org.eclipse.jgit.revwalk.RevSort;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.PushResult;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.RemoteRefUpdate;
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.eclipse.jgit.util.io.DisabledOutputStream;
+
+/*
+ * 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.
+ */
+
+/**
+ * JGit utility functions.
+ *
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitUtils.java 894145 2009-12-28 10:13:39Z struberg $
+ */
+public class JGitUtils
+{
+
+ private JGitUtils()
+ {
+ // no op
+ }
+
+ /**
+ * Construct a logging ProgressMonitor for all JGit operations.
+ *
+ * @param logger
+ * @return a ProgressMonitor for use
+ */
+ public static ProgressMonitor getMonitor( ScmLogger logger )
+ {
+ // X TODO write an own ProgressMonitor which logs to ScmLogger!
+ return new TextProgressMonitor();
+ }
+
+ /**
+ * Prepares the in memory configuration of git to connect to the configured
+ * repository. It configures the following settings in memory: <br />
+ * <li>push url</li> <li>fetch url</li>
+ * <p/>
+ *
+ * @param logger used to log some details
+ * @param git the instance to configure (only in memory, not saved)
+ * @param repository the repo config to be used
+ * @return {@link CredentialsProvider} in case there are credentials
+ * informations configured in the repository.
+ */
+ public static CredentialsProvider prepareSession( ScmLogger logger, Git git, GitScmProviderRepository repository )
+ {
+ StoredConfig config = git.getRepository().getConfig();
+ config.setString( "remote", "origin", "url", repository.getFetchUrl() );
+ config.setString( "remote", "origin", "pushURL", repository.getPushUrl() );
+
+ // make sure we do not log any passwords to the output
+ String password =
+ StringUtils.isNotBlank( repository.getPassword() ) ? repository.getPassword().trim() : "no-pwd-defined";
+ logger.info( "fetch url: " + repository.getFetchUrl().replace( password, "******" ) );
+ logger.info( "push url: " + repository.getPushUrl().replace( password, "******" ) );
+ return getCredentials( repository );
+ }
+
+ /**
+ * Creates a credentials provider from the information passed in the
+ * repository. Current implementation supports: <br />
+ * <li>UserName/Password</li>
+ * <p/>
+ *
+ * @param repository the config to get the details from
+ * @return <code>null</code> if there is not enough info to create a
+ * provider with
+ */
+ public static CredentialsProvider getCredentials( GitScmProviderRepository repository )
+ {
+ if ( StringUtils.isNotBlank( repository.getUser() ) && StringUtils.isNotBlank( repository.getPassword() ) )
+ {
+ return new UsernamePasswordCredentialsProvider( repository.getUser().trim(),
+ repository.getPassword().trim() );
+ }
+ return null;
+ }
+
+ public static Iterable<PushResult> push( ScmLogger logger, Git git, GitScmProviderRepository repo, RefSpec refSpec )
+ throws GitAPIException, InvalidRemoteException, TransportException
+ {
+ CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo );
+ Iterable<PushResult> pushResultList =
+ git.push().setCredentialsProvider( credentials ).setRefSpecs( refSpec ).call();
+ for ( PushResult pushResult : pushResultList )
+ {
+ Collection<RemoteRefUpdate> ru = pushResult.getRemoteUpdates();
+ for ( RemoteRefUpdate remoteRefUpdate : ru )
+ {
+ logger.info( remoteRefUpdate.getStatus() + " - " + remoteRefUpdate.toString() );
+ }
+ }
+ return pushResultList;
+ }
+
+ /**
+ * Does the Repository have any commits?
+ *
+ * @param repo
+ * @return false if there are no commits
+ */
+ public static boolean hasCommits( Repository repo )
+ {
+ if ( repo != null && repo.getDirectory().exists() )
+ {
+ return ( new File( repo.getDirectory(), "objects" ).list().length > 2 ) || (
+ new File( repo.getDirectory(), "objects/pack" ).list().length > 0 );
+ }
+ return false;
+ }
+
+ /**
+ * get a list of all files in the given commit
+ *
+ * @param repository the repo
+ * @param commit the commit to get the files from
+ * @return a list of files included in the commit
+ * @throws MissingObjectException
+ * @throws IncorrectObjectTypeException
+ * @throws CorruptObjectException
+ * @throws IOException
+ */
+ public static List<ScmFile> getFilesInCommit( Repository repository, RevCommit commit )
+ throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
+ {
+ List<ScmFile> list = new ArrayList<ScmFile>();
+ if ( JGitUtils.hasCommits( repository ) )
+ {
+ RevWalk rw = new RevWalk(repository);
+ RevCommit realParant = commit.getParentCount() > 0 ? commit.getParent(0) : commit;
+ RevCommit parent = rw.parseCommit(realParant.getId());
+ DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
+ df.setRepository(repository);
+ df.setDiffComparator(RawTextComparator.DEFAULT);
+ df.setDetectRenames(true);
+ List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
+ for (DiffEntry diff : diffs) {
+ list.add( new ScmFile( diff.getNewPath(), ScmFileStatus.CHECKED_IN ));
+ }
+ rw.release();
+ }
+ return list;
+ }
+
+ /**
+ * Translate a {@code FileStatus} in the matching {@code ScmFileStatus}.
+ *
+ * @param changeType
+ * @return the matching ScmFileStatus
+ * @throws ScmException if the given Status cannot be translated
+ */
+ public static ScmFileStatus getScmFileStatus( ChangeType changeType )
+ {
+ switch ( changeType )
+ {
+ case ADD:
+ return ScmFileStatus.ADDED;
+ case MODIFY:
+ return ScmFileStatus.MODIFIED;
+ case DELETE:
+ return ScmFileStatus.DELETED;
+ case RENAME:
+ return ScmFileStatus.RENAMED;
+ case COPY:
+ return ScmFileStatus.COPIED;
+ default:
+ return ScmFileStatus.UNKNOWN;
+ }
+ }
+
+ /**
+ * Adds all files in the given fileSet to the repository.
+ *
+ * @param git the repo to add the files to
+ * @param fileSet the set of files within the workspace, the files are added
+ * relative to the basedir of this fileset
+ * @return a list of added files
+ * @throws GitAPIException
+ * @throws NoFilepatternException
+ */
+ public static List<ScmFile> addAllFiles( Git git, ScmFileSet fileSet )
+ throws GitAPIException, NoFilepatternException
+ {
+ URI baseUri = fileSet.getBasedir().toURI();
+ AddCommand add = git.add();
+ for ( File file : fileSet.getFileList() )
+ {
+ if (!file.isAbsolute())
+ {
+ file = new File( fileSet.getBasedir().getPath(), file.getPath() );
+ }
+
+ if ( file.exists() )
+ {
+ String path = relativize( baseUri, file );
+ add.addFilepattern( path );
+ add.addFilepattern( file.getAbsolutePath() );
+ }
+ }
+ add.call();
+
+ Status status = git.status().call();
+
+ Set<String> allInIndex = new HashSet<String>();
+ allInIndex.addAll(status.getAdded());
+ allInIndex.addAll(status.getChanged());
+
+ // System.out.println("All in index: "+allInIndex.size());
+
+ List<ScmFile> addedFiles = new ArrayList<ScmFile>( allInIndex.size() );
+
+ // rewrite all detected files to now have status 'checked_in'
+ for ( String entry : allInIndex )
+ {
+ ScmFile scmfile = new ScmFile( entry, ScmFileStatus.ADDED );
+
+ // if a specific fileSet is given, we have to check if the file is
+ // really tracked
+ for ( Iterator<File> itfl = fileSet.getFileList().iterator(); itfl.hasNext(); )
+ {
+ String path = relativize( baseUri, itfl.next() );
+ if ( path.equals( scmfile.getPath() ) )
+ {
+ addedFiles.add( scmfile );
+ }
+ }
+ }
+ return addedFiles;
+ }
+
+ private static String relativize( URI baseUri, File f )
+ {
+ String path = f.getPath();
+ if ( f.isAbsolute() )
+ {
+ path = baseUri.relativize( new File( path ).toURI() ).getPath();
+ }
+ return path;
+ }
+
+ /**
+ * Get a list of commits between two revisions.
+ *
+ * @param repo the repository to work on
+ * @param sortings sorting
+ * @param fromRev start revision
+ * @param toRev if null, falls back to head
+ * @param fromDate from which date on
+ * @param toDate until which date
+ * @param maxLines max number of lines
+ * @return a list of commits, might be empty, but never <code>null</code>
+ * @throws IOException
+ * @throws MissingObjectException
+ * @throws IncorrectObjectTypeException
+ */
+ public static List<RevCommit> getRevCommits( Repository repo, RevSort[] sortings, String fromRev, String toRev,
+ Date fromDate, Date toDate, int maxLines )
+ throws IOException, MissingObjectException, IncorrectObjectTypeException
+ {
+ List<RevCommit> revs = new ArrayList<RevCommit>();
+ RevWalk walk = new RevWalk( repo );
+
+ ObjectId fromRevId = fromRev != null ? repo.resolve( fromRev ) : null;
+ ObjectId toRevId = toRev != null ? repo.resolve( toRev ) : null;
+
+ if ( sortings == null || sortings.length == 0 )
+ {
+ sortings = new RevSort[]{ RevSort.TOPO, RevSort.COMMIT_TIME_DESC };
+ }
+
+ for ( final RevSort s : sortings )
+ {
+ walk.sort( s, true );
+ }
+
+ if ( fromDate != null && toDate != null )
+ {
+ walk.setRevFilter( CommitTimeRevFilter.between( fromDate, toDate ) );
+ }
+ else
+ {
+ if ( fromDate != null )
+ {
+ walk.setRevFilter( CommitTimeRevFilter.after( fromDate ) );
+ }
+
+ if ( toDate != null )
+ {
+ walk.setRevFilter( CommitTimeRevFilter.before( toDate ) );
+ }
+ }
+
+ if ( fromRevId != null )
+ {
+ RevCommit c = walk.parseCommit( fromRevId );
+ c.add( RevFlag.UNINTERESTING );
+ RevCommit real = walk.parseCommit( c );
+ walk.markUninteresting( real );
+ }
+
+ if ( toRevId != null )
+ {
+ RevCommit c = walk.parseCommit( toRevId );
+ c.remove( RevFlag.UNINTERESTING );
+ RevCommit real = walk.parseCommit( c );
+ walk.markStart( real );
+ }
+ else
+ {
+ final ObjectId head = repo.resolve( Constants.HEAD );
+ if ( head == null )
+ {
+ throw new RuntimeException( "Cannot resolve " + Constants.HEAD );
+ }
+ RevCommit real = walk.parseCommit( head );
+ walk.markStart( real );
+ }
+
+ int n = 0;
+ for ( final RevCommit c : walk )
+ {
+ n++;
+ if ( maxLines != -1 && n > maxLines )
+ {
+ break;
+ }
+
+ revs.add( c );
+ }
+ return revs;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/add/JGitAddCommand.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/add/JGitAddCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/add/JGitAddCommand.java
new file mode 100644
index 0000000..3867bb7
--- /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/add/JGitAddCommand.java
@@ -0,0 +1,80 @@
+package org.apache.maven.scm.provider.git.jgit.command.add;
+
+/*
+ * 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.util.List;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.add.AbstractAddCommand;
+import org.apache.maven.scm.command.add.AddScmResult;
+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.eclipse.jgit.api.Git;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitAddCommand.java 894145 2009-12-28 10:13:39Z struberg $
+ */
+public class JGitAddCommand
+ extends AbstractAddCommand
+ implements GitCommand
+{
+ /**
+ * {@inheritDoc}
+ */
+ protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
+ boolean binary )
+ throws ScmException
+ {
+
+ if ( fileSet.getFileList().isEmpty() )
+ {
+ throw new ScmException( "You must provide at least one file/directory to add (e.g. -Dincludes=...)" );
+ }
+ try
+ {
+ Git git = Git.open( fileSet.getBasedir() );
+
+ List<ScmFile> addedFiles = JGitUtils.addAllFiles( git, fileSet );
+
+ if ( getLogger().isDebugEnabled() )
+ {
+ for ( ScmFile scmFile : addedFiles )
+ {
+ getLogger().info( "added file: " + scmFile );
+ }
+ }
+
+ return new AddScmResult( "JGit add", addedFiles );
+
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit add failure!", e );
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/blame/JGitBlameCommand.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/blame/JGitBlameCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/blame/JGitBlameCommand.java
new file mode 100644
index 0000000..85bc6e0
--- /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/blame/JGitBlameCommand.java
@@ -0,0 +1,75 @@
+package org.apache.maven.scm.provider.git.jgit.command.blame;
+
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.blame.AbstractBlameCommand;
+import org.apache.maven.scm.command.blame.BlameLine;
+import org.apache.maven.scm.command.blame.BlameScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.blame.BlameResult;
+
+/**
+ * @author Dominik Bartholdi (imod)
+ */
+public class JGitBlameCommand
+ extends AbstractBlameCommand
+ implements GitCommand
+{
+
+ @Override
+ public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet workingDirectory,
+ String filename )
+ throws ScmException
+ {
+
+ File basedir = workingDirectory.getBasedir();
+ try
+ {
+ Git git = Git.open( basedir );
+ BlameResult blameResult = git.blame().setFilePath( filename ).call();
+
+ List<BlameLine> lines = new ArrayList<BlameLine>();
+
+ int i = 0;
+ while ( ( i = blameResult.computeNext() ) != -1 )
+ {
+ lines.add( new BlameLine( blameResult.getSourceAuthor( i ).getWhen(),
+ blameResult.getSourceCommit( i ).getName(),
+ blameResult.getSourceAuthor( i ).getName(),
+ blameResult.getSourceCommitter( i ).getName() ) );
+ }
+
+ return new BlameScmResult( "JGit blame", lines );
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit blame failure!", e );
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/branch/JGitBranchCommand.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/branch/JGitBranchCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/branch/JGitBranchCommand.java
new file mode 100644
index 0000000..6e58fc4
--- /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/branch/JGitBranchCommand.java
@@ -0,0 +1,137 @@
+package org.apache.maven.scm.provider.git.jgit.command.branch;
+
+/*
+ * 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.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.branch.AbstractBranchCommand;
+import org.apache.maven.scm.command.branch.BranchScmResult;
+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.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.treewalk.TreeWalk;
+
+/**
+ * @author Dominik Bartholdi (imod)
+ */
+public class JGitBranchCommand
+ extends AbstractBranchCommand
+ implements GitCommand
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ScmResult executeBranchCommand( ScmProviderRepository repo, ScmFileSet fileSet, String branch,
+ String message )
+ throws ScmException
+ {
+ if ( branch == null || StringUtils.isEmpty( branch.trim() ) )
+ {
+ throw new ScmException( "branch name must be specified" );
+ }
+
+ if ( !fileSet.getFileList().isEmpty() )
+ {
+ throw new ScmException( "This provider doesn't support branching subsets of a directory" );
+ }
+
+ try
+ {
+ Git git = Git.open( fileSet.getBasedir() );
+ Ref branchResult = git.branchCreate().setName( branch ).call();
+ getLogger().info( "created [" + branchResult.getName() + "]" );
+
+ if(getLogger().isDebugEnabled()){
+ for (String branchName : getShortLocalBranchNames(git))
+ {
+ getLogger().debug( "local branch available: "+branchName );
+ }
+ }
+
+ if ( repo.isPushChanges() )
+ {
+ getLogger().info( "push branch [" + branch + "] to remote..." );
+ JGitUtils.push( getLogger(), git, (GitScmProviderRepository) repo,
+ new RefSpec( Constants.R_HEADS + branch ) );
+ }
+
+
+ // search for the tagged files
+ RevWalk revWalk = new RevWalk(git.getRepository());
+ RevCommit commit = revWalk.parseCommit(branchResult.getObjectId());
+
+ final TreeWalk walk = new TreeWalk(git.getRepository());
+ walk.reset(); // drop the first empty tree, which we do not need here
+ walk.setRecursive(true);
+ walk.addTree(commit.getTree());
+
+ List<ScmFile> files = new ArrayList<ScmFile>();
+ while (walk.next()) {
+ files.add( new ScmFile( walk.getPathString(), ScmFileStatus.CHECKED_OUT) );
+ }
+
+ return new BranchScmResult( "JGit branch", files );
+
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit branch failed!", e );
+ }
+ }
+
+ /**
+ * gets a set of names of the available branches in the given repo
+ * @param git the repo to list the branches for
+ * @return set of short branch names
+ * @throws GitAPIException
+ */
+ public static Set<String> getShortLocalBranchNames(Git git) throws GitAPIException
+ {
+ Set<String> branches = new HashSet<String>();
+ Iterator<Ref> iter = git.branchList().call().iterator();
+ while(iter.hasNext()){
+ branches.add(Repository.shortenRefName(iter.next().getName()));
+ }
+ return branches;
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/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
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..77ba88d
--- /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/changelog/JGitChangeLogCommand.java
@@ -0,0 +1,287 @@
+package org.apache.maven.scm.provider.git.jgit.command.changelog;
+
+/*
+ * 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.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.maven.scm.ChangeSet;
+import org.apache.maven.scm.ScmBranch;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
+import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
+import org.apache.maven.scm.command.changelog.ChangeLogSet;
+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.eclipse.jgit.api.Git;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevSort;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitChangeLogCommand.java 894145 2009-12-28 10:13:39Z struberg
+ * $
+ */
+public class JGitChangeLogCommand
+ extends AbstractChangeLogCommand
+ implements GitCommand
+{
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ ScmVersion startVersion, ScmVersion endVersion,
+ String datePattern )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repo, fileSet, null, null, null, datePattern, startVersion, endVersion );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date endDate, ScmBranch branch,
+ String datePattern )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repo, fileSet, startDate, endDate, branch, datePattern, null, null );
+ }
+
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date endDate, ScmBranch branch,
+ String datePattern, ScmVersion startVersion,
+ ScmVersion endVersion )
+ throws ScmException
+ {
+ try
+ {
+ Git git = Git.open( fileSet.getBasedir() );
+
+ List<ChangeSet> modifications = new ArrayList<ChangeSet>();
+
+ String startRev = startVersion != null ? startVersion.getName() : null;
+ String endRev = endVersion != null ? endVersion.getName() : null;
+
+ List<ChangeEntry> gitChanges =
+ this.whatchanged( git.getRepository(), null, startRev, endRev, startDate, endDate, -1 );
+
+ for ( ChangeEntry change : gitChanges )
+ {
+ ChangeSet scmChange = new ChangeSet();
+
+ scmChange.setAuthor( change.getAuthorName() );
+ scmChange.setComment( change.getBody() );
+ scmChange.setDate( change.getAuthorDate() );
+ // X TODO scmChange.setFiles( change.get )
+
+ modifications.add( scmChange );
+ }
+
+ ChangeLogSet changeLogSet = new ChangeLogSet( modifications, startDate, endDate );
+ changeLogSet.setStartVersion( startVersion );
+ changeLogSet.setEndVersion( endVersion );
+
+ return new ChangeLogScmResult( "JGit changelog", changeLogSet );
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit changelog failure!", e );
+ }
+ }
+
+ public List<ChangeEntry> whatchanged( Repository repo, RevSort[] sortings, String fromRev, String toRev,
+ Date fromDate, Date toDate, int maxLines )
+ throws MissingObjectException, IncorrectObjectTypeException, IOException
+ {
+ List<ChangeEntry> changes = new ArrayList<ChangeEntry>();
+ List<RevCommit> revs = JGitUtils.getRevCommits( repo, sortings, fromRev, toRev, fromDate, toDate, maxLines );
+
+ for ( RevCommit c : revs )
+ {
+ ChangeEntry ce = new ChangeEntry();
+
+ ce.setAuthorDate( c.getAuthorIdent().getWhen() );
+ ce.setAuthorEmail( c.getAuthorIdent().getEmailAddress() );
+ ce.setAuthorName( c.getAuthorIdent().getName() );
+ ce.setCommitterDate( c.getCommitterIdent().getWhen() );
+ ce.setCommitterEmail( c.getCommitterIdent().getEmailAddress() );
+ ce.setCommitterName( c.getCommitterIdent().getName() );
+
+ ce.setSubject( c.getShortMessage() );
+ ce.setBody( c.getFullMessage() );
+
+ ce.setCommitHash( c.getId().name() );
+ ce.setTreeHash( c.getTree().getId().name() );
+
+ // X TODO missing: file list
+
+ changes.add( ce );
+ }
+
+ return changes;
+ }
+
+ public static final class ChangeEntry
+ {
+ private String commitHash;
+
+ private String treeHash;
+
+ private String authorName;
+
+ private String authorEmail;
+
+ private Date authorDate;
+
+ private String committerName;
+
+ private String committerEmail;
+
+ private Date committerDate;
+
+ private String subject;
+
+ private String body;
+
+ private List<File> files;
+
+ public String getCommitHash()
+ {
+ return commitHash;
+ }
+
+ public void setCommitHash( String commitHash )
+ {
+ this.commitHash = commitHash;
+ }
+
+ public String getTreeHash()
+ {
+ return treeHash;
+ }
+
+ public void setTreeHash( String treeHash )
+ {
+ this.treeHash = treeHash;
+ }
+
+ public String getAuthorName()
+ {
+ return authorName;
+ }
+
+ public void setAuthorName( String authorName )
+ {
+ this.authorName = authorName;
+ }
+
+ public String getAuthorEmail()
+ {
+ return authorEmail;
+ }
+
+ public void setAuthorEmail( String authorEmail )
+ {
+ this.authorEmail = authorEmail;
+ }
+
+ public Date getAuthorDate()
+ {
+ return authorDate;
+ }
+
+ public void setAuthorDate( Date authorDate )
+ {
+ this.authorDate = authorDate;
+ }
+
+ public String getCommitterName()
+ {
+ return committerName;
+ }
+
+ public void setCommitterName( String committerName )
+ {
+ this.committerName = committerName;
+ }
+
+ public String getCommitterEmail()
+ {
+ return committerEmail;
+ }
+
+ public void setCommitterEmail( String committerEmail )
+ {
+ this.committerEmail = committerEmail;
+ }
+
+ public Date getCommitterDate()
+ {
+ return committerDate;
+ }
+
+ public void setCommitterDate( Date committerDate )
+ {
+ this.committerDate = committerDate;
+ }
+
+ public String getSubject()
+ {
+ return subject;
+ }
+
+ public void setSubject( String subject )
+ {
+ this.subject = subject;
+ }
+
+ public String getBody()
+ {
+ return body;
+ }
+
+ public void setBody( String body )
+ {
+ this.body = body;
+ }
+
+ public List<File> getFiles()
+ {
+ return files;
+ }
+
+ public void setFiles( List<File> files )
+ {
+ this.files = files;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.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/checkin/JGitCheckInCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
new file mode 100644
index 0000000..c067366
--- /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/checkin/JGitCheckInCommand.java
@@ -0,0 +1,130 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkin;
+
+/*
+ * 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 java.util.List;
+import java.util.Set;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+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.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.jgit.api.AddCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.RefSpec;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitCheckInCommand.java 894145 2009-12-28 10:13:39Z struberg $
+ */
+public class JGitCheckInCommand
+ extends AbstractCheckInCommand
+ implements GitCommand
+{
+ /**
+ * {@inheritDoc}
+ */
+ protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
+ ScmVersion version )
+ throws ScmException
+ {
+
+ try
+ {
+ File basedir = fileSet.getBasedir();
+ Git git = Git.open( basedir );
+
+ boolean doCommit = false;
+
+ if ( !fileSet.getFileList().isEmpty() )
+ {
+ doCommit = JGitUtils.addAllFiles( git, fileSet ).size() > 0;
+ }
+ else
+ {
+ // add all tracked files which are modified manually
+ Set<String> changeds = git.status().call().getModified();
+ if ( changeds.isEmpty() )
+ {
+ // warn there is nothing to add
+ getLogger().warn( "there are no files to be added" );
+ doCommit = false;
+ }
+ else
+ {
+ AddCommand add = git.add();
+ for ( String changed : changeds )
+ {
+ getLogger().debug( "add manualy: " + changed );
+ add.addFilepattern( changed );
+ doCommit = true;
+ }
+ add.call();
+ }
+ }
+
+ List<ScmFile> checkedInFiles = Collections.emptyList();
+ if ( doCommit )
+ {
+ RevCommit commitRev = git.commit().setMessage( message ).call();
+ getLogger().info( "commit done: " + commitRev.getShortMessage() );
+ checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
+ if ( getLogger().isDebugEnabled() )
+ {
+ for ( ScmFile scmFile : checkedInFiles )
+ {
+ getLogger().debug( "in commit: " + scmFile );
+ }
+ }
+ }
+
+ if ( repo.isPushChanges() )
+ {
+ String branch = version != null ? version.getName() : null;
+ if ( StringUtils.isBlank( branch ) )
+ {
+ branch = git.getRepository().getBranch();
+ }
+ RefSpec refSpec = new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_HEADS + branch );
+ getLogger().info( "push changes to remote... " + refSpec.toString() );
+ JGitUtils.push( getLogger(), git, (GitScmProviderRepository) repo, refSpec );
+ }
+
+ return new CheckInScmResult( "JGit checkin", checkedInFiles );
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit checkin failure!", e );
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/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
----------------------------------------------------------------------
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/checkout/JGitCheckOutCommand.java b/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
new file mode 100644
index 0000000..f8269ab
--- /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/checkout/JGitCheckOutCommand.java
@@ -0,0 +1,190 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkout;
+
+/*
+ * 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.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.ScmTag;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult;
+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.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
+import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ProgressMonitor;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.treewalk.TreeWalk;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @author Dominik Bartholdi (imod)
+ * @version $Id: JGitCheckOutCommand.java 894145 2009-12-28 10:13:39Z struberg $
+ */
+public class JGitCheckOutCommand
+ extends AbstractCheckOutCommand
+ implements GitCommand
+{
+ /**
+ * For git, the given repository is a remote one. We have to clone it first
+ * if the working directory does not contain a git repo yet, otherwise we
+ * have to git-pull it.
+ * <p/>
+ * {@inheritDoc}
+ */
+ protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ ScmVersion version, boolean recursive )
+ throws ScmException
+ {
+ GitScmProviderRepository repository = (GitScmProviderRepository) repo;
+
+ if ( GitScmProviderRepository.PROTOCOL_FILE.equals( repository.getFetchInfo().getProtocol() )
+ && repository.getFetchInfo().getPath().indexOf( fileSet.getBasedir().getPath() ) >= 0 )
+ {
+ throw new ScmException( "remote repository must not be the working directory" );
+ }
+
+ try
+ {
+
+ ProgressMonitor monitor = JGitUtils.getMonitor( getLogger() );
+
+ String branch = version != null ? version.getName() : null;
+
+ if ( StringUtils.isBlank( branch ) )
+ {
+ branch = Constants.MASTER;
+ }
+
+ getLogger().debug("try checkout of branch: "+branch);
+
+ if ( !fileSet.getBasedir().exists() || !( new File( fileSet.getBasedir(), ".git" ).exists() ) )
+ {
+ if ( fileSet.getBasedir().exists() )
+ {
+ // git refuses to clone otherwise
+ fileSet.getBasedir().delete();
+ }
+
+ // no git repo seems to exist, let's clone the original repo
+ CredentialsProvider credentials = JGitUtils.getCredentials( (GitScmProviderRepository) repo );
+ getLogger().info( "cloning [" + branch + "] to " + fileSet.getBasedir() );
+ Git.cloneRepository().setURI( repository.getFetchUrl() ).setCredentialsProvider(
+ credentials ).setCloneAllBranches(true).setDirectory(
+ fileSet.getBasedir() ).setProgressMonitor( monitor ).call();
+ }
+
+ JGitRemoteInfoCommand remoteInfoCommand = new JGitRemoteInfoCommand();
+ remoteInfoCommand.setLogger(getLogger());
+ RemoteInfoScmResult result = remoteInfoCommand.executeRemoteInfoCommand(repository, fileSet, null);
+
+ Git git = Git.open( fileSet.getBasedir() );
+ if ( fileSet.getBasedir().exists() && new File( fileSet.getBasedir(), ".git" ).exists()
+ && result.getBranches().size() > 0 )
+ {
+ // git repo exists, so we must git-pull the changes
+ CredentialsProvider credentials = JGitUtils.prepareSession(getLogger(), git, repository);
+
+ if ( version != null && StringUtils.isNotEmpty( version.getName() ) && ( version instanceof ScmTag ) )
+ {
+ // A tag will not be pulled but we only fetch all the commits from the upstream repo
+ // This is done because checking out a tag might not happen on the current branch
+ // but create a 'detached HEAD'.
+ // In fact, a tag in git may be in multiple branches. This occurs if
+ // you create a branch after the tag has been created
+ getLogger().debug( "fetch..." );
+ git.fetch().setCredentialsProvider(credentials).setProgressMonitor( monitor ).call();
+ }
+ else
+ {
+ getLogger().debug( "pull..." );
+ git.pull().setCredentialsProvider(credentials).setProgressMonitor( monitor ).call();
+
+ }
+ }
+
+ Set<String> localBranchNames = JGitBranchCommand.getShortLocalBranchNames(git);
+ if(version instanceof ScmTag )
+ {
+ getLogger().info( "checkout tag [" + branch + "] at " + fileSet.getBasedir() );
+ git.checkout().setName(branch).call();
+ }
+ else if(localBranchNames.contains(branch))
+ {
+ getLogger().info( "checkout [" + branch + "] at " + fileSet.getBasedir() );
+ git.checkout().setName( branch ).call();
+ }
+ else
+ {
+ getLogger().info( "checkout remote branch [" + branch + "] at " + fileSet.getBasedir() );
+ git.checkout().setName( branch ).setCreateBranch( true ).setStartPoint( Constants.DEFAULT_REMOTE_NAME + "/" + branch ).call();
+ }
+
+ RevWalk revWalk = new RevWalk(git.getRepository());
+ RevCommit commit = revWalk.parseCommit( git.getRepository().resolve( Constants.HEAD ) );
+
+ final TreeWalk walk = new TreeWalk(git.getRepository());
+ walk.reset(); // drop the first empty tree, which we do not need here
+ walk.setRecursive(true);
+ walk.addTree(commit.getTree());
+
+ List<ScmFile> listedFiles = new ArrayList<ScmFile>();
+ while (walk.next())
+ {
+ listedFiles.add( new ScmFile( walk.getPathString(), ScmFileStatus.CHECKED_OUT ) );
+ }
+
+ getLogger().debug( "current branch: " + git.getRepository().getBranch() );
+
+ return new CheckOutScmResult( "checkout via JGit", listedFiles );
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit checkout failure!", e );
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e86351f4/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.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/diff/JGitDiffCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/diff/JGitDiffCommand.java
new file mode 100644
index 0000000..0d17e9b
--- /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/diff/JGitDiffCommand.java
@@ -0,0 +1,135 @@
+package org.apache.maven.scm.provider.git.jgit.command.diff;
+
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.diff.AbstractDiffCommand;
+import org.apache.maven.scm.command.diff.DiffScmResult;
+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.DiffCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.treewalk.AbstractTreeIterator;
+import org.eclipse.jgit.treewalk.CanonicalTreeParser;
+
+/**
+ * @author Dominik Bartholdi (imod)
+ */
+public class JGitDiffCommand
+ extends AbstractDiffCommand
+ implements GitCommand
+{
+
+ @Override
+ protected DiffScmResult executeDiffCommand( ScmProviderRepository repository, ScmFileSet fileSet,
+ ScmVersion startRevision, ScmVersion endRevision )
+ throws ScmException
+ {
+
+ try
+ {
+ Git git = Git.open( fileSet.getBasedir() );
+
+ return callDiff( git, startRevision, endRevision );
+ }
+ catch ( Exception e )
+ {
+ throw new ScmException( "JGit diff failure!", e );
+ }
+ }
+
+ public DiffScmResult callDiff( Git git, ScmVersion startRevision, ScmVersion endRevision )
+ throws IOException, GitAPIException, ScmException
+ {
+ AbstractTreeIterator oldTree = null;
+ if ( startRevision != null && StringUtils.isNotEmpty( startRevision.getName().trim() ) )
+ {
+ String startRev = startRevision.getName().trim();
+ oldTree = getTreeIterator( git.getRepository(), startRev );
+ }
+
+ AbstractTreeIterator newTree = null;
+ if ( endRevision != null && StringUtils.isNotEmpty( endRevision.getName().trim() ) )
+ {
+ String endRev = endRevision.getName().trim();
+ newTree = getTreeIterator( git.getRepository(), endRev );
+ }
+
+ OutputStream out = new ByteArrayOutputStream();
+
+ DiffCommand diff = git.diff().setOutputStream( out ).setOldTree( oldTree ).setNewTree( newTree );
+ List<DiffEntry> entries = diff.call();
+ List<ScmFile> changedFiles = new ArrayList<ScmFile>();
+
+ // TODO get differences (but actually these are captured in the out
+ // already...)
+ Map<String, CharSequence> differences = new HashMap<String, CharSequence>();
+
+ for ( DiffEntry diffEntry : entries )
+ {
+ changedFiles.add(
+ new ScmFile( diffEntry.getNewPath(), JGitUtils.getScmFileStatus( diffEntry.getChangeType() ) ) );
+ }
+
+ return new DiffScmResult( changedFiles, differences, out.toString(),
+ new ScmResult( "JGit diff", "diff", null, true ) );
+ }
+
+ private AbstractTreeIterator getTreeIterator( Repository repo, String name )
+ throws IOException
+ {
+ final ObjectId id = repo.resolve( name );
+ if ( id == null )
+ {
+ throw new IllegalArgumentException( name );
+ }
+ final CanonicalTreeParser p = new CanonicalTreeParser();
+ final ObjectReader or = repo.newObjectReader();
+ try
+ {
+ p.reset( or, new RevWalk( repo ).parseTree( id ) );
+ return p;
+ }
+ finally
+ {
+ or.release();
+ }
+ }
+}