You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val outFile =File(project.file(outputDir), spec.output)
128
+
val outFile =resolveFile(project.file(outputDir), spec.output!!)
120
129
121
-
if (project.logger.isInfoEnabled) {
122
-
project.logger.info("Generating ${spec.name} as '${spec.output}' as '${outFile}'")
123
-
} else {
124
-
project.logger.lifecycle("Generating ${spec.name} as '${spec.output}'")
125
-
}
126
130
if (spec.generator !=null) {
127
131
val gname = spec.generator
128
132
val generatorClass = classLoader.loadClass(gname)
129
-
if (!outFile.isFile) {
130
-
outFile.parentFile.mkdirs()
133
+
if (outFile.isDirectory) throwInvalidUserDataException("The output can not be a directory, it must be a file ($outFile)")
134
+
if (!outFile.exists()) {
135
+
outFile.parentFile.apply { if (! exists()) mkdirs() ||throwInvalidUserDataException("The target directory for the output file $outFile could not be created")}
131
136
outFile.createNewFile()
132
137
}
138
+
if (!outFile.canWrite()) throwInvalidUserDataException("The output file ($outFile) is not writeable.")
133
139
134
-
val m = generatorClass.getGenerateMethod(spec.input)
135
-
val generatorInst =if (Modifier.isStatic(m.modifiers)) nullelse generatorClass.newInstance()
136
-
outFile.writer().use { writer ->
137
-
if (m.parameterCount ==2) {
138
-
m.invoke(generatorInst, writer, spec.input)
139
-
} else {
140
-
m.invoke(generatorInst, writer)
141
-
}
140
+
if (project.logger.isInfoEnabled) {
141
+
project.logger.info("Generating ${spec.name} as '${spec.output}' as '${outFile}'")
142
+
} else {
143
+
project.logger.lifecycle("Generating ${spec.name} as '${spec.output}'")
142
144
}
143
145
146
+
val baseError ="""
147
+
Generators must have a unique public method "doGenerate(Writer|Appendable, [Object])"
148
+
where the second parameter is optional iff the input is null. If not a static
149
+
method, the class must have a noArg constructor.""".trimIndent()
.filter { if (input==null) it.parameterCount in1..2else it.parameterCount==2 }
184
-
.let {
185
-
val candidates = it.toList()
186
-
candidates.asSequence().filter { (File::class.java==it.parameterTypes[0].apply { project.logger.debug("Rejecting $it as the first parameter is not a file") }) }
187
-
.filter { if (it.parameterCount==1) trueelse isSecondParameterCompatible(input, it) }
188
-
.singleOrNull() ?:throwNoSuchMethodError("""
189
-
Generators must have a unique public method "doGenerate(File, [Object])"
190
-
where the second parameter is optional iff the input is null. If not a static
191
-
method, the class must have a noArg constructor.
192
-
193
-
Candidates were (with input = ${input?.javaClass?.name?:"null"}):
0 commit comments