mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
726ddc37d5
22 changed files with 354 additions and 491 deletions
|
@ -32,17 +32,15 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
|||
val newLine: Boolean)
|
||||
private val logLines = ConcurrentHashMap<CharSequence, ArrayList<LogLine>>()
|
||||
|
||||
private val runningProjects = ConcurrentLinkedQueue<CharSequence>()
|
||||
private val runningProjects = ConcurrentLinkedQueue<String>()
|
||||
var startTime: Long? = null
|
||||
|
||||
fun onProjectStarted(name: String) {
|
||||
if (startTime == null) {
|
||||
startTime = System.currentTimeMillis()
|
||||
}
|
||||
if (! runningProjects.contains(name)) {
|
||||
runningProjects.add(name)
|
||||
logLines[name] = arrayListOf()
|
||||
}
|
||||
runningProjects.add(name)
|
||||
logLines[name] = arrayListOf()
|
||||
if (currentName == null) {
|
||||
currentName = name
|
||||
}
|
||||
|
@ -76,7 +74,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
|||
}
|
||||
|
||||
val LOCK = Any()
|
||||
var currentName: CharSequence? = null
|
||||
var currentName: String? = null
|
||||
set(newName) {
|
||||
field = newName
|
||||
}
|
||||
|
@ -121,9 +119,6 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
|||
if (args.sequential) {
|
||||
kobaltLog(level, message, newLine)
|
||||
} else {
|
||||
if (! runningProjects.contains(tag)) {
|
||||
runningProjects.add(tag)
|
||||
}
|
||||
addLogLine(tag, LogLine(tag, level, message, Type.LOG, newLine))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package com.beust.kobalt.internal.build
|
||||
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
/**
|
||||
* Sometimes, build files are moved to temporary files, so we give them a specific name for clarity.
|
||||
* @param path is the path where that file was moved, @param realPath is where the actual file is.
|
||||
|
@ -12,23 +10,5 @@ import java.nio.file.attribute.BasicFileAttributes
|
|||
class BuildFile(val path: Path, val name: String, val realPath: Path = path) {
|
||||
fun exists() : Boolean = Files.exists(path)
|
||||
|
||||
val lastModified : Long
|
||||
get() = Files.readAttributes(realPath, BasicFileAttributes::class.java).lastModifiedTime().toMillis()
|
||||
|
||||
val directory : File get() = path.toFile().parentFile
|
||||
|
||||
/**
|
||||
* @return the .kobalt directory where this build file will be compiled.
|
||||
*/
|
||||
val dotKobaltDir: File get() = File(directory.parentFile.parentFile, KFiles.KOBALT_DOT_DIR).apply {
|
||||
mkdirs()
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the absolute directory of this project's location, assuming the build file is in
|
||||
* $project/kobalt/src/Build.kt.
|
||||
*/
|
||||
val absoluteDir : File? get() {
|
||||
return path.parent?.parent?.parent?.toFile()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package com.beust.kobalt.internal.build
|
||||
|
||||
import com.beust.kobalt.homeDir
|
||||
import java.io.File
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
interface IBuildSources {
|
||||
fun findSourceFiles() : List<File>
|
||||
val root: File
|
||||
fun exists(): Boolean
|
||||
}
|
||||
|
||||
class SingleFileBuildSources(val file: File) : IBuildSources {
|
||||
override fun exists() = file.exists()
|
||||
override fun findSourceFiles() = listOf(file)
|
||||
override val root: File = file.parentFile.parentFile
|
||||
}
|
||||
|
||||
class BuildSources(val file: File) : IBuildSources {
|
||||
|
||||
override val root = file
|
||||
|
||||
override fun findSourceFiles() : List<File> {
|
||||
return listOf(/* "kobalt/src/a.kt", */ "kobalt/src/Build.kt")
|
||||
.map(::File)
|
||||
// .map { BuildFile(Paths.get(it), it)}
|
||||
}
|
||||
|
||||
override fun exists() = findSourceFiles().isNotEmpty()
|
||||
|
||||
override fun toString() = "{BuildSources " + findSourceFiles()[0] + "...}"
|
||||
|
||||
fun _findSourceFiles() : List<File> {
|
||||
val result = arrayListOf<File>()
|
||||
Files.walkFileTree(Paths.get(file.absolutePath), object : SimpleFileVisitor<Path>() {
|
||||
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
if (dir != null) {
|
||||
val path = dir.toFile()
|
||||
println(path.name)
|
||||
if (path.name == "src" && path.parentFile.name == "kobalt") {
|
||||
val sources = path.listFiles().filter { it.name.endsWith(".kt")}
|
||||
result.addAll(sources)
|
||||
}
|
||||
}
|
||||
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val sources = BuildSources(File(homeDir("kotlin/kobalt"))).findSourceFiles()
|
||||
println("sources: " + sources)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.beust.kobalt.internal.remote
|
||||
|
||||
import com.beust.kobalt.Constants
|
||||
import java.io.PrintWriter
|
||||
import java.net.Socket
|
||||
|
||||
fun main(argv: Array<String>) {
|
||||
Socket("localhost", 1234).use { socket ->
|
||||
(PrintWriter(socket.outputStream, true)).use { out ->
|
||||
out.println("""{ "name" : "getDependencies", "buildFile":
|
||||
"/Users/beust/kotlin/kobalt/kobalt/src/${Constants.BUILD_FILE_NAME}"}""")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,18 @@ fun main(argv: Array<String>) {
|
|||
// BlockExtractor("plugins", '(', ')').extractBlock(lines)
|
||||
}
|
||||
|
||||
class BuildScriptInfo(val content: String, val startLine: Int, val endLine: Int)
|
||||
class Section(val start: Int, val end: Int) {
|
||||
override fun toString() = "$start-$end"
|
||||
}
|
||||
|
||||
class BuildScriptInfo(val content: String, val sections: List<Section>) {
|
||||
fun isInSection(lineNumber: Int): Boolean {
|
||||
sections.forEach {
|
||||
if (lineNumber >= it.start && lineNumber <= it.end) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to extract a keyword followed by opening and closing tags out of a list of strings,
|
||||
|
@ -26,7 +37,7 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
|
|||
var foundKeyword = false
|
||||
var foundClosing = false
|
||||
var count = 0
|
||||
val result = StringBuffer()
|
||||
val buildScript = arrayListOf<String>()
|
||||
val topLines = arrayListOf<String>()
|
||||
|
||||
fun updateCount(line: String) {
|
||||
|
@ -46,9 +57,13 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
|
|||
if (foundKeyword && count > 0) currentLine.append(c)
|
||||
}
|
||||
|
||||
if (currentLine.isNotEmpty()) result.append(currentLine.toString()).append("\n")
|
||||
if (currentLine.isNotEmpty() && foundKeyword) buildScript.add(currentLine.toString())
|
||||
}
|
||||
|
||||
val allowedImports = listOf("com.beust", "java")
|
||||
val disallowedImports = listOf("com.beust.kobalt.plugin")
|
||||
val imports = arrayListOf<String>()
|
||||
val sections = arrayListOf<Section>()
|
||||
lines.forEach { line ->
|
||||
currentLineNumber++
|
||||
val found = regexp.matcher(line).matches()
|
||||
|
@ -56,26 +71,33 @@ class BlockExtractor(val regexp: Pattern, val opening: Char, val closing: Char)
|
|||
startLine = currentLineNumber
|
||||
foundKeyword = true
|
||||
count = 1
|
||||
result.append(topLines.joinToString("\n")).append("\n")
|
||||
result.append(line).append("\n")
|
||||
buildScript.add(line)
|
||||
topLines.add(line)
|
||||
} else {
|
||||
val allowedImports = listOf("com.beust", "java")
|
||||
val disallowedImports = listOf("com.beust.kobalt.plugin")
|
||||
if (! line.startsWith("import") ||
|
||||
(line.startsWith("import") && allowedImports.any { line.contains(it) }
|
||||
&& ! disallowedImports.any { line.contains(it) })) {
|
||||
if (line.startsWith("import")) {
|
||||
if (allowedImports.any { line.contains(it) } && !disallowedImports.any { line.contains(it) }) {
|
||||
imports.add(line)
|
||||
}
|
||||
} else {
|
||||
topLines.add(line)
|
||||
}
|
||||
updateCount(line)
|
||||
}
|
||||
|
||||
if (foundKeyword && foundClosing && count == 0) {
|
||||
return BuildScriptInfo(result.toString(), startLine, endLine)
|
||||
sections.add(Section(startLine, endLine))
|
||||
foundKeyword = false
|
||||
foundClosing = false
|
||||
count = 0
|
||||
startLine = 0
|
||||
endLine = 0
|
||||
}
|
||||
}
|
||||
|
||||
if (foundKeyword && foundClosing && count == 0) {
|
||||
return BuildScriptInfo(result.toString(), startLine, endLine)
|
||||
if (sections.isNotEmpty()) {
|
||||
val result = (imports.distinct() + buildScript).joinToString("\n") + "\n"
|
||||
|
||||
return BuildScriptInfo(result, sections)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.beust.kobalt.misc
|
|||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import com.beust.kobalt.internal.build.IBuildSources
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import java.io.*
|
||||
import java.nio.file.Files
|
||||
|
@ -261,10 +261,9 @@ class KFiles {
|
|||
/**
|
||||
* The build location for build scripts is .kobalt/build
|
||||
*/
|
||||
fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String {
|
||||
val result = joinDir(buildFile.dotKobaltDir.path, KFiles.SCRIPT_BUILD_DIR, jarFile)
|
||||
kobaltLog(2, "Build file dotKobaltDir: " + buildFile.dotKobaltDir)
|
||||
kobaltLog(2, "Script jar file: $result")
|
||||
fun findBuildScriptLocation(buildSources: IBuildSources, jarFile: String) : String {
|
||||
val result = joinDir(buildSources.root.path, KFiles.dotKobaltDir.path, KFiles.SCRIPT_BUILD_DIR, jarFile)
|
||||
kobaltLog(2, " Script jar file: $result")
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -387,18 +386,7 @@ class KFiles {
|
|||
}
|
||||
}
|
||||
|
||||
fun findBuildFile(projectRoot: String = "."): File {
|
||||
val deprecatedLocation = File(Constants.BUILD_FILE_NAME)
|
||||
val result: File =
|
||||
if (deprecatedLocation.exists()) {
|
||||
warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to "
|
||||
+ Constants.BUILD_FILE_DIRECTORY)
|
||||
deprecatedLocation
|
||||
} else {
|
||||
File(KFiles.joinDir(projectRoot, Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME))
|
||||
}
|
||||
return result
|
||||
}
|
||||
val dotKobaltDir = File(KFiles.joinAndMakeDir(KFiles.KOBALT_DOT_DIR))
|
||||
}
|
||||
|
||||
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue