|
1 | 1 | package tests.wurstscript.tests; |
2 | 2 |
|
3 | | -import de.peeeq.wurstscript.WLogger; |
4 | | -import org.eclipse.jgit.api.Git; |
5 | | -import org.eclipse.jgit.api.errors.GitAPIException; |
6 | | -import org.eclipse.jgit.lib.Constants; |
| 3 | +import de.peeeq.wurstscript.utils.Utils; |
7 | 4 | import org.testng.annotations.Test; |
8 | 5 |
|
9 | 6 | import java.io.File; |
10 | | -import java.io.IOException; |
11 | 7 |
|
12 | 8 | /** |
13 | 9 | * Helper class to download the standard library, which is required by some test |
@@ -35,52 +31,44 @@ public class StdLib { |
35 | 31 |
|
36 | 32 | @Test |
37 | 33 | public void download() { |
38 | | - assert(downloadStandardlib()); |
| 34 | + downloadStandardlib(); |
39 | 35 | } |
40 | 36 |
|
41 | | - public synchronized static boolean downloadStandardlib() { |
| 37 | + public synchronized static void downloadStandardlib() { |
42 | 38 | if (isInitialized) { |
43 | | - return true; |
| 39 | + return; |
44 | 40 | } |
45 | | - |
46 | 41 | try { |
| 42 | + |
| 43 | + |
47 | 44 | if (!stdLibFolder.exists()) { |
48 | 45 | tempFolder.mkdirs(); |
49 | | - try (Git git = Git |
50 | | - .cloneRepository() |
51 | | - .setDirectory(stdLibFolder) |
52 | | - .setURI(gitRepo) |
53 | | - .call()) { |
54 | | - git.checkout().setName(Constants.MASTER).call(); |
55 | | - }; |
| 46 | + Utils.exec(tempFolder, "git", "clone", gitRepo, stdLibFolder.getName()); |
56 | 47 | } |
57 | 48 |
|
58 | | - try (Git git = Git.open(stdLibFolder)) { |
59 | | - String head = git.getRepository().resolve(Constants.HEAD).getName(); |
60 | | - if (!head.equals(version)) { |
61 | | - System.out.println("Wrong version '" + head + "', executing git pull to get '" + version + "'"); |
62 | | - |
63 | | - git.checkout().setName(Constants.MASTER).call(); |
64 | | - git.pull().call(); |
65 | | - git.checkout().setName(version).setForceRefUpdate(true).call(); |
66 | | - } |
| 49 | + String revision = Utils.exec(stdLibFolder, "git", "rev-parse", "HEAD").trim(); |
| 50 | + if (!revision.equals(version)) { |
| 51 | + System.out.println("Wrong version '" + revision + "', executing git pull to get '" + version + "'"); |
| 52 | + Utils.exec(stdLibFolder, "git", "checkout", "master"); |
| 53 | + Utils.exec(stdLibFolder, "git", "pull"); |
| 54 | + Utils.exec(stdLibFolder, "git", "checkout", version, "-f"); |
67 | 55 | } |
68 | 56 |
|
69 | 57 | // reset all possible changes |
70 | | - Git.open(stdLibFolder).clean().setForce(true).setCleanDirectories(true).setIgnore(false).call(); |
71 | | - Git.open(stdLibFolder).checkout().setName(version).call(); |
| 58 | + Utils.exec(stdLibFolder, "git", "clean", "-fdx"); |
| 59 | + Utils.exec(stdLibFolder, "git", "checkout", "."); |
| 60 | + Utils.exec(stdLibFolder, "git", "checkout", version); |
72 | 61 |
|
73 | 62 | isInitialized = true; |
74 | | - } catch (IOException | GitAPIException e) { |
75 | | - WLogger.severe(e.getStackTrace().toString()); |
76 | | - return false; |
| 63 | + } catch (Exception e) { |
| 64 | + throw new RuntimeException(e); |
77 | 65 | } |
78 | | - |
79 | | - return true; |
80 | 66 | } |
81 | 67 |
|
82 | 68 | public static String getLib() { |
83 | 69 | downloadStandardlib(); |
84 | 70 | return stdLibFolder.getPath(); |
85 | 71 | } |
| 72 | + |
| 73 | + |
86 | 74 | } |
0 commit comments