Skip to content

Commit

Permalink
Fix issue with configuration cache and jgit
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Dec 1, 2023
1 parent 3772407 commit aea7d79
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions src/main/groovy/net/minecraftforge/gradleutils/GradleUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String, String> gitInfo(File dir, String... globFilters) {
var git
var parent = SystemReader.instance
SystemReader.instance = new DisableSystemConfig(parent)

try {
git = Git.open(dir)
} catch (RepositoryNotFoundException e) {
Expand Down Expand Up @@ -77,6 +100,7 @@ class GradleUtils {
// Remove any lingering null values
ret.removeAll {it.value === null }

SystemReader.instance = parent
return ret
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit aea7d79

Please sign in to comment.