summaryrefslogtreecommitdiff
path: root/src/test/java/cuchaz/enigma/TestSourceIndex.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/cuchaz/enigma/TestSourceIndex.java')
-rw-r--r--src/test/java/cuchaz/enigma/TestSourceIndex.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java
index 8a604f8..b1d1182 100644
--- a/src/test/java/cuchaz/enigma/TestSourceIndex.java
+++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java
@@ -13,13 +13,15 @@ package cuchaz.enigma;
13 13
14import com.google.common.collect.Sets; 14import com.google.common.collect.Sets;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.index.JarIndex;
17import cuchaz.enigma.translation.representation.entry.ClassEntry; 19import cuchaz.enigma.translation.representation.entry.ClassEntry;
18import org.junit.Test; 20import org.junit.Test;
19 21
20import java.io.File; 22import java.nio.file.Path;
23import java.nio.file.Paths;
21import java.util.Set; 24import java.util.Set;
22import java.util.jar.JarFile;
23 25
24public class TestSourceIndex { 26public class TestSourceIndex {
25 @Test 27 @Test
@@ -27,31 +29,41 @@ public class TestSourceIndex {
27 throws Exception { 29 throws Exception {
28 // Figure out where Minecraft is... 30 // Figure out where Minecraft is...
29 final String mcDir = System.getProperty("enigma.test.minecraftdir"); 31 final String mcDir = System.getProperty("enigma.test.minecraftdir");
30 File mcJar = null; 32 Path mcJar = null;
31 if (mcDir == null) { 33 if (mcDir == null) {
32 String osname = System.getProperty("os.name").toLowerCase(); 34 String osname = System.getProperty("os.name").toLowerCase();
33 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { 35 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) {
34 mcJar = new File(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); 36 mcJar = Paths.get(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar");
35 } else if (osname.contains("mac") || osname.contains("darwin")) { 37 } else if (osname.contains("mac") || osname.contains("darwin")) {
36 mcJar = new File(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); 38 mcJar = Paths.get(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar");
37 } else if (osname.contains("win")) { 39 } else if (osname.contains("win")) {
38 mcJar = new File(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); 40 mcJar = Paths.get(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar");
39 } 41 }
40 } else { 42 } else {
41 mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); 43 mcJar = Paths.get(mcDir, "versions/1.8.3/1.8.3.jar");
42 } 44 }
43 45
44 Enigma enigma = new Enigma(new JarFile(mcJar)); 46 if (mcJar == null) {
47 throw new NullPointerException("Couldn't find jar");
48 }
49
50 Enigma enigma = Enigma.create();
51 EnigmaProject project = enigma.openJar(mcJar, ProgressListener.none());
52
53 ClassCache classCache = project.getClassCache();
54 JarIndex index = project.getJarIndex();
55
56 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
57 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
45 58
46 // get all classes that aren't inner classes 59 // get all classes that aren't inner classes
47 Set<ClassEntry> classEntries = Sets.newHashSet(); 60 Set<ClassEntry> classEntries = Sets.newHashSet();
48 for (ClassEntry obfClassEntry : enigma.getJarIndex().getEntryIndex().getClasses()) { 61 for (ClassEntry obfClassEntry : index.getEntryIndex().getClasses()) {
49 if (!obfClassEntry.isInnerClass()) { 62 if (!obfClassEntry.isInnerClass()) {
50 classEntries.add(obfClassEntry); 63 classEntries.add(obfClassEntry);
51 } 64 }
52 } 65 }
53 66
54 SourceProvider sourceProvider = enigma.getObfSourceProvider();
55 for (ClassEntry obfClassEntry : classEntries) { 67 for (ClassEntry obfClassEntry : classEntries) {
56 try { 68 try {
57 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); 69 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName());