You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2008/07/12 02:07:07 UTC

svn commit: r676103 - in /maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder: AbstractEmbedderTestCase.java execution/EmbedderUsingScmPluginTest.java

Author: jvanzyl
Date: Fri Jul 11 17:07:06 2008
New Revision: 676103

URL: http://svn.apache.org/viewvc?rev=676103&view=rev
Log:
o adding some code to detect system executables so that tests which wrap those executables are only run when they are present. in trying to get people to run the ITs from a Hudson bundle it's apparent that not everyone had SVN installed. we need to be more sensitive to different environments for testing if we want more people to participate.


Modified:
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java
    maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/execution/EmbedderUsingScmPluginTest.java

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java?rev=676103&r1=676102&r2=676103&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java (original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java Fri Jul 11 17:07:06 2008
@@ -1,45 +1,76 @@
 package org.apache.maven.embedder;
 
 /*
- * 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.
+ * 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.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.StringTokenizer;
 
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
 
 public abstract class AbstractEmbedderTestCase
     extends PlexusTestCase
 {
     protected MavenEmbedder maven;
 
+    private String defaultPath;
+
+    private List defaultPathList;
+
     protected void setUp()
         throws Exception
     {
         super.setUp();
-        
+
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 
-        Configuration configuration = new DefaultConfiguration()
-            .setClassLoader( classLoader )
-            .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
+        Configuration configuration = new DefaultConfiguration().setClassLoader( classLoader ).setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
 
         maven = new MavenEmbedder( configuration );
+        
+        // Some help with detecting executables on the command line. We want, in some cases, to use tools that are available on the command line
+        // but if they are not present on the machine we don't want tests to fail. Case in point would be using SVN via the SCM plugin. We'll
+        // run it if we can, pass through gracefully otherwise.
+
+        defaultPath = CommandLineUtils.getSystemEnvVars().getProperty( "PATH" );
+
+        if ( defaultPath == null )
+        {
+            defaultPathList = Collections.EMPTY_LIST;
+        }
+        else
+        {
+            String separator = System.getProperty( "path.separator" );
+
+            StringTokenizer tokenizer = new StringTokenizer( defaultPath, separator );
+
+            defaultPathList = new LinkedList();
+
+            while ( tokenizer.hasMoreElements() )
+            {
+                String element = (String) tokenizer.nextElement();
+
+                defaultPathList.add( element );
+            }
+        }        
     }
 
     protected void tearDown()
@@ -47,4 +78,69 @@
     {
         maven.stop();
     }
+
+    // ----------------------------------------------------------------------
+    // ExecutableResolver Implementation
+    // ----------------------------------------------------------------------
+
+    public List getDefaultPath()
+    {
+        return defaultPathList;
+    }
+
+    public File findExecutable( String executable )
+    {
+        return findExecutable( executable, getDefaultPath() );
+    }
+
+    public File findExecutable( String executable, List path )
+    {
+        if ( StringUtils.isEmpty( executable ) )
+        {
+            throw new NullPointerException( "executable cannot be null" );
+        }
+
+        if ( path == null )
+        {
+            throw new NullPointerException( "path cannot be null" );
+        }
+
+        File f = new File( executable );
+
+        if ( f.isAbsolute() && f.isFile() )
+        {
+            return f;
+        }
+
+        if ( path == null )
+        {
+            return null;
+        }
+
+        // TODO: Need to resolve it with defaults extension of system
+        // ie. if executable is 'mvn', we must search 'mvn.bat'
+        for ( Iterator it = path.iterator(); it.hasNext(); )
+        {
+            String s = (String) it.next();
+
+            f = new File( s, executable );
+
+            if ( f.isFile() )
+            {
+                return f;
+            }
+        }
+
+        return null;
+    }
+
+    public boolean hasExecutable( String executable )
+    {
+        return hasExecutable( executable, getDefaultPath() );
+    }
+
+    public boolean hasExecutable( String executable, List path )
+    {
+        return findExecutable( executable, path ) != null;
+    }
 }

Modified: maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/execution/EmbedderUsingScmPluginTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/execution/EmbedderUsingScmPluginTest.java?rev=676103&r1=676102&r2=676103&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/execution/EmbedderUsingScmPluginTest.java (original)
+++ maven/components/trunk/maven-embedder/src/test/java/org/apache/maven/embedder/execution/EmbedderUsingScmPluginTest.java Fri Jul 11 17:07:06 2008
@@ -1,22 +1,18 @@
 package org.apache.maven.embedder.execution;
 
 /*
- * 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.
+ * 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;
@@ -34,19 +30,29 @@
     public void testRunningScmPlugin()
         throws Exception
     {
-        File svnDirectory = new File( getBasedir(), ".svn" );
-
-        if ( svnDirectory.exists() )
+        if ( hasExecutable( "svn" ) )
         {
-            Properties p = new Properties();
+            File svnDirectory = new File( getBasedir(), ".svn" );
+
+            if ( svnDirectory.exists() )
+            {
+                Properties p = new Properties();
 
-            File outputDirectory = new File( getBasedir(), "target/scm.diff" );
+                File outputDirectory = new File( getBasedir(), "target/scm.diff" );
 
-            p.setProperty( "outputDirectory", outputDirectory.getCanonicalPath() );
+                p.setProperty( "outputDirectory", outputDirectory.getCanonicalPath() );
 
-            p.setProperty( "connectionUrl", "scm:svn:http://svn.apache.org/repos/asf/maven/components/trunk/maven-embedder" );
+                p.setProperty( "connectionUrl", "scm:svn:http://svn.apache.org/repos/asf/maven/components/trunk/maven-embedder" );
 
-            File basedir = runWithProject( "org.apache.maven.plugins:maven-scm-plugin:1.0:diff", p );
+                runWithProject( "org.apache.maven.plugins:maven-scm-plugin:1.0:diff", p );
+                
+                System.out.println( "SVN is available on this system, so we're running this SVN-related test." );                
+            }
+        }
+        else
+        {
+            System.out.println( "SVN is not available on this system, so we're not running this SVN-related test." );
         }
+       
     }
 }