Launcher/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java

51 lines
2 KiB
Java
Raw Normal View History

2018-09-17 10:07:32 +03:00
package ru.gravit.launchserver.binary;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
2018-12-02 15:21:27 +03:00
import java.util.ArrayList;
2018-12-26 15:33:49 +03:00
import ru.gravit.launchserver.LaunchServer;
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.UnpackBuildTask;
2018-12-26 15:33:49 +03:00
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
2018-09-17 10:07:32 +03:00
public final class JARLauncherBinary extends LauncherBinary {
public ArrayList<LauncherBuildTask> tasks;
2018-12-20 18:45:01 +03:00
public JARLauncherBinary(LaunchServer server) throws IOException {
super(server);
tasks = new ArrayList<>();
tasks.add(new UnpackBuildTask());
tasks.add(new MainBuildTask());
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask());
syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar");
2018-12-20 18:45:01 +03:00
}
2018-12-20 18:45:01 +03:00
@Override
public void build() throws IOException {
// Build launcher binary
LogHelper.info("Building launcher binary file");
Path thisPath = null;
boolean isNeedDelete = false;
long time_start = System.currentTimeMillis();
long time_this = time_start;
for(LauncherBuildTask task : tasks)
{
LogHelper.subInfo("Task %s",task.getName());
Path oldPath = thisPath;
thisPath = task.process(oldPath);
long time_task_end = System.currentTimeMillis();
long time_task = time_task_end - time_this;
time_this = time_task_end;
if(isNeedDelete) Files.delete(oldPath);
isNeedDelete = task.allowDelete();
LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task);
}
long time_end = System.currentTimeMillis();
IOHelper.move(thisPath, syncBinaryFile);
LogHelper.info("Build successful from %d millis",time_end - time_start);
2018-12-20 18:45:01 +03:00
}
2018-09-17 10:07:32 +03:00
}