mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-03 15:01:56 +03:00
Remove line numbers option.
This commit is contained in:
parent
2f4870e96c
commit
1fa95318db
3 changed files with 76 additions and 3 deletions
|
@ -86,7 +86,7 @@
|
|||
|
||||
public final class LaunchServer implements Runnable {
|
||||
public static final class Config {
|
||||
public int port;
|
||||
public int port;
|
||||
|
||||
private String address;
|
||||
|
||||
|
@ -131,7 +131,6 @@ public static final class Config {
|
|||
|
||||
public String authRejectString;
|
||||
|
||||
|
||||
public String whitelistRejectString;
|
||||
|
||||
public boolean genMappings;
|
||||
|
@ -140,6 +139,7 @@ public static final class Config {
|
|||
|
||||
public boolean isWarningMissArchJava;
|
||||
public boolean enabledProGuard;
|
||||
public boolean stripLineNumbers;
|
||||
|
||||
public String startScript;
|
||||
|
||||
|
@ -577,8 +577,8 @@ private void generateConfigIfNotExists() throws IOException {
|
|||
|
||||
newConfig.threadCoreCount = 0; // on your own
|
||||
newConfig.enabledProGuard = true;
|
||||
newConfig.stripLineNumbers = false;
|
||||
newConfig.threadCount = JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() >= 4 ? JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors() / 2 : JVMHelper.OPERATING_SYSTEM_MXBEAN.getAvailableProcessors();
|
||||
|
||||
// Set server address
|
||||
LogHelper.println("LaunchServer address: ");
|
||||
newConfig.setAddress(commandHandler.readLine());
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
||||
import ru.gravit.launchserver.binary.tasks.StripLineNumbersTask;
|
||||
import ru.gravit.launchserver.binary.tasks.UnpackBuildTask;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
@ -22,6 +23,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
|||
tasks.add(new UnpackBuildTask(server));
|
||||
tasks.add(new MainBuildTask(server));
|
||||
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server));
|
||||
if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server));
|
||||
syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar");
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package ru.gravit.launchserver.binary.tasks;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.asm.ClassMetadataReader;
|
||||
import ru.gravit.launchserver.asm.SafeClassWriter;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
|
||||
public class StripLineNumbersTask implements LauncherBuildTask {
|
||||
|
||||
private final LaunchServer server;
|
||||
private final ClassMetadataReader reader;
|
||||
|
||||
public StripLineNumbersTask(LaunchServer server) {
|
||||
this.server = server;
|
||||
reader = new ClassMetadataReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Strip debug task";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path process(Path inputFile) throws IOException {
|
||||
Path out = server.dir.resolve(server.config.projectName + "-stripped.jar");
|
||||
reader.getCp().add(new JarFile(inputFile.toFile()));
|
||||
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
||||
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
while (e != null) {
|
||||
String filename = e.getName();
|
||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||
if (filename.endsWith(".class")) {
|
||||
byte[] bytes = null;
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
|
||||
IOHelper.transfer(input, outputStream);
|
||||
bytes = outputStream.toByteArray();
|
||||
}
|
||||
output.write(classFix(bytes, reader));
|
||||
} else
|
||||
IOHelper.transfer(input, output);
|
||||
e = input.getNextEntry();
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader) {
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
cr.accept(cw, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowDelete() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue