Ejemplo n.º 1
0
 private AnalyzeRequest GenerateRequest(IApiPortOptions options, IDependencyInfo dependencyInfo)
 {
     return(new AnalyzeRequest
     {
         Targets = options.Targets.SelectMany(_targetMapper.GetNames).ToList(),
         Dependencies = dependencyInfo.Dependencies,
         AssembliesToIgnore = _assembliesToIgnore,                 // We pass along assemblies to ignore instead of filtering them from Dependencies at this point
                                                                   // because breaking change analysis and portability analysis will likely want to filter dependencies
                                                                   // in different ways for ignored assemblies.
                                                                   // For breaking changes, we should show breaking changes for
                                                                   // an assembly if it is un-ignored on any of the user-specified targets and we should hide breaking changes
                                                                   // for an assembly if it ignored on all user-specified targets.
                                                                   // For portability analysis, on the other hand, we will want to show portability for precisely those targets
                                                                   // that a user specifies that are not on the ignore list. In this case, some of the assembly's dependency
                                                                   // information will be needed.
         UnresolvedAssemblies = dependencyInfo.UnresolvedAssemblies.Keys.ToList(),
         UnresolvedAssembliesDictionary = dependencyInfo.UnresolvedAssemblies,
         UserAssemblies = dependencyInfo.UserAssemblies.ToList(),
         AssembliesWithErrors = dependencyInfo.AssembliesWithErrors.ToList(),
         ApplicationName = options.Description,
         Version = AnalyzeRequest.CurrentVersion,
         RequestFlags = options.RequestFlags,
         BreakingChangesToSuppress = options.BreakingChangeSuppressions
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolve the specified bean.
        /// </summary>
        /// <returns>The instance of the resolved dependency.</returns>
        /// <param name="beanName">The bean name.</param>
        public object Resolve(string beanName = null)
        {
            string beanKey = !String.IsNullOrEmpty(beanName) ? beanName : String.Empty;

            if (instances.ContainsKey(beanKey))
            {
                return(instances[beanKey]);
            }

            if (String.IsNullOrEmpty(beanKey))
            {
                IDependencyInfo info = primary ??
                                       (beans.Count == 1 ? beans.Values.First() :
                                        throw new BeanCreationException(String.Format(beans.Count > 1 ?
                                                                                      "Multiple beans found for {0}, none marked as primary." :
                                                                                      "No primary bean found for {0}.", type.Name)));

                return(Create(info, String.Empty));
            }

            if (!beans.ContainsKey(beanKey))
            {
                throw new BeanNotFoundException(String.Format("No bean found under the name of {0} for type {1}", beanKey, type.Name));
            }

            return(Create(beans[beanKey], beanKey));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Implement the on build method that will be called for each definition added.
 /// </summary>
 /// <param name="definition">The dependency info that describes what is required.</param>
 protected override void OnBuild(IDependencyInfo definition)
 {
     if (!TryRegisterTypeTo(definition as IDependencyTypeInfo) && !TryRegisterMethod(definition as IDependencyMethodInfo) && !TryRegisterInstance(definition as IDependencyInstanceInfo) && !TryRegisterFactory(definition as IDependencyFactoryInfo))
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The binding for the type '{0}' is invalid. The binding has not been configured correctly", definition.ResolvedTypes.ToArray()));
     }
 }
        public async Task ExecuteAsync()
        {
            IEnumerable <IDependencyInfo> dependencyInfos = new IDependencyInfo[]
            {
                CreateBuildInfo(RuntimeImageVariant,
                                this.options.DateStampRuntime ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(SdkImageVariant,
                                this.options.DateStampSdk ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(AspnetImageVariant,
                                this.options.DateStampAspnet ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(WcfImageVariant,
                                this.options.DateStampWcf ?? this.options.DateStampAll ?? String.Empty),
            };

            DependencyUpdateResults updateResults = UpdateFiles(dependencyInfos);

            if (updateResults.ChangesDetected())
            {
                if (this.options.UpdateOnly)
                {
                    Trace.TraceInformation($"Changes made but no GitHub credentials specified, skipping PR creation");
                }
                else
                {
                    await CreatePullRequestAsync(dependencyInfos);
                }
            }
        }
Ejemplo n.º 5
0
 protected override void OnBuild(IDependencyInfo info)
 {
     if (!TryRegisterTypeTo(Builder, info as IDependencyTypeInfo) && !TryRegisterMethod(Builder, info as IDependencyMethodInfo) && !TryRegisterInstance(Builder, info as IDependencyInstanceInfo) && !TryRegisterFactory(Builder, info))
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The binding for the type '{0}' is invalid. The binding has not been configured correctly", info));
     }
 }
Ejemplo n.º 6
0
        protected override string TryGetDesiredValue(
            IEnumerable <IDependencyInfo> dependencyBuildInfos, out IEnumerable <IDependencyInfo> usedBuildInfos)
        {
            IDependencyInfo productInfo = dependencyBuildInfos.First(info => info.SimpleName == _productName);

            usedBuildInfos = new IDependencyInfo[] { productInfo };

            string version;

            switch (_versionType)
            {
            case VersionType.Build:
                version = GetBuildVersion(productInfo);
                break;

            case VersionType.Product:
                version = GetProductVersion(productInfo);
                break;

            default:
                throw new NotSupportedException($"Unsupported VersionType: {_versionType}");
            }

            return(version);
        }
Ejemplo n.º 7
0
        protected override string TryGetDesiredValue(
            IEnumerable <IDependencyInfo> dependencyBuildInfos, out IEnumerable <IDependencyInfo> usedBuildInfos)
        {
            IDependencyInfo productInfo = dependencyBuildInfos.First(info => info.SimpleName == _productName);

            usedBuildInfos = new IDependencyInfo[] { productInfo };

            const string RtmSubstring = "-rtm.";

            string versionDir  = _buildVersion;
            string versionFile = _buildVersion;

            if (versionFile.Contains(RtmSubstring))
            {
                versionFile = versionFile.Substring(0, versionFile.IndexOf(RtmSubstring));
            }

            string downloadUrl = s_urls[_productName]
                                 .Replace("$ARCHIVE_EXT", _os.Contains("win") ? "zip" : "tar.gz")
                                 .Replace("$VERSION_DIR", versionDir)
                                 .Replace("$VERSION_FILE", versionFile)
                                 .Replace("$OS", _os)
                                 .Replace("$ARCH", _arch)
                                 .Replace("..", ".");

            return(GetArtifactShaAsync(downloadUrl).Result);
        }
Ejemplo n.º 8
0
        private static void Validate(IDependencyInfo definition)
        {
            if (definition.ResolvedTypes?.Count > 0)
            {
                return;
            }

            throw new InvalidOperationException($"The definition '{definition}', does not contain any resolve types.");
        }
Ejemplo n.º 9
0
        public DependencyFactoryInfo(Type factoryType, string methodName, IDependencyInfo info) : base(info)
        {
            if (string.IsNullOrWhiteSpace(methodName))
            {
                throw new ArgumentException($"'{nameof(methodName)}' cannot be null or whitespace.", nameof(methodName));
            }

            FactoryType = factoryType ?? throw new ArgumentNullException(nameof(factoryType));
            MethodName  = methodName;
        }
Ejemplo n.º 10
0
        protected override void OnBuild(IDependencyInfo info)
        {
            IBindingToSyntax <object> initial = Kernel.Bind(info.ResolvedTypes.ToArray());

            IBindingWhenInNamedWithOrOnSyntax <object> binding = BuildTo(info, initial);

            BindScope(info, binding);
            BindNamedIfConfigured(info, binding);

            Definitions.Add(info);
        }
Ejemplo n.º 11
0
        public IRuntimeResolutionPlan FromInfo(IDependencyInfo info)
        {
            if (info is IDependencyTypeInfo typeInfo)
            {
                return(CreateTypedPlan(typeInfo.ResolutionType));
            }

            var resolver = Ioc.Container.Resolver();

            return(new RuntimeResolutionPlanResolution(resolver.TryGetResolution(info.ResolvedTypes.First(), info.Key)));
        }
Ejemplo n.º 12
0
        protected override string TryGetDesiredValue(
            IEnumerable <IDependencyInfo> dependencyBuildInfos, out IEnumerable <IDependencyInfo> usedBuildInfos)
        {
            IDependencyInfo productInfo = dependencyBuildInfos.First(info => info.SimpleName == _productName);

            usedBuildInfos = new IDependencyInfo[] { productInfo };

            return(_versionType switch
            {
                VersionType.Build => GetBuildVersion(productInfo),
                VersionType.Product => GetProductVersion(productInfo),
                _ => throw new NotSupportedException($"Unsupported VersionType: {_versionType}"),
            });
Ejemplo n.º 13
0
        private static void BindScope(IDependencyInfo info, IBindingWhenInNamedWithOrOnSyntax <object> binding)
        {
            switch (info.Scope)
            {
            case DependyBuilderScope.Transient:
                binding.InTransientScope();
                break;

            case DependyBuilderScope.Singleton:
                binding.InSingletonScope();
                break;
            }
        }
Ejemplo n.º 14
0
        public void Add(IDependencyInfo dependency)
        {
            var keys = dependency.ResolvedTypes;

            foreach (var key in keys)
            {
                if (!Definitions.TryGetValue(key, out IList <IDependencyInfo> definitions))
                {
                    Definitions[key] = definitions = new List <IDependencyInfo>();
                }

                definitions.Add(dependency);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create the new bean by the specified key.
        /// </summary>
        /// <returns>The create.</returns>
        /// <param name="beanKey">Bean key.</param>
        private object Create(IDependencyInfo info, string beanKey)
        {
            object val = context.Autowire(info.Create());

            instances.Add(beanKey, val);

            val.GetType()
            .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
            .ToList()
            .FindAll(x => x.Name.Equals(info.InitMethod) || x.GetCustomAttributes <PostConstructAttribute>().Any())
            .ForEach(x => InvokeInitMethod(x, val));

            return(val);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Convert a generic type info into a concrete type info
        /// </summary>
        /// <param name="info">The current dependency info</param>
        /// <param name="genericTypeArguments">The generic type arguments.</param>
        /// <returns>A new instance of the dependency info with the concrete information set.</returns>
        public static IDependencyInfo As(this IDependencyInfo info, params Type[] genericTypeArguments)
        {
            if (info is IDependencyTypeInfo typeInfo)
            {
                return(As(typeInfo, genericTypeArguments));
            }

            if (info is IDependencyFactoryInfo factoryInfo)
            {
                return(As(factoryInfo, genericTypeArguments));
            }

            throw new NotSupportedException($"The dependency info {info} is not currently supported.");
        }
Ejemplo n.º 17
0
        public static IDependencyInfo As(this IDependencyInfo info, Type concreteRequestType)
        {
            if (info is IDependencyTypeInfo typeInfo)
            {
                return(As(typeInfo, concreteRequestType));
            }

            if (info is IDependencyFactoryInfo factoryInfo)
            {
                return(As(factoryInfo, concreteRequestType));
            }

            throw new NotSupportedException($"The dependency info {info} is not currently supported.");
        }
Ejemplo n.º 18
0
        private static void Build <TActivatorData, TRegistrationStyle>(IDependencyInfo info, IRegistrationBuilder <object, TActivatorData, TRegistrationStyle> binding)
        {
            binding.As(info.ResolvedTypes.ToArray());

            switch (info.Scope)
            {
            case DependyBuilderScope.Transient:
                binding.InstancePerDependency();
                break;

            case DependyBuilderScope.Singleton:
                binding.SingleInstance();
                break;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Create a new instance with copied values.
        /// </summary>
        /// <param name="copy">The base instance to copy from.</param>
        protected DependencyInfo(IDependencyInfo copy) : this()
        {
            if (copy == null)
            {
                return;
            }

            Key   = copy.Key;
            Scope = copy.Scope;

            foreach (var resolvedType in copy.ResolvedTypes)
            {
                ResolvedTypes.Add(resolvedType);
            }
        }
Ejemplo n.º 20
0
        protected override string TryGetDesiredValue(
            IEnumerable <IDependencyInfo> dependencyBuildInfos, out IEnumerable <IDependencyInfo> usedBuildInfos)
        {
            IDependencyInfo productInfo = dependencyBuildInfos.First(info => info.SimpleName == _productName);

            usedBuildInfos = new IDependencyInfo[] { productInfo };

            string downloadUrl = s_urls[_productName]
                                 .Replace("$ARCHIVE_EXT", _os.Contains("win") ? "zip" : "tar.gz")
                                 .Replace("$VERSION", _buildVersion)
                                 .Replace("$OS", _os)
                                 .Replace("$ARCH", _arch)
                                 .Replace("..", ".");

            return(GetArtifactShaAsync(downloadUrl).Result);
        }
Ejemplo n.º 21
0
        private AnalyzeRequest GenerateRequest(IApiPortOptions options, IDependencyInfo dependencyInfo)
        {
            // Match the dependencyInfo for each user assembly to the given
            // input assemblies to see whether or not the assembly was explicitly
            // specified.
            foreach (var assembly in dependencyInfo.UserAssemblies)
            {
                // Windows's file paths are case-insensitive
                var matchingAssembly = options.InputAssemblies.FirstOrDefault(x => x.Key.Name.Equals(assembly.Location, StringComparison.OrdinalIgnoreCase));

                // AssemblyInfo is explicitly specified if we found a matching
                // assembly location in the input dictionary AND the value is
                // true.
                assembly.IsExplicitlySpecified = matchingAssembly.Key != default(IAssemblyFile) &&
                                                 matchingAssembly.Value;
            }

            return(new AnalyzeRequest
            {
                Entrypoints = new[] { options.Entrypoint },
                Targets = options.Targets.SelectMany(_targetMapper.GetNames).ToList(),
                Dependencies = dependencyInfo.Dependencies,

                // We pass along assemblies to ignore instead of filtering them from Dependencies at this point
                // because breaking change analysis and portability analysis will likely want to filter dependencies
                // in different ways for ignored assemblies.
                // For breaking changes, we should show breaking changes for
                // an assembly if it is un-ignored on any of the user-specified targets and we should hide breaking changes
                // for an assembly if it ignored on all user-specified targets.
                // For portability analysis, on the other hand, we will want to show portability for precisely those targets
                // that a user specifies that are not on the ignore list. In this case, some of the assembly's dependency
                // information will be needed.
                AssembliesToIgnore = _assembliesToIgnore,
                UnresolvedAssemblies = dependencyInfo.UnresolvedAssemblies.Keys.ToList(),
                UnresolvedAssembliesDictionary = dependencyInfo.UnresolvedAssemblies,
                UserAssemblies = dependencyInfo.UserAssemblies.ToList(),
                NonUserAssemblies = dependencyInfo.NonUserAssemblies.ToList(),
                AssembliesWithErrors = dependencyInfo.AssembliesWithErrors.ToList(),
                ApplicationName = options.Description,
                Version = AnalyzeRequest.CurrentVersion,
                RequestFlags = options.RequestFlags,
                BreakingChangesToSuppress = options.BreakingChangeSuppressions,
                ReferencedNuGetPackages = options.ReferencedNuGetPackages
            });
        }
Ejemplo n.º 22
0
        private string GetProductVersion(IDependencyInfo productInfo)
        {
            // Derive the Docker tag version from the product build version.
            // 5.0.0-preview.2.19530.9 => 5.0.0-preview.2
            string versionRegexPattern = "[\\d]+.[\\d]+.[\\d]+(-[\\w]+(.[\\d]+)?)?";
            Match  versionMatch        = Regex.Match(productInfo.SimpleVersion, versionRegexPattern);
            string version             = versionMatch.Success ? versionMatch.Value : productInfo.SimpleVersion;

            foreach (string excludedMoniker in s_excludedMonikers)
            {
                int monikerIndex = version.IndexOf($"-{excludedMoniker}", StringComparison.OrdinalIgnoreCase);
                if (monikerIndex != -1)
                {
                    version = version.Substring(0, monikerIndex);
                }
            }

            return(version);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Adds the bean.
        /// </summary>
        /// <param name="name">The bean name.</param>
        /// <param name="mInfo">The Method info.</param>
        /// <param name="isPrimary">If set to <c>true</c> is primary.</param>
        public void AddBean(string name, MemberInfo mInfo, bool isPrimary, string initMethod = null)
        {
            if (isPrimary && primary != null)
            {
                throw new InjectStartupException(String.Format("Multiple primary beans detected for type: {0}. Bean names: {1}, {2}", type.Name, primary.Name, name));
            }

            if (beans.ContainsKey(name))
            {
                throw new InjectStartupException(String.Format("Duplicated bean found for type: {0}. Bean name: {1}", type.Name, name));
            }

            IDependencyInfo info = CreateDependencyInfo(name, mInfo, isPrimary, initMethod);

            if (isPrimary)
            {
                primary = info;
            }

            beans.Add(name, info);
        }
Ejemplo n.º 24
0
        private static void BindNamedIfConfigured(IDependencyInfo info, IBindingWhenInNamedWithOrOnSyntax <object> binding)
        {
            string named;

            if (info.Key is Enum enumKey)
            {
                named = enumKey.GetBindingName();
            }
            else if (info.Key is string name)
            {
                named = name;
            }
            else
            {
                named = info.Key?.ToString();
            }

            if (!string.IsNullOrWhiteSpace(named))
            {
                binding.Named(named);
            }
        }
Ejemplo n.º 25
0
        private IBindingWhenInNamedWithOrOnSyntax <object> BuildTo(IDependencyInfo info, IBindingToSyntax <object> initial)
        {
            if (info is IDependencyMethodInfo methodInfo)
            {
                return(initial.ToMethod(ctx => ExecuteMethod(methodInfo, ctx)));
            }

            if (info is IDependencyTypeInfo typeInfo)
            {
                return(initial.To(typeInfo.ResolutionType));
            }

            if (info is IDependencyInstanceInfo instanceInfo)
            {
                return(initial.ToConstant(instanceInfo.Instance));
            }

            if (info is IDependencyFactoryInfo factoryInfo)
            {
                return(initial.ToMethod(ctx => ExecuteFactory(factoryInfo, ctx)));
            }

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The binding for the types '{0}' is invalid. The binding has not been configured correctly", info));
        }
Ejemplo n.º 26
0
 public IDependencyBuilderBindingMetaData WithFactory(Type factoryType, string methodName)
 {
     _info = new DependencyFactoryInfo(factoryType, methodName, _info);
     return(this);
 }
Ejemplo n.º 27
0
 public IDependencyBuilderBindingMetaData WithFactory <T>(string methodName)
 {
     _info = new DependencyFactoryInfo(typeof(T), methodName, _info);
     return(this);
 }
Ejemplo n.º 28
0
 public IDependencyBuilderBindingMetaData With <T>(T instance)
 {
     _info = new DependencyInstanceInfo(instance, _info);
     return(this);
 }
Ejemplo n.º 29
0
 public IDependencyBuilderBindingMetaData With(Func <IDependencyContext, object> method)
 {
     _info = new DependencyMethodInfo(method, _info);
     return(this);
 }
Ejemplo n.º 30
0
 public IDependencyBuilderBindingMetaData With(Type type)
 {
     _info = new DependencyTypeInfo(type, _info);
     return(this);
 }
Ejemplo n.º 31
0
        /// <summary>
        /// Gets the Portability of an application as a ReportingResult.
        /// </summary>
        /// <returns>Set of APIs/assemblies that are not portable/missing.</returns>
        private async Task<ReportingResult> GetResultFromServiceAsync(AnalyzeRequest request, IDependencyInfo dependencyInfo)
        {
            var fullResponse = await RetrieveResultAsync(request);

            CheckEndpointStatus(fullResponse.Headers.Status);

            return GetReportingResult(request, fullResponse.Response, dependencyInfo);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Gets the Portability of an application as a ReportingResult.
        /// </summary>
        /// <returns>Set of APIs/assemblies that are not portable/missing.</returns>
        private async Task<ReportingResult> GetResultFromServiceAsync(AnalyzeRequest request, IDependencyInfo dependencyInfo)
        {
            var fullResponse = await RetrieveResultAsync(request);

            CheckEndpointStatus(fullResponse.Headers.Status);

            using (var progressTask = _progressReport.StartTask(LocalizedStrings.ComputingReport))
            {
                try
                {
                    var response = fullResponse.Response;

                    return _reportGenerator.ComputeReport(
                        response.Targets,
                        response.SubmissionId,
                        request.RequestFlags,
                        dependencyInfo?.Dependencies,
                        response.MissingDependencies,
                        dependencyInfo?.UnresolvedAssemblies,
                        response.UnresolvedUserAssemblies,
                        dependencyInfo?.AssembliesWithErrors
                    );
                }
                catch (Exception)
                {
                    progressTask.Abort();
                    throw;
                }
            }
        }
Ejemplo n.º 33
0
 private AnalyzeRequest GenerateRequest(IApiPortOptions options, IDependencyInfo dependencyInfo)
 {
     return new AnalyzeRequest
     {
         Targets = options.Targets.SelectMany(_targetMapper.GetNames).ToList(),
         Dependencies = dependencyInfo.Dependencies,
         AssembliesToIgnore = _assembliesToIgnore,                 // We pass along assemblies to ignore instead of filtering them from Dependencies at this point
                                                                   // because breaking change analysis and portability analysis will likely want to filter dependencies
                                                                   // in different ways for ignored assemblies. 
                                                                   // For breaking changes, we should show breaking changes for
                                                                   // an assembly if it is un-ignored on any of the user-specified targets and we should hide breaking changes
                                                                   // for an assembly if it ignored on all user-specified targets. 
                                                                   // For portability analysis, on the other hand, we will want to show portability for precisely those targets
                                                                   // that a user specifies that are not on the ignore list. In this case, some of the assembly's dependency
                                                                   // information will be needed.
         UnresolvedAssemblies = dependencyInfo.UnresolvedAssemblies.Keys.ToList(),
         UnresolvedAssembliesDictionary = dependencyInfo.UnresolvedAssemblies,
         UserAssemblies = dependencyInfo.UserAssemblies.ToList(),
         AssembliesWithErrors = dependencyInfo.AssembliesWithErrors.ToList(),
         ApplicationName = options.Description,
         Version = AnalyzeRequest.CurrentVersion,
         RequestFlags = options.RequestFlags,
         BreakingChangesToSuppress = options.BreakingChangeSuppressions
     };
 }
Ejemplo n.º 34
0
        private ReportingResult GetReportingResult(AnalyzeRequest request, AnalyzeResponse response, IDependencyInfo dependencyInfo)
        {
            if (response == null)
            {
                return null;
            }

            using (var progressTask = _progressReport.StartTask(LocalizedStrings.ComputingReport))
            {
                try
                {
                    return _reportGenerator.ComputeReport(
                        response.Targets,
                        response.SubmissionId,
                        request.RequestFlags,
                        dependencyInfo?.Dependencies,
                        response.MissingDependencies,
                        dependencyInfo?.UnresolvedAssemblies,
                        response.UnresolvedUserAssemblies,
                        dependencyInfo?.AssembliesWithErrors
                    );
                }
                catch (Exception)
                {
                    progressTask.Abort();
                    throw;
                }
            }
        }
Ejemplo n.º 35
0
 public ICodeFileInfo FindCodeFileFor(IDependencyInfo dependencyInfo)
 {
     return projects.SelectMany(p => p.CodeFiles)
         .FirstOrDefault(c => c.Declerations.Any(d => d.Name == dependencyInfo.Name));
 }