Search in sources :

Example 1 with Entry

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();
}
Also used : ZipEntry(java.util.zip.ZipEntry) Entry(teamdash.wbs.ChangeHistory.Entry) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RobustFileOutputStream(net.sourceforge.processdash.util.RobustFileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Entry

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();
}
Also used : ZipEntry(java.util.zip.ZipEntry) Entry(teamdash.wbs.ChangeHistory.Entry) IOException(java.io.IOException) File(java.io.File)

Example 3 with Entry

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) ZipEntry(java.util.zip.ZipEntry) Entry(teamdash.wbs.ChangeHistory.Entry) Dimension(java.awt.Dimension) JList(javax.swing.JList)

Example 4 with Entry

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;
}
Also used : ZipEntry(java.util.zip.ZipEntry) Entry(teamdash.wbs.ChangeHistory.Entry) HashSet(java.util.HashSet)

Example 5 with Entry

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;
}
Also used : ZipEntry(java.util.zip.ZipEntry) Entry(teamdash.wbs.ChangeHistory.Entry) ArrayList(java.util.ArrayList)

Aggregations

Entry (teamdash.wbs.ChangeHistory.Entry)12 ZipEntry (java.util.zip.ZipEntry)8 IOException (java.io.IOException)3 ChangeHistory (teamdash.wbs.ChangeHistory)3 File (java.io.File)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Element (org.w3c.dom.Element)2 SAXException (org.xml.sax.SAXException)2 Dimension (java.awt.Dimension)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 Matcher (java.util.regex.Matcher)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 JList (javax.swing.JList)1 JScrollPane (javax.swing.JScrollPane)1 RobustFileOutputStream (net.sourceforge.processdash.util.RobustFileOutputStream)1