maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mper...@apache.org
Subject svn commit: r481650 - in /maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce: ./ src/main/java/org/apache/maven/scm/provider/perforce/ src/main/java/org/apache/maven/scm/provider/perforce/command/ src/test/java/org/apache/maven/scm/provide...
Date Sat, 02 Dec 2006 22:32:46 GMT
Author: mperham
Date: Sat Dec  2 14:32:45 2006
New Revision: 481650

URL: http://svn.apache.org/viewvc?view=rev&rev=481650
Log:
Update getUsername to use 'p4 info' instead of relying on the POM or system property.
Add special logic to tell when the unit tests are running so others can run the unit tests
even when they don't have Perforce installed.

Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/pom.xml
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommand.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceWhereCommand.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommandTest.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/pom.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/pom.xml?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/pom.xml (original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/pom.xml Sat Dec  2 14:32:45
2006
@@ -15,4 +15,25 @@
       <version>1.3</version>
     </dependency>
   </dependencies>
-</project>
\ No newline at end of file
+
+  <build>
+      <plugins>
+          <plugin>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                  <systemProperties>
+                      <!-- 
+                      Allows the system to tell if it is in a unit test or
+                      not and take special action to disable server communication
+                      when the tests are run on a machine without Perforce installed.
+                      -->
+                      <property>
+                          <name>maven.scm.testing</name>
+                          <value>true</value>
+                      </property>
+                  </systemProperties>
+              </configuration>
+          </plugin>
+      </plugins>
+  </build>
+</project>

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/PerforceScmProvider.java
Sat Dec  2 14:32:45 2006
@@ -47,6 +47,7 @@
 import org.apache.maven.scm.provider.perforce.command.unedit.PerforceUnEditCommand;
 import org.apache.maven.scm.provider.perforce.command.update.PerforceUpdateCommand;
 import org.apache.maven.scm.provider.perforce.command.PerforceWhereCommand;
+import org.apache.maven.scm.provider.perforce.command.PerforceInfoCommand;
 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
 import org.apache.maven.scm.repository.ScmRepository;
 import org.apache.maven.scm.repository.ScmRepositoryException;
@@ -55,6 +56,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
@@ -390,12 +393,15 @@
 
     private static String getUsername( PerforceScmProviderRepository repo )
     {
-        // TODO Need to use PeforceInfoCommand here.
-        // os user != perforce user
-        String username = repo.getUser();
+        String username = PerforceInfoCommand.getInfo( null, repo ).getEntry( "User name");
         if ( username == null )
         {
-            username = System.getProperty( "user.name", "nouser" );
+            // os user != perforce user
+            username = repo.getUser();
+            if ( username == null )
+            {
+                username = System.getProperty( "user.name", "nouser" );
+            }
         }
         return username;
     }
@@ -443,5 +449,48 @@
             }
         }
         return loc;
+    }
+
+
+    private static Boolean live = null;
+
+    public static boolean isLive()
+    {
+        if ( live == null )
+        {
+            if ( !Boolean.getBoolean( "maven.scm.testing" ) )
+            {
+                // We are not executing in the tests so we are live.
+                live = Boolean.TRUE;
+            }
+            else
+            {
+                // During unit tests, we need to check the local system
+                // to see if the user has Perforce installed.  If not, we mark
+                // the provider as "not live" (or dead, I suppose!) and skip
+                // anything that requires an active server connection.
+                try
+                {
+                    Commandline command = new Commandline();
+                    command.setExecutable( "p4" );
+                    Process proc = command.execute();
+                    BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream()
) );
+                    String line;
+                    while ( ( line = br.readLine() ) != null )
+                    {
+                        //System.out.println(line);
+                    }
+                    int rc = proc.exitValue();
+                    live = (rc == 0 ? Boolean.TRUE : Boolean.FALSE);
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                    live = Boolean.FALSE;
+                }
+            }
+        }
+
+        return live.booleanValue();
     }
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommand.java?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommand.java
Sat Dec  2 14:32:45 2006
@@ -4,6 +4,7 @@
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.log.ScmLogger;
 import org.apache.maven.scm.command.AbstractCommand;
 import org.apache.maven.scm.provider.ScmProviderRepository;
 import org.apache.maven.scm.provider.perforce.PerforceScmProvider;
@@ -60,7 +61,10 @@
         if (singleton == null)
         {
             PerforceInfoCommand pic = new PerforceInfoCommand();
-            pic.setLogger( cmd.getLogger() );
+            if ( cmd != null )
+            {
+                pic.setLogger( cmd.getLogger() );
+            }
             try
             {
                 pic.executeCommand( repo, null, null );
@@ -74,16 +78,24 @@
         return singleton;
     }
 
-
     protected ScmResult executeCommand( ScmProviderRepository repo, ScmFileSet scmFileSet,
                                         CommandParameters commandParameters )
         throws ScmException
     {
+        if ( !PerforceScmProvider.isLive() )
+        {
+            return null;
+        }
+
+        boolean log = getLogger() != null;
         try
         {
             Commandline command = PerforceScmProvider.createP4Command( (PerforceScmProviderRepository)
repo, null );
             command.createArgument().setValue( "info" );
-            getLogger().debug( PerforceScmProvider.clean( "Executing: " + command.toString()
) );
+            if (log)
+            {
+                getLogger().debug( PerforceScmProvider.clean( "Executing: " + command.toString()
) );
+            }
             Process proc = command.execute();
             BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream()
) );
             String line;
@@ -102,12 +114,10 @@
         }
         catch ( CommandLineException e )
         {
-            getLogger().error( e );
             throw new ScmException( e.getLocalizedMessage() );
         }
         catch ( IOException e )
         {
-            getLogger().error( e );
             throw new ScmException( e.getLocalizedMessage() );
         }
         return null;

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceWhereCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceWhereCommand.java?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceWhereCommand.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/main/java/org/apache/maven/scm/provider/perforce/command/PerforceWhereCommand.java
Sat Dec  2 14:32:45 2006
@@ -46,6 +46,11 @@
      */
     public String getDepotLocation( String filepath )
     {
+        if ( !PerforceScmProvider.isLive() )
+        {
+            return null;
+        }
+
         try
         {
             Commandline command = PerforceScmProvider.createP4Command( repo, null );

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/PerforceScmProviderTest.java
Sat Dec  2 14:32:45 2006
@@ -19,13 +19,14 @@
 import org.apache.maven.scm.ScmTestCase;
 import org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository;
 import org.apache.maven.scm.repository.ScmRepository;
-import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.CommandLineException;
 
-import java.io.OutputStream;
-import java.io.DataOutputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Collections;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -34,39 +35,17 @@
 public class PerforceScmProviderTest
     extends ScmTestCase
 {
-    private static Boolean live = null;
-
-    public static boolean hasClientBinaries()
+    public void testParseConnection()
+        throws Exception
     {
-        if ( live == null )
+        Properties prop = System.getProperties();
+        List keys = new ArrayList(prop.keySet());
+        Collections.sort(keys);
+        for( Iterator it = keys.iterator(); it.hasNext(); )
         {
-            try
-            {
-                Commandline command = new Commandline();
-                command.setExecutable( "p4" );
-                Process proc = command.execute();
-                BufferedReader br = new BufferedReader( new InputStreamReader( proc.getInputStream()
) );
-                String line;
-                while ( ( line = br.readLine() ) != null )
-                {
-                    //System.out.println(line);
-                }
-                int rc = proc.exitValue();
-                live = (rc == 0 ? Boolean.TRUE : Boolean.FALSE);
-            }
-            catch ( Exception e )
-            {
-                e.printStackTrace();
-                live = Boolean.FALSE;
-            }
+            System.out.println( it.next() );
         }
 
-        return live.booleanValue();
-    }
-
-    public void testParseConnection()
-        throws Exception
-    {
         ScmRepository repo = makeScmRepository( "scm:perforce://depot/projects/pathname"
);
 
         PerforceScmProviderRepository p4Repo = (PerforceScmProviderRepository) repo.getProviderRepository();
@@ -198,6 +177,4 @@
 
         assertEquals( "//depot/foo/bar/...", PerforceScmProvider.getCanonicalRepoPath( "//depot/foo/bar/..."
) );
     }
-
-    // TODO: Add more tests for invalid connection strings.
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommandTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommandTest.java?view=diff&rev=481650&r1=481649&r2=481650
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommandTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-perforce/src/test/java/org/apache/maven/scm/provider/perforce/command/PerforceInfoCommandTest.java
Sat Dec  2 14:32:45 2006
@@ -25,7 +25,7 @@
         PerforceTagCommand cmd = new PerforceTagCommand();
         cmd.setLogger( prov.getLogger() );
 
-        if ( PerforceScmProviderTest.hasClientBinaries() )
+        if ( PerforceScmProvider.isLive() )
         {
             assertNotNull( PerforceInfoCommand.getInfo( cmd, p4Repo ).getEntry( "User name"
) );
             assertNotNull( PerforceInfoCommand.getInfo( cmd, p4Repo ).getEntry( "Client root"
) );



Mime
View raw message