Exemplo n.º 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);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            int errlvl = 0;

            try {
                // Process Command-line Arguments
                string buildPath        = null;
                string buildUserProfile = null;
                string maxFileAge       = null;
                string exclusionFile    = null;
                string buildCfgFile     = null;

                if (args.Length < 1)
                {
                    Console.WriteLine();
                    Console.Error.WriteLine("Missing or Invalid Parameter.");
                    Usage();
                    errlvl = 2;
                    return(errlvl);
                }

                buildPath = args[0];
                foreach (string arg in args)
                {
                    if (arg.ToLower().StartsWith("/p:"))
                    {
                        buildUserProfile = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/a:"))
                    {
                        maxFileAge = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/e:"))
                    {
                        exclusionFile = arg.Substring(3).Trim();
                    }
                    if (arg.ToLower().StartsWith("/f:"))
                    {
                        buildCfgFile = arg.Substring(3).Trim();
                    }
                }

                Console.WriteLine();
                Console.WriteLine("buildPath:        " + buildPath);
                Console.WriteLine("buildUserProfile: " + buildUserProfile);
                Console.WriteLine("maxFileAge:       " + maxFileAge);
                Console.WriteLine("exclusionFile:    " + exclusionFile);
                Console.WriteLine("buildCfgFile:     " + buildCfgFile);
                Console.WriteLine();

                //build dataset
                ProductBuildDataSet pbDataSet = null;
                if (buildCfgFile != null)
                {
                    pbDataSet = ProductBuildDataSet.ReadBuildConfigurationFile(buildCfgFile);
                }
                else
                {
                    LibraryManifest li = new LibraryManifest(buildPath);
                    if (buildUserProfile == null)
                    {
                        buildUserProfile = "Development";
                    }
                    pbDataSet = ProductBuildDataSet.GetProductBuildDataSetWithoutComplist(buildUserProfile,
                                                                                          li.GetName(),
                                                                                          li.GetVersion(),
                                                                                          li.GetPlatform(),
                                                                                          li.GetBranchOrTrunkName(),
                                                                                          li.GetDirectory(),
                                                                                          buildPath,
                                                                                          li.GetDate());
                    pbDataSet.LoadComplist();
                    pbDataSet.FinalizeProperties();
                }

                if (maxFileAge == null)
                {
                    maxFileAge = pbDataSet.GetBuildProperty("MaximumTargetAge");
                }
                //hack for backwards compatibility
                int colonIndex  = maxFileAge.IndexOf(':');
                int periodIndex = maxFileAge.IndexOf('.');
                if (periodIndex == -1 || colonIndex < periodIndex)
                {
                    maxFileAge = maxFileAge.Substring(0, colonIndex) + "." + maxFileAge.Substring(colonIndex + 1);
                }

                ArrayList checkedTargets   = pbDataSet.GetTargets(true);
                ArrayList uncheckedTargets = pbDataSet.GetTargets(false);

                if (exclusionFile != null)
                {
                    StringCollection excludedFiles = CollectionUtil.ReadValueFile(exclusionFile);
                    foreach (string excludedFile in excludedFiles)
                    {
                        foreach (string checkedTarget in checkedTargets)
                        {
                            if (excludedFile.ToLower() == checkedTarget.ToLower())
                            {
                                checkedTargets.Remove(checkedTarget);
                                uncheckedTargets.Add(checkedTarget);
                            }
                        }
                    }
                    uncheckedTargets.Sort();
                }

                //check the build
                Console.WriteLine();
                Console.WriteLine("Checking product , {0}, {1}, {2}, {3}",
                                  new object[] { pbDataSet.GetBuildProperty("ProductName"),
                                                 pbDataSet.GetBuildProperty("ProductVersion"),
                                                 pbDataSet.GetBuildProperty("ProductPlatform"),
                                                 pbDataSet.GetBuildProperty("BranchOrTrunkName"),
                                                 buildPath });
                Console.WriteLine("  in {0}", buildPath);
                Console.WriteLine();

                int  totalTargets     = checkedTargets.Count + uncheckedTargets.Count;
                int  foundTargets     = 0;
                int  duplicateTargets = 0;
                int  excludedTargets  = uncheckedTargets.Count;
                int  missingTargets   = 0;
                int  overAgeTargets   = 0;
                bool buildSucceeded   = true;

                string binPath = Path.Combine(buildPath, "bin");

                DateTime currentTime = DateTime.Now;
                DateTime checkTime   = currentTime - TimeSpan.Parse(maxFileAge);
                for (int targetIndex = 0; targetIndex < checkedTargets.Count; targetIndex++)
                {
                    string target = (string)checkedTargets[targetIndex];
                    if (targetIndex > 0 && target.ToLower() == ((string)checkedTargets[targetIndex - 1]).ToLower())
                    {
                        duplicateTargets++;
                        continue;
                    }
                    string targetFilename = Path.Combine(binPath, target);
                    if (!File.Exists(targetFilename))
                    {
                        buildSucceeded = false;
                        missingTargets++;
                        Console.WriteLine("{0,-32} Missing", target);
                        continue;
                    }
                    foundTargets++;
                    DateTime creationTime = File.GetLastWriteTime(targetFilename);
                    if (creationTime < checkTime)
                    {
                        buildSucceeded = false;
                        overAgeTargets++;
                        TimeSpan overAgeTime   = currentTime - creationTime;
                        string   overAgeString = "";
                        if (overAgeTime.Days > 0)
                        {
                            overAgeString += String.Format("{0,4}d", overAgeTime.Days);
                        }
                        if (overAgeTime.Hours > 0)
                        {
                            overAgeString += String.Format("{0:D2}h", overAgeTime.Hours);
                        }
                        overAgeString += String.Format("{0:D2}m", overAgeTime.Minutes);
                        Console.WriteLine("{0,-32} OverAge:{1}", target, overAgeString);
                    }
                }

                //results summary
                Console.WriteLine();
                Console.WriteLine("CheckBuild Statistics:");
                Console.WriteLine("Product           : {0}", pbDataSet.GetBuildProperty("ProductName"));
                Console.WriteLine("Version           : {0}", pbDataSet.GetBuildProperty("ProductVersion"));
                Console.WriteLine("Platform          : {0}", pbDataSet.GetBuildProperty("ProductPlatform"));
                Console.WriteLine("BranchOrTrunkName : {0}", pbDataSet.GetBuildProperty("BranchOrTrunkName"));
                Console.WriteLine("Target Dir        : {0}", buildPath);
                Console.WriteLine("Max File Age      : {0} (DD.HH:MM:SS)", maxFileAge);
                Console.WriteLine("Targets           : {0}", totalTargets);
                Console.WriteLine("Found             : {0}", foundTargets);
                Console.WriteLine("Duplicates        : {0}", duplicateTargets);
                Console.WriteLine("Excluded          : {0}", excludedTargets);
                Console.WriteLine("Missing           : {0}", missingTargets);
                Console.WriteLine("OverAge           : {0}", overAgeTargets);
                string successString = (buildSucceeded) ? "Successful Build." : "Build Failed!!!";
                Console.WriteLine("Results           : {0}", successString);

                errlvl = (buildSucceeded) ? 0 : 1;
            }
            catch (Exception e) {
                errlvl = 2;
                Console.Error.WriteLine("An error occurred in CheckBuild:");
                Console.Error.WriteLine(e.ToString());
                Usage();
            }

            return(errlvl);
        }