mirror of
https://github.com/mitb-archive/filebot
synced 2024-08-13 17:03:45 -04:00
Lazy-load script bundle
This commit is contained in:
parent
612a243518
commit
f7ac0a79d7
@ -31,14 +31,12 @@ class MemoizedResource<R> implements Resource<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R get() throws Exception {
|
public synchronized R get() throws Exception {
|
||||||
synchronized (resource) {
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = resource.get();
|
value = resource.get();
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TransformedResource<R, T> implements Resource<T> {
|
class TransformedResource<R, T> implements Resource<T> {
|
||||||
|
@ -15,19 +15,21 @@ import java.util.jar.JarInputStream;
|
|||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
|
import net.filebot.Resource;
|
||||||
|
|
||||||
public class ScriptBundle implements ScriptProvider {
|
public class ScriptBundle implements ScriptProvider {
|
||||||
|
|
||||||
private byte[] bytes;
|
private Resource<byte[]> bundle;
|
||||||
private Certificate certificate;
|
private Certificate certificate;
|
||||||
|
|
||||||
public ScriptBundle(byte[] bytes, InputStream certificate) throws CertificateException {
|
public ScriptBundle(Resource<byte[]> bundle, InputStream certificate) throws CertificateException {
|
||||||
this.bytes = bytes;
|
this.bundle = bundle.memoize();
|
||||||
this.certificate = CertificateFactory.getInstance("X.509").generateCertificate(certificate);
|
this.certificate = CertificateFactory.getInstance("X.509").generateCertificate(certificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getScript(String name) throws Exception {
|
public String getScript(String name) throws Exception {
|
||||||
try (JarInputStream jar = new JarInputStream(new ByteArrayInputStream(bytes), true)) {
|
try (JarInputStream jar = new JarInputStream(new ByteArrayInputStream(bundle.get()), true)) {
|
||||||
for (JarEntry f = jar.getNextJarEntry(); f != null; f = jar.getNextJarEntry()) {
|
for (JarEntry f = jar.getNextJarEntry(); f != null; f = jar.getNextJarEntry()) {
|
||||||
if (f.isDirectory() || !f.getName().startsWith(name) || !f.getName().substring(name.length()).equals(".groovy"))
|
if (f.isDirectory() || !f.getName().startsWith(name) || !f.getName().substring(name.length()).equals(".groovy"))
|
||||||
continue;
|
continue;
|
||||||
|
@ -10,6 +10,7 @@ import java.time.Duration;
|
|||||||
|
|
||||||
import net.filebot.Cache;
|
import net.filebot.Cache;
|
||||||
import net.filebot.CacheType;
|
import net.filebot.CacheType;
|
||||||
|
import net.filebot.Resource;
|
||||||
|
|
||||||
public enum ScriptSource {
|
public enum ScriptSource {
|
||||||
|
|
||||||
@ -22,10 +23,10 @@ public enum ScriptSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptProvider getScriptProvider(String input) throws Exception {
|
public ScriptProvider getScriptProvider(String input) throws Exception {
|
||||||
URI bundle = new URI(getApplicationProperty("github.stable"));
|
URI resource = new URI(getApplicationProperty("github.stable"));
|
||||||
byte[] bytes = getCache().bytes(bundle, URI::toURL).expire(Cache.ONE_WEEK).get();
|
Resource<byte[]> bundle = getCache().bytes(resource, URI::toURL).expire(Cache.ONE_WEEK);
|
||||||
|
|
||||||
return new ScriptBundle(bytes, getClass().getResourceAsStream("repository.cer"));
|
return new ScriptBundle(bundle, getClass().getResourceAsStream("repository.cer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user