maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject git commit: Use URI to prevent unnecessary to/from String conversions
Date Sun, 17 Mar 2013 20:10:24 GMT
Updated Branches:
  refs/heads/master 10099c042 -> 55aec671a


Use URI to prevent unnecessary to/from String conversions


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

Branch: refs/heads/master
Commit: 55aec671a0fed84c3d73ab6c60fa818f1db81452
Parents: 10099c0
Author: rfscholte <rfscholte@apache.org>
Authored: Sun Mar 17 21:09:50 2013 +0100
Committer: rfscholte <rfscholte@apache.org>
Committed: Sun Mar 17 21:09:50 2013 +0100

----------------------------------------------------------------------
 .../git/gitexe/command/add/GitAddCommand.java      |    4 +-
 .../gitexe/command/checkin/GitCheckInCommand.java  |    4 +-
 .../gitexe/command/status/GitStatusCommand.java    |    4 +-
 .../gitexe/command/status/GitStatusConsumer.java   |   26 ++++++++++++--
 .../command/status/GitStatusConsumerTest.java      |   21 ++++++------
 5 files changed, 39 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/55aec671/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
index 59bc521..1ea1e07 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
@@ -76,7 +76,7 @@ public class GitAddCommand
         CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 
-        String relativeRepositoryPath = null;
+        URI relativeRepositoryPath = null;
         
         int exitCode;
 
@@ -91,7 +91,7 @@ public class GitAddCommand
         }
         else
         {
-            relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ).getPath(); 
+            relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ); 
         }
 
         // git-add doesn't show single files, but only summary :/

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/55aec671/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java
index f00db3b..a37aaaf 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java
@@ -104,7 +104,7 @@ public class GitCheckInCommand
             stdout = new CommandLineUtils.StringStreamConsumer();
             stderr = new CommandLineUtils.StringStreamConsumer();
 
-            String relativeRepositoryPath = null;
+            URI relativeRepositoryPath = null;
             
             exitCode = GitCommandLineUtils.execute( clRevparse, stdout, stderr, getLogger()
);
             if ( exitCode != 0 )
@@ -117,7 +117,7 @@ public class GitCheckInCommand
             }
             else
             {
-                relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ).getPath(); 
+                relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ); 
             }
 
             // git-commit doesn't show single files, but only summary :/

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/55aec671/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusCommand.java
index 2689a49..133f5aa 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusCommand.java
@@ -50,7 +50,7 @@ public class GitStatusCommand
     	CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 
-        String relativeRepositoryPath = null;
+        URI relativeRepositoryPath = null;
         
         int exitCode;
 
@@ -65,7 +65,7 @@ public class GitStatusCommand
         }
         else
         {
-            relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ).getPath(); 
+            relativeRepositoryPath = URI.create( stdout.getOutput().trim() ).relativize(
fileSet.getBasedir().toURI() ); 
         }
     	
         Commandline cl = createCommandLine( (GitScmProviderRepository) repo, fileSet );

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/55aec671/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
index 2ee90a8..074d66a 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumer.java
@@ -68,19 +68,37 @@ public class GitStatusConsumer
      */
     private List<ScmFile> changedFiles = new ArrayList<ScmFile>();
 
-    private String relativeRepositoryPath;
+    private URI relativeRepositoryPath;
     
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
 
+    /**
+     * Consumer when workingDirectory and repositoryRootDirectory are the same
+     * 
+     * @param logger the logger
+     * @param workingDirectory the working directory
+     */
     public GitStatusConsumer( ScmLogger logger, File workingDirectory )
     {
         this.logger = logger;
         this.workingDirectory = workingDirectory;
     }
 
-    public GitStatusConsumer( ScmLogger logger, File workingDirectory, String relativeRepositoryPath
)
+    /**
+     * Assuming that you have to discover the repositoryRoot, this is how you can get the
<code>relativeRepositoryPath</code>
+     * <pre>
+     * URI.create( repositoryRoot ).relativize( fileSet.getBasedir().toURI() )
+     * </pre>
+     * 
+     * @param logger the logger
+     * @param workingDirectory the working directory
+     * @param relativeRepositoryPath the working directory relative to the repository root
+     * @since 1.9
+     * @see GitStatusCommand#createRevparseShowToplevelCommand(org.apache.maven.scm.ScmFileSet)
+     */
+    public GitStatusConsumer( ScmLogger logger, File workingDirectory, URI relativeRepositoryPath
)
     {
         this( logger, workingDirectory );
         this.relativeRepositoryPath = relativeRepositoryPath;
@@ -198,12 +216,12 @@ public class GitStatusConsumer
         return new File( workingDirectory, file ).isFile();
     }
 
-    protected static String resolvePath( String fileEntry, String path )
+    protected static String resolvePath( String fileEntry, URI path )
     {
         if ( path != null )
         {
             
-            return URI.create( path ).relativize( URI.create( fileEntry ) ).getPath();
+            return path.relativize( URI.create( fileEntry ) ).getPath();
         }
         else
         {

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/55aec671/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
index 9d9b924..5e4ceeb 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/status/GitStatusConsumerTest.java
@@ -19,6 +19,13 @@ package org.apache.maven.scm.provider.git.gitexe.command.status;
  * under the License.
  */
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URI;
+import java.util.List;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.scm.ScmFile;
@@ -26,12 +33,6 @@ import org.apache.maven.scm.ScmFileStatus;
 import org.apache.maven.scm.log.DefaultLog;
 import org.codehaus.plexus.PlexusTestCase;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.List;
-
 /**
  * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
  */
@@ -45,7 +46,7 @@ public class GitStatusConsumerTest
         return getChangedFiles( gitlog, null );
     }
     
-    private List<ScmFile> getChangedFiles( File gitlog, String relativeRepoPath )
+    private List<ScmFile> getChangedFiles( File gitlog, URI relativeRepoPath )
         throws IOException
     {
         GitStatusConsumer consumer = new GitStatusConsumer( new DefaultLog(), null, relativeRepoPath
);
@@ -288,7 +289,7 @@ public class GitStatusConsumerTest
     public void testLog3Consumer()
                     throws Exception
                 {
-                    List<ScmFile> changedFiles = getChangedFiles( getTestFile( "/src/test/resources/git/status/gitstatus2.gitlog"
), "maven-scm-provider-gitexe" );
+                    List<ScmFile> changedFiles = getChangedFiles( getTestFile( "/src/test/resources/git/status/gitstatus2.gitlog"
), URI.create( "maven-scm-provider-gitexe" ) );
 
                     assertEquals( 4, changedFiles.size() );
 
@@ -312,9 +313,9 @@ public class GitStatusConsumerTest
         File repositoryRoot = getTestFile( "repo" );
         File workingDirectory = getTestFile( "repo/work" );
 
-        String path = repositoryRoot.toURI().relativize( workingDirectory.toURI() ).getPath();
+        URI path = repositoryRoot.toURI().relativize( workingDirectory.toURI() );
 
-        assertEquals( "work", path );
+        assertEquals( "work", path.getPath() );
 
         assertEquals( "pom.xml", GitStatusConsumer.resolvePath( "work/pom.xml", path ) );
         assertEquals( "work/pom.xml", GitStatusConsumer.resolvePath( "work/pom.xml", null
) );


Mime
View raw message