You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nmaven-commits@incubator.apache.org by ew...@apache.org on 2008/01/03 05:10:12 UTC

svn commit: r608342 - in /incubator/nmaven/trunk: core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/ plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/

Author: eworley
Date: Wed Jan  2 21:10:12 2008
New Revision: 608342

URL: http://svn.apache.org/viewvc?rev=608342&view=rev
Log:
Refactored TestCompiler and Compiler to have a common base class, awaiting Shane's rebuttal

Added:
    incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractCompilerMojo.java
Modified:
    incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/pom.xml
    incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/CompilerMojo.java
    incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestCompilerMojo.java

Modified: incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/pom.xml?rev=608342&r1=608341&r2=608342&view=diff
==============================================================================
--- incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/pom.xml (original)
+++ incubator/nmaven/trunk/core-integration-tests/src/test/resources/MavenITmng-0007-CSharpCompileTestLibrary/pom.xml Wed Jan  2 21:10:12 2008
@@ -17,13 +17,23 @@
         <artifactId>maven-compiler-plugin</artifactId>
         <extensions>true</extensions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.dotnet.plugins</groupId>
+        <artifactId>dotnet-test-plugin</artifactId>
+        <configuration>
+            <arguments>
+                <param>/nologo</param>
+                <param>/labels</param>
+            </arguments>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
   <dependencies>
     <dependency>
       <groupId>NUnit</groupId>
       <artifactId>NUnit.Framework</artifactId>
-      <version>2.2.8.0</version>
+      <version>2.4.3</version>
       <type>dotnet:library</type>
       <scope>test</scope>
     </dependency>

Added: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractCompilerMojo.java?rev=608342&view=auto
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractCompilerMojo.java (added)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/AbstractCompilerMojo.java Wed Jan  2 21:10:12 2008
@@ -0,0 +1,186 @@
+package org.apache.maven.dotnet.plugin.compiler;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.maven.dotnet.ArtifactType;
+import org.apache.maven.dotnet.InitializationException;
+import org.apache.maven.dotnet.ProgrammingLanguage;
+import org.apache.maven.dotnet.Vendor;
+import org.apache.maven.dotnet.compiler.DotnetCompilerConfig;
+import org.apache.maven.dotnet.compiler.DotnetCompilerContext;
+import org.apache.maven.dotnet.compiler.DotnetCompilerPlatformVersion;
+import org.apache.maven.dotnet.compiler.InvalidArtifactException;
+import org.apache.maven.dotnet.compiler.KeyInfo;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+public abstract class AbstractCompilerMojo
+    extends AbstractMojo
+{
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    protected MavenProject project;
+
+    /**
+     * The location of the local Maven repository.
+     *
+     * @parameter expression="${settings.localRepository}"
+     */
+    private File localRepository;
+
+    /**
+     * Specify a strong name key file.
+     *
+     * @parameter expression = "${keyfile}"
+     */
+    private File keyfile;
+
+    /**
+     * Specifies a strong name key container.
+     *
+     * @parameter expression = "${keycontainer}"
+     */
+    private String keycontainer;
+
+    /**
+     * The framework version to compile under: 1.1, 2.0, 3.0
+     *
+     * @parameter expression = "${frameworkVersion}" default-value="2.0.50727"
+     */
+    private String frameworkVersion;
+
+    /**
+     * .NET Language. The default value is <code>C_SHARP</code>.
+     *
+     * @parameter expression="${language}" default-value = "C_SHARP"
+     * @required
+     */
+    private String language;
+
+    /**
+     * The Vendor for the Compiler.
+     *
+     * @parameter expression="${vendor}"
+     */
+    private String vendorName;
+
+    /**
+     * @component
+     */
+    private DotnetCompilerContext dotnetCompilerContext;
+
+    /**
+     * Performs compilation
+     * 
+     * @return <code>File</code> The assembly that was generated
+     * 
+     * @throws MojoExecutionException
+     */
+    protected File compile() throws MojoExecutionException {
+        String outputDir = project.getBuild().getDirectory();
+        File sourceDir = 
+            new File( outputDir, getSourceDirectoryName());
+        
+        // No source to process
+        if (!sourceDir.exists()) {
+            return null;
+        }
+
+        Vendor vendor;
+        if ( vendorName != null )
+        {
+            vendor = Vendor.valueOf( vendorName.toUpperCase() );
+        }
+        else
+        {
+            vendor = Vendor.getDefaultVendorForOS();
+        }
+
+        getLog().info( ".NET Vendor: " + vendor );
+        DotnetCompilerConfig compilerConfig = DotnetCompilerConfig.Factory.createDefaultCompilerConfig();
+        compilerConfig.setArtifactType(
+            ArtifactType.valueOf( project.getPackaging().split( "[:]" )[1].toUpperCase() ) );
+        compilerConfig.setCompilerPlatformVersion( DotnetCompilerPlatformVersion.valueFromVersion( frameworkVersion ) );
+
+        KeyInfo keyInfo = KeyInfo.Factory.createDefaultKeyInfo();
+        if ( keyfile != null )
+        {
+//            try
+//            {
+                keyInfo.setKeyFileUri( keyfile.toURI() );
+//            }
+//            catch ( URISyntaxException e )
+//            {
+//                throw new MojoExecutionException( e.getMessage() );
+//            }
+        }
+
+        keyInfo.setKeyContainerName( keycontainer );
+        compilerConfig.setKeyInfo( keyInfo );
+
+        compilerConfig.setLocalRepository( localRepository );
+        compilerConfig.setProgrammingLanguage( ProgrammingLanguage.C_SHARP );
+        compilerConfig.setTestCompile( isTestCompile() );
+        compilerConfig.setCompilerSourceDirectory( sourceDir );
+        compilerConfig.setVendor( vendor );
+        compilerConfig.setTargetDirectory( new File( outputDir ) );
+        compilerConfig.setArtifactFileName(
+            project.getBuild().getFinalName() + getAssemblySuffix() + "." + compilerConfig.getArtifactType().getExtension() );
+
+        try
+        {
+            dotnetCompilerContext.init( project, compilerConfig );
+        }
+        catch ( InitializationException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+        try
+        {
+            return dotnetCompilerContext.getClassCompiler().compile();
+        }
+        catch ( InvalidArtifactException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+    }
+    
+    /**
+     * 
+     * @return <code>String</code> The name of the source directory, 
+     * relative to the project's directory
+     */
+    protected abstract String getSourceDirectoryName();
+    
+    /**
+     * Sub classes can override this method to add a suffix to the 
+     * assembly file name
+     * 
+     * @return <code>String</code> The suffix to append to the filename in the form
+     * {FILENAME}{SUFFIX}.{EXTENSION}
+     */
+    protected String getAssemblySuffix() {
+        return "";
+    }
+    
+    /**
+     * Sub classes can override this to configure the compiler
+     * for test compilation
+     * @return <code>boolean</code> true if test compile, else false
+     */
+    protected boolean isTestCompile() {
+        return false;
+    }
+}

Modified: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/CompilerMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/CompilerMojo.java?rev=608342&r1=608341&r2=608342&view=diff
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/CompilerMojo.java (original)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/CompilerMojo.java Wed Jan  2 21:10:12 2008
@@ -18,28 +18,9 @@
  */
 package org.apache.maven.dotnet.plugin.compiler;
 
-import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.dotnet.BuildDirectories;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.dotnet.compiler.DotnetCompilerContext;
-import org.apache.maven.dotnet.compiler.DotnetCompilerConfig;
-import org.apache.maven.dotnet.compiler.DotnetCompilerPlatformVersion;
-import org.apache.maven.dotnet.compiler.KeyInfo;
-import org.apache.maven.dotnet.compiler.InvalidArtifactException;
-import org.apache.maven.dotnet.ProgrammingLanguage;
-import org.apache.maven.dotnet.Vendor;
-import org.apache.maven.dotnet.BuildDirectories;
-import org.apache.maven.dotnet.ArtifactType;
-import org.apache.maven.dotnet.InitializationException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
 
 /**
  * Maven Mojo for compiling Class files to the .NET Intermediate Language.
@@ -50,137 +31,17 @@
  * @description Maven Mojo for compiling class files to the .NET Intermediate Language
  */
 public class CompilerMojo
-    extends AbstractMojo
+    extends AbstractCompilerMojo
 {
-    /**
-     * The maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     */
-    private MavenProject project;
-
-    /**
-     * The location of the local Maven repository.
-     *
-     * @parameter expression="${settings.localRepository}"
-     */
-    private File localRepository;
-
-    /**
-     * Specify a strong name key file.
-     *
-     * @parameter expression = "${keyfile}"
-     */
-    private File keyfile;
-
-    /**
-     * Specifies a strong name key container.
-     *
-     * @parameter expression = "${keycontainer}"
-     */
-    private String keycontainer;
-
-    /**
-     * The framework version to compile under: 1.1, 2.0, 3.0
-     *
-     * @parameter expression = "${frameworkVersion}" default-value="2.0.50727"
-     */
-    private String frameworkVersion;
-
-    /**
-     * .NET Language. The default value is <code>C_SHARP</code>.
-     *
-     * @parameter expression="${language}" default-value = "C_SHARP"
-     * @required
-     */
-    private String language;
-
-    /**
-     * The Vendor for the Compiler.
-     *
-     * @parameter expression="${vendor}"
-     */
-    private String vendorName;
-
-    /**
-     * @component
-     */
-    private DotnetCompilerContext dotnetCompilerContext;
+    @Override
+    protected String getSourceDirectoryName()
+    {
+        return BuildDirectories.BUILD_SOURCES.getBuildDirectoryName();
+    }
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-
-        File sourceDir =
-            new File( project.getBuild().getDirectory(), BuildDirectories.BUILD_SOURCES.getBuildDirectoryName() );
-
-        // No source to process
-        if ( !sourceDir.exists() )
-        {
-            return;
-        }
-
-        Vendor vendor;
-        if ( vendorName != null )
-        {
-            vendor = Vendor.valueOf( vendorName.toUpperCase() );
-        }
-        else
-        {
-            vendor = Vendor.getDefaultVendorForOS();
-        }
-
-        getLog().info( ".NET Vendor: " + vendor );
-        DotnetCompilerConfig compilerConfig = DotnetCompilerConfig.Factory.createDefaultCompilerConfig();
-
-        compilerConfig.setArtifactType(
-            ArtifactType.valueOf( project.getPackaging().split( "[:]" )[1].toUpperCase() ) );
-        compilerConfig.setCompilerPlatformVersion( DotnetCompilerPlatformVersion.valueFromVersion( frameworkVersion ) );
-
-        KeyInfo keyInfo = KeyInfo.Factory.createDefaultKeyInfo();
-        if ( keyfile != null )
-        {
-            //try
-            //{
-                keyInfo.setKeyFileUri( keyfile.toURI());
-            //}
-         //   catch ( URISyntaxException e )
-           // {
-             //   throw new MojoExecutionException( e.getMessage() );
-           // }
-        }
-
-        keyInfo.setKeyContainerName( keycontainer );
-        compilerConfig.setKeyInfo( keyInfo );
-
-        compilerConfig.setLocalRepository( localRepository );
-        compilerConfig.setProgrammingLanguage( ProgrammingLanguage.C_SHARP );
-        compilerConfig.setCompilerSourceDirectory( sourceDir );
-        compilerConfig.setVendor( vendor );
-        compilerConfig.setTargetDirectory( new File( project.getBuild().getDirectory() ) );
-        compilerConfig.setArtifactFileName(
-            project.getBuild().getFinalName() + "." + compilerConfig.getArtifactType().getExtension() );
-
-        try
-        {
-            dotnetCompilerContext.init( project, compilerConfig );
-        }
-        catch ( InitializationException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
-        try
-        {
-            project.getArtifact().setFile( dotnetCompilerContext.getClassCompiler().compile() );
-        }
-        catch ( InvalidArtifactException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
+        project.getArtifact().setFile( compile() );
     }
 }

Modified: incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestCompilerMojo.java
URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestCompilerMojo.java?rev=608342&r1=608341&r2=608342&view=diff
==============================================================================
--- incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestCompilerMojo.java (original)
+++ incubator/nmaven/trunk/plugins/maven-compiler-plugin/src/main/java/org/apache/maven/dotnet/plugin/compiler/TestCompilerMojo.java Wed Jan  2 21:10:12 2008
@@ -18,28 +18,9 @@
  */
 package org.apache.maven.dotnet.plugin.compiler;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.dotnet.ArtifactType;
 import org.apache.maven.dotnet.BuildDirectories;
-import org.apache.maven.dotnet.InitializationException;
-import org.apache.maven.dotnet.ProgrammingLanguage;
-import org.apache.maven.dotnet.Vendor;
-import org.apache.maven.dotnet.compiler.DotnetCompilerConfig;
-import org.apache.maven.dotnet.compiler.DotnetCompilerContext;
-import org.apache.maven.dotnet.compiler.DotnetCompilerPlatformVersion;
-import org.apache.maven.dotnet.compiler.InvalidArtifactException;
-import org.apache.maven.dotnet.compiler.KeyInfo;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
 
 /**
  * Maven Mojo for compiling Class files to the .NET Intermediate Language.
@@ -50,78 +31,11 @@
  * @description Maven Mojo for compiling class files to the .NET Intermediate Language
  */
 public class TestCompilerMojo
-    extends AbstractMojo
+    extends AbstractCompilerMojo
 {
-    /**
-     * The maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     */
-    private MavenProject project;
-
-    /**
-     * The location of the local Maven repository.
-     *
-     * @parameter expression="${settings.localRepository}"
-     */
-    private File localRepository;
-
-    /**
-     * Specify a strong name key file.
-     *
-     * @parameter expression = "${keyfile}"
-     */
-    private File keyfile;
-
-    /**
-     * Specifies a strong name key container. (not currently supported)
-     *
-     * @parameter expression = "${keycontainer}"
-     */
-    private String keycontainer;
-
-    /**
-     * The framework version to compile under: 1.1, 2.0, 3.0
-     *
-     * @parameter expression = "${frameworkVersion}" default-value="2.0.50727"
-     */
-    private String frameworkVersion;
-
-    /**
-     * .NET Language. The default value is <code>C_SHARP</code>. Not case or white-space sensitive.
-     *
-     * @parameter expression="${language}" default-value = "C_SHARP"
-     * @required
-     */
-    private String language;
-
-    /**
-     * The Vendor for the Compiler. Not case or white-space sensitive.
-     *
-     * @parameter expression="${vendor}"
-     */
-    private String vendorName;
-
-    /**
-     * @component
-     */
-    private DotnetCompilerContext compilerContext;
-
-    /**
-     * @component
-     */
-    private List<ArtifactHandler> artifactHandlers;
-
-    /**
-     * @component
-     */
-    private ArtifactHandlerManager artifactHandlerManager;
-
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        
         String skipTest = System.getProperty( "maven.test.skip" );
         if ( "TRUE".equalsIgnoreCase( skipTest ) )
         {
@@ -129,75 +43,24 @@
             return;
         }
         
-        File sourceDir = 
-            new File( project.getBuild().getDirectory(), 
-                      BuildDirectories.TEST_SOURCES.getBuildDirectoryName() );
-        
-        // No test source to process
-        if (!sourceDir.exists()) {
-            return;
-        }
-        this.getLog();
-        Vendor vendor;
-        if ( vendorName != null )
-        {
-            vendor = Vendor.valueOf( vendorName.toUpperCase() );
-        }
-        else
-        {
-            vendor = Vendor.getDefaultVendorForOS();
-        }
-
-        getLog().info( ".NET Vendor: " + vendor );
-        DotnetCompilerConfig compilerConfig = DotnetCompilerConfig.Factory.createDefaultCompilerConfig();
-        compilerConfig.setArtifactType(
-            ArtifactType.valueOf( project.getPackaging().split( "[:]" )[1].toUpperCase() ) );
-        compilerConfig.setCompilerPlatformVersion( DotnetCompilerPlatformVersion.valueFromVersion( frameworkVersion ) );
-
-        KeyInfo keyInfo = KeyInfo.Factory.createDefaultKeyInfo();
-        if ( keyfile != null )
-        {
-            try
-            {
-                keyInfo.setKeyFileUri( new URI( keyfile.getAbsolutePath() ) );
-            }
-            catch ( URISyntaxException e )
-            {
-                throw new MojoExecutionException( e.getMessage() );
-            }
-        }
+        compile();
+    }
 
-        keyInfo.setKeyContainerName( keycontainer );
-        compilerConfig.setKeyInfo( keyInfo );
+    @Override
+    protected String getSourceDirectoryName()
+    {
+        return BuildDirectories.TEST_SOURCES.getBuildDirectoryName();
+    }
 
-        compilerConfig.setLocalRepository( localRepository );
-        compilerConfig.setProgrammingLanguage( ProgrammingLanguage.C_SHARP );
-        compilerConfig.setTestCompile( true );
-        compilerConfig.setCompilerSourceDirectory( sourceDir );
-        compilerConfig.setVendor( vendor );
-        compilerConfig.setTargetDirectory( new File( project.getBuild().getDirectory() ) );
-        compilerConfig.setArtifactFileName(
-            project.getBuild().getFinalName() + "-test" + "." + compilerConfig.getArtifactType().getExtension() );
+    @Override
+    protected String getAssemblySuffix()
+    {
+        return "-test";
+    }
 
-        try
-        {
-            compilerContext.init( project, compilerConfig );
-        }
-        catch ( InitializationException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
-        try
-        {
-            compilerContext.getClassCompiler().compile();
-        }
-        catch ( InvalidArtifactException e )
-        {
-            throw new MojoExecutionException( e.getMessage() );
-        }
+    @Override
+    protected boolean isTestCompile()
+    {
+        return true;
     }
 }