Beispiel #1
0
 public Builder(BuilderParameters parameters)
 {
     _parameters = parameters;
 }
Beispiel #2
0
        private static void ValidateParameters(BuilderParameters parameters)
        {
            List <string> logs = new List <string>();

            if (parameters.PlatformsConfiguration.Count == 0)
            {
                logs.Add("Error: No platforms defined");
            }
            if (parameters.TargetsConfiguration.Count == 0)
            {
                logs.Add("Error: No targets defined");
            }
            if (parameters.ApplicationsConfiguration.Count == 0)
            {
                logs.Add("Error: No applications defined");
            }

            logs.AddRange(
                parameters.PlatformsConfiguration.Keys
                .Where(platformName => !ValidateNames(platformName))
                .Select(platformName => $"Error: platform {platformName} has invalid name, only [A-Za-z0-9_-] allowed"));

            logs.AddRange(
                parameters.TargetsConfiguration.Keys
                .Where(targetName => !ValidateNames(targetName))
                .Select(targetName => $"Error: target {targetName} has invalid name, only [A-Za-z0-9_-] allowed"));

            logs.AddRange(
                parameters.ApplicationsConfiguration.Keys
                .Where(applicationName => !ValidateNames(applicationName))
                .Select(applicationName => $"Error: application {applicationName} has invalid name, only [A-Za-z0-9_-] allowed"));

            //check if all platform used in targets are defined in global list
            logs.AddRange(
                parameters.TargetsConfiguration.SelectMany(target =>
                                                           target.Value.Platforms.Keys
                                                           .Where(platformName => !parameters.PlatformsConfiguration.ContainsKey(platformName))
                                                           .Select(platformName => $"Error: platform {platformName} used in target {target.Key} does not exists in platforms list")
                                                           )
                );

            //check if all targets used in application are defined in global list
            logs.AddRange(
                parameters.ApplicationsConfiguration.SelectMany(application =>
                                                                application.Value.Targets.Keys
                                                                .Where(targetName => !parameters.TargetsConfiguration.ContainsKey(targetName))
                                                                .Select(targetName => $"Error: target {targetName} used in application {application.Key} does not exists in targets list")
                                                                )
                );

            //check if all platforms used in targets in application are defined for this targets
            logs.AddRange(
                parameters.ApplicationsConfiguration.SelectMany(application =>
                                                                application.Value.Targets
                                                                //check if all platforms used are defined in global list
                                                                .SelectMany(target =>
                                                                            target.Value.Platforms.Keys
                                                                            .Where(platformName => !parameters.PlatformsConfiguration.ContainsKey(platformName))
                                                                            .Select(platformName => $"Error: platform {platformName} used in application {application.Key} and target {target.Key} does not exists in platforms list")
                                                                            )
                                                                //check if all platforms used are also defined in the corresponding target platforms list
                                                                .Concat(application.Value.Targets
                                                                        .Where(target => parameters.TargetsConfiguration.ContainsKey(target.Key))
                                                                        .Select(target => Tuple.Create(target, parameters.TargetsConfiguration[target.Key]))
                                                                        .Where(targets => targets.Item2.Platforms.Count > 0)
                                                                        .SelectMany(targets =>
                                                                                    targets.Item1.Value.Platforms.Keys
                                                                                    .Where(platformName => !targets.Item2.Platforms.ContainsKey(platformName))
                                                                                    .Select(platformName => $"Error: platform {platformName} used in application {application.Key} and target {targets.Item1.Key} does not exists in the target {targets.Item1.Key} platforms list")
                                                                                    )
                                                                        )
                                                                )
                );

            if (logs.Count > 0)
            {
                parameters.Context.CakeContext.LogAndThrow(string.Join(Environment.NewLine, logs));
            }
        }
Beispiel #3
0
        private static List <Target> MergeTargets(BuilderParameters parameters)
        {
            ValidateParameters(parameters);
            List <Target> result = new List <Target>();

            foreach (KeyValuePair <string, IApplicationConfiguration> applicationItem in parameters.ApplicationsConfiguration)
            {
                IApplicationConfiguration applicationConfiguration = applicationItem.Value;

                IReadOnlyDictionary <string, ITargetConfiguration> applicationTargets = null;
                IReadOnlyDictionary <string, ITargetConfiguration> targets;

                if (applicationConfiguration.Targets.Count > 0)                 // does the application define specific targets or not ?
                {
                    applicationTargets = applicationConfiguration.Targets;
                    targets            = FilterTargets(parameters.TargetsConfiguration, applicationTargets); //filter global list of targets to be restricted to the ones accepted by the application
                }
                else                                                                                         //if not, use all defined target in the global configuration
                {
                    targets = parameters.TargetsConfiguration;
                }

                //on each targets
                foreach (KeyValuePair <string, ITargetConfiguration> targetItem in targets)
                {
                    string targetName = targetItem.Key;
                    ITargetConfiguration targetConfiguration            = targetItem.Value;
                    ITargetConfiguration applicationTargetConfiguration = applicationTargets?[targetName];

                    IReadOnlyDictionary <string, IPlatformConfiguration> applicationTargetPlatforms = null;
                    IReadOnlyDictionary <string, IPlatformConfiguration> targetPlatforms            = null;
                    IReadOnlyDictionary <string, IPlatformConfiguration> platforms;

                    if (applicationTargetConfiguration != null && applicationTargetConfiguration.Platforms.Count > 0)
                    {
                        applicationTargetPlatforms = applicationTargetConfiguration.Platforms;
                        if (targetConfiguration.Platforms.Count > 0)
                        {
                            targetPlatforms = FilterPlatforms(targetConfiguration.Platforms, applicationTargetPlatforms);                   //filter list of platforms in target to the ones defined by the application
                        }
                        platforms = FilterPlatforms(parameters.PlatformsConfiguration, applicationTargetPlatforms);                         //filter global list of platforms to the ones defined in the application
                    }
                    else if (targetConfiguration.Platforms.Count > 0)
                    {
                        targetPlatforms = targetConfiguration.Platforms;
                        platforms       = FilterPlatforms(parameters.PlatformsConfiguration, targetPlatforms);                   //filter global list of platforms to be restricted to the ones accepted by the target
                    }
                    else
                    {
                        platforms = parameters.PlatformsConfiguration;
                    }

                    foreach (KeyValuePair <string, IPlatformConfiguration> platformItem in platforms)
                    {
                        string platformName = platformItem.Key;
                        IPlatformConfiguration platformConfiguration                  = platformItem.Value;
                        IPlatformConfiguration targetPlatformConfiguration            = targetPlatforms?[platformName];
                        IPlatformConfiguration applicationTargetPlatformConfiguration = applicationTargetPlatforms?[platformName];

                        IConfiguration rootLevel        = parameters.RootConfiguration;
                        IConfiguration switchLevel      = parameters.SwitchConfiguration;
                        IConfiguration platformLevel    = platformConfiguration;
                        IConfiguration targetLevel      = targetConfiguration;
                        IConfiguration applicationLevel = applicationConfiguration;

                        // merge platform specific detail in target level
                        if (targetPlatformConfiguration != null)
                        {
                            targetLevel = targetLevel.Merge(targetPlatformConfiguration);
                        }

                        // merge target and platform specific detail in application level
                        if (applicationTargetConfiguration != null)
                        {
                            IConfiguration applicationTargetLevel = applicationTargetConfiguration;
                            if (applicationTargetPlatformConfiguration != null)
                            {
                                applicationTargetLevel = applicationTargetLevel.Merge(applicationTargetPlatformConfiguration);
                            }
                            applicationLevel = applicationLevel.Merge(applicationTargetLevel);
                        }

                        IConfiguration configuration = rootLevel.Merge(switchLevel.Merge(platformLevel.Merge(targetLevel.Merge(applicationLevel))));
                        result.Add(new Target(applicationItem.Key, targetItem.Key, platformItem.Key, configuration));
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
 public CleanTaskBuilder(BuilderParameters parameters)
 {
     _parameters = parameters;
 }