-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nbaztec/autodetect-root-package
autodetect root package
- Loading branch information
Showing
19 changed files
with
225 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ class CoverallsJacocoPlugin : Plugin<Project> { | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.gradle.plugin.coveralls.jacoco | ||
|
||
import java.io.File | ||
import org.apache.log4j.LogManager | ||
import org.apache.log4j.Logger | ||
|
||
class FileFinder(private val dirs: Iterable<File>) { | ||
private val logger: Logger by lazy { LogManager.getLogger(FileFinder::class.java) } | ||
private val packageRegex = """package\s+(\S+)""".toRegex() | ||
|
||
private val rootPackages = dirs.associateWith { dir -> | ||
dir.listFiles() | ||
?.firstOrNull { it.extension == "kt" } | ||
?.let { f -> | ||
f.bufferedReader().useLines { seq -> | ||
seq.firstOrNull { packageRegex.matches(it) } | ||
?.let { | ||
packageRegex.find(it)!!.groupValues[1].replace(".", "/") | ||
} | ||
} | ||
} | ||
}.also { | ||
it.forEach { (dir, pkg) -> | ||
pkg?.let { | ||
logger.info("mapped root package ${pkg.replace("/", ".")} for directory '$dir'") | ||
} | ||
} | ||
} | ||
|
||
fun find(file: File): File? { | ||
dirs.any { dir -> | ||
val adjustedFile = rootPackages[dir]?.let { | ||
File(file.path.replace(Regex("^$it/"), "")) | ||
} ?: file | ||
|
||
val f = File(dir, adjustedFile.toString()) | ||
f.exists().also { exists -> | ||
if (exists) { | ||
return f | ||
} | ||
} | ||
} | ||
|
||
logger.info("could not find file '$file'") | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,3 @@ class ServiceInfoParser(val envGetter: EnvGetter) { | |
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.