Gunslingor
07/15/2020, 3:01 PMFile file = new File(
getClass().getClassLoader().getResource("database.properties").getFile()
);
Is this really the best way to access files in the resources folder?natpryce
07/15/2020, 3:26 PMtddmonkey
07/15/2020, 4:03 PMgetResourceAsStream
(if memory serves)Gunslingor
07/16/2020, 4:14 AMtddmonkey
07/16/2020, 7:10 AMGunslingor
07/16/2020, 6:34 PMGunslingor
07/16/2020, 6:52 PMfun String.runCommand(workingDir: File): String? {
try {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
proc.waitFor(60, TimeUnit.MINUTES)
return proc.inputStream.bufferedReader().readText()
} catch(e: IOException) {
e.printStackTrace()
return null
}
}
class DockerImageApi(val workingDir: File) {
fun build(tagName: String, fileName: String): String? {
return "docker image build -t $tagName -f $fileName .".runCommand(workingDir)
}
}
class DockerApi(val workingDir: File) {
val image = DockerImageApi(workingDir)
val images = fun (): String?{
return "docker images".runCommand(workingDir)
}
}
fun main(){
val dockerFile = File(DockerApi::class.java.classLoader.getResource("dockerfiles")!!.file)
val docker = DockerApi(dockerFile)
println(docker.images())
println(docker.image.build("test2", "svrDB"))
println(docker.images())
}
tddmonkey
07/17/2020, 7:44 AM