maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r679832 - in /maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it: DefaultInvoker.java Verifier.java
Date Fri, 25 Jul 2008 15:20:05 GMT
Author: jvanzyl
Date: Fri Jul 25 08:20:05 2008
New Revision: 679832

URL: http://svn.apache.org/viewvc?rev=679832&view=rev
Log: (empty)

Modified:
    maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/DefaultInvoker.java
    maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/Verifier.java

Modified: maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/DefaultInvoker.java
URL: http://svn.apache.org/viewvc/maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/DefaultInvoker.java?rev=679832&r1=679831&r2=679832&view=diff
==============================================================================
--- maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/DefaultInvoker.java
(original)
+++ maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/DefaultInvoker.java
Fri Jul 25 08:20:05 2008
@@ -20,6 +20,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -30,6 +31,7 @@
 import java.util.Properties;
 
 import org.apache.maven.it.util.FileUtils;
+import org.apache.maven.it.util.StringUtils;
 import org.apache.maven.it.util.cli.CommandLineException;
 import org.apache.maven.it.util.cli.CommandLineUtils;
 import org.apache.maven.it.util.cli.Commandline;
@@ -57,20 +59,59 @@
     public void executeGoal( String goal, String basedir )
         throws VerificationException
     {
-        executeGoal( goal, basedir, Collections.EMPTY_MAP );
+        executeGoals( Arrays.asList( StringUtils.split( goal, "," ) ), basedir, Collections.EMPTY_MAP
);
     }
 
     public void executeGoal( String goal, String basedir, Map envVars )
         throws VerificationException
     {
-        executeGoals( Arrays.asList( new String[] { goal } ), basedir, envVars );
+        executeGoals( Arrays.asList( StringUtils.split( goal, "," ) ), basedir, envVars );
     }
 
-    public String getExecutable()
+    public String getMavenVersion() 
+        throws VerificationException
     {
-        // Use a strategy for finding the maven executable, John has a simple method like
this
-        // but a little strategy + chain of command would be nicer.
+        Commandline cmd = createCommandLine();
+        cmd.addArguments( new String[] { "--version" } );
+
+        Writer writer = new StringWriter();
+        
+        try
+        {
+            runCommandLine( System.getProperty( "maven.home" ), cmd, writer );
+        }
+        catch ( CommandLineException e )
+        {
+            throw new VerificationException( "Error running commandline " + cmd.toString(),
e );
+        }
+        catch ( IOException e )
+        {
+            throw new VerificationException( "IO Error communicating with commandline " +
cmd.toString(), e );
+        }
 
+        String separator = System.getProperty( "line.separator" );        
+        
+        // Maven version: 2.1-SNAPSHOT
+        // Java version: 1.6.0_05
+        // Default locale: en_US, platform encoding: MacRoman
+        // OS name: "mac os x" version: "10.5.4" arch: "x86_64" family: "mac"
+        
+        String version = StringUtils.split( writer.toString(), separator )[0];
+        version = version.substring( version.indexOf( ":" ) + 1 );
+        System.out.println( "'" + version + "'" );
+        
+        if ( version == null )
+        {
+            throw new VerificationException( "Illegal maven output: String 'Maven version:
' not found in the following output: " + writer.toString() );
+        }
+        else
+        {
+            return version;
+        }
+    }
+
+    public String getExecutable()
+    {
         String mavenHome = System.getProperty( "maven.home" );
 
         if ( mavenHome != null )
@@ -196,11 +237,9 @@
         return cmd;
     }
 
-    private int runCommandLine( String mavenHome, Commandline cli, File logFile )
+    private int runCommandLine( String mavenHome, Commandline cli, Writer logWriter )
         throws CommandLineException, IOException
     {
-        Writer logWriter = new FileWriter( logFile );
-
         StreamConsumer out = new WriterStreamConsumer( logWriter );
 
         StreamConsumer err = new WriterStreamConsumer( logWriter );
@@ -215,6 +254,14 @@
         }
     }
 
+    private int runCommandLine( String mavenHome, Commandline cli, File logFile )
+        throws CommandLineException, IOException
+    {
+        Writer logWriter = new FileWriter( logFile );
+
+        return runCommandLine( mavenHome, cli, logWriter );
+    }
+
     private static String getLogContents( File logFile )
     {
         try

Modified: maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/Verifier.java
URL: http://svn.apache.org/viewvc/maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/Verifier.java?rev=679832&r1=679831&r2=679832&view=diff
==============================================================================
--- maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/Verifier.java
(original)
+++ maven/shared/branches/embedder-verifier/src/main/java/org/apache/maven/it/Verifier.java
Fri Jul 25 08:20:05 2008
@@ -51,19 +51,23 @@
 
 /**
  * @author Jason van Zyl
- * @author <a href="mailto:brett@apache.org">Brett Porter</a>
- * @version $Id$
- * @noinspection UseOfSystemOutOrSystemErr,RefusedBequest
+ * @todo pass in what's necessary to invoker
+ * @todo separate out verifier
+ * @todo separate out tools
+ * @todo create embedder invoker
+ * @todo find better way to pass in maven version
  */
 public class Verifier
 {
     private static final String LOG_FILENAME = "log.txt";
     public String localRepo;
     private final String basedir;
+
     private final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
     private final ByteArrayOutputStream errStream = new ByteArrayOutputStream();
     private PrintStream originalOut;
     private PrintStream originalErr;
+
     private List cliOptions = new ArrayList();
     private Properties systemProperties = new Properties();
     private Properties verifierProperties = new Properties();
@@ -76,7 +80,7 @@
     // Execution
 
     Invoker invoker = new DefaultInvoker();
-    
+
     public void executeGoal( String goal )
         throws VerificationException
     {
@@ -89,6 +93,17 @@
         invoker.executeGoal( goal, basedir, envars );
     }
 
+    public String getMavenVersion()
+        throws VerificationException
+    {
+        return invoker.getMavenVersion();
+    }
+
+    public String getExecutable()
+    {
+        return invoker.getExecutable();
+    }
+
     //
 
     public Verifier( String basedir, String settingsFile )



Mime
View raw message