This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-invoker-plugin-1.1
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git

commit 4fe657987ac9b6d9e250cb3283ff035efbf3d70c
Author: Oliver Lamy <ol...@apache.org>
AuthorDate: Wed Nov 21 22:56:16 2007 +0000

    add unit test
    
    git-svn-id: 
https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-invoker-plugin@597241
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 46 ++++++++++++-
 .../apache/maven/plugin/invoker/InvokerMojo.java   |  7 +-
 .../maven/plugin/invoker/InvokerMojoTest.java      | 80 ++++++++++++++++++++++
 src/test/resources/unit/goals-from-file/goals.txt  |  2 +
 src/test/resources/unit/goals-from-file/pom.xml    | 26 +++++++
 .../unit/goals-from-file/validate-goal.txt         |  1 +
 src/test/resources/unit/goals-from-file/verify.bsh | 49 +++++++++++++
 7 files changed, 209 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 95169cd..56d4d5e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java 
b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
index 280b22e..7cec502 100644
--- a/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
@@ -527,6 +527,7 @@ public class InvokerMojo
 
             try
             {
+                System.out.println( "invoker == null " + (invoker == null) );
                 result = invoker.execute( request );
             }
             catch ( final MavenInvocationException e )
@@ -584,6 +585,10 @@ public class InvokerMojo
     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 @@ public class InvokerMojo
         return result;
     }
 
-    private List getGoals( final File basedir )
+    protected List getGoals( final File basedir )
     {
         List invocationGoals = goals;
 
diff --git a/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java 
b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
new file mode 100644
index 0000000..068a761
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
@@ -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:ol...@apache.org";>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();
+    }
+    
+}
diff --git a/src/test/resources/unit/goals-from-file/goals.txt 
b/src/test/resources/unit/goals-from-file/goals.txt
new file mode 100644
index 0000000..e58333f
--- /dev/null
+++ b/src/test/resources/unit/goals-from-file/goals.txt
@@ -0,0 +1,2 @@
+clean , test
+install
\ No newline at end of file
diff --git a/src/test/resources/unit/goals-from-file/pom.xml 
b/src/test/resources/unit/goals-from-file/pom.xml
new file mode 100644
index 0000000..fc80363
--- /dev/null
+++ b/src/test/resources/unit/goals-from-file/pom.xml
@@ -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
diff --git a/src/test/resources/unit/goals-from-file/validate-goal.txt 
b/src/test/resources/unit/goals-from-file/validate-goal.txt
new file mode 100644
index 0000000..1d8e0fd
--- /dev/null
+++ b/src/test/resources/unit/goals-from-file/validate-goal.txt
@@ -0,0 +1 @@
+validate
\ No newline at end of file
diff --git a/src/test/resources/unit/goals-from-file/verify.bsh 
b/src/test/resources/unit/goals-from-file/verify.bsh
new file mode 100644
index 0000000..61c620a
--- /dev/null
+++ b/src/test/resources/unit/goals-from-file/verify.bsh
@@ -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;

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <commits@maven.apache.org>.

Reply via email to