2016-08-03 13:24:58 -06:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
2016-11-02 10:55:40 -07:00
|
|
|
mavenLocal()
|
2016-08-03 13:24:58 -06:00
|
|
|
jcenter()
|
2016-11-02 10:55:40 -07:00
|
|
|
mavenCentral()
|
2016-08-03 13:24:58 -06:00
|
|
|
}
|
2016-08-19 15:36:00 -06:00
|
|
|
dependencies {
|
|
|
|
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
|
|
|
|
}
|
2016-08-03 13:24:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
plugins {
|
2016-08-16 16:49:37 -06:00
|
|
|
id 'com.github.johnrengelman.shadow' version '1.2.3'
|
|
|
|
id 'me.champeau.gradle.jmh' version '0.3.1'
|
2016-08-03 13:24:58 -06:00
|
|
|
}
|
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
import org.gradle.internal.jvm.Jvm
|
2016-07-08 15:39:40 -06:00
|
|
|
import org.apache.tools.ant.util.TeeOutputStream
|
2016-11-02 10:55:40 -07:00
|
|
|
boolean debug = false
|
2016-07-07 16:45:20 -06:00
|
|
|
|
2016-07-13 16:34:14 -06:00
|
|
|
class Tags {
|
2016-07-28 12:48:23 -06:00
|
|
|
Boolean hasMainMethod = false
|
2016-07-13 16:34:14 -06:00
|
|
|
Boolean compileTimeError = false
|
|
|
|
Boolean throwsException = false
|
|
|
|
Boolean errorOutputExpected = false
|
|
|
|
Boolean validateByHand = false
|
2016-07-14 18:18:02 -06:00
|
|
|
Boolean ignoreOutput = false // This tag isn't used in the build...
|
2016-07-14 13:29:44 -06:00
|
|
|
String fileRoot
|
|
|
|
String mainClass
|
2016-07-13 16:34:14 -06:00
|
|
|
String javaCmd = null
|
2016-07-14 12:23:33 -06:00
|
|
|
List<String> args = []
|
2016-07-14 13:43:54 -06:00
|
|
|
List<String> jVMArgs = []
|
2016-07-28 16:47:35 -06:00
|
|
|
String javap = null
|
2016-07-13 16:34:14 -06:00
|
|
|
String runFirst = null
|
2016-07-18 14:46:40 -06:00
|
|
|
String outputLine = null
|
2016-07-13 16:34:14 -06:00
|
|
|
private String block
|
2016-07-31 02:25:33 -07:00
|
|
|
def Tags(File file) {
|
|
|
|
block = file.text
|
2016-07-28 12:48:23 -06:00
|
|
|
hasMainMethod = block.contains('main(String[] args)')
|
2016-07-31 02:25:33 -07:00
|
|
|
def firstLine = block.substring(0, block.indexOf("\n"))
|
2016-08-01 23:05:22 -07:00
|
|
|
fileRoot = (firstLine.split("/")[-1] - ".java").trim() // Remove \r if it exists
|
2016-07-14 13:29:44 -06:00
|
|
|
mainClass = fileRoot
|
2016-07-27 17:31:28 -06:00
|
|
|
javaCmd = extract('java')
|
|
|
|
if(javaCmd) {
|
2016-07-28 12:48:23 -06:00
|
|
|
def pieces = javaCmd.split()
|
|
|
|
mainClass = pieces[0]
|
|
|
|
if(pieces.size() > 1)
|
|
|
|
for(p in pieces[1..-1])
|
|
|
|
if(p.startsWith("-"))
|
|
|
|
jVMArgs << p
|
|
|
|
else
|
|
|
|
args << p
|
2016-07-27 17:31:28 -06:00
|
|
|
}
|
2016-07-28 12:48:23 -06:00
|
|
|
compileTimeError = hasTag('CompileTimeError')
|
|
|
|
throwsException = hasTag('ThrowsException')
|
|
|
|
errorOutputExpected = hasTag('ErrorOutputExpected')
|
|
|
|
validateByHand = hasTag('ValidateByHand')
|
|
|
|
ignoreOutput = hasTag('IgnoreOutput')
|
2016-07-28 16:55:57 -06:00
|
|
|
javap = extract('javap') // Includes only arguments to command
|
2016-07-13 16:34:14 -06:00
|
|
|
runFirst = extract('RunFirst:')
|
2016-07-31 02:25:33 -07:00
|
|
|
outputLine = extractOutputLine()
|
2016-07-13 16:34:14 -06:00
|
|
|
}
|
2016-07-28 12:48:23 -06:00
|
|
|
private def hasTag(String marker) {
|
2016-07-13 16:34:14 -06:00
|
|
|
return block.contains("// {" + marker + "}")
|
|
|
|
}
|
2016-07-31 02:25:33 -07:00
|
|
|
def extractOutputLine() {
|
2016-07-31 18:11:25 -07:00
|
|
|
def matcher = (block =~ /(?m)^(\/\* Output:.*)$/)
|
|
|
|
if (matcher) {
|
|
|
|
return matcher[0][1]
|
2016-07-31 02:25:33 -07:00
|
|
|
} else {
|
2016-07-31 18:11:25 -07:00
|
|
|
return null
|
2016-07-31 02:25:33 -07:00
|
|
|
}
|
|
|
|
}
|
2016-07-13 16:34:14 -06:00
|
|
|
private def extract(String marker) {
|
2016-07-31 02:25:33 -07:00
|
|
|
// Assume some whitespace is after marker
|
|
|
|
if(!block.contains("// {${marker} "))
|
2016-07-13 16:34:14 -06:00
|
|
|
return null
|
2016-07-31 02:25:33 -07:00
|
|
|
def matcher = (block =~ /\/\/ \{${marker}\s+([^}]+)/)
|
|
|
|
if (matcher) {
|
|
|
|
def matched = matcher[0][1].trim()
|
|
|
|
return matched.replaceAll("\n?//", "")
|
2016-07-13 16:34:14 -06:00
|
|
|
} else {
|
2016-07-31 02:25:33 -07:00
|
|
|
println "Searching for: " + matcher
|
2016-07-13 16:34:14 -06:00
|
|
|
println block
|
|
|
|
System.exit(1)
|
|
|
|
}
|
|
|
|
}
|
2016-07-14 05:59:30 -06:00
|
|
|
public boolean hasTags() {
|
|
|
|
return compileTimeError ||
|
|
|
|
throwsException ||
|
|
|
|
errorOutputExpected ||
|
|
|
|
validateByHand ||
|
|
|
|
ignoreOutput ||
|
|
|
|
javaCmd ||
|
|
|
|
args ||
|
|
|
|
jVMArgs ||
|
2016-07-28 16:47:35 -06:00
|
|
|
javap ||
|
2016-07-14 05:59:30 -06:00
|
|
|
runFirst
|
|
|
|
}
|
2016-07-13 16:34:14 -06:00
|
|
|
public String toString() {
|
|
|
|
String result = ""
|
2016-07-31 02:25:33 -07:00
|
|
|
block.eachLine{ ln ->
|
2016-07-14 05:59:30 -06:00
|
|
|
if(ln.startsWith("//") || ln.startsWith("package "))
|
|
|
|
result += ln + "\n"
|
2016-07-31 02:25:33 -07:00
|
|
|
}
|
2016-07-14 18:18:02 -06:00
|
|
|
"""
|
2016-07-28 12:48:23 -06:00
|
|
|
hasMainMethod
|
2016-07-14 18:18:02 -06:00
|
|
|
compileTimeError
|
|
|
|
throwsException
|
|
|
|
errorOutputExpected
|
|
|
|
validateByHand
|
|
|
|
ignoreOutput
|
|
|
|
fileRoot
|
|
|
|
mainClass
|
|
|
|
javaCmd
|
|
|
|
args
|
|
|
|
jVMArgs
|
2016-07-28 16:47:35 -06:00
|
|
|
javap
|
2016-07-14 18:18:02 -06:00
|
|
|
runFirst
|
|
|
|
""".split().each { str ->
|
|
|
|
if(this[str])
|
|
|
|
result += str + ": " + this[str] + "\n"
|
|
|
|
}
|
|
|
|
result
|
2016-07-13 16:34:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 12:33:38 -06:00
|
|
|
ext {
|
|
|
|
junitJupiterVersion = '5.0.0-M2'
|
|
|
|
}
|
2016-08-19 15:36:00 -06:00
|
|
|
|
2016-10-25 10:19:31 -07:00
|
|
|
compileJava {
|
|
|
|
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:43:10 -06:00
|
|
|
subprojects {
|
2016-08-16 16:49:37 -06:00
|
|
|
apply plugin: 'com.github.johnrengelman.shadow'
|
2016-08-03 13:24:58 -06:00
|
|
|
apply plugin: 'me.champeau.gradle.jmh'
|
2016-07-07 12:43:10 -06:00
|
|
|
apply plugin: 'java'
|
2016-08-19 15:36:00 -06:00
|
|
|
apply plugin: 'org.junit.platform.gradle.plugin'
|
2016-09-01 21:30:15 -06:00
|
|
|
//apply plugin: 'checkstyle'
|
|
|
|
//apply plugin: 'findbugs'
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-07-07 12:43:10 -06:00
|
|
|
sourceCompatibility = '1.8'
|
|
|
|
targetCompatibility = '1.8'
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-07-07 12:43:10 -06:00
|
|
|
repositories {
|
|
|
|
mavenLocal()
|
2016-08-05 14:39:40 -06:00
|
|
|
jcenter()
|
2016-07-07 12:43:10 -06:00
|
|
|
mavenCentral()
|
|
|
|
}
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-08-16 14:23:39 -06:00
|
|
|
dependencies {
|
2016-08-27 10:12:56 -06:00
|
|
|
// Logging:
|
2016-08-16 18:03:29 -06:00
|
|
|
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
|
|
|
|
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
|
|
|
|
// You can also use the JDK's built-in logging as the back end:
|
|
|
|
// compile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.5'
|
2016-08-19 15:36:00 -06:00
|
|
|
|
2016-08-27 10:12:56 -06:00
|
|
|
// JUnit testing:
|
2016-11-02 10:55:40 -07:00
|
|
|
compile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
|
2016-08-27 10:12:56 -06:00
|
|
|
testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
|
|
|
|
testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
|
2016-08-19 15:36:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
junitPlatform {
|
|
|
|
includeClassNamePattern '.*'
|
2016-08-16 14:23:39 -06:00
|
|
|
}
|
|
|
|
|
2016-09-01 14:54:30 -06:00
|
|
|
// See: http://blog.jessitron.com/2012/07/using-checkstyle-in-gradle.html
|
|
|
|
// https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
|
|
|
|
// http://checkstyle.sourceforge.net/reports/google-java-style.html
|
2016-09-01 21:30:15 -06:00
|
|
|
/* checkstyle {
|
|
|
|
// configFile = new File(rootDir, "checkstyle.xml")
|
2016-09-01 14:54:30 -06:00
|
|
|
toolVersion = '6.7'
|
2016-09-01 21:30:15 -06:00
|
|
|
}*/
|
|
|
|
|
|
|
|
/* findbugsMain {
|
|
|
|
reports {
|
|
|
|
xml.enabled = false
|
|
|
|
html.enabled = true
|
|
|
|
}
|
|
|
|
ignoreFailures = true
|
2016-09-01 14:54:30 -06:00
|
|
|
}
|
|
|
|
|
2016-09-01 21:30:15 -06:00
|
|
|
findbugsJmh {
|
|
|
|
reports {
|
|
|
|
xml.enabled = false
|
|
|
|
html.enabled = true
|
|
|
|
}
|
|
|
|
ignoreFailures = true
|
|
|
|
}
|
|
|
|
*/
|
2016-07-07 12:43:10 -06:00
|
|
|
sourceSets {
|
|
|
|
main {
|
|
|
|
java {
|
|
|
|
srcDir projectDir
|
2016-09-01 15:14:44 -06:00
|
|
|
exclude "tests/**"
|
2016-07-07 12:43:10 -06:00
|
|
|
}
|
2016-08-19 17:16:23 -06:00
|
|
|
resources {
|
|
|
|
srcDir projectDir
|
|
|
|
include '*.xml'
|
|
|
|
}
|
2015-12-15 15:35:04 -07:00
|
|
|
}
|
2016-08-05 13:55:39 -06:00
|
|
|
jmh {
|
|
|
|
java {
|
|
|
|
srcDir projectDir
|
|
|
|
}
|
|
|
|
}
|
2016-09-01 15:14:44 -06:00
|
|
|
test {
|
2016-08-19 15:36:00 -06:00
|
|
|
java {
|
2016-09-01 15:14:44 -06:00
|
|
|
srcDir new File(projectDir, "tests")
|
2016-08-19 15:36:00 -06:00
|
|
|
}
|
2016-09-01 15:14:44 -06:00
|
|
|
}
|
2016-08-05 13:55:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
jmh {
|
2016-10-01 10:45:37 -06:00
|
|
|
jmhVersion = '1.15'
|
2016-08-16 16:49:37 -06:00
|
|
|
duplicateClassesStrategy = 'warn'
|
2016-10-25 09:03:51 -07:00
|
|
|
failOnError = true
|
|
|
|
// See https://github.com/melix/jmh-gradle-plugin
|
|
|
|
// for other options
|
2015-12-15 15:35:04 -07:00
|
|
|
}
|
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
List createdTasks = []
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
projectDir.eachFileRecurse { file ->
|
|
|
|
if (file.name.endsWith('.java')) {
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
Tags tags = new Tags(file)
|
2016-11-02 10:55:40 -07:00
|
|
|
if(debug && tags.hasTags()) println tags
|
2015-12-15 15:35:04 -07:00
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
// Exclude java sources that will not compile
|
|
|
|
if (tags.compileTimeError) {
|
2016-07-31 10:21:28 -07:00
|
|
|
sourceSets.main.java.excludes.add(file.name)
|
2016-07-31 02:25:33 -07:00
|
|
|
} else {
|
|
|
|
JavaExec javaTask = null
|
|
|
|
// Add tasks for java sources with main methods
|
|
|
|
if (tags.hasMainMethod || tags.javaCmd) {
|
|
|
|
javaTask = tasks.create(name: tags.fileRoot, type: JavaExec, dependsOn: tags.runFirst) {
|
|
|
|
main = tags.mainClass
|
|
|
|
classpath = sourceSets.main.runtimeClasspath
|
|
|
|
args = tags.args
|
|
|
|
jvmArgs = tags.jVMArgs
|
|
|
|
}
|
|
|
|
} else if (tags.javap) {
|
|
|
|
// Create task for running javap
|
|
|
|
javaTask = tasks.create(name: "${tags.fileRoot}", type: JavaExec, dependsOn: tags.runFirst) {
|
|
|
|
main = "com.sun.tools.javap.Main"
|
|
|
|
classpath = sourceSets.main.runtimeClasspath + files(Jvm.current().toolsJar)
|
|
|
|
// Assuming javap represents all the args and there's no need to jVMArgs
|
|
|
|
args tags.javap.split()
|
|
|
|
}
|
2016-07-07 12:43:10 -06:00
|
|
|
}
|
|
|
|
|
2016-07-31 02:25:33 -07:00
|
|
|
if (javaTask) {
|
|
|
|
def baseName = file.name.substring(0, file.name.lastIndexOf('.'))
|
|
|
|
File outFile = new File(file.parentFile, baseName + '.out')
|
|
|
|
File errFile = new File(file.parentFile, baseName + '.err')
|
|
|
|
|
|
|
|
javaTask.configure {
|
|
|
|
ignoreExitValue = tags.validateByHand || tags.throwsException
|
|
|
|
doFirst {
|
|
|
|
if(outFile.exists())
|
|
|
|
outFile.delete()
|
|
|
|
if(tags.outputLine)
|
|
|
|
outFile << tags.outputLine + "\n"
|
|
|
|
|
|
|
|
standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out)
|
|
|
|
errorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
|
|
|
|
}
|
|
|
|
doLast {
|
|
|
|
if(outFile.size() == 0)
|
|
|
|
outFile.delete()
|
|
|
|
else if(!outFile.text.contains("/* Output:"))
|
|
|
|
outFile.delete()
|
|
|
|
if(errFile.size() == 0) errFile.delete()
|
|
|
|
}
|
2016-07-19 15:42:38 -06:00
|
|
|
}
|
2016-07-31 02:25:33 -07:00
|
|
|
|
|
|
|
if (!tags.validateByHand) {
|
|
|
|
// Only add tasks that we know we can run successfully to the task list
|
|
|
|
createdTasks.add(javaTask)
|
2016-07-19 15:42:38 -06:00
|
|
|
}
|
2016-07-07 12:43:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 02:25:33 -07:00
|
|
|
task run(dependsOn: createdTasks)
|
2016-09-01 17:05:02 -06:00
|
|
|
|
|
|
|
/* Store test output in $projectName/tests
|
|
|
|
JUnit 5's junitPlatformTest runs as a "javaExec" rather than a "test",
|
|
|
|
so we can't hook into the before/after test behavior.
|
|
|
|
*/
|
2016-09-01 21:30:15 -06:00
|
|
|
tasks.findByPath(":$name:junitPlatformTest").configure {
|
|
|
|
File testDir = new File(project.name + "/tests")
|
|
|
|
if(testDir.exists()) {
|
|
|
|
File outFile = new File(testDir, 'report.txt')
|
|
|
|
doFirst {
|
|
|
|
standardOutput = new TeeOutputStream(new FileOutputStream(outFile, true), System.out)
|
|
|
|
}
|
|
|
|
doLast {
|
|
|
|
if(outFile.size() == 0)
|
|
|
|
outFile.delete()
|
|
|
|
else if(outFile.text.contains("0 tests found"))
|
|
|
|
outFile.delete()
|
|
|
|
}
|
2016-09-01 17:05:02 -06:00
|
|
|
}
|
|
|
|
}
|
2015-12-15 15:35:04 -07:00
|
|
|
}
|
|
|
|
|
2016-08-29 07:27:53 -06:00
|
|
|
project(':validating') {
|
2016-08-10 15:38:02 -06:00
|
|
|
jmh {
|
2016-08-29 07:27:53 -06:00
|
|
|
include = 'validating.jmh.*'
|
2016-08-10 15:38:02 -06:00
|
|
|
}
|
2016-08-10 10:36:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
project(':understandingcollections') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':typeinfo')
|
|
|
|
compile project(':collections')
|
|
|
|
}
|
|
|
|
jmh {
|
2016-08-18 11:05:53 -06:00
|
|
|
include = 'understandingcollections.jmh.*'
|
2016-08-10 10:36:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':threads') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':enums')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':strings') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':generics')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':serialization') {
|
|
|
|
configurations.all {
|
|
|
|
resolutionStrategy {
|
|
|
|
force 'xml-apis:xml-apis:1.0.b2'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
compile 'com.io7m.xom:xom:1.2.10'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':interfaces') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':polymorphism')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':hiding') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':com')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':generics') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':typeinfo')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
project(':collections') {
|
|
|
|
dependencies {
|
|
|
|
compile project(':typeinfo')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:43:10 -06:00
|
|
|
configure(subprojects - project(':onjava')) {
|
|
|
|
dependencies {
|
|
|
|
compile project(':onjava')
|
2016-08-15 17:10:52 -06:00
|
|
|
compile group: 'com.google.guava', name: 'guava', version: '19.0'
|
2016-08-09 11:49:57 -06:00
|
|
|
compile "org.openjdk.jmh:jmh-core:${jmh.jmhVersion}"
|
2016-11-02 10:55:40 -07:00
|
|
|
compile 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M2'
|
2016-07-07 12:43:10 -06:00
|
|
|
}
|
|
|
|
}
|
2016-07-22 17:26:49 -06:00
|
|
|
|
2016-08-02 11:00:06 -06:00
|
|
|
task verify(type:Exec) {
|
2016-08-12 13:37:34 -06:00
|
|
|
description 'Uses Python tool to verify example output'
|
2016-08-26 16:34:59 -06:00
|
|
|
commandLine 'python', '_verify_output.py'
|
2016-08-02 11:00:06 -06:00
|
|
|
doFirst {
|
|
|
|
println("execute 'gradlew run' first")
|
|
|
|
}
|
2016-07-22 17:26:49 -06:00
|
|
|
}
|