mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
IDEA template.
This commit is contained in:
parent
d7a86df947
commit
c1c87d976d
2 changed files with 39 additions and 16 deletions
|
@ -265,7 +265,7 @@ class KFiles {
|
|||
|
||||
fun copy(from: InputStream, to: OutputStream) {
|
||||
var read = from.read()
|
||||
while (from.available() > 0 && read != -1) {
|
||||
while (read != -1) {
|
||||
to.write(read)
|
||||
read = from.read()
|
||||
}
|
||||
|
|
|
@ -26,13 +26,14 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
|
||||
companion object {
|
||||
val IDEA_DIR = File(".idea").apply { mkdirs() }
|
||||
val KOTLIN_JAVA_RUNTIME = "KotlinJavaRuntime"
|
||||
}
|
||||
|
||||
override fun generateTemplate(args: Args, classLoader: ClassLoader) {
|
||||
val dependencyData = Kobalt.INJECTOR.getInstance(DependencyData::class.java)
|
||||
val data = dependencyData.dependenciesDataFor(Constants.BUILD_FILE_PATH, args)
|
||||
val outputDir = File(".")// KFiles.makeDir(".")//KFiles.makeDir(homeDir("t/idea"))
|
||||
generateLibraries(data, outputDir)
|
||||
generateLibraries(classLoader, data, outputDir)
|
||||
generateModulesXml(data, outputDir)
|
||||
generateImlFiles(classLoader, data, outputDir)
|
||||
generateMiscXml(classLoader, outputDir)
|
||||
|
@ -42,7 +43,6 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
KFiles.joinDir(ITemplateContributor.DIRECTORY_NAME, templateName, fileName)
|
||||
|
||||
private fun writeTemplate(classLoader: ClassLoader, outputDir: File, fileName: String) {
|
||||
log(2, "Opening template " + templatePath(fileName))
|
||||
val ins = classLoader.getResource(templatePath(fileName)).openConnection().inputStream
|
||||
val outputFile = File(KFiles.joinDir(outputDir.absolutePath, fileName))
|
||||
outputFile.parentFile.mkdir()
|
||||
|
@ -82,10 +82,10 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
fun sourceDir(dir: String, isTest: Boolean)
|
||||
= " <sourceFolder url=\"file://\$MODULE_DIR$/$dir\" isTestSource=\"$isTest\" />"
|
||||
|
||||
project.sourceDirs.forEach { sourceDir ->
|
||||
project.sourceDirs.filter { File(it).exists() }.forEach { sourceDir ->
|
||||
add(sourceDir(sourceDir, false))
|
||||
}
|
||||
project.testDirs.forEach { sourceDir ->
|
||||
project.testDirs.filter { File(it).exists() }.forEach { sourceDir ->
|
||||
add(sourceDir(sourceDir, true))
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,13 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
(project.name + TEST_SUFFIX).let {
|
||||
add(" <orderEntry type=\"library\" scope=\"TEST\" name=\"$it\" level=\"project\" />")
|
||||
}
|
||||
val isKotlin = true
|
||||
if (isKotlin) {
|
||||
add(" <orderEntry type=\"library\" name=\"$KOTLIN_JAVA_RUNTIME\"" +
|
||||
" level=\"project\" />")
|
||||
add(" <orderEntry type=\"library\" scope=\"TEST\" name=\"$KOTLIN_JAVA_RUNTIME\"" +
|
||||
" level=\"project\" />")
|
||||
}
|
||||
|
||||
//
|
||||
// Dependent projects
|
||||
|
@ -148,18 +155,19 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
private val COMPILE_SUFFIX = " (Compile)"
|
||||
private val TEST_SUFFIX = " (Test)"
|
||||
|
||||
private fun generateLibraries(data: DependencyData.GetDependenciesData, outputDir: File) {
|
||||
private fun generateLibraries(classLoader: ClassLoader, data: DependencyData.GetDependenciesData, outputDir: File) {
|
||||
data.projects.forEach {
|
||||
generateLibrary(it.name, it.compileDependencies, COMPILE_SUFFIX, outputDir)
|
||||
generateLibrary(it.name, it.testDependencies, TEST_SUFFIX, outputDir)
|
||||
generateLibrary(classLoader, it.name, it.compileDependencies, COMPILE_SUFFIX, outputDir)
|
||||
generateLibrary(classLoader, it.name, it.testDependencies, TEST_SUFFIX, outputDir)
|
||||
}
|
||||
val kobaltDd = DependencyData.DependencyData("kobalt", "compile",
|
||||
KFiles.joinDir(KFiles.distributionsDir, Kobalt.version, "kobalt", "wrapper",
|
||||
"kobalt-${Kobalt.version}.jar"))
|
||||
generateLibrary("kobalt.jar", listOf(kobaltDd), "", outputDir)
|
||||
generateLibrary(classLoader, "kobalt.jar", listOf(kobaltDd), "", outputDir)
|
||||
}
|
||||
|
||||
private fun generateLibrary(name: String, compileDependencies: List<DependencyData.DependencyData>,
|
||||
private fun generateLibrary(classLoader: ClassLoader, name: String,
|
||||
compileDependencies: List<DependencyData .DependencyData>,
|
||||
suffix: String, outputDir: File) {
|
||||
val libraryName = name + suffix
|
||||
val librariesOutputDir = KFiles.joinAndMakeDir(IDEA_DIR.path, outputDir.path, "libraries")
|
||||
|
@ -175,6 +183,10 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
.replace(".", "_")
|
||||
writeFile(this, File(librariesOutputDir, fileName + ".xml"))
|
||||
}
|
||||
|
||||
if (compileDependencies.any { it.id.contains("kotlin") }) {
|
||||
generateKotlinJavaRuntime(classLoader, outputDir)
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateList(libraries: List<DependencyData.DependencyData>, tag: String) : List<String> {
|
||||
|
@ -200,6 +212,17 @@ class IdeaFilesTemplate @Inject constructor() : ITemplate {
|
|||
}
|
||||
}
|
||||
|
||||
private fun generateKotlinJavaRuntime(classLoader: ClassLoader, outputDir: File) {
|
||||
writeTemplate(classLoader,
|
||||
File(KFiles.joinDir(outputDir.path, IDEA_DIR.path, "libraries")), "KotlinJavaRuntime.xml")
|
||||
with(File(outputDir.path, "lib")) {
|
||||
mkdirs()
|
||||
listOf("reflect", "runtime-sources", "runtime").forEach {
|
||||
writeTemplate(classLoader, File(outputDir, path), "kotlin-$it.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeFile(lines: List<String>, file: File) {
|
||||
file.writeText(lines.joinToString("\n"))
|
||||
log(2, "Created ${file.absolutePath}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue