Skip to content

Commit 81395dd

Browse files
authored
Fix tools ci.yml (#46088)
Fix tools ci.yml
1 parent 4502d86 commit 81395dd

35 files changed

+494
-619
lines changed

sdk/tools/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extends:
7979
skipPublishDocGithubIo: true
8080
skipPublishDocMs: true
8181
- name: linting-extensions
82-
groupId: io.clientcore.tools
82+
groupId: io.clientcore
8383
releaseInBatch: ${{ parameters.release_lintingextensions }}
8484
safeName: lintingextensions
8585
skipPublishDocGithubIo: true

sdk/tools/linting-extensions/pom.xml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,60 @@
175175
</executions>
176176
</plugin>
177177

178+
<plugin>
179+
<groupId>com.azure.tools</groupId>
180+
<artifactId>codesnippet-maven-plugin</artifactId>
181+
<version>1.0.0-beta.10</version> <!-- {x-version-update;com.azure.tools:codesnippet-maven-plugin;external_dependency} -->
182+
<configuration>
183+
<readmeGlob>**/*.md</readmeGlob>
184+
</configuration>
185+
<executions>
186+
<execution>
187+
<id>update-codesnippets</id>
188+
<goals>
189+
<goal>update-codesnippet</goal>
190+
</goals>
191+
</execution>
192+
<execution>
193+
<id>verify-codesnippets</id>
194+
<goals>
195+
<goal>verify-codesnippet</goal>
196+
</goals>
197+
</execution>
198+
</executions>
199+
</plugin>
200+
201+
<plugin>
202+
<groupId>com.diffplug.spotless</groupId>
203+
<artifactId>spotless-maven-plugin</artifactId>
204+
<version>2.30.0</version> <!-- {x-version-update;com.diffplug.spotless:spotless-maven-plugin;external_dependency} -->
205+
<configuration>
206+
<skip>${spotless.skip}</skip>
207+
<java>
208+
<eclipse>
209+
<version>4.19.0</version> <!-- 4.19.0 is the last version of the Eclipse formatter supporting Java 8. -->
210+
<file>${project.basedir}/../../../.vscode/eclipse-format-azure-sdk-for-java.xml</file>
211+
</eclipse>
212+
</java>
213+
</configuration>
214+
<executions>
215+
<execution>
216+
<id>spotless-apply</id>
217+
<goals>
218+
<goal>apply</goal>
219+
</goals>
220+
<phase>process-sources</phase>
221+
</execution>
222+
<execution>
223+
<id>spotless-check</id>
224+
<goals>
225+
<goal>check</goal>
226+
</goals>
227+
<phase>verify</phase>
228+
</execution>
229+
</executions>
230+
</plugin>
231+
178232
<plugin>
179233
<groupId>org.apache.maven.plugins</groupId>
180234
<artifactId>maven-site-plugin</artifactId>
@@ -192,5 +246,4 @@
192246
</plugin>
193247
</plugins>
194248
</build>
195-
196249
</project>

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/DenyListedWordsCheck.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public final void setDenyListedWords(String... denyListedWords) {
4343

4444
@Override
4545
public int[] getTokensForCheck() {
46-
return new int[] { TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.METHOD_DEF,
46+
return new int[] {
47+
TokenTypes.CLASS_DEF,
48+
TokenTypes.INTERFACE_DEF,
49+
TokenTypes.METHOD_DEF,
4750
TokenTypes.VARIABLE_DEF };
4851
}
4952

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/EnforceFinalFieldsCheck.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public int[] getRequiredTokens() {
8383
TokenTypes.DEC,
8484
TokenTypes.POST_DEC,
8585
TokenTypes.METHOD_DEF,
86-
TokenTypes.CTOR_DEF,
87-
};
86+
TokenTypes.CTOR_DEF, };
8887
}
8988

9089
@Override
@@ -101,6 +100,7 @@ public void visitToken(DetailAST token) {
101100
this.currentClassName = token.findFirstToken(TokenTypes.IDENT).getText();
102101
fillClassFieldDefinitions(token);
103102
break;
103+
104104
case TokenTypes.ASSIGN:
105105
case TokenTypes.PLUS_ASSIGN:
106106
case TokenTypes.BAND_ASSIGN:
@@ -119,11 +119,13 @@ public void visitToken(DetailAST token) {
119119
case TokenTypes.POST_DEC:
120120
checkAssignation(token);
121121
break;
122+
122123
case TokenTypes.METHOD_DEF:
123124
case TokenTypes.CTOR_DEF:
124125
scopeParent = token;
125126
variablesInScope = new HashMap<>();
126127
break;
128+
127129
default:
128130
// Checkstyle complains if there's no default block in switch
129131
break;
@@ -139,6 +141,7 @@ public void leaveToken(DetailAST token) {
139141
currentScopeParameterSet = null;
140142
variablesInScope = null;
141143
break;
144+
142145
default:
143146
break;
144147
}
@@ -171,16 +174,18 @@ private DetailAST getAssignedField(final DetailAST assignationToken) {
171174
if (assignationWithDot != null) {
172175
if (assignationWithDot.findFirstToken(TokenTypes.LITERAL_THIS) != null) {
173176
return assignationWithDot.findFirstToken(TokenTypes.IDENT);
174-
} else if (TokenUtil.findFirstTokenByPredicate(assignationWithDot,
175-
token -> token.getText().equals(this.currentClassName)).isPresent()) {
177+
} else if (TokenUtil
178+
.findFirstTokenByPredicate(assignationWithDot, token -> token.getText().equals(this.currentClassName))
179+
.isPresent()) {
176180
// Case when referencing same class for private static fields
177181
return assignationWithDot.getLastChild();
178182
} else if (assignationWithDot.getFirstChild().getType() == TokenTypes.IDENT) {
179183
// Case where setting a field on a variable.
180184
String variableNameToken = assignationWithDot.getFirstChild().getText();
181185
DetailAST variableDeclaration = variablesInScope.get(variableNameToken);
182186
DetailAST parentScope = getParentScope(assignationToken);
183-
if (variableDeclaration != null && parentScope != null
187+
if (variableDeclaration != null
188+
&& parentScope != null
184189
&& CheckUtil.isBeforeInSource(variableDeclaration, parentScope)) {
185190
return assignationWithDot.getLastChild();
186191
}
@@ -232,7 +237,8 @@ private void checkAssignation(final DetailAST assignationToken) {
232237

233238
final DetailAST assignationParent = assignationToken.getParent();
234239
if (assignationParent != null && TokenTypes.VARIABLE_DEF == assignationParent.getType()) {
235-
String variableType = FullIdent.createFullIdentBelow(assignationParent.findFirstToken(TokenTypes.TYPE)).getText();
240+
String variableType
241+
= FullIdent.createFullIdentBelow(assignationParent.findFirstToken(TokenTypes.TYPE)).getText();
236242
if (Objects.equals(currentClassName, variableType)) {
237243
// Track variable definitions of the class we're currently in.
238244
variablesInScope.put(assignationParent.findFirstToken(TokenTypes.IDENT).getText(), assignationParent);
@@ -247,7 +253,6 @@ private void checkAssignation(final DetailAST assignationToken) {
247253
}
248254
}
249255

250-
251256
/*
252257
* Check each non-final field definition from a class and fill nonFinalFields
253258
*

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/ExceptionCreatedButNotThrownCheck.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ExceptionCreatedButNotThrownCheck extends AbstractCheck {
1616
+ "either thrown or not created at all. See "
1717
+ "https://github.com/Azure/azure-sdk-for-java/wiki/Client-core:-logging-exceptions-best-practices for more details.";
1818
private static final String[] THROWABLE_AT_LOGGING_METHODS
19-
= new String[] {".throwableAtError", ".throwableAtWarning"};
19+
= new String[] { ".throwableAtError", ".throwableAtWarning" };
2020

2121
/**
2222
* Creates a new instance of {@link ExceptionCreatedButNotThrownCheck}.
@@ -69,10 +69,11 @@ private static boolean isInsideThrow(DetailAST methodCallAst) {
6969
DetailAST parent = methodCallAst.getParent();
7070

7171
// Walk up to skip DOT or EXPR
72-
while (parent != null && (parent.getType() == TokenTypes.DOT
73-
|| parent.getType() == TokenTypes.EXPR
74-
|| parent.getType() == TokenTypes.TYPECAST
75-
|| parent.getType() == TokenTypes.METHOD_CALL)) {
72+
while (parent != null
73+
&& (parent.getType() == TokenTypes.DOT
74+
|| parent.getType() == TokenTypes.EXPR
75+
|| parent.getType() == TokenTypes.TYPECAST
76+
|| parent.getType() == TokenTypes.METHOD_CALL)) {
7677
parent = parent.getParent();
7778
}
7879

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/ExternalDependencyExposedCheck.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* {@code java.} and {@code javax.} are always allowed prefixes.
2222
*/
2323
public class ExternalDependencyExposedCheck extends ImplementationExcludingCheck {
24-
private static final String EXTERNAL_DEPENDENCY_ERROR =
25-
"Class ''%s'', is a class from external dependency. You should not use it as a %s type.";
24+
private static final String EXTERNAL_DEPENDENCY_ERROR
25+
= "Class ''%s'', is a class from external dependency. You should not use it as a %s type.";
2626

2727
private static final String[] ALWAYS_ALLOWED = new String[] { "java.", "javax." };
2828

@@ -96,15 +96,15 @@ private void checkNoExternalDependencyExposed(DetailAST methodDefToken) {
9696
// Checks for the return type of method
9797
final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE);
9898
if (typeToken != null) {
99-
getInvalidReturnTypes(typeToken).forEach((token, returnTypeName) ->
100-
log(token, String.format(EXTERNAL_DEPENDENCY_ERROR, returnTypeName, "return")));
99+
getInvalidReturnTypes(typeToken).forEach((token, returnTypeName) -> log(token,
100+
String.format(EXTERNAL_DEPENDENCY_ERROR, returnTypeName, "return")));
101101
}
102102

103103
// Checks for the parameters of the method
104104
final DetailAST parametersToken = methodDefToken.findFirstToken(TokenTypes.PARAMETERS);
105105
if (parametersToken != null) {
106-
getInvalidParameterTypes(parametersToken).forEach((token, parameterTypeName) ->
107-
log(token, String.format(EXTERNAL_DEPENDENCY_ERROR, parameterTypeName, "method argument")));
106+
getInvalidParameterTypes(parametersToken).forEach((token, parameterTypeName) -> log(token,
107+
String.format(EXTERNAL_DEPENDENCY_ERROR, parameterTypeName, "method argument")));
108108
}
109109
}
110110

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/FluentMethodNameCheck.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public void visitToken(DetailAST token) {
7777

7878
// logs error if the @Fluent method has 'throws' at the method declaration.
7979
if (token.findFirstToken(TokenTypes.LITERAL_THROWS) != null) {
80-
log(token, String.format(
81-
"Fluent Method ''%s'' must not be declared to throw any checked exceptions.",
80+
log(token, String.format("Fluent Method ''%s'' must not be declared to throw any checked exceptions.",
8281
token.findFirstToken(TokenTypes.IDENT).getText()));
8382
}
8483
}
@@ -97,15 +96,19 @@ public void leaveToken(DetailAST token) {
9796
*/
9897
private void checkMethodNamePrefix(DetailAST methodDefToken) {
9998
// A fluent method should only have one parameter.
100-
if (TokenUtil.findFirstTokenByPredicate(methodDefToken, parameters ->
101-
parameters.getType() == TokenTypes.PARAMETERS && parameters.getChildCount() != 1).isPresent()) {
99+
if (TokenUtil
100+
.findFirstTokenByPredicate(methodDefToken,
101+
parameters -> parameters.getType() == TokenTypes.PARAMETERS && parameters.getChildCount() != 1)
102+
.isPresent()) {
102103
log(methodDefToken, "A fluent method should only have one parameter.");
103104
}
104105

105106
// A fluent method's return type should be the class itself
106107
final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE);
107-
if (TokenUtil.findFirstTokenByPredicate(typeToken, ident -> ident.getType() == TokenTypes.IDENT
108-
&& !ident.getText().equals(classNameStack.peek())).isPresent()) {
108+
if (TokenUtil
109+
.findFirstTokenByPredicate(typeToken,
110+
ident -> ident.getType() == TokenTypes.IDENT && !ident.getText().equals(classNameStack.peek()))
111+
.isPresent()) {
109112
log(methodDefToken, "Return type of fluent method should be the class itself");
110113
}
111114

@@ -129,8 +132,9 @@ private boolean isFluentMethod(DetailAST methodDefToken) {
129132
// Always has MODIFIERS node
130133
final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS);
131134
// If no @Fluent annotated with this class, return false
132-
return TokenUtil.findFirstTokenByPredicate(modifiersToken,
133-
annotationToken -> annotationToken.getType() == TokenTypes.ANNOTATION)
135+
return TokenUtil
136+
.findFirstTokenByPredicate(modifiersToken,
137+
annotationToken -> annotationToken.getType() == TokenTypes.ANNOTATION)
134138
.flatMap(annotationToken -> TokenUtil.findFirstTokenByPredicate(annotationToken,
135139
identToken -> identToken.getType() == TokenTypes.IDENT && "Fluent".equals(identToken.getText())))
136140
.isPresent();

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/GoodLoggingCheck.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,29 @@
3939
* file. If left empty, an exception will be thrown by the check.
4040
*/
4141
public class GoodLoggingCheck extends AbstractCheck {
42-
private static final int[] REQUIRED_TOKENS = new int[]{
42+
private static final int[] REQUIRED_TOKENS = new int[] {
4343
TokenTypes.IMPORT,
4444
TokenTypes.INTERFACE_DEF,
4545
TokenTypes.ENUM_DEF,
4646
TokenTypes.CLASS_DEF,
4747
TokenTypes.LITERAL_NEW,
4848
TokenTypes.VARIABLE_DEF,
49-
TokenTypes.METHOD_CALL
50-
};
49+
TokenTypes.METHOD_CALL };
5150

52-
static final String LOGGER_NAME_ERROR = "ClientLogger instance naming: use \"%s\" instead of \"%s\" for consistency.";
53-
static final String NOT_CLIENT_LOGGER_ERROR = "Do not use %s class. Use \"%s\" as a logging mechanism instead of \"%s\".";
54-
static final String LOGGER_NAME_MISMATCH_ERROR = "Not newing a ClientLogger with matching class name. Use \"%s.class\" "
55-
+ "instead of \"%s\".";
51+
static final String LOGGER_NAME_ERROR
52+
= "ClientLogger instance naming: use \"%s\" instead of \"%s\" for consistency.";
53+
static final String NOT_CLIENT_LOGGER_ERROR
54+
= "Do not use %s class. Use \"%s\" as a logging mechanism instead of \"%s\".";
55+
static final String LOGGER_NAME_MISMATCH_ERROR
56+
= "Not newing a ClientLogger with matching class name. Use \"%s.class\" " + "instead of \"%s\".";
5657

5758
// Boolean indicator that indicates if the java class imports ClientLogger
5859
private boolean hasClientLoggerImported;
5960
// A LIFO queue stores the class names, pop top element if exist the class name AST node
6061
private final Queue<String> classNameDeque = Collections.asLifoQueue(new ArrayDeque<>());
6162
// Collection of Invalid logging packages
62-
private static final String[] INVALID_LOGS = new String[] {
63-
"org.slf4j", "org.apache.logging.log4j", "java.util.logging"
64-
};
63+
private static final String[] INVALID_LOGS
64+
= new String[] { "org.slf4j", "org.apache.logging.log4j", "java.util.logging" };
6565

6666
private String fullyQualifiedLoggerName;
6767
private String simpleClassName;
@@ -169,31 +169,38 @@ public void visitToken(DetailAST ast) {
169169

170170
for (String invalidLog : INVALID_LOGS) {
171171
if (importClassPath.startsWith(invalidLog)) {
172-
log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "external logger", fullyQualifiedLoggerName, invalidLog));
172+
log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "external logger", fullyQualifiedLoggerName,
173+
invalidLog));
173174
}
174175
}
175176
break;
177+
176178
case TokenTypes.CLASS_DEF:
177179
case TokenTypes.INTERFACE_DEF:
178180
case TokenTypes.ENUM_DEF:
179181
classNameDeque.offer(ast.findFirstToken(TokenTypes.IDENT).getText());
180182
break;
183+
181184
case TokenTypes.LITERAL_NEW:
182185
checkLoggerInstantiation(ast);
183186
break;
187+
184188
case TokenTypes.VARIABLE_DEF:
185189
checkLoggerNameMatch(ast);
186190
break;
191+
187192
case TokenTypes.METHOD_CALL:
188193
final DetailAST dotToken = ast.findFirstToken(TokenTypes.DOT);
189194
if (dotToken == null) {
190195
return;
191196
}
192197
final String methodCallName = FullIdent.createFullIdentBelow(dotToken).getText();
193198
if (methodCallName.startsWith("System.out") || methodCallName.startsWith("System.err")) {
194-
log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "Java System", fullyQualifiedLoggerName, methodCallName));
199+
log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "Java System", fullyQualifiedLoggerName,
200+
methodCallName));
195201
}
196202
break;
203+
197204
default:
198205
// Checkstyle complains if there's no default block in switch
199206
break;
@@ -211,8 +218,10 @@ private boolean isTypeClientLogger(DetailAST varDefAST) {
211218
if (typeAST == null) {
212219
return false;
213220
}
214-
return TokenUtil.findFirstTokenByPredicate(typeAST,
215-
node -> node.getType() == TokenTypes.IDENT && node.getText().equals(simpleClassName)).isPresent();
221+
return TokenUtil
222+
.findFirstTokenByPredicate(typeAST,
223+
node -> node.getType() == TokenTypes.IDENT && node.getText().equals(simpleClassName))
224+
.isPresent();
216225
}
217226

218227
/**

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/HttpPipelinePolicyCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ private void checkPublicNonImplementationPolicyClass(DetailAST classDefToken) {
6767
return;
6868
}
6969

70-
TokenUtil.findFirstTokenByPredicate(implementsClauseToken,
71-
node -> node.getType() == TokenTypes.IDENT && HTTP_PIPELINE_POLICY.equals(node.getText()))
70+
TokenUtil
71+
.findFirstTokenByPredicate(implementsClauseToken,
72+
node -> node.getType() == TokenTypes.IDENT && HTTP_PIPELINE_POLICY.equals(node.getText()))
7273
.ifPresent(ignored -> {
7374
final String className = classDefToken.findFirstToken(TokenTypes.IDENT).getText();
7475
// Public class check

sdk/tools/linting-extensions/src/main/java/io/clientcore/linting/extensions/checkstyle/checks/ImmutableClassCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public int[] getAcceptableTokens() {
4747

4848
@Override
4949
public int[] getRequiredTokens() {
50-
return new int[]{ TokenTypes.CLASS_DEF, TokenTypes.VARIABLE_DEF, TokenTypes.METHOD_DEF };
50+
return new int[] { TokenTypes.CLASS_DEF, TokenTypes.VARIABLE_DEF, TokenTypes.METHOD_DEF };
5151
}
5252

5353
@Override

0 commit comments

Comments
 (0)