From 62616f1f451d37f194e6c0ed7d3005ae895ad9ec Mon Sep 17 00:00:00 2001 From: Cokemonkey11 Date: Wed, 29 Jul 2020 09:04:14 +0100 Subject: [PATCH 1/3] Revert "hotfix" This reverts commit 06938245272f8a98975852d88222136cf2255242. --- .../java/tests/wurstscript/tests/StdLib.java | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/StdLib.java b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/StdLib.java index 6fcf0aa3f..2fa9397ba 100644 --- a/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/StdLib.java +++ b/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/StdLib.java @@ -1,9 +1,13 @@ package tests.wurstscript.tests; -import de.peeeq.wurstscript.utils.Utils; +import de.peeeq.wurstscript.WLogger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Constants; import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; /** * Helper class to download the standard library, which is required by some test @@ -31,44 +35,52 @@ public class StdLib { @Test public void download() { - downloadStandardlib(); + assert(downloadStandardlib()); } - public synchronized static void downloadStandardlib() { + public synchronized static boolean downloadStandardlib() { if (isInitialized) { - return; + return true; } - try { - + try { if (!stdLibFolder.exists()) { tempFolder.mkdirs(); - Utils.exec(tempFolder, "git", "clone", gitRepo, stdLibFolder.getName()); + try (Git git = Git + .cloneRepository() + .setDirectory(stdLibFolder) + .setURI(gitRepo) + .call()) { + git.checkout().setName(Constants.MASTER).call(); + }; } - String revision = Utils.exec(stdLibFolder, "git", "rev-parse", "HEAD").trim(); - if (!revision.equals(version)) { - System.out.println("Wrong version '" + revision + "', executing git pull to get '" + version + "'"); - Utils.exec(stdLibFolder, "git", "checkout", "master"); - Utils.exec(stdLibFolder, "git", "pull"); - Utils.exec(stdLibFolder, "git", "checkout", version, "-f"); + try (Git git = Git.open(stdLibFolder)) { + String head = git.getRepository().resolve(Constants.HEAD).getName(); + if (!head.equals(version)) { + System.out.println("Wrong version '" + head + "', executing git pull to get '" + version + "'"); + + git.checkout().setName(Constants.MASTER).call(); + git.pull().call(); + git.checkout().setName(version).setForceRefUpdate(true).call(); + } } // reset all possible changes - Utils.exec(stdLibFolder, "git", "clean", "-fdx"); - Utils.exec(stdLibFolder, "git", "checkout", "."); - Utils.exec(stdLibFolder, "git", "checkout", version); + Git.open(stdLibFolder).clean().setForce(true).setCleanDirectories(true).setIgnore(false).call(); + Git.open(stdLibFolder).checkout().setName(version).call(); isInitialized = true; - } catch (Exception e) { - throw new RuntimeException(e); + } catch (IOException | GitAPIException e) { + WLogger.severe(e.getStackTrace().toString()); + return false; } + + return true; } public static String getLib() { downloadStandardlib(); return stdLibFolder.getPath(); } - - } From 62d381787cc871c7750a7f203053e361a18214ed Mon Sep 17 00:00:00 2001 From: Cokemonkey11 Date: Wed, 29 Jul 2020 09:04:35 +0100 Subject: [PATCH 2/3] Revert "revert build.gradle changes" This reverts commit 6b39d5da18421ab4f23aed674d47db71bd0093ed. --- de.peeeq.wurstscript/build.gradle | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/de.peeeq.wurstscript/build.gradle b/de.peeeq.wurstscript/build.gradle index fbdda36c8..9f3ba4aaf 100644 --- a/de.peeeq.wurstscript/build.gradle +++ b/de.peeeq.wurstscript/build.gradle @@ -5,6 +5,7 @@ buildscript { dependencies { classpath 'de.undercouch:gradle-download-task:3.2.0' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:1.0.2' + classpath 'org.eclipse.jgit:org.eclipse.jgit:5.7.+' } } @@ -19,6 +20,10 @@ plugins { } import de.undercouch.gradle.tasks.download.Download +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.internal.storage.file.FileRepository +import org.eclipse.jgit.lib.Constants +import org.eclipse.jgit.lib.ObjectId import java.util.regex.Matcher import java.util.regex.Pattern @@ -159,23 +164,11 @@ task versionInfoFile { String gitRevision = "unknown-version" String gitRevisionlong = "unknown-version" - new ByteArrayOutputStream().withStream { os -> - def result = exec { - executable = 'git' - args = ['describe', '--tags', '--always'] - standardOutput = os - } - gitRevision = os.toString().trim() - } + Git git = Git.open(new File(rootProject.projectDir, '..')) + ObjectId head = git.getRepository().resolve(Constants.HEAD) - new ByteArrayOutputStream().withStream { os -> - def result = exec { - executable = 'git' - args = ['describe', '--tags', '--always', '--abbrev=0'] - standardOutput = os - } - gitRevisionlong = os.toString().trim() - } + gitRevision = head.abbreviate(8).name() + gitRevisionlong = head.getName() String wurstVersion = "${version}-${gitRevision}" inputs.property("wurstVersion", wurstVersion) @@ -228,11 +221,6 @@ clean.doFirst { delete genDir } -//task wrapper(type: Wrapper) { -// gradleVersion = '2.12' -//} - - apply plugin: 'de.undercouch.download' From 5e5cfad57dece2a9ae153bf5243935fa46437ce1 Mon Sep 17 00:00:00 2001 From: Cokemonkey11 Date: Thu, 30 Jul 2020 15:34:52 +0100 Subject: [PATCH 3/3] Fix regression that came with reforged/jgit: read tag (defaults to "null") --- de.peeeq.wurstscript/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/de.peeeq.wurstscript/build.gradle b/de.peeeq.wurstscript/build.gradle index 9f3ba4aaf..7f41fbf33 100644 --- a/de.peeeq.wurstscript/build.gradle +++ b/de.peeeq.wurstscript/build.gradle @@ -170,7 +170,9 @@ task versionInfoFile { gitRevision = head.abbreviate(8).name() gitRevisionlong = head.getName() - String wurstVersion = "${version}-${gitRevision}" + String tag = git.describe().setTarget(head).setAlways(true).setTags(true).call() + + String wurstVersion = "${version}-${tag}" inputs.property("wurstVersion", wurstVersion) def dir = new File('./src-gen/de/peeeq/wurstscript/')