resolve idea classes
This commit is contained in:
+65
-17
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.cli.jvm.compiler.longTest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
@@ -41,6 +42,8 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@@ -51,24 +54,54 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ResolveDescriptorsFromExternalLibraries().run();
|
||||
boolean hasErrors = new ResolveDescriptorsFromExternalLibraries().run();
|
||||
System.out.println("$");
|
||||
if (hasErrors) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void run() throws Exception {
|
||||
testLibraryFile(null, "rt.jar");
|
||||
testLibrary("com.google.guava", "guava", "12.0-rc2");
|
||||
testLibrary("org.springframework", "spring-core", "3.1.1.RELEASE");
|
||||
private static List<File> findJarsInDirectory(@NotNull File directory) {
|
||||
List<File> r = Lists.newArrayList();
|
||||
|
||||
List<File> stack = Lists.newArrayList();
|
||||
stack.add(directory);
|
||||
while (!stack.isEmpty()) {
|
||||
File file = stack.get(stack.size() - 1);
|
||||
stack.remove(stack.size() - 1);
|
||||
if (file.isFile() && file.getName().endsWith(".jar")) {
|
||||
r.add(file);
|
||||
}
|
||||
File[] children = file.listFiles();
|
||||
if (children != null) {
|
||||
stack.addAll(Arrays.asList(children));
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private void testLibrary(@NotNull String org, @NotNull String module, @NotNull String rev) throws Exception {
|
||||
private boolean run() throws Exception {
|
||||
boolean hasErrors = false;
|
||||
|
||||
hasErrors |= testLibraryFile(null, "rt.jar");
|
||||
|
||||
for (File jar : findJarsInDirectory(new File("ideaSDK"))) {
|
||||
hasErrors |= testLibraryFile(jar, jar.getPath());
|
||||
}
|
||||
|
||||
hasErrors |= testLibrary("com.google.guava", "guava", "12.0-rc2");
|
||||
hasErrors |= testLibrary("org.springframework", "spring-core", "3.1.1.RELEASE");
|
||||
return hasErrors;
|
||||
}
|
||||
|
||||
private boolean testLibrary(@NotNull String org, @NotNull String module, @NotNull String rev) throws Exception {
|
||||
LibFromMaven lib = new LibFromMaven(org, module, rev);
|
||||
File jar = getLibrary(lib);
|
||||
|
||||
testLibraryFile(jar, lib.toString());
|
||||
return testLibraryFile(jar, lib.toString());
|
||||
}
|
||||
|
||||
private void testLibraryFile(@Nullable File jar, @NotNull String libDescription) throws IOException {
|
||||
private boolean testLibraryFile(@Nullable File jar, @NotNull String libDescription) throws IOException {
|
||||
System.out.println("Testing library " + libDescription + "...");
|
||||
if (jar != null) {
|
||||
System.out.println("Using file " + jar);
|
||||
@@ -99,9 +132,13 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(jetCoreEnvironment.getCompilerDependencies(), jetCoreEnvironment.getProject());
|
||||
|
||||
FileInputStream is = new FileInputStream(jar);
|
||||
boolean hasErrors;
|
||||
try {
|
||||
ZipInputStream zip = new ZipInputStream(is);
|
||||
for (;;) {
|
||||
|
||||
hasErrors = false;
|
||||
|
||||
for (; ; ) {
|
||||
ZipEntry entry = zip.getNextEntry();
|
||||
if (entry == null) {
|
||||
break;
|
||||
@@ -117,14 +154,23 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
continue;
|
||||
}
|
||||
String className = entryName.substring(0, entryName.length() - ".class".length()).replace("/", ".");
|
||||
ClassDescriptor clazz = injector.getJavaDescriptorResolver().resolveClass(new FqName(className), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||
if (clazz == null) {
|
||||
throw new IllegalStateException("class not found by name " + className + " in " + libDescription);
|
||||
}
|
||||
clazz.getDefaultType().getMemberScope().getAllDescriptors();
|
||||
}
|
||||
|
||||
} finally {
|
||||
try {
|
||||
ClassDescriptor clazz = injector.getJavaDescriptorResolver().resolveClass(new FqName(className), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||
if (clazz == null) {
|
||||
throw new IllegalStateException("class not found by name " + className + " in " + libDescription);
|
||||
}
|
||||
clazz.getDefaultType().getMemberScope().getAllDescriptors();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("failed to resolve " + className);
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("failed to resolve " + className + ": " + e, e);
|
||||
hasErrors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
@@ -133,7 +179,9 @@ public class ResolveDescriptorsFromExternalLibraries {
|
||||
Disposer.dispose(junk);
|
||||
}
|
||||
|
||||
System.out.println("Testing library " + libDescription + " done in " + TimeUtils.millisecondsToSecondsString(System.currentTimeMillis() - start) + "s");
|
||||
System.out.println("Testing library " + libDescription + " done in " + TimeUtils.millisecondsToSecondsString(System.currentTimeMillis() - start) + "s " + (hasErrors ? "with" : "without") + " errors");
|
||||
|
||||
return hasErrors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user