Author: sisbell Date: Sun Dec 2 11:31:32 2007 New Revision: 600361 URL: http://svn.apache.org/viewvc?rev=600361&view=rev Log: Implementation for dynamically loading compiler classes based on annotations. Also changed CompilerAnnotation to specify multiple vendor and framework versions.
Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpCompiler.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerAnnotation.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpCompiler.java URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpCompiler.java?rev=600361&r1=600360&r2=600361&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpCompiler.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpCompiler.java Sun Dec 2 11:31:32 2007 @@ -17,8 +17,8 @@ import org.apache.maven.dotnet.compiler.ProgrammingLanguage; import org.apache.maven.dotnet.compiler.Vendor; [EMAIL PROTECTED](getProgrammingLanguaqe = ProgrammingLanguage.C_SHARP, getVendor = Vendor.MICROSOFT, - getDotnetCompilerPlatformVersion = DotnetCompilerPlatformVersion.VERSION_2_0_50727) [EMAIL PROTECTED](programmingLanguaqe = ProgrammingLanguage.C_SHARP, vendors = {Vendor.MICROSOFT, Vendor.NOVELL, Vendor.ANY}, + dotnetCompilerPlatformVersions = {DotnetCompilerPlatformVersion.VERSION_2_0_50727, DotnetCompilerPlatformVersion.VERSION_3_0}) public class CSharpCompiler implements org.apache.maven.dotnet.compiler.Compiler { @@ -43,12 +43,11 @@ Set<Artifact> modules = compilerContext.getDirectModuleDependencies(); File sourceDirectory = config.getSourceDirectory(); - // File artifactFilePath = new File(config.getTargetDirectory(), ) + // File artifactFilePath = new File(config.getTargetDirectory(), ) String targetArtifactType = config.getArtifactType().getTargetCompileType(); - Set<String> commands = new HashSet<String>(); - // commands.add( "/out:" + artifactFilePath ); + // commands.add( "/out:" + artifactFilePath ); commands.add( "/target:" + targetArtifactType ); commands.add( "/recurse:" + sourceDirectory + File.separator + "**" ); if ( modules != null && !modules.isEmpty() ) @@ -98,7 +97,7 @@ } if ( config.getVendor().equals( Vendor.MICROSOFT ) && - config.getCompilerPlatformVersion().equals( DotnetCompilerPlatformVersion.VERSION_3_0) ) + config.getCompilerPlatformVersion().equals( DotnetCompilerPlatformVersion.VERSION_3_0 ) ) { String wcfRef = "/reference:" + System.getenv( "SystemRoot" ) + "\\Microsoft.NET\\Framework\\v3.0\\Windows Communication Foundation\\"; @@ -135,8 +134,7 @@ } if ( !config.isTestCompile() ) { - commands.add( - "/doc:" + new File( config.getTargetDirectory(), "comments.xml" ).getAbsolutePath() ); + commands.add( "/doc:" + new File( config.getTargetDirectory(), "comments.xml" ).getAbsolutePath() ); } return commands; } @@ -152,7 +150,7 @@ //commandExecutor.setLogger( logger ); try { - commandExecutor.executeCommand(getCompilerFileName(), getCommands() ); + commandExecutor.executeCommand( getCompilerFileName(), getCommands() ); } catch ( CompilerException e ) { Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerAnnotation.java URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerAnnotation.java?rev=600361&r1=600360&r2=600361&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerAnnotation.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerAnnotation.java Sun Dec 2 11:31:32 2007 @@ -1,10 +1,15 @@ package org.apache.maven.dotnet.compiler; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + [EMAIL PROTECTED](RetentionPolicy.RUNTIME) + public @interface CompilerAnnotation { - ProgrammingLanguage getProgrammingLanguaqe(); + ProgrammingLanguage programmingLanguaqe(); - Vendor getVendor(); + Vendor[] vendors(); - DotnetCompilerPlatformVersion getDotnetCompilerPlatformVersion(); + DotnetCompilerPlatformVersion[] dotnetCompilerPlatformVersions(); } Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java?rev=600361&r1=600360&r2=600361&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java Sun Dec 2 11:31:32 2007 @@ -1,9 +1,13 @@ package org.apache.maven.dotnet.compiler.impl; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import java.util.Enumeration; +import java.util.jar.JarFile; +import java.util.jar.JarEntry; import org.apache.maven.artifact.Artifact; import org.apache.maven.dotnet.compiler.Compiler; @@ -13,6 +17,7 @@ import org.apache.maven.dotnet.compiler.DotnetCompilerPlatformVersion; import org.apache.maven.dotnet.compiler.PlatformUnsupportedException; import org.apache.maven.dotnet.compiler.Vendor; +import org.apache.maven.dotnet.compiler.CompilerAnnotation; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.StringUtils; @@ -194,6 +199,63 @@ } }//end for loop } + String[] classPathJars = System.getProperty( "java.class.path" ).split( "[\\" + File.separator + "]" ); + for ( String classPathJar : classPathJars ) + { + if ( classPathJar.contains( "dotnet-compiler-" ) ) + { + JarFile jarFile = null; + try + { + jarFile = new JarFile( classPathJar ); + } + catch ( IOException e ) + { + e.printStackTrace(); + } + Enumeration jarEntries = jarFile.entries(); + + while ( jarEntries.hasMoreElements() ) + { + JarEntry jarEntry = (JarEntry) jarEntries.nextElement(); + if ( jarEntry.isDirectory() ) + { + continue; + } + + String className = null; + try + { + Class c = Class.forName( jarEntry.getName() ); + className = c.getName(); + CompilerAnnotation annotation = + (CompilerAnnotation) c.getAnnotation( CompilerAnnotation.class ); + if ( annotation != null ) + { + if ( isMatchBetween( (DotnetCompilerConfig) compilerConfig, annotation ) ) + { + compiler = (Compiler) c.newInstance(); + compiler.init( this ); + } + } + } + catch ( ClassNotFoundException e ) + { + e.printStackTrace(); + } + catch ( InstantiationException e ) + { + throw new PlatformUnsupportedException( + "NMAVEN-061-005: Unable to create NetCompiler: Class Name = " + className, e ); + } + catch ( IllegalAccessException e ) + { + throw new PlatformUnsupportedException( + "NMAVEN-061-006: Unable to create NetCompiler: Class Name = " + className, e ); + } + } + } + } /* String className = compilerCapability.getPluginClassName(); @@ -253,6 +315,14 @@ protected void turnOnAssemblyExistsCheck() { this.assemblyExistsCheck = true; + } + + private static boolean isMatchBetween( DotnetCompilerConfig compilerConfig, CompilerAnnotation compilerAnnotation ) + { + return Arrays.asList( compilerAnnotation.vendors() ).contains( compilerConfig.getVendor() ) && + Arrays.asList( compilerAnnotation.dotnetCompilerPlatformVersions() ).contains( + compilerConfig.getCompilerPlatformVersion() ) && + compilerAnnotation.programmingLanguaqe().equals( compilerConfig.getProgrammingLanguage() ); } private String getGacRootForMono()