Ejemplo n.º 1
0
        public static void Main(string[] argv)
        {
            var    args = new MainArgs(argv, exit: true, version: (string)GetDisplayVersion());
            string repoToken;

            if (args.IsProvided("--repoToken"))
            {
                repoToken = args.OptRepotoken;
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoToken is required.");
                }
            }
            else
            {
                var variable = args.OptRepotokenvariable;
                if (variable.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoTokenVariable is required.");
                }

                repoToken = Environment.GetEnvironmentVariable(variable);
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("No token found in Environment Variable '{0}'.".FormatWith(variable));
                }
            }
            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;

            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List <CoverageFile> files;

            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    ExitWithError("Input file '" + fileName + "' cannot be found");
                }
                Dictionary <string, XDocument> documents =
                    new DirectoryInfo(fileName).GetFiles()
                    .Where(f => f.Name.EndsWith(".xml"))
                    .ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else
            {
                List <FileCoverageData> coverageData;
                if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new DynamicCodeCoverageParser().GenerateSourceFiles(document);
                }
                else if (args.IsProvided("--exportcodecoverage") && args.OptExportcodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new ExportCodeCoverageParser().GenerateSourceFiles(document);
                }
                else
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new OpenCoverParser().GenerateSourceFiles(document);
                }

                files = coverageData.Select(coverageFileData =>
                {
                    var coverageBuilder = new CoverageFileBuilder(coverageFileData);

                    var path = coverageFileData.FullPath;
                    if (args.OptUserelativepaths)
                    {
                        path = pathProcessor.ConvertPath(coverageFileData.FullPath);
                    }
                    path = pathProcessor.UnixifyPath(path);
                    coverageBuilder.SetPath(path);

                    var readAllText = new FileSystem().TryLoadFile(coverageFileData.FullPath);
                    if (readAllText.HasValue)
                    {
                        coverageBuilder.AddSource((string)readAllText);
                    }

                    var coverageFile = coverageBuilder.CreateFile();
                    return(coverageFile);
                }).ToList();
            }

            var gitData = ResolveGitData(args);

            var serviceJobId  = ResolveServiceJobId(args);
            var pullRequestId = ResolvePullRequestId(args);

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var    data        = new CoverallData
            {
                RepoToken     = repoToken,
                ServiceJobId  = serviceJobId.ValueOr("0"),
                ServiceName   = serviceName,
                PullRequestId = pullRequestId.ValueOr(null),
                SourceFiles   = files.ToArray(),
                Git           = gitData.ValueOrDefault()
            };

            var fileData = JsonConvert.SerializeObject(data);

            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploadResult = new CoverallsService().Upload(fileData);
                if (!uploadResult.Successful)
                {
                    var message = string.Format("Failed to upload to coveralls\n{0}", uploadResult.Error);
                    if (args.OptTreatuploaderrorsaswarnings)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        ExitWithError(message);
                    }
                }
                else
                {
                    Console.WriteLine("Coverage data uploaded to coveralls.");
                }
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] argv)
        {
            var args = new MainArgs(argv, exit: true, version: (string)GetDisplayVersion());
            string repoToken;
            if (args.IsProvided("--repoToken"))
            {
                repoToken = args.OptRepotoken;
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoToken is required.");
                }
            }
            else
            {
                var variable = args.OptRepotokenvariable;
                if (variable.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoTokenVariable is required.");
                }

                repoToken = Environment.GetEnvironmentVariable(variable);
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("No token found in Environment Variable '{0}'.".FormatWith(variable));
                }

            }
            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;
            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List<CoverageFile> files;
            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    ExitWithError("Input file '" + fileName + "' cannot be found");
                }
                Dictionary<string, XDocument> documents =
                    new DirectoryInfo(fileName).GetFiles()
                        .Where(f => f.Name.EndsWith(".xml"))
                        .ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else
            {
                List<FileCoverageData> coverageData;
                if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new DynamicCodeCoverageParser().GenerateSourceFiles(document);
                }
                else
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new OpenCoverParser().GenerateSourceFiles(document);
                }

                files = coverageData.Select(coverageFileData =>
                {
                    var coverageBuilder = new CoverageFileBuilder(coverageFileData);

                    var path = coverageFileData.FullPath;
                    if (args.OptUserelativepaths)
                    {
                        path = pathProcessor.ConvertPath(coverageFileData.FullPath);
                    }
                    path = pathProcessor.UnixifyPath(path);
                    coverageBuilder.SetPath(path);

                    var readAllText = new FileSystem().TryLoadFile(coverageFileData.FullPath);
                    if (readAllText.HasValue)
                    {
                        coverageBuilder.AddSource((string)readAllText);
                    }

                    var coverageFile = coverageBuilder.CreateFile();
                    return coverageFile;
                }).ToList();
            }

            var gitData = ResolveGitData(args);

            var serviceJobId = ResolveServiceJobId(args);

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var data = new CoverallData
            {
                RepoToken = repoToken,
                ServiceJobId = serviceJobId.ValueOr("0"),
                ServiceName = serviceName,
                SourceFiles = files.ToArray(),
                Git = gitData.ValueOrDefault()
            };

            var fileData = JsonConvert.SerializeObject(data);
            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploadResult = new CoverallsService().Upload(fileData);
                if (!uploadResult.Successful)
                {
                    var message = string.Format("Failed to upload to coveralls\n{0}", uploadResult.Error);
                    if (args.OptTreatuploaderrorsaswarnings)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        ExitWithError(message);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] argv)
        {
            var args      = new MainArgs(argv, exit: true, version: Assembly.GetEntryAssembly().GetName().Version);
            var repoToken = args.OptRepotoken;

            if (string.IsNullOrWhiteSpace(repoToken))
            {
                Console.Error.WriteLine("parameter repoToken is required.");
                Console.WriteLine(MainArgs.Usage);
                Environment.Exit(1);
            }
            var fileName = args.OptInput;

            if (!File.Exists(fileName))
            {
                Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                Environment.Exit(1);
            }
            var document = XDocument.Load(fileName);

            List <CoverageFile> files = new OpenCoverParser(new FileSystem()).GenerateSourceFiles(document);

            GitData gitData  = null;
            var     commitId = args.OptCommitid ?? string.Empty;

            if (!string.IsNullOrWhiteSpace(commitId))
            {
                var committerName = args.OptCommitauthor ?? string.Empty;
                var comitterEmail = args.OptCommitemail ?? string.Empty;
                var commitMessage = args.OptCommitmessage ?? string.Empty;
                gitData = new GitData
                {
                    Head = new GitHead
                    {
                        Id            = commitId,
                        AuthorName    = committerName,
                        AuthorEmail   = comitterEmail,
                        CommitterName = committerName,
                        ComitterEmail = comitterEmail,
                        Message       = commitMessage
                    },
                    Branch = args.OptCommitbranch ?? string.Empty
                };
            }

            var serviceJobId = args.OptJobid ?? "0";

            var data = new CoverallData
            {
                RepoToken    = repoToken,
                ServiceJobId = serviceJobId,
                ServiceName  = "coveralls.net",
                SourceFiles  = files.ToArray(),
                Git          = gitData
            };

            var fileData = JsonConvert.SerializeObject(data);
            var uploaded = Upload(@"https://coveralls.io/api/v1/jobs", fileData);

            if (!uploaded)
            {
                Console.Error.WriteLine("Failed to upload to coveralls");
                Environment.Exit(1);
            }
        }
Ejemplo n.º 4
0
        public static void Main(string[] argv)
        {
            var args = new MainArgs(argv, exit: true, version: Assembly.GetEntryAssembly().GetName().Version);
            var repoToken = args.OptRepotoken;
            if (string.IsNullOrWhiteSpace(repoToken))
            {
                Console.Error.WriteLine("parameter repoToken is required.");
                Console.WriteLine(MainArgs.Usage);
                Environment.Exit(1);
            }

            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;
            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List<CoverageFile> files;
            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
                Dictionary<string,XDocument> documents = new DirectoryInfo(fileName).GetFiles().Where(f => f.Name.EndsWith(".xml")).ToDictionary(f=>f.Name, f=>XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new DynamicCodeCoverageParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--mprof") && args.OptMprof)
            {
                var fileName = args.OptInput;
                files = null;

                if (File.Exists(fileName)) 
                {
                    var document = XDocument.Load (fileName);

                    files = new MonoProfParser (new FileSystem (), pathProcessor).GenerateSourceFiles (document, args.OptUserelativepaths);
                }
                else if (Directory.Exists(fileName))
                {
                    Dictionary<string,XDocument> documents = new DirectoryInfo(fileName).GetFiles().Where(f => f.Name.EndsWith(".xml")).ToDictionary(f=>f.Name, f=>XDocument.Load(f.FullName));

					files = new MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
                }
                else
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
            }
            else
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new OpenCoverParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }

            GitData gitData = null;
            var commitId = args.IsProvided("--commitId") ? args.OptCommitid : string.Empty;
            if (commitId.IsNotNullOrWhitespace())
            {
                var committerName = args.OptCommitauthor ?? string.Empty;
                var comitterEmail = args.OptCommitemail ?? string.Empty;
                var commitMessage = args.OptCommitmessage ?? string.Empty;
                gitData = new GitData
                {
                    Head = new GitHead
                    {
                        Id = commitId,
                        AuthorName = committerName,
                        AuthorEmail = comitterEmail,
                        CommitterName = committerName,
                        ComitterEmail = comitterEmail,
                        Message = commitMessage
                    },
                    Branch = args.OptCommitbranch ?? string.Empty
                };
            }

            var serviceJobId = args.IsProvided("--jobId") ? args.OptJobid : "0";

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var data = new CoverallData
            {
                RepoToken = repoToken,
                ServiceJobId = serviceJobId,
                ServiceName = serviceName,
                SourceFiles = files.ToArray(),
                Git = gitData
            };

            var fileData = JsonConvert.SerializeObject(data);
            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploaded = Upload(@"https://coveralls.io/api/v1/jobs", fileData);
                if (!uploaded)
                {
                    Console.Error.WriteLine("Failed to upload to coveralls");
                    Environment.Exit(1);
                }
            }
        }
Ejemplo n.º 5
0
        public static void Main(string[] argv)
        {
            var args      = new MainArgs(argv, exit: true, version: Assembly.GetEntryAssembly().GetName().Version);
            var repoToken = args.OptRepotoken;

            if (string.IsNullOrWhiteSpace(repoToken))
            {
                Console.Error.WriteLine("parameter repoToken is required.");
                Console.WriteLine(MainArgs.Usage);
                Environment.Exit(1);
            }

            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;

            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List <CoverageFile> files;

            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
                Dictionary <string, XDocument> documents = new DirectoryInfo(fileName).GetFiles().Where(f => f.Name.EndsWith(".xml")).ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new DynamicCodeCoverageParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--mprof") && args.OptMprof)
            {
                var fileName = args.OptInput;
                files = null;

                if (File.Exists(fileName))
                {
                    var document = XDocument.Load(fileName);

                    files = new MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
                }
                else if (Directory.Exists(fileName))
                {
                    Dictionary <string, XDocument> documents = new DirectoryInfo(fileName).GetFiles().Where(f => f.Name.EndsWith(".xml")).ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                    files = new MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
                }
                else
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
            }
            else
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new OpenCoverParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }

            GitData gitData  = null;
            var     commitId = args.IsProvided("--commitId") ? args.OptCommitid : string.Empty;

            if (commitId.IsNotNullOrWhitespace())
            {
                var committerName = args.OptCommitauthor ?? string.Empty;
                var comitterEmail = args.OptCommitemail ?? string.Empty;
                var commitMessage = args.OptCommitmessage ?? string.Empty;
                gitData = new GitData
                {
                    Head = new GitHead
                    {
                        Id            = commitId,
                        AuthorName    = committerName,
                        AuthorEmail   = comitterEmail,
                        CommitterName = committerName,
                        ComitterEmail = comitterEmail,
                        Message       = commitMessage
                    },
                    Branch = args.OptCommitbranch ?? string.Empty
                };
            }

            var serviceJobId = args.IsProvided("--jobId") ? args.OptJobid : "0";

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var    data        = new CoverallData
            {
                RepoToken    = repoToken,
                ServiceJobId = serviceJobId,
                ServiceName  = serviceName,
                SourceFiles  = files.ToArray(),
                Git          = gitData
            };

            var fileData = JsonConvert.SerializeObject(data);

            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploaded = Upload(@"https://coveralls.io/api/v1/jobs", fileData);
                if (!uploaded)
                {
                    Console.Error.WriteLine("Failed to upload to coveralls");
                    Environment.Exit(1);
                }
            }
        }