1
1
/*
2
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3
- * Copyright (c) 2022 SAP SE. All rights reserved.
2
+ * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
3
+ * Copyright (c) 2022, 2024 SAP SE. All rights reserved.
4
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
5
*
6
6
* This code is free software; you can redistribute it and/or modify it
@@ -68,7 +68,7 @@ public static File openHsErrFileFromOutput(OutputAnalyzer output) {
68
68
* @throws RuntimeException, {@link IOException}
69
69
*/
70
70
public static void checkHsErrFileContent (File f , Pattern [] patterns , boolean verbose ) throws IOException {
71
- checkHsErrFileContent (f , patterns , null , true , verbose );
71
+ checkHsErrFileContent (f , patterns , null , true , verbose , false );
72
72
}
73
73
74
74
/**
@@ -80,11 +80,43 @@ public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean ver
80
80
* Order is irrelevant.
81
81
* @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
82
82
* that hs-err file printing did not complete successfully.
83
- * @param verbose If true, the content of the hs-err file is printed while matching. If false, only important
84
- * information are printed.
83
+ * @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
84
+ * are printed.
85
85
* @throws RuntimeException, {@link IOException}
86
86
*/
87
87
public static void checkHsErrFileContent (File f , Pattern [] positivePatterns , Pattern [] negativePatterns , boolean checkEndMarker , boolean verbose ) throws IOException {
88
+ checkHsErrFileContent (f , positivePatterns , negativePatterns , checkEndMarker , verbose , false );
89
+ }
90
+
91
+ /**
92
+ * Given an open hs-err file, read it line by line and check for existence of a set of patterns. Will fail
93
+ * if patterns are missing, or if the END marker is missing.
94
+ * @param f Input file
95
+ * @param patterns An array of patterns that need to match, in that order
96
+ * @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
97
+ * are printed.
98
+ * @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
99
+ * @throws RuntimeException, {@link IOException}
100
+ */
101
+ public static void checkHsErrFileContent (File f , Pattern [] patterns , boolean verbose , boolean printHserrOnError ) throws IOException {
102
+ checkHsErrFileContent (f , patterns , null , true , verbose , printHserrOnError );
103
+ }
104
+
105
+ /**
106
+ * Given an open hs-err file, read it line by line and check for various conditions.
107
+ * @param f input file
108
+ * @param positivePatterns Optional array of patterns that need to appear, in given order, in the file. Missing
109
+ * patterns cause the test to fail.
110
+ * @param negativePatterns Optional array of patterns that must not appear in the file; test fails if they do.
111
+ * Order is irrelevant.
112
+ * @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
113
+ * that hs-err file printing did not complete successfully.
114
+ * @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
115
+ * are printed.
116
+ * @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
117
+ * @throws RuntimeException, {@link IOException}
118
+ */
119
+ public static void checkHsErrFileContent (File f , Pattern [] positivePatterns , Pattern [] negativePatterns , boolean checkEndMarker , boolean verbose , boolean printHserrOnError ) throws IOException {
88
120
try (
89
121
FileInputStream fis = new FileInputStream (f );
90
122
BufferedReader br = new BufferedReader (new InputStreamReader (fis ));
@@ -123,6 +155,9 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
123
155
System .out .println (line );
124
156
}
125
157
System .out .println ("^^^ Forbidden pattern found at line " + lineNo + ": " + negativePattern + "^^^" );
158
+ if (printHserrOnError ) {
159
+ printHsErrFile (f );
160
+ }
126
161
throw new RuntimeException ("Forbidden pattern found at line " + lineNo + ": " + negativePattern );
127
162
}
128
163
}
@@ -132,13 +167,33 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
132
167
}
133
168
// If the current pattern is not null then it didn't match
134
169
if (currentPositivePattern != null ) {
170
+ if (printHserrOnError ) {
171
+ printHsErrFile (f );
172
+ }
135
173
throw new RuntimeException ("hs-err file incomplete (first missing pattern: " + currentPositivePattern .pattern () + ")" );
136
174
}
137
175
if (checkEndMarker && !lastLine .equals ("END." )) {
176
+ if (printHserrOnError ) {
177
+ printHsErrFile (f );
178
+ }
138
179
throw new RuntimeException ("hs-err file incomplete (missing END marker.)" );
139
180
}
140
181
System .out .println ("hs-err file " + f .getAbsolutePath () + " scanned successfully." );
141
182
}
142
183
}
143
184
185
+ private static void printHsErrFile (File f ) throws IOException {
186
+ try (
187
+ FileInputStream fis = new FileInputStream (f );
188
+ BufferedReader br = new BufferedReader (new InputStreamReader (fis ));
189
+ ) {
190
+ String line ;
191
+ System .out .println ("------------------------ hs-err file ------------------------" );
192
+ while ((line = br .readLine ()) != null ) {
193
+ System .out .println (line );
194
+ }
195
+ System .out .println ("-------------------------------------------------------------" );
196
+ }
197
+ }
198
+
144
199
}
0 commit comments