Further towards use of Tags class
This commit is contained in:
parent
6c93ba2268
commit
74d0a678b4
38
build.gradle
38
build.gradle
@ -7,6 +7,8 @@ class Tags {
|
|||||||
Boolean errorOutputExpected = false
|
Boolean errorOutputExpected = false
|
||||||
Boolean validateByHand = false
|
Boolean validateByHand = false
|
||||||
Boolean ignoreOutput = false // probably don't need this tag
|
Boolean ignoreOutput = false // probably don't need this tag
|
||||||
|
String fileRoot
|
||||||
|
String mainClass
|
||||||
String javaCmd = null
|
String javaCmd = null
|
||||||
List<String> args = []
|
List<String> args = []
|
||||||
String jVMArgs = null
|
String jVMArgs = null
|
||||||
@ -18,14 +20,19 @@ class Tags {
|
|||||||
this.lines = lines
|
this.lines = lines
|
||||||
block = lines.join('')
|
block = lines.join('')
|
||||||
mainMethod = block.contains('main(String[] args)')
|
mainMethod = block.contains('main(String[] args)')
|
||||||
|
fileRoot = lines[0].split("/")[-1] - ".java"
|
||||||
|
mainClass = fileRoot
|
||||||
|
javaCmd = extract('main:')
|
||||||
|
if(javaCmd)
|
||||||
|
mainClass = javaCmd
|
||||||
compileTimeError = testFor('CompileTimeError')
|
compileTimeError = testFor('CompileTimeError')
|
||||||
throwsException = testFor('ThrowsException')
|
throwsException = testFor('ThrowsException')
|
||||||
errorOutputExpected = testFor('ErrorOutputExpected')
|
errorOutputExpected = testFor('ErrorOutputExpected')
|
||||||
validateByHand = testFor('ValidateByHand')
|
validateByHand = testFor('ValidateByHand')
|
||||||
ignoreOutput = testFor('IgnoreOutput')
|
ignoreOutput = testFor('IgnoreOutput')
|
||||||
javaCmd = extract('main:')
|
|
||||||
def argString = extract('Args:')
|
def argString = extract('Args:')
|
||||||
if(argString) args = argString.split(' ')
|
if(argString)
|
||||||
|
args = argString.split(' ')
|
||||||
jVMArgs = extract('JVMArgs:')
|
jVMArgs = extract('JVMArgs:')
|
||||||
exec = extract('Exec:')
|
exec = extract('Exec:')
|
||||||
runFirst = extract('RunFirst:')
|
runFirst = extract('RunFirst:')
|
||||||
@ -39,11 +46,7 @@ class Tags {
|
|||||||
def re = "\\/\\/ \\{" + marker + /[^}]+}/
|
def re = "\\/\\/ \\{" + marker + /[^}]+}/
|
||||||
def tagline = block =~ re
|
def tagline = block =~ re
|
||||||
if(tagline.getCount()) {
|
if(tagline.getCount()) {
|
||||||
if(block.contains("TestRegularExpression"))
|
|
||||||
println tagline[0]
|
|
||||||
def rtrim = tagline[0].reverse().dropWhile{ it != '}'}.reverse()[0..-2]
|
def rtrim = tagline[0].reverse().dropWhile{ it != '}'}.reverse()[0..-2]
|
||||||
if(block.contains("TestRegularExpression"))
|
|
||||||
println rtrim
|
|
||||||
def ltrim = rtrim - ("// {" + marker)
|
def ltrim = rtrim - ("// {" + marker)
|
||||||
return ltrim.trim()
|
return ltrim.trim()
|
||||||
} else {
|
} else {
|
||||||
@ -130,26 +133,9 @@ subprojects {
|
|||||||
// Add tasks for java sources with main methods
|
// Add tasks for java sources with main methods
|
||||||
if ((tags.mainMethod || tags.javaCmd) && (!tags.compileTimeError)) {
|
if ((tags.mainMethod || tags.javaCmd) && (!tags.compileTimeError)) {
|
||||||
|
|
||||||
/* String maybeArgsLine = lines.find { it.startsWith('// {Args: ')}
|
|
||||||
|
|
||||||
List maybeArgs = []
|
|
||||||
if (maybeArgsLine != null) {
|
|
||||||
maybeArgs = maybeArgsLine.trim().replaceAll('\\/\\/ \\{Args: ', '').reverse().replaceFirst('}', '').reverse().split(' ')
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
String mainClass = it.name.replaceAll('.java', '')
|
|
||||||
|
|
||||||
String taskName = mainClass
|
|
||||||
|
|
||||||
if (!tags.validateByHand) {
|
if (!tags.validateByHand) {
|
||||||
// only add tasks that we know we can run successfully to the task list
|
// only add tasks that we know we can run successfully to the task list
|
||||||
tasks.add(taskName)
|
tasks.add(tags.fileRoot)
|
||||||
}
|
|
||||||
|
|
||||||
// some java sources with a main method specify a different main class
|
|
||||||
String maybeMainLine = lines.find { it.startsWith('// {main: ')}
|
|
||||||
if (maybeMainLine != null) {
|
|
||||||
mainClass = maybeMainLine.trim().replaceAll('\\/\\/ \\{main: ', '').replaceAll('}', '')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// some java sources with JVM args
|
// some java sources with JVM args
|
||||||
@ -178,8 +164,8 @@ subprojects {
|
|||||||
|
|
||||||
OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
|
OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
|
||||||
|
|
||||||
task "$taskName"(type: JavaExec, dependsOn: maybeRunFirst) {
|
task "$tags.fileRoot"(type: JavaExec, dependsOn: maybeRunFirst) {
|
||||||
main = mainClass
|
main = tags.mainClass
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
args = tags.args
|
args = tags.args
|
||||||
jvmArgs = maybeJvmArgs
|
jvmArgs = maybeJvmArgs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user