incubator-npanday-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfall...@apache.org
Subject svn commit: r1142150 - in /incubator/npanday/trunk: components/dotnet-assembler/src/main/java/npanday/assembler/ components/dotnet-assembler/src/main/java/npanday/assembler/impl/ components/dotnet-core/src/main/resources/META-INF/npanday/ plugins/maven...
Date Sat, 02 Jul 2011 03:52:53 GMT
Author: jfallows
Date: Sat Jul  2 03:52:53 2011
New Revision: 1142150

URL: http://svn.apache.org/viewvc?rev=1142150&view=rev
Log:
Fix NPANDAY-450 by adding support for Portable Class Libraries

Modified:
    incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/AssemblyInfo.java
    incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/AssemblerContextImpl.java
    incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/DefaultAssemblyInfoMarshaller.java
    incubator/npanday/trunk/components/dotnet-core/src/main/resources/META-INF/npanday/compiler-plugins.xml
    incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AssemblyInfoGeneratorMojo.java

Modified: incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/AssemblyInfo.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/AssemblyInfo.java?rev=1142150&r1=1142149&r2=1142150&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/AssemblyInfo.java
(original)
+++ incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/AssemblyInfo.java
Sat Jul  2 03:52:53 2011
@@ -19,6 +19,7 @@
 package npanday.assembler;
 
 import java.io.File;
+import java.util.Collections;
 import java.util.Map;
 
 /**
@@ -83,8 +84,12 @@ public class AssemblyInfo
 
     private File keyFile;
 
+    private TargetFramework targetFramework;
+
     private Map<String, String> customStringAttributes;
     
+    private static final Map<String, String> EMPTY_CUSTOM_STRING_ATTRIBUTES = Collections.emptyMap();;
+    
     /**
      * Default constructor
      */
@@ -104,7 +109,8 @@ public class AssemblyInfo
             .append( "\r\nCopyright: " ).append( copyright )
             .append( "\r\nTrademark: " ).append( trademark )
             .append( "\r\nCulture: " ).append( culture )
-            .append( "\r\nConfiguration: " ).append( configuration );
+            .append( "\r\nConfiguration: " ).append( configuration )
+            .append( "\r\nTargetFramework: " ).append( targetFramework );
         return sb.toString();
     }
 
@@ -135,7 +141,7 @@ public class AssemblyInfo
 
     public String getVersion()
     {
-        return ( version != null ) ? version : "";
+        return version;
     }
 
     public void setVersion( String version )
@@ -145,7 +151,7 @@ public class AssemblyInfo
     
     public String getInformationalVersion()
     {
-        return ( informationalVersion != null ) ? informationalVersion : "";
+        return informationalVersion;
     }
 
     public void setInformationalVersion( String informationalVersion )
@@ -156,7 +162,7 @@ public class AssemblyInfo
 
     public String getDescription()
     {
-        return ( description != null ) ? description : "";
+        return description;
     }
 
     public void setDescription( String description )
@@ -166,7 +172,7 @@ public class AssemblyInfo
 
     public String getTitle()
     {
-        return ( title != null ) ? title : "";
+        return title;
     }
 
     public void setTitle( String title )
@@ -176,7 +182,7 @@ public class AssemblyInfo
 
     public String getCompany()
     {
-        return ( company != null ) ? company : "";
+        return company;
     }
 
     public void setCompany( String company )
@@ -186,7 +192,7 @@ public class AssemblyInfo
 
     public String getProduct()
     {
-        return ( product != null ) ? product : "";
+        return product;
     }
 
     public void setProduct( String product )
@@ -196,7 +202,7 @@ public class AssemblyInfo
 
     public String getCopyright()
     {
-        return ( copyright != null ) ? copyright : "";
+        return copyright;
     }
 
     public void setCopyright( String copyright )
@@ -206,7 +212,7 @@ public class AssemblyInfo
 
     public String getTrademark()
     {
-        return ( trademark != null ) ? trademark : "";
+        return trademark;
     }
 
     public void setTrademark( String trademark )
@@ -216,7 +222,7 @@ public class AssemblyInfo
 
     public String getCulture()
     {
-        return ( culture != null ) ? culture : "";
+        return culture;
     }
 
     public void setCulture( String culture )
@@ -226,7 +232,7 @@ public class AssemblyInfo
 
     public String getConfiguration()
     {
-        return ( configuration != null ) ? configuration : "";
+        return configuration;
     }
 
     public void setConfiguration( String configuration )
@@ -234,9 +240,19 @@ public class AssemblyInfo
         this.configuration = configuration;
     }
 
+    public void setTargetFramework( TargetFramework targetFramework )
+    {
+        this.targetFramework = targetFramework;
+    }
+
+    public TargetFramework getTargetFramework()
+    {
+        return targetFramework;
+    }
+
     public Map<String, String> getCustomStringAttributes()
     {
-        return customStringAttributes;
+        return (customStringAttributes != null) ? customStringAttributes : EMPTY_CUSTOM_STRING_ATTRIBUTES;
     }
 
     public void setCustomStringAttributes(Map<String, String> attributes)
@@ -293,6 +309,10 @@ public class AssemblyInfo
         {
             return false;
         }
+        if ( targetFramework != null ? !targetFramework.equals( that.targetFramework ) :
that.targetFramework != null )
+        {
+            return false;
+        }
 
         return true;
     }
@@ -310,7 +330,81 @@ public class AssemblyInfo
         result = 29 * result + ( trademark != null ? trademark.hashCode() : 0 );
         result = 29 * result + ( culture != null ? culture.hashCode() : 0 );
         result = 29 * result + ( configuration != null ? configuration.hashCode() : 0 );
+        result = 29 * result + ( targetFramework != null ? targetFramework.hashCode() : 0
);
         return result;
     }
 
+    public static class TargetFramework
+    {
+        /**
+         * Target framework name
+         */
+        private String frameworkName;
+
+        /**
+         * Target framework display name
+         */
+        private String frameworkDisplayName;
+
+        public void setFrameworkName(String frameworkName)
+        {
+            this.frameworkName = frameworkName;
+        }
+
+        public String getFrameworkName()
+        {
+            return this.frameworkName;
+        }
+
+        public void setFrameworkDisplayName(String frameworkDisplayName)
+        {
+            this.frameworkDisplayName = frameworkDisplayName;
+        }
+
+        public String getFrameworkDisplayName()
+        {
+            return this.frameworkDisplayName;
+        }
+
+        public boolean equals( Object o )
+        {
+            if ( this == o )
+            {
+                return true;
+            }
+            if ( o == null || getClass() != o.getClass() )
+            {
+                return false;
+            }
+
+            final TargetFramework that = (TargetFramework) o;
+            if ( frameworkName != null ? !frameworkName.equals( that.frameworkName ) : that.frameworkName
!= null )
+            {
+                return false;
+            }
+            if ( frameworkDisplayName != null ? !frameworkDisplayName.equals( that.frameworkDisplayName
) : that.frameworkDisplayName != null )
+            {
+                return false;
+            }
+            return true;
+        }
+
+        public int hashCode()
+        {
+            int result;
+            result = ( frameworkName != null ? frameworkName.hashCode() : 0 );
+            result = 29 * result + ( frameworkDisplayName != null ? frameworkDisplayName.hashCode()
: 0 );
+            return result;
+        }
+
+        public String toString()
+        {
+            StringBuffer sb = new StringBuffer();
+            sb.append( "FrameworkName: " ).append( frameworkName )
+                .append( "\r\nFrameworkDisplayName: " ).append( frameworkDisplayName );
+            return sb.toString();
+        }
+
+    }
+
 }

Modified: incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/AssemblerContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/AssemblerContextImpl.java?rev=1142150&r1=1142149&r2=1142150&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/AssemblerContextImpl.java
(original)
+++ incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/AssemblerContextImpl.java
Sat Jul  2 03:52:53 2011
@@ -89,12 +89,12 @@ public final class AssemblerContextImpl
     {
         String basedir = mavenProject.getBasedir().toString();
         AssemblyInfo assemblyInfo = new AssemblyInfo();
-        String description = mavenProject.getDescription();
-        String version = mavenProject.getVersion();
+        String description = ( mavenProject.getDescription() != null ) ? mavenProject.getDescription()
: "";
+        String version = ( mavenProject.getVersion() != null ) ? mavenProject.getVersion()
: "";
         String name = mavenProject.getName();
         Organization org = mavenProject.getOrganization();
         String company = ( org != null ) ? org.getName() : "";
-        String copyright = null;
+        String copyright = "";
         String informationalVersion = "";
         String configuration = "";
 

Modified: incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/DefaultAssemblyInfoMarshaller.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/DefaultAssemblyInfoMarshaller.java?rev=1142150&r1=1142149&r2=1142150&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/DefaultAssemblyInfoMarshaller.java
(original)
+++ incubator/npanday/trunk/components/dotnet-assembler/src/main/java/npanday/assembler/impl/DefaultAssemblyInfoMarshaller.java
Sat Jul  2 03:52:53 2011
@@ -21,6 +21,7 @@ package npanday.assembler.impl;
 import npanday.assembler.AssemblyInfoException;
 import npanday.assembler.AssemblyInfoMarshaller;
 import npanday.assembler.AssemblyInfo;
+import npanday.assembler.AssemblyInfo.TargetFramework;
 import npanday.model.assembly.plugins.AssemblyPlugin;
 
 import java.io.OutputStream;
@@ -56,33 +57,48 @@ final class DefaultAssemblyInfoMarshalle
     public void marshal( AssemblyInfo assemblyInfo, MavenProject mavenProject, OutputStream
outputStream )
         throws AssemblyInfoException, IOException
     {
-        String src = mavenProject.getBuild().getDirectory() + "/build-sources";
         StringBuffer sb = new StringBuffer();
         sb.append( "using System.Reflection;\r\n" )
-            .append( "using System.Runtime.CompilerServices;\r\n" )
-            .append( createEntry( "Description", assemblyInfo.getDescription() ) )
-            .append( createEntry( "Title", assemblyInfo.getTitle() ) )
-            .append( createEntry( "Company", assemblyInfo.getCompany() ) )
-            .append( createEntry( "Product", assemblyInfo.getProduct() ) )
-            .append( createEntry( "Copyright", assemblyInfo.getCopyright().replace( "\"",
"\\" ) ) )
-            .append( createEntry( "Trademark", assemblyInfo.getTrademark() ) )
-            .append( createEntry( "Culture", assemblyInfo.getCulture() ) )
-            .append( createEntry( "Version", assemblyInfo.getVersion() ) )
-            .append( createEntry( "InformationalVersion", assemblyInfo.getInformationalVersion()
) )
-            .append( createEntry( "Configuration", assemblyInfo.getConfiguration() ) );
-        if ( assemblyInfo.getKeyName() != null )
+            .append( "using System.Runtime.CompilerServices;\r\n" );
+        appendEntry( sb, "Description", assemblyInfo.getDescription() );
+        appendEntry( sb, "Title", assemblyInfo.getTitle() );
+        appendEntry( sb, "Company", assemblyInfo.getCompany() );
+        appendEntry( sb, "Product", assemblyInfo.getProduct() );
+        if (assemblyInfo.getCopyright() != null)
+        {
+            appendEntry( sb, "Copyright", assemblyInfo.getCopyright().replace( "\"", "\\"
) );
+        }
+        appendEntry( sb, "Trademark", assemblyInfo.getTrademark() );
+        appendEntry( sb, "Culture", assemblyInfo.getCulture() );
+        appendEntry( sb, "Version", assemblyInfo.getVersion() );
+        appendEntry( sb, "InformationalVersion", assemblyInfo.getInformationalVersion() );
+        appendEntry( sb, "Configuration", assemblyInfo.getConfiguration() );
+        appendEntry( sb, "KeyName", assemblyInfo.getKeyName() );
+
+        if ( assemblyInfo.getKeyFile() != null )
         {
-            sb.append( createEntry( "KeyName", assemblyInfo.getKeyName() ) );
+            appendEntry( sb, "KeyFile", assemblyInfo.getKeyFile().getAbsolutePath().replace(
"\\", "\\\\" ) );
         }
-        if ( assemblyInfo.getKeyFile() != null )
+
+        TargetFramework targetFramework = assemblyInfo.getTargetFramework();
+        if (targetFramework != null)
         {
-            sb.append( createEntry( "KeyFile", assemblyInfo.getKeyFile().getAbsolutePath().replace(
"\\", "\\\\" ) ) );
+            String frameworkName = targetFramework.getFrameworkName();
+            String frameworkDisplayName = targetFramework.getFrameworkDisplayName();
+            sb.append( "[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute"
)
+              .append( "(\"" ).append( frameworkName ).append("\"");
+            if (frameworkDisplayName != null)
+            {
+                sb.append(",FrameworkDisplayName=\"").append(frameworkDisplayName).append("\"");
+            }
+            sb.append( ")]" ).append("\r\n" );
         }
 
         boolean wroteCustomStringAttribute = false;
         for(Entry<String, String> e: assemblyInfo.getCustomStringAttributes().entrySet())
{
             if(StringUtils.isEmpty(e.getValue()))
                 continue;
+
             sb.append(createCustomStringEntry(e.getKey(), e.getValue()));
             wroteCustomStringAttribute = true;
         }
@@ -100,12 +116,17 @@ final class DefaultAssemblyInfoMarshalle
         FileOutputStream man = null;
         try
         {
-            String groupIdAsDir = mavenProject.getGroupId().replace( ".", File.separator
);
-            File file = new File( src + "/META-INF/" + groupIdAsDir );
-            file.mkdirs();
-            man = new FileOutputStream(
-                src + "/META-INF/" + groupIdAsDir + File.separator + "AssemblyInfo." + plugin.getExtension()
);
-            man.write( sb.toString().getBytes() );
+            if ( outputStream == null )
+            {
+                String src = mavenProject.getBuild().getDirectory() + "/build-sources";
+                String groupIdAsDir = mavenProject.getGroupId().replace( ".", File.separator
);
+                File file = new File( src + "/META-INF/" + groupIdAsDir );
+                file.mkdirs();
+                man = new FileOutputStream(
+                    src + "/META-INF/" + groupIdAsDir + File.separator + "AssemblyInfo."
+ plugin.getExtension() );
+                outputStream = man;
+            }
+            outputStream.write( sb.toString().getBytes() );
         }
         catch ( IOException e )
         {
@@ -222,18 +243,19 @@ final class DefaultAssemblyInfoMarshalle
     }
 
     /**
-     * Returns an assembly entry with a name-value pair surrounded by brackets.
+     * Appends an assembly entry with a name-value pair surrounded by brackets.
      *
+     * @param sb    the string buffer to be appended
      * @param name  the name of the assembly entry
      * @param value the value of the assembly entry
-     * @return an assembly entry with a name-value pair surrounded by brackets
      */
-    private String createEntry( String name, String value )
+    private void appendEntry( StringBuffer sb, String name, String value )
     {
-        StringBuffer sb = new StringBuffer();
-        sb.append( "[assembly: Assembly" ).append( name ).append( "(\"" ).append( value ).append(
"\")]" ).append(
-            "\r\n" );
-        return sb.toString();
+        if (value != null)
+        {
+            sb.append( "[assembly: Assembly" ).append( name ).append( "(\"" ).append( value
).append( "\")]" ).append(
+                "\r\n" );
+        }
     }
 
     private String createCustomStringEntry( String name, String value )

Modified: incubator/npanday/trunk/components/dotnet-core/src/main/resources/META-INF/npanday/compiler-plugins.xml
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-core/src/main/resources/META-INF/npanday/compiler-plugins.xml?rev=1142150&r1=1142149&r2=1142150&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-core/src/main/resources/META-INF/npanday/compiler-plugins.xml
(original)
+++ incubator/npanday/trunk/components/dotnet-core/src/main/resources/META-INF/npanday/compiler-plugins.xml
Sat Jul  2 03:52:53 2011
@@ -209,6 +209,78 @@ under the License.
     </commandFilter>
   </compilerPlugin>
   <compilerPlugin>
+    <identifier>MS-CS:4.0:Portable</identifier>
+    <pluginClass>npanday.executable.compiler.impl.CSharpCompilerForProfile</pluginClass>
+    <vendor>MICROSOFT</vendor>
+    <executable>csc</executable>
+    <language>C_SHARP</language>
+    <profile>PORTABLE</profile>
+    <frameworkVersions>
+      <frameworkVersion>4.0</frameworkVersion>      
+    </frameworkVersions>
+    <platforms>
+      <platform>
+        <operatingSystem>Windows</operatingSystem>
+        <architecture>x86</architecture>
+      </platform>
+    </platforms>
+    <defaultAssemblyPath>C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0</defaultAssemblyPath>
+    <assemblies>
+      <assembly>mscorlib</assembly>
+      <assembly>System</assembly>
+      <assembly>System.ComponentModel.Composition</assembly>
+      <assembly>System.Core</assembly>
+      <assembly>System.Net</assembly>
+      <assembly>System.Runtime.Serialization</assembly>
+      <assembly>System.ServiceModel</assembly>
+      <assembly>System.Windows</assembly>
+      <assembly>System.Xml</assembly>
+      <assembly>System.Xml.Serialization</assembly>
+    </assemblies>
+    <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>help</include>
+        <include>nologo</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>
+      </includes>
+    </commandFilter>
+  </compilerPlugin>
+  <compilerPlugin>
     <identifier>MS-VB</identifier>
     <pluginClass>npanday.executable.compiler.impl.DefaultCompiler</pluginClass>
     <vendor>MICROSOFT</vendor>

Modified: incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AssemblyInfoGeneratorMojo.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AssemblyInfoGeneratorMojo.java?rev=1142150&r1=1142149&r2=1142150&view=diff
==============================================================================
--- incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AssemblyInfoGeneratorMojo.java
(original)
+++ incubator/npanday/trunk/plugins/maven-compile-plugin/src/main/java/npanday/plugin/compile/AssemblyInfoGeneratorMojo.java
Sat Jul  2 03:52:53 2011
@@ -26,16 +26,19 @@ import org.codehaus.plexus.util.FileUtil
 
 import java.io.IOException;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import npanday.InitializationException;
+import npanday.PlatformUnsupportedException;
 import npanday.vendor.*;
 import npanday.assembler.AssemblerContext;
 import npanday.assembler.AssemblyInfoMarshaller;
 import npanday.assembler.AssemblyInfoException;
 import npanday.assembler.AssemblyInfo;
+import npanday.assembler.AssemblyInfo.TargetFramework;
 
 /**
  * Generates an AssemblyInfo.* class based on information within the pom file.
@@ -110,6 +113,20 @@ public class AssemblyInfoGeneratorMojo
     private String sourceDirectory;
 
     /**
+     * The framework name to target.
+     *
+     * @parameter expression = "${frameworkName}"
+     */
+    private String frameworkName;
+
+    /**
+     * The framework display name to target.
+     *
+     * @parameter expression = "${frameworkDisplayName}"
+     */
+    private String frameworkDisplayName;
+
+    /**
      * @component
      */ 
     private AssemblerContext assemblerContext;
@@ -139,6 +156,57 @@ public class AssemblyInfoGeneratorMojo
             return;
         }
 
+
+        // auto-generate the target framework attribute metadata (needed for .NETPortable)
+        if ( frameworkName != null )
+        {
+            TargetFramework targetFramework = new TargetFramework();
+            targetFramework.setFrameworkName(frameworkName);
+            targetFramework.setFrameworkDisplayName(frameworkDisplayName);
+
+            AssemblyInfo assemblyInfo = new AssemblyInfo();
+            assemblyInfo.setTargetFramework(targetFramework);
+
+            try
+            {
+                FileOutputStream assemblyAttrs = null;
+                try
+                {
+                    String sourcesDir = project.getBuild().getDirectory() + "/build-sources";
+                    String groupIdAsDir = project.getGroupId().replace( ".", File.separator
);
+
+                    File assemblyAttrsDir = new File( sourcesDir + "/META-INF/" + groupIdAsDir
);
+                    String assemblyAttrsExt = assemblerContext.getClassExtensionFor( language.trim()
);
+
+                    assemblyAttrsDir.mkdirs();
+                    assemblyAttrs = new FileOutputStream(
+                        assemblyAttrsDir + File.separator + frameworkName + ".AssemblyAttributes."
+ assemblyAttrsExt );
+
+                    AssemblyInfoMarshaller marshaller = assemblerContext.getAssemblyInfoMarshallerFor(
language.trim() );
+                    marshaller.marshal( assemblyInfo, project, assemblyAttrs );
+                }
+                finally
+                {
+                    if ( assemblyAttrs != null )
+                    {
+                        assemblyAttrs .close();
+                    }
+                }
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "NPANDAY-902-008: Problem generating assembly
attributes class", e );
+            }
+            catch ( AssemblyInfoException e )
+            {
+                throw new MojoExecutionException( "NPANDAY-902-009: Problem generating assembly
attributes class", e );
+            }
+            catch ( PlatformUnsupportedException e )
+            {
+                throw new MojoExecutionException( "NPANDAY-902-010: Problem generating assembly
attributes class", e );
+            }
+        }
+
         File srcFile = new File( sourceDirectory );
         if ( srcFile.exists() )
         {



Mime
View raw message