You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/05/02 08:43:42 UTC
svn commit: r398826 - in /maven/plugins/trunk/maven-release-plugin/src:
main/java/org/apache/maven/plugins/release/exec/
main/java/org/apache/maven/plugins/release/phase/
main/resources/META-INF/plexus/
test/java/org/apache/maven/plugins/release/exec/ ...
Author: brett
Date: Mon May 1 23:43:39 2006
New Revision: 398826
URL: http://svn.apache.org/viewcvs?rev=398826&view=rev
Log:
[MRELEASE-98] add run tests phase and tests
Added:
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java (with props)
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java (with props)
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java (with props)
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java (with props)
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java (with props)
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java (with props)
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java (with props)
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java (with props)
Modified:
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RunTestsPhase.java
maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
Added: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java Mon May 1 23:43:39 2006
@@ -0,0 +1,42 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Create a command line for execution. Componentised to allow mocking.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface CommandLineFactory
+{
+ /**
+ * Plexus role.
+ */
+ String ROLE = CommandLineFactory.class.getName();
+
+ /**
+ * Create a command line object with default environment for the given executable.
+ *
+ * @param executable the executable
+ * @return the command line
+ * @throws MavenExecutorException if there was a problem creating the command line
+ */
+ Commandline createCommandLine( String executable )
+ throws MavenExecutorException;
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/CommandLineFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java Mon May 1 23:43:39 2006
@@ -0,0 +1,46 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Create a command line instance.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class DefaultCommandLineFactory
+ implements CommandLineFactory
+{
+ public Commandline createCommandLine( String executable )
+ throws MavenExecutorException
+ {
+ Commandline commandline = new Commandline();
+ commandline.setExecutable( executable );
+
+ try
+ {
+ commandline.addSystemEnvironment();
+ }
+ catch ( Exception e )
+ {
+ throw new MavenExecutorException( e.getMessage(), e );
+ }
+
+ return commandline;
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/DefaultCommandLineFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java Mon May 1 23:43:39 2006
@@ -0,0 +1,127 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+
+/**
+ * Fork Maven to executed a series of goals.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ForkedMavenExecutor
+ extends AbstractLogEnabled
+ implements MavenExecutor
+{
+ private CommandLineFactory commandLineFactory;
+
+ public void executeGoals( File workingDirectory, String goals, boolean interactive, String arguments )
+ throws MavenExecutorException
+ {
+ Commandline cl = commandLineFactory.createCommandLine( "mvn" );
+
+ cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+
+ cl.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
+
+ if ( goals != null )
+ {
+ // accept both space and comma, so the old way still work
+ String [] tokens = StringUtils.split( goals, ", " );
+
+ for ( int i = 0; i < tokens.length; ++i )
+ {
+ cl.createArgument().setValue( tokens[i] );
+ }
+ }
+
+ cl.createArgument().setValue( "--no-plugin-updates" );
+
+ if ( !interactive )
+ {
+ cl.createArgument().setValue( "--batch-mode" );
+ }
+
+ // TODO [!] check that callers split parameters that could formerly be comma-separated
+ if ( !StringUtils.isEmpty( arguments ) )
+ {
+ cl.createArgument().setLine( arguments );
+ }
+
+ /* TODO [!]
+ List profiles = project.getActiveProfiles();
+
+ if ( profiles != null && !profiles.isEmpty() )
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append( "-P " );
+
+ for ( Iterator it = profiles.iterator(); it.hasNext(); )
+ {
+ Profile profile = (Profile) it.next();
+
+ buffer.append( profile.getId() ).append( "," );
+ }
+
+ buffer.setLength( buffer.length() - 1 );
+
+ cl.createArgument().setLine( buffer.toString() );
+ }
+*/
+
+ // TODO: do these still stream?
+ StreamConsumer stdOut = new CommandLineUtils.StringStreamConsumer();
+
+ StreamConsumer stdErr = new CommandLineUtils.StringStreamConsumer();
+
+ try
+ {
+ getLogger().debug( cl.toString() );
+
+ int result = CommandLineUtils.executeCommandLine( cl, stdOut, stdErr );
+
+ if ( result != 0 )
+ {
+ throw new MavenExecutorException( "Maven execution failed, exit code: \'" + result + "\'", result,
+ stdOut.toString(), stdErr.toString() );
+ }
+ }
+ catch ( CommandLineException e )
+ {
+ throw new MavenExecutorException( "Can't run goal " + goals, stdOut.toString(), stdErr.toString(), e );
+ }
+ }
+
+ public void executeGoals( File workingDirectory, String goals, boolean interactive )
+ throws MavenExecutorException
+ {
+ executeGoals( workingDirectory, goals, interactive, null );
+ }
+
+ public void setCommandLineFactory( CommandLineFactory commandLineFactory )
+ {
+ this.commandLineFactory = commandLineFactory;
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java Mon May 1 23:43:39 2006
@@ -0,0 +1,55 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+/**
+ * Execute Maven. May be implemented as a forked instance, or embedded.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface MavenExecutor
+{
+ /**
+ * Plexus Role.
+ */
+ String ROLE = MavenExecutor.class.getName();
+
+ /**
+ * Execute goals using Maven.
+ *
+ * @param workingDirectory the directory to execute in
+ * @param goals the goals to run (space delimited)
+ * @param interactive whether to execute in interactive mode, or the default batch mode
+ * @param arguments the arguments to pass to the executable (space delimited)
+ * @throws MavenExecutorException if an error occurred executing Maven
+ */
+ void executeGoals( File workingDirectory, String goals, boolean interactive, String arguments )
+ throws MavenExecutorException;
+
+ /**
+ * Execute goals using Maven.
+ *
+ * @param workingDirectory the directory to execute in
+ * @param goals the goals to run (space delimited)
+ * @param interactive whether to execute in interactive mode, or the default batch mode
+ * @throws MavenExecutorException if an error occurred executing Maven
+ */
+ void executeGoals( File workingDirectory, String goals, boolean interactive )
+ throws MavenExecutorException;
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java Mon May 1 23:43:39 2006
@@ -0,0 +1,59 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Exception executing Maven.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class MavenExecutorException
+ extends Exception
+{
+ private String stdErr;
+
+ private String stdOut;
+
+ private int exitCode;
+
+ public MavenExecutorException( String message, int exitCode, String stdOut, String stdErr )
+ {
+ super( message );
+
+ this.exitCode = exitCode;
+ this.stdOut = stdOut;
+ this.stdErr = stdErr;
+ }
+
+ public MavenExecutorException( String message, String stdOut, String stdErr, Exception e )
+ {
+ super( message, e );
+
+ this.stdOut = stdOut;
+ this.stdErr = stdErr;
+ }
+
+ public MavenExecutorException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+ public int getExitCode()
+ {
+ return exitCode;
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/exec/MavenExecutorException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RunTestsPhase.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RunTestsPhase.java?rev=398826&r1=398825&r2=398826&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RunTestsPhase.java (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/RunTestsPhase.java Mon May 1 23:43:39 2006
@@ -16,25 +16,51 @@
* limitations under the License.
*/
+import org.apache.maven.plugins.release.ReleaseExecutionException;
import org.apache.maven.plugins.release.config.ReleaseConfiguration;
+import org.apache.maven.plugins.release.exec.MavenExecutor;
+import org.apache.maven.plugins.release.exec.MavenExecutorException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
- * TODO [!]: Description.
+ * Run the integration tests for the project to verify that it builds before committing.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
*/
public class RunTestsPhase
+ extends AbstractLogEnabled
implements ReleasePhase
{
+ /**
+ * Component to assist in executing Maven.
+ */
+ private MavenExecutor mavenExecutor;
+
public void execute( ReleaseConfiguration releaseConfiguration )
+ throws ReleaseExecutionException
{
- // TODO [!]: implement
-
+ try
+ {
+ mavenExecutor.executeGoals( releaseConfiguration.getWorkingDirectory(), "clean integration-test",
+ releaseConfiguration.isInteractive() );
+ }
+ catch ( MavenExecutorException e )
+ {
+ throw new ReleaseExecutionException( e.getMessage(), e );
+ }
}
public void simulate( ReleaseConfiguration releaseConfiguration )
+ throws ReleaseExecutionException
{
- // TODO [!]: implement
+ getLogger().info(
+ "Executing tests - since this is simulation mode it is testing the original project, not the rewritten ones" );
+ execute( releaseConfiguration );
+ }
+
+ public void setMavenExecutor( MavenExecutor mavenExecutor )
+ {
+ this.mavenExecutor = mavenExecutor;
}
}
Modified: maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml?rev=398826&r1=398825&r2=398826&view=diff
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml Mon May 1 23:43:39 2006
@@ -138,6 +138,11 @@
<role>org.apache.maven.plugins.release.phase.ReleasePhase</role>
<role-hint>run-tests</role-hint>
<implementation>org.apache.maven.plugins.release.phase.RunTestsPhase</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.plugins.release.exec.MavenExecutor</role>
+ </requirement>
+ </requirements>
</component>
<component>
<role>org.apache.maven.plugins.release.phase.ReleasePhase</role>
@@ -185,6 +190,14 @@
<role>org.apache.maven.plugins.release.scm.ScmTranslator</role>
<role-hint>svn</role-hint>
<implementation>org.apache.maven.plugins.release.scm.SubversionScmTranslator</implementation>
+ </component>
+ <component>
+ <role>org.apache.maven.plugins.release.exec.MavenExecutor</role>
+ <implementation>org.apache.maven.plugins.release.exec.ForkedMavenExecutor</implementation>
+ </component>
+ <component>
+ <role>org.apache.maven.plugins.release.exec.CommandLineFactory</role>
+ <implementation>org.apache.maven.plugins.release.exec.DefaultCommandLineFactory</implementation>
</component>
</components>
</component-set>
Added: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java Mon May 1 23:43:39 2006
@@ -0,0 +1,49 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Test the command line factory.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class CommandLineFactoryTest
+ extends PlexusTestCase
+{
+ private CommandLineFactory factory;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ factory = (CommandLineFactory) lookup( CommandLineFactory.ROLE );
+ }
+
+ public void testCreation()
+ throws Exception
+ {
+ Commandline cl = factory.createCommandLine( "exec" );
+
+ assertEquals( "Check executable", "exec", cl.getExecutable() );
+ assertNotNull( "Check environment", cl.getEnvironments() );
+ assertFalse( "Check environment", cl.getEnvironments().length == 0 );
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/CommandLineFactoryTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java Mon May 1 23:43:39 2006
@@ -0,0 +1,213 @@
+package org.apache.maven.plugins.release.exec;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.StringInputStream;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.jmock.cglib.Mock;
+import org.jmock.core.constraint.IsEqual;
+import org.jmock.core.matcher.InvokeOnceMatcher;
+import org.jmock.core.stub.ReturnStub;
+import org.jmock.core.stub.ThrowStub;
+
+import java.io.File;
+
+/**
+ * Test the forked Maven executor.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class ForkedMavenExecutorTest
+ extends PlexusTestCase
+{
+ private ForkedMavenExecutor executor;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ executor = (ForkedMavenExecutor) lookup( MavenExecutor.ROLE );
+ }
+
+ public void testExecution()
+ throws MavenExecutorException
+ {
+ File workingDirectory = getTestFile( "target/working-directory" );
+
+ Process process = createMockProcess( 0 );
+
+ Mock commandLineMock = createMockCommandLine( workingDirectory, process );
+ expectDefaultArguments( commandLineMock );
+
+ Mock mock = new Mock( CommandLineFactory.class );
+
+ mock.expects( new InvokeOnceMatcher() ).method( "createCommandLine" ).with( new IsEqual( "mvn" ) ).will(
+ new ReturnStub( commandLineMock.proxy() ) );
+
+ executor.setCommandLineFactory( (CommandLineFactory) mock.proxy() );
+
+ executor.executeGoals( workingDirectory, "clean integration-test", false );
+
+ assertTrue( true );
+ }
+
+ public void testExecutionWithArguments()
+ throws MavenExecutorException
+ {
+ File workingDirectory = getTestFile( "target/working-directory" );
+
+ Process process = createMockProcess( 0 );
+
+ Mock commandLineMock = createMockCommandLine( workingDirectory, process );
+ String arguments = "-DperformRelease=true -Dmaven.test.skip=true";
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "createArgument" ).will(
+ new ReturnStub( createArgumentLineMock( arguments ) ) );
+
+ expectDefaultArguments( commandLineMock );
+
+ Mock mock = new Mock( CommandLineFactory.class );
+
+ mock.expects( new InvokeOnceMatcher() ).method( "createCommandLine" ).with( new IsEqual( "mvn" ) ).will(
+ new ReturnStub( commandLineMock.proxy() ) );
+
+ executor.setCommandLineFactory( (CommandLineFactory) mock.proxy() );
+
+ executor.executeGoals( workingDirectory, "clean integration-test", false, arguments );
+
+ assertTrue( true );
+ }
+
+ public void testExecutionWithNonZeroExitCode()
+ throws MavenExecutorException
+ {
+ File workingDirectory = getTestFile( "target/working-directory" );
+
+ Process process = createMockProcess( 1 );
+
+ Mock commandLineMock = createMockCommandLine( workingDirectory, process );
+
+ expectDefaultArguments( commandLineMock );
+
+ Mock mock = new Mock( CommandLineFactory.class );
+
+ mock.expects( new InvokeOnceMatcher() ).method( "createCommandLine" ).with( new IsEqual( "mvn" ) ).will(
+ new ReturnStub( commandLineMock.proxy() ) );
+
+ executor.setCommandLineFactory( (CommandLineFactory) mock.proxy() );
+
+ try
+ {
+ executor.executeGoals( workingDirectory, "clean integration-test", false );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( MavenExecutorException e )
+ {
+ assertEquals( "Check exit code", 1, e.getExitCode() );
+ }
+ }
+
+ public void testExecutionWithCommandLineException()
+ throws MavenExecutorException
+ {
+ File workingDirectory = getTestFile( "target/working-directory" );
+
+ Mock commandLineMock = new Mock( Commandline.class );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "setWorkingDirectory" ).with(
+ new IsEqual( workingDirectory.getAbsolutePath() ) );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "addEnvironment" ).with(
+ new IsEqual( "MAVEN_TERMINATE_CMD" ), new IsEqual( "on" ) );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "execute" ).will(
+ new ThrowStub( new CommandLineException( "..." ) ) );
+
+ expectDefaultArguments( commandLineMock );
+
+ Mock mock = new Mock( CommandLineFactory.class );
+
+ mock.expects( new InvokeOnceMatcher() ).method( "createCommandLine" ).with( new IsEqual( "mvn" ) ).will(
+ new ReturnStub( commandLineMock.proxy() ) );
+
+ executor.setCommandLineFactory( (CommandLineFactory) mock.proxy() );
+
+ try
+ {
+ executor.executeGoals( workingDirectory, "clean integration-test", false );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( MavenExecutorException e )
+ {
+ assertEquals( "Check cause", CommandLineException.class, e.getCause().getClass() );
+ }
+ }
+
+ private static void expectDefaultArguments( Mock commandLineMock )
+ {
+ String[] args = new String[]{"clean", "integration-test", "--no-plugin-updates", "--batch-mode"};
+ for ( int i = args.length - 1; i >= 0; i-- )
+ {
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "createArgument" ).will(
+ new ReturnStub( createArgumentValueMock( args[i] ) ) );
+ }
+ }
+
+ private static Mock createMockCommandLine( File workingDirectory, Process process )
+ {
+ Mock commandLineMock = new Mock( Commandline.class );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "setWorkingDirectory" ).with(
+ new IsEqual( workingDirectory.getAbsolutePath() ) );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "addEnvironment" ).with(
+ new IsEqual( "MAVEN_TERMINATE_CMD" ), new IsEqual( "on" ) );
+ commandLineMock.expects( new InvokeOnceMatcher() ).method( "execute" ).will( new ReturnStub( process ) );
+
+ return commandLineMock;
+ }
+
+ private static Commandline.Argument createArgumentValueMock( String value )
+ {
+ Mock mock = new Mock( Commandline.Argument.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "setValue" ).with( new IsEqual( value ) );
+ return (Commandline.Argument) mock.proxy();
+ }
+
+ private static Commandline.Argument createArgumentLineMock( String value )
+ {
+ Mock mock = new Mock( Commandline.Argument.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "setLine" ).with( new IsEqual( value ) );
+ return (Commandline.Argument) mock.proxy();
+ }
+
+ private static Process createMockProcess( int exitCode )
+ {
+ Mock mockProcess = new Mock( Process.class );
+ mockProcess.expects( new InvokeOnceMatcher() ).method( "getInputStream" ).will(
+ new ReturnStub( new StringInputStream( "" ) ) );
+ mockProcess.expects( new InvokeOnceMatcher() ).method( "getErrorStream" ).will(
+ new ReturnStub( new StringInputStream( "" ) ) );
+ mockProcess.expects( new InvokeOnceMatcher() ).method( "waitFor" ).will(
+ new ReturnStub( Integer.valueOf( exitCode ) ) );
+ if ( exitCode != 0 )
+ {
+ mockProcess.expects( new InvokeOnceMatcher() ).method( "exitValue" ).will(
+ new ReturnStub( Integer.valueOf( exitCode ) ) );
+ }
+ return (Process) mockProcess.proxy();
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/exec/ForkedMavenExecutorTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java?rev=398826&view=auto
==============================================================================
--- maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java (added)
+++ maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java Mon May 1 23:43:39 2006
@@ -0,0 +1,145 @@
+package org.apache.maven.plugins.release.phase;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.plugins.release.ReleaseExecutionException;
+import org.apache.maven.plugins.release.config.ReleaseConfiguration;
+import org.apache.maven.plugins.release.exec.MavenExecutor;
+import org.apache.maven.plugins.release.exec.MavenExecutorException;
+import org.codehaus.plexus.PlexusTestCase;
+import org.jmock.cglib.Mock;
+import org.jmock.core.constraint.IsEqual;
+import org.jmock.core.constraint.IsSame;
+import org.jmock.core.matcher.InvokeOnceMatcher;
+import org.jmock.core.stub.ThrowStub;
+
+import java.io.File;
+
+/**
+ * Test the simple test running phase.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class RunTestsPhaseTest
+ extends PlexusTestCase
+{
+ private RunTestsPhase phase;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ phase = (RunTestsPhase) lookup( ReleasePhase.ROLE, "run-tests" );
+ }
+
+ public void testExecute()
+ throws ReleaseExecutionException
+ {
+ File testFile = getTestFile( "target/working-directory" );
+
+ ReleaseConfiguration config = new ReleaseConfiguration();
+ config.setWorkingDirectory( testFile );
+
+ Mock mock = new Mock( MavenExecutor.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "executeGoals" ).with( new IsSame( testFile ),
+ new IsEqual( "clean integration-test" ),
+ new IsEqual( Boolean.TRUE ) );
+
+ phase.setMavenExecutor( (MavenExecutor) mock.proxy() );
+
+ phase.execute( config );
+
+ // just needs to survive the mock
+ assertTrue( true );
+ }
+
+ public void testSimulate()
+ throws ReleaseExecutionException
+ {
+ File testFile = getTestFile( "target/working-directory" );
+
+ ReleaseConfiguration config = new ReleaseConfiguration();
+ config.setWorkingDirectory( testFile );
+
+ Mock mock = new Mock( MavenExecutor.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "executeGoals" ).with( new IsSame( testFile ),
+ new IsEqual( "clean integration-test" ),
+ new IsEqual( Boolean.TRUE ) );
+
+ phase.setMavenExecutor( (MavenExecutor) mock.proxy() );
+
+ phase.simulate( config );
+
+ // just needs to survive the mock
+ assertTrue( true );
+ }
+
+ public void testExecuteException()
+ {
+ File testFile = getTestFile( "target/working-directory" );
+
+ ReleaseConfiguration config = new ReleaseConfiguration();
+ config.setWorkingDirectory( testFile );
+
+ Mock mock = new Mock( MavenExecutor.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "executeGoals" ).with( new IsSame( testFile ),
+ new IsEqual( "clean integration-test" ),
+ new IsEqual( Boolean.TRUE ) ).will(
+ new ThrowStub( new MavenExecutorException( "...", new Exception() ) ) );
+
+ phase.setMavenExecutor( (MavenExecutor) mock.proxy() );
+
+ try
+ {
+ phase.execute( config );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( ReleaseExecutionException e )
+ {
+ assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() );
+ }
+ }
+
+ public void testSimulateException()
+ {
+ File testFile = getTestFile( "target/working-directory" );
+
+ ReleaseConfiguration config = new ReleaseConfiguration();
+ config.setWorkingDirectory( testFile );
+
+ Mock mock = new Mock( MavenExecutor.class );
+ mock.expects( new InvokeOnceMatcher() ).method( "executeGoals" ).with( new IsSame( testFile ),
+ new IsEqual( "clean integration-test" ),
+ new IsEqual( Boolean.TRUE ) ).will(
+ new ThrowStub( new MavenExecutorException( "...", new Exception() ) ) );
+
+ phase.setMavenExecutor( (MavenExecutor) mock.proxy() );
+
+ try
+ {
+ phase.simulate( config );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( ReleaseExecutionException e )
+ {
+ assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() );
+ }
+ }
+}
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/RunTestsPhaseTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision