Esempio n. 1
0
 public ExternalToolProperties(string filePath)
 {
     using (var fileStream = new FileStream(filePath, FileMode.Open))
     {
         _properties = new JavaProperties(PropertiesConstants.DEFAULTS);
         _properties.Load(fileStream);
     }
 }
Esempio n. 2
0
 public T Deserialize <T>(Stream stream)
 {
     try {
         JavaProperties props = new JavaProperties();
         props.Load(stream);
         return((T)DeserializeFields(emptyPrefix, props, typeof(T)));
     } catch (IOException e) {
         throw new TeseReadException(e);
     }
 }
 public void TestJavaPropertiesSaveAndLoad()
 {
     JavaProperties props = new JavaProperties();
     JavaProperties props1 = new JavaProperties();
     props.Add("a=", "b=\"''");
     props.Store("c:\\tempPropFileCsharp.txt", "comment1");
     props1.Load("c:\\tempPropFileCsharp.txt");
     File.Delete("c:\\tempPropFileCsharp.txt");
     Assert.AreEqual(props1["a="], props["a="]);
 }
Esempio n. 4
0
        public void TestJavaPropertiesSaveAndLoad()
        {
            JavaProperties props  = new JavaProperties();
            JavaProperties props1 = new JavaProperties();

            props.Add("a=", "b=\"''");
            props.Store("c:\\tempPropFileCsharp.txt", "comment1");
            props1.Load("c:\\tempPropFileCsharp.txt");
            File.Delete("c:\\tempPropFileCsharp.txt");
            Assert.AreEqual(props1["a="], props["a="]);
        }
        public void PropertiesWriter_WorkdirPerModuleExplicitlySet()
        {
            // Tests that .sonar.working.directory is explicityl set per module

            // Arrange
            string projectBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_AnalysisSettingsWritten");
            string productProject = CreateEmptyFile(projectBaseDir, "MyProduct.csproj");

            string        productFile  = CreateEmptyFile(projectBaseDir, "File.cs");
            List <string> productFiles = new List <string>
            {
                productFile
            };
            string productFileListFilePath = Path.Combine(projectBaseDir, "productManagedFiles.txt");

            string      projectKey = "7B3B7244-5031-4D74-9BBD-3316E6B5E7D5";
            ProjectInfo product    = CreateProjectInfo("AnalysisSettingsTest.proj", projectKey, productProject, false, productFiles, productFileListFilePath, null, "language", "UTF-8");

            List <ProjectInfo> projects = new List <ProjectInfo>
            {
                product
            };

            AnalysisConfig config = new AnalysisConfig()
            {
                SonarOutputDir = @"C:\my_folder"
            };

            // Act
            PropertiesWriter writer = new PropertiesWriter(config);

            writer.WriteSettingsForProject(product, new string[] { productFile }, null);
            writer.WriteSonarProjectInfo("dummy basedir", new List <string>());
            string s = writer.Flush();

            var props = new JavaProperties();

            props.Load(GenerateStreamFromString(s));
            string key = projectKey + "." + SonarProperties.WorkingDirectory;

            Assert.IsTrue(props.ContainsKey(key));
        }
        public void PropertiesWriter_WorkdirPerModuleExplicitlySet()
        {
            // Tests that .sonar.working.directory is explicitly set per module

            // Arrange
            var projectBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "PropertiesWriterTest_AnalysisSettingsWritten");
            var productProject = CreateEmptyFile(projectBaseDir, "MyProduct.csproj");

            var productFile  = CreateEmptyFile(projectBaseDir, "File.cs");
            var productFiles = new List <FileInfo>
            {
                productFile
            };
            var productFileListFilePath = Path.Combine(projectBaseDir, "productManagedFiles.txt");

            var projectKey = "7B3B7244-5031-4D74-9BBD-3316E6B5E7D5";
            var product    = new ProjectData(CreateProjectInfo("AnalysisSettingsTest.proj", projectKey, productProject, false, productFiles, productFileListFilePath, null, "language", "UTF-8"));

            product.ReferencedFiles.Add(productFile);

            var config = new AnalysisConfig()
            {
                SonarOutputDir = @"C:\my_folder"
            };

            // Act
            var writer = new PropertiesWriter(config, new TestLogger());

            writer.WriteSettingsForProject(product);
            writer.WriteSonarProjectInfo(new DirectoryInfo("dummy basedir"));
            var s = writer.Flush();

            var props = new JavaProperties();

            props.Load(GenerateStreamFromString(s));
            var key = projectKey + "." + SonarProperties.WorkingDirectory;

#pragma warning disable DictionaryShouldContainKey // Simplify Assertion
            props.ContainsKey(key).Should().BeTrue();
#pragma warning restore DictionaryShouldContainKey // Simplify Assertion
        }
        public void LoadSettings()
        {
            FileStream stream = new FileStream(pathSettings, FileMode.Open);

            try
            {
                JavaProperties settings = new JavaProperties();
                settings.Load(stream);
                pathSongs   = settings.GetProperty("pathSongs");
                pathReplays = settings.GetProperty("pathReplays");
                pathOsuDB   = settings.GetProperty("pathOsuDB");
                Console.WriteLine(pathOsuDB);
                osuDbP = new OsuDbAPI.OsuDbFile(pathOsuDB);
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error parsing settings:\n" + exp.ToString());
            }
            finally
            {
                stream.Close();
            }
        }
Esempio n. 8
0
        public PropertiesFileConfigurationSource(PropertiesFileConfigurationSourceConfig config)
            : base(config)
        {
            _properties = new JavaProperties();

            try
            {
                using (Stream @is = new FileStream(config.FileName, FileMode.Open))
                {
                    if (@is == null)
                    {
                        Logger.Warn("file not found: {0}", config.FileName);
                        return;
                    }

                    _properties.Load(@is, new UTF8Encoding(false));
                }
            }
            catch (Exception e)
            {
                Logger.Warn(e, "failed to load properties file: " + config.FileName);
            }
        }
Esempio n. 9
0
 public void Load(FileStream fileStream)
 {
     _properties.Clear();
     _properties.Load(fileStream);
 }
Esempio n. 10
0
 public ExternalToolProperties(FileStream fileStream)
 {
     _properties = new JavaProperties(PropertiesConstants.DEFAULTS);
     _properties.Load(fileStream);
 }
        static void Main(string[] args)
        {
            try
            {
                if (args == null || args.Length == 0)
                {
                    Console.Out.WriteLine("Usage: HpToolsAborter paramfile");
                    return;
                }

                if (!File.Exists(args[0]))
                {
                    Console.Out.WriteLine("File {0} is missing", args[0]);
                    return;
                }

                string paramfile;

                using (FileStream fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        paramfile = sr.ReadToEnd();
                    }
                }

                Console.Out.WriteLine("============================================================================");
                Console.Out.WriteLine("Aborting testing tool related processes");

                JavaProperties _ciParams = new JavaProperties();

                _ciParams.Load(args[0]);
                string timeout = _ciParams["timeout"];

                if (!string.IsNullOrEmpty(timeout))
                {
                    int timeoutInSeconds = Int32.Parse(timeout);
                    System.Threading.Thread.Sleep(timeoutInSeconds * 1000);
                }

                string runType = _ciParams["runType"];

                if (string.IsNullOrEmpty(runType))
                {
                    Console.Out.WriteLine("Unable to find runType in " + args[0]);
                    return;
                }

                if (runType == "FileSystem")
                {
                    KillQtpAutomationProcess();
                    KillLoadRunnerAutomationProcess();
                }

                if (runType == "Alm")
                {
                    string almRunMode = _ciParams["almRunMode"];
                    if (almRunMode == "RUN_LOCAL")
                    {
                        KillQtpAutomationFromAlm();
                        KillServiceTestFromAlm();
                    }
                    else if (almRunMode == "RUN_REMOTE")
                    {
                        Console.Out.WriteLine(string.Format("Stopping a test in a remote machine is not supported. Test in {0} should be stopped manually", _ciParams["almRunHost"]));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(string.Format("Error in HpToolsAborter: {0} ", ex.Message));
            }
        }
        bool IsInstalled(AndroidToolchainComponent component, string path, out bool missing)
        {
            missing = true;
            if (!Directory.Exists(path))
            {
                Log.DebugLine($"Component '{component.Name}' directory does not exist: {path}");
                return(false);
            }

            // This is just a cursory check, we might want to check versions
            string propsFile = Path.Combine(path, "source.properties");

            if (!File.Exists(propsFile))
            {
                Log.DebugLine($"Component '{component.Name}' properties file does not exist: {propsFile}");
                return(false);
            }

            missing = false;
            if ((RefreshSdk && !IsNdk(component)) || (RefreshNdk && IsNdk(component)))
            {
                Log.DebugLine($"A reinstall has been requested for component '{component.Name}'");
                return(false);
            }

            if (String.IsNullOrEmpty(component.PkgRevision))
            {
                Log.DebugLine($"Component '{component.Name}' does not specify required Pkg.Revision, assuming it's valid");
                return(true);
            }

            Log.DebugLine($"Component '{component.Name}' requires Pkg.Revision to be '{component.PkgRevision}', verifying");
            var props = new JavaProperties();

            try {
                using (var fs = File.OpenRead(propsFile)) {
                    props.Load(fs);
                }
            } catch (Exception ex) {
                Log.DebugLine($"Failed to read '{component.Name}' source.properties. Assuming invalid version, component will be reinstalled.");
                Log.DebugLine(ex.ToString());
                return(false);
            }

            string pkgRevision = props.GetProperty("Pkg.Revision", String.Empty);

            if (String.IsNullOrEmpty(pkgRevision))
            {
                Log.DebugLine($"Component '{component.Name}' does not have Pkg.Revision in its source.properties file, it will be reinstalled.");
                return(false);
            }

            if (!ParseVersion(pkgRevision, out Version pkgVer))
            {
                Log.DebugLine($"Failed to parse a valid version from Pkg.Revision ({pkgRevision}) for component '{component.Name}'. Component will be reinstalled.");
                return(false);
            }

            if (!ParseVersion(component.PkgRevision, out Version expectedPkgVer))
            {
                throw new InvalidOperationException($"Invalid expected package version for component '{component.Name}': {component.PkgRevision}");
            }

            bool equal = pkgVer == expectedPkgVer;

            if (!equal)
            {
                Log.DebugLine($"Installed version of '{component.Name}' ({pkgVer}) is different than the required one ({expectedPkgVer})");
            }

            return(equal);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            try
            {
                if (args == null || args.Length == 0)
                {
                    ShowHelp();
                    return;
                }

                if (args[0] == "-v" || args[0] == "-version" || args[0] == "/v")
                {
                    Console.Out.WriteLine(Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Environment.Exit(0);
                    return;
                }

                if (!File.Exists(args[0]))
                {
                    Console.Out.WriteLine("File '{0}' is missing", args[0]);
                    Environment.Exit(1);
                    return;
                }

                string paramfile;

                using (FileStream fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        paramfile = sr.ReadToEnd();
                    }
                }

                Console.Out.WriteLine("============================================================================");
                Console.Out.WriteLine("Aborting testing tool related processes");

                JavaProperties _ciParams = new JavaProperties();

                _ciParams.Load(args[0]);

                string runType = _ciParams["runType"];

                if (string.IsNullOrEmpty(runType))
                {
                    Console.Out.WriteLine("Unable to find runType in " + args[0]);
                    return;
                }

                if (runType == "FileSystem")
                {
                    KillQtpAutomationProcess();
                    KillLoadRunnerAutomationProcess();
                    KillParallelRunnerAutomationProcesses();
                }

                if (runType == "Alm")
                {
                    string almRunMode = _ciParams["almRunMode"];
                    if (almRunMode == "RUN_LOCAL")
                    {
                        KillQtpAutomationFromAlm();
                        KillServiceTestFromAlm();
                    }
                    else if (almRunMode == "RUN_REMOTE")
                    {
                        Console.Out.WriteLine(string.Format("Stopping a test in a remote machine is not supported. Test in {0} should be stopped manually", _ciParams["almRunHost"]));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(string.Format("Error in HpToolsAborter: {0} ", ex.Message));
            }
        }
        static void Main(string[] args)
        {
            try
            {
                if (args == null)
                {
                    Console.Out.WriteLine("Usage: HpToolsAborter paramfile");
                    return;
                }

                if (!File.Exists(args[0]))
                {
                    Console.Out.WriteLine("File {0} is missing", args[0]);
                    return;
                }

                string paramfile;

                using (FileStream fs = File.Open(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        paramfile = sr.ReadToEnd();
                    }
                }

                Console.Out.WriteLine("============================================================================");
                Console.Out.WriteLine("Aborting testing tool related processes!");

               JavaProperties _ciParams = new JavaProperties();

                _ciParams.Load(args[0]);

               string runType = _ciParams["runType"];

                if (string.IsNullOrEmpty(runType))
                {
                    Console.Out.WriteLine("Unable to find runType in " + args[0]);
                    return;
                }

                if (runType=="FileSystem")
                {
                    KillQtpAutomationProcess();
                    KillLoadRunnerAutomationProcess();
                }

                if (runType=="Alm")
                {
                     string almRunMode = _ciParams["almRunMode"];
                    if (almRunMode=="RUN_LOCAL")
                    {
                        Console.Out.WriteLine("begin to kill processed (Alm)" );
                        KillQtpAutomationFromAlm();
                        KillServiceTestFromAlm();
                    }
                    else if (almRunMode == "RUN_REMOTE")
                    {
                        Console.Out.WriteLine(string.Format("Stopping a test in a remote machine is not supported. Test in {0} should be stopped manually",_ciParams["almRunHost"]));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(string.Format("Error in HpToolsAborter: {0} ",ex.Message));
            }
        }