2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launchserver.binary;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-01-05 18:28:25 +03:00
|
|
|
import java.nio.file.Files;
|
2018-12-06 05:29:34 +03:00
|
|
|
import java.nio.file.Path;
|
2018-12-02 15:21:27 +03:00
|
|
|
import java.util.ArrayList;
|
2019-01-08 18:29:24 +03:00
|
|
|
import java.util.List;
|
2019-01-08 16:36:05 +03:00
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
2019-01-07 08:01:15 +03:00
|
|
|
|
2019-06-03 10:58:10 +03:00
|
|
|
import pro.gravit.launcher.Launcher;
|
|
|
|
import pro.gravit.launchserver.LaunchServer;
|
2019-07-15 22:47:07 +03:00
|
|
|
import pro.gravit.launchserver.binary.tasks.*;
|
2019-06-03 10:58:10 +03:00
|
|
|
import pro.gravit.utils.helper.CommonHelper;
|
|
|
|
import pro.gravit.utils.helper.IOHelper;
|
|
|
|
import pro.gravit.utils.helper.LogHelper;
|
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final class JARLauncherBinary extends LauncherBinary {
|
2019-01-15 06:35:39 +03:00
|
|
|
public final AtomicLong count;
|
2019-01-07 08:01:15 +03:00
|
|
|
public final Path runtimeDir;
|
|
|
|
public final Path guardDir;
|
2019-01-08 16:36:05 +03:00
|
|
|
public final Path buildDir;
|
2019-01-08 18:29:24 +03:00
|
|
|
public List<LauncherBuildTask> tasks;
|
|
|
|
public List<Path> coreLibs;
|
2019-04-03 16:27:40 +03:00
|
|
|
public List<Path> addonLibs;
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2018-12-20 18:45:01 +03:00
|
|
|
public JARLauncherBinary(LaunchServer server) throws IOException {
|
2019-06-02 05:03:08 +03:00
|
|
|
super(server, resolve(server, ".jar"));
|
2019-01-08 16:36:05 +03:00
|
|
|
count = new AtomicLong(0);
|
2019-01-07 08:01:15 +03:00
|
|
|
runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
|
|
|
|
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
|
2019-01-08 16:36:05 +03:00
|
|
|
buildDir = server.dir.resolve("build");
|
2019-01-08 16:41:13 +03:00
|
|
|
tasks = new ArrayList<>();
|
2019-01-08 18:29:24 +03:00
|
|
|
coreLibs = new ArrayList<>();
|
2019-03-15 17:40:48 +03:00
|
|
|
addonLibs = new ArrayList<>();
|
2019-01-09 11:29:54 +03:00
|
|
|
if (!Files.isDirectory(buildDir)) {
|
2019-01-15 06:35:39 +03:00
|
|
|
Files.deleteIfExists(buildDir);
|
|
|
|
Files.createDirectory(buildDir);
|
2019-01-09 11:29:54 +03:00
|
|
|
}
|
2019-01-08 16:57:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init() {
|
2019-01-09 11:29:54 +03:00
|
|
|
tasks.add(new PrepareBuildTask(server));
|
2019-01-08 16:41:13 +03:00
|
|
|
tasks.add(new MainBuildTask(server));
|
2019-05-31 01:40:19 +03:00
|
|
|
if (server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
2019-01-08 18:29:24 +03:00
|
|
|
tasks.add(new ProGuardBuildTask(server));
|
2019-03-15 20:04:26 +03:00
|
|
|
tasks.add(new AdditionalFixesApplyTask(server));
|
2019-05-31 01:40:19 +03:00
|
|
|
if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
2019-07-15 22:47:07 +03:00
|
|
|
if(server.config.launcher.compress) tasks.add(new CompressBuildTask(server));
|
2018-12-20 18:45:01 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2018-12-20 18:45:01 +03:00
|
|
|
@Override
|
|
|
|
public void build() throws IOException {
|
|
|
|
LogHelper.info("Building launcher binary file");
|
2019-01-09 11:29:54 +03:00
|
|
|
count.set(0); // set jar number
|
2019-01-05 18:15:19 +03:00
|
|
|
Path thisPath = null;
|
2019-01-05 18:28:25 +03:00
|
|
|
boolean isNeedDelete = false;
|
2019-01-05 18:43:05 +03:00
|
|
|
long time_start = System.currentTimeMillis();
|
|
|
|
long time_this = time_start;
|
2019-01-15 06:35:39 +03:00
|
|
|
for (LauncherBuildTask task : tasks) {
|
|
|
|
LogHelper.subInfo("Task %s", task.getName());
|
2019-01-05 18:28:25 +03:00
|
|
|
Path oldPath = thisPath;
|
|
|
|
thisPath = task.process(oldPath);
|
2019-01-05 18:43:05 +03:00
|
|
|
long time_task_end = System.currentTimeMillis();
|
|
|
|
long time_task = time_task_end - time_this;
|
|
|
|
time_this = time_task_end;
|
2019-08-09 19:04:26 +03:00
|
|
|
if (isNeedDelete && server.config.launcher.deleteTempFiles) Files.deleteIfExists(oldPath);
|
2019-01-05 18:28:25 +03:00
|
|
|
isNeedDelete = task.allowDelete();
|
2019-01-15 06:35:39 +03:00
|
|
|
LogHelper.subInfo("Task %s processed from %d millis", task.getName(), time_task);
|
2019-01-05 18:15:19 +03:00
|
|
|
}
|
2019-01-05 18:43:05 +03:00
|
|
|
long time_end = System.currentTimeMillis();
|
2019-08-09 19:04:26 +03:00
|
|
|
if (isNeedDelete && server.config.launcher.deleteTempFiles) IOHelper.move(thisPath, syncBinaryFile);
|
2019-01-08 16:50:40 +03:00
|
|
|
else IOHelper.copy(thisPath, syncBinaryFile);
|
2019-01-15 06:35:39 +03:00
|
|
|
LogHelper.info("Build successful from %d millis", time_end - time_start);
|
2018-12-20 18:45:01 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-08 16:36:05 +03:00
|
|
|
public String nextName(String taskName) {
|
2019-01-15 06:35:39 +03:00
|
|
|
return String.format("Launcher-%s-%d.jar", taskName, count.getAndIncrement());
|
2019-01-08 16:36:05 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-08 16:36:05 +03:00
|
|
|
public Path nextPath(String taskName) {
|
2019-01-15 06:35:39 +03:00
|
|
|
return buildDir.resolve(nextName(taskName));
|
2019-01-08 16:36:05 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-08 16:36:05 +03:00
|
|
|
public Path nextPath(LauncherBuildTask task) {
|
2019-01-15 06:35:39 +03:00
|
|
|
return nextPath(task.getName());
|
2019-01-08 16:36:05 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 06:35:39 +03:00
|
|
|
public Path nextLowerPath(LauncherBuildTask task) {
|
|
|
|
return nextPath(CommonHelper.low(task.getName()));
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|