mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Put the javac command in a file.
Also introduce fixSlashes().
This commit is contained in:
parent
771f90332c
commit
4e4c5a7d9e
5 changed files with 15 additions and 8 deletions
|
@ -65,7 +65,7 @@ class JarUtils {
|
||||||
entry = stream.nextEntry
|
entry = stream.nextEntry
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val entryFileName = file.to(foundFile.path).path.replace("\\", "/")
|
val entryFileName = KFiles.fixSlashes(file.to(foundFile.path))
|
||||||
val entry = JarEntry(entryFileName)
|
val entry = JarEntry(entryFileName)
|
||||||
entry.time = localFile.lastModified()
|
entry.time = localFile.lastModified()
|
||||||
addEntry(FileInputStream(localFile), entry, outputStream, onError)
|
addEntry(FileInputStream(localFile), entry, outputStream, onError)
|
||||||
|
|
|
@ -115,6 +115,9 @@ class KFiles {
|
||||||
*/
|
*/
|
||||||
fun joinFileAndMakeDir(vararg ts: String) = joinDir(joinAndMakeDir(ts.slice(0..ts.size - 2)), ts[ts.size - 1])
|
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) =
|
fun makeDir(dir: String, s: String? = null) =
|
||||||
(if (s != null) File(dir, s) else File(dir)).apply { mkdirs() }
|
(if (s != null) File(dir, s) else File(dir)).apply { mkdirs() }
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.beust.kobalt.homeDir
|
||||||
import com.beust.kobalt.internal.GraphUtil
|
import com.beust.kobalt.internal.GraphUtil
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
import com.beust.kobalt.maven.aether.Exceptions
|
import com.beust.kobalt.maven.aether.Exceptions
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.inject.Guice
|
import com.google.inject.Guice
|
||||||
|
@ -31,7 +32,7 @@ class KobaltClient : Runnable {
|
||||||
val client = OkHttpClient()
|
val client = OkHttpClient()
|
||||||
val port = KobaltServer.port ?: 1240
|
val port = KobaltServer.port ?: 1240
|
||||||
val url = "ws://localhost:$port/v1/getDependencyGraph"
|
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()
|
val request = Request.Builder()
|
||||||
// .url("ws://echo.websocket.org")
|
// .url("ws://echo.websocket.org")
|
||||||
.url("$url?buildFile=$buildFile")
|
.url("$url?buildFile=$buildFile")
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.google.inject.Inject
|
||||||
import com.google.inject.Singleton
|
import com.google.inject.Singleton
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
|
import java.nio.file.Files
|
||||||
import javax.tools.DiagnosticCollector
|
import javax.tools.DiagnosticCollector
|
||||||
import javax.tools.JavaFileObject
|
import javax.tools.JavaFileObject
|
||||||
import javax.tools.ToolProvider
|
import javax.tools.ToolProvider
|
||||||
|
@ -77,11 +78,13 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltL
|
||||||
allArgs.addAll(info.compilerArgs)
|
allArgs.addAll(info.compilerArgs)
|
||||||
allArgs.addAll(info.sourceFiles.filter { File(it).isFile })
|
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()
|
pb.inheritIO()
|
||||||
val line = allArgs.joinToString(" ")
|
|
||||||
logk(1, " Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
|
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(" ")
|
command = allArgs.joinToString(" ") + " " + info.sourceFiles.joinToString(" ")
|
||||||
val process = pb.start()
|
val process = pb.start()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.internal.KobaltPluginXml
|
import com.beust.kobalt.internal.KobaltPluginXml
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import org.testng.annotations.BeforeClass
|
import org.testng.annotations.BeforeClass
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -27,7 +28,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
*/
|
*/
|
||||||
fun compileSingleProject(projectText: String, args: Args = Args()) : Project {
|
fun compileSingleProject(projectText: String, args: Args = Args()) : Project {
|
||||||
val projectName = "p" + Math.abs(Random().nextInt())
|
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= """
|
val buildFileText= """
|
||||||
import com.beust.kobalt.*
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.*
|
||||||
|
@ -87,7 +88,6 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
forceRecompile = true)
|
forceRecompile = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createTemporaryProjectDirectory() = Files.createTempDirectory("kobaltTest").toFile().path
|
fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
|
||||||
.replace("\\", "/")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue