Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/wsplgen/ProblemObserver.java @ 1147:e7d5452a7381
Added a 'ProblemObserver' that analyses WSPLGEN's error stream for errors and warnings.
flys-artifacts/trunk@2677 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Sep 2011 11:24:27 +0000 |
parents | |
children | 64b465699a24 |
comparison
equal
deleted
inserted
replaced
1146:66d98964f2df | 1147:e7d5452a7381 |
---|---|
1 package de.intevation.flys.wsplgen; | |
2 | |
3 import java.util.HashMap; | |
4 import java.util.Map; | |
5 import java.util.regex.Matcher; | |
6 import java.util.regex.Pattern; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import de.intevation.flys.artifacts.model.WSPLGENJob; | |
11 | |
12 | |
13 public class ProblemObserver extends JobObserver { | |
14 | |
15 private static Logger logger = Logger.getLogger(ProblemObserver.class); | |
16 | |
17 | |
18 public static final Pattern WSPLGEN_ERROR_START = Pattern.compile( | |
19 ".*->Fehler\\s*\\((\\d+)\\).*", | |
20 Pattern.DOTALL); | |
21 | |
22 public static final Pattern WSPLGEN_ERROR_END = Pattern.compile( | |
23 ".*<-Fehler .*", | |
24 Pattern.DOTALL); | |
25 | |
26 public static final Pattern WSPLGEN_WARNING_START = Pattern.compile( | |
27 ".*->Warnung\\s*\\((\\d+)\\).*", | |
28 Pattern.DOTALL); | |
29 | |
30 public static final Pattern WSPLGEN_WARNING_END = Pattern.compile( | |
31 ".*<-Warnung .*", | |
32 Pattern.DOTALL); | |
33 | |
34 | |
35 protected int error; | |
36 protected int warning; | |
37 | |
38 protected Map<Integer, String> errorMsg; | |
39 protected Map<Integer, String> warningMsg; | |
40 | |
41 | |
42 public ProblemObserver(WSPLGENJob job) { | |
43 super(job); | |
44 error = -1; | |
45 warning = -1; | |
46 errorMsg = new HashMap<Integer, String>(); | |
47 warningMsg = new HashMap<Integer, String>(); | |
48 } | |
49 | |
50 | |
51 public void run() { | |
52 logger.debug("Start observation..."); | |
53 | |
54 super.run(); | |
55 } | |
56 | |
57 | |
58 @Override | |
59 protected void prepareRegexes() { | |
60 // do nothing | |
61 } | |
62 | |
63 | |
64 @Override | |
65 protected void update(String log) { | |
66 Matcher startError = WSPLGEN_ERROR_START.matcher(log); | |
67 if (startError.matches()) { | |
68 error = Integer.parseInt(startError.group(1)); | |
69 return; | |
70 } | |
71 | |
72 Matcher endError = WSPLGEN_ERROR_END.matcher(log); | |
73 if (endError.matches()) { | |
74 error = -1; | |
75 } | |
76 | |
77 if (error > 0) { | |
78 errorMsg.put(new Integer(error), log); | |
79 } | |
80 | |
81 Matcher startWarning = WSPLGEN_WARNING_START.matcher(log); | |
82 if (startWarning.matches()) { | |
83 warning = Integer.parseInt(startWarning.group(1)); | |
84 return; | |
85 } | |
86 | |
87 Matcher endWarning = WSPLGEN_WARNING_END.matcher(log); | |
88 if (endWarning.matches()) { | |
89 warning = -1; | |
90 } | |
91 | |
92 if (warning > 0) { | |
93 warningMsg.put(new Integer(warning), log); | |
94 } | |
95 } | |
96 | |
97 | |
98 public int numErrors() { | |
99 return errorMsg.size(); | |
100 } | |
101 | |
102 | |
103 public int numWarnings() { | |
104 return warningMsg.size(); | |
105 } | |
106 } | |
107 // vim:set ts=4 sw=4 si et sta sts=5 fenc=utf-8 : |