19
19
package org .deepjava .host ;
20
20
/**
21
21
changes:
22
+ <br>2022-03-25, OST/GRAU error file must be found in all use cases
22
23
<br>11-09-12, NTB/MILR error(int errNr, String additionalInfo): printing errNr, errMsg and additional informations, handling if class is into a jar
23
24
<br>09-04-22, NTB/ED error(int errNr, String errMsg): printing errNr, errMsg
24
25
<br>09-03-23, NTB/ED extension of error(int errNr, String errMsg)
31
32
import java .io .IOException ;
32
33
import java .io .InputStreamReader ;
33
34
import java .io .PrintStream ;
35
+ import java .io .UnsupportedEncodingException ;
36
+ import java .net .URLDecoder ;
34
37
import java .util .jar .JarFile ;
35
38
import java .util .zip .ZipEntry ;
36
39
40
43
*/
41
44
public class ErrorReporter {
42
45
public static final ErrorReporter reporter ;
46
+ private static PrintStream vrb = StdStreams .vrb ;
43
47
private PrintStream errPrStream ;
44
48
private String errorMsgFilePath = "rsc/ErrorMsg.txt" ;
45
49
private JarFile jar ;
@@ -57,29 +61,36 @@ public class ErrorReporter {
57
61
private ErrorReporter () {
58
62
clear ();
59
63
errPrStream = StdStreams .err ;
60
- String home = "" ;
61
-
62
- if (System .getProperty ("os.name" ).contains ("Windows" )){ // Running on Microsoft Windows
63
- home = getClass ().getProtectionDomain ().getCodeSource ().getLocation ().toString ().substring (6 ); // get jar name
64
- // we have to remove the first 6 characters of the returned _absolute_ path to the JAR file,
65
- // because the string starts with "file:/" which is not a valid file name!
66
- // Example: file:/I:\eclipse\..
67
- } else { // Running on Linux, Mac OS X or another UNIX system
68
- home = getClass ().getProtectionDomain ().getCodeSource ().getLocation ().toString ().substring (5 ); // get jar name
69
- // we have to remove the first 5 characters of the returned _absolute_ path to the JAR file,
70
- // because the string starts with "file:" which is not a valid file name!
71
- // Example: file:/opt/eclipse/..
64
+ String path = getClass ().getProtectionDomain ().getCodeSource ().getLocation ().getPath ();
65
+ String url = null ;
66
+ try {
67
+ url = URLDecoder .decode (path , "UTF-8" );
68
+ } catch (UnsupportedEncodingException e ) {
69
+ vrb .println ("Error message file cannot be loaded, URL syntax error " );
72
70
}
73
-
74
- if (home .endsWith ("jar" )) { // used when running as an eclipse plugin
75
- try {
76
- jar = new JarFile (home );
77
- } catch (IOException e ) {
78
- e .printStackTrace (errPrStream );
79
- }
80
-
71
+ // errPrStream.println(url);
72
+ while (url .contains (".." )) { // used when eclipse launched from within eclipse workspace
73
+ int index = url .indexOf (".." );
74
+ char ch = url .charAt (index - 1 );
75
+ int index1 = url .lastIndexOf (ch , index - 2 );
76
+ String p1 = url .substring (0 , index1 );
77
+ String p2 = url .substring (index + 2 );
78
+ url = p1 + p2 ;
79
+ }
80
+ if (url .endsWith ("jar" )) { // used when running as an eclipse plugin
81
+ try {
82
+ jar = new JarFile (url );
83
+ } catch (IOException e ) {
84
+ vrb .println ("Error message file cannot be loaded" );
85
+ }
86
+ } else {
87
+ if (url .endsWith ("bin/" )) { // used when started directly in eclipse (e.g. with the Testlauncher)
88
+ url = url .substring (0 , url .length () - 4 );
89
+ }
90
+ errorMsgFilePath = url + errorMsgFilePath ;
81
91
}
82
92
this .maxNofErrors = Integer .MAX_VALUE ;
93
+ // errPrStream.println(errorMsgFilePath);
83
94
}
84
95
85
96
public void setMaxNrOfErrors (int maxNofErrors ) {
0 commit comments