Adding Compilers

You can add support for additional compilers in two different ways:

  1. Add a compiler-plugins.xml file, similar to the examples below, in the root of each module that you are building. NMaven will pick it up and add it to the list of supported compilers.
  2. Add a compilerPlugin entry to the master file: components/dotnet-core/src/resources/META-INF/nmaven/compiler-plugins.xml.

Of course, if your compiler does not work with the org.apache.maven.dotnet.executable.compiler.impl.DefaultCompiler, you will also need to create your own implementation of org.apache.maven.dotnet.executable.compiler.CompilerExecutable and add the fully-qualified class name implementation to the pluginClass tag.

compiler-plugins.xml

  • compiler-plugins.xml is the master plugin file.
  • Compiler Plugins Model

    Example:

    <compilerPlugins>
        <compilerPlugin>
            <identifier>MS-CS</identifier>
            <pluginClass>org.apache.maven.dotnet.executable.compiler.impl.DefaultCompiler</pluginClass>
            <compiler>MICROSOFT</compiler>
            <executable>csc</executable>
            <language>C_SHARP</language>
            <profile>FULL</profile>
            <frameworkVersions>
                <frameworkVersion>2.0.50727</frameworkVersion>
                <frameworkVersion>1.1.4322</frameworkVersion>
            </frameworkVersions>
            <platforms>
                <platform>
                    <operatingSystem>Windows</operatingSystem>
                    <architecture>x86</architecture>
                </platform>
            </platforms>
            <profile>FULL</profile>
            <commandFilter>
                <includes>
                    <include>out</include>
                    <include>target</include>
                    <include>delaysign</include>
                    <include>doc</include>
                    <include>keyfile</include>
                    <include>keycontainer</include>
                    <include>platform</include>
                    <include>recurse</include>
                    <include>reference</include>
                    <include>addmodule</include>
                    <include>win32res</include>
                    <include>win32icon</include>
                    <include>resource</include>
                    <include>linkresource</include>
                    <include>debug</include>
                    <include>optimize</include>
                    <include>warnaserror</include>
                    <include>warn</include>
                    <include>nowarn</include>
                    <include>checked</include>
                    <include>unsafe</include>
                    <include>define</include>
                    <include>langversion</include>
                    <include>noconfig</include>
                    <include>baseaddress</include>
                    <include>bugreport</include>
                    <include>codepage</include>
                    <include>utf8output</include>
                    <include>main</include>
                    <include>fullpaths</include>
                    <include>filealign</include>
                    <include>pdb</include>
                    <include>nostdlib</include>
                    <include>lib</include>
                    <include>errorreport</include>
                    <include>moduleassemblyname</include>
                    <include>nologo</include>
               </includes>
            </commandFilter>
        </compilerPlugin>
    </compilerPlugins>
    
    

Creating Profiles

NMaven matches a plugin based on four user-specified parameters - vendor, language, framework version and profile - and on one platform parameter: operating system. Sometimes a user may want to target, say C# version 2.0.50727 but would like to use a different CompilerExecutable implementation than the standard one. The <profile/> field gives this capability. The profile also has other uses such using a different set of command filters; or, as in the case of the COMPACT profile, specifying a new set of system assemblies.

The .NET Compact Profile:

    <compilerPlugin>
        <identifier>MS-CS:COMPACT</identifier>
        <pluginClass>org.apache.maven.dotnet.executable.compiler.impl.CSharpCompilerForProfile</pluginClass>
        <compiler>MICROSOFT</compiler>
        <executable>csc</executable>
        <language>C_SHARP</language>
        <profile>COMPACT</profile>
        <frameworkVersions>
            <frameworkVersion>2.0.50727</frameworkVersion>
        </frameworkVersions>
        <platforms>
            <platform>
                <operatingSystem>Windows</operatingSystem>
                <architecture>x86</architecture>
            </platform>
        </platforms>
        <defaultAssemblyPath>
            C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE
        </defaultAssemblyPath>
        <assemblies>
            <assembly>mscorlib</assembly>
            <assembly>System.Data</assembly>
            <assembly>System</assembly>
            <assembly>System.Drawing</assembly>
            <assembly>System.Messaging</assembly>
            <assembly>System.Web.Services</assembly>
            <assembly>System.Windows.Forms.DataGrid</assembly>
            <assembly>System.Windows.Forms</assembly>
            <assembly>Microsoft.WindowsCE.Forms</assembly>
            <assembly>System.Xml</assembly>
        </assemblies>
        <commandFilter>
            <includes>
                ...
           </includes>
        </commandFilter>
    </compilerPlugin>

Adding Assembly Plugins

assembly-plugins.xml

For each compiler that implements a new language, you will also need to 1) add an assembly-plugin entry to the components/dotnet-core/src/resources/META-INF/nmaven/assembly-plugins.xml file and 2) implement a new AssemblyInfoMarshaller interface (provided the default one does not work).

The assembly-plugin entry consists of an identifier (for traceability), a pluginClass, which provides the fully-qualified class name of the AssemblyInfoMarshaller implementation, the language (which should match one of the supported .NET languages within the compiler-plugins.xml) and an extension that NMaven will use in the class file name (the CS assembly plugin will generate a class file called AssemblyInfo.cs).

<assemblyPlugins>
    <assemblyPlugin>
        <identifier>CS</identifier>
        <pluginClass>
            org.apache.maven.dotnet.assembler.impl.DefaultAssemblyInfoMarshaller
        </pluginClass>
        <language>C_SHARP</language>
        <extension>cs</extension>
    </assemblyPlugin>
    <assemblyPlugin>
        <identifier>VB</identifier>
        <pluginClass>
            org.apache.maven.dotnet.assembler.impl.VBAssemblyInfoMarshaller
        </pluginClass>
        <language>VB</language>
        <extension>vb</extension>
    </assemblyPlugin>
</assemblyPlugins>