Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [Spotless] Entire project running spotless #2016

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/sql-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- '!sql-jdbc/**'
- '**gradle*'
- '**lombok*'
- '**checkstyle*'
- '**spotless*'
- 'integ-test/**'
- '**/*.jar'
- '**/*.pom'
Expand Down
8 changes: 3 additions & 5 deletions DEVELOPER_GUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ The plugin codebase is in standard layout of Gradle project::
├── THIRD-PARTY
├── build.gradle
├── config
│ └── checkstyle
│ └── spotless
├── docs
│   ├── attributions.md
│   ├── category.json
Expand Down Expand Up @@ -170,7 +170,7 @@ Here are sub-folders (Gradle modules) for plugin source code:
Here are other files and sub-folders that you are likely to touch:

- ``build.gradle``: Gradle build script.
- ``config``: only Checkstyle configuration files for now.
- ``config``: only Spotless configuration files for now.
- ``docs``: documentation for developers and reference manual for users.
- ``doc-test``: code that run .rst docs in ``docs`` folder by Python doctest library.

Expand Down Expand Up @@ -230,9 +230,7 @@ Most of the time you just need to run ./gradlew build which will make sure you p
* - ./gradlew generateGrammarSource
- (Re-)Generate ANTLR parser from grammar file.
* - ./gradlew compileJava
- Compile all Java source files.
* - ./gradlew checkstyle
- Run all checks according to Checkstyle configuration.
- Compile all Java source files.
* - ./gradlew test
- Run all unit tests.
* - ./gradlew :integ-test:integTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@Fork(value = 1)
public class ComparisonOperatorBenchmark {

@Param(value = { "int", "string", "date" })
@Param(value = {"int", "string", "date"})
private String testDataType;

private final Map<String, ExprValue> params =
Expand All @@ -65,9 +65,7 @@ public void testGreaterOperator() {

private void run(Function<Expression[], FunctionExpression> dsl) {
ExprValue param = params.get(testDataType);
FunctionExpression func = dsl.apply(new Expression[] {
literal(param), literal(param)
});
FunctionExpression func = dsl.apply(new Expression[] {literal(param), literal(param)});
func.valueOf();
}
}
20 changes: 1 addition & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ buildscript {
plugins {
id 'nebula.ospackage' version "8.3.0"
id 'java-library'
id 'checkstyle'
id "io.freefair.lombok" version "6.4.0"
id 'jacoco'
id 'com.diffplug.spotless' version '6.19.0'
Expand All @@ -84,7 +83,7 @@ repositories {
spotless {
java {
target fileTree('.') {
include 'core/**/*.java'
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down Expand Up @@ -184,23 +183,6 @@ jacocoTestCoverageVerification {
}
check.dependsOn jacocoTestCoverageVerification

// TODO: fix code style in main and test source code
allprojects {
apply plugin: 'checkstyle'
checkstyle {
configFile rootProject.file("config/checkstyle/google_checks.xml")
toolVersion "10.3.2"
configProperties = [
"org.checkstyle.google.suppressionfilter.config": rootProject.file("config/checkstyle/suppressions.xml")]
ignoreFailures = false
}
}
checkstyle {
configFile file("config/checkstyle/checkstyle.xml")
}
checkstyleMain.ignoreFailures = false
checkstyleTest.ignoreFailures = true

configurations.all {
resolutionStrategy.force 'junit:junit:4.13.2'
exclude group: "commons-logging", module: "commons-logging"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.common.antlr;

import org.antlr.v4.runtime.CharStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.common.antlr;

import java.util.Locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


package org.opensearch.sql.common.antlr;

public class SyntaxCheckException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ public class AwsSigningInterceptor implements Interceptor {
private static final Logger LOG = LogManager.getLogger();

/**
* AwsSigningInterceptor which intercepts http requests
* and adds required headers for sigv4 authentication.
* AwsSigningInterceptor which intercepts http requests and adds required headers for sigv4
* authentication.
*
* @param awsCredentialsProvider awsCredentialsProvider.
* @param region region.
* @param serviceName serviceName.
*/
public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvider,
@NonNull String region, @NonNull String serviceName) {
public AwsSigningInterceptor(
@NonNull AWSCredentialsProvider awsCredentialsProvider,
@NonNull String region,
@NonNull String serviceName) {
this.okHttpAwsV4Signer = new OkHttpAwsV4Signer(region, serviceName);
this.awsCredentialsProvider = awsCredentialsProvider;
}
Expand All @@ -48,25 +50,27 @@ public AwsSigningInterceptor(@NonNull AWSCredentialsProvider awsCredentialsProvi
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();

DateTimeFormatter timestampFormat = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
.withZone(ZoneId.of("GMT"));
DateTimeFormatter timestampFormat =
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneId.of("GMT"));


Request.Builder newRequestBuilder = request.newBuilder()
.addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now()))
.addHeader("host", request.url().host());
Request.Builder newRequestBuilder =
request
.newBuilder()
.addHeader("x-amz-date", timestampFormat.format(ZonedDateTime.now()))
.addHeader("host", request.url().host());

AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials();
if (awsCredentialsProvider instanceof STSAssumeRoleSessionCredentialsProvider) {
newRequestBuilder.addHeader("x-amz-security-token",
newRequestBuilder.addHeader(
"x-amz-security-token",
((STSAssumeRoleSessionCredentialsProvider) awsCredentialsProvider)
.getCredentials()
.getSessionToken());
}
Request newRequest = newRequestBuilder.build();
Request signed = okHttpAwsV4Signer.sign(newRequest,
awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey());
Request signed =
okHttpAwsV4Signer.sign(
newRequest, awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey());
return chain.proceed(signed);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ public BasicAuthenticationInterceptor(@NonNull String username, @NonNull String
this.credentials = Credentials.basic(username, password);
}


@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Request authenticatedRequest = request.newBuilder()
.header("Authorization", credentials).build();
Request authenticatedRequest =
request.newBuilder().header("Authorization", credentials).build();
return chain.proceed(authenticatedRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
* Convert String argument to the right type.
*/
/** Convert String argument to the right type. */
public class Converter {

public enum Type {
Expand All @@ -51,13 +49,13 @@ public enum Type {
private static final Pattern SPLITTER = Pattern.compile("[:;]");

private static final Map<String, Type> TYPES =
Arrays.stream(Type.values())
.collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));
Arrays.stream(Type.values()).collect(Collectors.toMap(t -> t.name().toLowerCase(), t -> t));

private static final Map<String, Type> TYPE_ALIASES =
Arrays.stream(Type.values())
.flatMap(type -> type.aliases.stream()
.map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
.flatMap(
type ->
type.aliases.stream().map(alias -> new AbstractMap.SimpleEntry<>(alias, type)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

private static Type getType(String key) {
Expand All @@ -69,34 +67,30 @@ private static Type getType(String key) {
return type;
}

/**
* getConverters.
*/
public static Map<String, IConverter<? extends Object>>
getConverters(Collection<String> groupNames, Object... params) {
/** getConverters. */
public static Map<String, IConverter<? extends Object>> getConverters(
Collection<String> groupNames, Object... params) {
return groupNames.stream()
.filter(Converter::containsDelimiter)
.collect(Collectors.toMap(Function.identity(), key -> {
String[] list = splitGrokPattern(key);
IConverter<? extends Object> converter = getType(list[1]).converter;
if (list.length == 3) {
converter = converter.newConverter(list[2], params);
}
return converter;
}));
.collect(
Collectors.toMap(
Function.identity(),
key -> {
String[] list = splitGrokPattern(key);
IConverter<? extends Object> converter = getType(list[1]).converter;
if (list.length == 3) {
converter = converter.newConverter(list[2], params);
}
return converter;
}));
}

/**
* getGroupTypes.
*/
/** getGroupTypes. */
public static Map<String, Type> getGroupTypes(Collection<String> groupNames) {
return groupNames.stream()
.filter(Converter::containsDelimiter)
.map(Converter::splitGrokPattern)
.collect(Collectors.toMap(
l -> l[0],
l -> getType(l[1])
));
.collect(Collectors.toMap(l -> l[0], l -> getType(l[1])));
}

public static String extractKey(String key) {
Expand All @@ -120,7 +114,6 @@ default IConverter<T> newConverter(String param, Object... params) {
}
}


static class DateConverter implements IConverter<Instant> {

private final DateTimeFormatter formatter;
Expand All @@ -138,8 +131,12 @@ private DateConverter(DateTimeFormatter formatter, ZoneId timeZone) {

@Override
public Instant convert(String value) {
TemporalAccessor dt = formatter
.parseBest(value.trim(), ZonedDateTime::from, LocalDateTime::from, OffsetDateTime::from,
TemporalAccessor dt =
formatter.parseBest(
value.trim(),
ZonedDateTime::from,
LocalDateTime::from,
OffsetDateTime::from,
Instant::from,
LocalDate::from);
if (dt instanceof ZonedDateTime) {
Expand Down
Loading