Author: sisbell Date: Sun Dec 2 22:40:44 2007 New Revision: 600434 URL: http://svn.apache.org/viewvc?rev=600434&view=rev Log: Bug fixes in the locating and loading of the compiler classes. Changed name of compiler to classcompiler so as not to conflict with java.util.compiler.
Added: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpClassCompiler.java (with props) incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/ClassCompiler.java (with props) incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/resources/ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/resources/dotnet-compiler-ext-0.14-incubating-SNAPSHOT.jar (with props) Removed: 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/Compiler.java Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerConfig.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerContext.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/DotnetCompilerConfig.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImpl.java incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImplTest.java Added: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpClassCompiler.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/CSharpClassCompiler.java?rev=600434&view=auto ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpClassCompiler.java (added) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpClassCompiler.java Sun Dec 2 22:40:44 2007 @@ -0,0 +1,192 @@ +package org.apache.maven.dotnet.compiler.ext; + +import java.io.File; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.dotnet.compiler.CommandExecutor; +import org.apache.maven.dotnet.compiler.CompilerAnnotation; +import org.apache.maven.dotnet.compiler.CompilerContext; +import org.apache.maven.dotnet.compiler.CompilerException; +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.ProgrammingLanguage; +import org.apache.maven.dotnet.compiler.Vendor; + [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 CSharpClassCompiler + implements org.apache.maven.dotnet.compiler.ClassCompiler +{ + private DotnetCompilerContext compilerContext; + + private File compiledArtifact; + + public File getCompiledArtifact() + throws InvalidArtifactException + { + if ( compiledArtifact == null || !compiledArtifact.exists() ) + { + throw new InvalidArtifactException(); + } + return compiledArtifact; + } + + public boolean failOnErrorOutput() + { + return false; + } + + public Set<String> getCommands() + { + DotnetCompilerConfig config = (DotnetCompilerConfig) compilerContext.getCompilerConfig(); + Set<Artifact> references = compilerContext.getLibraryDependencies(); + Set<Artifact> modules = compilerContext.getDirectModuleDependencies(); + + File sourceDirectory = config.getSourceDirectory(); + compiledArtifact = + new File( config.getTargetDirectory(), compilerContext.getCompilerConfig().getArtifactFileName() ); + String targetArtifactType = config.getArtifactType().getTargetCompileType(); + + Set<String> commands = new HashSet<String>(); + commands.add( "/out:" + compiledArtifact.getAbsolutePath() ); + commands.add( "/target:" + targetArtifactType ); + commands.add( "/recurse:" + sourceDirectory + File.separator + "**" ); + if ( modules != null && !modules.isEmpty() ) + { + StringBuffer sb = new StringBuffer(); + for ( Iterator i = modules.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + String path = artifact.getFile().getAbsolutePath(); + sb.append( path ); + if ( i.hasNext() ) + { + sb.append( ";" ); + } + } + commands.add( "/addmodule:" + sb.toString() ); + } + if ( !references.isEmpty() ) + { + for ( Artifact artifact : references ) + { + String path = artifact.getFile().getAbsolutePath(); + commands.add( "/reference:" + path ); + } + } + + for ( File file : compilerContext.getEmbeddedResources() ) + { + commands.add( "/resource:" + file.getAbsolutePath() ); + } + for ( File file : compilerContext.getLinkedResources() ) + { + commands.add( "/linkresource:" + file.getAbsolutePath() ); + } + for ( File file : compilerContext.getWin32Resources() ) + { + commands.add( "/win32res:" + file.getAbsolutePath() ); + } + if ( compilerContext.getWin32Icon() != null ) + { + commands.add( "/win32icon:" + compilerContext.getWin32Icon().getAbsolutePath() ); + } + + if ( config.getVendor().equals( Vendor.MICROSOFT ) ) + { + commands.add( "/nologo" ); + } + + if ( config.getVendor().equals( Vendor.MICROSOFT ) && + config.getCompilerPlatformVersion().equals( DotnetCompilerPlatformVersion.VERSION_3_0 ) ) + { + String wcfRef = "/reference:" + System.getenv( "SystemRoot" ) + + "\\Microsoft.NET\\Framework\\v3.0\\Windows Communication Foundation\\"; + //TODO: This is a hard-coded path: Don't have a registry value either. + commands.add( wcfRef + "System.ServiceModel.dll" ); + commands.add( wcfRef + "Microsoft.Transactions.Bridge.dll" ); + commands.add( wcfRef + "Microsoft.Transactions.Bridge.Dtc.dll" ); + commands.add( wcfRef + "System.ServiceModel.Install.dll" ); + commands.add( wcfRef + "System.ServiceModel.WasHosting.dll" ); + commands.add( wcfRef + "System.Runtime.Serialization.dll" ); + commands.add( wcfRef + "SMDiagnostics.dll" ); + } + + if ( config.getKeyInfo().getKeyFileUri() != null ) + { + commands.add( "/keyfile:" + config.getKeyInfo().getKeyFileUri() ); + } + else if ( config.getKeyInfo().getKeyContainerName() != null ) + { + commands.add( "/keycontainer:" + config.getKeyInfo().getKeyContainerName() ); + } +/* + if ( config.getCommands() != null ) + { + commands.addAll( config.getCommands() ); + } + */ + commands.add( "/warnaserror-" ); + if ( config.getVendor().equals( Vendor.NOVELL ) ) + { + commands.add( "/reference:System.Drawing" ); + commands.add( "/reference:System.Windows.Forms" ); + commands.add( "/reference:System.Web.Services" ); + } + if ( !config.isTestCompile() ) + { + commands.add( "/doc:" + new File( config.getTargetDirectory(), "comments.xml" ).getAbsolutePath() ); + } + return commands; + } + + public void resetCommands( Set<String> commands ) + { + + } + + public void compile() + { + CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor(); + //commandExecutor.setLogger( logger ); + try + { + commandExecutor.executeCommand( getCompilerFileName(), getCommands() ); + } + catch ( CompilerException e ) + { + e.printStackTrace(); + } + } + + public String getCompilerFileName() + { + if ( compilerContext.getCompilerConfig().getVendor().equals( Vendor.MICROSOFT ) ) + { + return "csc"; + } + else if ( compilerContext.getCompilerConfig().getVendor().equals( Vendor.NOVELL ) ) + { + return "gmcs"; + } + else + { + return null; + } + } + + public void init( CompilerContext compilerContext ) + { + if ( compilerContext == null || ! ( compilerContext instanceof DotnetCompilerContext ) ) + { + throw new IllegalArgumentException( "compilerContext" ); + } + this.compilerContext = (DotnetCompilerContext) compilerContext; + } +} Propchange: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler-ext/src/main/java/org/apache/maven/dotnet/compiler/ext/CSharpClassCompiler.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/ClassCompiler.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/ClassCompiler.java?rev=600434&view=auto ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/ClassCompiler.java (added) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/ClassCompiler.java Sun Dec 2 22:40:44 2007 @@ -0,0 +1,53 @@ +package org.apache.maven.dotnet.compiler; + +import java.io.File; +import java.util.Set; + +public interface ClassCompiler +{ + /** + * Returns a file pointing to the compiled artifact for this executable. + * + * @return a file pointing to the compiled artifact for this executable + * @throws InvalidArtifactException if the artifact is invalid + */ + File getCompiledArtifact() + throws InvalidArtifactException; + + /** + * Returns true to fail the build if the compiler writes anything to the error stream, otherwise return false. + * + * @return true to fail the build if the compiler writes anything to the error stream, otherwise return false + */ + boolean failOnErrorOutput(); + + /** + * Returns the commands that this compiler will use to compile the application. This list is unmodifiable. + * + * @return the commands that this compiler will use to compile the application + */ + Set<String> getCommands(); + + /** + * Resets the commands to be used by the executable. This should only be used if the executable is being reused with + * different commands from the one that it was initialized with. + * + * @param commands + */ + void resetCommands( Set<String> commands ); + + /** + * Compiles class files. + */ + void compile(); + + /** + * Returns the executable file name that this compiler will use to compile the application. + * + * @return the executable file name that this compiler will use to compile the application + */ + String getCompilerFileName(); + + void init(CompilerContext compilerContext); + +} Propchange: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/ClassCompiler.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerConfig.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/CompilerConfig.java?rev=600434&r1=600433&r2=600434&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerConfig.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerConfig.java Sun Dec 2 22:40:44 2007 @@ -73,6 +73,8 @@ Vendor getVendor(); + String getArtifactFileName(); + void verifyCompilerConfig() throws IllegalArgumentException; Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerContext.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/CompilerContext.java?rev=600434&r1=600433&r2=600434&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerContext.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/CompilerContext.java Sun Dec 2 22:40:44 2007 @@ -17,7 +17,7 @@ * * @return an instance of the compiler appropriate for this context */ - Compiler getCompiler(); + ClassCompiler getClassCompiler(); MavenProject getMavenProject(); Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/DotnetCompilerConfig.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/DotnetCompilerConfig.java?rev=600434&r1=600433&r2=600434&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/DotnetCompilerConfig.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/main/java/org/apache/maven/dotnet/compiler/DotnetCompilerConfig.java Sun Dec 2 22:40:44 2007 @@ -60,6 +60,17 @@ private Vendor vendor; + private String artifactFileName; + + public String getArtifactFileName() + { + return artifactFileName; + } + + public void setArtifactFileName(String artifactFileName) + { + this.artifactFileName = artifactFileName; + } public KeyInfo getKeyInfo() { return keyInfo; 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=600434&r1=600433&r2=600434&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 22:40:44 2007 @@ -10,7 +10,7 @@ import java.util.jar.JarEntry; import org.apache.maven.artifact.Artifact; -import org.apache.maven.dotnet.compiler.Compiler; +import org.apache.maven.dotnet.compiler.ClassCompiler; import org.apache.maven.dotnet.compiler.CompilerConfig; import org.apache.maven.dotnet.compiler.DotnetCompilerConfig; import org.apache.maven.dotnet.compiler.DotnetCompilerContext; @@ -37,7 +37,7 @@ private Set<Artifact> moduleDependencies; - private Compiler compiler; + private ClassCompiler classCompiler; /** * A logger for writing log messages @@ -100,9 +100,9 @@ return netCompilerConfig; } - public Compiler getCompiler() + public ClassCompiler getClassCompiler() { - return compiler; + return classCompiler; } public MavenProject getMavenProject() @@ -199,7 +199,7 @@ } }//end for loop } - String[] classPathJars = System.getProperty( "java.class.path" ).split( "[\\" + File.separator + "]" ); + String[] classPathJars = System.getProperty( "java.class.path" ).split( "[" + File.pathSeparator + "]" ); for ( String classPathJar : classPathJars ) { if ( classPathJar.contains( "dotnet-compiler-" ) ) @@ -218,7 +218,7 @@ while ( jarEntries.hasMoreElements() ) { JarEntry jarEntry = (JarEntry) jarEntries.nextElement(); - if ( jarEntry.isDirectory() ) + if ( jarEntry.isDirectory() || !jarEntry.getName().endsWith( "class" ) ) { continue; } @@ -226,22 +226,22 @@ String className = null; try { - Class c = Class.forName( jarEntry.getName() ); + String[] tokens = jarEntry.getName().split( "[//]" ); + + Class c = Class.forName( tokens[tokens.length - 1].split( "[.]")[0] ); className = c.getName(); CompilerAnnotation annotation = (CompilerAnnotation) c.getAnnotation( CompilerAnnotation.class ); - if ( annotation != null ) + if ( annotation != null && isMatchBetween( (DotnetCompilerConfig) compilerConfig, annotation ) ) { - if ( isMatchBetween( (DotnetCompilerConfig) compilerConfig, annotation ) ) - { - compiler = (Compiler) c.newInstance(); - compiler.init( this ); - } + classCompiler = (ClassCompiler) c.newInstance(); + classCompiler.init( this ); } } catch ( ClassNotFoundException e ) { - e.printStackTrace(); + throw new PlatformUnsupportedException( + "NMAVEN-061-007: Unable to create NetCompiler: Class Name = " + className, e ); } catch ( InstantiationException e ) { Modified: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImplTest.java URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImplTest.java?rev=600434&r1=600433&r2=600434&view=diff ============================================================================== --- incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImplTest.java (original) +++ incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/java/org/apache/maven/dotnet/compiler/impl/DotnetCompilerContextImplTest.java Sun Dec 2 22:40:44 2007 @@ -17,6 +17,7 @@ import org.apache.maven.dotnet.compiler.DotnetCompilerPlatformVersion; import org.apache.maven.dotnet.compiler.ProgrammingLanguage; import org.apache.maven.dotnet.compiler.Vendor; +import org.apache.maven.dotnet.compiler.ClassCompiler; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; @@ -44,6 +45,7 @@ DotnetCompilerContextImpl ctx = new DotnetCompilerContextImpl(); ctx.init( new MavenProject(), null ); + } @Test @@ -219,6 +221,25 @@ assertThat( libraries.size(), equalTo( 1 ) ); assertThat( ( (Artifact) libraries.toArray()[0] ).getFile().getAbsolutePath(), equalTo( "C:\\Program Files\\Mono\\lib\\mono\\gac\\artifactId\\1.0__dsfajkdsfajdfs\\artifactId.dll" ) ); + } + + @Test + public void testInit_ForCorrectCompiler() + throws PlatformUnsupportedException + { + DotnetCompilerContextImpl ctx = new DotnetCompilerContextImpl(); + MavenProject project = new MavenProject(); + + Build build = new Build(); + build.setDirectory( "" ); + project.setBuild( build ); + + System.setProperty( "java.class.path", new File( "src/test/resources", + "dotnet-compiler-ext-0.14-incubating-SNAPSHOT.jar" ).getAbsolutePath() ); + + ctx.init( project, getDefaultDotnetCompilerConfig() ); + + ClassCompiler compiler = ctx.getClassCompiler(); } private static DotnetCompilerConfig getDefaultDotnetCompilerConfig() Added: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/resources/dotnet-compiler-ext-0.14-incubating-SNAPSHOT.jar URL: http://svn.apache.org/viewvc/incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/resources/dotnet-compiler-ext-0.14-incubating-SNAPSHOT.jar?rev=600434&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/nmaven/branches/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-compiler/src/test/resources/dotnet-compiler-ext-0.14-incubating-SNAPSHOT.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream