static void Main(string[] args) { //Debug.Assert(false, "Wanna attach for debugging purposes?"); try { if (args.Length == 0) { OutputHelper.PrintHeader(); OutputHelper.ShowUsage(); return; } string verb = args[0]; if (verb.Equals(INSTALL, StringComparison.InvariantCultureIgnoreCase)) { string gxPath = ""; if (args.Length == 2) { gxPath = args[1]; } if (string.IsNullOrEmpty(gxPath)) { if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Config.GXENEXUS_EXE))) { gxPath = AppDomain.CurrentDomain.BaseDirectory; } else { Console.WriteLine("You must enter the path to a valid GeneXus installation."); gxPath = Console.ReadLine(); } } Config.Install(gxPath); return; } if (verb.Equals(HELP, StringComparison.InvariantCultureIgnoreCase)) { OutputHelper.ShowUsage(); return; } if (verb.Equals(VERSION, StringComparison.InvariantCultureIgnoreCase)) { OutputHelper.PrintHeader(); return; } if (verb.Equals(OPEN, StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine($"Opening GeneXus from {Config.Default.GeneXusPath}"); Process p = new Process(); p.StartInfo = new ProcessStartInfo(Path.Combine(Config.Default.GeneXusPath, Config.GXENEXUS_EXE), "/nolastkb"); p.Start(); return; } if (Config.Default.Providers.ContainsKey(verb.ToLower())) { Dictionary <string, string> options = ParseArguments(args.Skip(1)); if (options.ContainsKey(HELP)) { OutputHelper.ShowUsage(verb); return; } ConfigProvider provider = Config.Default.Providers[verb.ToLower()]; BuildRunner.Execute(provider, options); return; } ThrowInvalidVerb(verb); } catch (ApplicationException aex) { Console.WriteLine(string.Empty); string[] lines = aex.Message.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { if (i == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(lines[i]); Console.ResetColor(); } else { Console.WriteLine(lines[i]); } } } catch (Exception ex) { Console.WriteLine(string.Empty); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Exception inner = ex.InnerException; #if DEBUG Console.WriteLine(ex.StackTrace); #endif while (inner != null) { Console.WriteLine(inner.Message); #if DEBUG Console.WriteLine(inner.StackTrace); #endif inner = inner.InnerException; } Console.ResetColor(); } }
public static void Install(string gxPath) { if (string.IsNullOrEmpty(gxPath)) { throw new Exception("You must enter the path to a GeneXus installation"); } if (!Directory.Exists(gxPath)) { throw new DirectoryNotFoundException($"'{gxPath}' does not look like a valid directory"); } string gxExe = Path.Combine(gxPath, Config.GXENEXUS_EXE); if (!File.Exists(gxExe)) { throw new Exception($"'{gxPath}' does not look like a valid GeneXus installation folder"); } AssemblyInformationalVersionAttribute afv = Assembly.LoadFrom(gxExe).GetCustomAttribute <AssemblyInformationalVersionAttribute>(); s_instance = new Config { GeneXusPath = gxPath, GeneXusVersion = afv.InformationalVersion, CurrentVersion = Application.ProductVersion }; var dir = AppDomain.CurrentDomain.BaseDirectory; string modulesPath = Path.Combine(dir, GXCLI_MODULES); foreach (string dllPath in Directory.GetFiles(modulesPath, "*.dll")) { Assembly ass = Assembly.LoadFrom(dllPath); Console.WriteLine($"Analyzing {ass.GetName().Name}..."); Attribute att = ass.GetCustomAttribute(typeof(GXCliVerbProviderAttribute)); if (att == null) { continue; } Console.WriteLine($"{ass.GetName().Name} is a gxcli verb provider"); Console.WriteLine($"Adding {ass.GetName().Name} verbs..."); foreach (Type t in ass.GetExportedTypes()) { if (typeof(IGXCliVerbProvider).IsAssignableFrom(t)) { IGXCliVerbProvider obj = Activator.CreateInstance(t) as IGXCliVerbProvider; ConfigProvider configProvider = new ConfigProvider(dllPath, t.FullName, obj) { HasValidator = typeof(ParameterValidator).IsAssignableFrom(t) }; if (!s_instance.Providers.ContainsKey(obj.Name)) { Console.WriteLine($"- {obj.Name}"); s_instance.Providers.Add(obj.Name.ToLower(), configProvider); } } } } s_instance.Save(); }
public static void Execute(ConfigProvider provider, Dictionary <string, string> props) { ValidateRequiredProperties(provider, props); if (provider.HasValidator) { ValidateVerbSpecificParameters(provider, props); } List <ILogger> loggers = new List <ILogger> { new ConsoleLogger(GetLoggerVerbosity(props)) }; props["GX_PROGRAM_DIR"] = Config.Default.GeneXusPath; string scriptPath = provider.AssemblyLocation.Replace(".dll", ".targets"); if (!File.Exists(scriptPath)) { scriptPath = provider.AssemblyLocation.Replace(".dll", ".msbuild"); if (!File.Exists(scriptPath)) { throw new FileNotFoundException("Could not find MSBuild script", scriptPath); } } string[] targets = provider.Target.Split(new[] { ',' }); foreach (string target in targets) { BuildRequestData requestData = new BuildRequestData(scriptPath, props, "4.0", new string[] { target }, null); var parameters = new BuildParameters(new ProjectCollection()) { Loggers = loggers }; BuildResult result = BuildManager.DefaultBuildManager.Build(parameters, requestData); if (result.Exception != null) { throw result.Exception; } if (result.OverallResult == BuildResultCode.Failure) { return; } TargetResult tResult = result.ResultsByTarget[target]; foreach (ITaskItem item in tResult.Items) { string[] outProps = item.ItemSpec.Split(new[] { ',' }); foreach (string outProp in outProps) { string[] keyVal = outProp.Split(new[] { '=' }); if (keyVal.Length == 0 || keyVal.Length > 2) { continue; } if (keyVal.Length == 2) { props[keyVal[0]] = keyVal[1]; } else if (keyVal.Length == 1) { props[keyVal[0]] = bool.TrueString; } } } } }