1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Put the javac command in a file.

Also introduce fixSlashes().
This commit is contained in:
Cedric Beust 2017-03-24 23:42:41 -07:00
parent 771f90332c
commit 4e4c5a7d9e
5 changed files with 15 additions and 8 deletions

View file

@ -65,7 +65,7 @@ class JarUtils {
entry = stream.nextEntry
}
} else {
val entryFileName = file.to(foundFile.path).path.replace("\\", "/")
val entryFileName = KFiles.fixSlashes(file.to(foundFile.path))
val entry = JarEntry(entryFileName)
entry.time = localFile.lastModified()
addEntry(FileInputStream(localFile), entry, outputStream, onError)

View file

@ -115,6 +115,9 @@ class KFiles {
*/
fun joinFileAndMakeDir(vararg ts: String) = joinDir(joinAndMakeDir(ts.slice(0..ts.size - 2)), ts[ts.size - 1])
fun fixSlashes(f: File) = KFiles.fixSlashes(f.path)
fun fixSlashes(s: String) = s.replace('\\', '/')
fun makeDir(dir: String, s: String? = null) =
(if (s != null) File(dir, s) else File(dir)).apply { mkdirs() }

View file

@ -8,6 +8,7 @@ import com.beust.kobalt.homeDir
import com.beust.kobalt.internal.GraphUtil
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.maven.aether.Exceptions
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.warn
import com.google.gson.Gson
import com.google.inject.Guice
@ -31,7 +32,7 @@ class KobaltClient : Runnable {
val client = OkHttpClient()
val port = KobaltServer.port ?: 1240
val url = "ws://localhost:$port/v1/getDependencyGraph"
val buildFile = homeDir("kotlin/kobalt/kobalt/src/Build.kt").replace("\\", "/")
val buildFile = KFiles.fixSlashes(homeDir("kotlin/kobalt/kobalt/src/Build.kt"))
val request = Request.Builder()
// .url("ws://echo.websocket.org")
.url("$url?buildFile=$buildFile")

View file

@ -15,6 +15,7 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.io.File
import java.io.PrintWriter
import java.nio.file.Files
import javax.tools.DiagnosticCollector
import javax.tools.JavaFileObject
import javax.tools.ToolProvider
@ -77,11 +78,13 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
allArgs.addAll(info.compilerArgs)
allArgs.addAll(info.sourceFiles.filter { File(it).isFile })
val pb = ProcessBuilder(allArgs)
val dir = Files.createTempDirectory("kobalt").toFile()
val atFile = File(dir, "javac-" + project?.name + ".txt")
atFile.writeText(KFiles.fixSlashes(allArgs.subList(1, allArgs.size).joinToString(" ")))
val pb = ProcessBuilder(executable.absolutePath, "@" + KFiles.fixSlashes(atFile))
pb.inheritIO()
val line = allArgs.joinToString(" ")
logk(1, " Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
logk(2, " Java compiling $line")
logk(2, " Java compiling file: " + KFiles.fixSlashes(atFile))
command = allArgs.joinToString(" ") + " " + info.sourceFiles.joinToString(" ")
val process = pb.start()

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.KobaltPluginXml
import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import org.testng.annotations.BeforeClass
import java.io.File
@ -27,7 +28,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
*/
fun compileSingleProject(projectText: String, args: Args = Args()) : Project {
val projectName = "p" + Math.abs(Random().nextInt())
val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path.replace("\\", "/")
val projectDirectory = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
val buildFileText= """
import com.beust.kobalt.*
import com.beust.kobalt.api.*
@ -87,7 +88,6 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
forceRecompile = true)
}
fun createTemporaryProjectDirectory() = Files.createTempDirectory("kobaltTest").toFile().path
.replace("\\", "/")
fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
}