mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Introduce tooling api module (#2861)
* Prototype a configuration dsl * Implement a service returning the default configuration * Implement a service returning the runtime detekt version * Add logging and issues specific configuration to ProcessingSpec * Define interfaces to load detekt instances during runtime * Use new DetektProvider in cli Runner for detekt analysis * Rename IssuesSpec to RulesSpec * Support to run chosen single or multiple rules via spec api * Move logic to check for build error to core Add tooling support for MaxIssuePolicy. * Make Runner config validation testcases independent of possible build failure logic * Simplify test runner creation * Make KtFileModifier a FileProcessListener Removes special treatment inside DetektFacade * Allow to add a reason UnstableApi annotation * Remove unnecessary DetektFacade.create factory functions * Implement remaining DetektFacade functions based on a new Lifecycle class * Fix using excludes * Fix using given BindingContext instead of creating one * Rename to AnalysisFacade and Analyzer for core classes * Support running a single from core module * Unwrap the unexpected error before throwing it * Move LicenceHeader test to rules module where it is declared * Finalize migration to loading Config from Spec instead of CliArgs by moving and reworking existing test cases * Move --run-rule test cases to runner as there is no SingleRuleRunner anymore * Implement a default configuration provider * Deprecate obsolete methods to retrieve the default configuration * Implement a default version provider * Support excludeCorrectable for RulesSpec which should make the config property obsolete * Simplify loading ConfigValidators * Use ReportsSpec.Report in core and move ReportsPath to cli again * Create an abstraction for build>maxIssues config part based on MaxIssuePolicy * Remove core dependency for formatting by moving top level auto correct test * Make local test-only rules private * Extract measuring performance logic into a dedicated class * Remove unnecessary side-effects from parsing arguments * Reimplement cli logic based on new DetektCli interface * Remove all trailing comma leftovers from testing with 1.4 language version * Introduce NonSpecified MaxIssuePolicy to make it explicit when to use legacy build section from the config * Change output and error channel types to Appendable * Share ProcessingSpec in ProcessingSettings This is the first step to migrate ProcessingSettings properties usages to spec. * Move PathFilters out of ProcessingSettings They were just referenced in KtTreeCompiler. * Extract common logging logic from ProcessingSettings into a separate class * Extract common properties logic from ProcessingSettings into a PropertiesFacade class * Remove output and error channels from ProcessingSettings * Extract Kotlin environment logic to a dedicated class * Pass buildUponDefaultConfig from cli to core module * Extract plugin and extension logic from ProcessingSettings * Remove excludeDefaultRuleSets from ProcessingSettings * Remove parallel property from ProcessingSettings * Remove autoCorrect property from ProcessingSettings * Remove executorService property from ProcessingSettings * Remove inputPaths property from ProcessingSettings * Move configUris outside the constructor * Allow extensions to be disabled via their ids in ExtensionSpec * Remove unused constructs * Deprecate convenient print method only usable for PrintStreams * Remove obsolete ExitCode enum * Make core a runtimeOnly dependency * Make all detekt-core dependencies implementation-dependencies * Make DefaultConfig object internal * Make AnalysisResult.exitCode an extension function * Remove BindingTrace entry point * Make using a parsing strategy explicit * Use yml to be consistent with other naming * Remove unnecessary factory method for KtTreeCompiler * Make Throwable branch the else branch * Close only self constructed URLClassloaders * Test exit codes from AnalysisResult * Test either plugin paths or a classloader is used * Test loading a DetektCli instance
This commit is contained in:
@@ -18,24 +18,21 @@ open class KtCompiler(
|
||||
|
||||
protected val psiFileFactory: PsiFileFactory = PsiFileFactory.getInstance(environment.project)
|
||||
|
||||
fun compile(root: Path, subPath: Path): KtFile {
|
||||
require(Files.isRegularFile(subPath)) { "Given sub path ($subPath) should be a regular file!" }
|
||||
val relativePath =
|
||||
(if (root == subPath) subPath.fileName
|
||||
else root.fileName.resolve(root.relativize(subPath))).normalize()
|
||||
val absolutePath = subPath.toAbsolutePath().normalize()
|
||||
val content = subPath.toFile().readText()
|
||||
val lineSeparator = content.determineLineSeparator()
|
||||
val ktFile = createKtFile(content, absolutePath)
|
||||
|
||||
return ktFile.apply {
|
||||
putUserData(LINE_SEPARATOR, lineSeparator)
|
||||
putUserData(RELATIVE_PATH, relativePath.toString())
|
||||
putUserData(ABSOLUTE_PATH, absolutePath.toString())
|
||||
}
|
||||
fun compile(basePath: Path, path: Path): KtFile {
|
||||
require(Files.isRegularFile(path)) { "Given sub path ($path) should be a regular file!" }
|
||||
val content = path.toFile().readText()
|
||||
return createKtFile(content, basePath, path)
|
||||
}
|
||||
|
||||
private fun createKtFile(content: String, path: Path): KtFile {
|
||||
fun createKtFile(content: String, basePath: Path, path: Path): KtFile {
|
||||
require(Files.isRegularFile(path)) { "Given sub path ($path) should be a regular file!" }
|
||||
|
||||
val relativePath =
|
||||
(if (basePath == path) path.fileName
|
||||
else basePath.fileName.resolve(basePath.relativize(path))).normalize()
|
||||
val absolutePath = path.toAbsolutePath().normalize()
|
||||
val lineSeparator = content.determineLineSeparator()
|
||||
|
||||
val psiFile = psiFileFactory.createFileFromText(
|
||||
path.fileName.toString(),
|
||||
KotlinLanguage.INSTANCE,
|
||||
@@ -43,7 +40,11 @@ open class KtCompiler(
|
||||
true, true, false,
|
||||
LightVirtualFile(path.toString())
|
||||
)
|
||||
return psiFile as? KtFile ?: error("kotlin file expected")
|
||||
return (psiFile as? KtFile ?: error("kotlin file expected")).apply {
|
||||
putUserData(LINE_SEPARATOR, lineSeparator)
|
||||
putUserData(RELATIVE_PATH, relativePath.toString())
|
||||
putUserData(ABSOLUTE_PATH, absolutePath.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user