Example #1
0
 object ITaskProcessor.Process(BCBBuildTask task) {
     if(task == null) return null;
     string project = task.ProjectPath;            
     string projectDir = Path.GetDirectoryName(project);
     if(!File.Exists(CommonSettings.BprToMakExe)) {
         return new FileNotFoundException(string.Format("File not found {0}", CommonSettings.BprToMakExe));                
     }
     if(!File.Exists(CommonSettings.MakeExe)) {
         return new FileNotFoundException(string.Format("File not found {0}", CommonSettings.MakeExe));     
     }
     string currentDir = Directory.GetCurrentDirectory();
     Directory.SetCurrentDirectory(projectDir);
     bool removeProjectFile = PrepareProject(ref project, task);
     string projectName = Path.GetFileNameWithoutExtension(project);
     try {
         BprToMak(project, projectName);
         Make(project, projectName);
     }catch(Exception ex){
         return ex;
     } finally {
         Directory.SetCurrentDirectory(currentDir);
         if(removeProjectFile && File.Exists(project))
                 File.Delete(project);
         string makeFileName = Path.ChangeExtension(project, "mak");
         if(File.Exists(makeFileName))
             File.Delete(makeFileName);
     }
     return null;
 }
 object ITaskProcessor.Process(BCBBuildTask task) {
     ProcessBaseTask(task);
     task.ProjectPath = ProcessString(task.ProjectPath);
     task.AddDefines = ProcessString(task.AddDefines);
     if(task.ProcessingItems != null) {
         foreach(var processintItem in task.ProcessingItems) {
             processintItem.Element = ProcessString(processintItem.Element);
             processintItem.Attribute = ProcessString(processintItem.Attribute);
             processintItem.ToAdd = ProcessString(processintItem.ToAdd);
             processintItem.ToRemove = ProcessString(processintItem.ToRemove);
         }
     }
     return null;
 }
Example #3
0
 static bool PrepareProject(ref string project, BCBBuildTask task) {
     if(string.IsNullOrEmpty(task.AddDefines) && (task.ProcessingItems == null || task.ProcessingItems.Length == 0))
         return false;
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(project);
     if(!string.IsNullOrEmpty(task.AddDefines)) {
         XmlNodeList definesNodeList = xmlDoc.GetElementsByTagName(DefinesTag);
         foreach(XmlNode node in definesNodeList) {
             node.Attributes["value"].Value = string.Concat(node.Attributes["value"].Value, separatorString, string.Join(separatorString, task.AddDefines.Split(separatorChars, StringSplitOptions.RemoveEmptyEntries)), separatorString);
         }
     }
     if(task.ProcessingItems != null) {
         foreach(BCBProjectProcessingItem item in task.ProcessingItems) {
             if(string.IsNullOrEmpty(item.Element)) continue;
             XmlNodeList nodeList = xmlDoc.GetElementsByTagName(item.Element);
             string[] removeList = string.IsNullOrEmpty(item.ToRemove) ? null : item.ToRemove.Split(new string[] { ";;" }, StringSplitOptions.RemoveEmptyEntries);
             foreach(XmlNode node in nodeList) {
                 if(string.IsNullOrEmpty(item.Attribute)) continue;
                 XmlAttribute attribute = node.Attributes[item.Attribute];
                 if(attribute == null) {
                     attribute = xmlDoc.CreateAttribute(item.Attribute); 
                     node.Attributes.Append(attribute);
                 }
                 if(item.Value != null) {
                     attribute.Value = item.Value;
                     continue;
                 }
                 string value = attribute.Value;                        
                 if(removeList != null) {
                     foreach(var remove in removeList) {
                         value = value.Replace(remove, "");
                     }
                 }
                 if(!string.IsNullOrEmpty(item.ToAdd)) {
                     value = value + item.ToAdd;
                 }
                 attribute.Value = value;
             }
         }
     }
     string dir = Path.GetDirectoryName(project);
     string projectName = Path.GetFileNameWithoutExtension(project);
     project = Path.Combine(dir, string.Concat(projectName, Guid.NewGuid().ToString("N"), ".bpr"));
     xmlDoc.Save(project);
     string contect = File.ReadAllText(project);
     contect.Replace("
", Environment.NewLine);
     File.WriteAllText(project, contect);
     return true;
 }