From ac652431c9fe4d31761ead46dae53d71984541da Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Thu, 10 Dec 2020 19:41:21 -0500 Subject: [PATCH 1/4] Add version num to CLI; updates old Repl tests --- build.gradle | 15 +++++++ cli/src/org/partiql/cli/Repl.kt | 15 ++++++- cli/test/org/partiql/cli/ReplTest.kt | 66 ++++++++-------------------- 3 files changed, 46 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index b11c8c21b2..f060e2540f 100644 --- a/build.gradle +++ b/build.gradle @@ -90,11 +90,26 @@ subprojects { }) plugins.withId('org.jetbrains.kotlin.jvm', { _ -> + def generatedVersionDir = "${buildDir}/generated-version" sourceSets { main.kotlin.srcDirs = ["src"] test.kotlin.srcDirs = ["test"] + + main { + output.dir(generatedVersionDir, builtBy: 'generateVersionProperties') + } + } + task generateVersionProperties { + doLast { + def propertiesFile = file "$generatedVersionDir/version.properties" + propertiesFile.parentFile.mkdirs() + def properties = new Properties() + properties.setProperty("version", version.toString()) + propertiesFile.withWriter { properties.store(it, null) } + } } + processResources.dependsOn generateVersionProperties }) } diff --git a/cli/src/org/partiql/cli/Repl.kt b/cli/src/org/partiql/cli/Repl.kt index 72f6886f36..86f1e970e9 100644 --- a/cli/src/org/partiql/cli/Repl.kt +++ b/cli/src/org/partiql/cli/Repl.kt @@ -18,12 +18,11 @@ import com.amazon.ion.system.* import com.amazon.ionelement.api.toIonValue import org.partiql.cli.ReplState.* import org.partiql.lang.* -import org.partiql.lang.ast.* -import org.partiql.lang.ast.passes.MetaStrippingRewriter import org.partiql.lang.eval.* import org.partiql.lang.syntax.* import org.partiql.lang.util.* import java.io.* +import java.util.Properties import java.util.concurrent.* internal const val PROMPT_1 = "PartiQL> " @@ -192,6 +191,17 @@ internal class Repl(private val valueFactory: ExprValueFactory, outputWriter.write("\n") } + fun retrievePartiQLVersion(): String { + val versionProperties = Properties() + versionProperties.load(this.javaClass.getResourceAsStream("/version.properties")) + return versionProperties.getProperty("version") + } + + private fun printVersionNumber() { + outputWriter.write("Using version: ${retrievePartiQLVersion()}") + outputWriter.write("\n") + } + private fun printPrompt() { when { buffer.isEmpty() -> outputWriter.write(PROMPT_1) @@ -268,6 +278,7 @@ internal class Repl(private val valueFactory: ExprValueFactory, state = when (state) { INIT -> { printWelcomeMessage() + printVersionNumber() READY } diff --git a/cli/test/org/partiql/cli/ReplTest.kt b/cli/test/org/partiql/cli/ReplTest.kt index b7c1faa803..b6ccd5dc1d 100644 --- a/cli/test/org/partiql/cli/ReplTest.kt +++ b/cli/test/org/partiql/cli/ReplTest.kt @@ -21,6 +21,7 @@ import org.junit.* import org.junit.Assert.* import org.partiql.lang.* import java.io.* +import java.util.* import java.util.concurrent.* import kotlin.concurrent.* @@ -79,6 +80,8 @@ private class ReplTester(bindings: Bindings = Bindings.empty()) { private val repl = Repl(valueFactory, input, output, parser, compiler, bindings, zeroTimer) + val partiqlVersion = repl.retrievePartiQLVersion() + private val actualReplPrompt = StringBuilder() private val outputPhaser = Phaser() @@ -148,11 +151,13 @@ private class ReplTester(bindings: Bindings = Bindings.empty()) { @Ignore("https://github.com/partiql/partiql-lang-kotlin/issues/266") class ReplTest { + private val partiqlVersion = ReplTester().partiqlVersion @Test fun singleQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> 1+1 # | #===' @@ -167,6 +172,7 @@ class ReplTest { fun querySemiColon() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> 1+1; #===' #2 @@ -180,6 +186,7 @@ class ReplTest { fun multipleQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> 1 + 1 # | #===' @@ -201,66 +208,24 @@ class ReplTest { fun astWithoutMetas() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> 1 + 1 # | !! #===' # #( - # plus - # ( - # lit - # 1 - # ) - # ( - # lit - # 1 - # ) - #) - #--- - #OK! - #PartiQL> - """.trimMargin("#")) - } - - @Test - fun astWithMetas() { - ReplTester().assertReplPrompt(""" - #Welcome to the PartiQL REPL! - #PartiQL> 1 + 1 - # | !? - #===' - # - #( - # meta + # query # ( # plus # ( - # meta - # ( - # lit - # 1 - # ) - # { - # line:1, - # column:1 - # } + # lit + # 1 # ) # ( - # meta - # ( - # lit - # 1 - # ) - # { - # line:1, - # column:5 - # } + # lit + # 1 # ) # ) - # { - # line:1, - # column:3 - # } #) #--- #OK! @@ -272,6 +237,7 @@ class ReplTest { fun addToGlobalEnvAndQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>} # | #===' @@ -314,6 +280,7 @@ class ReplTest { ReplTester(initialBindings).assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> !global_env # | #===' @@ -334,6 +301,7 @@ class ReplTest { fun dumpEmptyInitialEnv() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> !global_env # | #===' @@ -348,6 +316,7 @@ class ReplTest { fun dumpEnvAfterAltering() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>} # | #===' @@ -386,6 +355,7 @@ class ReplTest { fun listCommands() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! + #Using version: $partiqlVersion #PartiQL> !list_commands # | # From 5976bb63ca8ff405c625c3a771cd33b51352f775 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Thu, 10 Dec 2020 19:49:38 -0500 Subject: [PATCH 2/4] Remove unused import --- cli/test/org/partiql/cli/ReplTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/test/org/partiql/cli/ReplTest.kt b/cli/test/org/partiql/cli/ReplTest.kt index b6ccd5dc1d..6dc1b1393d 100644 --- a/cli/test/org/partiql/cli/ReplTest.kt +++ b/cli/test/org/partiql/cli/ReplTest.kt @@ -21,7 +21,6 @@ import org.junit.* import org.junit.Assert.* import org.partiql.lang.* import java.io.* -import java.util.* import java.util.concurrent.* import kotlin.concurrent.* From 6786c36c69b347705e24e7525a91551841979fb9 Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Tue, 15 Dec 2020 13:05:56 -0500 Subject: [PATCH 3/4] Add short commit hash --- build.gradle | 21 +++++++++++++++++---- cli/src/org/partiql/cli/Repl.kt | 10 +++++----- cli/test/org/partiql/cli/ReplTest.kt | 22 +++++++++++----------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index f060e2540f..2dc4278db0 100644 --- a/build.gradle +++ b/build.gradle @@ -97,19 +97,32 @@ subprojects { test.kotlin.srcDirs = ["test"] main { - output.dir(generatedVersionDir, builtBy: 'generateVersionProperties') + output.dir(generatedVersionDir, builtBy: 'generateVersionAndHashProperties') } } - task generateVersionProperties { + + // generates a build properties file with the current PartiQL version and most recent commit hash + task generateVersionAndHashProperties { doLast { - def propertiesFile = file "$generatedVersionDir/version.properties" + def propertiesFile = file "$generatedVersionDir/partiql.properties" propertiesFile.parentFile.mkdirs() def properties = new Properties() + + // get current PartiQL version properties.setProperty("version", version.toString()) + + // get most recent short commit hash + def commitHash = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-parse', '--short', 'HEAD' + standardOutput = commitHash + } + properties.setProperty("commit", commitHash.toString().trim()) + propertiesFile.withWriter { properties.store(it, null) } } } - processResources.dependsOn generateVersionProperties + processResources.dependsOn generateVersionAndHashProperties }) } diff --git a/cli/src/org/partiql/cli/Repl.kt b/cli/src/org/partiql/cli/Repl.kt index 86f1e970e9..659ac97dda 100644 --- a/cli/src/org/partiql/cli/Repl.kt +++ b/cli/src/org/partiql/cli/Repl.kt @@ -191,14 +191,14 @@ internal class Repl(private val valueFactory: ExprValueFactory, outputWriter.write("\n") } - fun retrievePartiQLVersion(): String { - val versionProperties = Properties() - versionProperties.load(this.javaClass.getResourceAsStream("/version.properties")) - return versionProperties.getProperty("version") + fun retrievePartiQLVersionAndHash(): String { + val properties = Properties() + properties.load(this.javaClass.getResourceAsStream("/partiql.properties")) + return "${properties.getProperty("version")}-${properties.getProperty("commit")}" } private fun printVersionNumber() { - outputWriter.write("Using version: ${retrievePartiQLVersion()}") + outputWriter.write("Using version: ${retrievePartiQLVersionAndHash()}") outputWriter.write("\n") } diff --git a/cli/test/org/partiql/cli/ReplTest.kt b/cli/test/org/partiql/cli/ReplTest.kt index 6dc1b1393d..8ca2f59aa5 100644 --- a/cli/test/org/partiql/cli/ReplTest.kt +++ b/cli/test/org/partiql/cli/ReplTest.kt @@ -79,7 +79,7 @@ private class ReplTester(bindings: Bindings = Bindings.empty()) { private val repl = Repl(valueFactory, input, output, parser, compiler, bindings, zeroTimer) - val partiqlVersion = repl.retrievePartiQLVersion() + val partiqlVersionAndHash = repl.retrievePartiQLVersionAndHash() private val actualReplPrompt = StringBuilder() @@ -150,13 +150,13 @@ private class ReplTester(bindings: Bindings = Bindings.empty()) { @Ignore("https://github.com/partiql/partiql-lang-kotlin/issues/266") class ReplTest { - private val partiqlVersion = ReplTester().partiqlVersion + private val partiqlVersionAndHash = ReplTester().partiqlVersionAndHash @Test fun singleQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> 1+1 # | #===' @@ -171,7 +171,7 @@ class ReplTest { fun querySemiColon() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> 1+1; #===' #2 @@ -185,7 +185,7 @@ class ReplTest { fun multipleQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> 1 + 1 # | #===' @@ -207,7 +207,7 @@ class ReplTest { fun astWithoutMetas() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> 1 + 1 # | !! #===' @@ -236,7 +236,7 @@ class ReplTest { fun addToGlobalEnvAndQuery() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>} # | #===' @@ -279,7 +279,7 @@ class ReplTest { ReplTester(initialBindings).assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> !global_env # | #===' @@ -300,7 +300,7 @@ class ReplTest { fun dumpEmptyInitialEnv() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> !global_env # | #===' @@ -315,7 +315,7 @@ class ReplTest { fun dumpEnvAfterAltering() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>} # | #===' @@ -354,7 +354,7 @@ class ReplTest { fun listCommands() { ReplTester().assertReplPrompt(""" #Welcome to the PartiQL REPL! - #Using version: $partiqlVersion + #Using version: $partiqlVersionAndHash #PartiQL> !list_commands # | # From 4ca4c2ae1fff9e53980f006a672ba27438c53f8d Mon Sep 17 00:00:00 2001 From: Alan Cai Date: Tue, 15 Dec 2020 13:37:47 -0500 Subject: [PATCH 4/4] Remove stray TODO for version num --- cli/src/org/partiql/cli/Repl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/org/partiql/cli/Repl.kt b/cli/src/org/partiql/cli/Repl.kt index 659ac97dda..862f10d78c 100644 --- a/cli/src/org/partiql/cli/Repl.kt +++ b/cli/src/org/partiql/cli/Repl.kt @@ -29,7 +29,7 @@ internal const val PROMPT_1 = "PartiQL> " internal const val PROMPT_2 = " | " internal const val BAR_1 = "===' " internal const val BAR_2 = "--- " -internal const val WELCOME_MSG = "Welcome to the PartiQL REPL!" // TODO: extract version from gradle.build and append to message +internal const val WELCOME_MSG = "Welcome to the PartiQL REPL!" private enum class ReplState { /** Initial state, first state as soon as you start the REPL */