Skip to content

Commit

Permalink
Merge pull request #72 from uzzu/4.x
Browse files Browse the repository at this point in the history
4.x
  • Loading branch information
uzzu authored Dec 22, 2023
2 parents 1d7bc57 + e68a53d commit 2368110
Show file tree
Hide file tree
Showing 20 changed files with 1,020 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run reviewdog
if: always()
run: |
find . -type f -name "ktlint*Check.xml" -exec sh -c "cat {} | reviewdog -f=checkstyle -name='ktlint' -reporter=github-pr-review" \;
cat build/reports/detekt/detekt-merged-report.sarif | reviewdog -f=sarif -name="detekt" -reporter="github-check" -level="error" -filter-mode="nofilter" -fail-on-error
- name: Gradle publish to mavenLocal
run: |
./gradlew publishToMavenLocal
Expand Down
26 changes: 22 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

## [4.0.0] - 2023-12-22

### Changed

- Use Gradle 8.5
- Use Kotlin 1.9.21

### Removed

- `val (Map<String, String>) env.allVariables`
- Replace to use a method `(Map<String, String>) env.allVariables()` instead.

## [3.0.0] - 2023-11-27

### Changed
- The behavior of project to ignore the filename option specified for this plugin in the parent project's gradle properties by default.

- The behavior of project to ignore the filename option specified for this plugin in the parent project's gradle
properties by default.
- Fix of [#39](https://github.com/uzzu/dotenv-gradle/issues/39)
- For example, if `dotenv.filename=.env.staging` is set in the root project, this setting will automatically apply to sub-projects as well. While this follows the correct resolution order of Gradle Properties, it has been a source of confusion for users working with dotenv.
- To disable this default behavior, add `dotenv.filename.ignore.parent=false` to the gradle.properties in the root project.
- A same update has been applied to the feature of changing `.env.template` filename. To disable this default behavior, add `dotenv.template.filename.ignore.parent=false` to the gradle.properties in the root project.
- For example, if `dotenv.filename=.env.staging` is set in the root project, this setting will automatically apply to
sub-projects as well. While this follows the correct resolution order of Gradle Properties, it has been a source of
confusion for users working with dotenv.
- To disable this default behavior, add `dotenv.filename.ignore.parent=false` to the gradle.properties in the root
project.
- A same update has been applied to the feature of changing `.env.template` filename. To disable this default
behavior, add `dotenv.template.filename.ignore.parent=false` to the gradle.properties in the root project.

### Deprecated

Expand Down
109 changes: 88 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,100 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import kotlin.streams.asSequence
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

plugins {
base
id("co.uzzu.dotenv.gradle") version "3.0.0"
kotlin("jvm") version "1.4.31" apply false
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
alias(libs.plugins.dotenv.gradle)
alias(libs.plugins.detekt)
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.gradle.plugin.publish) apply false
}

val reportMerge by tasks.registering(ReportMergeTask::class) {
output.set(rootProject.layout.buildDirectory.file("reports/detekt/detekt-merged-report.sarif"))
}

detektConfigurationRoot(reportMerge)

subprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
detektConfigurationShared(reportMergeTask = reportMerge)
}

// region detekt configuration

fun Project.detektConfigurationRoot(
reportMergeTask: TaskProvider<ReportMergeTask>,
) {
val allKtsFiles = allKtsFiles()
detektConfigurationShared(
reportMergeTask = reportMergeTask,
source = allKtsFiles
+ allBuildSrcKtFiles()
+ files("src"),
)
}

allprojects {
repositories {
mavenCentral()
fun Project.detektConfigurationShared(
reportMergeTask: TaskProvider<ReportMergeTask>,
source: List<Any> = listOf(files("src")),
detektConfig: File = rootProject.file("./gradle/detekt.yml"),
) {
detekt {
buildUponDefaultConfig = true
config.setFrom(detektConfig)
this.source.setFrom(source)
ignoreFailures = false
debug = false
parallel = true
}

tasks.withType<Detekt>().configureEach {
finalizedBy(reportMerge)
reports.sarif.required = true
}

reportMergeTask {
input.from(tasks.withType<Detekt>().map { it.sarifReportFile })
}
}

ktlint {
verbose.set(true)
outputToConsole.set(true)
reporters {
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE)
fun Project.allBuildSrcKtFiles(): List<Path> {
if (!file(rootProject.projectDir.path + "/buildSrc").exists()) {
return emptyList()
}
ignoreFailures.set(true)
val ignoringPath = listOf(".git/", "build/", ".gradle/")
val ktPattern = "glob:**/*.kt"
val ktsPattern = "glob:**/*.kts"
val ktMatcher = FileSystems.getDefault().getPathMatcher(ktPattern)
val ktsMatcher = FileSystems.getDefault().getPathMatcher(ktsPattern)
val results = Files.walk(Paths.get(rootProject.projectDir.path + "/buildSrc"))
.asSequence()
.filter {
val path = it.toString()
!ignoringPath.contains(path) &&
(ktMatcher.matches(it) || ktsMatcher.matches(it))
}
.toList()
return results
}

subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
ktlint {
verbose.set(true)
outputToConsole.set(true)
reporters {
reporter(org.jlleitschuh.gradle.ktlint.reporter.ReporterType.CHECKSTYLE)
fun Project.allKtsFiles(): List<Path> {
val ignoringPath = listOf(".git/", "build/", ".gradle/", "src/")
val pattern = "glob:**/*.kts"
val matcher = FileSystems.getDefault().getPathMatcher(pattern)
val results = Files.walk(Paths.get(projectDir.path))
.asSequence()
.filter {
val path = it.toString()
!ignoringPath.contains(path) && matcher.matches(it)
}
ignoreFailures.set(true)
}
.toList()
return results
}

// endregion
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

- [Basic Usage](/examples/basic)
- [Change `.env` filename](/examples/change_file)
- [Change `.env.template` filename](/examples/change_template_file)
- [Hierarchical dotenv definitions](/examples/hierarchical_definitions)
2 changes: 1 addition & 1 deletion examples/basic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "3.0.0"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}

val keys = listOf(
Expand Down
17 changes: 16 additions & 1 deletion examples/basic/sub/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
val keys = listOf(
"FOO",
"BAR",
"BAZ",
"QUX"
)

println("""[$name] ${env.FOO.orElse("default_foo")}""")
println("""[$name] ${env.BAR.orNull()}""")
try {
Expand All @@ -8,4 +15,12 @@ try {
println("""[$name] ${env.QUX.value}""")

// All environment variables which are merged with variables specified in .env files.
env.allVariables
print("[$name] #allVariables() (filtered by keys in .env.template and .env): ")
println(env.allVariables().filterKeys { keys.contains(it) })

// All environment variables which are merged with variables specified in .env files includes null.
// The Plugin set key if defined in .env template files, but it could not be retrieved as nullable value entries by using allVariables()
// By using allVariablesOrNull instead of allVariables, it is possible to retrieve all environment variables, including those that are only defined in the .env template (which means their values are null).
env.allVariablesOrNull()
print("[$name] #allVariablesOrNull() (filtered by keys in .env.template and .env): ")
println(env.allVariablesOrNull().filterKeys { keys.contains(it) })
2 changes: 1 addition & 1 deletion examples/change_file/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "3.0.0"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}

println(env.FOO.value)
2 changes: 1 addition & 1 deletion examples/change_template_file/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "3.0.0"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}

val keys = listOf(
Expand Down
2 changes: 1 addition & 1 deletion examples/hierarchical_definitions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
base
id("co.uzzu.dotenv.gradle") version "3.0.0"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}

println("[$name] FOO: ${env.FOO.value}")
Expand Down
Loading

0 comments on commit 2368110

Please sign in to comment.