private void updateData(MavenProgressIndicator progress, File newDataDir, boolean fullUpdate)
      throws MavenIndexException {

    IndexData newData = new IndexData(newDataDir);
    try {
      doUpdateIndexData(newData, progress);
      newData.flush();
    } catch (Throwable e) {
      newData.close(true);
      FileUtil.delete(newDataDir);

      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 = newDataDir.getName();

      if (fullUpdate) {
        myUpdateTimestamp = System.currentTimeMillis();
      }

      oldData.close(true);

      for (File each : FileUtil.notNullize(myDir.listFiles())) {
        if (each.getName().startsWith(DATA_DIR_PREFIX) && !each.getName().equals(myDataDirName)) {
          FileUtil.delete(each);
        }
      }
    }
  }
예제 #2
0
 public synchronized void close(boolean releaseIndexContext) {
   try {
     if (myData != null) myData.close(releaseIndexContext);
   } catch (MavenIndexException e) {
     MavenLog.LOG.warn(e);
   }
   myData = null;
 }
예제 #3
0
  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);
          }
        }
      }
    }
  }