private synchronized void save() { myDir.mkdirs(); Properties props = new Properties(); props.setProperty(KIND_KEY, myKind.toString()); props.setProperty(ID_KEY, myRepositoryId); props.setProperty(PATH_OR_URL_KEY, myRepositoryPathOrUrl); props.setProperty(INDEX_VERSION_KEY, CURRENT_VERSION); if (myUpdateTimestamp != null) props.setProperty(TIMESTAMP_KEY, String.valueOf(myUpdateTimestamp)); if (myDataDirName != null) props.setProperty(DATA_DIR_NAME_KEY, myDataDirName); if (myFailureMessage != null) props.setProperty(FAILURE_MESSAGE_KEY, myFailureMessage); try { FileOutputStream s = new FileOutputStream(new File(myDir, INDEX_INFO_FILE)); try { props.store(s, null); } finally { s.close(); } } catch (IOException e) { MavenLog.LOG.warn(e); } }
public MavenIndex(MavenIndexerWrapper indexer, File dir, IndexListener listener) throws MavenIndexException { myIndexer = indexer; myDir = dir; myListener = listener; Properties props = new Properties(); try { FileInputStream s = new FileInputStream(new File(dir, INDEX_INFO_FILE)); try { props.load(s); } finally { s.close(); } } catch (IOException e) { throw new MavenIndexException("Cannot read " + INDEX_INFO_FILE + " file", e); } if (!CURRENT_VERSION.equals(props.getProperty(INDEX_VERSION_KEY))) { throw new MavenIndexException("Incompatible index version, needs to be updated: " + dir); } myKind = Kind.valueOf(props.getProperty(KIND_KEY)); myRepositoryId = props.getProperty(ID_KEY); myRepositoryPathOrUrl = normalizePathOrUrl(props.getProperty(PATH_OR_URL_KEY)); try { String timestamp = props.getProperty(TIMESTAMP_KEY); if (timestamp != null) myUpdateTimestamp = Long.parseLong(timestamp); } catch (Exception ignored) { } myDataDirName = props.getProperty(DATA_DIR_NAME_KEY); myFailureMessage = props.getProperty(FAILURE_MESSAGE_KEY); if (!getUpdateDir().exists()) { myUpdateTimestamp = null; } open(); }