3
0
KCauldronX/buildSrc/src/main/groovy/kcauldron/InstallBundle.groovy

65 lines
1.6 KiB
Groovy
Raw Normal View History

2015-06-09 04:01:23 +00:00
package kcauldron
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.tasks.*
2015-06-09 04:01:23 +00:00
class InstallBundle extends DefaultTask {
@InputFile
def File serverJar
@InputFiles
def ConfigurableFileCollection bootstrapClasspath
@Input
def String bootstrapMain
InstallBundle() {
bootstrapClasspath = project.files()
}
def bootstrapClasspath(Object... args) {
bootstrapClasspath.from args
}
2015-06-09 04:01:23 +00:00
@OutputDirectory
def File getInstallLocation() {
new File(project.buildDir, 'bundle')
}
@TaskAction
def install() {
installLocation.deleteDir()
installLocation.mkdirs()
2017-07-23 06:14:27 +00:00
def cp = bootstrapClasspath
2015-06-09 04:01:23 +00:00
for (int i = 0; i < 3; i++) {
def result = project.javaexec { it ->
2015-06-09 04:01:23 +00:00
workingDir installLocation
classpath cp
main bootstrapMain
args '--serverDir', installLocation.canonicalPath,
'--installServer', serverJar.canonicalFile,
'--binDir', 'libraries'
2015-06-09 04:01:23 +00:00
}
if (result.exitValue == 0) return
}
throw new GradleException("Failed to install bundle into ${installLocation}")
}
private static final class NopOutputStream extends OutputStream {
@Override
void write(byte[] b, int off, int len) throws IOException {
}
@Override
void write(byte[] b) throws IOException {
}
@Override
void write(int b) throws IOException {
}
}
}