From 97bb871d139ec136d505bae3b462d091d5f20187 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Ckpepper=E2=80=9D?= <kp11@sanger.ac.uk>
Date: Tue, 6 Feb 2018 14:45:39 +0000
Subject: [PATCH] Fix for ticket 503254 - ACT was not validating input file
arguments
---
ChangeLog | 4 +-
act | 2 +-
art | 2 +-
uk/ac/sanger/artemis/components/ActMain.java | 85 ++++++++++++++++----
4 files changed, 75 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e3c83d5f3..79ea212ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,7 +32,7 @@ Version 17
Fixed RT ticket #606061 - Using EBI-Dbfetch on ARTEMIS. Change to DbfetchEntrySource.java due to incorrect regular expression and EBI URL.
- Resized splash screen.
+ Resized splash screen, as it was too small to the accommodate text info.
Added error handling for dnaplotter template file loading in standalone mode.
@@ -40,6 +40,8 @@ Version 17
Fixed RT ticket #467433 - Genbank DBSOURCE field was not recognised by Artemis. DBLINK was already added.
+ Fixed RT ticket #503254 - Act doesn't detect if file does not exist.
+
KNOWN ISSUES:
1) Java JDKs 1.8.0_131 and above have a Swing bug related to overlaying of modal dialogs for Mac OS X: https://bugs.openjdk.java.net/browse/JDK-8179335
2) There is a current bug in htsjdk whereby calls to the queryMate functionality can throw an exception on reads with secondaries and/or supplementals.
diff --git a/act b/act
index f07e84da6..2cb25aec2 100755
--- a/act
+++ b/act
@@ -24,7 +24,7 @@ usage () {
echo " -DuserplotX=FILE[,FILE2] For sequence 'X' open one or more userplots"
echo " -DloguserplotX=FILE[,FILE2] For sequence 'X' open one or more userplots, take log(data)"
echo " -DbamX=FILE[,FILE2,...] For sequence 'X' open one or more BAM, CRAM, VCF, or BCF files"
- echo " -Dchado="h:p/d?u" Get ACT to open this CHADO database"
+ echo " -Dchado=\"h:p/d?u\" Get ACT to open this CHADO database"
echo " -Dread_only Open CHADO database read-only"
echo "EXAMPLES"
echo " % act"
diff --git a/art b/art
index ce30ace7b..36c80034f 100755
--- a/art
+++ b/art
@@ -31,7 +31,7 @@ usage () {
echo " -Dshow_cov_plot Open coverage plot in BamView"
echo " -Dshow_forward_lines=? Hide/show forward frame lines [true,false]"
echo " -Dshow_reverse_lines=? Hide/show reverse frame lines [true,false]"
- echo " -Dchado="h:p/d?u" Get Artemis to open this CHADO database"
+ echo " -Dchado=\"h:p/d?u\" Get Artemis to open this CHADO database"
echo " -Dread_only Open CHADO database read-only"
echo "EXAMPLES"
echo " % art AJ006275.embl"
diff --git a/uk/ac/sanger/artemis/components/ActMain.java b/uk/ac/sanger/artemis/components/ActMain.java
index fabcbb50d..e804f7df1 100644
--- a/uk/ac/sanger/artemis/components/ActMain.java
+++ b/uk/ac/sanger/artemis/components/ActMain.java
@@ -39,7 +39,10 @@ import uk.ac.sanger.artemis.io.EntryInformation;
import uk.ac.sanger.artemis.io.SimpleEntryInformation;
import java.awt.event.*;
+import java.io.File;
import java.io.IOException;
+import java.net.URL;
+
import javax.swing.JFrame;
/**
@@ -344,26 +347,52 @@ public class ActMain extends Splash
{
System.exit(0);
}
-
+
/**
- * Main entry point for ACT
- **/
- public static void main(final String [] args)
+ * Validate the program input arguments and exit
+ * if they are not valid, displaying an error message(s).
+ * @param args String array
+ */
+ protected static void validateStartupArguments(final String[] args)
{
- final ActMain main_window = new ActMain();
- main_window.setVisible(true);
-
- final InputStreamProgressListener progress_listener =
- main_window.getInputStreamProgressListener();
-
- if(args.length >= 3)
- ActMain.makeMultiComparator(main_window, progress_listener,
- args);
+ boolean valid = true;
+
+ if(args.length >= 3)
+ {
+ // Make sure the files provided are actually valid as far as possible...
+ for (String file : args)
+ {
+ if (file.startsWith("ftp") || file.startsWith("http"))
+ {
+ // web resource
+ try
+ {
+ URL url = new URL(file);
+ }
+ catch (Exception e)
+ {
+ valid = false;
+ System.err.println("\nError - " + file + " is not a valid URL.");
+ }
+ }
+ else
+ {
+ // normal file
+ File argFile = new File(file);
+ if (!argFile.exists() || !argFile.isFile())
+ {
+ valid = false;
+ System.err.println("\nError - " + argFile + " is not a valid file.");
+ }
+ }
+ }
+
+ }
else
{
if(args.length != 0)
{
- System.err.println("Error - this program needs either no " +
+ System.err.println("\nError - this program needs either no" +
" arguments or an odd number\n" +
"(3 or more):");
System.err.println(" act sequence_1 comparison_data sequence_2");
@@ -371,8 +400,34 @@ public class ActMain extends Splash
System.err.println(" act seq_1 comparison_data_2_v_1 seq_2 comparison_data_3_v_2 seq_3");
System.err.println("or");
System.err.println(" act");
- System.exit(1);
+ valid = false;
}
+ }
+
+ if (!valid)
+ {
+ System.exit(1);
+ }
+
+ }
+
+ /**
+ * Main entry point for ACT
+ **/
+ public static void main(final String [] args)
+ {
+ validateStartupArguments(args);
+
+ final ActMain main_window = new ActMain();
+ main_window.setVisible(true);
+
+ final InputStreamProgressListener progress_listener =
+ main_window.getInputStreamProgressListener();
+
+ if(args.length >= 3)
+ {
+ ActMain.makeMultiComparator(main_window, progress_listener,
+ args);
}
}
--
GitLab