maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From epunza...@apache.org
Subject svn commit: r389969 - in /maven/sandbox/maven-plugin-testing-harness/src: main/java/org/apache/maven/plugins/testing/ test/java/org/apache/maven/plugin/testing/
Date Thu, 30 Mar 2006 02:45:24 GMT
Author: epunzalan
Date: Wed Mar 29 18:45:22 2006
New Revision: 389969

URL: http://svn.apache.org/viewcvs?rev=389969&view=rev
Log:
Added expression evaluator for ${localRepository} with testcase

Added:
    maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
    maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
Modified:
    maven/sandbox/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugins/testing/ResolverExpressionEvaluatorStub.java

Modified: maven/sandbox/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugins/testing/ResolverExpressionEvaluatorStub.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugins/testing/ResolverExpressionEvaluatorStub.java?rev=389969&r1=389968&r2=389969&view=diff
==============================================================================
--- maven/sandbox/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugins/testing/ResolverExpressionEvaluatorStub.java
(original)
+++ maven/sandbox/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugins/testing/ResolverExpressionEvaluatorStub.java
Wed Mar 29 18:45:22 2006
@@ -21,6 +21,9 @@
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 
 /**
  * StubResolverExpressionEvaluator:
@@ -32,7 +35,7 @@
 public class ResolverExpressionEvaluatorStub
     implements ExpressionEvaluator
 {
-    
+
     public Object evaluate( String expr )
         throws ExpressionEvaluationException
     {
@@ -94,6 +97,11 @@
                 System.out.println( "Got expression '" + expression + "' that was not recognised"
);
             }
             return value;
+        }
+        else if ( "localRepository".equals( expression ) )
+        {
+            return new DefaultArtifactRepository( "localRepository", "file://" + System.getProperty(
"localRepository"),
+                                                  new DefaultRepositoryLayout() );
         }
         else
         {

Added: maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java?rev=389969&view=auto
==============================================================================
--- maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
(added)
+++ maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
Wed Mar 29 18:45:22 2006
@@ -0,0 +1,43 @@
+package org.apache.maven.plugin.testing;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ExpressionEvaluatorMojo
+    extends AbstractMojo
+{
+    private String basedir;
+
+    private ArtifactRepository localRepository;
+
+    private String workdir;
+
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        if ( StringUtils.isEmpty( basedir ) )
+        {
+            throw new MojoExecutionException( "basedir was not injected." );
+        }
+
+        if ( localRepository == null )
+        {
+            throw new MojoExecutionException( "localRepository was not injected." );
+        }
+
+        if ( StringUtils.isEmpty( workdir ) )
+        {
+            throw new MojoExecutionException( "workdir was not injected." );
+        }
+        else if ( !workdir.startsWith( basedir ) )
+        {
+            throw new MojoExecutionException( "workdir does not start with basedir." );
+        }
+    }
+}

Added: maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
URL: http://svn.apache.org/viewcvs/maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java?rev=389969&view=auto
==============================================================================
--- maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
(added)
+++ maven/sandbox/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
Wed Mar 29 18:45:22 2006
@@ -0,0 +1,64 @@
+package org.apache.maven.plugin.testing;
+
+import org.apache.maven.plugins.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+
+import java.io.StringReader;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class ExpressionEvaluatorTest
+    extends AbstractMojoTestCase
+{
+    private Xpp3Dom pomDom;
+
+    private PlexusConfiguration pluginConfiguration;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        StringBuffer pom = new StringBuffer();
+
+        pom.append( "<project>" ).append( "\n" );
+        pom.append( "  <build>" ).append( "\n" );
+        pom.append( "    <plugins>" ).append( "\n" );
+        pom.append( "      <plugin>" ).append( "\n" );
+        pom.append( "        <artifactId>maven-test-mojo</artifactId>" ).append(
"\n" );
+        pom.append( "        <configuration>" ).append( "\n" );
+        pom.append( "          <basedir>${basedir}</basedir>" ).append( "\n"
);
+        pom.append( "          <workdir>${basedir}/workDirectory</workdir>" ).append(
"\n" );
+        pom.append( "          <localRepository>${localRepository}</localRepository>"
).append( "\n" );
+        pom.append( "        </configuration>" ).append( "\n" );
+        pom.append( "      </plugin>" ).append( "\n" );
+        pom.append( "    </plugins>" ).append( "\n" );
+        pom.append( "  </build>" ).append( "\n" );
+        pom.append( "</project>" ).append( "\n" );
+
+        pomDom = Xpp3DomBuilder.build( new StringReader( pom.toString() ) );
+
+        pluginConfiguration = extractPluginConfiguration( "maven-test-mojo", pomDom );
+    }
+
+    public void testInjection()
+        throws Exception
+    {
+        ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo();
+
+        mojo = (ExpressionEvaluatorMojo) configureMojo( mojo, pluginConfiguration );
+
+        try
+        {
+            mojo.execute();
+        }
+        catch ( MojoExecutionException e )
+        {
+            fail( e.getMessage() );
+        }
+    }
+}



Mime
View raw message