Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.+'
}
}

Expand All @@ -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
Expand Down Expand Up @@ -159,25 +164,15 @@ 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}"
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/')
Expand Down Expand Up @@ -228,11 +223,6 @@ clean.doFirst {
delete genDir
}

//task wrapper(type: Wrapper) {
// gradleVersion = '2.12'
//}



apply plugin: 'de.undercouch.download'

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


}