private static string FindRunnerExe(ILogger logger)
        {
            string exeFileName = FileLocator.FindDefaultSonarRunnerExecutable();

            if (exeFileName == null)
            {
                logger.LogError(Resources.ERR_FailedToLocateSonarRunner, FileLocator.SonarRunnerFileName);
            }
            else
            {
                logger.LogMessage(Resources.DIAG_LocatedSonarRunner, exeFileName);
            }
            return(exeFileName);
        }
        /// <summary>
        /// Creates the sonar runner file structure required for the
        /// product "FileLocator" code to work and create a sonar-runner properties
        /// file containing the specified host url setting
        /// </summary>
        /// <returns>Returns the path of the runner bin directory</returns>
        private string CreateRunnerFilesInScope(EnvironmentVariableScope scope)
        {
            string runnerConfDir = TestUtils.EnsureTestSpecificFolder(this.TestContext, "conf");
            string runnerBinDir  = TestUtils.EnsureTestSpecificFolder(this.TestContext, "bin");

            // Create a sonar-runner.properties file
            string runnerExe = Path.Combine(runnerBinDir, "sonar-runner.bat");

            File.WriteAllText(runnerExe, "dummy content - only the existence of the file matters");
            string configFile = Path.Combine(runnerConfDir, ActualRunnerPropertiesFileName);

            File.WriteAllText(configFile, "# dummy properties file content");

            scope.SetPath(runnerBinDir);

            Assert.IsFalse(string.IsNullOrWhiteSpace(FileLocator.FindDefaultSonarRunnerExecutable()), "Test setup error: failed to locate the created runner executable file");

            return(configFile);
        }
예제 #3
0
        public void FileLoc_GetSonarRunner()
        {
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string runnerFile = Path.Combine(testDir, FileLocator.SonarRunnerFileName);

            File.WriteAllText(runnerFile, "dummy runner file");

            using (TestUtilities.EnvironmentVariableScope scope = new TestUtilities.EnvironmentVariableScope())
            {
                // 1. Not found on path
                scope.SetPath("c:\\");
                string actual = FileLocator.FindDefaultSonarRunnerExecutable();
                Assert.IsNull(actual, "Not expecting the file to be found");

                // 2. Found on path
                scope.SetPath("c:\\;" + testDir);
                actual = FileLocator.FindDefaultSonarRunnerExecutable();
                Assert.IsNotNull(actual, "Expecting the runner file to be found");
                Assert.AreEqual(runnerFile, actual, "Unexpected file name returned");
            }
        }