From aea7d7977e6b3b5fde6258e4316432ced06a539d Mon Sep 17 00:00:00 2001 From: LexManos Date: Thu, 30 Nov 2023 20:17:32 -0800 Subject: [PATCH] Fix issue with configuration cache and jgit --- build.gradle | 6 +++-- gradle.properties | 2 +- .../gradleutils/GradleUtils.groovy | 24 +++++++++++++++++++ .../changelog/GenerateChangelog.groovy | 13 +++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 4a7cd2c..62ba2c1 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-gradle-plugin' id 'groovy' id 'maven-publish' - id 'org.cadixdev.licenser' version '0.6.1' + //id 'org.cadixdev.licenser' version '0.6.1' id 'com.gradle.plugin-publish' version '1.2.1' id 'net.minecraftforge.gradleutils' id 'com.github.johnrengelman.shadow' version '8.1.1' @@ -31,11 +31,13 @@ tasks.withType(GroovyCompile).configureEach { groovyOptions.optimizationOptions.indy = true } +/* license { header = file('LICENSE-header.txt') newLine = false - exclude '**/*.properties' + exclude '** /*.properties' } +*/ gradlePlugin { website = 'https://github.com/MinecraftForge/GradleUtils' diff --git a/gradle.properties b/gradle.properties index e2a0fd7..13bd1c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.caching=true org.gradle.parallel=true org.gradle.configureondemand=true -#org.gradle.configuration-cache=true +org.gradle.configuration-cache=true diff --git a/src/main/groovy/net/minecraftforge/gradleutils/GradleUtils.groovy b/src/main/groovy/net/minecraftforge/gradleutils/GradleUtils.groovy index 5bc1985..433101f 100644 --- a/src/main/groovy/net/minecraftforge/gradleutils/GradleUtils.groovy +++ b/src/main/groovy/net/minecraftforge/gradleutils/GradleUtils.groovy @@ -10,10 +10,14 @@ import groovy.transform.CompileStatic import groovy.transform.Immutable import org.eclipse.jgit.api.Git import org.eclipse.jgit.errors.RepositoryNotFoundException +import org.eclipse.jgit.lib.Config import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.Repository +import org.eclipse.jgit.storage.file.FileBasedConfig import org.eclipse.jgit.transport.RemoteConfig +import org.eclipse.jgit.util.FS +import org.eclipse.jgit.util.SystemReader import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.artifacts.repositories.MavenArtifactRepository @@ -44,8 +48,27 @@ class GradleUtils { return lst } + @CompileStatic + static class DisableSystemConfig extends SystemReader { + @Delegate final SystemReader parent + DisableSystemConfig(SystemReader parent) { + this.parent = parent + } + + @Override + FileBasedConfig openSystemConfig(Config parent, FS fs) { + return new FileBasedConfig(parent, null, fs) { + @Override void load() {} + @Override boolean isOutdated() { false } + } + } + } + static Map gitInfo(File dir, String... globFilters) { var git + var parent = SystemReader.instance + SystemReader.instance = new DisableSystemConfig(parent) + try { git = Git.open(dir) } catch (RepositoryNotFoundException e) { @@ -77,6 +100,7 @@ class GradleUtils { // Remove any lingering null values ret.removeAll {it.value === null } + SystemReader.instance = parent return ret } diff --git a/src/main/groovy/net/minecraftforge/gradleutils/changelog/GenerateChangelog.groovy b/src/main/groovy/net/minecraftforge/gradleutils/changelog/GenerateChangelog.groovy index a2c12b6..623c370 100644 --- a/src/main/groovy/net/minecraftforge/gradleutils/changelog/GenerateChangelog.groovy +++ b/src/main/groovy/net/minecraftforge/gradleutils/changelog/GenerateChangelog.groovy @@ -2,21 +2,18 @@ * Copyright (c) Forge Development LLC and contributors * SPDX-License-Identifier: LGPL-2.1-only */ -package net.minecraftforge.gradleutils.changelog; +package net.minecraftforge.gradleutils.changelog import net.minecraftforge.gradleutils.GradleUtils; import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevCommit +import org.eclipse.jgit.util.SystemReader; import org.gradle.api.DefaultTask; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.* -import org.gradle.internal.impldep.org.glassfish.jaxb.core.api.impl.NameConverter - -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; abstract class GenerateChangelog extends DefaultTask { GenerateChangelog() { @@ -48,6 +45,8 @@ abstract class GenerateChangelog extends DefaultTask { void exec() throws IOException { String changelog = "" + def parent = SystemReader.instance + SystemReader.instance = new GradleUtils.DisableSystemConfig(parent) try(Git git = Git.open(getGitDirectory().getAsFile().get())) { def url = projectUrl.getOrNull() if (url == null) @@ -72,6 +71,8 @@ abstract class GenerateChangelog extends DefaultTask { def head = ChangelogUtils.getHead(git) changelog = ChangelogUtils.generateChangelogFromTo(git, url, !buildMarkdown.get(), from, head) + } finally { + SystemReader.instance = parent } var file = outputFile.asFile.get()