1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.bin; |
22 |
|
|
23 |
|
import jalview.datamodel.PDBEntry; |
24 |
|
import jalview.gui.UserDefinedColours; |
25 |
|
import jalview.schemes.ColourSchemeLoader; |
26 |
|
import jalview.schemes.ColourSchemes; |
27 |
|
import jalview.schemes.UserColourScheme; |
28 |
|
import jalview.structure.StructureImportSettings; |
29 |
|
import jalview.urls.IdOrgSettings; |
30 |
|
import jalview.util.ColorUtils; |
31 |
|
import jalview.util.Platform; |
32 |
|
import jalview.ws.sifts.SiftsSettings; |
33 |
|
|
34 |
|
import java.awt.Color; |
35 |
|
import java.io.BufferedReader; |
36 |
|
import java.io.File; |
37 |
|
import java.io.FileInputStream; |
38 |
|
import java.io.FileOutputStream; |
39 |
|
import java.io.InputStream; |
40 |
|
import java.io.InputStreamReader; |
41 |
|
import java.net.URL; |
42 |
|
import java.text.DateFormat; |
43 |
|
import java.text.SimpleDateFormat; |
44 |
|
import java.util.Collections; |
45 |
|
import java.util.Date; |
46 |
|
import java.util.Enumeration; |
47 |
|
import java.util.Locale; |
48 |
|
import java.util.Properties; |
49 |
|
import java.util.StringTokenizer; |
50 |
|
import java.util.TreeSet; |
51 |
|
import java.util.regex.Pattern; |
52 |
|
|
53 |
|
import javax.swing.LookAndFeel; |
54 |
|
import javax.swing.UIManager; |
55 |
|
|
56 |
|
import org.apache.log4j.ConsoleAppender; |
57 |
|
import org.apache.log4j.Level; |
58 |
|
import org.apache.log4j.Logger; |
59 |
|
import org.apache.log4j.SimpleLayout; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@author |
213 |
|
@version |
214 |
|
|
|
|
| 49.2% |
Uncovered Elements: 220 (433) |
Complexity: 114 |
Complexity Density: 0.38 |
|
215 |
|
public class Cache |
216 |
|
{ |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
public static final String CASTORLOGLEVEL = "logs.Castor.level"; |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
public static final String AXISLOGLEVEL = "logs.Axis.level"; |
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
public static final String JALVIEWLOGLEVEL = "logs.Jalview.level"; |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System |
236 |
|
.getProperty("user.home") + File.separatorChar |
237 |
|
+ ".sifts_downloads" + File.separatorChar; |
238 |
|
|
239 |
|
private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2"; |
240 |
|
|
241 |
|
private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30"; |
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
private static final String ID_ORG_FILE = System.getProperty("user.home") |
247 |
|
+ File.separatorChar + ".identifiers.org.ids.json"; |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF |
253 |
|
.toString(); |
254 |
|
|
255 |
|
private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER |
256 |
|
.toString(); |
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
private static final DateFormat date_format = SimpleDateFormat |
264 |
|
.getDateTimeInstance(SimpleDateFormat.MEDIUM, |
265 |
|
SimpleDateFormat.MEDIUM, Locale.UK); |
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
public static Logger log; |
271 |
|
|
272 |
|
|
273 |
|
public static Properties applicationProperties = new Properties() |
274 |
|
{ |
275 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
276 |
0 |
@Override... |
277 |
|
public synchronized Enumeration<Object> keys() |
278 |
|
{ |
279 |
0 |
return Collections.enumeration(new TreeSet<>(super.keySet())); |
280 |
|
} |
281 |
|
}; |
282 |
|
|
283 |
|
|
284 |
|
static String propertiesFile; |
285 |
|
|
286 |
|
private static boolean propsAreReadOnly = Platform.isJS(); |
287 |
|
|
288 |
|
private final static String JS_PROPERTY_PREFIX = "jalview_"; |
289 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 3 |
Complexity Density: 0.17 |
|
290 |
51 |
public static void initLogger()... |
291 |
|
{ |
292 |
51 |
if (log != null) |
293 |
|
{ |
294 |
32 |
return; |
295 |
|
} |
296 |
19 |
try |
297 |
|
{ |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
19 |
ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(), |
302 |
|
"System.err"); |
303 |
19 |
ap.setName("JalviewLogger"); |
304 |
19 |
org.apache.log4j.Logger.getRootLogger().addAppender(ap); |
305 |
|
|
306 |
19 |
Logger laxis = Logger.getLogger("org.apache.axis"); |
307 |
19 |
Logger lcastor = Logger.getLogger("org.exolab.castor"); |
308 |
19 |
jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview"); |
309 |
|
|
310 |
19 |
laxis.setLevel(Level.toLevel( |
311 |
|
Cache.getDefault("logs.Axis.Level", Level.INFO.toString()))); |
312 |
19 |
lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", |
313 |
|
Level.INFO.toString()))); |
314 |
19 |
lcastor = Logger.getLogger("org.exolab.castor.xml"); |
315 |
19 |
lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", |
316 |
|
Level.INFO.toString()))); |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
19 |
org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO); |
322 |
|
|
323 |
19 |
jalview.bin.Cache.log.setLevel(Level.toLevel(Cache |
324 |
|
.getDefault("logs.Jalview.level", Level.INFO.toString()))); |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
19 |
jalview.bin.Cache.log.debug("Jalview Debugging Output Follows."); |
330 |
|
} catch (Exception ex) |
331 |
|
{ |
332 |
0 |
System.err.println("Problems initializing the log4j system\n"); |
333 |
0 |
ex.printStackTrace(System.err); |
334 |
|
} |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
|
|
| 73.6% |
Uncovered Elements: 19 (72) |
Complexity: 16 |
Complexity Density: 0.29 |
|
341 |
110 |
public static void loadProperties(String propsFile)... |
342 |
|
{ |
343 |
110 |
propertiesFile = propsFile; |
344 |
110 |
if (propsFile == null && !propsAreReadOnly) |
345 |
|
{ |
346 |
17 |
propertiesFile = System.getProperty("user.home") + File.separatorChar |
347 |
|
+ ".jalview_properties"; |
348 |
|
} |
349 |
|
else |
350 |
|
{ |
351 |
|
|
352 |
93 |
propsAreReadOnly = true; |
353 |
|
} |
354 |
|
|
355 |
110 |
if (propertiesFile == null) |
356 |
|
{ |
357 |
7 |
Platform.readInfoProperties(JS_PROPERTY_PREFIX, |
358 |
|
applicationProperties); |
359 |
|
} |
360 |
|
else |
361 |
|
{ |
362 |
103 |
try |
363 |
|
{ |
364 |
103 |
InputStream fis; |
365 |
103 |
try |
366 |
|
{ |
367 |
103 |
fis = new java.net.URL(propertiesFile).openStream(); |
368 |
0 |
System.out.println( |
369 |
|
"Loading jalview properties from : " + propertiesFile); |
370 |
0 |
System.out.println( |
371 |
|
"Disabling Jalview writing to user's local properties file."); |
372 |
0 |
propsAreReadOnly = true; |
373 |
|
|
374 |
|
} catch (Exception ex) |
375 |
|
{ |
376 |
103 |
fis = null; |
377 |
|
} |
378 |
103 |
if (fis == null) |
379 |
|
{ |
380 |
103 |
fis = new FileInputStream(propertiesFile); |
381 |
|
} |
382 |
103 |
applicationProperties.clear(); |
383 |
103 |
applicationProperties.load(fis); |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
103 |
deleteBuildProperties(); |
388 |
103 |
fis.close(); |
389 |
|
} catch (Exception ex) |
390 |
|
{ |
391 |
0 |
System.out.println("Error reading properties file: " + ex); |
392 |
|
} |
393 |
|
} |
394 |
110 |
if (getDefault("USE_PROXY", false)) |
395 |
|
{ |
396 |
0 |
String proxyServer = getDefault("PROXY_SERVER", ""), |
397 |
|
proxyPort = getDefault("PROXY_PORT", "8080"); |
398 |
|
|
399 |
0 |
System.out.println("Using proxyServer: " + proxyServer |
400 |
|
+ " proxyPort: " + proxyPort); |
401 |
|
|
402 |
0 |
System.setProperty("http.proxyHost", proxyServer); |
403 |
0 |
System.setProperty("http.proxyPort", proxyPort); |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
110 |
String authorDetails = resolveResourceURLFor("/authors.props"); |
408 |
|
|
409 |
110 |
try |
410 |
|
{ |
411 |
110 |
if (authorDetails != null) |
412 |
|
{ |
413 |
110 |
URL localJarFileURL = new URL(authorDetails); |
414 |
110 |
InputStream in = localJarFileURL.openStream(); |
415 |
110 |
applicationProperties.load(in); |
416 |
110 |
in.close(); |
417 |
|
} |
418 |
|
} catch (Exception ex) |
419 |
|
{ |
420 |
0 |
System.out.println("Error reading author details: " + ex); |
421 |
0 |
authorDetails = null; |
422 |
|
} |
423 |
110 |
if (authorDetails == null) |
424 |
|
{ |
425 |
0 |
applicationProperties.remove("AUTHORS"); |
426 |
0 |
applicationProperties.remove("AUTHORFNAMES"); |
427 |
0 |
applicationProperties.remove("YEAR"); |
428 |
|
} |
429 |
|
|
430 |
110 |
loadBuildProperties(false); |
431 |
|
|
432 |
110 |
SiftsSettings |
433 |
|
.setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false)); |
434 |
|
|
435 |
110 |
SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache |
436 |
|
.getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR)); |
437 |
|
|
438 |
110 |
SiftsSettings.setFailSafePIDThreshold( |
439 |
|
jalview.bin.Cache.getDefault("sifts_fail_safe_pid_threshold", |
440 |
|
DEFAULT_FAIL_SAFE_PID_THRESHOLD)); |
441 |
|
|
442 |
110 |
SiftsSettings.setCacheThresholdInDays( |
443 |
|
jalview.bin.Cache.getDefault("sifts_cache_threshold_in_days", |
444 |
|
DEFAULT_CACHE_THRESHOLD_IN_DAYS)); |
445 |
|
|
446 |
110 |
IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL", |
447 |
|
"http://www.jalview.org/services/identifiers")); |
448 |
110 |
IdOrgSettings.setDownloadLocation(ID_ORG_FILE); |
449 |
|
|
450 |
110 |
StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache |
451 |
|
.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT)); |
452 |
110 |
StructureImportSettings |
453 |
|
.setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER); |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
110 |
String jnlpVersion = System.getProperty("jalview.version"); |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
|
464 |
110 |
if (jnlpVersion == null && getDefault("VERSION_CHECK", true) |
465 |
|
&& (System.getProperty("java.awt.headless") == null || System |
466 |
|
.getProperty("java.awt.headless").equals("false"))) |
467 |
|
{ |
468 |
4 |
new Thread() |
469 |
|
{ |
|
|
| 78.6% |
Uncovered Elements: 6 (28) |
Complexity: 5 |
Complexity Density: 0.23 |
|
470 |
4 |
@Override... |
471 |
|
public void run() |
472 |
|
{ |
473 |
4 |
String orgtimeout = System |
474 |
|
.getProperty("sun.net.client.defaultConnectTimeout"); |
475 |
4 |
if (orgtimeout == null) |
476 |
|
{ |
477 |
4 |
orgtimeout = "30"; |
478 |
4 |
System.out.println("# INFO: Setting default net timeout to " |
479 |
|
+ orgtimeout + " seconds."); |
480 |
|
} |
481 |
4 |
String remoteVersion = null; |
482 |
4 |
try |
483 |
|
{ |
484 |
4 |
System.setProperty("sun.net.client.defaultConnectTimeout", |
485 |
|
"5000"); |
486 |
4 |
java.net.URL url = new java.net.URL(Cache |
487 |
|
.getDefault("www.jalview.org", "http://www.jalview.org") |
488 |
|
+ "/webstart/jalview.jnlp"); |
489 |
4 |
BufferedReader in = new BufferedReader( |
490 |
|
new InputStreamReader(url.openStream())); |
491 |
4 |
String line = null; |
492 |
? |
while ((line = in.readLine()) != null) |
493 |
|
{ |
494 |
272 |
if (line.indexOf("jalview.version") == -1) |
495 |
|
{ |
496 |
268 |
continue; |
497 |
|
} |
498 |
|
|
499 |
4 |
line = line.substring(line.indexOf("value=") + 7); |
500 |
4 |
line = line.substring(0, line.lastIndexOf("\"")); |
501 |
4 |
remoteVersion = line; |
502 |
4 |
break; |
503 |
|
} |
504 |
|
} catch (Exception ex) |
505 |
|
{ |
506 |
0 |
System.out.println( |
507 |
|
"Non-fatal exception when checking version at www.jalview.org :"); |
508 |
0 |
System.out.println(ex); |
509 |
0 |
remoteVersion = getProperty("VERSION"); |
510 |
|
} |
511 |
4 |
System.setProperty("sun.net.client.defaultConnectTimeout", |
512 |
|
orgtimeout); |
513 |
|
|
514 |
4 |
setProperty("LATEST_VERSION", remoteVersion); |
515 |
|
} |
516 |
|
}.start(); |
517 |
|
} |
518 |
|
else |
519 |
|
{ |
520 |
106 |
if (jnlpVersion != null) |
521 |
|
{ |
522 |
0 |
setProperty("LATEST_VERSION", jnlpVersion); |
523 |
|
} |
524 |
|
else |
525 |
|
{ |
526 |
106 |
applicationProperties.remove("LATEST_VERSION"); |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
|
|
531 |
110 |
Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); |
532 |
110 |
jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", |
533 |
|
false); |
534 |
|
} |
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
@param |
540 |
|
@return |
541 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
542 |
255 |
private static String resolveResourceURLFor(String resourcePath)... |
543 |
|
{ |
544 |
255 |
String url = null; |
545 |
255 |
if (Platform.isJS() || !Cache.class.getProtectionDomain() |
546 |
|
.getCodeSource().getLocation().toString().endsWith(".jar")) |
547 |
|
{ |
548 |
255 |
try |
549 |
|
{ |
550 |
255 |
url = Cache.class.getResource(resourcePath).toString(); |
551 |
|
} catch (Exception ex) |
552 |
|
{ |
553 |
0 |
System.err.println("Failed to resolve resource " + resourcePath + ": " |
554 |
|
+ ex.getMessage()); |
555 |
|
} |
556 |
|
} |
557 |
|
else |
558 |
|
{ |
559 |
0 |
url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource() |
560 |
|
.getLocation().toString().concat("!" + resourcePath)); |
561 |
|
} |
562 |
255 |
return url; |
563 |
|
} |
564 |
|
|
|
|
| 79.2% |
Uncovered Elements: 5 (24) |
Complexity: 5 |
Complexity Density: 0.25 |
|
565 |
145 |
public static void loadBuildProperties(boolean reportVersion)... |
566 |
|
{ |
567 |
145 |
String codeInstallation = getProperty("INSTALLATION"); |
568 |
145 |
boolean printVersion = codeInstallation == null; |
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
145 |
try |
575 |
|
{ |
576 |
145 |
String buildDetails = resolveResourceURLFor("/.build_properties"); |
577 |
145 |
URL localJarFileURL = new URL(buildDetails); |
578 |
145 |
InputStream in = localJarFileURL.openStream(); |
579 |
145 |
applicationProperties.load(in); |
580 |
145 |
in.close(); |
581 |
|
} catch (Exception ex) |
582 |
|
{ |
583 |
0 |
System.out.println("Error reading build details: " + ex); |
584 |
0 |
applicationProperties.remove("VERSION"); |
585 |
|
} |
586 |
145 |
String codeVersion = getProperty("VERSION"); |
587 |
145 |
codeInstallation = getProperty("INSTALLATION"); |
588 |
|
|
589 |
145 |
if (codeVersion == null) |
590 |
|
{ |
591 |
|
|
592 |
0 |
codeVersion = "Test"; |
593 |
0 |
codeInstallation = ""; |
594 |
|
} |
595 |
|
else |
596 |
|
{ |
597 |
145 |
codeInstallation = " (" + codeInstallation + ")"; |
598 |
|
} |
599 |
145 |
setProperty("VERSION", codeVersion); |
600 |
145 |
new BuildDetails(codeVersion, null, codeInstallation); |
601 |
145 |
if (printVersion && reportVersion) |
602 |
|
{ |
603 |
18 |
System.out |
604 |
|
.println("Jalview Version: " + codeVersion + codeInstallation); |
605 |
|
} |
606 |
|
} |
607 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
608 |
103 |
private static void deleteBuildProperties()... |
609 |
|
{ |
610 |
103 |
applicationProperties.remove("LATEST_VERSION"); |
611 |
103 |
applicationProperties.remove("VERSION"); |
612 |
103 |
applicationProperties.remove("AUTHORS"); |
613 |
103 |
applicationProperties.remove("AUTHORFNAMES"); |
614 |
103 |
applicationProperties.remove("YEAR"); |
615 |
103 |
applicationProperties.remove("BUILD_DATE"); |
616 |
103 |
applicationProperties.remove("INSTALLATION"); |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
@param |
624 |
|
|
625 |
|
|
626 |
|
@return |
627 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
628 |
21943 |
public static String getProperty(String key)... |
629 |
|
{ |
630 |
21943 |
String prop = applicationProperties.getProperty(key); |
631 |
21942 |
if (prop == null && Platform.isJS()) |
632 |
|
{ |
633 |
0 |
prop = applicationProperties.getProperty(Platform.getUniqueAppletID() |
634 |
|
+ "_" + JS_PROPERTY_PREFIX + key); |
635 |
|
} |
636 |
21942 |
return prop; |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
644 |
15591 |
public static boolean getDefault(String property, boolean def)... |
645 |
|
{ |
646 |
15591 |
String string = getProperty(property); |
647 |
15591 |
if (string != null) |
648 |
|
{ |
649 |
10278 |
def = Boolean.valueOf(string).booleanValue(); |
650 |
|
} |
651 |
|
|
652 |
15591 |
return def; |
653 |
|
} |
654 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
655 |
0 |
public static int getDefault(String property, int def)... |
656 |
|
{ |
657 |
0 |
String string = getProperty(property); |
658 |
0 |
if (string != null) |
659 |
|
{ |
660 |
0 |
try |
661 |
|
{ |
662 |
0 |
def = Integer.parseInt(string); |
663 |
|
} catch (NumberFormatException e) |
664 |
|
{ |
665 |
0 |
System.out.println("Error parsing int property '" + property |
666 |
|
+ "' with value '" + string + "'"); |
667 |
|
} |
668 |
|
} |
669 |
|
|
670 |
0 |
return def; |
671 |
|
} |
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
|
676 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
677 |
4653 |
public static String getDefault(String property, String def)... |
678 |
|
{ |
679 |
4653 |
String value = getProperty(property); |
680 |
4653 |
return value == null ? def : value; |
681 |
|
} |
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
@param |
687 |
|
|
688 |
|
@param |
689 |
|
|
690 |
|
|
691 |
|
@return |
692 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.44 |
|
693 |
355 |
public static Object setProperty(String key, String obj)... |
694 |
|
{ |
695 |
355 |
Object oldValue = null; |
696 |
355 |
try |
697 |
|
{ |
698 |
355 |
oldValue = applicationProperties.setProperty(key, obj); |
699 |
355 |
if (propertiesFile != null && !propsAreReadOnly) |
700 |
|
{ |
701 |
57 |
FileOutputStream out = new FileOutputStream(propertiesFile); |
702 |
57 |
applicationProperties.store(out, "---JalviewX Properties File---"); |
703 |
57 |
out.close(); |
704 |
|
} |
705 |
|
} catch (Exception ex) |
706 |
|
{ |
707 |
0 |
System.out.println( |
708 |
|
"Error setting property: " + key + " " + obj + "\n" + ex); |
709 |
|
} |
710 |
355 |
return oldValue; |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
@param |
717 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
718 |
0 |
public static void removeProperty(String string)... |
719 |
|
{ |
720 |
0 |
applicationProperties.remove(string); |
721 |
0 |
saveProperties(); |
722 |
|
} |
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
727 |
0 |
public static void saveProperties()... |
728 |
|
{ |
729 |
0 |
if (!propsAreReadOnly) |
730 |
|
{ |
731 |
0 |
try |
732 |
|
{ |
733 |
0 |
FileOutputStream out = new FileOutputStream(propertiesFile); |
734 |
0 |
applicationProperties.store(out, "---JalviewX Properties File---"); |
735 |
0 |
out.close(); |
736 |
|
} catch (Exception ex) |
737 |
|
{ |
738 |
0 |
System.out.println("Error saving properties: " + ex); |
739 |
|
} |
740 |
|
} |
741 |
|
} |
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
private static int vamsasJarsArePresent = -1; |
747 |
|
|
748 |
|
|
749 |
|
|
750 |
|
|
751 |
|
@return |
752 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
753 |
0 |
public static boolean vamsasJarsPresent()... |
754 |
|
{ |
755 |
0 |
if (vamsasJarsArePresent == -1) |
756 |
|
{ |
757 |
0 |
try |
758 |
|
{ |
759 |
0 |
if (jalview.jbgui.GDesktop.class.getClassLoader() |
760 |
|
.loadClass("uk.ac.vamsas.client.VorbaId") != null) |
761 |
|
{ |
762 |
0 |
jalview.bin.Cache.log.debug( |
763 |
|
"Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)"); |
764 |
0 |
vamsasJarsArePresent = 1; |
765 |
0 |
Logger lvclient = Logger.getLogger("uk.ac.vamsas"); |
766 |
0 |
lvclient.setLevel(Level.toLevel(Cache |
767 |
|
.getDefault("logs.Vamsas.Level", Level.INFO.toString()))); |
768 |
|
|
769 |
0 |
lvclient.addAppender(log.getAppender("JalviewLogger")); |
770 |
|
|
771 |
0 |
lvclient.debug("Jalview Vamsas Client Debugging Output Follows."); |
772 |
|
} |
773 |
|
} catch (Exception e) |
774 |
|
{ |
775 |
0 |
vamsasJarsArePresent = 0; |
776 |
0 |
jalview.bin.Cache.log.debug("Vamsas Classes are not present"); |
777 |
|
} |
778 |
|
} |
779 |
0 |
return (vamsasJarsArePresent > 0); |
780 |
|
} |
781 |
|
|
782 |
|
|
783 |
|
|
784 |
|
|
785 |
|
private static int groovyJarsArePresent = -1; |
786 |
|
|
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
@return |
791 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.36 |
|
792 |
0 |
public static boolean groovyJarsPresent()... |
793 |
|
{ |
794 |
0 |
if (groovyJarsArePresent == -1) |
795 |
|
{ |
796 |
0 |
try |
797 |
|
{ |
798 |
0 |
if (Cache.class.getClassLoader() |
799 |
|
.loadClass("groovy.lang.GroovyObject") != null) |
800 |
|
{ |
801 |
0 |
jalview.bin.Cache.log.debug( |
802 |
|
"Found Groovy (groovy.lang.GroovyObject can be loaded)"); |
803 |
0 |
groovyJarsArePresent = 1; |
804 |
0 |
Logger lgclient = Logger.getLogger("groovy"); |
805 |
0 |
lgclient.setLevel(Level.toLevel(Cache |
806 |
|
.getDefault("logs.Groovy.Level", Level.INFO.toString()))); |
807 |
|
|
808 |
0 |
lgclient.addAppender(log.getAppender("JalviewLogger")); |
809 |
|
|
810 |
0 |
lgclient.debug("Jalview Groovy Client Debugging Output Follows."); |
811 |
|
} |
812 |
|
} catch (Error e) |
813 |
|
{ |
814 |
0 |
groovyJarsArePresent = 0; |
815 |
0 |
jalview.bin.Cache.log.debug("Groovy Classes are not present", e); |
816 |
|
} catch (Exception e) |
817 |
|
{ |
818 |
0 |
groovyJarsArePresent = 0; |
819 |
0 |
jalview.bin.Cache.log.debug("Groovy Classes are not present"); |
820 |
|
} |
821 |
|
} |
822 |
0 |
return (groovyJarsArePresent > 0); |
823 |
|
} |
824 |
|
|
825 |
|
|
826 |
|
|
827 |
|
|
828 |
|
|
829 |
|
protected static Object tracker = null; |
830 |
|
|
831 |
|
protected static Class trackerfocus = null; |
832 |
|
|
833 |
|
protected static Class jgoogleanalyticstracker = null; |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 17 |
Complexity Density: 0.46 |
|
838 |
0 |
public static void initGoogleTracker()... |
839 |
|
{ |
840 |
0 |
if (tracker == null) |
841 |
|
{ |
842 |
0 |
if (jgoogleanalyticstracker == null) |
843 |
|
{ |
844 |
|
|
845 |
0 |
try |
846 |
|
{ |
847 |
0 |
jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass( |
848 |
|
"com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker"); |
849 |
0 |
trackerfocus = Cache.class.getClassLoader() |
850 |
|
.loadClass("com.boxysystems.jgoogleanalytics.FocusPoint"); |
851 |
|
} catch (Exception e) |
852 |
|
{ |
853 |
0 |
log.debug( |
854 |
|
"com.boxysystems.jgoogleanalytics package is not present - tracking not enabled."); |
855 |
0 |
tracker = null; |
856 |
0 |
jgoogleanalyticstracker = null; |
857 |
0 |
trackerfocus = null; |
858 |
0 |
return; |
859 |
|
} |
860 |
|
} |
861 |
|
|
862 |
0 |
Exception re = null, ex = null; |
863 |
0 |
Error err = null; |
864 |
0 |
String vrs = "No Version Accessible"; |
865 |
0 |
try |
866 |
|
{ |
867 |
|
|
868 |
0 |
tracker = jgoogleanalyticstracker |
869 |
|
.getConstructor(new Class[] |
870 |
|
{ String.class, String.class, String.class }) |
871 |
|
.newInstance(new Object[] |
872 |
|
{ "Jalview Desktop", |
873 |
|
(vrs = jalview.bin.Cache.getProperty("VERSION") + "_" |
874 |
|
+ jalview.bin.Cache.getDefault("BUILD_DATE", |
875 |
|
"unknown")), |
876 |
|
"UA-9060947-1" }); |
877 |
0 |
jgoogleanalyticstracker |
878 |
|
.getMethod("trackAsynchronously", new Class[] |
879 |
|
{ trackerfocus }) |
880 |
|
.invoke(tracker, new Object[] |
881 |
|
{ trackerfocus.getConstructor(new Class[] { String.class }) |
882 |
|
.newInstance(new Object[] |
883 |
|
{ "Application Started." }) }); |
884 |
|
} catch (RuntimeException e) |
885 |
|
{ |
886 |
0 |
re = e; |
887 |
|
} catch (Exception e) |
888 |
|
{ |
889 |
0 |
ex = e; |
890 |
|
} catch (Error e) |
891 |
|
{ |
892 |
0 |
err = e; |
893 |
|
} |
894 |
0 |
if (re != null || ex != null || err != null) |
895 |
|
{ |
896 |
0 |
if (log != null) |
897 |
|
{ |
898 |
0 |
if (re != null) |
899 |
|
{ |
900 |
0 |
log.debug("Caught runtime exception in googletracker init:", |
901 |
|
re); |
902 |
|
} |
903 |
0 |
if (ex != null) |
904 |
|
{ |
905 |
0 |
log.warn( |
906 |
|
"Failed to initialise GoogleTracker for Jalview Desktop with version " |
907 |
|
+ vrs, |
908 |
|
ex); |
909 |
|
} |
910 |
0 |
if (err != null) |
911 |
|
{ |
912 |
0 |
log.error( |
913 |
|
"Whilst initing GoogleTracker for Jalview Desktop version " |
914 |
|
+ vrs, |
915 |
|
err); |
916 |
|
} |
917 |
|
} |
918 |
|
else |
919 |
|
{ |
920 |
0 |
if (re != null) |
921 |
|
{ |
922 |
0 |
System.err.println( |
923 |
|
"Debug: Caught runtime exception in googletracker init:" |
924 |
|
+ vrs); |
925 |
0 |
re.printStackTrace(); |
926 |
|
} |
927 |
0 |
if (ex != null) |
928 |
|
{ |
929 |
0 |
System.err.println( |
930 |
|
"Warning: Failed to initialise GoogleTracker for Jalview Desktop with version " |
931 |
|
+ vrs); |
932 |
0 |
ex.printStackTrace(); |
933 |
|
} |
934 |
|
|
935 |
0 |
if (err != null) |
936 |
|
{ |
937 |
0 |
System.err.println( |
938 |
|
"ERROR: Whilst initing GoogleTracker for Jalview Desktop version " |
939 |
|
+ vrs); |
940 |
0 |
err.printStackTrace(); |
941 |
|
} |
942 |
|
} |
943 |
|
} |
944 |
|
else |
945 |
|
{ |
946 |
0 |
log.debug("Successfully initialised tracker."); |
947 |
|
} |
948 |
|
} |
949 |
|
} |
950 |
|
|
951 |
|
|
952 |
|
|
953 |
|
|
954 |
|
@param |
955 |
|
@param |
956 |
|
@return |
957 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
958 |
0 |
public static Color getDefaultColour(String property, Color defcolour)... |
959 |
|
{ |
960 |
0 |
String colprop = getProperty(property); |
961 |
0 |
if (colprop == null) |
962 |
|
{ |
963 |
0 |
return defcolour; |
964 |
|
} |
965 |
0 |
Color col = ColorUtils.parseColourString(colprop); |
966 |
0 |
if (col == null) |
967 |
|
{ |
968 |
0 |
log.warn("Couldn't parse '" + colprop + "' as a colour for " |
969 |
|
+ property); |
970 |
|
} |
971 |
0 |
return (col == null) ? defcolour : col; |
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
|
@param |
978 |
|
@param |
979 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
980 |
0 |
public static void setColourProperty(String property, Color colour)... |
981 |
|
{ |
982 |
0 |
setProperty(property, jalview.util.Format.getHexString(colour)); |
983 |
|
} |
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
|
988 |
|
@param |
989 |
|
@param |
990 |
|
@return |
991 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
992 |
17 |
public static String setDateProperty(String propertyName, Date date)... |
993 |
|
{ |
994 |
17 |
String formatted = date_format.format(date); |
995 |
17 |
setProperty(propertyName, formatted); |
996 |
17 |
return formatted; |
997 |
|
} |
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
|
|
1003 |
|
@param |
1004 |
|
@return |
1005 |
|
|
1006 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
1007 |
6 |
public static Date getDateProperty(String propertyName)... |
1008 |
|
{ |
1009 |
6 |
String val = getProperty(propertyName); |
1010 |
6 |
if (val != null) |
1011 |
|
{ |
1012 |
6 |
try |
1013 |
|
{ |
1014 |
6 |
return date_format.parse(val); |
1015 |
|
} catch (Exception ex) |
1016 |
|
{ |
1017 |
2 |
System.err.println("Invalid or corrupt date in property '" |
1018 |
|
+ propertyName + "' : value was '" + val + "'"); |
1019 |
|
} |
1020 |
|
} |
1021 |
2 |
return null; |
1022 |
|
} |
1023 |
|
|
1024 |
|
|
1025 |
|
|
1026 |
|
|
1027 |
|
|
1028 |
|
@param |
1029 |
|
@return |
1030 |
|
|
|
|
| 37.5% |
Uncovered Elements: 5 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
1031 |
16 |
public static Integer getIntegerProperty(String property)... |
1032 |
|
{ |
1033 |
16 |
String val = getProperty(property); |
1034 |
? |
if (val != null && (val = val.trim()).length() > 0) |
1035 |
|
{ |
1036 |
0 |
try |
1037 |
|
{ |
1038 |
0 |
return Integer.valueOf(val); |
1039 |
|
} catch (NumberFormatException x) |
1040 |
|
{ |
1041 |
0 |
System.err.println("Invalid integer in property '" + property |
1042 |
|
+ "' (value was '" + val + "')"); |
1043 |
|
} |
1044 |
|
} |
1045 |
16 |
return null; |
1046 |
|
} |
1047 |
|
|
1048 |
|
|
1049 |
|
|
1050 |
|
|
1051 |
|
|
1052 |
|
@param |
1053 |
|
@param |
1054 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
1055 |
0 |
public static void setOrRemove(String propName, String value)... |
1056 |
|
{ |
1057 |
0 |
if (propName == null) |
1058 |
|
{ |
1059 |
0 |
return; |
1060 |
|
} |
1061 |
0 |
if (value == null || value.trim().length() < 1) |
1062 |
|
{ |
1063 |
0 |
Cache.applicationProperties.remove(propName); |
1064 |
|
} |
1065 |
|
else |
1066 |
|
{ |
1067 |
0 |
Cache.applicationProperties.setProperty(propName, value); |
1068 |
|
} |
1069 |
|
} |
1070 |
|
|
1071 |
|
|
1072 |
|
|
1073 |
|
|
1074 |
|
@param |
1075 |
|
|
1076 |
|
|
|
|
| 10% |
Uncovered Elements: 27 (30) |
Complexity: 9 |
Complexity Density: 0.5 |
|
1077 |
110 |
public static void initUserColourSchemes(String files)... |
1078 |
|
{ |
1079 |
110 |
if (files == null || files.length() == 0) |
1080 |
|
{ |
1081 |
110 |
return; |
1082 |
|
} |
1083 |
|
|
1084 |
|
|
1085 |
|
|
1086 |
0 |
StringBuffer coloursFound = new StringBuffer(); |
1087 |
0 |
StringTokenizer st = new StringTokenizer(files, "|"); |
1088 |
0 |
while (st.hasMoreElements()) |
1089 |
|
{ |
1090 |
0 |
String file = st.nextToken(); |
1091 |
0 |
try |
1092 |
|
{ |
1093 |
0 |
UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file); |
1094 |
0 |
if (ucs != null) |
1095 |
|
{ |
1096 |
0 |
if (coloursFound.length() > 0) |
1097 |
|
{ |
1098 |
0 |
coloursFound.append("|"); |
1099 |
|
} |
1100 |
0 |
coloursFound.append(file); |
1101 |
0 |
ColourSchemes.getInstance().registerColourScheme(ucs); |
1102 |
|
} |
1103 |
|
} catch (Exception ex) |
1104 |
|
{ |
1105 |
0 |
System.out.println("Error loading User ColourFile\n" + ex); |
1106 |
|
} |
1107 |
|
} |
1108 |
0 |
if (!files.equals(coloursFound.toString())) |
1109 |
|
{ |
1110 |
0 |
if (coloursFound.toString().length() > 1) |
1111 |
|
{ |
1112 |
0 |
setProperty(UserDefinedColours.USER_DEFINED_COLOURS, |
1113 |
|
coloursFound.toString()); |
1114 |
|
} |
1115 |
|
else |
1116 |
|
{ |
1117 |
0 |
applicationProperties |
1118 |
|
.remove(UserDefinedColours.USER_DEFINED_COLOURS); |
1119 |
|
} |
1120 |
|
} |
1121 |
|
} |
1122 |
|
|
1123 |
|
|
1124 |
|
|
1125 |
|
|
1126 |
|
@param |
1127 |
|
@param |
1128 |
|
@param |
1129 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
1130 |
72 |
private static void appendIfNotNull(StringBuilder sb, String prefix,... |
1131 |
|
String value, String suffix, String defaultValue) |
1132 |
|
{ |
1133 |
72 |
if (value == null && defaultValue == null) |
1134 |
|
{ |
1135 |
54 |
return; |
1136 |
|
} |
1137 |
18 |
String line = prefix + (value != null ? value : defaultValue) + suffix; |
1138 |
18 |
sb.append(line); |
1139 |
|
} |
1140 |
|
|
1141 |
|
|
1142 |
|
|
1143 |
|
@return |
1144 |
|
|
|
|
| 82.1% |
Uncovered Elements: 5 (28) |
Complexity: 4 |
Complexity Density: 0.18 |
|
1145 |
18 |
public static String getVersionDetailsForConsole()... |
1146 |
|
{ |
1147 |
18 |
StringBuilder sb = new StringBuilder(); |
1148 |
18 |
sb.append("Jalview Version: " + jalview.bin.Cache.getDefault("VERSION", "TEST")); |
1149 |
18 |
sb.append("\n"); |
1150 |
18 |
sb.append("Jalview Installation: " |
1151 |
|
+ jalview.bin.Cache.getDefault("INSTALLATION", "unknown")); |
1152 |
18 |
sb.append("\n"); |
1153 |
18 |
sb.append("Build Date: " + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")); |
1154 |
18 |
sb.append("\n"); |
1155 |
18 |
sb.append("Java version: " + System.getProperty("java.version")); |
1156 |
18 |
sb.append("\n"); |
1157 |
18 |
sb.append(System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); |
1158 |
18 |
sb.append("\n"); |
1159 |
18 |
appendIfNotNull(sb, "Install4j version: ", |
1160 |
|
System.getProperty("sys.install4jVersion"), "\n", null); |
1161 |
18 |
appendIfNotNull(sb, "Install4j template version: ", |
1162 |
|
System.getProperty("installer_template_version"), "\n", null); |
1163 |
18 |
appendIfNotNull(sb, "Launcher version: ", |
1164 |
|
System.getProperty("launcher_version"), "\n", null); |
1165 |
18 |
LookAndFeel laf = UIManager.getLookAndFeel(); |
1166 |
18 |
String lafName = laf == null?"Not obtained":laf.getName(); |
1167 |
18 |
String lafClass = laf == null?"unknown":laf.getClass().getName(); |
1168 |
18 |
appendIfNotNull(sb, "LookAndFeel: ", lafName+" ("+lafClass+")", "\n", null); |
1169 |
|
|
1170 |
18 |
if (Pattern.matches("^\\d[\\d\\.]*\\d[\\.\\-\\w]*$", jalview.bin.Cache.getDefault("VERSION", "TEST"))) { |
1171 |
0 |
appendIfNotNull(sb, "Getdown appdir: ", |
1172 |
|
System.getProperty("getdownappdir"), "\n", null); |
1173 |
0 |
appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"), |
1174 |
|
"\n", "unknown"); |
1175 |
|
} |
1176 |
18 |
return sb.toString(); |
1177 |
|
} |
1178 |
|
|
1179 |
|
|
1180 |
|
|
1181 |
|
@return |
1182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1183 |
188 |
public static String getBuildDetailsForSplash()... |
1184 |
|
{ |
1185 |
|
|
1186 |
|
|
1187 |
188 |
return jalview.bin.Cache.getDefault("INSTALLATION", "unknown"); |
1188 |
|
} |
1189 |
|
} |