public void syncCQs(File file, FS fs, URL base, String username,
String password) throws IOException, ConfigInvalidException {
if (!file.getParentFile().exists())
file.getParentFile().mkdirs();
LockFile lf = new LockFile(file, fs);
if (!lf.lock())
throw new IOException(MessageFormat.format(IpLogText.get().cannotLock, file));
try {
FileBasedConfig cfg = new FileBasedConfig(file, fs);
cfg.load();
loadFrom(cfg);
IPZillaQuery ipzilla = new IPZillaQuery(base, username, password);
Set<CQ> current = ipzilla.getCQs(projects);
for (CQ cq : sort(current, CQ.COMPARATOR)) {
String id = Long.toString(cq.getID());
set(cfg, S_CQ, id, K_DESCRIPTION, cq.getDescription());
set(cfg, S_CQ, id, K_LICENSE, cq.getLicense());
set(cfg, S_CQ, id, K_USE, cq.getUse());
set(cfg, S_CQ, id, K_STATE, cq.getState());
set(cfg, S_CQ, id, K_COMMENTS, cq.getComments());
}
for (CQ cq : cqs) {
if (!current.contains(cq))
cfg.unsetSection(S_CQ, Long.toString(cq.getID()));
}
lf.write(Constants.encode(cfg.toText()));
if (!lf.commit())
throw new IOException(MessageFormat.format(IpLogText.get().cannotWrite, file));
} finally {
lf.unlock();
}
}