Skip to content

Commit

Permalink
Merge pull request #509 from jmfayard/update-toml
Browse files Browse the repository at this point in the history
Add support for Versions Catalogs `gradle/libs.versions.toml`
  • Loading branch information
LouisCAD authored Aug 10, 2022
2 parents a6e58b1 + 2e31ae9 commit 0f0d63f
Show file tree
Hide file tree
Showing 100 changed files with 5,184 additions and 719 deletions.
52 changes: 44 additions & 8 deletions checkPlugins.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
#!/usr/bin/env bash
fail() {
echo "$1"
exit 1
}
checkInstalled() {
which "$1" || fail "ERROR: please install $1"
}

cd plugins
./gradlew test publishToMavenLocal
runGradleTaskInFolder() {
echo
echo "== cd $1 =="
cd $1 || fail "ERROR: Folder $1 doesn't exist"
pwd

echo '$' "./gradlew $TASK"
./gradlew $TASK || fail "ERROR for task $TASK"
cd ..
}

DIR="$(basename $PWD)"
TASK="check refreshVersions"

test -n "$1" && TASK="$*"
echo "TASK=$TASK"

cd ../sample-plugins
./gradlew check refreshVersions
test "$DIR" = "refreshVersions" || fail "ERROR: must be called from the refreshVersions folder"
checkInstalled java
checkInstalled node
checkInstalled yarn


cd plugins || fail "can't cd plugins"
./gradlew test publishToMavenLocal
cd ..

cd ../sample-kotlin
./gradlew check refreshVersions
runGradleTaskInFolder sample-kotlin
runGradleTaskInFolder sample-multi-modules
runGradleTaskInFolder sample-groovy
runGradleTaskInFolder sample-kotlin-js

cd ..sample-groovy
./gradlew check refreshVersions
test -n "$ANDROID_SDK_ROOT" && {
runGradleTaskInFolder sample-android
}

echo "SUCCESS"
test "$TASK" = "refreshVersionsCleanup" || {
echo "To clean up your git history, you can run:"
echo " ./checkPlugins.sh refreshVersionsCleanup"
}
Binary file modified dummy-library-for-testing/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions dummy-library-for-testing/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions dummy-library-for-testing/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
4 changes: 2 additions & 2 deletions plugins/buildSrcLibs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies {

testImplementation(Testing.kotest.runner.junit5)

testImplementation(platform(notation = "org.junit:junit-bom:_"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform(notation = Testing.junit.bom))
testImplementation(Testing.junit.jupiter)
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because("allows tests to run from IDEs that bundle older version of launcher")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.fayard.buildSrcLibs

import de.fayard.refreshVersions.core.internal.skipConfigurationCache
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -14,6 +15,7 @@ class BuildSrcLibsPlugin : Plugin<Project> {
group = "refreshVersions"
description = "Update buildSrc/src/main/kotlin/Libs.kt"
outputs.upToDateWhen { false }
skipConfigurationCache()
}
project.tasks.register<DefaultTask>(
name = "buildSrcVersions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package de.fayard.buildSrcLibs
import com.squareup.kotlinpoet.FileSpec
import de.fayard.buildSrcLibs.internal.*
import de.fayard.refreshVersions.core.addMissingEntriesInVersionsProperties
import de.fayard.refreshVersions.core.internal.Case
import de.fayard.refreshVersions.core.internal.MEANING_LESS_NAMES
import de.fayard.refreshVersions.core.internal.OutputFile
import de.fayard.refreshVersions.core.internal.checkModeAndNames
import de.fayard.refreshVersions.core.internal.computeAliases
import de.fayard.refreshVersions.core.internal.findDependencies
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

Expand All @@ -17,7 +22,7 @@ open class BuildSrcLibsTask : DefaultTask() {

@TaskAction
fun taskActionInitializeBuildSrc() {
OutputFile.checkWhichFilesExist(project.rootDir)
OutputFile.checkWhichFilesExist()
project.file(OutputFile.OUTPUT_DIR.path).also {
if (it.isDirectory.not()) it.mkdirs()
}
Expand All @@ -42,11 +47,10 @@ open class BuildSrcLibsTask : DefaultTask() {

@TaskAction
fun taskUpdateLibsKt() {
val outputDir = project.file(OutputFile.OUTPUT_DIR.path)
val outputDir = OutputFile.OUTPUT_DIR.file

val allDependencies = project.findDependencies()
val resolvedUseFqdn = computeUseFqdnFor(
libraries = allDependencies,
val resolvedUseFqdn = allDependencies.computeAliases(
configured = emptyList(),
byDefault = MEANING_LESS_NAMES
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package de.fayard.buildSrcLibs.internal

import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import de.fayard.refreshVersions.core.internal.Deps
import de.fayard.refreshVersions.core.internal.Library

internal fun kotlinpoet(
deps: Deps
deps: Deps,
): FileSpec {
val libraries: List<Library> = deps.libraries
val indent = " "

val libsProperties: List<PropertySpec> = libraries
.distinctBy { it.groupModule() }
.map { d ->
val libValue = when {
d.version == "none" -> CodeBlock.of("%S", d.groupModule())
val libValue = when (d.version) {
null -> CodeBlock.of("%S", d.groupModule())
else -> CodeBlock.of("%S", d.groupModuleUnderscore())
}
constStringProperty(
Expand All @@ -36,11 +42,10 @@ internal fun kotlinpoet(
}



internal fun constStringProperty(
name: String,
initializer: CodeBlock,
kdoc: CodeBlock? = null
kdoc: CodeBlock? = null,
): PropertySpec = PropertySpec.builder(name, String::class)
.addModifiers(KModifier.CONST)
.initializer(initializer)
Expand Down
22 changes: 0 additions & 22 deletions plugins/buildSrcLibs/src/test/kotlin/CaseTest.kt

This file was deleted.

4 changes: 2 additions & 2 deletions plugins/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ dependencies {
implementation(Square.moshi.kotlinReflect)

testImplementation(Square.okHttp3.loggingInterceptor)
testImplementation(platform(notation = "org.junit:junit-bom:_"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform(notation = Testing.junit.bom))
testImplementation(Testing.junit.jupiter)
testImplementation(Testing.kotest.runner.junit5)
testImplementation(Kotlin.test.annotationsCommon)
testImplementation(Kotlin.test.junit5)
Expand Down
Loading

0 comments on commit 0f0d63f

Please sign in to comment.