-
-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b8d273
commit 65bf336
Showing
7 changed files
with
32 additions
and
24 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
5 changes: 3 additions & 2 deletions
5
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/DefaultConfig.kt
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package io.gitlab.arturbosch.detekt.core.config | ||
|
||
import io.github.detekt.tooling.internal.getSafeResourceAsStream | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
|
||
internal object DefaultConfig { | ||
|
||
const val RESOURCE_NAME = "default-detekt-config.yml" | ||
|
||
fun newInstance(): Config { | ||
val configUrl = javaClass.getResource("/$RESOURCE_NAME")!! | ||
return YamlConfig.loadResource(configUrl) | ||
val configReader = javaClass.getSafeResourceAsStream("/$RESOURCE_NAME")!!.reader() | ||
return YamlConfig.load(configReader) | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
detekt-tooling/src/main/kotlin/io/github/detekt/tooling/internal/Resources.kt
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,20 @@ | ||
package io.github.detekt.tooling.internal | ||
|
||
import java.io.InputStream | ||
import java.net.URL | ||
|
||
fun URL.openSafeStream(): InputStream { | ||
return openConnection() | ||
/* | ||
* Due to https://bugs.openjdk.java.net/browse/JDK-6947916 and https://bugs.openjdk.java.net/browse/JDK-8155607, | ||
* it is necessary to disallow caches to maintain stability on JDK 8. Otherwise, simultaneous invocations of | ||
* Detekt in the same VM can fail spuriously. A similar bug is referenced in | ||
* https://github.com/detekt/detekt/issues/3396. The performance regression is likely unnoticeable. | ||
*/ | ||
.apply { if (System.getProperty("java.specification.version") == "1.8") useCaches = false } | ||
.getInputStream() | ||
} | ||
|
||
fun <T> Class<T>.getSafeResourceAsStream(name: String): InputStream? { | ||
return getResource(name)?.openSafeStream() | ||
} |