Author: sisbell Date: Tue Nov 27 17:36:09 2007 New Revision: 598845 URL: http://svn.apache.org/viewvc?rev=598845&view=rev Log: Tightened up the API and added implementation to the net context. This implementation just uses a config, not the platform capability/requirements.
Added: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java (with props) incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java (with props) incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java (with props) incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java (with props) Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerConfig.java incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerConfig.java incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerContext.java incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerConfig.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerConfig.java?rev=598845&r1=598844&r2=598845&view=diff ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerConfig.java (original) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerConfig.java Tue Nov 27 17:36:09 2007 @@ -71,12 +71,9 @@ void setProgrammingLanguage( ProgrammingLanguage programLanguage ); - String getProgramLanguageVersion(); + void setVendor(Vendor vendor); - void setProgrammingLanguageVersion(String programLanguageVersion); + Vendor getVendor(); - void setVendor(String vendor); - - String getVendor(); } Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java?rev=598845&r1=598844&r2=598845&view=diff ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java (original) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/CompilerContext.java Tue Nov 27 17:36:09 2007 @@ -1,5 +1,7 @@ package org.apache.maven.dotnet.compiler; +import org.apache.maven.project.MavenProject; + public interface CompilerContext { /** @@ -11,10 +13,14 @@ CompilerConfig getCompilerConfig(); /** - * Returns an instance of the NetExecutable appropriate for given language/vendor/OS. + * Returns an instance of the compiler appropriate for this context. * - * @return an instance of the NetExecutable appropriate for given language/vendor/OS. + * @return an instance of the compiler appropriate for this context */ Compiler getCompiler(); + + MavenProject getMavenProject(); + + void init( MavenProject project, CompilerConfig compilerConfig) throws PlatformUnsupportedException; } Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerConfig.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerConfig.java?rev=598845&r1=598844&r2=598845&view=diff ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerConfig.java (original) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerConfig.java Tue Nov 27 17:36:09 2007 @@ -16,4 +16,8 @@ * @param keyInfo key info used for signing assemblies */ void setKeyInfo( KeyInfo keyInfo); + + NetCompilerPlatformVersion getCompilerPlatformVersion(); + + void setCompilerPlatformVersion(NetCompilerPlatformVersion compilerPlatformVersion); } Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerContext.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerContext.java?rev=598845&r1=598844&r2=598845&view=diff ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerContext.java (original) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerContext.java Tue Nov 27 17:36:09 2007 @@ -67,4 +67,5 @@ * @return a list of win32 resources. */ Set<File> getWin32Resources(); + } Added: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java?rev=598845&view=auto ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java (added) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java Tue Nov 27 17:36:09 2007 @@ -0,0 +1,21 @@ +package org.apache.maven.dotnet.compiler; + +public enum NetCompilerPlatformVersion +{ + VERSION_1_1_4322("1.1.4322"), + VERSION_2_0_50727("2.0.50727"), + VERSION_3_0("3.0"), + VERSION_3_5("3.5"); + + private String version; + + NetCompilerPlatformVersion(String version) + { + this.version = version; + } + + public String getVersionAsString() + { + return version; + } +} Propchange: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/NetCompilerPlatformVersion.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java?rev=598845&view=auto ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java (added) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java Tue Nov 27 17:36:09 2007 @@ -0,0 +1,54 @@ +package org.apache.maven.dotnet.compiler; + +/** + * Exception class thrown when the invoking platform does not support the given vendor (MICROSOFT/MONO) or the compiler + * language. + * + * @author Shane Isbell + */ +public class PlatformUnsupportedException + extends Exception +{ + + static final long serialVersionUID = 342635474673243L; + + /** + * Constructs an <code>PlatformUnsupportedException</code> with no exception message. + */ + public PlatformUnsupportedException() + { + super(); + } + + /** + * Constructs an <code>PlatformUnsupportedException</code> with the specified exception message. + * + * @param message the exception message + */ + public PlatformUnsupportedException( String message ) + { + super( message ); + } + + /** + * Constructs an <code>PlatformUnsupportedException</code> with the specified exception message and cause of the exception. + * + * @param message the exception message + * @param cause the cause of the exception + */ + public PlatformUnsupportedException( String message, Throwable cause ) + { + super( message, cause ); + } + + /** + * Constructs an <code>PlatformUnsupportedException</code> with the cause of the exception. + * + * @param cause the cause of the exception + */ + public PlatformUnsupportedException( Throwable cause ) + { + super( cause ); + } + +} Propchange: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/PlatformUnsupportedException.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java?rev=598845&view=auto ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java (added) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java Tue Nov 27 17:36:09 2007 @@ -0,0 +1,20 @@ +package org.apache.maven.dotnet.compiler; + +public enum ProgrammingLanguage +{ + JAVA("java"), + C_SHARP("cs"), + VISUAL_BASIC("vb"); + + private String classFileExtension; + + ProgrammingLanguage(String classFileExtension) + { + this.classFileExtension = classFileExtension; + } + + public String getClassFileExtension() + { + return classFileExtension; + } +} Propchange: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/ProgrammingLanguage.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java?rev=598845&view=auto ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java (added) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java Tue Nov 27 17:36:09 2007 @@ -0,0 +1,8 @@ +package org.apache.maven.dotnet.compiler; + +public enum Vendor +{ + MICROSOFT, + NOVELL, + ANY +} Propchange: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/Vendor.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java URL: http://svn.apache.org/viewvc/incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java?rev=598845&r1=598844&r2=598845&view=diff ============================================================================== --- incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java (original) +++ incubator/nmaven/tags/SI_MAVEN_INTEGRATION/sandbox/components/dotnet-executable/src/org/apache/maven/dotnet/compiler/impl/NetCompilerContextImpl.java Tue Nov 27 17:36:09 2007 @@ -2,14 +2,50 @@ import org.apache.maven.dotnet.compiler.*; import org.apache.maven.dotnet.compiler.Compiler; +import org.apache.maven.dotnet.compiler.CompilerConfig; +import org.apache.maven.dotnet.compiler.PlatformUnsupportedException; import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.logging.Logger; import java.util.Set; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.io.File; -public class NetCompilerContextImpl implements NetCompilerContext +public class NetCompilerContextImpl + implements NetCompilerContext { + + /** + * The maven project + */ + private MavenProject project; + + private NetCompilerConfig netCompilerConfig; + + private Set<Artifact> libraryDependencies; + + private Set<Artifact> moduleDependencies; + + private Compiler compiler; + + /** + * A logger for writing log messages + */ + private Logger logger; + + private Set<File> linkedResources; + + private Set<File> embeddedResources; + + private File win32icon; + + private Set<File> win32resources; + + public Set<String> getCoreAssemblyNames() { return null; @@ -22,41 +58,217 @@ public Set<Artifact> getLibraryDependencies() { - return null; + return libraryDependencies; } public Set<Artifact> getModuleDependencies() { - return null; + return moduleDependencies; } public Set<File> getLinkedResources() { - return null; + return linkedResources; } public Set<File> getEmbeddedResources() { - return null; + return embeddedResources; } public File getWin32Icon() { - return null; + return win32icon; } public Set<File> getWin32Resources() { - return null; + return win32resources; } public CompilerConfig getCompilerConfig() { - return null; + return netCompilerConfig; } public Compiler getCompiler() { - return null; + return compiler; + } + + public MavenProject getMavenProject() + { + return project; + } + + public void init( MavenProject project, CompilerConfig compilerConfig ) + throws PlatformUnsupportedException + { + this.project = project; + this.netCompilerConfig = (NetCompilerConfig) compilerConfig; + libraryDependencies = new HashSet<Artifact>(); + moduleDependencies = new HashSet<Artifact>(); + + Set<Artifact> dependenctArtifacts = project.getDependencyArtifacts(); + if ( dependenctArtifacts != null ) + { + for ( Artifact dependenctArtifact : dependenctArtifacts ) + { + String type = dependenctArtifact.getType(); + if ( type.equals( "module" ) ) + { + moduleDependencies.add( dependenctArtifact ); + } + else if ( type.equals( "library" ) || type.equals( "exe" ) ) + { + libraryDependencies.add( dependenctArtifact ); + } + else if ( type.equals( "gac_generic" ) ) + { + String gacRoot = null; + if ( netCompilerConfig.getVendor().equals( Vendor.MICROSOFT ) && + ( netCompilerConfig.getCompilerPlatformVersion().compareTo( + NetCompilerPlatformVersion.VERSION_2_0_50727 ) >= 0 ) ) + { + gacRoot = System.getenv( "SystemRoot" ) + "\\assembly\\GAC_MSIL\\"; + } + else if ( netCompilerConfig.getVendor().equals( Vendor.MICROSOFT ) && + netCompilerConfig.equals( NetCompilerPlatformVersion.VERSION_1_1_4322 ) ) + { + gacRoot = System.getenv( "SystemRoot" ) + "\\assembly\\GAC\\"; + } + else if ( netCompilerConfig.getVendor().equals( Vendor.NOVELL ) ) + { + gacRoot = getGacRootForMono(); + } + + if ( gacRoot != null ) + { + setArtifactGacFile( gacRoot, dependenctArtifact ); + libraryDependencies.add( dependenctArtifact ); + } + } + else if ( type.equals( "gac" ) ) + { + String gacRoot = ( netCompilerConfig.getVendor().equals( Vendor.NOVELL ) ) ? getGacRootForMono() + : System.getenv( "SystemRoot" ) + "\\assembly\\GAC\\"; + setArtifactGacFile( gacRoot, dependenctArtifact ); + libraryDependencies.add( dependenctArtifact ); + } + else if ( type.equals( "gac_32" ) ) + { + String gacRoot = ( netCompilerConfig.getVendor().equals( Vendor.NOVELL ) ) ? getGacRootForMono() + : System.getenv( "SystemRoot" ) + "\\assembly\\GAC_32\\"; + setArtifactGacFile( gacRoot, dependenctArtifact ); + libraryDependencies.add( dependenctArtifact ); + } + else if ( type.equals( "gac_msil" ) ) + { + String gacRoot = ( netCompilerConfig.getVendor().equals( Vendor.NOVELL ) ) ? getGacRootForMono() + : System.getenv( "SystemRoot" ) + "\\assembly\\GAC_MSIL\\"; + setArtifactGacFile( gacRoot, dependenctArtifact ); + libraryDependencies.add( dependenctArtifact ); + } + } + } +/* + String className = compilerCapability.getPluginClassName(); + + try + { + Class cc = Class.forName( className ); + compiler = (Compiler) cc.newInstance(); + compiler.init( this );//TODO: Add ArtifactInfo? + } + catch ( ClassNotFoundException e ) + { + throw new PlatformUnsupportedException( + "NMAVEN-061-004: Unable to create NetCompiler: Class Name = " + className, e ); + } + 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 basedir = project.getBuild().getDirectory() + File.separator + "assembly-resources" + File.separator; + linkedResources = new File( basedir, "linkresource" ).exists() ? new HashSet<File>( + Arrays.asList( new File( basedir, "linkresource" ).listFiles() ) ) : new HashSet<File>(); + + embeddedResources = new File( basedir, "resource" ).exists() ? new HashSet<File>( + Arrays.asList( new File( basedir, "resource" ).listFiles() ) ) : new HashSet<File>(); + win32resources = new File( basedir, "win32res" ).exists() ? new HashSet<File>( + Arrays.asList( new File( basedir, "win32res" ).listFiles() ) ) : new HashSet<File>(); + File win32IconDir = new File( basedir, "win32icon" ); + if ( win32IconDir.exists() ) + { + File[] icons = win32IconDir.listFiles(); + if ( icons.length > 1 ) + { + throw new PlatformUnsupportedException( + "NMAVEN-061-007: There is more than one win32icon in resource directory: Number = " + icons + .length ); + } + if ( icons.length == 1 ) + { + win32icon = icons[0]; + } + } + } + + private static String getGacRootForMono() + throws PlatformUnsupportedException + { + String path = System.getenv( "PATH" ); + if ( path != null ) + { + String[] tokens = path.split( System.getProperty( "path.separator" ) ); + for ( String token : tokens ) + { + File gacRoot = new File( new File( token ).getParentFile(), "lib/mono/gac/" ); + if ( gacRoot.exists() ) + { + return gacRoot.getAbsolutePath(); + } + } + } + String monoRoot = System.getenv( "MONO_ROOT" ); + if ( monoRoot != null && !new File( monoRoot ).exists() ) + { + //logger.warn( "MONO_ROOT has been incorrectly set. Trying /usr : MONO_ROOT = " + monoRoot ); + } + else if ( monoRoot != null ) + { + return ( !monoRoot.endsWith( File.separator ) ) ? monoRoot + File.separator : monoRoot; + } + + if ( new File( "/usr/lib/mono/gac/" ).exists() ) + { + return new File( "/usr/lib/mono/gac/" ).getAbsolutePath(); + } + else + { + throw new PlatformUnsupportedException( + "NMAVEN-061-008: Could not locate Global Assembly Cache for Mono. Try setting the MONO_ROOT environmental variable." ); + } + } + + private static void setArtifactGacFile( String gacRoot, Artifact artifact ) + throws PlatformUnsupportedException + { + File gacFile = new File( gacRoot, artifact.getArtifactId() + File.separator + artifact.getVersion() + "__" + + artifact.getClassifier() + File.separator + artifact.getArtifactId() + ".dll" ); + if ( !gacFile.exists() ) + { + throw new PlatformUnsupportedException( + "NMAVEN-000-000: Could not find GAC dependency: File = " + gacFile.getAbsolutePath() ); + } + artifact.setFile( gacFile ); } }