Skip to content

Commit

Permalink
Use Spotless and .editorconfig for import order normalization instead…
Browse files Browse the repository at this point in the history
… of Checkstyle

It makes it much simpler to understand the violations,
and it provides automatic fix via ./gradlew spotlessApply
  • Loading branch information
vlsi committed Nov 17, 2019
1 parent c493310 commit 92045d0
Show file tree
Hide file tree
Showing 38 changed files with 147 additions and 51 deletions.
47 changes: 47 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
root = true

[*]
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = space

[{*.sh,gradlew}]
end_of_line = lf

[{*.bat,*.cmd}]
end_of_line = crlf

[{*.kts,*.kt}]
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_name_count_to_use_star_import = 99
ij_kotlin_name_count_to_use_star_import_for_members = 99
ij_java_use_single_class_imports = true
max_line_length = 100
ij_any_wrap_long_lines = true

[*.java]
# Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0
# $ means "static"
ij_java_imports_layout = org.apache.calcite.**,|,org.apache.**,|,au.com.**,|,com.**,|,io.**,|,mondrian.**,|,net.**,|,org.**,|,scala.**,|,java.**,javax.**,|,*,|,$com.**,|,$org.apache.calcite.**,|,$org.apache.**,|,$org.**,|,$java,|,$*
indent_size = 2
tab_width = 2
max_line_length = 100
ij_any_spaces_around_additive_operators = true
ij_any_spaces_around_assignment_operators = true
ij_any_spaces_around_bitwise_operators = true
ij_any_spaces_around_equality_operators = true
ij_any_spaces_around_lambda_arrow = true
ij_any_spaces_around_logical_operators = true
ij_any_spaces_around_multiplicative_operators = true
ij_any_spaces_around_relational_operators = true
ij_any_spaces_around_shift_operators = true
ij_continuation_indent_size = 4
ij_java_if_brace_force = always
ij_java_indent_case_from_switch = false
ij_java_space_after_colon = true
ij_java_space_before_colon = true
ij_java_ternary_operation_signs_on_next_line = true
ij_java_use_single_class_imports = true
ij_java_wrap_long_lines = true

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.editorconfig
*~
/.idea
*.iml
Expand Down
58 changes: 57 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import com.github.vlsi.gradle.properties.dsl.toBool
import com.github.vlsi.gradle.release.RepositoryType
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApisExtension
import org.apache.tools.ant.DirectoryScanner
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
publishing
// Verification
checkstyle
id("com.diffplug.gradle.spotless")
id("org.nosphere.apache.rat")
id("com.github.spotbugs")
id("de.thetaphi.forbiddenapis") apply false
Expand Down Expand Up @@ -61,6 +61,7 @@ val lastEditYear by extra(lastEditYear())
// Do not enable spotbugs by default. Execute it only when -Pspotbugs is present
val enableSpotBugs = props.bool("spotbugs", default = false)
val skipCheckstyle by props()
val skipSpotless by props()
val skipJavadoc by props()
val enableMavenLocal by props()
val enableGradleMetadata by props()
Expand Down Expand Up @@ -152,10 +153,34 @@ val javadocAggregate by tasks.registering(Javadoc::class) {
setDestinationDir(file("$buildDir/docs/javadocAggregate"))
}

val licenseHeaderFile = file("config/license.header.java")

allprojects {
group = "org.apache.calcite.avatica"
version = buildVersion

if (!skipSpotless) {
apply(plugin = "com.diffplug.gradle.spotless")
spotless {
kotlinGradle {
ktlint()
trimTrailingWhitespace()
endWithNewline()
}
if (project == rootProject) {
// Spotless does not exclude subprojects when using target(...)
// So **/*.md is enough to scan all the md files in the codebase
// See https://github.com/diffplug/spotless/issues/468
format("markdown") {
target("**/*.md")
// Flot is known to have trailing whitespace, so the files
// are kept in their original format (e.g. to simplify diff on library upgrade)
trimTrailingWhitespace()
endWithNewline()
}
}
}
}
if (!skipCheckstyle) {
apply<CheckstylePlugin>()
dependencies {
Expand Down Expand Up @@ -257,6 +282,37 @@ allprojects {
}
}

if (!skipSpotless) {
spotless {
java {
// targetExclude(*javaccGeneratedPatterns + "**/test/java/*.java")
licenseHeaderFile(licenseHeaderFile)
importOrder(
"org.apache.calcite.",
"org.apache.",
"au.com.",
"com.",
"io.",
"mondrian.",
"net.",
"org.",
"scala.",
"java",
"",
"static com.",
"static org.apache.calcite.",
"static org.apache.",
"static org.",
"static java",
"static "
)
removeUnusedImports()
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
}
}
if (enableSpotBugs) {
apply(plugin = "com.github.spotbugs")
spotbugs {
Expand Down
16 changes: 16 additions & 0 deletions config/license.header.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you 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.
*/
6 changes: 5 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
*
*/

import com.google.protobuf.gradle.*
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.ofSourceSet
import com.google.protobuf.gradle.proto
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.security.PrivilegedAction;
import java.util.Objects;

import javax.security.auth.Subject;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KerberosTicket;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.File;
import java.util.Locale;
import java.util.Map.Entry;

import javax.security.auth.Subject;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ calcite.avatica.version=1.16.0
# publishGradleMetadata=true

# Plugins
com.diffplug.gradle.spotless.version=3.25.0
com.github.johnrengelman.shadow.version=5.1.0
com.github.spotbugs.version=2.0.0
com.github.vlsi.vlsi-release-plugins.version=1.47.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.calcite.avatica.remote.MetricsHelper.concat;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
Expand All @@ -71,6 +69,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.apache.calcite.avatica.remote.MetricsHelper.concat;

/** Implementation of {@link Meta} upon an existing JDBC data source. */
public class JdbcMeta implements ProtobufMeta {
private static final Logger LOG = LoggerFactory.getLogger(JdbcMeta.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Collections;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.Callable;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.Callable;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Objects;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.calcite.avatica.server;

import java.util.Objects;

import javax.servlet.http.HttpServletRequest;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;

import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.login.LoginContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.lang.reflect.Field;
import java.util.Objects;

import javax.security.auth.Subject;
import javax.servlet.ServletRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.HashMap;
import java.util.Map;

import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -42,7 +41,6 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.security.auth.Subject;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;

import org.junit.AfterClass;
import org.junit.Before;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;

import javax.security.auth.login.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

/**
* Test case for Avatica with TLS connectors.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.security.Principal;
import java.util.HashSet;
import java.util.Set;

import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.login.Configuration;
Expand Down
Loading

0 comments on commit 92045d0

Please sign in to comment.