@Subscribe public void onEvent(ModelArchiveDownloadedEvent e) throws IOException { if (!isRunning()) { log(INFO_SERVICE_NOT_RUNNING); return; } if (isIndex(e.model)) { File location = repository.getLocation(e.model, false).orNull(); String remoteUri = e.model.getHint(HINT_REPOSITORY_URL).orNull(); if (remoteUri != null) { Pair<File, IModelIndex> pair = openDelegates.get(remoteUri); if (pair == null) { File folder = createIndexLocation(remoteUri); folder.mkdir(); Zips.unzip(location, folder); openDelegate(remoteUri, folder); } else { File folder = Files.createTempDir(); Zips.unzip(location, folder); IModelIndex modelIndex = pair.getSecond(); modelIndex.updateIndex(folder); bus.post(new ModelIndexOpenedEvent()); FileUtils.deleteDirectory(folder); } } } }
@Override protected void shutDown() throws Exception { cache.invalidateAll(); for (Pair<File, IModelIndex> delegate : openDelegates.values()) { removeDelegate(delegate); delegate.getSecond().close(); } }
@Override public Optional<ProjectCoordinate> suggestProjectCoordinateByArtifactId(String artifactId) { if (!isRunning()) { log(INFO_SERVICE_NOT_RUNNING); return absent(); } for (Pair<File, IModelIndex> delegate : openDelegates.values()) { IModelIndex index = delegate.getSecond(); Optional<ProjectCoordinate> suggest = index.suggestProjectCoordinateByArtifactId(artifactId); if (suggest.isPresent()) { return suggest; } } return absent(); }