OSGiIndex(String name, HttpClient client, File cache, List<URI> uris, int staleTime, boolean refresh) throws Exception { this.name = name; this.uris = uris; this.client = client; this.promiseFactory = client.promiseFactory(); this.cache = checkCache(cache); this.staleTime = staleTime * 1000L; this.repository = readIndexes(refresh); }
private Promise<BridgeRepository> readIndexes(boolean refresh) throws Exception { Promise<List<Resource>> resources = getURIs().stream() .map(uri -> download(uri, refresh)) .collect(toPromise(promiseFactory)) .map(ll -> ll.stream() .flatMap(List::stream) .collect(toList())); Promise<BridgeRepository> bridge = resources.map(ResourcesRepository::new) .map(BridgeRepository::new); return bridge; }
@Override public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) { try { return getIndex().findProviders(requirements); } catch (Exception e) { throw Exceptions.duck(e); } } }
@Override public SortedSet<Version> versions(String bsn) throws Exception { return getIndex().getBridge() .versions(bsn); }
@Override public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { File target = IO.getFile(getIndex().getCache(), bsn + "-" + version + ".jar"); Promise<File> promise = getIndex().get(bsn, version, target); if (promise == null) return null; if (listeners.length == 0) { return promise.getValue(); } new DownloadListenerPromise(reporter, "Download " + bsn + "-" + version + " into " + config.name(), promise, listeners); return target; }
@Override public String tooltip(Object... target) throws Exception { if (target.length == 0) { try (Formatter f = new Formatter()) { if (stale) { f.format("[stale] Needs reload, see menu\n"); } f.format("Name : %s\n", getName()); f.format("Cache : %s\n", getRoot()); f.format("Max stale (secs) : %s\n", config.max_stale(YEAR)); f.format("\n" + "URLs :\n"); for (URI uri : getIndex().getURIs()) { f.format(" %s\n", uri); } return f.toString(); } } return getIndex().getBridge() .tooltip(target); }
index = new OSGiIndex(config.name(), client, cache, urls, config.max_stale(YEAR), refresh); if (refresh) { index.getBridgeRepository() .onResolve(this::notifyRepositoryListeners);
@Override public String getLocation() { try { return Strings.join(getIndex().getURIs()); } catch (Exception e) { return config.locations(); } }
@Override public File getRoot() throws Exception { return getIndex().getCache(); }
void poll() throws Exception { if (stale) { return; } OSGiIndex ix; synchronized (this) { ix = index; } if (ix == null) return; if (ix.isStale()) { stale = true; this.notifyRepositoryListeners(); } }
@Override public List<String> list(String pattern) throws Exception { return getIndex().getBridge() .list(pattern); }
@Override public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception { File target = IO.getFile(getIndex().getCache(), bsn + "-" + version + ".jar"); Promise<File> promise = getIndex().get(bsn, version, target); if (promise == null) return null; if (listeners.length == 0) { return promise.getValue(); } new DownloadListenerPromise(reporter, "Download " + bsn + "-" + version + " into " + config.name(), promise, listeners); return target; }
@Override public String tooltip(Object... target) throws Exception { if (target.length == 0) { try (Formatter f = new Formatter()) { if (stale) { f.format("[stale] Needs reload, see menu\n"); } f.format("Name : %s\n", getName()); f.format("Cache : %s\n", getRoot()); f.format("Max stale (secs) : %s\n", config.max_stale(YEAR)); f.format("\n" + "URLs :\n"); for (URI uri : getIndex().getURIs()) { f.format(" %s\n", uri); } return f.toString(); } } return getIndex().getBridge() .tooltip(target); }
index = new OSGiIndex(config.name(), client, cache, urls, config.max_stale(YEAR), refresh); if (refresh) { index.getBridgeRepository() .onResolve(this::notifyRepositoryListeners);
@Override public String getLocation() { try { return Strings.join(getIndex().getURIs()); } catch (Exception e) { return config.locations(); } }
@Override public File getRoot() throws Exception { return getIndex().getCache(); }
void poll() throws Exception { if (stale) { return; } OSGiIndex ix; synchronized (this) { ix = index; } if (ix == null) return; if (ix.isStale()) { stale = true; this.notifyRepositoryListeners(); } }
Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) throws Exception { return getBridge().getRepository() .findProviders(requirements); } }
OSGiIndex(String name, HttpClient client, File cache, List<URI> uris, int staleTime, boolean refresh) throws Exception { this.name = name; this.uris = uris; this.client = client; this.promiseFactory = client.promiseFactory(); this.cache = checkCache(cache); this.staleTime = staleTime * 1000L; this.repository = readIndexes(refresh); }
private Promise<BridgeRepository> readIndexes(boolean refresh) throws Exception { Promise<List<Resource>> resources = getURIs().stream() .map(uri -> download(uri, refresh)) .collect(toPromise(promiseFactory)) .map(ll -> ll.stream() .flatMap(List::stream) .collect(toList())); Promise<BridgeRepository> bridge = resources.map(ResourcesRepository::new) .map(BridgeRepository::new); return bridge; }