Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git
description = "Relational eXpression Map"

apply plugin: "java"
apply plugin: "application"

sourceCompatibility = 1.8
targetCompatibility = 1.8

// For testing.
mainClassName = "com.whitemagicsoftware.rxm.Main"

def javadocLinks = [
  "http://docs.oracle.com/javase/8/docs/api",
  "http://www.antlr.org/api/Java",
] as String[]

sourceSets {
  main {
    java {
      srcDir "source"
    }
  }
}

tasks.withType( JavaCompile ) {
  options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

javadoc {
  source( "source", "source/antlr" )
  destinationDir = file( "docs/javadoc" )
  include( "**/*.java" )

  options.links( javadocLinks )
}

// The zip and tar currently include the libraries twice.
distZip.enabled = false
distTar.enabled = false

jar {
  manifest {
    attributes "Main-Class": "$mainClassName"
  }

  from {
    configurations.compile.collect {
      it.isDirectory() ? it : zipTree( it )
    }
  }
}  

run {
  systemProperties = System.getProperties()

  if( project.hasProperty( 'args' ) ) {
    args project.args.split()
  }
}

// Configure ANTLR
ext.antlr = [
  grammarPackage: "com.whitemagicsoftware.rxm.grammar",
  antlrSource: "source/grammar",
  destinationDir: "source/antlr"
]

configurations {
  antlr {
    description = "ANTLR4"
  }
}

task antlrOutputDir << {
  mkdir( antlr.destinationDir )
}

// Run ANTLR against the grammar.
task generateGrammarSource( dependsOn: antlrOutputDir, type: JavaExec ) {
  description = "Generates Java sources from ANTLR4 grammars."
  inputs.dir file( antlr.antlrSource )
  outputs.dir file( antlr.destinationDir )
  def grammars = fileTree( antlr.antlrSource ).include( "**/*.g" )
  main = "org.antlr.v4.Tool"
  classpath = configurations.antlr
  def pkg = antlr.grammarPackage.replaceAll( "\\.", "/" )
  args = [
    "-o", "${antlr.destinationDir}/${pkg}"/*,
    "-atn"*/, "-visitor",
    "-package", antlr.grammarPackage, grammars.files
  ].flatten()
}

compileJava {
  dependsOn generateGrammarSource
  source antlr.destinationDir
}

dependencies {
  antlr "org.antlr:antlr4:4.5"
  compile( "org.antlr:antlr4:4.5" )
}

// Only invoke this from the command line to create a libs directory containing
// the dependent JAR files.
task copyToLib(type: Copy) {
  into "lib"
  from configurations.runtime
}

repositories {
  mavenCentral()
}