Run dex checker only on java 6 files

This commit is contained in:
Mikhael Bogdanov
2017-04-12 11:44:16 +02:00
parent 73d771717c
commit 2bb5b3881a
@@ -23,10 +23,10 @@ import com.android.dx.dex.cf.CfTranslator;
import com.android.dx.dex.file.DexFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.org.objectweb.asm.Opcodes;
import org.junit.Assert;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -47,7 +47,9 @@ public class DxChecker {
for (OutputFile file : ClassFileUtilsKt.getClassFiles(outputFiles)) {
try {
byte[] bytes = file.asByteArray();
checkFileWithDx(bytes, file.getRelativePath(), arguments);
if (isJava6Class(bytes)) {
checkFileWithDx(bytes, file.getRelativePath(), arguments);
}
}
catch (Throwable e) {
Assert.fail(generateExceptionMessage(e));
@@ -55,6 +57,18 @@ public class DxChecker {
}
}
private static boolean isJava6Class(byte[] bytes) throws IOException {
try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes))) {
int header = stream.readInt();
if (0xCAFEBABE != header) {
throw new IOException("Invalid header class header: " + header);
}
int minor = stream.readUnsignedShort();
int major = stream.readUnsignedShort();
return major == Opcodes.V1_6;
}
}
public static void checkFileWithDx(byte[] bytes, @NotNull String relativePath) {
Main.Arguments arguments = new Main.Arguments();
String[] array = new String[1];