Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Add SetOnce#reset, update LICENSE description, upgrade Gradle to 8.0.2 (
Browse files Browse the repository at this point in the history
closes #73)
  • Loading branch information
auguwu committed Mar 23, 2023
1 parent 0834390 commit cf1d1ae
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 43 deletions.
11 changes: 6 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
root = true

[*]
indent_size = 4
end_of_line = lf
charset = utf-8
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120

[*.{kt,kts}]
indent_size = 4
end_of_line = lf
ij_kotlin_allow_trailing_comma = false
ktlint_standard = enabled
ktlint_experimental = enabled
Expand All @@ -38,6 +39,7 @@ ktlint_standard_no-unused-imports = enabled
ktlint_standard_no-unit-return = enabled
ktlint_function_signature_body_expression_wrapping = multiline
ktlint_standard_no-consecutive-blank-lines = enabled
ktlint_standard_no-unused-imports = enabled
ktlint_experimental_fun-keyword-spacing = enabled
ktlint_experimental_unnecessary-parentheses-before-trailing-lambda = enabled
ktlint_experimental_property-naming = disabled
Expand All @@ -46,6 +48,5 @@ ktlint_standard_annotation-spacing = disabled
ktlint_standard_filename = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_argument-list-wrapping = disabled

[*.{json,yaml,yml,md}]
indent_size = 2
ktlint_standard_import-ordering = disabled
max_line_length = off
4 changes: 2 additions & 2 deletions assets/HEADING
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 18 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,6 +41,22 @@ repositories {
mavenLocal()
}

spotless {
// For Kotlin (Gradle), we will need to move the license header
// as the last step due to https://github.com/diffplug/spotless/issues/1599
kotlinGradle {
endWithNewline()
encoding("UTF-8")
target("**/*.gradle.kts")
ktlint().apply {
setUseExperimental(true)
setEditorConfigPath(file("${rootProject.projectDir}/.editorconfig"))
}

licenseHeaderFile(file("${rootProject.projectDir}/assets/HEADING"), "(package |@file|import |pluginManagement|plugins|rootProject.name)")
}
}

tasks {
wrapper {
distributionType = ALL
Expand Down
64 changes: 58 additions & 6 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,11 +22,10 @@
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.api.JavaVersion

plugins {
id("com.diffplug.spotless") version "6.17.0"
`kotlin-dsl`
groovy
}

repositories {
Expand All @@ -42,6 +41,59 @@ dependencies {
implementation(gradleApi())
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

spotless {
// For Kotlin and Kotlin (Gradle), we will need to move the license header
// as the last step due to https://github.com/diffplug/spotless/issues/1599
kotlin {
endWithNewline()
encoding("UTF-8")
target("**/*.kt")
ktlint().apply {
setUseExperimental(true)
setEditorConfigPath(file("${rootProject.projectDir}/../.editorconfig"))
}

licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING"))
}

kotlinGradle {
endWithNewline()
encoding("UTF-8")
target("**/*.gradle.kts")
ktlint().apply {
setUseExperimental(true)
setEditorConfigPath(file("${rootProject.projectDir}/../.editorconfig"))
}

licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING"), "(package |@file|import |pluginManagement|plugins|rootProject.name)")
}

java {
licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING"))
trimTrailingWhitespace()
removeUnusedImports()
palantirJavaFormat()
endWithNewline()
encoding("UTF-8")
}
}

tasks {
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "17"
}
}

configurations.configureEach {
if (isCanBeResolved) {
attributes {
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, project.objects.named(GradleVersion.current().version))
}
}
}
42 changes: 42 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import org.gradle.toolchains.foojay.FoojayToolchainsConventionPlugin

pluginManagement {
repositories {
gradlePluginPortal()
}
}

buildscript {
repositories {
gradlePluginPortal()
}

dependencies {
classpath("org.gradle.toolchains:foojay-resolver:0.4.0")
}
}

apply<FoojayToolchainsConventionPlugin>()
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/commons-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.gradle.api.JavaVersion
/**
* Returns the current version of `commons-utils` package.
*/
val VERSION = "2.5.0"
val VERSION = "2.5.1"

/**
* The Java version it's being compiled to.
Expand Down
4 changes: 2 additions & 2 deletions extensions-koin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions extensions-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions gradle-utils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@

org.gradle.kotlin.dsl.precompiled.accessors.strict=true
org.gradle.dependency.verification.console=verbose
org.gradle.warning.mode=all
org.gradle.parallel=true
org.gradle.appname=common-utils
org.gradle.caching=false
org.gradle.caching=true
kotlin.code.style=official
org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions java-utils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 9 additions & 2 deletions java-utils/src/main/java/dev/floofy/utils/java/SetOnce.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -76,6 +76,13 @@ public boolean wasSet() {
return ref.get() != null;
}

/**
* Resets the given value, if needed.
*/
public void reset() {
ref.set(null);
}

@Override
public int hashCode() {
final var value = ref.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 5 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,9 +21,10 @@
* SOFTWARE.
*/

rootProject.name = "commons"
rootProject.name = "commons-utils"

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
id("com.gradle.enterprise") version "3.12.5"
}

Expand All @@ -33,7 +34,7 @@ include(
":extensions-kotlin",
":gradle-utils",
":java-utils",
":slf4j"
":slf4j",
)

val buildScanServer = System.getProperty("dev.floofy.gradle.build-scan-server", "") ?: ""
Expand Down
4 changes: 2 additions & 2 deletions slf4j/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 🤹 common-utils: Common Kotlin utilities made for my personal usage.
* Copyright (c) 2021-2023 Noel <cutie@floofy.dev>
* 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^
* Copyright (c) 2021-2023 Noel Towa <cutie@floofy.dev>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit cf1d1ae

Please sign in to comment.