Skip to content

Commit

Permalink
eng, prepare release 0.21.1 (#2957)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Sep 27, 2024
1 parent d105853 commit e283800
Show file tree
Hide file tree
Showing 60 changed files with 5,611 additions and 440 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated 276 files
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ public EclipseLanguageServerFacade(String pathToLanguageServerPlugin, Logger log
if (javaVersion < 17) {
// JAR to start v1.12.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar");
} else if (javaVersion < 21) {
// JAR to start v1.29.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.500.v20230717-2134.jar");
} else {
// JAR to start v1.31.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.700.v20231214-2017.jar");
// JAR to start v1.39.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.900.v20240613-2009.jar");
}

command.add("--add-modules=ALL-SYSTEM");
Expand All @@ -76,8 +73,7 @@ public EclipseLanguageServerFacade(String pathToLanguageServerPlugin, Logger log
}

logger.info("Starting Eclipse JDT language server at {}", languageServerPath);
server = new ProcessBuilder(command)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
server = new ProcessBuilder(command).redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectInput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true)
.directory(languageServerPath.toFile())
Expand All @@ -96,23 +92,16 @@ private static Path getLanguageServerDirectory(int javaVersion, Logger logger) t
if (javaVersion < 17) {
// Eclipse JDT language server version 1.12.0 is the last version that supports Java 11, which is
// autorest.java's baseline.
downloadUrl = URI.create(DOWNLOAD_BASE_URL + "1.12.0/jdt-language-server-1.12.0-202206011637.tar.gz")
.toURL();
downloadUrl
= URI.create(DOWNLOAD_BASE_URL + "1.12.0/jdt-language-server-1.12.0-202206011637.tar.gz").toURL();
languageServerPath = autorestLanguageServer.resolve("1.12.0");
} else if (javaVersion < 21) {
// Eclipse JDT language server version 1.29.0 is the latest version that supports Java 17.
// In the future this else statement may need to be replaced with an else if as newer versions of
// Eclipse JDT language server may baseline on Java 21 (or later).
downloadUrl = URI.create(DOWNLOAD_BASE_URL + "1.29.0/jdt-language-server-1.29.0-202310261436.tar.gz")
.toURL();
languageServerPath = autorestLanguageServer.resolve("1.29.0");
} else {
// Eclipse JDT language server version 1.31.0 is the latest version that supports Java 21.
// Eclipse JDT language server version 1.39.0 is the latest version that supports Java 17.
// In the future this else statement may need to be replaced with an else if as newer versions of
// Eclipse JDT language server may baseline on Java 25 (or later).
downloadUrl = URI.create(DOWNLOAD_BASE_URL + "1.31.0/jdt-language-server-1.31.0-202401111522.tar.gz")
.toURL();
languageServerPath = autorestLanguageServer.resolve("1.31.0");
// Eclipse JDT language server may baseline on Java 21 (or later).
downloadUrl
= URI.create(DOWNLOAD_BASE_URL + "1.39.0/jdt-language-server-1.39.0-202408291433.tar.gz").toURL();
languageServerPath = autorestLanguageServer.resolve("1.39.0");
}

Path languageServer = languageServerPath.resolve("jdt-language-server");
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@autorest/java",
"version": "4.1.37",
"version": "4.1.38",
"description": "The Java extension for classic generators in AutoRest.",
"scripts": {
"autorest": "autorest",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

This module defines/configures the rules for code quality analysis tools such as checkstyle and spotbugs.
For more information refer to [Checkstyle](https://checkstyle.org/) and [Spotbugs](https://spotbugs.github.io/).

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Feng%2Fcode-quality-reports%2FREADME.png)
19 changes: 14 additions & 5 deletions protocol-sdk-integration-tests/eng/code-quality-reports/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. -->
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
Expand Down Expand Up @@ -31,6 +31,15 @@
</scm>

<dependencies>

<!-- Transient Direct Dependency until bump to Java 11 baseline -->
<!-- Necessary because com.puppycrawl.tools:checkstyle:10+ requires Java 11 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.1.0-jre</version> <!-- {x-version-update;com.google.guava:guava;external_dependency} -->
</dependency>

<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
Expand Down Expand Up @@ -109,17 +118,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version> <!-- {x-version-update;org.apache.maven.plugins:maven-site-plugin;external_dependency} -->
<version>3.12.1</version> <!-- {x-version-update;org.apache.maven.plugins:maven-site-plugin;external_dependency} -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-project-info-reports-plugin;external_dependency} -->
<version>3.5.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-project-info-reports-plugin;external_dependency} -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
<version>3.2.5</version> <!-- {x-version-update;org.apache.maven.plugins:maven-surefire-plugin;external_dependency} -->
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;
import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Ensure that code is not using words or abbreviations that are blacklisted by this Checkstyle.
* blacklistedWords: the words that have been blacklisted in the checkstyle.xml config file
*
* Prints out a message stating the location and the class, method or variable as well as the list
* blacklisted words.
* Ensure that code is not using words or abbreviations that are deny listed by this Checkstyle. denyListedWords: the
* words that have been denied in the checkstyle.xml config file
* <p>
* Prints out a message stating the location and the class, method or variable as well as the list of deny listed words.
*/
public class BlacklistedWordsCheck extends AbstractCheck {
private final Set<String> blacklistedWords = new HashSet<>();
public class DenyListedWordsCheck extends AbstractCheck {
private final Set<String> denyListedWords = new HashSet<>();

static final String ERROR_MESSAGE = "%s, All Public API Classes, Fields and Methods should follow "
+ "Camelcase standards for the following words: %s.";

/**
* Adds words that Classes, Methods and Variables that should follow Camelcasing standards
* @param blacklistedWords words that should follow normal Camelcasing standards
*
* @param denyListedWords words that should follow normal Camelcasing standards
*/
public final void setBlacklistedWords(String... blacklistedWords) {
if (blacklistedWords != null) {
Collections.addAll(this.blacklistedWords, blacklistedWords);
public final void setDenyListedWords(String... denyListedWords) {
if (denyListedWords != null) {
Collections.addAll(this.denyListedWords, denyListedWords);
}
}

Expand All @@ -51,7 +49,7 @@ public int[] getAcceptableTokens() {

@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.CLASS_DEF,
return new int[]{TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.VARIABLE_DEF};
}
Expand All @@ -67,7 +65,7 @@ public void visitToken(DetailAST token) {
}

final String tokenName = token.findFirstToken(TokenTypes.IDENT).getText();
if (!hasBlacklistedWords(tokenName)) {
if (!hasDenyListedWords(tokenName)) {
break;
}

Expand All @@ -76,7 +74,7 @@ public void visitToken(DetailAST token) {
break;
}

log(token, String.format(ERROR_MESSAGE, tokenName, String.join(", ", this.blacklistedWords)));
log(token, String.format(ERROR_MESSAGE, tokenName, String.join(", ", this.denyListedWords)));

break;
default:
Expand All @@ -100,13 +98,13 @@ private boolean isPublicApi(DetailAST token) {

/**
* Gets the disallowed abbreviation contained in given String.
*
* @param tokenName the given String.
* @return the disallowed abbreviation contained in given String as a
* separate String.
* @return the disallowed abbreviation contained in given String as a separate String.
*/
private boolean hasBlacklistedWords(String tokenName) {
for (String blacklistedWord : blacklistedWords) {
if (tokenName.contains(blacklistedWord)) {
private boolean hasDenyListedWords(String tokenName) {
for (String denyListedWord : denyListedWords) {
if (tokenName.contains(denyListedWord)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@

import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;
import com.puppycrawl.tools.checkstyle.utils.TokenUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -19,7 +24,7 @@
* nonFinalFields: keep an array of non private fields as tokens (to keep line number)
* assignmentsFromConstructor: Save a set of string for each field name that gets its value assigned in constructor
* assignmentsFromMethods: Save a set of strings for each field name that gets updated in any method
*
* <p>
* On finish tree, check what non-final fields get a value only in constructor and nowhere else by looking for
* strings inside nonFinalFields AND assignmentsFromConstructor but NOT in assignmentsFromMethods
*/
Expand All @@ -36,6 +41,7 @@ public class EnforceFinalFieldsCheck extends AbstractCheck {
private Set<String> assignmentsFromMethods;
private DetailAST scopeParent = null;
private Set<String> currentScopeParameterSet = null;
private Map<String, DetailAST> variablesInScope = null;
private String currentClassName = null;

@Override
Expand Down Expand Up @@ -108,6 +114,7 @@ public void visitToken(DetailAST token) {
case TokenTypes.METHOD_DEF:
case TokenTypes.CTOR_DEF:
scopeParent = token;
variablesInScope = new HashMap<>();
break;
default:
// Checkstyle complains if there's no default block in switch
Expand All @@ -122,6 +129,7 @@ public void leaveToken(DetailAST token) {
case TokenTypes.CTOR_DEF:
scopeParent = null;
currentScopeParameterSet = null;
variablesInScope = null;
break;
default:
break;
Expand Down Expand Up @@ -160,6 +168,15 @@ private DetailAST getAssignedField(final DetailAST assignationToken) {
token -> token.getText().equals(this.currentClassName)).isPresent()) {
// Case when referencing same class for private static fields
return assignationWithDot.getLastChild();
} else if (assignationWithDot.getFirstChild().getType() == TokenTypes.IDENT) {
// Case where setting a field on a variable.
String variableNameToken = assignationWithDot.getFirstChild().getText();
DetailAST variableDeclaration = variablesInScope.get(variableNameToken);
DetailAST parentScope = getParentScope(assignationToken);
if (variableDeclaration != null && parentScope != null
&& CheckUtil.isBeforeInSource(variableDeclaration, parentScope)) {
return assignationWithDot.getLastChild();
}
}
} else {
final DetailAST variableNameToken = assignationToken.getFirstChild();
Expand All @@ -172,6 +189,17 @@ private DetailAST getAssignedField(final DetailAST assignationToken) {
return null;
}

private static DetailAST getParentScope(DetailAST ast) {
DetailAST parent = ast.getParent();
do {
if (parent.getType() == TokenTypes.SLIST) {
return parent;
}
} while ((parent = parent.getParent()) != null);

return null;
}

/*
* Saves a field name to a container depending on the provided type
*/
Expand All @@ -197,7 +225,12 @@ private void checkAssignation(final DetailAST assignationToken) {

final DetailAST assignationParent = assignationToken.getParent();
if (assignationParent != null && TokenTypes.VARIABLE_DEF == assignationParent.getType()) {
// Assignation for a variable definition. No need to check this assignation
String variableType = FullIdent.createFullIdentBelow(assignationParent.findFirstToken(TokenTypes.TYPE)).getText();
if (Objects.equals(currentClassName, variableType)) {
// Track variable definitions of the class we're currently in.
variablesInScope.put(assignationParent.findFirstToken(TokenTypes.IDENT).getText(), assignationParent);
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifierOption;
import com.puppycrawl.tools.checkstyle.utils.CheckUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* No external dependency exposed in public API
*/
public class ExternalDependencyExposedCheck extends AbstractCheck {
private static final String EXTERNAL_DEPENDENCY_ERROR =
"Class ''%s'', is a class from external dependency. You should not use it as a %s type.";
private static final Set<String> VALID_DEPENDENCY_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"java", "com.azure", "reactor", "org.reactivestreams"
)));

private final Map<String, String> simpleClassNameToQualifiedNameMap = new HashMap<>();

Expand Down Expand Up @@ -198,7 +191,12 @@ private boolean isValidClassDependency(String typeName) {
}

final String qualifiedName = simpleClassNameToQualifiedNameMap.get(typeName);
return VALID_DEPENDENCY_SET.stream()
.anyMatch(validPackageName -> qualifiedName.startsWith(validPackageName));

return "com.azure.".regionMatches(0, qualifiedName, 0, 10)
|| "io.clientcore.".regionMatches(0, qualifiedName, 0, 14)
|| "java.".regionMatches(0, qualifiedName, 0, 5)
|| "javax.".regionMatches(0, qualifiedName, 0, 6)
|| "reactor.".regionMatches(0, qualifiedName, 0, 8)
|| "org.reactivestreams.".regionMatches(0, qualifiedName, 0, 20);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public class GoodLoggingCheck extends AbstractCheck {
private static final int[] REQUIRED_TOKENS = new int[]{
TokenTypes.IMPORT,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.LITERAL_NEW,
TokenTypes.VARIABLE_DEF,
TokenTypes.METHOD_CALL
};

static final String STATIC_LOGGER_ERROR = "Use a static ClientLogger instance in a static method.";
static final String LOGGER_NAME_ERROR = "ClientLogger instance naming: use \"%s\" instead of \"%s\" for consistency.";
static final String NOT_CLIENT_LOGGER_ERROR = "Do not use %s class. Use \"%s\" as a logging mechanism instead of \"%s\".";
static final String LOGGER_NAME_MISMATCH_ERROR = "Not newing a ClientLogger with matching class name. Use \"%s.class\" "
Expand Down Expand Up @@ -78,7 +78,9 @@ public void finishTree(DetailAST ast) {

@Override
public void leaveToken(DetailAST ast) {
if (ast.getType() == TokenTypes.CLASS_DEF) {
if (ast.getType() == TokenTypes.CLASS_DEF
|| ast.getType() == TokenTypes.INTERFACE_DEF
|| ast.getType() == TokenTypes.ENUM_DEF) {
classNameDeque.poll();
}
}
Expand All @@ -98,6 +100,7 @@ public void visitToken(DetailAST ast) {
break;
case TokenTypes.CLASS_DEF:
case TokenTypes.INTERFACE_DEF:
case TokenTypes.ENUM_DEF:
classNameDeque.offer(ast.findFirstToken(TokenTypes.IDENT).getText());
break;
case TokenTypes.LITERAL_NEW:
Expand Down
Loading

0 comments on commit e283800

Please sign in to comment.