158 lines
5.8 KiB
Java
158 lines
5.8 KiB
Java
package lombok.bytecode;
|
|
|
|
import com.zwitserloot.cmdreader.CmdReader;
|
|
import com.zwitserloot.cmdreader.Description;
|
|
import com.zwitserloot.cmdreader.InvalidCommandLineException;
|
|
import com.zwitserloot.cmdreader.Mandatory;
|
|
import com.zwitserloot.cmdreader.Sequential;
|
|
import com.zwitserloot.cmdreader.Shorthand;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import lombok.core.DiagnosticsReceiver;
|
|
import lombok.core.LombokApp;
|
|
import lombok.core.PostCompiler;
|
|
/* loaded from: com.discord-120106.apk:lombok/bytecode/PostCompilerApp.SCL.lombok */
|
|
public class PostCompilerApp extends LombokApp {
|
|
|
|
/* loaded from: com.discord-120106.apk:lombok/bytecode/PostCompilerApp$CmdArgs.SCL.lombok */
|
|
public static class CmdArgs {
|
|
@Mandatory
|
|
@Description("paths to class files to be converted. If a directory is named, all files (recursively) in that directory will be converted.")
|
|
@Sequential
|
|
private List<String> classFiles = new ArrayList();
|
|
@Description("Prints lots of status information as the post compiler runs")
|
|
@Shorthand({"v"})
|
|
boolean verbose = false;
|
|
@Description("Shows this help text")
|
|
@Shorthand({"h", "?"})
|
|
boolean help = false;
|
|
|
|
static /* synthetic */ List access$0(CmdArgs cmdArgs) {
|
|
return cmdArgs.classFiles;
|
|
}
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public List<String> getAppAliases() {
|
|
return Arrays.asList("post", "postcompile");
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public String getAppDescription() {
|
|
return "Runs registered post compiler handlers to against existing class files, modifying them in the process.";
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public String getAppName() {
|
|
return "post-compile";
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public int runApp(List<String> list) throws Exception {
|
|
CmdReader of = CmdReader.of(CmdArgs.class);
|
|
try {
|
|
CmdArgs cmdArgs = (CmdArgs) of.make((String[]) list.toArray(new String[0]));
|
|
if (cmdArgs.help) {
|
|
System.out.println(of.generateCommandLineHelp("java -jar lombok.jar post-compile"));
|
|
return 0;
|
|
}
|
|
int i = 0;
|
|
int i2 = 0;
|
|
Iterator<File> it = cmdArgsToFiles(CmdArgs.access$0(cmdArgs)).iterator();
|
|
while (it.hasNext()) {
|
|
File next = it.next();
|
|
if (!next.exists() || !next.isFile()) {
|
|
System.out.printf("Cannot find file '%s'\n", next);
|
|
} else {
|
|
i++;
|
|
if (cmdArgs.verbose) {
|
|
System.out.println("Processing " + next.getAbsolutePath());
|
|
}
|
|
byte[] readFile = readFile(next);
|
|
byte[] bArr = (byte[]) readFile.clone();
|
|
byte[] applyTransformations = PostCompiler.applyTransformations(bArr, next.toString(), DiagnosticsReceiver.CONSOLE);
|
|
if (bArr != applyTransformations && !Arrays.equals(readFile, applyTransformations)) {
|
|
i2++;
|
|
if (cmdArgs.verbose) {
|
|
System.out.println("Rewriting " + next.getAbsolutePath());
|
|
}
|
|
writeFile(next, applyTransformations);
|
|
}
|
|
}
|
|
}
|
|
if (cmdArgs.verbose) {
|
|
System.out.printf("Total files visited: %d total files changed: %d\n", Integer.valueOf(i), Integer.valueOf(i2));
|
|
}
|
|
return i == 0 ? 1 : 0;
|
|
} catch (InvalidCommandLineException e) {
|
|
System.err.println(e.getMessage());
|
|
System.err.println(of.generateCommandLineHelp("java -jar lombok.jar post-compile"));
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
static List<File> cmdArgsToFiles(List<String> list) {
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator<String> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
addFiles(arrayList, it.next());
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
static void addFiles(List<File> list, String str) {
|
|
File file = new File(str);
|
|
if (file.isDirectory()) {
|
|
addRecursively(list, file);
|
|
} else {
|
|
list.add(file);
|
|
}
|
|
}
|
|
|
|
static void addRecursively(List<File> list, File file) {
|
|
File[] listFiles;
|
|
for (File file2 : file.listFiles()) {
|
|
if (file2.isDirectory()) {
|
|
addRecursively(list, file2);
|
|
} else if (file2.getName().endsWith(".class")) {
|
|
list.add(file2);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Finally extract failed */
|
|
static byte[] readFile(File file) throws IOException {
|
|
byte[] bArr = new byte[1024];
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
FileInputStream fileInputStream = new FileInputStream(file);
|
|
while (true) {
|
|
try {
|
|
int read = fileInputStream.read(bArr);
|
|
if (read == -1) {
|
|
fileInputStream.close();
|
|
return byteArrayOutputStream.toByteArray();
|
|
}
|
|
byteArrayOutputStream.write(bArr, 0, read);
|
|
} catch (Throwable th) {
|
|
fileInputStream.close();
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void writeFile(File file, byte[] bArr) throws IOException {
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
try {
|
|
fileOutputStream.write(bArr);
|
|
} finally {
|
|
fileOutputStream.close();
|
|
}
|
|
}
|
|
}
|