private static string TryResolveRunnerPropertiesPath(string propertiesPath, ILogger logger)
        {
            string resolvedPath;

            if (string.IsNullOrEmpty(propertiesPath))
            {
                logger.LogMessage(Resources.DIAG_LocatingRunnerProperties);
                resolvedPath = FileLocator.FindDefaultSonarRunnerProperties();

                if (string.IsNullOrWhiteSpace(resolvedPath))
                {
                    logger.LogError(Resources.ERROR_FailedToLocateRunnerProperties);
                }
                else
                {
                    logger.LogMessage(Resources.DIAG_LocatedRunnerProperties, resolvedPath);
                }
            }
            else
            {
                if (File.Exists(propertiesPath))
                {
                    resolvedPath = propertiesPath;
                }
                else
                {
                    logger.LogError(Resources.ERROR_InvalidRunnerPropertiesLocationSupplied, propertiesPath);
                    resolvedPath = null;
                }
            }

            return(resolvedPath);
        }
        /// <summary>
        /// Gets the URL from the sonar-runner.properties file. Throws if the
        /// properties file cannot be located.
        /// </summary>
        private static string GetUrlFromPropertiesFile()
        {
            var sonarRunnerProperties = FileLocator.FindDefaultSonarRunnerProperties();

            if (sonarRunnerProperties == null)
            {
                throw new ArgumentException(Resources.ERROR_CouldNotFindSonarRunnerProperties);
            }

            var propertiesProvider = new FilePropertiesProvider(sonarRunnerProperties);
            var server             = propertiesProvider.GetProperty(SonarProperties.HostUrl);

            Debug.Assert(!string.IsNullOrWhiteSpace(server), "Not expecting the host url property in the sonar-runner.properties file to be null/empty");

            return(server);
        }
Ejemplo n.º 3
0
        public void FileLoc_GetSonarRunnerProperties()
        {
            // 0. Set up
            string runnerRootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string binDir        = TestUtils.EnsureTestSpecificFolder(this.TestContext, "bin");
            string configDir     = TestUtils.EnsureTestSpecificFolder(this.TestContext, "conf");

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

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

            string configFile = Path.Combine(configDir, "sonar-runner.properties");

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

            using (TestUtilities.EnvironmentVariableScope scope = new TestUtilities.EnvironmentVariableScope())
            {
                // 1. Runner not found on path -> nothing
                scope.SetPath("c:\\");
                string actual = FileLocator.FindDefaultSonarRunnerProperties();
                Assert.IsNull(actual, "Not expecting the runner properties file to be found");


                // 2. Runner found on path but no properties file -> not found
                scope.SetPath("c:\\;" + binDir);
                File.Delete(configFile);

                using (new AssertIgnoreScope())
                {
                    actual = FileLocator.FindDefaultSonarRunnerProperties();
                }
                Assert.IsNull(actual, "Not expecting the runner properties file to be found");


                // 3. Runner found on path and config file exists in expected relative location -> found

                // Create the properties file in the expected location
                configFile = Path.Combine(configDir, "sonar-runner.properties");
                File.WriteAllText(configFile, "dummy runner properties file");

                actual = FileLocator.FindDefaultSonarRunnerProperties();
                Assert.IsNotNull(actual, "Expecting the runner properties file to be found");
                Assert.AreEqual(configFile, actual, "Unexpected file name returned");
            }
        }