Пример #1
0
 private static bool ContainsUnsettableParameter(string propertyName, IEnumerable <Property> properties, ILogger logger)
 {
     if (Property.TryGetProperty(propertyName, properties, out Property existing))
     {
         logger.LogError(Resources.ERROR_CmdLine_CannotSetPropertyOnCommandLine, propertyName);
         return(true);
     }
     return(false);
 }
Пример #2
0
 private static bool ContainsNamedParameter(string propertyName, IEnumerable <Property> properties, ILogger logger, string errorMessage)
 {
     if (Property.TryGetProperty(propertyName, properties, out Property existing))
     {
         logger.LogError(errorMessage);
         return(true);
     }
     return(false);
 }
Пример #3
0
        public bool TryGetProperty(string key, out Property property)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }

            return(Property.TryGetProperty(key, properties, out property));
        }
        /// <summary>
        /// Fetches and processes any analysis properties from the command line arguments
        /// </summary>
        /// <param name="analysisProperties">The extracted analysis properties, if any</param>
        /// <returns>Returns false if any errors are encountered, otherwise true</returns>
        /// <remarks>
        /// Analysis properties (/d:[key]=[value] arguments) need further processing. We need
        /// to extract the key-value pairs and check for duplicate keys.
        /// </remarks>
        private static bool ExtractAndValidateProperties(IEnumerable <ArgumentInstance> arguments, ILogger logger,
                                                         out IEnumerable <Property> analysisProperties)
        {
            var containsDuplicateProperty = false;
            var containsAnalysisProperty  = false;

            var validProperties = new List <Property>();

            foreach (var argument in arguments.Where(a => a.Descriptor.Id == DynamicPropertyArgumentId))
            {
                if (Property.TryParse(argument.Value, out Property property))
                {
                    if (Property.TryGetProperty(property.Id, validProperties, out Property existing))
                    {
                        logger.LogError(Resources.ERROR_CmdLine_DuplicateProperty, argument.Value, existing.Value);
                        containsDuplicateProperty = true;
                    }
                    else
                    {
                        validProperties.Add(property);
                    }
                }
                else
                {
                    logger.LogError(Resources.ERROR_CmdLine_InvalidAnalysisProperty, argument.Value);
                    containsAnalysisProperty = true;
                }
            }

            // Check for named parameters that can't be set by dynamic properties
            var containsProjectKey = ContainsNamedParameter(SonarProperties.ProjectKey, validProperties, logger,
                                                            Resources.ERROR_CmdLine_MustUseProjectKey);
            var containsProjectName = ContainsNamedParameter(SonarProperties.ProjectName, validProperties, logger,
                                                             Resources.ERROR_CmdLine_MustUseProjectName);
            var containsProjectVersion = ContainsNamedParameter(SonarProperties.ProjectVersion, validProperties, logger,
                                                                Resources.ERROR_CmdLine_MustUseProjectVersion);

            // Check for others properties that can't be set
            var containsUnsettableWorkingDirectory = ContainsUnsettableParameter(SonarProperties.WorkingDirectory, validProperties,
                                                                                 logger);

            analysisProperties = validProperties;

            return(!containsDuplicateProperty &&
                   !containsAnalysisProperty &&
                   !containsProjectKey &&
                   !containsProjectName &&
                   !containsProjectVersion &&
                   !containsUnsettableWorkingDirectory);
        }
Пример #5
0
 public bool TryGetProperty(string key, out Property property)
 {
     return(Property.TryGetProperty(key, this.propertiesFile, out property));
 }
Пример #6
0
 public bool TryGetProperty(string key, out Property property)
 {
     return(Property.TryGetProperty(key, properties, out property));
 }