maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject [3/7] git commit: add functionality to reset the the basedir of a ScmFileSet for GitCommands
Date Sun, 20 Jul 2014 11:57:08 GMT
add functionality to reset the the basedir of a ScmFileSet for GitCommands


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

Branch: refs/heads/MRELEASE-875
Commit: 2e7cf44594dc2b37338ec386962856e49202b98b
Parents: f0cd098
Author: imod <domi@fortysix.ch>
Authored: Sun Jul 20 12:53:47 2014 +0200
Committer: imod <domi@fortysix.ch>
Committed: Sun Jul 20 13:07:35 2014 +0200

----------------------------------------------------------------------
 .../provider/git/AbstractGitScmProvider.java    |  7 ++-
 .../scm/provider/git/command/GitCommand.java    | 11 ++++-
 .../maven/scm/provider/git/util/GitUtil.java    | 45 ++++++++++++++++++--
 3 files changed, 58 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/2e7cf445/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java
index 1d1655f..7451d97 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/AbstractGitScmProvider.java
@@ -288,7 +288,12 @@ public abstract class AbstractGitScmProvider
     {
         command.setLogger( getLogger() );
 
-        return command.execute( repository, fileSet, parameters );
+        ScmFileSet newSet = fileSet;
+        if ( command.requiresToWorkInRepoRootDir() )
+        {
+            newSet = GitUtil.convertScmFileSetToRepoRootPath( fileSet );
+        }
+        return command.execute( repository, newSet, parameters );
     }
 
     protected abstract GitCommand getListCommand();

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/2e7cf445/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/command/GitCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/command/GitCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/command/GitCommand.java
index d1f3d8a..851fb37 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/command/GitCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/command/GitCommand.java
@@ -23,9 +23,18 @@ import org.apache.maven.scm.command.Command;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
- *
+ * @author Dominik Bartholdi
  */
 public interface GitCommand
     extends Command
 {
+    /**
+     * Whether the filesets passed to the command should be reset to the root of the repository
prior to execute the
+     * command
+     * 
+     * @return <code>true</code> if the fileset must have the repository as the
basedirectory.
+     * @see org.apache.maven.scm.provider.git.AbstractGitScmProvider.executeCommand(GitCommand,
ScmProviderRepository,
+     *      ScmFileSet, CommandParameters)
+     */
+    boolean requiresToWorkInRepoRootDir();
 }

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/2e7cf445/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
index 9ebd71f..737fd9f 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
@@ -19,18 +19,21 @@ package org.apache.maven.scm.provider.git.util;
  * under the License.
  */
 
+import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.providers.gitlib.settings.Settings;
 import org.apache.maven.scm.providers.gitlib.settings.io.xpp3.GitXpp3Reader;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
- *
  */
 public class GitUtil
 {
@@ -91,9 +94,45 @@ public class GitUtil
         settingsDirectory = directory;
         settings = readSettings();
     }
-    
+
     public static File getSettingsFile()
     {
-    	return new File( settingsDirectory, GIT_SETTINGS_FILENAME );
+        return new File( settingsDirectory, GIT_SETTINGS_FILENAME );
+    }
+
+    public static File getRepoRootDir( File current )
+    {
+        if ( new File( current, ".git" ).exists() || !current.getParentFile().exists() )
+        {
+            return current;
+        }
+        return getRepoRootDir( current.getParentFile() );
+    }
+
+    public static ScmFileSet convertScmFileSetToRepoRootPath( ScmFileSet fileSet )
+    {
+        File realRepoRootDir = getRepoRootDir( fileSet.getBasedir() );
+        List<File> newFiles = new ArrayList<File>( fileSet.getFileList().size()
);
+        for ( File f : fileSet.getFileList() )
+        {
+            if ( !f.isAbsolute() )
+            {
+
+                String deltaPath =
+                    fileSet.getBasedir().getAbsolutePath().substring( realRepoRootDir.getAbsolutePath().length()
);
+
+                deltaPath = StringUtils.isBlank( deltaPath ) ? "" : deltaPath + "/";
+                deltaPath = deltaPath.startsWith( "/" ) ? deltaPath.substring( 1 ) : deltaPath;
+
+                File newFile = new File( deltaPath + f.getPath() );
+                newFiles.add( newFile );
+            }
+            else
+            {
+                newFiles.add( f );
+            }
+        }
+        ScmFileSet newFileSet = new ScmFileSet( realRepoRootDir, newFiles );
+        return newFileSet;
     }
 }


Mime
View raw message