discord-jadx/app/src/main/java/lombok/core/PublicApiCreatorApp.java

162 lines
6.0 KiB
Java

package lombok.core;
import com.discord.widgets.chat.input.autocomplete.AutocompleteViewModel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import lombok.Lombok;
import lombok.patcher.ClassRootFinder;
/* loaded from: com.discord-118107.apk:lombok/core/PublicApiCreatorApp.SCL.lombok */
public class PublicApiCreatorApp extends LombokApp {
/* loaded from: com.discord-118107.apk:lombok/core/PublicApiCreatorApp$Fail.SCL.lombok */
private static class Fail extends Exception {
Fail(String str) {
super(str);
}
}
@Override // lombok.core.LombokApp
public String getAppName() {
return "publicApi";
}
@Override // lombok.core.LombokApp
public String getAppDescription() {
return "Creates a small lombok-api.jar with the annotations and other public API\nclasses of all lombok features. This is primarily useful to include in your\nandroid projects.";
}
@Override // lombok.core.LombokApp
public int runApp(List<String> list) throws Exception {
String str = ".";
switch (list.size()) {
case 0:
break;
default:
System.err.println("Supply 1 path to specify the directory where lombok-api.jar will be created. No path means the current directory is used.");
return 1;
case 1:
str = list.get(0);
break;
}
File file = new File(str, "lombok-api.jar");
try {
return writeApiJar(file);
} catch (Exception e) {
System.err.println("ERROR: Creating " + canonical(file) + " failed: ");
e.printStackTrace();
return 1;
}
}
private static File findOurJar() {
return new File(ClassRootFinder.findClassRootOfClass(PublicApiCreatorApp.class));
}
/* JADX WARN: Finally extract failed */
private int writeApiJar(File file) throws Exception {
File findOurJar = findOurJar();
if (findOurJar == null) {
System.err.println("The publicApi option only works if lombok is a jar.");
return 2;
}
ArrayList arrayList = new ArrayList();
JarFile jarFile = new JarFile(findOurJar);
try {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
String name = entries.nextElement().getName();
if (name.startsWith("lombok/") && !name.endsWith("/package-info.class") && name.endsWith(".class")) {
String substring = name.substring(7, name.length() - 6);
int indexOf = substring.indexOf(47);
if (indexOf != -1) {
String substring2 = substring.substring(0, indexOf);
if ("extern".equals(substring2) || "experimental".equals(substring2)) {
arrayList.add(name);
}
} else if (!substring.startsWith("ConfigurationKeys")) {
arrayList.add(name);
}
}
}
jarFile.close();
if (arrayList.isEmpty()) {
System.out.println("Not generating lombok-api.jar: No lombok api classes required!");
return 1;
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
try {
JarOutputStream jarOutputStream = new JarOutputStream(fileOutputStream);
Iterator it = arrayList.iterator();
while (it.hasNext()) {
String str = (String) it.next();
InputStream resourceAsStream = Lombok.class.getResourceAsStream(AutocompleteViewModel.COMMAND_DISCOVER_TOKEN + str);
if (resourceAsStream == null) {
throw new Fail(String.format("api class %s cannot be found", str));
}
writeIntoJar(jarOutputStream, str, 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);
}
}
} catch (Throwable th2) {
jarFile.close();
throw th2;
}
}
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 static String canonical(File file) {
try {
return file.getCanonicalPath();
} catch (Exception unused) {
return file.getAbsolutePath();
}
}
}