/// <summary> /// Building main entry point. /// </summary> /// <param name="abstractOpen"></param> /// <param name="output"></param> /// <param name="fxCopPath">FxCopCmd.exe path</param> /// <param name="fXCopOut">FxCop result directory</param> /// <param name="row">CSV file second row</param> public static void Start(AbstractOpen abstractOpen, string output, string fxCopPath, string fXCopOut, string outListFilePath) { WriteMsg.WriteLine("Starting analysis..."); MainDeclaration.Instance.CSSIExtension = (abstractOpen is FileOpen) ? Constants.CSSIEXTENSION : Constants.LCSSIEXTENSION; MainDeclaration.Instance.Solution = abstractOpen.Solution; foreach (Project project in abstractOpen.TopologicallySortedProjectDependencies) { if (Commons.Common.CheckOuterFilters(project.FilePath)) { continue; } WriteMsg.WriteWithBreak("Analyzing {0}...", WriteMsg.MsgLevel.Normal, 4, project.AssemblyName); Analyse(project, output, fxCopPath, fXCopOut); } MainDeclaration.Instance.Statistics[0].CSharpASGBuildingTime = MainDeclaration.Instance.CSSIWatch.ElapsedSeconds; MainDeclaration.Instance.Statistics[0].LIMASGBildingTime = MainDeclaration.Instance.LIMWatch.ElapsedSeconds; LineMetrics.Calculate(); WriteMsg.WriteLine("Analysis finished"); if (!string.IsNullOrEmpty(outListFilePath)) { File.WriteAllText(outListFilePath, string.Join(Environment.NewLine, outfiles)); } MainDeclaration.Instance.FxCopTasks.WaitAll(); }
/// <summary> /// The program main entry point. /// </summary> /// <param name="args">Command line arguments</param> private static void Main(string[] args) { #if !DEBUG try { #endif MainDeclaration.Instance.MainWatch.Start(); //this should be called first, before any output WriteMsg.Initialize(args); WriteMsg.WriteLine( "C# Analyzer {0} ({1}) - {2}", WriteMsg.MsgLevel.Silent, 0, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3), //we use 3 digit versions, eg 7.0.6 Columbus.Common.Revision, Columbus.Common.CopyRightMessage); WriteMsg.WriteLine(); Process myProcess = Process.GetCurrentProcess(); if (Arguments.ProcessArguments(args, OPTIONS_OBJ, "-", ppUnknownOption) && !string.IsNullOrEmpty(INPUT) && !string.IsNullOrEmpty(OUTPUT)) { WriteMsg.WriteLine("Input: " + INPUT); WriteMsg.WriteLine("Output: " + OUTPUT); if (!string.IsNullOrEmpty(FXCOPPATH)) { WriteMsg.WriteLine("FxCopPath: " + FXCOPPATH); } } else { WriteMsg.WriteLine("Error: No input and/or output specified!", WriteMsg.MsgLevel.Error); WriteMsg.WriteLine("", WriteMsg.MsgLevel.Error); ppHelp(default(Option), null); Environment.Exit(1); } if (!CheckFxCopPath()) { Environment.Exit(1); } CheckStopwatches(); if (MainDeclaration.Instance.HardFilter != null) { WriteMsg.WriteLine("Hardfilter: " + EXTERNALHARDFILTER); } if (MainDeclaration.Instance.SoftFilter != null) { WriteMsg.WriteLine("Softfilter: " + EXTERNALSOFTFILTER); } MainDeclaration.Instance.LimFactory.Language = Lim.Asg.Types.LanguageKind.lnkCsharp; WriteMsg.WriteLine("File parsing..."); var timer = MainDeclaration.Instance.MainWatch.ElapsedSeconds; using (AbstractOpen file = AbstractOpen.CreateInstance(INPUT, CONFIGURATION, PLATFORM)) { file.Parse(); MainDeclaration.Instance.Statistics[0].FilesParsingTime = MainDeclaration.Instance.MainWatch.ElapsedSeconds - timer; WriteMsg.WriteLine("File parsing finished."); float buildTime = 0f; if (BUILDPROJECT) { WriteMsg.WriteLine("Build started"); Stopwatch watch = Stopwatch.StartNew(); MainDeclaration.Instance.BuildTask = file.BuildSoulution().ContinueWith(task => { buildTime = watch.ElapsedSeconds; WriteMsg.WriteLine(task.Result ? "Build succeeded" : "Build failed"); }); } timer = MainDeclaration.Instance.MainWatch.ElapsedSeconds; Build.Start(file, OUTPUT, RUNFXCOP ? FXCOPPATH : null, FXCOPOUT, OUTLIST); MainDeclaration.Instance.Statistics[0].ASGBuildingTime = MainDeclaration.Instance.MainWatch.ElapsedSeconds - timer; if (MainDeclaration.Instance.BuildTask != null) { MainDeclaration.Instance.BuildTask.Wait(); } MainDeclaration.Instance.Statistics[0].SolutionsBuildingTime = buildTime; MainDeclaration.Instance.Statistics[0].RoslynTime = MainDeclaration.Instance.RoslynWatch.ElapsedSeconds; timer = MainDeclaration.Instance.MainWatch.ElapsedSeconds; Build.SaveLimASG(INPUT, OUTPUT, LIMNAME); MainDeclaration.Instance.Statistics[0].SaveTime = MainDeclaration.Instance.MainWatch.ElapsedSeconds - timer; MainDeclaration.Instance.MainWatch.Stop(); WriteMsg.WriteLine(); WriteStatistics(MainDeclaration.Instance.MainWatch, myProcess.PeakWorkingSet64); if (!string.IsNullOrEmpty(STAT)) { MainDeclaration.Instance.Statistics.ToCsv(new CsvDestination(STAT), new CsvDefinition() { FieldSeparator = CSVSEPARATOR, DecimalSeparator = DECIMALSEPARATOR }); } } #if !DEBUG } /// Catch everything to prevent .NET's default "stopped working" dialog from showing up /// and blocking multiple processes waiting on this to exit catch (AggregateException e) { Console.Error.WriteLine(); Console.Error.WriteLine("EXCEPTION: {0}", e.GetType()); Console.Error.WriteLine(); if (e.InnerExceptions.Count > 1) { foreach (var error in e.InnerExceptions) { Console.Error.WriteLine("EXCEPTION: {0}", error.GetType()); Console.Error.WriteLine(error.Message); Console.Error.WriteLine(error.StackTrace); Console.Error.WriteLine(); } } else if (e.InnerException != null) { Console.Error.WriteLine("EXCEPTION: {0}", e.InnerException.GetType()); Console.Error.WriteLine(e.InnerException.Message); Console.Error.WriteLine(e.InnerException.StackTrace); } else { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } Environment.Exit(1); } catch (Exception e) { Console.Error.WriteLine(); Console.Error.WriteLine("EXCEPTION: {0}", e.GetType()); Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(1); } #endif }