2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launchserver.binary;
|
2018-09-19 16:14:50 +03:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-12-26 12:34:18 +03:00
|
|
|
import java.util.HashSet;
|
2018-09-19 16:29:31 +03:00
|
|
|
import java.util.Set;
|
2018-09-19 16:14:50 +03:00
|
|
|
import java.util.zip.ZipEntry;
|
2018-12-06 05:29:34 +03:00
|
|
|
import java.util.zip.ZipInputStream;
|
2018-09-19 16:14:50 +03:00
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
2019-06-03 10:58:10 +03:00
|
|
|
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
|
|
|
import pro.gravit.utils.helper.IOHelper;
|
|
|
|
|
2018-09-19 16:14:50 +03:00
|
|
|
public class BuildContext {
|
|
|
|
public final ZipOutputStream output;
|
|
|
|
public final JAConfigurator config;
|
2019-01-05 18:15:19 +03:00
|
|
|
public final MainBuildTask data;
|
2018-12-26 12:34:18 +03:00
|
|
|
public final HashSet<String> fileList;
|
|
|
|
|
2018-09-19 16:14:50 +03:00
|
|
|
|
2019-01-05 18:15:19 +03:00
|
|
|
public BuildContext(ZipOutputStream output, JAConfigurator config, MainBuildTask data) {
|
2018-09-19 16:14:50 +03:00
|
|
|
this.output = output;
|
|
|
|
this.config = config;
|
2018-12-06 05:29:34 +03:00
|
|
|
this.data = data;
|
2018-12-26 12:34:18 +03:00
|
|
|
fileList = new HashSet<>(1024);
|
2018-09-19 16:14:50 +03:00
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
|
|
|
public void pushFile(String filename, InputStream inputStream) throws IOException {
|
2018-09-19 16:14:50 +03:00
|
|
|
ZipEntry zip = IOHelper.newZipEntry(filename);
|
|
|
|
output.putNextEntry(zip);
|
2018-09-22 17:33:00 +03:00
|
|
|
IOHelper.transfer(inputStream, output);
|
2018-12-26 12:34:18 +03:00
|
|
|
fileList.add(filename);
|
2018-09-19 16:14:50 +03:00
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-12-06 05:29:34 +03:00
|
|
|
public void pushJarFile(ZipInputStream input) throws IOException {
|
2018-09-19 16:14:50 +03:00
|
|
|
ZipEntry e = input.getNextEntry();
|
|
|
|
while (e != null) {
|
2018-12-26 12:34:18 +03:00
|
|
|
if (fileList.contains(e.getName())) {
|
|
|
|
e = input.getNextEntry();
|
|
|
|
continue;
|
|
|
|
}
|
2018-12-26 16:17:47 +03:00
|
|
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
2018-09-22 17:33:00 +03:00
|
|
|
IOHelper.transfer(input, output);
|
2018-12-26 12:34:18 +03:00
|
|
|
fileList.add(e.getName());
|
2018-09-19 16:14:50 +03:00
|
|
|
e = input.getNextEntry();
|
|
|
|
}
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-12-06 05:29:34 +03:00
|
|
|
public void pushJarFile(ZipInputStream input, Set<String> blacklist) throws IOException {
|
2018-09-19 16:29:31 +03:00
|
|
|
ZipEntry e = input.getNextEntry();
|
|
|
|
while (e != null) {
|
2018-09-22 17:33:00 +03:00
|
|
|
if (blacklist.contains(e.getName())) {
|
2018-09-19 16:29:31 +03:00
|
|
|
e = input.getNextEntry();
|
|
|
|
continue;
|
|
|
|
}
|
2018-12-26 16:17:47 +03:00
|
|
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
2018-09-22 17:33:00 +03:00
|
|
|
IOHelper.transfer(input, output);
|
2018-12-26 12:34:18 +03:00
|
|
|
fileList.add(e.getName());
|
2018-09-19 16:29:31 +03:00
|
|
|
e = input.getNextEntry();
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 16:14:50 +03:00
|
|
|
}
|