222 lines
8.5 KiB
Java
222 lines
8.5 KiB
Java
package lombok.core.runtimeDependencies;
|
|
|
|
import com.discord.widgets.chat.input.autocomplete.AutocompleteViewModel;
|
|
import com.zwitserloot.cmdreader.CmdReader;
|
|
import com.zwitserloot.cmdreader.Description;
|
|
import com.zwitserloot.cmdreader.InvalidCommandLineException;
|
|
import com.zwitserloot.cmdreader.Mandatory;
|
|
import com.zwitserloot.cmdreader.Requires;
|
|
import com.zwitserloot.cmdreader.Shorthand;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.PrintStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.jar.JarOutputStream;
|
|
import java.util.zip.ZipEntry;
|
|
import lombok.core.LombokApp;
|
|
import lombok.core.SpiLoadUtil;
|
|
/* loaded from: com.discord-118106.apk:lombok/core/runtimeDependencies/CreateLombokRuntimeApp.SCL.lombok */
|
|
public class CreateLombokRuntimeApp extends LombokApp {
|
|
private List<RuntimeDependencyInfo> infoObjects;
|
|
|
|
/* loaded from: com.discord-118106.apk:lombok/core/runtimeDependencies/CreateLombokRuntimeApp$CmdArgs.SCL.lombok */
|
|
private static class CmdArgs {
|
|
@Description("Prints those lombok transformations that require lombok-runtime.jar.")
|
|
@Mandatory(onlyIfNot = {"create"})
|
|
@Shorthand({"p"})
|
|
boolean print;
|
|
@Description("Creates the lombok-runtime.jar.")
|
|
@Mandatory(onlyIfNot = {"print"})
|
|
@Shorthand({"c"})
|
|
boolean create;
|
|
@Requires({"create"})
|
|
@Description("Where to write the lombok-runtime.jar. Defaults to the current working directory.")
|
|
@Shorthand({"o"})
|
|
String output;
|
|
@Description("Shows this help text")
|
|
boolean help;
|
|
|
|
private CmdArgs() {
|
|
}
|
|
}
|
|
|
|
/* loaded from: com.discord-118106.apk:lombok/core/runtimeDependencies/CreateLombokRuntimeApp$Fail.SCL.lombok */
|
|
private static class Fail extends Exception {
|
|
Fail(String str) {
|
|
super(str);
|
|
}
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public String getAppName() {
|
|
return "createRuntime";
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public String getAppDescription() {
|
|
return "Creates a small lombok-runtime.jar with the runtime\ndependencies of all lombok transformations that have them,\nand prints the names of each lombok transformation that\nrequires the lombok-runtime.jar at runtime.";
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public List<String> getAppAliases() {
|
|
return Arrays.asList("runtime");
|
|
}
|
|
|
|
@Override // lombok.core.LombokApp
|
|
public int runApp(List<String> list) throws Exception {
|
|
CmdReader<CmdArgs> of = CmdReader.of(CmdArgs.class);
|
|
try {
|
|
CmdArgs make = of.make((String[]) list.toArray(new String[0]));
|
|
if (make.help) {
|
|
printHelp(of, null, System.out);
|
|
return 0;
|
|
}
|
|
initializeInfoObjects();
|
|
if (make.print) {
|
|
printRuntimeDependents();
|
|
}
|
|
int i = 0;
|
|
if (make.create) {
|
|
File file = new File("./lombok-runtime.jar");
|
|
if (make.output != null) {
|
|
file = new File(make.output);
|
|
if (file.isDirectory()) {
|
|
file = new File(file, "lombok-runtime.jar");
|
|
}
|
|
}
|
|
try {
|
|
i = writeRuntimeJar(file);
|
|
} catch (Exception e) {
|
|
System.err.println("ERROR: Creating " + canonical(file) + " failed: ");
|
|
e.printStackTrace();
|
|
return 1;
|
|
}
|
|
}
|
|
return i;
|
|
} catch (InvalidCommandLineException e2) {
|
|
printHelp(of, e2.getMessage(), System.err);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private void printRuntimeDependents() {
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator<RuntimeDependencyInfo> it = this.infoObjects.iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.addAll(it.next().getRuntimeDependentsDescriptions());
|
|
}
|
|
if (arrayList.isEmpty()) {
|
|
System.out.println("Not printing dependents: No lombok transformations currently have any runtime dependencies!");
|
|
return;
|
|
}
|
|
System.out.println("Using any of these lombok features means your app will need lombok-runtime.jar:");
|
|
Iterator it2 = arrayList.iterator();
|
|
while (it2.hasNext()) {
|
|
System.out.println((String) it2.next());
|
|
}
|
|
}
|
|
|
|
private int writeRuntimeJar(File file) throws Exception {
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
Iterator<RuntimeDependencyInfo> it = this.infoObjects.iterator();
|
|
while (it.hasNext()) {
|
|
RuntimeDependencyInfo next = it.next();
|
|
List<String> runtimeDependencies = next.getRuntimeDependencies();
|
|
if (runtimeDependencies != null) {
|
|
Iterator<String> it2 = runtimeDependencies.iterator();
|
|
while (it2.hasNext()) {
|
|
String next2 = it2.next();
|
|
if (!linkedHashMap.containsKey(next2)) {
|
|
linkedHashMap.put(next2, next.getClass());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (linkedHashMap.isEmpty()) {
|
|
System.out.println("Not generating lombok-runtime.jar: No lombok transformations currently have any runtime dependencies!");
|
|
return 1;
|
|
}
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
try {
|
|
JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream);
|
|
linkedHashMap.put("LICENSE", CreateLombokRuntimeApp.class);
|
|
linkedHashMap.put("AUTHORS", CreateLombokRuntimeApp.class);
|
|
Iterator it3 = linkedHashMap.entrySet().iterator();
|
|
while (it3.hasNext()) {
|
|
Map.Entry entry = (Map.Entry) it3.next();
|
|
InputStream resourceAsStream = ((Class) entry.getValue()).getResourceAsStream(AutocompleteViewModel.COMMAND_DISCOVER_TOKEN + ((String) entry.getKey()));
|
|
if (resourceAsStream == null) {
|
|
throw new Fail(String.format("Dependency %s contributed by %s cannot be found", entry.getKey(), entry.getValue()));
|
|
}
|
|
writeIntoJar(jarOutputStream, (String) entry.getKey(), resourceAsStream);
|
|
if (resourceAsStream != null) {
|
|
resourceAsStream.close();
|
|
}
|
|
}
|
|
jarOutputStream.close();
|
|
fileOutputStream.close();
|
|
System.out.println("Successfully created: " + canonical(file));
|
|
return 0;
|
|
} catch (Throwable th) {
|
|
try {
|
|
fileOutputStream.close();
|
|
} catch (Throwable unused) {
|
|
}
|
|
if (0 == 0) {
|
|
file.delete();
|
|
}
|
|
if (th instanceof Fail) {
|
|
System.err.println(th.getMessage());
|
|
return 1;
|
|
} else if (th instanceof Exception) {
|
|
throw ((Exception) th);
|
|
} else if (th instanceof Error) {
|
|
throw ((Error) th);
|
|
} else {
|
|
throw new Exception(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void writeIntoJar(JarOutputStream jarOutputStream, String str, InputStream inputStream) throws IOException {
|
|
jarOutputStream.putNextEntry(new ZipEntry(str));
|
|
byte[] bArr = new byte[65536];
|
|
while (true) {
|
|
int read = inputStream.read(bArr);
|
|
if (read == -1) {
|
|
jarOutputStream.closeEntry();
|
|
inputStream.close();
|
|
return;
|
|
}
|
|
jarOutputStream.write(bArr, 0, read);
|
|
}
|
|
}
|
|
|
|
private void initializeInfoObjects() throws IOException {
|
|
this.infoObjects = SpiLoadUtil.readAllFromIterator(SpiLoadUtil.findServices(RuntimeDependencyInfo.class));
|
|
}
|
|
|
|
private static String canonical(File file) {
|
|
try {
|
|
return file.getCanonicalPath();
|
|
} catch (Exception unused) {
|
|
return file.getAbsolutePath();
|
|
}
|
|
}
|
|
|
|
private void printHelp(CmdReader<CmdArgs> cmdReader, String str, PrintStream printStream) {
|
|
if (str != null) {
|
|
printStream.println(str);
|
|
printStream.println("----------------------------");
|
|
}
|
|
printStream.println(cmdReader.generateCommandLineHelp("java -jar lombok.jar createRuntime"));
|
|
}
|
|
}
|