Skip to content

Commit

Permalink
Freshen the Java quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Dec 6, 2023
1 parent 64ef041 commit 897f152
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 173 deletions.
49 changes: 17 additions & 32 deletions Src/java-quickstart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'antlr'

group = 'org.cqframework.example'
version = '0.1'
Expand All @@ -16,46 +17,30 @@ repositories {
}

dependencies {
compile group: 'org.antlr', name: 'antlr4', version: '4.5'
testCompile group: 'org.testng', name: 'testng', version: '6.8.8'
antlr group: 'org.antlr', name: 'antlr4', version: '4.10.1'
api "org.antlr:antlr4-runtime:4.10.1"
testImplementation group: 'org.testng', name: 'testng', version: '6.8.8'
}

test {
useTestNG()
}

// ANTLR4 code generation (loosely based on https://github.com/ae6rt/gradle-antlr4-template)

ext.antlr = [
package: 'org.cqframework.cql.gen',
srcDir: 'src/main/resources',
destDir: 'src/generated/java'
]

task antlrTool(type: JavaExec) {
description = 'Generates Java sources from ANTLR4 grammars.'

mkdir(antlr.destDir)
inputs.dir file(antlr.srcDir)
outputs.dir file(antlr.destDir)

def grammars = fileTree(antlr.srcDir).include('**/*.g4')

main = 'org.antlr.v4.Tool'
classpath = configurations.compile
def pkg = antlr.package.replaceAll("\\.", "/")
args = ["-o", "${antlr.destDir}/${pkg}", "-visitor", "-package", antlr.package, grammars.files].flatten()
sourceSets {
main {
antlr {
srcDirs = ["src/main/resources"]
}
java {
srcDir 'build/generated/sources/antlr/main/java'
}
}
}

compileJava.dependsOn antlrTool
sourceSets.main.java.srcDirs += antlr.destDir

clean {
delete antlr.destDir
generateGrammarSource {
outputDirectory = file("${project.buildDir}/generated/sources/antlr/main/java/org/cqframework/cql/gen")
arguments = ['-visitor', '-package', 'org.cqframework.cql.gen']
}

// IDEA config to force ANTLR plugin to use same source locations as gradle

idea {
project {
languageLevel = JavaVersion.VERSION_11
Expand All @@ -64,7 +49,7 @@ idea {
iws {
withXml { provider ->
def props = provider.node.component.find { it.@name == 'PropertiesComponent' }

def propMap = [
'$PROJECT_DIR$/src/main/resources/cql.g4::/output-dir' : '$PROJECT_DIR$/src/generated/java',
'$PROJECT_DIR$/src/main/resources/cql.g4::/lib-dir' : '$PROJECT_DIR$/src/main/resources',
Expand Down
Binary file modified Src/java-quickstart/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions Src/java-quickstart/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Wed Oct 18 04:59:14 NDT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 897f152

Please sign in to comment.