/* for test purposes */ public static bool ExecuteJavaRunner(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName) { Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName); Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName); IgnoreSonarRunnerHome(logger); IEnumerable<string> allCmdLineArgs = GetAllCmdLineArgs(propertiesFileName, userCmdLineArguments, config); IDictionary<string, string> envVarsDictionary = GetAdditionalEnvVariables(logger); Debug.Assert(envVarsDictionary != null); logger.LogInfo(Resources.MSG_CallingSonarRunner); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(exeFileName, logger) { CmdLineArgs = allCmdLineArgs, WorkingDirectory = Path.GetDirectoryName(exeFileName), EnvironmentVariables = envVarsDictionary }; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); success = success && !runner.ErrorsLogged; if (success) { logger.LogInfo(Resources.MSG_SonarRunnerCompleted); } else { logger.LogError(Resources.ERR_SonarRunnerExecutionFailed); } return success; }
public void V0_9Upgrade_CalledFromV0_9() { // Arrange TestLogger logger = new TestLogger(); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(typeof(V0_9UpgradeMessageExe.Program).Assembly.Location, logger) { WorkingDirectory = this.TestContext.DeploymentDirectory }; // Act ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); // Assert Assert.IsFalse(success); logger.AssertSingleErrorExists(SonarQube.V0_9UpgradeMessageExe.Resources.UpgradeMessage); logger.AssertErrorsLogged(1); }
/* for test purposes */ public static bool ExecuteJavaRunner(AnalysisConfig config, IEnumerable<string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName) { Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName); Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName); IgnoreSonarScannerHome(logger); IEnumerable<string> allCmdLineArgs = GetAllCmdLineArgs(propertiesFileName, userCmdLineArguments, config); IDictionary<string, string> envVarsDictionary = GetAdditionalEnvVariables(logger); Debug.Assert(envVarsDictionary != null); logger.LogInfo(Resources.MSG_SonarScannerCalling); Debug.Assert(!String.IsNullOrWhiteSpace(config.SonarRunnerWorkingDirectory), "The working dir should have been set in the analysis config"); Debug.Assert(Directory.Exists(config.SonarRunnerWorkingDirectory), "The working dir should exist"); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(exeFileName, logger) { CmdLineArgs = allCmdLineArgs, WorkingDirectory = config.SonarRunnerWorkingDirectory, EnvironmentVariables = envVarsDictionary }; ProcessRunner runner = new ProcessRunner(); // SONARMSBRU-202 Note that the Sonar Scanner may write warnings to stderr so // we should only rely on the exit code when deciding if it ran successfully bool success = runner.Execute(runnerArgs); if (success) { logger.LogInfo(Resources.MSG_SonarScannerCompleted); } else { logger.LogError(Resources.ERR_SonarScannerExecutionFailed); } return success; }
public bool CompileJar(string jarContentDirectory, string manifestFilePath, string fullJarPath, ILogger logger) { if (string.IsNullOrWhiteSpace(fullJarPath)) { throw new ArgumentNullException("fullJarPath"); } if (string.IsNullOrWhiteSpace(jarContentDirectory)) { throw new ArgumentNullException("jarLayoutDirectory"); } if (logger == null) { throw new ArgumentNullException("logger"); } string jarExePath = TryFindJavaExe(JAR_BUILDER_EXE); Debug.Assert(!string.IsNullOrEmpty(jarExePath), "Failed to locate the jar exe, although the JDK appears to be installed"); // jar cvfm test.jar MANIFEST.MF myorg\*.class* resources\*.* string[] cmdLineArgs = new string[] { "cvfm", ProcessRunnerArguments.GetQuotedArg(fullJarPath), ProcessRunnerArguments.GetQuotedArg(manifestFilePath), "." // directory - will be processed recursively }; ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(jarExePath, logger) { CmdLineArgs = cmdLineArgs, WorkingDirectory = jarContentDirectory }; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); return success; }
/// <summary> /// Launches the build wrapper and asks it to attach to the current process. /// Returns whether the build wrapper was succesfully attached or not. /// </summary> private bool Attach(string outputDirectory) { string currentPID = GetProcessId(); // Choose either the 32- or 64-bit version of the monitor to match the current process string exeName = (Environment.Is64BitOperatingSystem ? BuildWrapperExeName64 : BuildWrapperExeName32); string monitorExeFilePath = Path.Combine(this.BinDirectoryPath, exeName); ProcessRunnerArguments args = new ProcessRunnerArguments(monitorExeFilePath, new MSBuildLoggerAdapter(this.Log)); args.TimeoutInMilliseconds = this.buildWrapperTimeoutInMs; // See https://jira.sonarsource.com/browse/CPP-1469 for the specification of the arguments to pass to the Cpp plugin // --msbuild - task < PID > < OUTPUT_DIR > args.CmdLineArgs = new string[] { "--msbuild-task", currentPID, outputDirectory }; this.Log.LogMessage(MessageImportance.Low, Resources.BuildWrapper_WaitingForAttach, currentPID); ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(args); if (success) { this.Log.LogMessage(MessageImportance.Low, Resources.BuildWrapper_AttachedSuccessfully); } else { this.Log.LogError(Resources.BuildWrapper_FailedToAttach); } return success; }
private static int PostProcess(IBootstrapperSettings settings, ILogger logger) { ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(settings.PostProcessorFilePath, logger) { CmdLineArgs = settings.ChildCmdLineArgs, WorkingDirectory = settings.TempDirectory }; ProcessRunner runner = new ProcessRunner(); runner.Execute(runnerArgs); return runner.ExitCode; }
private static int PreProcess(IBuildAgentUpdater updater, IBootstrapperSettings settings, ILogger logger) { string downloadBinPath = settings.DownloadDirectory; logger.LogInfo(Resources.MSG_PreparingDirectories); if (!Utilities.TryEnsureEmptyDirectories(logger, settings.TempDirectory, downloadBinPath)) { return ErrorCode; } string server = settings.SonarQubeUrl; Debug.Assert(!string.IsNullOrWhiteSpace(server), "Not expecting the server url to be null/empty"); logger.LogDebug(Resources.MSG_ServerUrl, server); logger.LogInfo(Resources.MSG_CheckingForUpdates); if (!updater.TryUpdate(server, downloadBinPath, logger)) { logger.LogError(Resources.ERROR_FailedToUpdateRunnerBinaries); return ErrorCode; } if (!updater.CheckBootstrapperApiVersion(settings.SupportedBootstrapperVersionsFilePath, settings.BootstrapperVersion)) { logger.LogError(Resources.ERROR_VersionMismatch); return ErrorCode; } var preprocessorFilePath = settings.PreProcessorFilePath; ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(preprocessorFilePath, logger) { CmdLineArgs = settings.ChildCmdLineArgs, WorkingDirectory = settings.TempDirectory, }; ProcessRunner runner = new ProcessRunner(); runner.Execute(runnerArgs); return runner.ExitCode; }
private static int PostProcess(IBootstrapperSettings settings, ILogger logger) { if (!File.Exists(settings.PostProcessorFilePath)) { logger.LogError(Resources.ERROR_PostProcessExeNotFound, settings.PostProcessorFilePath); return ErrorCode; } ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(settings.PostProcessorFilePath, logger) { CmdLineArgs = settings.ChildCmdLineArgs, WorkingDirectory = settings.TempDirectory }; ProcessRunner runner = new ProcessRunner(); runner.Execute(runnerArgs); return runner.ExitCode; }
public bool CompileSources(IEnumerable<string> args, ILogger logger) { if (args == null) { throw new ArgumentNullException("args"); } if (logger == null) { throw new ArgumentNullException("logger"); } string exePath = TryFindJavaExe(JAVA_COMPILER_EXE); Debug.Assert(!string.IsNullOrEmpty(exePath), "Failed to locate the Java compiler exe, although the JDK appears to be installed"); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(exePath, logger) { CmdLineArgs = args }; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); return success; }
// was internal public static bool ConvertBinaryToXml(string converterExeFilePath, string inputBinaryFilePath, string outputXmlFilePath, ILogger logger) { Debug.Assert(!string.IsNullOrEmpty(converterExeFilePath), "Expecting the conversion tool path to have been set"); Debug.Assert(File.Exists(converterExeFilePath), "Expecting the converter exe to exist: " + converterExeFilePath); Debug.Assert(Path.IsPathRooted(inputBinaryFilePath), "Expecting the input file name to be a full absolute path"); Debug.Assert(File.Exists(inputBinaryFilePath), "Expecting the input file to exist: " + inputBinaryFilePath); Debug.Assert(Path.IsPathRooted(outputXmlFilePath), "Expecting the output file name to be a full absolute path"); List<string> args = new List<string>(); args.Add("analyze"); args.Add(string.Format(System.Globalization.CultureInfo.InvariantCulture, @"/output:""{0}""", outputXmlFilePath)); args.Add(inputBinaryFilePath); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(converterExeFilePath, logger) { WorkingDirectory = Path.GetDirectoryName(outputXmlFilePath), CmdLineArgs = args, TimeoutInMilliseconds = ConversionTimeoutInMs }; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); if (success) { // Check the output file actually exists if (!File.Exists(outputXmlFilePath)) { logger.LogError(Resources.CONV_ERROR_OutputFileNotFound, outputXmlFilePath); success = false; } } else { logger.LogError(Resources.CONV_ERROR_ConversionToolFailed, inputBinaryFilePath); } return success; }
private string RunPluginInspector(string jarFilePath, string tempDir) { Debug.Assert(!string.IsNullOrEmpty(this.inspectorClassFilePath)); string reportFilePath = Path.Combine(tempDir, "report.xml"); IEnumerable<string> jarFiles = GetRuntimeDependencies(); // Construct the class path argument StringBuilder sb = new StringBuilder(); sb.AppendFormat("-cp \"{0}\"", Path.GetDirectoryName(this.inspectorClassFilePath)); foreach (string dependencyFilePath in jarFiles) { sb.AppendFormat(";{0}", dependencyFilePath); } IList<string> cmdLineArgs = new List<string>(); cmdLineArgs.Add(sb.ToString()); // options must preceed the name of the class to execute cmdLineArgs.Add(PluginInspectorFullClassName); cmdLineArgs.Add(jarFilePath); // parameter(s) to pass to the class cmdLineArgs.Add(reportFilePath); ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(GetJavaExePath(), logger); runnerArgs.CmdLineArgs = cmdLineArgs; ProcessRunner runner = new ProcessRunner(); bool success = runner.Execute(runnerArgs); Assert.IsTrue(success, "Test error: failed to execute the PluginInspector"); Assert.IsTrue(File.Exists(reportFilePath), "Test error: failed to create the PluginInspector report"); return reportFilePath; }