示例#1
0
        public void AddEnvironment(ChutzpahSettingsFileEnvironment environment)
        {
            environment.Path = ProcessEnvironmentPath(environment.Path);

            if (!environmentMap.ContainsKey(environment.Path))
            {
                environmentMap[environment.Path] = environment;
            }
        }
        public void AddEnvironment(ChutzpahSettingsFileEnvironment environment)
        {
            environment.Path = ProcessEnvironmentPath(environment.Path);

            if (!environmentMap.ContainsKey(environment.Path))
            {
                environmentMap[environment.Path] = environment;
            }
        }
        public void Will_normalize_slashes_and_casing()
        {
            var environment = new ChutzpahSettingsFileEnvironment("path");
            environment.Path = @"C:/Some/path";
            environment.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty("name1", "val1"));
            var environmentsWrapper = new ChutzpahSettingsFileEnvironments(new[] { environment });

            var matched = environmentsWrapper.GetSettingsFileEnvironment(@"c:\some\path\chutzpah.json");

            Assert.Equal(environment, matched);
        }
        public void Will_match_environment_given_chutzpah_json_path()
        {
            var environment = new ChutzpahSettingsFileEnvironment("path");
            environment.Path = @"C:\some\path";
            environment.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty("name1", "val1"));
            var environmentsWrapper = new ChutzpahSettingsFileEnvironments(new[] { environment });

            var matched = environmentsWrapper.GetSettingsFileEnvironment(@"c:\some\path\chutzpah.json");

            Assert.Equal(environment, matched);
        }
        public void Will_choose_longest_matching_path()
        {
            var environment1 = new ChutzpahSettingsFileEnvironment("path");
            environment1.Path = @"C:\some\";
            environment1.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty("name1", "val1"));
            var environment2 = new ChutzpahSettingsFileEnvironment("path");
            environment2.Path = @"C:\some\path\";
            environment2.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty( "name2", "val2" ));
            var environmentsWrapper = new ChutzpahSettingsFileEnvironments(new[] { environment1, environment2 });

            var matched = environmentsWrapper.GetSettingsFileEnvironment(@"c:\some\path\chutzpah.json");

            Assert.Equal(environment2, matched);
        }
示例#6
0
        private void AddSettingsFileEnvironment(string environmentStr)
        {   
            if (string.IsNullOrEmpty(environmentStr))
            {
                throw new ArgumentException(
                    "missing argument for /settingsFileEnvironment.  Expecting the settings file path and at least one property (e.g. settingsFilePath;prop1=val1;prop2=val2)");
            }

            var envParts = environmentStr.Split(new []{";"},StringSplitOptions.RemoveEmptyEntries);
            if(envParts.Length <2)
            {  
                throw new ArgumentException(
                    "invalid argument for /settingsFileEnvironment.  Expecting the settings file path and at least one property (e.g. settingsFilePath;prop1=val1;prop2=val2)");
            }

            var path = envParts[0];
            var environment = new ChutzpahSettingsFileEnvironment(path);
            for (var i = 1; i < envParts.Length; i++)
            {
                var propParts = envParts[i].Split('=');
                var name = propParts[0];
                var value = propParts.Length > 1 ? propParts[1] : "";
                environment.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty(name, value));
            }

            SettingsFileEnvironments.AddEnvironment(environment);
        }
        private ChutzpahTestSettingsFile FindSettingsFile(string directory, ChutzpahSettingsFileEnvironment environment)
        {
            if (string.IsNullOrEmpty(directory)) return ChutzpahTestSettingsFile.Default;

            directory = directory.TrimEnd('/', '\\');

            ChutzpahTestSettingsFile settings;
            if (!ChutzpahSettingsFileCache.TryGetValue(directory, out settings))
            {
                var testSettingsFilePath = fileProbe.FindTestSettingsFile(directory);
                if (string.IsNullOrEmpty(testSettingsFilePath))
                {
                    ChutzpahTracer.TraceInformation("Chutzpah.json file not found given starting directoy {0}", directory);
                    settings = ChutzpahTestSettingsFile.Default;
                }
                else if (!ChutzpahSettingsFileCache.TryGetValue(Path.GetDirectoryName(testSettingsFilePath), out settings))
                {
                    ChutzpahTracer.TraceInformation("Chutzpah.json file found at {0} given starting directoy {1}", testSettingsFilePath, directory);
                    settings = serializer.DeserializeFromFile<ChutzpahTestSettingsFile>(testSettingsFilePath);

                    if (settings == null)
                    {
                        settings = ChutzpahTestSettingsFile.Default;
                    }
                    else
                    {
                        settings.IsDefaultSettings = false;
                    }

                    settings.SettingsFileDirectory = Path.GetDirectoryName(testSettingsFilePath);

                    var chutzpahVariables = BuildChutzpahReplacementVariables(testSettingsFilePath, environment, settings);

                    ResolveTestHarnessDirectory(settings, chutzpahVariables);

                    ResolveAMDBaseUrl(settings, chutzpahVariables);

                    ResolveBatchCompileConfiguration(settings, chutzpahVariables);

                    ProcessPathSettings(settings, chutzpahVariables);

                    ProcessInheritance(environment, settings, chutzpahVariables);

                    // Add a mapping in the cache for the directory that contains the test settings file
                    ChutzpahSettingsFileCache.TryAdd(settings.SettingsFileDirectory, settings);
                }

                // Add mapping in the cache for the original directory tried to skip needing to traverse the tree again
                ChutzpahSettingsFileCache.TryAdd(directory, settings);
            }



            return settings;
        }
        private IDictionary<string, string> BuildChutzpahReplacementVariables(string settingsFilePath, ChutzpahSettingsFileEnvironment environment, ChutzpahTestSettingsFile settings)
        {
            IDictionary<string, string> chutzpahVariables = new Dictionary<string, string>();

            var clrDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
            var msbuildExe = Path.Combine(clrDir, "msbuild.exe");
            var powershellExe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"windowspowershell\v1.0\powershell.exe");


            AddChutzpahVariable(chutzpahVariables, "chutzpahsettingsdir", settings.SettingsFileDirectory);

            AddChutzpahVariable(chutzpahVariables, "clrdir", clrDir);
            AddChutzpahVariable(chutzpahVariables, "msbuildexe", msbuildExe);
            AddChutzpahVariable(chutzpahVariables, "powershellexe", powershellExe);

            // This is not needed but it is a nice alias
            AddChutzpahVariable(chutzpahVariables, "cmdexe", Environment.ExpandEnvironmentVariables("%comspec%"));

            if (environment != null)
            {
                // See if we have a settingsfileenvironment set and if so add its properties as chutzpah settings file variables
                var props = environment.Properties;
                foreach (var prop in props)
                {
                    AddChutzpahVariable(chutzpahVariables, prop.Name, prop.Value);
                }
            }

            return chutzpahVariables;
        }
        private void ProcessInheritance(ChutzpahSettingsFileEnvironment environment, ChutzpahTestSettingsFile settings, IDictionary<string, string> chutzpahVariables)
        {
            if (settings.InheritFromParent || !string.IsNullOrEmpty(settings.InheritFromPath))
            {

                if (string.IsNullOrEmpty(settings.InheritFromPath))
                {
                    ChutzpahTracer.TraceInformation("Searching for parent Chutzpah.json to inherit from");
                    settings.InheritFromPath = Path.GetDirectoryName(settings.SettingsFileDirectory);
                }
                else
                {
                    ChutzpahTracer.TraceInformation("Searching for Chutzpah.json to inherit from at {0}", settings.InheritFromPath);

                    string settingsToInherit = ExpandVariable(chutzpahVariables, settings.InheritFromPath);
                    if (settingsToInherit.EndsWith(Constants.SettingsFileName, StringComparison.OrdinalIgnoreCase))
                    {
                        settingsToInherit = Path.GetDirectoryName(settingsToInherit);
                    }

                    settingsToInherit = ResolveFolderPath(settings, settingsToInherit);

                    settings.InheritFromPath = settingsToInherit;
                }

                var parentSettingsFile = FindSettingsFile(settings.InheritFromPath, environment);

                if (!parentSettingsFile.IsDefaultSettings)
                {

                    ChutzpahTracer.TraceInformation("Found parent Chutzpah.json in directory {0}", parentSettingsFile.SettingsFileDirectory);
                    settings.InheritFrom(parentSettingsFile);
                }
                else
                {
                    ChutzpahTracer.TraceInformation("Could not find a parent Chutzpah.json");
                }

            }
        }
        private void UpdateChutzpahEnvironmentForProject(string projectPath)
        {
            var buildProject = ProjectCollection.GlobalProjectCollection.LoadedProjects
                                                .FirstOrDefault(x => x.FullPath.Equals(projectPath, StringComparison.OrdinalIgnoreCase));

            var chutzpahEnvProps = new Collection<ChutzpahSettingsFileEnvironmentProperty>();

            if (buildProject != null)
            {
                var dirPath = Path.GetDirectoryName(projectPath);
                foreach (var prop in ChutzpahMsBuildProps.GetProps())
                {
                    chutzpahEnvProps.Add(new ChutzpahSettingsFileEnvironmentProperty(prop, buildProject.GetPropertyValue(prop)));
                }

                lock (sync)
                {
                    var envProps = settingsMapper.Settings.ChutzpahSettingsFileEnvironments
                                                          .FirstOrDefault(x => x.Path.TrimEnd('/', '\\').Equals(dirPath, StringComparison.OrdinalIgnoreCase));
                    if (envProps == null)
                    {
                        envProps = new ChutzpahSettingsFileEnvironment(dirPath);

                        settingsMapper.Settings.ChutzpahSettingsFileEnvironments.Add(envProps);

                    }

                    envProps.Properties = chutzpahEnvProps;
                }
            }
        }
        private void InitializeSettingsFileEnvironments()
        {
            var newEnvironments = new ChutzpahSettingsFileEnvironments();
            var buildProjects = ProjectCollection.GlobalProjectCollection.LoadedProjects
                                        .Where(x => !x.FullPath.Equals(".user", StringComparison.OrdinalIgnoreCase));

            foreach (var buildProject in buildProjects)
            {
                var dirPath = buildProject.DirectoryPath;
                var environment = new ChutzpahSettingsFileEnvironment(dirPath);
                foreach (var prop in ChutzpahMsBuildProps.GetProps())
                {
                    environment.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty(prop, buildProject.GetPropertyValue(prop)));
                }

                newEnvironments.AddEnvironment(environment);
            }

            settingsEnvironments = newEnvironments;
        }