public override void Run(string[] args) { if (assertPreferences()) { var preferences = loadPreferences(); var config = new CodeGeneratorConfig(); config.Configure(preferences); fabl.Debug(config.ToString()); Type[] types = null; Dictionary <string, string> configurables = null; try { types = CodeGeneratorUtil.LoadTypesFromPlugins(preferences); configurables = CodeGeneratorUtil.GetConfigurables( CodeGeneratorUtil.GetUsed <ICodeGeneratorDataProvider>(types, config.dataProviders), CodeGeneratorUtil.GetUsed <ICodeGenerator>(types, config.codeGenerators), CodeGeneratorUtil.GetUsed <ICodeGenFilePostProcessor>(types, config.postProcessors) ); } catch (Exception ex) { printKeyStatus(config.defaultProperties.Keys.ToArray(), preferences); throw ex; } var requiredKeys = config.defaultProperties.Merge(configurables).Keys.ToArray(); printKeyStatus(requiredKeys, preferences); printPluginStatus(types, config); } }
public override void Run(string[] args) { var currentDir = Directory.GetCurrentDirectory(); var path = currentDir + Path.DirectorySeparatorChar + Preferences.PATH; if (args.isForce() || !File.Exists(path)) { var defaultConfig = new CodeGeneratorConfig(); var properties = new Properties(defaultConfig.defaultProperties); defaultConfig.Configure(properties); var propertiesString = defaultConfig.ToString(); File.WriteAllText(path, propertiesString); fabl.Info("Created " + path); fabl.Debug(propertiesString); new EditConfig().Run(args); } else { fabl.Warn(path + " already exists!"); fabl.Info("Use entitas new -f to overwrite the exiting file."); fabl.Info("Use entitas edit to open the exiting file."); } }
static void createNewConfig(bool force) { var currentDir = Directory.GetCurrentDirectory(); var path = currentDir + Path.DirectorySeparatorChar + Preferences.configPath; if (!File.Exists(path) || force) { var types = AppDomain.CurrentDomain.GetAllTypes(); var defaultConfig = new CodeGeneratorConfig( new Config(string.Empty), CodeGeneratorUtil.GetOrderedTypeNames <ICodeGeneratorDataProvider>(types).ToArray(), CodeGeneratorUtil.GetOrderedTypeNames <ICodeGenerator>(types).ToArray(), CodeGeneratorUtil.GetOrderedTypeNames <ICodeGenFilePostProcessor>(types).ToArray() ); var config = defaultConfig.ToString(); File.WriteAllText(path, config); _logger.Info("Created " + path); _logger.Debug(config); editConfig(); } else { _logger.Warn(path + " already exists!"); _logger.Info("Use entitas new -f to overwrite the exiting file."); _logger.Info("Use entitas edit to open the exiting file."); } }
void when_creating_config() { it["creates config from EntitasPreferencesConfig"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.generatedFolderPath.should_be("path/to/folder/"); config.pools.should_be(new [] { "Core", "Meta", "UI" }); }; it["gets default values when keys dont exist"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.generatedFolderPath.should_be("Assets/Generated/"); config.pools.should_be_empty(); }; it["sets values"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.generatedFolderPath = "new/path/"; config.pools = new [] { "Other1", "Other2" }; config.generatedFolderPath.should_be("new/path/"); config.pools.should_be(new [] { "Other1", "Other2" }); }; it["gets string"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.generatedFolderPath = "new/path/"; config.pools = new [] { "Other1", "Other2" }; config.ToString().should_be( "Entitas.Unity.CodeGenerator.GeneratedFolderPath = new/path/\n" + "Entitas.Unity.CodeGenerator.Pools = Other1,Other2\n"); }; it["gets string from empty config"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.ToString().should_be( "Entitas.Unity.CodeGenerator.GeneratedFolderPath = Assets/Generated/\n" + "Entitas.Unity.CodeGenerator.Pools = \n"); }; it["removes empty pools"] = () => { const string configString = "Entitas.Unity.CodeGenerator.Pools = ,,Core,,UI,,"; var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.pools.should_be(new [] { "Core", "UI" }); }; it["removes trailing comma in pools string"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.pools = new [] { "Meta", string.Empty }; config.ToString().should_be( "Entitas.Unity.CodeGenerator.GeneratedFolderPath = Assets/Generated/\n" + "Entitas.Unity.CodeGenerator.Pools = Meta\n" ); }; }
public override void Run(string[] args) { string text = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar.ToString() + "Entitas.properties"; if (ArgsExtension.isForce(args) || !File.Exists(text)) { CodeGeneratorConfig codeGeneratorConfig = new CodeGeneratorConfig(); Properties properties = new Properties(codeGeneratorConfig.defaultProperties); //codeGeneratorConfig.Configure(properties); string text2 = codeGeneratorConfig.ToString(); File.WriteAllText(text, text2); fabl.Info("Created " + text); fabl.Debug(text2); new EditConfig().Run(args); } else { fabl.Warn(text + " already exists!"); fabl.Info("Use entitas new -f to overwrite the exiting file."); fabl.Info("Use entitas edit to open the exiting file."); } }
void when_creating_config() { it["creates config from EntitasPreferencesConfig"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.targetDirectory.should_be("path/to/folder/"); config.contexts.should_be(new [] { "Core", "Meta", "UI" }); config.dataProviders.should_be(new [] { "DataProvider1", "DataProvider2", "DataProvider3" }); config.codeGenerators.should_be(new [] { "Generator1", "Generator2", "Generator3" }); config.postProcessors.should_be(new [] { "PostProcessor1", "PostProcessor2", "PostProcessor3" }); }; it["gets default values when keys dont exist"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty), new [] { "Data1, Data2" }, new [] { "Gen1, Gen2" }, new [] { "Post1, Post2" }); config.targetDirectory.should_be("Assets/Generated/"); config.contexts.should_be(new [] { "Game", "GameState", "Input" }); config.dataProviders.should_be(new [] { "Data1", "Data2" }); config.codeGenerators.should_be(new [] { "Gen1", "Gen2" }); config.postProcessors.should_be(new [] { "Post1", "Post2" }); }; it["sets values"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString), new string[0], new string[0], new string[0]); config.targetDirectory = "new/path/"; config.contexts = new [] { "Other1", "Other2" }; config.dataProviders = new [] { "Data4", "Data5" }; config.codeGenerators = new [] { "Generator4", "Generator5" }; config.postProcessors = new [] { "Post4", "Post5" }; config.targetDirectory.should_be("new/path/"); config.contexts.should_be(new [] { "Other1", "Other2" }); config.dataProviders.should_be(new [] { "Data4", "Data5" }); config.codeGenerators.should_be(new [] { "Generator4", "Generator5" }); config.postProcessors.should_be(new [] { "Post4", "Post5" }); }; it["gets string"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.targetDirectory = "new/path/"; config.contexts = new [] { "Other1", "Other2" }; config.dataProviders = new [] { "Data4", "Data5" }; config.codeGenerators = new [] { "Generator4", "Generator5" }; config.postProcessors = new [] { "Post4", "Post5" }; config.ToString().should_be( "Entitas.CodeGenerator.TargetDirectory = new/path/\n" + "Entitas.CodeGenerator.Contexts = Other1,Other2\n" + "Entitas.CodeGenerator.DataProviders = Data4,Data5\n" + "Entitas.CodeGenerator.CodeGenerators = Generator4,Generator5\n" + "Entitas.CodeGenerator.PostProcessors = Post4,Post5\n" ); }; it["gets string from empty config"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.ToString().should_be( "Entitas.CodeGenerator.TargetDirectory = Assets/Generated/\n" + "Entitas.CodeGenerator.Contexts = Game,GameState,Input\n" + "Entitas.CodeGenerator.DataProviders = \n" + "Entitas.CodeGenerator.CodeGenerators = \n" + "Entitas.CodeGenerator.PostProcessors = \n" ); }; it["removes empty contexts"] = () => { const string configString = "Entitas.CodeGenerator.Contexts = ,,Core,,UI,,"; var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.contexts.should_be(new [] { "Core", "UI" }); }; it["removes empty enabled code generators"] = () => { const string configString = "Entitas.CodeGenerator.CodeGenerators = ,,Gen1,,Gen2,,"; var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(configString)); config.codeGenerators.should_be(new [] { "Gen1", "Gen2" }); }; it["removes trailing comma in contexts string"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.contexts = new [] { "Meta", string.Empty }; config.ToString().should_be( "Entitas.CodeGenerator.TargetDirectory = Assets/Generated/\n" + "Entitas.CodeGenerator.Contexts = Meta\n" + "Entitas.CodeGenerator.DataProviders = \n" + "Entitas.CodeGenerator.CodeGenerators = \n" + "Entitas.CodeGenerator.PostProcessors = \n" ); }; it["removes trailing comma in enabled code generators string"] = () => { var config = new CodeGeneratorConfig(new EntitasPreferencesConfig(string.Empty)); config.codeGenerators = new [] { "Gen1", string.Empty }; config.ToString().should_be( "Entitas.CodeGenerator.TargetDirectory = Assets/Generated/\n" + "Entitas.CodeGenerator.Contexts = Game,GameState,Input\n" + "Entitas.CodeGenerator.DataProviders = \n" + "Entitas.CodeGenerator.CodeGenerators = Gen1\n" + "Entitas.CodeGenerator.PostProcessors = \n" ); }; }
void when_creating_config() { it["creates config from EntitasPreferencesConfig"] = () => { var config = new CodeGeneratorConfig(new Config(configString)); config.projectPath.should_be("path/to/project/"); config.searchPaths.should_be(new [] { "base1", "base/2/" }); config.assemblies.should_be(new [] { "game.dll", "kit.dll" }); config.plugins.should_be(new [] { "gen1.dll", "gen2.dll" }); config.dataProviders.should_be(new [] { "DataProvider1", "DataProvider2", "DataProvider3" }); config.codeGenerators.should_be(new [] { "Generator1", "Generator2", "Generator3" }); config.postProcessors.should_be(new [] { "PostProcessor1", "PostProcessor2", "PostProcessor3" }); config.targetDirectory.should_be("path/to/folder/"); config.contexts.should_be(new [] { "Core", "Meta", "UI" }); }; it["gets default values when keys dont exist"] = () => { var config = new CodeGeneratorConfig(new Config(string.Empty), new [] { "Data1, Data2" }, new [] { "Gen1, Gen2" }, new [] { "Post1, Post2" }); config.projectPath.should_be("Assembly-CSharp.csproj"); config.searchPaths.should_be(new [] { "Libraries/Entitas", "Libraries/Entitas/Editor", "/Applications/Unity/Unity.app/Contents/Managed", "/Applications/Unity/Unity.app/Contents/Mono/lib/mono/unity" }); config.assemblies.should_be(new [] { "Library/ScriptAssemblies/Assembly-CSharp.dll" }); config.plugins.should_be(new [] { "Entitas.CodeGeneration.Plugins", "Entitas.VisualDebugging.CodeGeneration.Plugins", "Entitas.Blueprints.CodeGeneration.Plugins" }); config.dataProviders.should_be(new [] { "Data1", "Data2" }); config.codeGenerators.should_be(new [] { "Gen1", "Gen2" }); config.postProcessors.should_be(new [] { "Post1", "Post2" }); config.targetDirectory.should_be("Assets/Generated"); config.contexts.should_be(new [] { "Game", "GameState", "Input" }); }; it["sets values"] = () => { var config = new CodeGeneratorConfig(new Config(configString), new string[0], new string[0], new string[0]); config.projectPath = "path/to/newProject/"; config.searchPaths = new [] { "newBase1", "newBase2" }; config.assemblies = new [] { "game.dll", "physics.dll" }; config.plugins = new [] { "myGen1.dll", "myGen2.dll" }; config.dataProviders = new [] { "Data4", "Data5" }; config.codeGenerators = new [] { "Generator4", "Generator5" }; config.postProcessors = new [] { "Post4", "Post5" }; config.targetDirectory = "new/path/"; config.contexts = new [] { "Other1", "Other2" }; config.projectPath.should_be("path/to/newProject/"); config.searchPaths.should_be(new [] { "newBase1", "newBase2" }); config.assemblies.should_be(new [] { "game.dll", "physics.dll" }); config.plugins.should_be(new [] { "myGen1.dll", "myGen2.dll" }); config.dataProviders.should_be(new [] { "Data4", "Data5" }); config.codeGenerators.should_be(new [] { "Generator4", "Generator5" }); config.postProcessors.should_be(new [] { "Post4", "Post5" }); config.targetDirectory.should_be("new/path/"); config.contexts.should_be(new [] { "Other1", "Other2" }); }; it["gets string"] = () => { var config = new CodeGeneratorConfig(new Config(configString)); config.projectPath = "path/to/newProject/"; config.searchPaths = new [] { "newBase1", "newBase2" }; config.assemblies = new [] { "game.dll", "physics.dll" }; config.plugins = new [] { "myGen1.dll", "myGen2.dll" }; config.dataProviders = new [] { "Data4", "Data5" }; config.codeGenerators = new [] { "Generator4", "Generator5" }; config.postProcessors = new [] { "Post4", "Post5" }; config.targetDirectory = "new/path/"; config.contexts = new [] { "Other1", "Other2" }; config.ToString().should_be( "Entitas.CodeGeneration.Project = path/to/newProject/\n" + "Entitas.CodeGeneration.SearchPaths = newBase1, newBase2\n" + "Entitas.CodeGeneration.Assemblies = game.dll, physics.dll\n" + "Entitas.CodeGeneration.Plugins = myGen1.dll, myGen2.dll\n" + "Entitas.CodeGeneration.DataProviders = Data4, Data5\n" + "Entitas.CodeGeneration.CodeGenerators = Generator4, Generator5\n" + "Entitas.CodeGeneration.PostProcessors = Post4, Post5\n" + "Entitas.CodeGeneration.TargetDirectory = new/path/\n" + "Entitas.CodeGeneration.Contexts = Other1, Other2\n" ); }; it["gets string from empty config"] = () => { var config = new CodeGeneratorConfig(new Config(string.Empty)); config.ToString().should_be( "Entitas.CodeGeneration.Project = Assembly-CSharp.csproj\n" + "Entitas.CodeGeneration.SearchPaths = Libraries/Entitas, Libraries/Entitas/Editor, /Applications/Unity/Unity.app/Contents/Managed, /Applications/Unity/Unity.app/Contents/Mono/lib/mono/unity\n" + "Entitas.CodeGeneration.Assemblies = Library/ScriptAssemblies/Assembly-CSharp.dll\n" + "Entitas.CodeGeneration.Plugins = Entitas.CodeGeneration.Plugins, Entitas.VisualDebugging.CodeGeneration.Plugins, Entitas.Blueprints.CodeGeneration.Plugins\n" + "Entitas.CodeGeneration.DataProviders = \n" + "Entitas.CodeGeneration.CodeGenerators = \n" + "Entitas.CodeGeneration.PostProcessors = \n" + "Entitas.CodeGeneration.TargetDirectory = Assets/Generated\n" + "Entitas.CodeGeneration.Contexts = Game, GameState, Input\n" ); }; it["removes empty entries"] = () => { const string configString = "Entitas.CodeGeneration.Contexts = ,,Core,,UI,,"; var config = new CodeGeneratorConfig(new Config(configString)); config.contexts.should_be(new [] { "Core", "UI" }); }; it["removes trailing comma"] = () => { var config = new CodeGeneratorConfig(new Config(string.Empty)); config.contexts = new [] { "Meta", string.Empty }; config.ToString().should_be( "Entitas.CodeGeneration.Project = Assembly-CSharp.csproj\n" + "Entitas.CodeGeneration.SearchPaths = Libraries/Entitas, Libraries/Entitas/Editor, /Applications/Unity/Unity.app/Contents/Managed, /Applications/Unity/Unity.app/Contents/Mono/lib/mono/unity\n" + "Entitas.CodeGeneration.Assemblies = Library/ScriptAssemblies/Assembly-CSharp.dll\n" + "Entitas.CodeGeneration.Plugins = Entitas.CodeGeneration.Plugins, Entitas.VisualDebugging.CodeGeneration.Plugins, Entitas.Blueprints.CodeGeneration.Plugins\n" + "Entitas.CodeGeneration.DataProviders = \n" + "Entitas.CodeGeneration.CodeGenerators = \n" + "Entitas.CodeGeneration.PostProcessors = \n" + "Entitas.CodeGeneration.TargetDirectory = Assets/Generated\n" + "Entitas.CodeGeneration.Contexts = Meta\n" ); }; it["has all keys"] = () => { var keys = CodeGeneratorConfig.keys; keys.should_contain("Entitas.CodeGeneration.Project"); keys.should_contain("Entitas.CodeGeneration.SearchPaths"); keys.should_contain("Entitas.CodeGeneration.Assemblies"); keys.should_contain("Entitas.CodeGeneration.Plugins"); keys.should_contain("Entitas.CodeGeneration.DataProviders"); keys.should_contain("Entitas.CodeGeneration.CodeGenerators"); keys.should_contain("Entitas.CodeGeneration.PostProcessors"); keys.should_contain("Entitas.CodeGeneration.TargetDirectory"); keys.should_contain("Entitas.CodeGeneration.Contexts"); }; }
static void status() { if (File.Exists(Preferences.configPath)) { var fileContent = File.ReadAllText(Preferences.configPath); var properties = new Properties(fileContent); var config = new CodeGeneratorConfig(new Config(fileContent)); _logger.Debug(config.ToString()); Type[] types = null; string[] configurableKeys = null; try { types = CodeGeneratorUtil.LoadTypesFromCodeGeneratorAssemblies(); configurableKeys = getConfigurableKeys( CodeGeneratorUtil.GetUsed <ICodeGeneratorDataProvider>(types, config.dataProviders), CodeGeneratorUtil.GetUsed <ICodeGenerator>(types, config.codeGenerators), CodeGeneratorUtil.GetUsed <ICodeGenFilePostProcessor>(types, config.postProcessors) ); } catch (Exception ex) { foreach (var key in getUnusedKeys(properties)) { _logger.Info("Unused key: " + key); } foreach (var key in getMissingKeys(properties)) { _logger.Warn("Missing key: " + key); } throw ex; } foreach (var key in getUnusedKeys(properties).Where(key => !configurableKeys.Contains(key))) { _logger.Info("Unused key: " + key); } foreach (var key in getMissingKeys(properties)) { _logger.Warn("Missing key: " + key); } foreach (var key in configurableKeys.Where(key => !properties.HasKey(key))) { _logger.Warn("Missing key: " + key); } printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGeneratorDataProvider>(types, config.dataProviders)); printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGenerator>(types, config.codeGenerators)); printUnavailable(CodeGeneratorUtil.GetUnavailable <ICodeGenFilePostProcessor>(types, config.postProcessors)); printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGeneratorDataProvider>(types, config.dataProviders)); printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGenerator>(types, config.codeGenerators)); printAvailable(CodeGeneratorUtil.GetAvailable <ICodeGenFilePostProcessor>(types, config.postProcessors)); } else { printNoConfig(); } }