Skip to content

Commit b21359e

Browse files
committed
Evolving towards using the Tag class
1 parent 28f14fa commit b21359e

1 file changed

Lines changed: 37 additions & 54 deletions

File tree

build.gradle

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Tags {
88
Boolean validateByHand = false
99
Boolean ignoreOutput = false // probably don't need this tag
1010
String javaCmd = null
11-
String args = null
11+
List<String> args = []
1212
String jVMArgs = null
1313
String exec = null
1414
String runFirst = null
@@ -24,7 +24,8 @@ class Tags {
2424
validateByHand = testFor('ValidateByHand')
2525
ignoreOutput = testFor('IgnoreOutput')
2626
javaCmd = extract('main:')
27-
args = extract('Args:')
27+
def argString = extract('Args:')
28+
if(argString) args = argString.split(' ')
2829
jVMArgs = extract('JVMArgs:')
2930
exec = extract('Exec:')
3031
runFirst = extract('RunFirst:')
@@ -38,7 +39,11 @@ class Tags {
3839
def re = "\\/\\/ \\{" + marker + /[^}]+}/
3940
def tagline = block =~ re
4041
if(tagline.getCount()) {
41-
def rtrim = tagline[0] - "}"
42+
if(block.contains("TestRegularExpression"))
43+
println tagline[0]
44+
def rtrim = tagline[0].reverse().dropWhile{ it != '}'}.reverse()[0..-2]
45+
if(block.contains("TestRegularExpression"))
46+
println rtrim
4247
def ltrim = rtrim - ("// {" + marker)
4348
return ltrim.trim()
4449
} else {
@@ -120,30 +125,23 @@ subprojects {
120125
List lines = it.readLines()
121126

122127
Tags tags = new Tags(lines) // Not used yet; just for demo
123-
if(tags.hasTags())
124-
println tags
125-
126-
Boolean hasMainMethod = lines.join('').contains('main(String[] args)')
127-
Boolean hasMainParam = lines.find { it.startsWith('// {main: ')}
128-
Boolean willNotCompile = lines.find { it.startsWith('// {CompileTimeError') }
129-
Boolean validateByHand = lines.find { it.startsWith('// {ValidateByHand}') }
130-
Boolean throwsException = lines.find { it.startsWith('// {ThrowsException}') }
128+
// if(tags.hasTags()) println tags // Trace output for debugging
131129

132130
// Add tasks for java sources with main methods
133-
if ((hasMainMethod || hasMainParam) && (!willNotCompile)) {
131+
if ((tags.mainMethod || tags.javaCmd) && (!tags.compileTimeError)) {
134132

135-
String maybeArgsLine = lines.find { it.startsWith('// {Args: ')}
133+
/* String maybeArgsLine = lines.find { it.startsWith('// {Args: ')}
136134
137135
List maybeArgs = []
138136
if (maybeArgsLine != null) {
139137
maybeArgs = maybeArgsLine.trim().replaceAll('\\/\\/ \\{Args: ', '').reverse().replaceFirst('}', '').reverse().split(' ')
140138
}
141-
139+
*/
142140
String mainClass = it.name.replaceAll('.java', '')
143141

144142
String taskName = mainClass
145143

146-
if (!validateByHand) {
144+
if (!tags.validateByHand) {
147145
// only add tasks that we know we can run successfully to the task list
148146
tasks.add(taskName)
149147
}
@@ -168,51 +166,36 @@ subprojects {
168166
maybeRunFirst = maybeRunFirstLine.trim().replaceAll('\\/\\/ \\{RunFirst: ', '').replaceAll('}', '')
169167
}
170168

171-
// some java apps intentionally throw an exception
172-
Boolean maybeIgnoreExitValue = (validateByHand || throwsException)
169+
// Some java apps intentionally throw an exception
170+
Boolean maybeIgnoreExitValue = (tags.validateByHand || tags.throwsException)
173171

174-
// some java apps need a timeout
175-
Boolean timeOutDuringTesting = false
176-
if (lines.find { it.startsWith('// {TimeOutDuringTesting}') } != null) {
177-
timeOutDuringTesting = true
178-
}
172+
String basePath = it.absolutePath.replaceAll('\\.java', '')
179173

180-
// create run and test tasks
181-
if (timeOutDuringTesting) {
182-
// todo: apps with timeOutDuringTesting need special handling
183-
task "$taskName" << {
184-
println "not implemented"
185-
}
186-
}
187-
else {
188-
String basePath = it.absolutePath.replaceAll('\\.java', '')
189-
190-
File outFile = new File(basePath + '.out')
191-
File errFile = new File(basePath + '.err')
192-
193-
OutputStream runStandardOutput = new TeeOutputStream(new FileOutputStream(outFile), System.out)
194-
195-
OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
196-
197-
task "$taskName"(type: JavaExec, dependsOn: maybeRunFirst) {
198-
main = mainClass
199-
classpath = sourceSets.main.runtimeClasspath
200-
args = maybeArgs
201-
jvmArgs = maybeJvmArgs
202-
ignoreExitValue = maybeIgnoreExitValue
203-
standardOutput = runStandardOutput
204-
errorOutput = runErrorOutput
205-
} << {
206-
runStandardOutput.close()
207-
runErrorOutput.close()
208-
if (outFile.size() == 0) outFile.delete()
209-
if (errFile.size() == 0) errFile.delete()
210-
}
174+
File outFile = new File(basePath + '.out')
175+
File errFile = new File(basePath + '.err')
176+
177+
OutputStream runStandardOutput = new TeeOutputStream(new FileOutputStream(outFile), System.out)
178+
179+
OutputStream runErrorOutput = new TeeOutputStream(new FileOutputStream(errFile), System.err)
180+
181+
task "$taskName"(type: JavaExec, dependsOn: maybeRunFirst) {
182+
main = mainClass
183+
classpath = sourceSets.main.runtimeClasspath
184+
args = tags.args
185+
jvmArgs = maybeJvmArgs
186+
ignoreExitValue = maybeIgnoreExitValue
187+
standardOutput = runStandardOutput
188+
errorOutput = runErrorOutput
189+
} << {
190+
runStandardOutput.close()
191+
runErrorOutput.close()
192+
if (outFile.size() == 0) outFile.delete()
193+
if (errFile.size() == 0) errFile.delete()
211194
}
212195
}
213196

214197
// exclude java sources that will not compile
215-
if (willNotCompile) {
198+
if (tags.compileTimeError) {
216199
sourceSets.main.java.excludes.add(it.name)
217200
}
218201
}

0 commit comments

Comments
 (0)