{
if ( compilerContext == null )
{
throw new ExecutionException( "NPANDAY-068-000: Compiler has not been initialized with a context" );
}
CompilerConfig config = compilerContext.getNetCompilerConfig();
// references uses directLibraryDependencies for non transitive dependencies
List<Artifact> references = compilerContext.getDirectLibraryDependencies();
List<Artifact> modules = compilerContext.getDirectModuleDependencies();
String sourceDirectory = compilerContext.getSourceDirectoryName();
String artifactFilePath = compilerContext.getArtifact().getAbsolutePath();
String targetArtifactType = config.getArtifactType().getTargetCompileType();
compilerContext.getCompilerRequirement().getFrameworkVersion();
List<String> commands = new ArrayList<String>();
if(config.getOutputDirectory() != null)
{
File f = new File(config.getOutputDirectory(), compilerContext.getArtifact().getName());
artifactFilePath = f.getAbsolutePath();
}
if(artifactFilePath!=null && artifactFilePath.toLowerCase().endsWith(".zip"))
{
artifactFilePath = artifactFilePath.substring(0, artifactFilePath.length() - 3) + "dll";
}
commands.add( "/out:" + artifactFilePath);
commands.add( "/target:" + targetArtifactType );
if(config.getIncludeSources() == null || config.getIncludeSources().isEmpty() )
{
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();
if( !path.contains( ".jar" ) )
{
commands.add( "/reference:" + path );
}
}
}
for ( String arg : compilerContext.getEmbeddedResourceArgs() )
{
if (logger.isDebugEnabled())
{
logger.debug( "NPANDAY-168-001 add resource: " + arg );
}
commands.add( "/resource:" + arg );
}
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 ( compilerContext.getCompilerRequirement().getVendor().equals( Vendor.MICROSOFT ) )
{
commands.add( "/nologo" );
}
if ( compilerContext.getCompilerRequirement().getVendor().equals( Vendor.MICROSOFT ) &&
compilerContext.getCompilerRequirement().getFrameworkVersion().equals( "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 ( compilerContext.getCompilerRequirement().getVendor().equals( Vendor.MICROSOFT ) &&
compilerContext.getCompilerRequirement().getFrameworkVersion().equals( "3.5" ) )
{
String wcfRef = "/reference:" + System.getenv( "SystemRoot" ) +
"\\Microsoft.NET\\Framework\\v3.5\\";
//TODO: This is a hard-coded path: Don't have a registry value either.
commands.add( wcfRef + "Microsoft.Build.Tasks.v3.5.dll" );
String cfBuildTasks = wcfRef + "Microsoft.CompactFramework.Build.Tasks.dll";
if (new File( cfBuildTasks ).exists())
{
commands.add( cfBuildTasks );
}
commands.add( wcfRef + "Microsoft.Data.Entity.Build.Tasks.dll" );
commands.add( wcfRef + "Microsoft.VisualC.STLCLR.dll" );
}
if ( compilerContext.getCompilerRequirement().getVendor().equals( Vendor.MICROSOFT ) &&
compilerContext.getCompilerRequirement().getFrameworkVersion().equals( "4.0" ) )
{
String wcfRef = "/reference:" + System.getenv( "SystemRoot" ) +
"\\Microsoft.NET\\Framework\\v4.0.30319\\";
//TODO: This is a hard-coded path: Don't have a registry value either.
commands.add( wcfRef + "Microsoft.Build.Tasks.v4.0.dll" );
commands.add( wcfRef + "Microsoft.Data.Entity.Build.Tasks.dll" );
commands.add( wcfRef + "Microsoft.VisualC.STLCLR.dll" );
}
if ( compilerContext.getKeyInfo().getKeyFileUri() != null )
{
commands.add( "/keyfile:" + compilerContext.getKeyInfo().getKeyFileUri() );
}
else if ( compilerContext.getKeyInfo().getKeyContainerName() != null )
{
commands.add( "/keycontainer:" + compilerContext.getKeyInfo().getKeyContainerName() );
}
if ( config.getCommands() != null )
{
commands.addAll( config.getCommands() );
}
commands.add( "/warnaserror-" );
//commands.add( "/nowarn" );
if ( compilerContext.getCompilerRequirement().getVendor().equals( Vendor.MONO ) )
{
commands.add( "/nostdlib" );
commands.add( "/noconfig" );
commands.add( "/reference:mscorlib" );
commands.add( "/reference:System.Data" );
commands.add( "/reference:System" );
commands.add( "/reference:System.Drawing" );
commands.add( "/reference:System.Messaging" );
commands.add( "/reference:System.Web.Services" );
commands.add( "/reference:System.Windows.Forms" );
commands.add( "/reference:System.Xml" );
commands.add( "/reference:System.Core" );
commands.add( "/reference:System.Data.DataSetExtensions" );
commands.add( "/reference:System.Xml.Linq" );
}
if ( !compilerContext.getNetCompilerConfig().isTestCompile() )
{
commands.add(
"/doc:" + new File( compilerContext.getTargetDirectory(), "comments.xml" ).getAbsolutePath() );
}
CommandFilter filter = compilerContext.getCommandFilter();
List<String> filteredCommands = filter.filter( commands );
//Include Sources code is being copied to temporary folder for the recurse option
String fileExt = "";
String frameWorkVer = ""+compilerContext.getCompilerRequirement().getFrameworkVersion();
String TempDir = "";
String targetDir = ""+compilerContext.getTargetDirectory();
Date date = new Date();
String Now =""+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds();
TempDir = targetDir+File.separator+Now;
try
{
FileUtils.deleteDirectory( TempDir );
}
catch(Exception e)
{
//Does Precautionary delete for tempDir
}
FileUtils.mkdir(TempDir);
if(config.getIncludeSources() != null && !config.getIncludeSources().isEmpty() )
{
int folderCtr=0;
for(String includeSource : config.getIncludeSources())
{
String[] sourceTokens = includeSource.replace('\\', '/').split("/");
String lastToken = sourceTokens[sourceTokens.length-1];