public void CmdLineArgProperties_InvalidArguments() { IAnalysisPropertyProvider provider; AssertException.Expects <ArgumentNullException>(() => CmdLineArgPropertyProvider.TryCreateProvider(null, new TestLogger(), out provider)); AssertException.Expects <ArgumentNullException>(() => CmdLineArgPropertyProvider.TryCreateProvider(Enumerable.Empty <ArgumentInstance>(), null, out provider)); }
/// <summary> /// Attempts to process the supplied command line arguments and /// reports any errors using the logger. /// Returns false if any parsing errors were encountered. /// </summary> public static bool TryProcessArgs(string[] commandLineArgs, ILogger logger, out IAnalysisPropertyProvider provider) { if (commandLineArgs == null) { throw new ArgumentNullException(nameof(commandLineArgs)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } provider = null; // This call will fail if there are duplicate or missing arguments var parser = new CommandLineParser(Descriptors, false /* don't allow unrecognized arguments*/); var parsedOk = parser.ParseArguments(commandLineArgs, logger, out IEnumerable <ArgumentInstance> arguments); if (parsedOk) { // Handler for command line analysis properties parsedOk &= CmdLineArgPropertyProvider.TryCreateProvider(arguments, logger, out provider); Debug.Assert(!parsedOk || provider != null); if (parsedOk && !AreParsedArgumentsValid(provider, logger)) { provider = null; } } return(provider != null); }
/// <summary> /// Attempts to process the supplied command line arguments and /// reports any errors using the logger. /// Returns null unless all of the properties are valid. /// </summary> public static ProcessedArgs TryProcessArgs(string[] commandLineArgs, ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } ProcessedArgs processed = null; IEnumerable <ArgumentInstance> arguments; // This call will fail if there are duplicate, missing, or unrecognized arguments CommandLineParser parser = new CommandLineParser(Descriptors, false /* don't allow unrecognized */); bool parsedOk = parser.ParseArguments(commandLineArgs, logger, out arguments); // Handle the /install: command line only argument bool installLoaderTargets; parsedOk &= TryGetInstallTargetsEnabled(arguments, logger, out installLoaderTargets); // Handler for command line analysis properties IAnalysisPropertyProvider cmdLineProperties; parsedOk &= CmdLineArgPropertyProvider.TryCreateProvider(arguments, logger, out cmdLineProperties); // Handler for scanner environment properties IAnalysisPropertyProvider scannerEnvProperties; parsedOk &= EnvScannerPropertiesProvider.TryCreateProvider(logger, out scannerEnvProperties); // Handler for property file IAnalysisPropertyProvider globalFileProperties; string asmPath = Path.GetDirectoryName(typeof(PreProcessor.ArgumentProcessor).Assembly.Location); parsedOk &= FilePropertyProvider.TryCreateProvider(arguments, asmPath, logger, out globalFileProperties); if (parsedOk) { Debug.Assert(cmdLineProperties != null); Debug.Assert(globalFileProperties != null); processed = new ProcessedArgs( GetArgumentValue(KeywordIds.ProjectKey, arguments), GetArgumentValue(KeywordIds.ProjectName, arguments), GetArgumentValue(KeywordIds.ProjectVersion, arguments), GetArgumentValue(KeywordIds.Organization, arguments), installLoaderTargets, cmdLineProperties, globalFileProperties, scannerEnvProperties); if (!AreParsedArgumentsValid(processed, logger)) { processed = null; } } return(processed); }
/// <summary> /// Attempts to process the supplied command line arguments and reports any errors using the logger. /// Returns false if any parsing errors were encountered. /// </summary> public static bool TryProcessArgs(string[] commandLineArgs, ILogger logger, out IBootstrapperSettings settings) { if (commandLineArgs == null) { throw new ArgumentNullException("commandLineArgs"); } if (logger == null) { throw new ArgumentNullException("logger"); } settings = null; IEnumerable <ArgumentInstance> arguments; // This call will fail if there are duplicate or missing arguments CommandLineParser parser = new CommandLineParser(Descriptors, true /* allow unrecognized arguments*/); bool parsedOk = parser.ParseArguments(commandLineArgs, logger, out arguments); // Handler for command line analysis properties IAnalysisPropertyProvider cmdLineProperties; parsedOk &= CmdLineArgPropertyProvider.TryCreateProvider(arguments, logger, out cmdLineProperties); // Handler for property file IAnalysisPropertyProvider globalFileProperties; string asmPath = Path.GetDirectoryName(typeof(Bootstrapper.ArgumentProcessor).Assembly.Location); parsedOk &= FilePropertyProvider.TryCreateProvider(arguments, asmPath, logger, out globalFileProperties); AnalysisPhase phase; parsedOk &= TryGetPhase(commandLineArgs.Length, arguments, logger, out phase); Debug.Assert(!parsedOk || cmdLineProperties != null); Debug.Assert(!parsedOk || globalFileProperties != null); if (parsedOk) { Debug.Assert(cmdLineProperties != null); Debug.Assert(globalFileProperties != null); IAnalysisPropertyProvider properties = new AggregatePropertiesProvider(cmdLineProperties, globalFileProperties); IList <string> baseChildArgs = RemoveBootstrapperArgs(commandLineArgs); if (phase == AnalysisPhase.PreProcessing) { settings = CreatePreProcessorSettings(baseChildArgs, properties, globalFileProperties, logger); } else { settings = CreatePostProcessorSettings(baseChildArgs, properties, logger); } } return(settings != null); }
private static IAnalysisPropertyProvider CheckProcessingSucceeds(IEnumerable <ArgumentInstance> args, TestLogger logger) { var success = CmdLineArgPropertyProvider.TryCreateProvider(args, logger, out IAnalysisPropertyProvider provider); Assert.IsTrue(success, "Expected processing to succeed"); Assert.IsNotNull(provider, "Not expecting a null provider when processing succeeds"); logger.AssertErrorsLogged(0); return(provider); }
public void CmdLineArgProperties_InvalidArguments() { IAnalysisPropertyProvider provider; Action act = () => CmdLineArgPropertyProvider.TryCreateProvider(null, new TestLogger(), out provider); act.Should().ThrowExactly <ArgumentNullException>(); act = () => CmdLineArgPropertyProvider.TryCreateProvider(Enumerable.Empty <ArgumentInstance>(), null, out provider); act.Should().ThrowExactly <ArgumentNullException>(); }
private static TestLogger CheckProcessingFails(IEnumerable <ArgumentInstance> args) { var logger = new TestLogger(); var success = CmdLineArgPropertyProvider.TryCreateProvider(args, logger, out IAnalysisPropertyProvider provider); Assert.IsFalse(success, "Not expecting the provider to be created"); Assert.IsNull(provider, "Expecting the provider to be null is processing fails"); logger.AssertErrorsLogged(); return(logger); }
private static TestLogger CheckProcessingFails(IEnumerable <ArgumentInstance> args) { var logger = new TestLogger(); var success = CmdLineArgPropertyProvider.TryCreateProvider(args, logger, out var provider); success.Should().BeFalse("Not expecting the provider to be created"); provider.Should().BeNull("Expecting the provider to be null is processing fails"); logger.AssertErrorsLogged(); return(logger); }