Author: olamy
Date: Wed Nov 21 14:56:16 2007
New Revision: 597241

URL: http://svn.apache.org/viewvc?rev=597241&view=rev
Log:
add unit test

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/test/
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/
    
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/
    
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/
    
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
    maven/plugins/trunk/maven-invoker-plugin/src/test/resources/
    maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/
    
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/
    
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/goals.txt
    
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/pom.xml
    
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/validate-goal.txt
    
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/verify.bsh
Modified:
    maven/plugins/trunk/maven-invoker-plugin/pom.xml
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=597241&r1=597240&r2=597241&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Wed Nov 21 14:56:16 2007
@@ -1,9 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
-    <version>8</version>
+    <version>10</version>
   </parent>
   <artifactId>maven-invoker-plugin</artifactId>
   <version>1.1-SNAPSHOT</version>
@@ -12,6 +31,20 @@
   </prerequisites>   
   <packaging>maven-plugin</packaging>
   <name>Maven Invoker Plugin</name>
+               
+  <scm>
+    
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin/</connection>
+    
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin/</developerConnection>
+    
<url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/</url>
+  </scm>       
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3</version>
+      </plugin>
+    </plugins>
+  </build>     
   <dependencies>
     <dependency>
       <groupId>org.apache.maven.shared</groupId>
@@ -48,5 +81,16 @@
       <artifactId>bsh</artifactId>
       <version>2.0b4</version>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.4.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-plugin-testing-harness</artifactId>
+      <version>1.1</version>
+      <scope>test</scope>
+    </dependency>      
   </dependencies>
 </project>

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=597241&r1=597240&r2=597241&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
 Wed Nov 21 14:56:16 2007
@@ -527,6 +527,7 @@
 
             try
             {
+                System.out.println( "invoker == null " + (invoker == null) );
                 result = invoker.execute( request );
             }
             catch ( final MavenInvocationException e )
@@ -584,6 +585,10 @@
     private Properties loadTestProperties( final File basedir )
         throws IOException
     {
+        if (testProperties == null)
+        {
+            return new Properties();
+        }
         final File testProperties = new File( basedir, testPropertiesFile );
 
         final Properties testProps = new Properties();
@@ -709,7 +714,7 @@
         return result;
     }
 
-    private List getGoals( final File basedir )
+    protected List getGoals( final File basedir )
     {
         List invocationGoals = goals;
 

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java?rev=597241&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
 Wed Nov 21 14:56:16 2007
@@ -0,0 +1,80 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.shared.invoker.Invoker;
+import org.codehaus.plexus.util.FileUtils;
+
+
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">olamy</a>
+ * @since 18 nov. 07
+ * @version $Id$
+ */
+public class InvokerMojoTest
+    extends AbstractMojoTestCase
+{
+
+    /**
+     * test reading goals from a file
+     */
+    public void testReadGoalsFromFile()
+        throws Exception
+    {
+        InvokerMojo invokerMojo = new InvokerMojo();
+        setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
+        String dirPath = getBasedir() + 
"/src/test/resources/unit/goals-from-file/";
+        List goals = invokerMojo.getGoals( new File( dirPath ) );
+        assertEquals( 3, goals.size() );
+    }
+    
+    public void testSimpleRunValidate()
+        throws Exception
+    {
+        InvokerMojo invokerMojo = new InvokerMojo();
+        setVariableValueToObject( invokerMojo, "goalsFile", 
"validate-goal.txt" );
+        String dirPath = getBasedir() + 
"/src/test/resources/unit/goals-from-file/";
+        List goals = invokerMojo.getGoals( new File( dirPath ) );
+        assertEquals( 1, goals.size() );
+        setVariableValueToObject( invokerMojo, "projectsDirectory", new File( 
dirPath ) );
+        List pomIncludes = new ArrayList();
+        pomIncludes.add( "pom.xml" );
+        setVariableValueToObject( invokerMojo, "pomIncludes", pomIncludes );
+        setVariableValueToObject( invokerMojo, "invoker", 
getContainer().lookup( Invoker.ROLE ) );
+        File cloneProjectsTo = new File( "target/goals-from-file/" );
+        // clean if exists
+        if ( cloneProjectsTo.exists() )
+        {
+            FileUtils.deleteDirectory( cloneProjectsTo );
+        }
+        //cloneProjectsTo.getParent()
+        setVariableValueToObject( invokerMojo, "cloneProjectsTo", 
cloneProjectsTo );
+        setVariableValueToObject( invokerMojo, "postBuildHookScript", 
"verify.bsh" );
+        invokerMojo.execute();
+    }
+    
+}

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/goals.txt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/goals.txt?rev=597241&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/goals.txt
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/goals.txt
 Wed Nov 21 14:56:16 2007
@@ -0,0 +1,2 @@
+clean , test
+install
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/pom.xml?rev=597241&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/pom.xml
 Wed Nov 21 14:56:16 2007
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.test</groupId>
+  <artifactId>unit</artifactId>
+  <packaging>pom</packaging>
+  <version>0.1-SNAPSHOT</version>
+</project>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/validate-goal.txt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/validate-goal.txt?rev=597241&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/validate-goal.txt
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/validate-goal.txt
 Wed Nov 21 14:56:16 2007
@@ -0,0 +1 @@
+validate
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/verify.bsh?rev=597241&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/verify.bsh
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/test/resources/unit/goals-from-file/verify.bsh
 Wed Nov 21 14:56:16 2007
@@ -0,0 +1,49 @@
+
+/*
+ * 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.*;
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    
+    File build = new File ( basedir, "build.log" );
+    if ( !build.exists() || build.isDirectory() )
+    {
+        System.err.println( "build.log file is missing or a directory." );
+        return false;
+    }    
+    FileInputStream fis = new FileInputStream ( build );
+    String buildContent = IOUtil.toString ( fis );
+    int indexOf = buildContent.indexOf( "BUILD SUCCESSFUL" );
+    if ( indexOf < 0)
+    {
+       System.err.println( "build.log doesn't contains BUILD SUCCESSFUL" );
+    }    
+}
+catch( IOException e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;


Reply via email to