test: always use runtime compiler for build dex (#536)
This commit is contained in:
@@ -311,21 +311,13 @@ public abstract class IntegrationTest extends TestUtils {
|
||||
}
|
||||
|
||||
public File getJarForClass(Class<?> cls) throws IOException {
|
||||
String path = cls.getPackage().getName().replace('.', '/');
|
||||
List<File> list;
|
||||
if (!withDebugInfo) {
|
||||
list = compileClass(cls);
|
||||
} else {
|
||||
list = getClassFilesWithInners(cls);
|
||||
if (list.isEmpty()) {
|
||||
list = compileClass(cls);
|
||||
}
|
||||
}
|
||||
assertThat("File list is empty", list, not(empty()));
|
||||
List<File> files = compileClass(cls);
|
||||
assertThat("File list is empty", files, not(empty()));
|
||||
|
||||
String path = cls.getPackage().getName().replace('.', '/');
|
||||
File temp = createTempFile(".jar");
|
||||
try (JarOutputStream jo = new JarOutputStream(new FileOutputStream(temp))) {
|
||||
for (File file : list) {
|
||||
for (File file : files) {
|
||||
addFileToJar(jo, file, path + '/' + file.getName());
|
||||
}
|
||||
}
|
||||
@@ -382,27 +374,29 @@ public abstract class IntegrationTest extends TestUtils {
|
||||
}
|
||||
|
||||
private List<File> compileClass(Class<?> cls) throws IOException {
|
||||
String fileName = cls.getName();
|
||||
int end = fileName.indexOf('$');
|
||||
String clsFullName = cls.getName();
|
||||
String rootClsName;
|
||||
int end = clsFullName.indexOf('$');
|
||||
if (end != -1) {
|
||||
fileName = fileName.substring(0, end);
|
||||
rootClsName = clsFullName.substring(0, end);
|
||||
} else {
|
||||
rootClsName = clsFullName;
|
||||
}
|
||||
fileName = fileName.replace('.', '/') + ".java";
|
||||
File file = new File(TEST_DIRECTORY, fileName);
|
||||
String javaFileName = rootClsName.replace('.', '/') + ".java";
|
||||
File file = new File(TEST_DIRECTORY, javaFileName);
|
||||
if (!file.exists()) {
|
||||
file = new File(TEST_DIRECTORY2, fileName);
|
||||
file = new File(TEST_DIRECTORY2, javaFileName);
|
||||
}
|
||||
assertThat("Test source file not found: " + fileName, file.exists(), is(true));
|
||||
assertThat("Test source file not found: " + javaFileName, file.exists(), is(true));
|
||||
List<File> compileFileList = Collections.singletonList(file);
|
||||
|
||||
File outTmp = createTempDir("jadx-tmp-classes");
|
||||
outTmp.deleteOnExit();
|
||||
List<File> files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo);
|
||||
files.forEach(File::deleteOnExit);
|
||||
// remove classes which are parents for test class
|
||||
files.removeIf(next -> !next.getName().contains(cls.getSimpleName()));
|
||||
for (File clsFile : files) {
|
||||
clsFile.deleteOnExit();
|
||||
}
|
||||
String clsName = clsFullName.substring(clsFullName.lastIndexOf('.') + 1);
|
||||
files.removeIf(next -> !next.getName().contains(clsName));
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,29 +11,29 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class TestImportGenericMap extends IntegrationTest {
|
||||
|
||||
public static class SuperClass<O extends SuperClass.ToImport> {
|
||||
|
||||
interface ToImport {
|
||||
}
|
||||
|
||||
interface NotToImport {
|
||||
}
|
||||
|
||||
static final class Class1<C extends NotToImport> {
|
||||
}
|
||||
|
||||
public <C extends NotToImport> SuperClass(Class1<C> zzf) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(SuperClass.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsString(
|
||||
"import " + SuperClass.ToImport.class.getName().replace('$', '.') + ';'));
|
||||
"import " + SuperClass.ToImport.class.getName().replace("$ToImport", ".ToImport") + ';'));
|
||||
assertThat(code, not(containsString(
|
||||
"import " + SuperClass.NotToImport.class.getName().replace('$', '.') + ';')));
|
||||
}
|
||||
}
|
||||
|
||||
final class SuperClass<O extends SuperClass.ToImport> {
|
||||
|
||||
interface ToImport {
|
||||
}
|
||||
|
||||
interface NotToImport {
|
||||
}
|
||||
|
||||
static final class Class1<C extends NotToImport> {
|
||||
}
|
||||
|
||||
public <C extends NotToImport> SuperClass(Class1<C> zzf) {
|
||||
"import " + SuperClass.NotToImport.class.getName().replace("NotToImport", ".NotToImport") + ';')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import static org.hamcrest.Matchers.not;
|
||||
public class TestInner2Samples extends IntegrationTest {
|
||||
|
||||
public static class TestInner2 {
|
||||
|
||||
private String a;
|
||||
|
||||
public class A {
|
||||
|
||||
Reference in New Issue
Block a user