From fa0d259c1527df04693dd3a44f2aa9ad09e6da8d Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sat, 4 Jul 2020 13:17:42 +0100 Subject: [PATCH] JAL-3628 More Cache.log.debug statements --- src/jalview/gui/AlignFrame.java | 143 +++++++++++++++++++++++---------------- src/jalview/io/BackupFiles.java | 58 ++++++++++++++-- 2 files changed, 138 insertions(+), 63 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b7d8b3a..4810a96 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -20,6 +20,54 @@ */ package jalview.gui; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; +import java.awt.dnd.DropTargetListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.print.PageFormat; +import java.awt.print.PrinterJob; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + +import javax.swing.ButtonGroup; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JEditorPane; +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JScrollPane; +import javax.swing.SwingUtilities; + import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; import jalview.analysis.CrossRef; @@ -91,6 +139,7 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -100,53 +149,6 @@ import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.seqfetcher.DbSourceProxy; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.StringSelection; -import java.awt.datatransfer.Transferable; -import java.awt.dnd.DnDConstants; -import java.awt.dnd.DropTargetDragEvent; -import java.awt.dnd.DropTargetDropEvent; -import java.awt.dnd.DropTargetEvent; -import java.awt.dnd.DropTargetListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.print.PageFormat; -import java.awt.print.PrinterJob; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Deque; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.List; -import java.util.Vector; - -import javax.swing.ButtonGroup; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JEditorPane; -import javax.swing.JInternalFrame; -import javax.swing.JLayeredPane; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JScrollPane; -import javax.swing.SwingUtilities; - /** * DOCUMENT ME! * @@ -1197,39 +1199,65 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, else { // create backupfiles object and get new temp filename destination + Cache.log.debug("ALIGNFRAME making backupfiles object for " + file); BackupFiles backupfiles = new BackupFiles(file); try { + Cache.log.debug("ALIGNFRAME setting PrintWriter"); PrintWriter out = new PrintWriter( new FileWriter(backupfiles.getTempFilePath())); + Cache.log.debug("ALIGNFRAME using temp file " + + backupfiles.getTempFilePath()); + out.print(output); + Cache.log.debug("ALIGNFRAME about to close file"); out.close(); + Cache.log.debug("ALIGNFRAME closed file"); this.setTitle(file); statusBar.setText(MessageManager.formatMessage( "label.successfully_saved_to_file_in_format", new Object[] { fileName, format.getName() })); + } catch (IOException e) + { + success = false; + Cache.log.error( + "ALIGNFRAME Something happened writing the temp file"); + Cache.log.error(e.getMessage()); + Cache.log.debug(e.getStackTrace()); + } catch (Exception ex) { success = false; - ex.printStackTrace(); + Cache.log.error( + "ALIGNFRAME Something else happened writing the temp file"); + Cache.log.error(ex.getMessage()); + Cache.log.debug(ex.getStackTrace()); } backupfiles.setWriteSuccess(success); + Cache.log.debug("ALIGNFRAME writing temp file was " + + (success ? "" : "not ") + "successful"); // do the backup file roll and rename the temp file to actual file + Cache.log.debug("ALIGNFRAME about to rollBackupsAndRenameTempFile"); success = backupfiles.rollBackupsAndRenameTempFile(); + Cache.log.debug("ALIGNFRAME performed rollBackupsAndRenameTempFile " + + (success ? "" : "un") + "successfully"); } } if (!success) { - JvOptionPane.showInternalMessageDialog(this, MessageManager - .formatMessage("label.couldnt_save_file", new Object[] - { fileName }), - MessageManager.getString("label.error_saving_file"), - JvOptionPane.WARNING_MESSAGE); + if (!Platform.isHeadless()) + { + JvOptionPane.showInternalMessageDialog(this, MessageManager + .formatMessage("label.couldnt_save_file", new Object[] + { fileName }), + MessageManager.getString("label.error_saving_file"), + JvOptionPane.WARNING_MESSAGE); + } } return success; @@ -2736,8 +2764,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (viewport.getViewName() == null) { - viewport.setViewName(MessageManager - .getString("label.view_name_original")); + viewport.setViewName( + MessageManager.getString("label.view_name_original")); } /* @@ -3366,8 +3394,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * otherwise set the chosen colour scheme (or null for 'None') */ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name, - viewport, - viewport.getAlignment(), viewport.getHiddenRepSequences()); + viewport, viewport.getAlignment(), + viewport.getHiddenRepSequences()); changeColour(cs); } @@ -5694,6 +5722,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } private Rectangle lastFeatureSettingsBounds = null; + @Override public void setFeatureSettingsGeometry(Rectangle bounds) { diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index 1a0f72d..d52dfbf 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -131,26 +131,37 @@ public class BackupFiles { String tempfilename = file.getName(); File tempdir = file.getParentFile(); + Cache.log.debug( + "BACKUPFILES [file!=null] attempting to create temp file " + + tempfilename + " in dir " + tempdir); temp = File.createTempFile(tempfilename, TEMP_FILE_EXT + newTempFileSuffix, tempdir); } else { + Cache.log.debug( + "BACKUPFILES [file==null] attempting to create default temp file " + + DEFAULT_TEMP_FILE + " with extension " + + TEMP_FILE_EXT); temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT); } } catch (IOException e) { - Cache.log.error( - "Could not create temp file to save into (IOException)"); + Cache.log + .error("Could not create temp file to save to (IOException)"); + Cache.log.error(e.getMessage()); + Cache.log.debug(e.getStackTrace()); } catch (Exception e) { Cache.log.error("Exception ctreating temp file for saving"); + Cache.log.debug(e.getStackTrace()); } this.setTempFile(temp); } public static void classInit() { + Cache.log.debug("BACKUPFILES classInit"); setEnabled(Cache.getDefault(ENABLED, true)); BackupFilesPresetEntry bfpe = BackupFilesPresetEntry .getSavedBackupEntry(); @@ -201,6 +212,7 @@ public class BackupFiles Cache.log.error( "IOException when getting Canonical Path of temp file '" + this.getTempFile().getName() + "'"); + Cache.log.debug(e.getStackTrace()); } return path; } @@ -244,22 +256,27 @@ public class BackupFiles return true; } + Cache.log.debug("BACKUPFILES rollBackupFiles starting"); + String dir = ""; File dirFile; try { dirFile = file.getParentFile(); dir = dirFile.getCanonicalPath(); - Cache.log.debug("BACKUPFILES: dir: " + dir); + Cache.log.debug("BACKUPFILES dir: " + dir); } catch (Exception e) { Cache.log.error( "Could not get canonical path for file '" + file + "'"); + Cache.log.error(e.getMessage()); + Cache.log.debug(e.getStackTrace()); return false; } String filename = file.getName(); String basename = filename; + Cache.log.debug("BACKUPFILES filename is " + filename); boolean ret = true; // Create/move backups up one @@ -276,6 +293,8 @@ public class BackupFiles if (backupFiles.length == 0) { // No other backup files. Just need to move existing file to backupfile_1 + Cache.log.debug( + "BACKUPFILES no existing backup files, setting index to 1"); nextIndexNum = 1; } else @@ -288,6 +307,7 @@ public class BackupFiles if (reverseOrder) { // backup style numbering + Cache.log.debug("BACKUPFILES rolling files in reverse order"); int tempMax = noMax ? -1 : max; // noMax == true means no limits @@ -319,6 +339,7 @@ public class BackupFiles // no "oldest" file to delete previousFile = backupfile_n; fileToBeDeleted = null; + Cache.log.debug("BACKUPFILES No oldest file to delete"); continue; } @@ -329,6 +350,10 @@ public class BackupFiles File replacementFile = backupfile_n; long fileToBeDeletedLMT = fileToBeDeleted.lastModified(); long replacementFileLMT = replacementFile.lastModified(); + Cache.log.debug("BACKUPFILES fileToBeDeleted is " + + fileToBeDeleted.getAbsolutePath()); + Cache.log.debug("BACKUPFILES replacementFile is " + + backupfile_n.getAbsolutePath()); try { @@ -352,6 +377,11 @@ public class BackupFiles boolean delete = confirmNewerDeleteFile(fileToBeDeleted, replacementFile, true); + Cache.log.debug("BACKUPFILES " + + (delete ? "confirmed" : "not") + " deleting file " + + fileToBeDeleted.getAbsolutePath() + + " which is newer than " + + replacementFile.getAbsolutePath()); if (delete) { @@ -360,11 +390,17 @@ public class BackupFiles } else { + Cache.log.debug("BACKUPFILES moving " + + fileToBeDeleted.getAbsolutePath() + " to " + + oldestTempFile.getAbsolutePath()); moveFileToFile(fileToBeDeleted, oldestTempFile); } } else { + Cache.log.debug("BACKUPFILES going to move " + + fileToBeDeleted.getAbsolutePath() + " to " + + oldestTempFile.getAbsolutePath()); moveFileToFile(fileToBeDeleted, oldestTempFile); addDeleteFile(oldestTempFile); } @@ -489,7 +525,7 @@ public class BackupFiles if (delete) { addDeleteFile(fileToBeDeleted); - Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDelted): " + Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): " + fileToBeDeleted); } @@ -828,10 +864,15 @@ public class BackupFiles int pos = deleteFiles.indexOf(fileToBeDeleted); if (pos > -1) { + Cache.log.debug("BACKUPFILES not adding file " + + fileToBeDeleted.getAbsolutePath() + + " to the delete list (already at index" + pos + ")"); return true; } else { + Cache.log.debug("BACKUPFILES adding file " + + fileToBeDeleted.getAbsolutePath() + " to the delete list"); deleteFiles.add(fileToBeDeleted); } return ret; @@ -845,19 +886,24 @@ public class BackupFiles try { // delete destination file - not usually necessary but Just In Case... + Cache.log.debug("BACKUPFILES deleting " + newFile.getAbsolutePath()); newFile.delete(); + Cache.log.debug("BACKUPFILES moving " + oldFile.getAbsolutePath() + + " to " + newFile.getAbsolutePath()); Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING); ret = true; + Cache.log.debug("BACKUPFILES move seemse to have succeeded"); } catch (IOException e) { Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '" + newPath.toString() + "'"); - Cache.log.error(e.getStackTrace()); + Cache.log.error(e.getMessage()); + Cache.log.debug(e.getStackTrace()); ret = false; } catch (Exception e) { Cache.log.error(e.getMessage()); - Cache.log.error(e.getStackTrace()); + Cache.log.debug(e.getStackTrace()); ret = false; } return ret; -- 1.7.10.2