use of teamdash.wbs.ChangeHistory.Entry in project processdash by dtuma.
the class WBSReplaceAction method maybeAddSnapshotToSrcZip.
/**
* Our WBS ZIP files contain historical snapshots that can be used as the
* parent in a 3-way merge operation. However, these snapshots are not
* created on every save. Since we just restored data from one WBS to
* another, we've created a new branch point when these two WBSes looked
* identical. Make sure our ZIP file contains a snapshot of what the
* data looked like at this branch point.
*/
private void maybeAddSnapshotToSrcZip(File srcZip, File replacementDir) throws IOException {
// get the unique ID of the change we just used in the replacement
ChangeHistory changeHistory = new ChangeHistory(replacementDir);
Entry lastChange = changeHistory.getLastEntry();
if (lastChange == null)
return;
// check to see if the source ZIP already included a snapshot
// corresponding to that change
String changeFileName = HISTORY_SUBDIR + "/" + lastChange.getUid() + ".zip";
File snapshotFile = new File(replacementDir, changeFileName);
if (snapshotFile.isFile())
return;
// Make a list of the files that should be included in the snapshot
List<String> newSnapshotFiles = FileUtils.listRecursively(replacementDir, DashboardBackupFactory.WBS_FILE_FILTER);
if (newSnapshotFiles == null || newSnapshotFiles.isEmpty())
return;
// If we renamed the settings.xml file, change the name back before
// we rebuild the ZIP file.
maybeRename(replacementDir, "X" + SETTINGS_FILENAME, SETTINGS_FILENAME);
// rebuild the source ZIP file and add a new snapshot
RobustFileOutputStream rOut = new RobustFileOutputStream(srcZip);
try {
ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(rOut));
// add the existing file contents back to the ZIP
List<String> existingFiles = FileUtils.listRecursively(replacementDir, null);
addToZip(replacementDir, existingFiles, zipOut);
// create a new snapshot and add it to the ZIP
zipOut.putNextEntry(new ZipEntry(changeFileName));
ZipOutputStream historyZip = new ZipOutputStream(zipOut);
addToZip(replacementDir, newSnapshotFiles, historyZip);
historyZip.finish();
zipOut.closeEntry();
zipOut.finish();
zipOut.flush();
} catch (IOException ioe) {
rOut.abort();
throw ioe;
}
rOut.close();
}
use of teamdash.wbs.ChangeHistory.Entry in project processdash by dtuma.
the class WBSReplaceAction method confirmChangesAndReplaceFromFile.
private void confirmChangesAndReplaceFromFile(File srcFile) {
// extract the files into a temporary directory
File replacementDir;
try {
replacementDir = extractChanges(srcFile);
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Unable to extract files", ioe);
displayUnableToExtractError();
return;
}
// check to see what changes would be lost. Alert the user and confirm.
List<Entry> lostChanges = getChangesThatWillBeLost(replacementDir);
if (confirmLostChanges(srcFile, lostChanges))
// if the user agrees, make the change.
new WorkerThread(srcFile, replacementDir).start();
}
use of teamdash.wbs.ChangeHistory.Entry in project processdash by dtuma.
the class WBSReplaceAction method confirmLostChanges.
/**
* Display a dialog to the user warning them about changes they are about
* to overwrite, and get confirmation that they wish to continue.
*/
private boolean confirmLostChanges(File srcFile, List<Entry> lostChanges) {
if (lostChanges == null || lostChanges.isEmpty())
return true;
boolean sameWbs = true;
if (lostChanges.get(0) == null) {
lostChanges.remove(0);
sameWbs = false;
}
Object[] items = new Object[lostChanges.size()];
for (int i = 0; i < items.length; i++) {
Entry e = lostChanges.get(i);
items[i] = resources.format("Lost_Changes.Item_FMT", e.getUser(), e.getTimestamp());
}
JList list = new JList(items);
JScrollPane sp = new JScrollPane(list);
Dimension d = list.getPreferredSize();
d.height = Math.min(d.height + 5, 200);
sp.setPreferredSize(d);
String title = resources.getString("Lost_Changes.Title");
Object[] message = new Object[] { resources.formatStrings("Lost_Changes.Header_FMT", srcFile.getPath()), " ", resources.getStrings(sameWbs ? "Lost_Changes.Same_WBS_Message" : "Lost_Changes.Different_WBS_Message"), sp, resources.getString("Lost_Changes.Footer") };
int userChoice = JOptionPane.showConfirmDialog(wbsEditor.frame, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
return userChoice == JOptionPane.YES_OPTION;
}
use of teamdash.wbs.ChangeHistory.Entry in project processdash by dtuma.
the class WBSReplaceAction method getMostRecentCommonChange.
/**
* Search through the change history of the current team project and the
* replacement project, and find the most recent change entry that they
* have in common. If they have no changes in common, returns null.
*/
private Entry getMostRecentCommonChange(File replacementDir) {
// make a list of the change UIDs for the main WBS.
Set<String> wbsEntryUids = new HashSet<String>();
for (Entry e : wbsEditor.changeHistory.getEntries()) wbsEntryUids.add(e.getUid());
// Load the change history for the replacement file.
ChangeHistory replacementHist = new ChangeHistory(replacementDir);
List<Entry> replacementChanges = replacementHist.getEntries();
// find the latest change history that is shared in common.
for (int i = replacementChanges.size(); i-- > 0; ) {
Entry e = replacementChanges.get(i);
String uid = e.getUid();
if (wbsEntryUids.contains(uid))
return e;
}
// no common change entry was found.
return null;
}
use of teamdash.wbs.ChangeHistory.Entry in project processdash by dtuma.
the class WBSReplaceAction method getChangesThatWillBeLost.
/**
* Get a list of past edits to the current team project that will be
* overwritten if the replacement proceeds.
*/
private List<Entry> getChangesThatWillBeLost(File replacementDir) {
List<Entry> wbsChanges = wbsEditor.changeHistory.getEntries();
Entry e = getMostRecentCommonChange(replacementDir);
if (e == null) {
// condition has occurred.
if (!wbsChanges.isEmpty())
wbsChanges.add(0, null);
return wbsChanges;
}
// make a list of the entries in the current team project that follow
// the most common change ancestor.
List<Entry> result = new ArrayList<Entry>();
for (int i = wbsChanges.size(); i-- > 0; ) {
Entry w = wbsChanges.get(i);
if (w.getUid().equals(e.getUid()))
break;
result.add(0, w);
}
return result;
}
Aggregations