Author: eworley Date: Sun Dec 30 17:23:20 2007 New Revision: 607643 URL: http://svn.apache.org/viewvc?rev=607643&view=rev Log: * Adding test lifecycle * Adding DotnetTestMojo * Added check for nunit-console not being on path * Adding basic nunit innvocation, with a few TODos left * Updating IT0007 to have a few tests in it for reporting
Added: incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/DotnetTestMojo.java Modified: incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/src/test/dotnet/It0007.cs incubator/nmaven/trunk/plugins/dotnet-test-plugin/pom.xml incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/resources/META-INF/plexus/components.xml Modified: incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/src/test/dotnet/It0007.cs URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/src/test/dotnet/It0007.cs?rev=607643&r1=607642&r2=607643&view=diff ============================================================================== --- incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/src/test/dotnet/It0007.cs (original) +++ incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/src/test/dotnet/It0007.cs Sun Dec 30 17:23:20 2007 @@ -6,8 +6,20 @@ [TestFixture] public class It0007 { [Test] - public void testSimple() { + public void testSimple1() { Assertion.AssertEquals(1, 1); + } + + [Test] + public void testSimple2() { + Assertion.AssertEquals(2, 2); + } + + [Test] + public void testTakesSomeTime() { + for (int i=0; i < 9999999; i++) { + Assertion.AssertEquals(i+1, i+1); + } } } } Modified: incubator/nmaven/trunk/plugins/dotnet-test-plugin/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/dotnet-test-plugin/pom.xml?rev=607643&r1=607642&r2=607643&view=diff ============================================================================== --- incubator/nmaven/trunk/plugins/dotnet-test-plugin/pom.xml (original) +++ incubator/nmaven/trunk/plugins/dotnet-test-plugin/pom.xml Sun Dec 30 17:23:20 2007 @@ -25,18 +25,25 @@ <version>0.15-incubating-SNAPSHOT</version> <artifactId>maven-dotnet-plugins</artifactId> </parent> + <modelVersion>4.0.0</modelVersion> <groupId>org.apache.maven.dotnet.plugins</groupId> <artifactId>dotnet-test-plugin</artifactId> <packaging>maven-plugin</packaging> <name>dotnet-test-plugin</name> <description>Maven Plugin for .NET: Handles nunit test execution and reporting</description> + <dependencies> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + </dependency> </dependencies> + <distributionManagement> <site> <id>nmaven-apache-site</id> Added: incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/DotnetTestMojo.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/DotnetTestMojo.java?rev=607643&view=auto ============================================================================== --- incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/DotnetTestMojo.java (added) +++ incubator/nmaven/trunk/plugins/dotnet-test-plugin/src/main/java/org/apache/maven/dotnet/plugin/nunit/DotnetTestMojo.java Sun Dec 30 17:23:20 2007 @@ -0,0 +1,138 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.plugin.nunit; + + +import java.io.File; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +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; + +/** + * Maven Mojo for executing nunit tests + * + * @goal test + * @phase test + * @description Maven Mojo for executing nunit tests + */ +public class DotnetTestMojo + extends AbstractMojo +{ + // Used to determine if nunit-console is not on the path + // TODO: This probably only works on Windows machines + private static final String COMMAND_NOT_FOUND_FRAGMENT = + "is not recognized as an internal or external command"; + + // Command, options, assembly + private static final String NUNIT_CALL_FMT = "%s %s %s"; + + private static final String NUNIT_EXECUTABLE = "nunit-console"; + private static final String NUNIT_OPTIONS = ""; +// private static final String NUNIT_OPTIONS = "/labels /nologo"; + + /** + * The maven project. + * + * @parameter expression="${project}" + * @required + */ + private MavenProject project; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + // The directory where the test artifact exists + String outputDirectory = project.getBuild().getDirectory(); + + String innvocation = getNUnitInvocation(); + + Commandline commandline = new Commandline(); + + getLog().debug("NMaven-test: workingDirectory(" + outputDirectory + ")"); + + commandline.setWorkingDirectory(outputDirectory); + commandline.setExecutable(innvocation); + + NUnitStreamConsumer systemOut = new NUnitStreamConsumer(getLog()); + NUnitStreamConsumer systemErr = new NUnitStreamConsumer(getLog()); + + try + { + // Execute the commandline + CommandLineUtils.executeCommandLine(commandline, systemOut, systemErr); + + // Check if nunit-console is not in the path + if (systemErr.isCommandNotFound()) + { + throw new MojoExecutionException("Please add nunit-console to your path"); + } + } + catch (CommandLineException e) + { + throw new MojoExecutionException("Failure executing commandline, " + e.getMessage()); + } + + // TODO: Turn this into a debug + getLog().info("Executed command: " + commandline); + + getLog().info("Done executing tests.."); + } + + private String getNUnitInvocation() throws MojoExecutionException { + + File file = project.getArtifact().getFile(); + String pieces = file.getName().substring(0, file.getName().lastIndexOf('.')); + String testAssemblyName = pieces + "-test.dll"; + + return String.format(NUNIT_CALL_FMT, NUNIT_EXECUTABLE, NUNIT_OPTIONS, testAssemblyName); + } + + private static class NUnitStreamConsumer implements StreamConsumer { + + private boolean commandNotFound; + private StringBuilder consumedLines = new StringBuilder(); + + private Log log; + + private NUnitStreamConsumer(Log log) { + this.log = log; + } + + public void consumeLine(String line) { + consumedLines.append(line + "\n"); + + log.info(line); + + if (line.contains(COMMAND_NOT_FOUND_FRAGMENT)) { + commandNotFound = true; + } + } + + public boolean isCommandNotFound() { + return commandNotFound; + } + } +} Modified: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/resources/META-INF/plexus/components.xml?rev=607643&r1=607642&r2=607643&view=diff ============================================================================== --- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/resources/META-INF/plexus/components.xml (original) +++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/resources/META-INF/plexus/components.xml Sun Dec 30 17:23:20 2007 @@ -21,6 +21,9 @@ <test-compile> org.apache.maven.dotnet.plugins:maven-compiler-plugin:test-compile </test-compile> + <test> + org.apache.maven.dotnet.plugins:dotnet-test-plugin:test + </test> <install> org.apache.maven.plugins:maven-install-plugin:install </install> @@ -50,6 +53,9 @@ <test-compile> org.apache.maven.dotnet.plugins:maven-compiler-plugin:test-compile </test-compile> + <test> + org.apache.maven.dotnet.plugins:dotnet-test-plugin:test + </test> <install> org.apache.maven.plugins:maven-install-plugin:install </install> @@ -79,6 +85,9 @@ <test-compile> org.apache.maven.dotnet.plugins:maven-compiler-plugin:test-compile </test-compile> + <test> + org.apache.maven.dotnet.plugins:dotnet-test-plugin:test + </test> <install> org.apache.maven.plugins:maven-install-plugin:install </install> @@ -108,6 +117,9 @@ <test-compile> org.apache.maven.dotnet.plugins:maven-compiler-plugin:test-compile </test-compile> + <test> + org.apache.maven.dotnet.plugins:dotnet-test-plugin:test + </test> <install> org.apache.maven.plugins:maven-install-plugin:install </install>