private static UpversionType AnalyzeInterface(InterfaceSpec oldInterfaceSpec, InterfaceSpec newInterfaceSpec) { UpversionType maxUpversionType = UpversionType.Patch; if (newInterfaceSpec == null) { // The new spec removed a publically facing class. return(UpversionType.Major); } UpversionType upversionType = NapackAnalyst.AnalyzeProperties(oldInterfaceSpec.Properties, newInterfaceSpec.Properties); if (upversionType == UpversionType.Major) { return(upversionType); } else if (upversionType == UpversionType.Minor) { maxUpversionType = UpversionType.Minor; } upversionType = NapackAnalyst.AnalyzeMethods(oldInterfaceSpec.Methods, newInterfaceSpec.Methods); if (upversionType == UpversionType.Major) { return(upversionType); } else if (upversionType == UpversionType.Minor) { maxUpversionType = UpversionType.Minor; } return(maxUpversionType); }
/// <summary> /// Determines the requried upversioning when code transitions from the old Napack to the new Napack. /// </summary> /// <remarks> /// Major == breaking changes. /// Minor == publically-facing API was added (but not changed or removed) from the new Napack. /// Patch == The publically-facing API is identical between both Napacks, excluding documentation. /// </remarks> public static UpversionType DeterminedRequiredUpversioning(NapackSpec oldNapack, NapackSpec newNapack) { UpversionType maxUpversionType = UpversionType.Patch; foreach (ClassSpec oldClassSpec in oldNapack.Classes) { ClassSpec newClassSpec = newNapack.Classes .FirstOrDefault(cls => cls.Name.Name.Equals(oldClassSpec.Name.Name, StringComparison.InvariantCulture)); UpversionType upversionType = NapackAnalyst.AnalyzeClass(oldClassSpec, newClassSpec); if (upversionType == UpversionType.Major) { // Exit early, as we found a breaking change. return(UpversionType.Major); } else if (upversionType == UpversionType.Minor) { maxUpversionType = UpversionType.Minor; } } foreach (InterfaceSpec oldInterfaceSpec in oldNapack.Interfaces) { InterfaceSpec newInterfaceSpec = newNapack.Interfaces .FirstOrDefault(cls => cls.Name.Name.Equals(oldInterfaceSpec.Name.Name, StringComparison.InvariantCulture)); UpversionType upversionType = NapackAnalyst.AnalyzeInterface(oldInterfaceSpec, newInterfaceSpec); if (upversionType == UpversionType.Major) { // Exit early, as we found a breaking change. return(UpversionType.Major); } else if (upversionType == UpversionType.Minor) { maxUpversionType = UpversionType.Minor; } } // No APIs added in the prior classes. Did the new package add classes? if (maxUpversionType == UpversionType.Patch && (newNapack.Classes.Count != oldNapack.Classes.Count || newNapack.Interfaces.Count != oldNapack.Interfaces.Count)) { maxUpversionType = UpversionType.Minor; } return(maxUpversionType); }
internal static InterfaceSpec AnalyzeInterfaceSyntaxTree(string napackName, string filename, InterfaceDeclarationSyntax interfaceNode) { InterfaceSpec interfaceSpec = new InterfaceSpec(); interfaceSpec.Name = DocumentedElement.LoadFromSyntaxNode(interfaceNode); // Parse methods foreach (MethodDeclarationSyntax node in interfaceNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.MethodDeclaration))) { interfaceSpec.Methods.Add(MethodSpec.LoadFromSyntaxNode(node)); } // Parse properties foreach (PropertyDeclarationSyntax node in interfaceNode.ChildNodes().Where(node => node.IsKind(SyntaxKind.PropertyDeclaration))) { interfaceSpec.Properties.Add(PropertySpec.LoadFromSyntaxNode(node)); } return(interfaceSpec); }