public synchronized void close(boolean releaseIndexContext) { try { if (myData != null) myData.close(releaseIndexContext); } catch (MavenIndexException e) { MavenLog.LOG.warn(e); } myData = null; }
private void updateData(MavenProgressIndicator progress) throws MavenIndexException { String newDataDirName; IndexData newData; newDataDirName = findAvailableDataDirName(); try { FileUtil.copyDir(getUpdateDir(), getDataContextDir(getDataDir(newDataDirName))); } catch (IOException e) { throw new MavenIndexException(e); } newData = openData(newDataDirName); try { doUpdateIndexData(newData, progress); newData.flush(); } catch (Throwable e) { newData.close(true); FileUtil.delete(getDataDir(newDataDirName)); if (e instanceof MavenServerIndexerException) throw new MavenIndexException(e); if (e instanceof IOException) throw new MavenIndexException(e); throw new RuntimeException(e); } synchronized (this) { IndexData oldData = myData; myData = newData; myDataDirName = newDataDirName; myUpdateTimestamp = System.currentTimeMillis(); oldData.close(true); File[] children = myDir.listFiles(); if (children != null) { for (File each : children) { if (each.getName().startsWith(DATA_DIR_PREFIX) && !each.getName().equals(newDataDirName)) { FileUtil.delete(each); } } } } }
private void doUpdateIndexData(IndexData data, MavenProgressIndicator progress) throws IOException, MavenServerIndexerException { final Map<String, Set<String>> groupToArtifactMap = new THashMap<String, Set<String>>(); final Map<String, Set<String>> groupWithArtifactToVersionMap = new THashMap<String, Set<String>>(); final StringBuilder builder = new StringBuilder(); progress.pushState(); progress.setIndeterminate(true); try { data.processArtifacts( new MavenIndicesProcessor() { @Override public void processArtifacts(Collection<MavenId> artifacts) { for (MavenId each : artifacts) { String groupId = each.getGroupId(); String artifactId = each.getArtifactId(); String version = each.getVersion(); builder.setLength(0); builder.append(groupId).append(":").append(artifactId); String ga = builder.toString(); getOrCreate(groupToArtifactMap, groupId).add(artifactId); getOrCreate(groupWithArtifactToVersionMap, ga).add(version); } } }); persist(groupToArtifactMap, data.groupToArtifactMap); persist(groupWithArtifactToVersionMap, data.groupWithArtifactToVersionMap); } finally { progress.popState(); } }