protected override void ExecuteTask()
{
FileInfo licensesFile = null;
// ensure base directory is set, even if fileset was not initialized
// from XML
if (Assemblies.BaseDirectory == null) {
Assemblies.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
}
// get the output .licenses file
if (OutputFile == null) {
try {
licensesFile = new FileInfo(Project.GetFullPath(Target + ".licenses"));
} catch (Exception ex) {
throw new BuildException(string.Format(CultureInfo.InvariantCulture,
ResourceUtils.GetString("NA2015"), Target), Location, ex);
}
} else {
licensesFile = OutputFile;
}
// make sure the directory for the .licenses file exists
if (!licensesFile.Directory.Exists) {
licensesFile.Directory.Create();
}
// determine whether .licenses file need to be recompiled
if (!NeedsCompiling(licensesFile)) {
return;
}
Log(Level.Verbose, ResourceUtils.GetString("String_CompilingLicenseUsingTarget"),
InputFile.FullName, licensesFile.FullName, Target);
if (HasCommandLineCompiler) {
// the command line compiler does not allow us to specify the
// full path to the output file, so we have it create the licenses
// file in a temp directory, and copy it to its actual output
// location
// use a newly created temporary directory as working directory
BaseDirectory = FileUtils.GetTempDirectory();
try {
// set target assembly for generated licenses file
Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
"/target:\"{0}\"", Target)));
// set input filename
Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
"/complist:\"{0}\"", InputFile.FullName)));
// set output directory
Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
"/outdir:\"{0}\"", BaseDirectory.FullName)));
// suppress display of startup banner
Arguments.Add(new Argument("/nologo"));
// adjust verbosity of tool if necessary
if (Verbose) {
Arguments.Add(new Argument("/v"));
}
// use command line tool to compile licenses file
base.ExecuteTask();
// delete any existing output file
if (File.Exists(licensesFile.FullName)) {
File.Delete(licensesFile.FullName);
}
// copy licenses file to output file (with overwrite)
File.Copy(Path.Combine(BaseDirectory.FullName, Target + ".licenses"),
licensesFile.FullName, true);
} finally {
// delete temporary directory and all files in it
DeleteTask deleteTask = new DeleteTask();
deleteTask.Project = Project;
deleteTask.Parent = this;
deleteTask.InitializeTaskConfiguration();
deleteTask.Directory = BaseDirectory;
deleteTask.Threshold = Level.None; // no output in build log
deleteTask.Execute();
}
} else {
// create new domain
#if (NET_4_0)
AppDomain newDomain = AppDomain.CreateDomain("LicenseGatheringDomain");
LicenseGatherer licenseGatherer = (LicenseGatherer)
newDomain.CreateInstanceAndUnwrap(typeof(LicenseGatherer).Assembly.FullName,
typeof(LicenseGatherer).FullName, false, BindingFlags.Public | BindingFlags.Instance,
null, new object[0], CultureInfo.InvariantCulture, new object[0]);
#else
AppDomain newDomain = AppDomain.CreateDomain("LicenseGatheringDomain",
AppDomain.CurrentDomain.Evidence);
LicenseGatherer licenseGatherer = (LicenseGatherer)
newDomain.CreateInstanceAndUnwrap(typeof(LicenseGatherer).Assembly.FullName,
typeof(LicenseGatherer).FullName, false, BindingFlags.Public | BindingFlags.Instance,
null, new object[0], CultureInfo.InvariantCulture, new object[0],
AppDomain.CurrentDomain.Evidence);
#endif
licenseGatherer.CreateLicenseFile(this, licensesFile.FullName);
// unload newly created domain
AppDomain.Unload(newDomain);
}
}