import jalview.bin.Cache;
import jalview.bin.Console;
import jalview.util.ChannelProperties;
-import jalview.util.HttpUtils;
+import jalview.util.UserAgent;
public class Plausible
{
// random clientId to make User-Agent unique (to register analytic)
clientId = String.format("%08x", new Random().nextInt());
- USER_AGENT = HttpUtils.getUserAgent(
+ USER_AGENT = UserAgent.getUserAgent(
MethodHandles.lookup().lookupClass().getCanonicalName() + " "
+ clientId);
}
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
+import jalview.util.ErrorLog;
+
/**
* Isolated class to ascertain physical memory of the system using
* com.sun.management.OperatingSystemMXBean class's getTotalPhysicalMemorySize
} catch (NoClassDefFoundError e)
{
// com.sun.management.OperatingSystemMXBean doesn't exist in this JVM
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"No com.sun.management.OperatingSystemMXBean: cannot get total physical memory size");
}
import java.awt.HeadlessException;
import java.util.Locale;
+import jalview.util.ErrorLog;
+
public class HiDPISetting
{
private static final int hidpiThreshold = 160;
}
} catch (NumberFormatException e)
{
- jalview.bin.Console.errPrintln(setHiDPIScalePropertyName
- + " property give (" + setHiDPIScaleProperty
- + ") but not parseable as integer");
+ ErrorLog.errPrintln(setHiDPIScalePropertyName + " property give ("
+ + setHiDPIScaleProperty + ") but not parseable as integer");
}
}
if (setHiDPI && setHiDPIScale > 0)
try
{
int existingPropertyVal = Integer.parseInt(existingProperty);
- jalview.bin.Console.outPrintln("Existing " + scalePropertyName
- + " is " + existingPropertyVal);
+ ErrorLog.outPrintln("Existing " + scalePropertyName + " is "
+ + existingPropertyVal);
if (existingPropertyVal > 1)
{
setHiDPIScale(existingPropertyVal);
}
} catch (NumberFormatException e)
{
- jalview.bin.Console.outPrintln(
+ ErrorLog.outPrintln(
"Could not convert property " + scalePropertyName
+ " vale '" + existingProperty + "' to number");
}
{
if (isLinux)
{
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"Cannot get screen resolution: " + e.getMessage());
}
}
{
if (isLinux)
{
- jalview.bin.Console
- .errPrintln("Cannot get screen size height and width:"
- + e.getMessage());
+ ErrorLog.errPrintln("Cannot get screen size height and width:"
+ + e.getMessage());
}
}
import jalview.util.LaunchUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.UserAgent;
import jalview.ws.jws2.Jws2Discoverer;
/**
{
headless = true;
}
- System.setProperty("http.agent", HttpUtils.getUserAgent());
+ System.setProperty("http.agent", UserAgent.getUserAgent());
try
{
import java.util.Locale;
-import jalview.bin.argparser.Arg;
+import jalview.util.ErrorLog;
/**
* Methods to decide on appropriate memory setting for Jalview based on two
*/
public class MemorySetting
{
- public static final String MAX_HEAPSIZE_PERCENT_PROPERTY_NAME = Arg.JVMMEMPC
- .getName();
+ // This must match the value of Arg.JVMMEMPC.getName()
+ public static final String MAX_HEAPSIZE_PERCENT_PROPERTY_NAME = "jvmmempc";
- public static final String MAX_HEAPSIZE_PROPERTY_NAME = Arg.JVMMEMMAX
- .getName();
+ // This must match the value of Arg.JVMMEMMAX.getName()
+ public static final String MAX_HEAPSIZE_PROPERTY_NAME = "jvmmemmax";
private static final int MAX_HEAPSIZE_PERCENT_DEFAULT = 90; // 90%
else
{
// number too big for a Long. Limit to Long.MAX_VALUE
- jalview.bin.Console.outPrintln("Memory parsing of '" + memString
+ ErrorLog.outPrintln("Memory parsing of '" + memString
+ "' produces number too big. Limiting to Long.MAX_VALUE="
+ Long.MAX_VALUE);
return Long.MAX_VALUE;
ADJUSTMENT_MESSAGE = reason;
if (!quiet)
{
- jalview.bin.Console.outPrintln(reason);
+ ErrorLog.outPrintln(reason);
}
}
if (channelPropsURL == null)
{
// complete failure of channel_properties, set all properties to defaults
- jalview.bin.Console.errPrintln("Failed to find '/"
- + CHANNEL_PROPERTIES_FILENAME + "' file at '"
+ ErrorLog.errPrintln("Failed to find '/" + CHANNEL_PROPERTIES_FILENAME
+ + "' file at '"
+ (channelPropsURL == null ? "null"
: channelPropsURL.toString())
+ "'. Using class defaultProps.");
channelPropsIS.close();
} catch (IOException e)
{
- jalview.bin.Console.errPrintln(e.getMessage());
+ ErrorLog.errPrintln(e.getMessage());
// return false;
}
}
channelProps.load(is);
} catch (FileNotFoundException e)
{
- jalview.bin.Console.errPrintln(e.getMessage());
+ ErrorLog.errPrintln(e.getMessage());
} catch (IOException e)
{
- jalview.bin.Console.errPrintln(e.getMessage());
+ ErrorLog.errPrintln(e.getMessage());
}
}
}
}
else
{
- jalview.bin.Console
- .errPrintln("Failed to get channel property '" + key + "'");
+ ErrorLog.errPrintln("Failed to get channel property '" + key + "'");
}
}
return null;
img = imgIcon == null ? null : imgIcon.getImage();
if (img == null)
{
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"Failed to load channel image " + key + "=" + path);
if (!useClassDefaultImage)
{
{
return urlMap().getOrDefault(key, null);
}
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"Do not use getImageURL(key) before using getImage(key...)");
}
return null;
--- /dev/null
+package jalview.util;
+
+public class ErrorLog
+{
+ private static boolean hasConsole = true;
+
+ public static void outPrintln(String message)
+ {
+ println(message, false);
+ }
+
+ public static void errPrintln(String message)
+ {
+ println(message, true);
+ }
+
+ public static void println(String message, boolean err)
+ {
+ if (hasConsole)
+ {
+ try
+ {
+ hasConsole = jalview.bin.Console.initLogger();
+ if (hasConsole)
+ {
+ if (err)
+ {
+ jalview.bin.Console.errPrintln(message);
+ }
+ else
+ {
+ jalview.bin.Console.outPrintln(message);
+ }
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ } catch (NoClassDefFoundError t)
+ {
+ hasConsole = false;
+ System.err.println(
+ "jalview.util.ErrorLog has no jalview.bin.Console. Using System.err and System.out.");
+ }
+ }
+ if (!hasConsole)
+ {
+ if (err)
+ {
+ System.err.println("jalview.util.ErrorLog: " + message);
+ }
+ else
+ {
+ System.out.println("jalview.util.ErrorLog: " + message);
+
+ }
+ }
+ }
+}
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.ProtocolException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
-import javax.ws.rs.HttpMethod;
-
-import jalview.bin.Cache;
-
public class HttpUtils
{
// jalview.bin.Console.outPrintln(System.currentTimeMillis() + " " + url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod(HttpMethod.HEAD);
+ connection.setRequestMethod("HEAD");
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setConnectTimeout(300);
return is;
}
- public static String getUserAgent()
+ /**
+ * check if a jalview:// scheme URL is given
+ *
+ * @param String
+ * uri
+ * @return boolean
+ */
+ public static boolean isJalviewSchemeUri(String jalviewUriString)
{
- return getUserAgent(null);
+ URI jalviewUri;
+ try
+ {
+ jalviewUri = new URI(jalviewUriString);
+ } catch (URISyntaxException e)
+ {
+ return false;
+ }
+ String scheme = jalviewUri.getScheme();
+ if (scheme == null || !scheme.startsWith("jalview"))
+ {
+ return false;
+ }
+ return scheme.length() == 7 // jalview
+ || scheme.length() == 8 // jalviewX
+ || scheme.substring(7).equals("http") // jalviewhttp
+ || scheme.substring(7).equals("https"); // jalviewhttps
}
- public static String getUserAgent(String className)
+ /**
+ * convert a jalview scheme URI to its equivalent URL or path
+ *
+ * @param String
+ * uri
+ * @return String
+ */
+ public static String equivalentJalviewUrl(String jalviewUriString)
{
- StringBuilder sb = new StringBuilder();
- sb.append("Jalview");
- sb.append('/');
- sb.append(Cache.getDefault("VERSION", "Unknown"));
- sb.append(" (");
- sb.append(System.getProperty("os.name"));
- sb.append("; ");
- sb.append(System.getProperty("os.arch"));
- sb.append(' ');
- sb.append(System.getProperty("os.name"));
- sb.append(' ');
- sb.append(System.getProperty("os.version"));
- sb.append("; ");
- sb.append("java/");
- sb.append(System.getProperty("java.version"));
- sb.append("; ");
- sb.append("jalview/");
- sb.append(ChannelProperties.getProperty("channel"));
- if (className != null)
- {
- sb.append("; ");
- sb.append(className);
+ if (!isJalviewSchemeUri(jalviewUriString))
+ {
+ return null;
}
- String installation = Cache.applicationProperties
- .getProperty("INSTALLATION");
- if (installation != null)
+ URI jalviewUri;
+ try
{
- sb.append("; ");
- sb.append(installation);
+ jalviewUri = new URI(jalviewUriString);
+ } catch (URISyntaxException e)
+ {
+ return null;
}
- sb.append(')');
- sb.append(" help@jalview.org");
- return sb.toString();
+ String scheme = jalviewUri.getScheme();
+ String host = jalviewUri.getHost();
+ if (host != null && host.length() > 0)
+ {
+ URI newUri;
+ try
+ {
+ newUri = new URI(scheme.equals("jalviewhttp") ? "http" : "https",
+ jalviewUri.getUserInfo(), host, jalviewUri.getPort(),
+ jalviewUri.getPath(), jalviewUri.getQuery(),
+ jalviewUri.getFragment());
+ // return a URL
+ return newUri.toURL().toString();
+ } catch (URISyntaxException | MalformedURLException e)
+ {
+ ErrorLog.errPrintln("Trying to convert '" + jalviewUriString
+ + "' to URL failed");
+ }
+ }
+ else
+ {
+ // return a file path (not a file URI)
+ return jalviewUri.getPath();
+ }
+ return null;
}
-
}
import java.net.URL;
import java.util.Properties;
-import jalview.bin.Console;
-
public class LaunchUtils
{
-
// setting these is LaunchUtils so don't need to import Platform
public final static boolean isMac = System.getProperty("os.name")
.indexOf("Mac") > -1;
return null;
} catch (IOException e)
{
- jalview.bin.Console.errPrintln(e.getMessage());
+ ErrorLog.errPrintln(e.getMessage());
return null;
}
}
null);
if (JCV == null)
{
- Console.errPrintln(
- "Could not obtain JAVA_COMPILE_VERSION for comparison");
+ ErrorLog.errPrintln("Could not obtain JAVA_COMPILE_VERSION for comparison");
return -2;
}
JAVA_COMPILE_VERSION = Integer.parseInt(JCV);
} catch (MalformedURLException e)
{
- jalview.bin.Console.errPrintln("Could not find " + buildDetails);
+ ErrorLog.errPrintln("Could not find " + buildDetails);
return -3;
} catch (IOException e)
{
- jalview.bin.Console.errPrintln("Could not load " + buildDetails);
+ ErrorLog.errPrintln("Could not load " + buildDetails);
return -4;
} catch (NumberFormatException e)
{
- jalview.bin.Console
- .errPrintln("Could not parse JAVA_COMPILE_VERSION");
+ ErrorLog.errPrintln("Could not parse JAVA_COMPILE_VERSION");
return -5;
}
String JV = System.getProperty("java.version");
if (JV == null)
{
- Console.errPrintln("Could not obtain java.version for comparison");
+ ErrorLog.errPrintln("Could not obtain java.version for comparison");
return -2;
}
if (JV.startsWith("1."))
: Integer.parseInt(JV.substring(0, JV.indexOf(".")));
} catch (NumberFormatException e)
{
- jalview.bin.Console.errPrintln("Could not parse java.version");
+ ErrorLog.errPrintln("Could not parse java.version");
return -3;
}
return JAVA_VERSION;
if (java_compile_version <= 0 || java_version <= 0)
{
- Console.errPrintln("Could not make Java version check");
+ ErrorLog.errPrintln("Could not make Java version check");
return true;
}
// Warn if these java.version and JAVA_COMPILE_VERSION conditions exist
jv.clear();
if (DEBUG)
{
- jalview.bin.Console.errPrintln("Array from '" + delimiter
+ ErrorLog.errPrintln("Array from '" + delimiter
+ "' separated List:\n" + v.length);
for (int i = 0; i < v.length; i++)
{
- jalview.bin.Console.errPrintln("item " + i + " '" + v[i] + "'");
+ ErrorLog.errPrintln("item " + i + " '" + v[i] + "'");
}
}
return v;
}
if (DEBUG)
{
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"Empty Array from '" + delimiter + "' separated List");
}
return null;
{
System.err
.println("Returning '" + separator + "' separated List:\n");
- jalview.bin.Console.errPrintln(v);
+ ErrorLog.errPrintln(v.toString());
}
return v.toString();
}
if (DEBUG)
{
- jalview.bin.Console.errPrintln(
+ ErrorLog.errPrintln(
"Returning empty '" + separator + "' separated List\n");
}
return "" + separator;
--- /dev/null
+package jalview.util;
+
+import jalview.bin.Cache;
+
+public class UserAgent
+{
+
+ public static String getUserAgent(String className)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Jalview");
+ sb.append('/');
+ sb.append(Cache.getDefault("VERSION", "Unknown"));
+ sb.append(" (");
+ sb.append(System.getProperty("os.name"));
+ sb.append("; ");
+ sb.append(System.getProperty("os.arch"));
+ sb.append(' ');
+ sb.append(System.getProperty("os.name"));
+ sb.append(' ');
+ sb.append(System.getProperty("os.version"));
+ sb.append("; ");
+ sb.append("java/");
+ sb.append(System.getProperty("java.version"));
+ sb.append("; ");
+ sb.append("jalview/");
+ sb.append(ChannelProperties.getProperty("channel"));
+ if (className != null)
+ {
+ sb.append("; ");
+ sb.append(className);
+ }
+ String installation = Cache.applicationProperties
+ .getProperty("INSTALLATION");
+ if (installation != null)
+ {
+ sb.append("; ");
+ sb.append(installation);
+ }
+ sb.append(')');
+ sb.append(" help@jalview.org");
+ return sb.toString();
+ }
+
+ public static String getUserAgent()
+ {
+ return getUserAgent(null);
+ }
+
+}