/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; using JetBrains.Build.AllAssemblies; using JetBrains.Build.Omea.Infra; using JetBrains.Build.Omea.Util; using JetBrains.Omea.Base.Install; namespace JetBrains.Build.Omea.Resolved.Infra { /// /// Same as the base class, plus some business logic helpers for extracting and validating specific Bag parameters. /// public abstract class TaskResolved : TaskBaseResolved { #region Data /// /// A semicolon-separated list of the valid assembly extensions. /// public static readonly string AssemblyExtensions = "dll;exe"; #endregion #region Operations /// /// Checks for the existing files and choses the assembly extension from the list, eg “exe” or “dll”. /// Throws if not found. /// public FileInfo FindAssemblyFile(AssemblyXml assemblyxml) { var sbProbingPaths = new StringBuilder(); foreach(string sExtension in AssemblyExtensions.Split(';')) { string sProbingPath = Path.Combine(Bag.GetString(AttributeName.ProductBinariesDir), string.Format("{0}.{1}", assemblyxml.Include, sExtension)); var fi = new FileInfo(sProbingPath); if(fi.Exists) return fi; sbProbingPaths.AppendLine(); sbProbingPaths.Append(sProbingPath); } throw new InvalidOperationException(string.Format("Could not locate the “{0}” assembly in the “{1}” product binaries directory. The probing paths are listed below.{2}", assemblyxml.Include, Bag.GetString(AttributeName.ProductBinariesDir), sbProbingPaths)); } #endregion #region Implementation /// /// Creates an installer based on the list. /// protected Installer CreateInstaller() { // Load the AllAssemblies file AllAssembliesXml allassembliesxml = AllAssembliesXml.LoadFrom(Bag.Get(AttributeName.AllAssembliesXml).ItemSpec); // Get the list of assemblies var assemblies = new List(); foreach(ItemGroupXml group in allassembliesxml.ItemGroup) { if(group.AllAssemblies == null) continue; foreach(AssemblyXml assemblyxml in group.AllAssemblies) { FileInfo fiAssembly = FindAssemblyFile(assemblyxml); // Check whether it's a managed or native assembly AssemblyName assemblyname = null; try { assemblyname = AssemblyName.GetAssemblyName(fiAssembly.FullName); } catch(BadImageFormatException) { } if(assemblyname == null) continue; // Not a managed assembly // Collect assemblies.Add(Assembly.LoadFrom(fiAssembly.FullName)); } } return new Installer(assemblies); } #endregion } }