Skip to content

Commit

Permalink
Breaking change attributes with target Az version (#394)
Browse files Browse the repository at this point in the history
* deprecate methods to ensure version as a must (#383)

Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* Hongtu/version must (#384)

* deprecate methods to ensure version as a must

* add GetAttributeSpecificVersion method in base breaking change attribute

---------

Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* Hongtu/version must (#386)

* deprecate methods to ensure version as a must

* add GetAttributeSpecificVersion method in base breaking change attribute

* change parameter type from string to Version

---------

Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* create new attributes with version instead of modifying existing attributes

* add resource of BreakingChangesAttributesInEffectByAzVersion

* Hongtu/attribute0518 (#387)

* Update Newtonsoft.Json from 10.0.3 to 13.0.2 (#385)

* create new attributes with version instead of modifying existing attributes

* add resource of BreakingChangesAttributesInEffectByAzVersion

---------

Co-authored-by: Yeming Liu <[email protected]>
Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* change internal to public

* remove az version to string

* Hongtu/attribute0518 (#388)

* Update Newtonsoft.Json from 10.0.3 to 13.0.2 (#385)

* create new attributes with version instead of modifying existing attributes

* add resource of BreakingChangesAttributesInEffectByAzVersion

* change internal to public

* remove az version to string

---------

Co-authored-by: Yeming Liu <[email protected]>
Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* change internal to public

* Hongtu/attribute0518 (#389)

* Update Newtonsoft.Json from 10.0.3 to 13.0.2 (#385)

* create new attributes with version instead of modifying existing attributes

* add resource of BreakingChangesAttributesInEffectByAzVersion

* change internal to public

* remove az version to string

* change internal to public

---------

Co-authored-by: Yeming Liu <[email protected]>
Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* add az version output when cmdlets are obsolate

* Hongtu/attribute0518 (#391)

* Update Newtonsoft.Json from 10.0.3 to 13.0.2 (#385)

* create new attributes with version instead of modifying existing attributes

* add resource of BreakingChangesAttributesInEffectByAzVersion

* change internal to public

* remove az version to string

* change internal to public

* add az version output when cmdlets are obsolate

---------

Co-authored-by: Yeming Liu <[email protected]>
Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>

* add \n to terminal warning output of az version

* change resources.resx

* change back common.csproj

* change to public resources

* change generic

* remove azversion from old attribute

* change obsolete to class level

* add comments

---------

Co-authored-by: xtR0d666 <[email protected]>
Co-authored-by: Hongtu Zhang (FA Talent) <[email protected]>
Co-authored-by: Yeming Liu <[email protected]>
  • Loading branch information
4 people authored Jun 21, 2023
1 parent 8b55763 commit 210dd3d
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 90 deletions.
18 changes: 9 additions & 9 deletions src/Common/CustomAttributes/BreakingChangeAttributeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Please leave this section at the top of the breaking change documentation.
* */
public static void ProcessCustomAttributesAtRuntime(Type type, InvocationInfo invocationInfo, Action<string> writeOutput)
{
List<GenericBreakingChangeAttribute> attributes = new List<GenericBreakingChangeAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
List<GenericBreakingChangeWithVersionAttribute> attributes = new List<GenericBreakingChangeWithVersionAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
StringBuilder sb = new StringBuilder();
Action<string> appendBreakingChangeInfo = (string s) => sb.Append(s);

if (attributes != null && attributes.Count > 0)
{
appendBreakingChangeInfo(string.Format(Resources.BreakingChangesAttributesHeaderMessage, Utilities.GetNameFromCmdletType(type)));

foreach (GenericBreakingChangeAttribute attribute in attributes)
foreach (GenericBreakingChangeWithVersionAttribute attribute in attributes)
{
attribute.PrintCustomAttributeInfo(type, false, appendBreakingChangeInfo);
}
Expand All @@ -109,7 +109,7 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)

//This is used as a migration guide, we need to process all properties/fields, moreover at this point of time we do not have a list of all the
//bound params anyways
foreach (GenericBreakingChangeAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
foreach (GenericBreakingChangeWithVersionAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
{
messages.Add(attribute.GetBreakingChangeTextFromAttribute(type, true));
}
Expand All @@ -124,25 +124,25 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)
* the boundParameterNames is a list of parameters bound to the cmdlet at runtime,
* We only process the Parameter beaking change attributes attached only params listed in this list (if present)
**/
public static IEnumerable<GenericBreakingChangeAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
public static IEnumerable<GenericBreakingChangeWithVersionAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
{
List<GenericBreakingChangeAttribute> attributeList = new List<GenericBreakingChangeAttribute>();
List<GenericBreakingChangeWithVersionAttribute> attributeList = new List<GenericBreakingChangeWithVersionAttribute>();

attributeList.AddRange(type.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
attributeList.AddRange(type.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());

foreach (MethodInfo m in type.GetRuntimeMethods())
{
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>()));
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>()));
}

foreach (FieldInfo f in type.GetRuntimeFields())
{
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
}

foreach (PropertyInfo p in type.GetRuntimeProperties())
{
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
}

return invocationInfo == null ? attributeList : attributeList.Where(e => e.IsApplicableToInvocation(invocationInfo));
Expand Down
11 changes: 4 additions & 7 deletions src/Common/CustomAttributes/CmdletDeprecationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
{
[AttributeUsage(
AttributeTargets.Class,
AllowMultiple = true)]
[Obsolete("This attribute is deprecated. Please use CmdletDeprecationWithVersionAttribute instead to provide the deprecate Az version and module version")]
public class CmdletDeprecationAttribute : GenericBreakingChangeAttribute
{
public string ReplacementCmdletName { get; set; }

public CmdletDeprecationAttribute() :
base(string.Empty)
{
}

public CmdletDeprecationAttribute(string deprecateByVersione) :
base(string.Empty, deprecateByVersione)
{
}

public CmdletDeprecationAttribute(string deprecateByVersion, string changeInEfectByDate) :
base(string.Empty, deprecateByVersion, changeInEfectByDate)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
{
/// <summary>
/// This attribute is used to mark cmdlets as deprecated. It provides information about the breaking change, including change description, the version from which the change is deprecated (DeprecateByVersion), the Azure version from which the change is deprecated (DeprecateByAzVersion). This class provides functionality to generate breaking change messages and display information about the breaking changes when needed.
/// </summary>
[AttributeUsage(
AttributeTargets.Class,
AllowMultiple = true)]
public class CmdletDeprecationWithVersionAttribute : GenericBreakingChangeWithVersionAttribute
{
public string ReplacementCmdletName { get; set; }

public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion) :
base(string.Empty, deprecateByAzVersion, deprecateByVersion)
{
}

public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion, string changeInEffectByDate) :
base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEffectByDate)
{
}

protected override string GetAttributeSpecificMessage()
{
if (string.IsNullOrWhiteSpace(ReplacementCmdletName))
{
return Resources.BreakingChangesAttributesCmdLetDeprecationMessageNoReplacement;
}
else
{
return string.Format(Resources.BreakingChangesAttributesCmdLetDeprecationMessageWithReplacement, ReplacementCmdletName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
{
[AttributeUsage(
AttributeTargets.Class,
AllowMultiple = true)]
[Obsolete("This attribute is deprecated. Please use CmdletOutputBreakingChangeWithVersionAttribute instead to provide the deprecate Az version and module version")]
public class CmdletOutputBreakingChangeAttribute : GenericBreakingChangeAttribute
{
public Type DeprecatedCmdLetOutputType { get; }
Expand All @@ -35,19 +33,19 @@ public class CmdletOutputBreakingChangeAttribute : GenericBreakingChangeAttribut
public string[] DeprecatedOutputProperties { get; set; }

public string[] NewOutputProperties { get; set; }

public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName) :
base(string.Empty)
{
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
}

public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion) :
base(string.Empty, deprecateByVersion)
{
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
}

public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion, string changeInEfectByDate) :
base(string.Empty, deprecateByVersion, changeInEfectByDate)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;
using System.Text;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
{
/// <summary>
/// This attribute is used to mark cmdlets output type has breaking changes. It provides information about the breaking change, including change description, the version from which the change is deprecated (DeprecateByVersion), the Azure version from which the change is deprecated (DeprecateByAzVersion). This class provides functionality to generate breaking change messages and display information about the breaking changes when needed.
/// </summary>
[AttributeUsage(
AttributeTargets.Class,
AllowMultiple = true)]
public class CmdletOutputBreakingChangeWithVersionAttribute : GenericBreakingChangeWithVersionAttribute
{
public Type DeprecatedCmdLetOutputType { get; }

//This is still a String instead of a Type as this
//might be undefined at the time of adding the attribute
public string ReplacementCmdletOutputTypeName { get; set; }

public string[] DeprecatedOutputProperties { get; set; }

public string[] NewOutputProperties { get; set; }


public CmdletOutputBreakingChangeWithVersionAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByAzVersion, string deprecateByVersion) :
base(string.Empty, deprecateByAzVersion, deprecateByVersion)
{
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
}

public CmdletOutputBreakingChangeWithVersionAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
{
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
}

protected override string GetAttributeSpecificMessage()
{
StringBuilder message = new StringBuilder();

//check for the deprecation scenario
if (string.IsNullOrWhiteSpace(ReplacementCmdletOutputTypeName) && NewOutputProperties == null && DeprecatedOutputProperties == null && string.IsNullOrWhiteSpace(ChangeDescription))
{
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputTypeDeprecated, DeprecatedCmdLetOutputType.FullName));
}
else
{
if (!string.IsNullOrWhiteSpace(ReplacementCmdletOutputTypeName))
{
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputChange1, DeprecatedCmdLetOutputType.FullName, ReplacementCmdletOutputTypeName));
}
else
{
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputChange2, DeprecatedCmdLetOutputType.FullName));
}

if (DeprecatedOutputProperties != null && DeprecatedOutputProperties.Length > 0)
{
message.Append(Resources.BreakingChangesAttributesCmdLetOutputPropertiesRemoved);
foreach (string property in DeprecatedOutputProperties)
{
message.Append(" '" + property + "'");
}
}

if (NewOutputProperties != null && NewOutputProperties.Length > 0)
{
message.Append(Resources.BreakingChangesAttributesCmdLetOutputPropertiesAdded);
foreach (string property in NewOutputProperties)
{
message.Append(" '" + property + "'");
}
}
}
return message.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

using Microsoft.WindowsAzure.Commands.Common.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;

namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
Expand All @@ -26,6 +24,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
AttributeTargets.Property |
AttributeTargets.Field,
AllowMultiple = true)]
[Obsolete("This attribute is deprecated. Please use CmdletParameterBreakingChangeWithVersionAttribute instead to provide the deprecate Az version and module version")]
public class CmdletParameterBreakingChangeAttribute : GenericBreakingChangeAttribute
{
public string NameOfParameterChanging { get; }
Expand All @@ -37,19 +36,19 @@ public class CmdletParameterBreakingChangeAttribute : GenericBreakingChangeAttri
public Type OldParamaterType { get; set; }

public String NewParameterTypeName { get; set; }

public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging) :
base(string.Empty)
{
this.NameOfParameterChanging = nameOfParameterChanging;
}

public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion) :
base(string.Empty, deprecateByVersion)
{
this.NameOfParameterChanging = nameOfParameterChanging;
}

public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion, string changeInEfectByDate) :
base(string.Empty, deprecateByVersion, changeInEfectByDate)
{
Expand Down
Loading

0 comments on commit 210dd3d

Please sign in to comment.