Skip to content

Commit 210dd3d

Browse files
greathongtuHongtu Zhang (FA Talent)isra-fel
authored
Breaking change attributes with target Az version (#394)
* 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]>
1 parent 8b55763 commit 210dd3d

11 files changed

+499
-90
lines changed

src/Common/CustomAttributes/BreakingChangeAttributeHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ Please leave this section at the top of the breaking change documentation.
7979
* */
8080
public static void ProcessCustomAttributesAtRuntime(Type type, InvocationInfo invocationInfo, Action<string> writeOutput)
8181
{
82-
List<GenericBreakingChangeAttribute> attributes = new List<GenericBreakingChangeAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
82+
List<GenericBreakingChangeWithVersionAttribute> attributes = new List<GenericBreakingChangeWithVersionAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
8383
StringBuilder sb = new StringBuilder();
8484
Action<string> appendBreakingChangeInfo = (string s) => sb.Append(s);
8585

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

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

110110
//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
111111
//bound params anyways
112-
foreach (GenericBreakingChangeAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
112+
foreach (GenericBreakingChangeWithVersionAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
113113
{
114114
messages.Add(attribute.GetBreakingChangeTextFromAttribute(type, true));
115115
}
@@ -124,25 +124,25 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)
124124
* the boundParameterNames is a list of parameters bound to the cmdlet at runtime,
125125
* We only process the Parameter beaking change attributes attached only params listed in this list (if present)
126126
**/
127-
public static IEnumerable<GenericBreakingChangeAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
127+
public static IEnumerable<GenericBreakingChangeWithVersionAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
128128
{
129-
List<GenericBreakingChangeAttribute> attributeList = new List<GenericBreakingChangeAttribute>();
129+
List<GenericBreakingChangeWithVersionAttribute> attributeList = new List<GenericBreakingChangeWithVersionAttribute>();
130130

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

133133
foreach (MethodInfo m in type.GetRuntimeMethods())
134134
{
135-
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>()));
135+
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>()));
136136
}
137137

138138
foreach (FieldInfo f in type.GetRuntimeFields())
139139
{
140-
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
140+
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
141141
}
142142

143143
foreach (PropertyInfo p in type.GetRuntimeProperties())
144144
{
145-
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
145+
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
146146
}
147147

148148
return invocationInfo == null ? attributeList : attributeList.Where(e => e.IsApplicableToInvocation(invocationInfo));

src/Common/CustomAttributes/CmdletDeprecationAttribute.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,27 @@
1414

1515
using Microsoft.WindowsAzure.Commands.Common.Properties;
1616
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
19-
using System.Text;
20-
using System.Threading.Tasks;
2117

2218
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
2319
{
2420
[AttributeUsage(
2521
AttributeTargets.Class,
2622
AllowMultiple = true)]
23+
[Obsolete("This attribute is deprecated. Please use CmdletDeprecationWithVersionAttribute instead to provide the deprecate Az version and module version")]
2724
public class CmdletDeprecationAttribute : GenericBreakingChangeAttribute
2825
{
2926
public string ReplacementCmdletName { get; set; }
30-
27+
3128
public CmdletDeprecationAttribute() :
3229
base(string.Empty)
3330
{
3431
}
35-
32+
3633
public CmdletDeprecationAttribute(string deprecateByVersione) :
3734
base(string.Empty, deprecateByVersione)
3835
{
3936
}
40-
37+
4138
public CmdletDeprecationAttribute(string deprecateByVersion, string changeInEfectByDate) :
4239
base(string.Empty, deprecateByVersion, changeInEfectByDate)
4340
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.Common.Properties;
16+
using System;
17+
18+
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
19+
{
20+
/// <summary>
21+
/// 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.
22+
/// </summary>
23+
[AttributeUsage(
24+
AttributeTargets.Class,
25+
AllowMultiple = true)]
26+
public class CmdletDeprecationWithVersionAttribute : GenericBreakingChangeWithVersionAttribute
27+
{
28+
public string ReplacementCmdletName { get; set; }
29+
30+
public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion) :
31+
base(string.Empty, deprecateByAzVersion, deprecateByVersion)
32+
{
33+
}
34+
35+
public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion, string changeInEffectByDate) :
36+
base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEffectByDate)
37+
{
38+
}
39+
40+
protected override string GetAttributeSpecificMessage()
41+
{
42+
if (string.IsNullOrWhiteSpace(ReplacementCmdletName))
43+
{
44+
return Resources.BreakingChangesAttributesCmdLetDeprecationMessageNoReplacement;
45+
}
46+
else
47+
{
48+
return string.Format(Resources.BreakingChangesAttributesCmdLetDeprecationMessageWithReplacement, ReplacementCmdletName);
49+
}
50+
}
51+
}
52+
}

src/Common/CustomAttributes/CmdletOutputBreakingChangeAttribute.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414

1515
using Microsoft.WindowsAzure.Commands.Common.Properties;
1616
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
1917
using System.Text;
20-
using System.Threading.Tasks;
2118

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

3735
public string[] NewOutputProperties { get; set; }
38-
36+
3937
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName) :
4038
base(string.Empty)
4139
{
4240
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
4341
}
44-
42+
4543
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion) :
4644
base(string.Empty, deprecateByVersion)
4745
{
4846
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
4947
}
50-
48+
5149
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion, string changeInEfectByDate) :
5250
base(string.Empty, deprecateByVersion, changeInEfectByDate)
5351
{
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.Common.Properties;
16+
using System;
17+
using System.Text;
18+
19+
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
20+
{
21+
/// <summary>
22+
/// 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.
23+
/// </summary>
24+
[AttributeUsage(
25+
AttributeTargets.Class,
26+
AllowMultiple = true)]
27+
public class CmdletOutputBreakingChangeWithVersionAttribute : GenericBreakingChangeWithVersionAttribute
28+
{
29+
public Type DeprecatedCmdLetOutputType { get; }
30+
31+
//This is still a String instead of a Type as this
32+
//might be undefined at the time of adding the attribute
33+
public string ReplacementCmdletOutputTypeName { get; set; }
34+
35+
public string[] DeprecatedOutputProperties { get; set; }
36+
37+
public string[] NewOutputProperties { get; set; }
38+
39+
40+
public CmdletOutputBreakingChangeWithVersionAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByAzVersion, string deprecateByVersion) :
41+
base(string.Empty, deprecateByAzVersion, deprecateByVersion)
42+
{
43+
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
44+
}
45+
46+
public CmdletOutputBreakingChangeWithVersionAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
47+
base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
48+
{
49+
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
50+
}
51+
52+
protected override string GetAttributeSpecificMessage()
53+
{
54+
StringBuilder message = new StringBuilder();
55+
56+
//check for the deprecation scenario
57+
if (string.IsNullOrWhiteSpace(ReplacementCmdletOutputTypeName) && NewOutputProperties == null && DeprecatedOutputProperties == null && string.IsNullOrWhiteSpace(ChangeDescription))
58+
{
59+
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputTypeDeprecated, DeprecatedCmdLetOutputType.FullName));
60+
}
61+
else
62+
{
63+
if (!string.IsNullOrWhiteSpace(ReplacementCmdletOutputTypeName))
64+
{
65+
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputChange1, DeprecatedCmdLetOutputType.FullName, ReplacementCmdletOutputTypeName));
66+
}
67+
else
68+
{
69+
message.Append(string.Format(Resources.BreakingChangesAttributesCmdLetOutputChange2, DeprecatedCmdLetOutputType.FullName));
70+
}
71+
72+
if (DeprecatedOutputProperties != null && DeprecatedOutputProperties.Length > 0)
73+
{
74+
message.Append(Resources.BreakingChangesAttributesCmdLetOutputPropertiesRemoved);
75+
foreach (string property in DeprecatedOutputProperties)
76+
{
77+
message.Append(" '" + property + "'");
78+
}
79+
}
80+
81+
if (NewOutputProperties != null && NewOutputProperties.Length > 0)
82+
{
83+
message.Append(Resources.BreakingChangesAttributesCmdLetOutputPropertiesAdded);
84+
foreach (string property in NewOutputProperties)
85+
{
86+
message.Append(" '" + property + "'");
87+
}
88+
}
89+
}
90+
return message.ToString();
91+
}
92+
}
93+
}

src/Common/CustomAttributes/CmdletParameterBreakingChangeAttribute.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
using Microsoft.WindowsAzure.Commands.Common.Properties;
1616
using System;
17-
using System.Collections.Generic;
1817
using System.Linq;
1918
using System.Text;
20-
using System.Threading.Tasks;
2119
using System.Management.Automation;
2220

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

3938
public String NewParameterTypeName { get; set; }
40-
39+
4140
public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging) :
4241
base(string.Empty)
4342
{
4443
this.NameOfParameterChanging = nameOfParameterChanging;
4544
}
46-
45+
4746
public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion) :
4847
base(string.Empty, deprecateByVersion)
4948
{
5049
this.NameOfParameterChanging = nameOfParameterChanging;
5150
}
52-
51+
5352
public CmdletParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion, string changeInEfectByDate) :
5453
base(string.Empty, deprecateByVersion, changeInEfectByDate)
5554
{

0 commit comments

Comments
 (0)