Exemple #1
0
        static int Main(string[] args)
        {
            if (args.Length < 1)
            {
                errorLevel = 3;
                Usage();
                return(errorLevel);
            }

            try {
                string    path = null;
                Hashtable commandLineProperties = new Hashtable();

                ProcessCommandLineArguments(args, ref path, commandLineProperties);

                LibraryManifest libraryInfo = new LibraryManifest(path);

                // default to Development profile
                string profileName            = "Development (Public)";
                string commandLineProfileName = (string)commandLineProperties["BuildProfileName"];
                profileName = (commandLineProfileName != null) ? commandLineProfileName : profileName;

                ProductBuildDataSet pbDataSet = ProductBuildDataSet.GetProductBuildDataSetWithoutComplist(
                    profileName,
                    libraryInfo.GetName(),
                    libraryInfo.GetVersion(),
                    libraryInfo.GetPlatform(),
                    libraryInfo.GetBranchOrTrunkName(),
                    libraryInfo.GetDirectory(),
                    path,
                    libraryInfo.GetDate());

                pbDataSet.ApplyCommandLineProperties(commandLineProperties);
                pbDataSet.LoadComplist();
                pbDataSet.FinalizeProperties();
                pbDataSet.WriteBuildConfigurationFile(pbDataSet.GetBuildConfigurationFilename());

                string           buildPath        = pbDataSet.GetBuildProperty("BuildPath");
                VmsProduct       currProduct      = new VmsProduct(libraryInfo.GetName(), libraryInfo.GetVersion(), libraryInfo.GetPlatform());
                VmsLibrary       currLibrary      = new VmsLibrary(currProduct, libraryInfo.GetBranchOrTrunkName());
                ControllerObject controllerObject = new ControllerObject();
                string           currentKey       = Util.GetServiceKey();
                bool             actionSucceeded  = false;
                string           errorMessage     = null;
                if (controllerObject.BuildLibrary(currLibrary, currentKey, buildPath, out errorMessage, false))
                {
                    NewMessage.ProcessMessages(currentKey, ref errorMessage, ref actionSucceeded, false, ref errorLevel);
                    if (actionSucceeded)
                    {
                        Console.WriteLine("    Successfully built " + currLibrary.ShortLibraryName);
                    }
                    else
                    {
                        Console.WriteLine("    Error building " + currLibrary.ShortLibraryName + ":" + errorMessage);
                    }
                }
                else
                {
                    Console.WriteLine("    Error building " + currLibrary.ShortLibraryName + ":" + errorMessage);
                }
            }
            catch (Exception e) {
                errorLevel = 3;
                Console.Error.WriteLine("An error occurred in ProductBuilder:");
                Console.Error.WriteLine(e.ToString());
                Usage();
            }
            return(errorLevel);
        }
Exemple #2
0
        static int Main(string[] commandArgs)
        {
            int returnValue = 0;

            try {
                if (commandArgs.Length < 1)   //error, no arg. supplied
                {
                    string errMsg = "No argument supplied.\n";
                    errMsg += "\tUsage: " + Process.GetCurrentProcess().ProcessName + " <Build Import Manifest>\n";
                    errMsg += "\tFor example, " + Process.GetCurrentProcess().ProcessName + " BuildImports.xml";
                    throw new Exception(errMsg);
                }
                if (!File.Exists(commandArgs[0]))
                {
                    throw new Exception("File not found: " + commandArgs[0]);
                }
                //Get build attributes. Note: This module always expects q:\ to be mapped to the build path by
                //LibraryBuilder prior to invocation.
                LibraryManifest     currManifest        = new LibraryManifest(LBEnvironment.BuildMapDrive);
                string              buildDefinitionFile = ProductBuildDataSet.GetBuildConfigurationFilename(LBEnvironment.BuildMapDrive);
                ProductBuildDataSet pbDataSet           = ProductBuildDataSet.ReadBuildConfigurationFile(buildDefinitionFile);
                string              buildProfile        = pbDataSet.GetBuildProperty("BuildProfileName");

                //Parse the xml file.
                XmlDocument xmlManifestDoc = new XmlDocument();
                xmlManifestDoc.Load(commandArgs[0]);
                //file may or may not contain version info
                XmlNode versionNode = xmlManifestDoc.DocumentElement.Attributes.GetNamedItem("version");
                int     fileVersion = (versionNode == null)? 1 : int.Parse(versionNode.InnerText);
                //version 3 or higher is implemented in LB and uses zip file implementation
                if (fileVersion >= 3)
                {
                    FileSystemInterface.ValidateComponentImportStep(LBEnvironment.BuildMapDrive,
                                                                    currManifest.GetBranchOrTrunkName(),
                                                                    commandArgs[0], false, true, false);
                }
                else
                {
                    foreach (XmlNode importNode in xmlManifestDoc.DocumentElement.ChildNodes)
                    {
                        if (importNode.NodeType != XmlNodeType.Comment)
                        {
                            string prodName           = importNode.Attributes["sourceProduct"].InnerText;
                            string prodVer            = importNode.Attributes["sourceVersion"].InnerText;
                            string platCode           = importNode.Attributes["sourcePlatform"].InnerText;
                            string branchOrTrunkName  = importNode.Attributes["sourceBranchOrTrunkName"].InnerText;
                            string itemToCopy         = importNode.SelectSingleNode("source").Attributes["path"].InnerText;
                            string destPath           = importNode.SelectSingleNode("destination").Attributes["path"].InnerText;;
                            bool   copySubdirectories = false;
                            bool   cleanAtDestination = false;
                            if (fileVersion > 1)
                            {
                                copySubdirectories = bool.Parse(importNode.SelectSingleNode("source").Attributes["copySubDirectories"].InnerText.ToLower());
                                cleanAtDestination = bool.Parse(importNode.SelectSingleNode("source").Attributes["cleanDestination"].InnerText.ToLower());
                            }

                            //Trim spaces and path characters
                            itemToCopy = itemToCopy.Trim(new char[] { ' ', '\\', '/' });
                            destPath   = destPath.Trim(new char[] { ' ', '\\', '/' });

                            string productPath = LBEnvironment.NetworkProductRootDir + "\\" + prodName + "\\V" + prodVer.Replace(".", "_") + "." + platCode;
                            if (!Directory.Exists(productPath))
                            {
                                throw new Exception("Product directory not found: " + productPath);
                            }

                            //Compute and identify - directory, file or wildcard - what to copy. Compute the destination as well.
                            // Also indicate whether listed path exists.
                            string       sourceFullPath          = productPath + "\\" + branchOrTrunkName + "\\" + itemToCopy;;
                            string       destFullpath            = Path.Combine(LBEnvironment.BuildMapDrive, destPath);
                            string       alternateSourceFullPath = productPath + "\\" + "DEVELOP" + "\\" + itemToCopy;;
                            bool         usingAlternateCopyPath  = false;
                            CopyItemType copyItemType            = CopyItemType.UNIDENTIFIED;
                            if (itemToCopy.IndexOf("*") > 1)
                            {
                                copyItemType = CopyItemType.WILDCARD;
                                if (!Directory.Exists(Path.GetDirectoryName(sourceFullPath)))
                                {
                                    usingAlternateCopyPath  = true;
                                    alternateSourceFullPath = productPath + "\\" + "DEVELOP" + "\\" + itemToCopy;
                                }
                            }
                            else if (Directory.Exists(sourceFullPath))
                            {
                                copyItemType = CopyItemType.DIRECTORY;
                            }
                            else if (Directory.Exists(alternateSourceFullPath))
                            {
                                copyItemType           = CopyItemType.DIRECTORY;
                                usingAlternateCopyPath = true;
                            }
                            else if (File.Exists(sourceFullPath))
                            {
                                copyItemType = CopyItemType.FILE;
                            }
                            else if (File.Exists(alternateSourceFullPath))
                            {
                                copyItemType           = CopyItemType.FILE;
                                usingAlternateCopyPath = true;
                            }
                            else   //Listed path not valid
                            {
                                throw new Exception("Unable to find import source: " + sourceFullPath);
                            }
                            //Create the destination directory
                            Directory.CreateDirectory(destFullpath);

                            //For QA profiles or non-DEVELOP builds, a build must fail if a listed path cannot be found. Accept no substitutes:
                            //A listed path must not be from DEVELOP, PREPROD, PROD or CANDIDATE and it must exist
                            if (buildProfile.ToUpper().StartsWith("QA") || (currManifest.GetBranchOrTrunkName().ToUpper() != "DEVELOP"))
                            {
                                if ((branchOrTrunkName.ToUpper() == "DEVELOP") || (branchOrTrunkName.ToUpper() == "CANDIDATE") ||
                                    (branchOrTrunkName.ToUpper() == "PREPROD") || (branchOrTrunkName.ToUpper() == "PROD") ||
                                    (branchOrTrunkName.ToUpper() == "STABLE"))
                                {
                                    string errMsg = "Cannot build QA level library or profile without a branch library import source. ";
                                    errMsg += "Please check your entry in " + commandArgs[0] + " for ";
                                    errMsg += prodName + " " + prodVer + " " + platCode + " " + branchOrTrunkName;
                                    throw new Exception(errMsg);
                                }
                                if (usingAlternateCopyPath)
                                {
                                    throw new Exception("Unable to find import source: " + sourceFullPath);
                                }
                            }

                            string sourceItem = (usingAlternateCopyPath)? alternateSourceFullPath : sourceFullPath;
                            //If copying a directory add a wildcard
                            if (copyItemType == CopyItemType.DIRECTORY)
                            {
                                sourceItem = Path.Combine(sourceItem, "*.*");
                            }
                            //if clean copy was requested, delete source files' paths at destination
                            if (cleanAtDestination && Directory.Exists(destFullpath))
                            {
                                ImportComponents.DeleteFiles(Path.Combine(destFullpath, Path.GetFileName(sourceItem)), copySubdirectories);
                            }

                            returnValue = ImportComponents.XCopyDirToQDrive(sourceItem, destFullpath, copySubdirectories);
                            if (returnValue != 0)
                            {
                                throw new Exception("xcopy returned an error(" + returnValue.ToString() + ") while copying " + sourceItem + " to " + destFullpath);
                            }
                        }
                    }//foreach
                }
            }
            catch (Exception currExcept) {
                Console.WriteLine("Error occurred during build import: " + currExcept.Message);
                if (returnValue == 0)
                {
                    returnValue = 1;
                }
            }
            return(returnValue);
        }