You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vl...@apache.org on 2019/11/19 08:15:40 UTC
[calcite] 05/11: [CALCITE-2905] Use code generation to create
DriverVersion
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 080423bc5c1396676f718db65b2ada36eaa70dbc
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Tue Nov 12 20:30:03 2019 +0300
[CALCITE-2905] Use code generation to create DriverVersion
It simplifies the implementation (no need to parse properties).
---
build.gradle.kts | 1 +
core/build.gradle.kts | 45 ++++++++++++++++++++++
.../main/java/org/apache/calcite/jdbc/Driver.java | 8 +---
.../apache/calcite/jdbc/CalciteDriverVersion.java | 41 ++++++++++++++++++++
4 files changed, 88 insertions(+), 7 deletions(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index 6c25408..aadc0b1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -188,6 +188,7 @@ val semaphore = `java.util.concurrent`.Semaphore(1)
val licenseHeaderFile = file("config/license.header.java")
val javaccGeneratedPatterns = arrayOf(
+ "org/apache/calcite/jdbc/CalciteDriverVersion.java",
"**/parser/**/*ParserImpl*.*",
"**/parser/**/PigletParser.*",
"**/parser/**/PigletParserConstants.*",
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 4648132..b8b438a 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -89,6 +89,51 @@ tasks.jar {
}
}
+val generatedVersionDir = File(buildDir, "generated/sources/version")
+val versionClass by tasks.registering(Sync::class) {
+ val re = Regex("^(\\d+)\\.(\\d+).*")
+
+ val version = project.version.toString()
+ val matchResult = re.find(version) ?: throw GradleException("Unable to parse major.minor version parts from project.version '$version'")
+ val (major, minor) = matchResult.destructured
+
+ // This makes Gradle re-execute the task when version is updated
+ inputs.property("version", version)
+
+ // Note: Gradle does not analyze regexps below, so this variable tells Gradle
+ // to treat the task input out of date when filtering logic is updated.
+ inputs.property("replace.logic.version.bump.when.updating.filter.below", 1)
+
+ outputs.dir(generatedVersionDir)
+
+ into(generatedVersionDir)
+ from("$projectDir/src/main/version") {
+ include("**/*.java")
+ val prop = Regex("""("[^"]++"|\S+)\s+/\* :(\w+) \*/""")
+ filter { x: String ->
+ prop.replace(x) {
+ val variableName = it.groups[2]?.value
+ when (variableName) {
+ "version" -> "\"$version\""
+ "major" -> major
+ "minor" -> minor
+ else -> "unknown variable: $x"
+ } + """ /* :$variableName */"""
+ }
+ }
+ }
+}
+
+ide {
+ generatedJavaSources(versionClass.get(), generatedVersionDir)
+}
+
+sourceSets {
+ main {
+ resources.exclude("version/org-apache-calcite-jdbc.properties")
+ }
+}
+
tasks.withType<Checkstyle>().configureEach {
exclude("org/apache/calcite/runtime/Resources.java")
}
diff --git a/core/src/main/java/org/apache/calcite/jdbc/Driver.java b/core/src/main/java/org/apache/calcite/jdbc/Driver.java
index 1840ed7..b839566 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/Driver.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/Driver.java
@@ -82,13 +82,7 @@ public class Driver extends UnregisteredDriver {
}
@Override protected DriverVersion createDriverVersion() {
- return DriverVersion.load(
- Driver.class,
- "org-apache-calcite-jdbc.properties",
- "Calcite JDBC Driver",
- "unknown version",
- "Calcite",
- "unknown version");
+ return CalciteDriverVersion.INSTANCE;
}
@Override protected Handler createHandler() {
diff --git a/core/src/main/version/org/apache/calcite/jdbc/CalciteDriverVersion.java b/core/src/main/version/org/apache/calcite/jdbc/CalciteDriverVersion.java
new file mode 100644
index 0000000..4503807
--- /dev/null
+++ b/core/src/main/version/org/apache/calcite/jdbc/CalciteDriverVersion.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.calcite.jdbc;
+
+import org.apache.calcite.avatica.DriverVersion;
+
+/**
+ * Provides information on the current Calcite version.
+ */
+class CalciteDriverVersion {
+ static final DriverVersion INSTANCE =
+ new DriverVersion(
+ "Calcite JDBC Driver",
+ "1.0.0-unprocessed-SNAPSHOT" /* :version */,
+ "Calcite",
+ "1.0.0-unprocessed-SNAPSHOT" /* :version */,
+ true,
+ 1 /* :major */,
+ 0 /* :minor */,
+ 1 /* :major */,
+ 0 /* :minor */);
+
+ private CalciteDriverVersion() {
+ }
+}
+
+// End CalciteDriverVersion.java