From: Jim Procter Date: Mon, 21 Sep 2020 11:01:51 +0000 (+0100) Subject: Merge branch 'merge_review/JAL-3490_2_11_2_develop' into develop X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=490bea038483dcc853766de08a8971668930f43a;hp=6703c43876aef57616388139c30b05ef53440b07;p=jalview.git Merge branch 'merge_review/JAL-3490_2_11_2_develop' into develop --- diff --git a/RELEASE b/RELEASE index 5a89907..ddc7974 100644 --- a/RELEASE +++ b/RELEASE @@ -1,2 +1,2 @@ -jalview.release=releases/Release_2_11_1_Branch -jalview.version=2.11.1.0 +jalview.release=releases/Release_2_11_2_Branch +jalview.version=2.11.2.0 diff --git a/build.gradle b/build.gradle index bfd7a8f..4fe4088 100644 --- a/build.gradle +++ b/build.gradle @@ -2841,10 +2841,25 @@ task jalviewjsIDE_checkJ2sPlugin { if (eclipseHome == null || ! IN_ECLIPSE) { throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. Skipping J2S Plugin Check.") } - def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}" - def eclipseJ2sPluginFile = file(eclipseJ2sPlugin) - if (!eclipseJ2sPluginFile.exists()) { - def msg = "Eclipse J2S Plugin is not installed (could not find '${eclipseJ2sPlugin}')\nTry running task jalviewjsIDE_copyJ2sPlugin" + def eclipseJ2sPluginDirs = [ "${eclipseHome}/dropins" ] + def altPluginsDir = System.properties["org.eclipse.equinox.p2.reconciler.dropins.directory"] + if (altPluginsDir != null && file(altPluginsDir).exists()) { + eclipseJ2sPluginDirs += altPluginsDir + } + def foundPlugin = false + def j2sPluginFileName = j2sPluginFile.getName() + def eclipseJ2sPlugin + def eclipseJ2sPluginFile + eclipseJ2sPluginDirs.any { dir -> + eclipseJ2sPlugin = "${dir}/${j2sPluginFileName}" + eclipseJ2sPluginFile = file(eclipseJ2sPlugin) + if (eclipseJ2sPluginFile.exists()) { + foundPlugin = true + return true + } + } + if (!foundPlugin) { + def msg = "Eclipse J2S Plugin is not installed (could not find '${j2sPluginFileName}' in\n"+eclipseJ2sPluginDirs.join("\n")+"\n)\nTry running task jalviewjsIDE_copyJ2sPlugin" System.err.println(msg) throw new StopExecutionException(msg) } @@ -2862,7 +2877,7 @@ task jalviewjsIDE_checkJ2sPlugin { System.err.println(msg) throw new StopExecutionException(msg) } else { - def msg = "Eclipse J2S Plugin is the same as '${j2sPlugin}' (this is good)" + def msg = "Eclipse J2S Plugin '${eclipseJ2sPlugin}' is the same as '${j2sPlugin}' (this is good)" println(msg) } } diff --git a/getdown/lib/FJVL_VERSION b/getdown/lib/FJVL_VERSION index e7a1de7..8228610 100644 --- a/getdown/lib/FJVL_VERSION +++ b/getdown/lib/FJVL_VERSION @@ -1 +1 @@ -1.8.3-1.2.4_FJVL +1.8.3-1.2.8_FJVL diff --git a/getdown/lib/JVL_VERSION b/getdown/lib/JVL_VERSION index 756f4bd..3e098de 100644 --- a/getdown/lib/JVL_VERSION +++ b/getdown/lib/JVL_VERSION @@ -1 +1 @@ -1.8.3-1.2.4_JVL +1.8.3-1.2.8_JVL diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index 9c0f96e..f800c5c 100644 Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ diff --git a/getdown/lib/getdown-launcher-local.jar b/getdown/lib/getdown-launcher-local.jar index cfa96f3..c0ed4a1 100644 Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index 2f8baa7..4fddd99 100644 Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ diff --git a/getdown/src/getdown/ant/pom.xml b/getdown/src/getdown/ant/pom.xml index 8dcef42..756bb16 100644 --- a/getdown/src/getdown/ant/pom.xml +++ b/getdown/src/getdown/ant/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.8_FJVL getdown-ant diff --git a/getdown/src/getdown/core/pom.xml b/getdown/src/getdown/core/pom.xml index 2d0e89a..7c4d779 100644 --- a/getdown/src/getdown/core/pom.xml +++ b/getdown/src/getdown/core/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.8_FJVL getdown-core diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java index fd53c79..b301a0f 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/data/Application.java @@ -27,6 +27,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; +import jalview.bin.HiDPISetting; import jalview.bin.MemorySetting; //import com.install4j.api.launcher.Variables; @@ -1071,6 +1072,13 @@ public class Application args.add("-Dinstaller_template_version=" + System.getProperty("installer_template_version")); args.add("-Dlauncher_version=" + Build.version()); + // set HiDPI property if wanted + String scalePropertyArg = HiDPISetting.getScalePropertyArg(); + if (scalePropertyArg != null) + { + args.add(scalePropertyArg); + } + // set the native library path if we have native resources // @TODO optional getdown.txt parameter to set addCurrentLibraryPath to true or false? ClassPath javaLibPath = PathBuilder.buildLibsPath(this, true); @@ -1411,6 +1419,8 @@ public class Application clearValidationMarkers(); // if the new copy validates, reinitialize ourselves; otherwise report baffling hoseage if (_digest.validateResource(crsrc, null)) { + // unset _initialisedConfig so new file is initialised + _initialisedConfig = null; init(true); } else { log.warning(CONFIG_FILE + " failed to validate even after redownloading. " + diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java new file mode 100644 index 0000000..5e20d76 --- /dev/null +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java @@ -0,0 +1,48 @@ +package jalview.bin; + +import java.awt.Toolkit; + +public class HiDPISetting +{ + public static final int dpi; + + public static final int scale; + + private static final int hidpi = 110; + + private static final String scaleProperty = "sun.java2d.uiScale"; + + private static final boolean isAMac = System.getProperty("os.name") + .indexOf("Mac") > -1; + + private static final boolean isLinux = System.getProperty("os.name") + .toLowerCase().indexOf("linux") > -1; + + private static final boolean isWindows = System.getProperty("os.name") + .toLowerCase().indexOf("windows") > -1; + + static + { + dpi = Toolkit.getDefaultToolkit().getScreenResolution(); + scale = dpi / hidpi + 1; + if (scale > 1 && isLinux) + { + System.out.println("DPI detected as " + dpi + + ". Scaling factor set to " + scale + "."); + } + } + + public static String getScalePropertyArg() + { + // HiDPI setting. Just looking at Linux to start with. Test with Windows. + if (!isLinux) + { + return null; + } + if (scale > 1) + { + return "-D" + scaleProperty + "=" + scale; + } + return null; + } +} diff --git a/getdown/src/getdown/launcher/pom.xml b/getdown/src/getdown/launcher/pom.xml index ad87541..6af81a9 100644 --- a/getdown/src/getdown/launcher/pom.xml +++ b/getdown/src/getdown/launcher/pom.xml @@ -4,7 +4,7 @@ com.threerings.getdown getdown - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.8_FJVL getdown-launcher diff --git a/getdown/src/getdown/mvn_cmd b/getdown/src/getdown/mvn_cmd index 3f9b4a2..6558cb9 100755 --- a/getdown/src/getdown/mvn_cmd +++ b/getdown/src/getdown/mvn_cmd @@ -3,7 +3,7 @@ if [ x$JVLVERSION != x ]; then export VERSION=$JVLVERSION else - export VERSION=1.8.3-1.2.4_JVL + export VERSION=1.8.3-1.2.8_JVL fi if [ x${VERSION%_JVL} = x$VERSION ]; then diff --git a/getdown/src/getdown/pom.xml b/getdown/src/getdown/pom.xml index 2ca4aa1..4585d06 100644 --- a/getdown/src/getdown/pom.xml +++ b/getdown/src/getdown/pom.xml @@ -10,7 +10,7 @@ com.threerings.getdown getdown pom - 1.8.3-1.2.4_FJVL + 1.8.3-1.2.8_FJVL getdown An application installer and updater. diff --git a/help/help/html/keys.html b/help/help/html/keys.html index 1a5fc18..29b6813 100755 --- a/help/help/html/keys.html +++ b/help/help/html/keys.html @@ -78,34 +78,24 @@ Redo the last sequence edit undone. - Up Arrow - Normal - Moves selected sequence(s) up the alignment - - - Down Arrow - Normal - Moves selected sequence(s) down the alignment. - - - Left Arrow - Normal - Slides selected sequence(s) left. Press Alt key to slide - in cursor mode - - - Right Arrow - Normal - Slides selected sequence(s) right. Press Alt key to slide - in cursor mode - - Cursor Keys
(Arrow Keys)
Cursor Move cursor around alignment + Cursor Keys
(Arrow Keys) +
+ Normal
+ (+Alt in Cursor) + Moves selected sequence(s) up, down, left, or right + according to the direction pressed.
+
+ Alt+Arrow key to move selection or sequence under cursor + in cursor mode. + + + Page Up Both Scroll up the alignment view diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index 9c0f96e..f800c5c 100644 Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ diff --git a/j8lib/getdown-core.jar b/j8lib/getdown-core.jar index 9c0f96e..f800c5c 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/src/jalview/bin/HiDPISetting.java b/src/jalview/bin/HiDPISetting.java new file mode 100644 index 0000000..5e20d76 --- /dev/null +++ b/src/jalview/bin/HiDPISetting.java @@ -0,0 +1,48 @@ +package jalview.bin; + +import java.awt.Toolkit; + +public class HiDPISetting +{ + public static final int dpi; + + public static final int scale; + + private static final int hidpi = 110; + + private static final String scaleProperty = "sun.java2d.uiScale"; + + private static final boolean isAMac = System.getProperty("os.name") + .indexOf("Mac") > -1; + + private static final boolean isLinux = System.getProperty("os.name") + .toLowerCase().indexOf("linux") > -1; + + private static final boolean isWindows = System.getProperty("os.name") + .toLowerCase().indexOf("windows") > -1; + + static + { + dpi = Toolkit.getDefaultToolkit().getScreenResolution(); + scale = dpi / hidpi + 1; + if (scale > 1 && isLinux) + { + System.out.println("DPI detected as " + dpi + + ". Scaling factor set to " + scale + "."); + } + } + + public static String getScalePropertyArg() + { + // HiDPI setting. Just looking at Linux to start with. Test with Windows. + if (!isLinux) + { + return null; + } + if (scale > 1) + { + return "-D" + scaleProperty + "=" + scale; + } + return null; + } +} diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index f5b7009..e130277 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -465,6 +465,7 @@ public class Jalview if (!headless) { + desktop = new Desktop(); desktop.setInBatchMode(true); // indicate we are starting up diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index fb1c5cd..5e6e48c 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -49,8 +49,8 @@ public class Launcher /** * main method for jalview.bin.Launcher. This restarts the same JRE's JVM with - * the same arguments but with memory adjusted based on extracted -jvmmempc and - * -jvmmemmax application arguments. If on a Mac then extra dock:icon and + * the same arguments but with memory adjusted based on extracted -jvmmempc + * and -jvmmemmax application arguments. If on a Mac then extra dock:icon and * dock:name arguments are also set. * * @param args @@ -130,7 +130,7 @@ public class Launcher if (!memSet) { long maxMemLong = MemorySetting.getMemorySetting(jvmmemmax, jvmmempc); - + if (maxMemLong > 0) { memSetting = "-Xmx" + Long.toString(maxMemLong); @@ -153,6 +153,12 @@ public class Launcher } } + String scalePropertyArg = HiDPISetting.getScalePropertyArg(); + if (scalePropertyArg != null) + { + command.add(scalePropertyArg); + } + command.add(startClass); command.addAll(arguments); @@ -176,7 +182,8 @@ public class Launcher if (e.getMessage().toLowerCase().contains("memory")) { System.out.println("Caught a memory exception: " + e.getMessage()); - // Probably the "Cannot allocate memory" error, try without the memory setting + // Probably the "Cannot allocate memory" error, try without the memory + // setting ArrayList commandNoMem = new ArrayList<>(); for (int i = 0; i < command.size(); i++) { diff --git a/src/jalview/ext/ensembl/EnsemblRestClient.java b/src/jalview/ext/ensembl/EnsemblRestClient.java index 771980c..59c568b 100644 --- a/src/jalview/ext/ensembl/EnsemblRestClient.java +++ b/src/jalview/ext/ensembl/EnsemblRestClient.java @@ -69,9 +69,9 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher * @see https://github.com/Ensembl/ensembl-rest/wiki/Change-log * @see http://rest.ensembl.org/info/rest?content-type=application/json */ - private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "10.0"; + private static final String LATEST_ENSEMBLGENOMES_REST_VERSION = "13.0"; - private static final String LATEST_ENSEMBL_REST_VERSION = "10.0"; + private static final String LATEST_ENSEMBL_REST_VERSION = "13.0"; private static final String REST_CHANGE_LOG = "https://github.com/Ensembl/ensembl-rest/wiki/Change-log"; diff --git a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java index 43cdeb1..ced22fa 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraCommands.java @@ -388,33 +388,6 @@ public class ChimeraCommands extends StructureCommandsBase return new StructureCommand("open " + file); } - /** - * Overrides the default method to concatenate colour commands into one - */ - @Override - public List colourBySequence( - Map colourMap) - { - List commands = new ArrayList<>(); - StringBuilder sb = new StringBuilder(colourMap.size() * 20); - boolean first = true; - for (Object key : colourMap.keySet()) - { - Color colour = (Color) key; - final AtomSpecModel colourData = colourMap.get(colour); - StructureCommandI command = getColourCommand(colourData, colour); - if (!first) - { - sb.append(getCommandSeparator()); - } - first = false; - sb.append(command.getCommand()); - } - - commands.add(new StructureCommand(sb.toString())); - return commands; - } - @Override public StructureCommandI openSession(String filepath) { diff --git a/src/jalview/ext/so/SequenceOntology.java b/src/jalview/ext/so/SequenceOntology.java index 0d631e6..138aa58 100644 --- a/src/jalview/ext/so/SequenceOntology.java +++ b/src/jalview/ext/so/SequenceOntology.java @@ -20,8 +20,6 @@ */ package jalview.ext.so; -import jalview.io.gff.SequenceOntologyI; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; @@ -44,6 +42,9 @@ import org.biojava.nbio.ontology.Triple; import org.biojava.nbio.ontology.io.OboParser; import org.biojava.nbio.ontology.utils.Annotation; +import jalview.bin.Cache; +import jalview.io.gff.SequenceOntologyI; + /** * A wrapper class that parses the Sequence Ontology and exposes useful access * methods. This version uses the BioJava parser. @@ -114,7 +115,7 @@ public class SequenceOntology implements SequenceOntologyI } } long elapsed = System.currentTimeMillis() - now; - System.out.println("Loaded Sequence Ontology from " + zipFile + " (" + Cache.log.info("Loaded Sequence Ontology from " + zipFile + " (" + elapsed + "ms)"); } catch (Exception e) { @@ -183,19 +184,19 @@ public class SequenceOntology implements SequenceOntologyI boolean oldTermIsObsolete = isObsolete(replaced); if (newTermIsObsolete && !oldTermIsObsolete) { - System.err.println("Ignoring " + term.getName() + Cache.log.debug("Ignoring " + term.getName() + " as obsolete and duplicated by " + replaced.getName()); term = replaced; } else if (!newTermIsObsolete && oldTermIsObsolete) { - System.err.println("Ignoring " + replaced.getName() + Cache.log.debug("Ignoring " + replaced.getName() + " as obsolete and duplicated by " + term.getName()); } else { - System.err.println("Warning: " + term.getName() + Cache.log.debug("Warning: " + term.getName() + " has replaced " + replaced.getName() + " for lookup of '" + description + "'"); } @@ -336,7 +337,7 @@ public class SequenceOntology implements SequenceOntologyI { if (!termsNotFound.contains(term)) { - System.err.println("SO term " + term + " invalid"); + Cache.log.error("SO term " + term + " invalid"); termsNotFound.add(term); } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b02a83d..1f3f409 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -1782,10 +1782,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! + * Calls AlignmentI.moveSelectedSequencesByOne with current sequence selection or the sequence under cursor in keyboard mode * * @param up - * DOCUMENT ME! + * or down (if !up) */ public void moveSelectedSequences(boolean up) { @@ -1793,8 +1793,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (sg == null) { - return; + if (viewport.cursorMode) + { + sg = new SequenceGroup(); + sg.addSequence(viewport.getAlignment() + .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY),false); + } else { + return; + } + } + + if (sg.getSize() < 1) + { + return; } + + // TODO: JAL-3733 - add an event to the undo buffer for this ! + viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up); alignPanel.paintAlignment(true, false); diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 35ae242..f8172dc 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -634,6 +634,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, mouseDragLastX = -1; mouseDragLastY = -1; mouseDragging = false; + if (dragMode == DragMode.Resize) + { + ap.adjustAnnotationHeight(); + } dragMode = DragMode.Undefined; ap.getScalePanel().mouseReleased(evt); @@ -674,16 +678,25 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } /** - * DOCUMENT ME! + * Action on starting or continuing a mouse drag. There are two possible + * actions: + *
    + *
  • drag up or down on a graphed annotation increases or decreases the + * height of the graph
  • + *
  • dragging left or right selects the columns dragged across
  • + *
+ * A drag on a graph annotation is treated as column selection if it starts + * with more horizontal than vertical movement, and as resize if it starts + * with more vertical than horizontal movement. Once started, the drag does + * not change mode. * * @param evt - * DOCUMENT ME! */ @Override public void mouseDragged(MouseEvent evt) { /* - * todo: if dragMode is Undefined: + * if dragMode is Undefined: * - set to Select if dx > dy * - set to Resize if dy > dx * - do nothing if dx == dy diff --git a/src/jalview/io/FileParse.java b/src/jalview/io/FileParse.java index 39d8ad4..2ff0d27 100755 --- a/src/jalview/io/FileParse.java +++ b/src/jalview/io/FileParse.java @@ -20,12 +20,6 @@ */ package jalview.io; -import jalview.api.AlignExportSettingsI; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.api.FeatureSettingsModelI; -import jalview.util.MessageManager; - import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -43,6 +37,12 @@ import java.net.URL; import java.net.URLConnection; import java.util.zip.GZIPInputStream; +import jalview.api.AlignExportSettingsI; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureSettingsModelI; +import jalview.bin.Cache; +import jalview.util.MessageManager; import jalview.util.Platform; /** @@ -210,18 +210,38 @@ public class FileParse } return error; } - + /** * Recognise the 2-byte magic header for gzip streams * * https://recalll.co/ask/v/topic/java-How-to-check-if-InputStream-is-Gzipped/555aadd62bd27354438b90f6 * - * @param bytes - at least two bytes - * @return + * @param bytes + * - at least two bytes + * @return + * @throws IOException */ - private static boolean isGzipStream(byte[] bytes) { - int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); - return (GZIPInputStream.GZIP_MAGIC == head); + public static boolean isGzipStream(InputStream input) throws IOException + { + if (!input.markSupported()) + { + Cache.log.error( + "FileParse.izGzipStream: input stream must support mark/reset"); + return false; + } + input.mark(4); + + // get first 2 bytes or return false + byte[] bytes = new byte[2]; + int read = input.read(bytes); + input.reset(); + if (read != bytes.length) + { + return false; + } + + int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + return (GZIPInputStream.GZIP_MAGIC == header); } /** @@ -231,27 +251,26 @@ public class FileParse * @param input * @return */ - private BufferedReader checkForGzipStream(InputStream input) throws Exception { - - // NB: stackoverflow https://stackoverflow.com/questions/4818468/how-to-check-if-inputstream-is-gzipped + private BufferedReader checkForGzipStream(InputStream input) + throws Exception + { + // NB: stackoverflow + // https://stackoverflow.com/questions/4818468/how-to-check-if-inputstream-is-gzipped // could use a PushBackInputStream rather than a BufferedInputStream - - BufferedInputStream bufinput; - if (!input.markSupported()) { - bufinput= new BufferedInputStream(input,16); - input = bufinput; + if (!input.markSupported()) + { + input = new BufferedInputStream(input, 16); } - input.mark(4); - byte[] bytes=input.readNBytes(2); - input.reset(); - if (bytes.length==2 && isGzipStream(bytes)) { + if (isGzipStream(input)) + { return getGzipReader(input); } // return a buffered reader for the stream. - InputStreamReader isReader= new InputStreamReader(input); - BufferedReader toReadFrom=new BufferedReader(isReader); + InputStreamReader isReader = new InputStreamReader(input); + BufferedReader toReadFrom = new BufferedReader(isReader); return toReadFrom; } + /** * Returns a {@code BufferedReader} which wraps the input stream with a * GZIPInputStream. Throws a {@code ZipException} if a GZIP format error @@ -304,16 +323,21 @@ public class FileParse throw new IOException( "Response status from " + urlStr + " was " + rc); } - } else { - try { - dataIn = checkForGzipStream(_conn.getInputStream()); - dataName=urlStr; + } + else + { + try + { + dataIn = checkForGzipStream(_conn.getInputStream()); + dataName = urlStr; } catch (IOException ex) { - throw new IOException("Failed to handle non-HTTP URI stream",ex); + throw new IOException("Failed to handle non-HTTP URI stream", ex); } catch (Exception ex) { - throw new IOException("Failed to determine type of input stream for given URI",ex); + throw new IOException( + "Failed to determine type of input stream for given URI", + ex); } return; } diff --git a/src/jalview/io/ScoreMatrixFile.java b/src/jalview/io/ScoreMatrixFile.java index 0b70dce..ee7503d 100644 --- a/src/jalview/io/ScoreMatrixFile.java +++ b/src/jalview/io/ScoreMatrixFile.java @@ -20,13 +20,13 @@ */ package jalview.io; +import java.io.IOException; +import java.util.StringTokenizer; + import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; import jalview.datamodel.SequenceI; -import java.io.IOException; -import java.util.StringTokenizer; - /** * A class that can parse a file containing a substitution matrix and register * it for use in Jalview @@ -131,7 +131,8 @@ public class ScoreMatrixFile extends AlignFile { continue; } - if (data.toUpperCase().startsWith(SCOREMATRIX)) + // equivalent to data.startsWithIgnoreCase(SCOREMATRIX) + if (data.regionMatches(true, 0, SCOREMATRIX, 0, SCOREMATRIX.length())) { /* * Parse name from ScoreMatrix diff --git a/src/jalview/structure/StructureCommandsBase.java b/src/jalview/structure/StructureCommandsBase.java index 57544b7..8716691 100644 --- a/src/jalview/structure/StructureCommandsBase.java +++ b/src/jalview/structure/StructureCommandsBase.java @@ -24,7 +24,7 @@ public abstract class StructureCommandsBase implements StructureCommandsI * * @return */ - protected static String getCommandSeparator() + protected String getCommandSeparator() { return CMD_SEPARATOR; } diff --git a/test/jalview/io/FileIOTester.java b/test/jalview/io/FileIOTester.java index f6480a6..e37ae3f 100644 --- a/test/jalview/io/FileIOTester.java +++ b/test/jalview/io/FileIOTester.java @@ -20,16 +20,25 @@ */ package jalview.io; -import jalview.gui.JvOptionPane; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.StringBufferInputStream; import org.testng.AssertJUnit; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import jalview.bin.Cache; +import jalview.gui.JvOptionPane; + /** * @author jimp * @@ -50,6 +59,7 @@ public class FileIOTester @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { + Cache.initLogger(); } /** @@ -88,8 +98,9 @@ public class FileIOTester public void testStarsInFasta1() throws IOException { String uri; - FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile() - .toString(), DataSourceType.FILE); + FileParse fp = new FileParse( + uri = STARS_FA_FILE1.getAbsoluteFile().toString(), + DataSourceType.FILE); assertValidFormat(FileFormat.Fasta, uri, fp); } @@ -97,8 +108,9 @@ public class FileIOTester public void testStarsInFasta2() throws IOException { String uri; - FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile() - .toString(), DataSourceType.FILE); + FileParse fp = new FileParse( + uri = STARS_FA_FILE2.getAbsoluteFile().toString(), + DataSourceType.FILE); assertValidFormat(FileFormat.Fasta, uri, fp); } @@ -106,8 +118,9 @@ public class FileIOTester public void testGzipIo() throws IOException { String uri; - FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI() - .toString(), DataSourceType.URL); + FileParse fp = new FileParse( + uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(), + DataSourceType.URL); assertValidFormat(FileFormat.Fasta, uri, fp); } @@ -115,17 +128,42 @@ public class FileIOTester public void testGziplocalFileIO() throws IOException { String filepath; - FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile() - .toString(), DataSourceType.FILE); + FileParse fp = new FileParse( + filepath = ALIGN_FILE.getAbsoluteFile().toString(), + DataSourceType.FILE); assertValidFormat(FileFormat.Fasta, filepath, fp); } @Test(groups = { "Functional" }) + public void testIsGzipInputStream() throws IOException + { + InputStream is = new FileInputStream(ALIGN_FILE); + + /* + * first try fails - FileInputStream does not support mark/reset + */ + assertFalse(FileParse.isGzipStream(is)); + + /* + * wrap in a BufferedInputStream and try again + */ + is = new BufferedInputStream(is, 16); + assertTrue(FileParse.isGzipStream(is)); + + /* + * check recognition of non-gzipped input + */ + assertFalse(FileParse.isGzipStream(new BufferedInputStream( + new ByteArrayInputStream("NOT A GZIP".getBytes())))); + } + + @Test(groups = { "Functional" }) public void testNonGzipURLIO() throws IOException { String uri; - FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile() - .toURI().toString(), DataSourceType.URL); + FileParse fp = new FileParse( + uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(), + DataSourceType.URL); assertValidFormat(FileFormat.Fasta, uri, fp); } @@ -133,8 +171,9 @@ public class FileIOTester public void testNonGziplocalFileIO() throws IOException { String filepath; - FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE - .getAbsoluteFile().toString(), DataSourceType.FILE); + FileParse fp = new FileParse( + filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(), + DataSourceType.FILE); assertValidFormat(FileFormat.Fasta, filepath, fp); } }