1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
|
/*
Derby - Class org.apache.derbyTesting.functionTests.harness.Sed
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.harness;
/***
* Sed.java
*
* This is a version of "sed" in Java for the Derby Function Tests,
* written using the java.util.regex regular expression classes.
* The substitutions/deletions are based on the original kornshell tests.
*
***/
import java.io.*;
import java.util.Vector;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.derbyTesting.functionTests.util.TestUtil;
public class Sed
{
private static final String SQL_EXCEPTION_FILTERED_SUBSTITUTION =
"java.sql.SQLException:";
public Sed()
{
}
public static void main(String[] args) throws Exception {
if (args == null || args.length != 2) {
System.err.println("Usage: Sed sourcefile targetfile");
System.exit(1);
}
File src = new File(args[0]);
File tgt = new File(args[1]);
new Sed().exec(src,tgt,null, false, false,false);
}
// The arguments should be the names of the input and output files
public void exec
(File srcFile, File dstFile, InputStream isSed, boolean isJCC, boolean isI18N, boolean isJDBC4)
throws IOException
{
String hostName = TestUtil.getHostName();
// Vector for storing lines to be deleted
Vector<String> deleteLines = new Vector<String>();
deleteLines.addElement("^ij version.*$");
deleteLines.addElement("^\\*\\*\\*\\* Test Run Started .* \\*\\*\\*\\*$");
deleteLines.addElement("^\\*\\*\\*\\* Test Run Completed .* \\*\\*\\*\\*$");
deleteLines.addElement("^ELAPSED TIME = [0-9]* milliseconds$");
deleteLines.addElement("^\\^\\?$");
//deleteLines.addElement("^\\.$"); // originally to remove lines with a dot
deleteLines.addElement("^S.*ij> $");
deleteLines.addElement("^ *$");
deleteLines.addElement("^Server StackTrace:$");
deleteLines.addElement("^\\[ *$");
deleteLines.addElement("^\\] *$");
deleteLines.addElement("^\\[$");
deleteLines.addElement("^\\]$");
deleteLines.addElement("^<not available>\\]$");
deleteLines.addElement("^(.*at .*)\\(.*:[0-9].*\\)$");
deleteLines.addElement("^(.*at .*)\\(*.java\\)$");
deleteLines.addElement("^(.*at .*)\\(Compiled Code\\)$");
deleteLines.addElement("^.*at java.*\\<init\\>\\(.*\\(Compiled Code\\)\\)$");
deleteLines.addElement("^(.*at .*)\\(Interpreted Code\\)$");
deleteLines.addElement("^(.*at .*)\\(Unknown Source\\)$");
deleteLines.addElement("^(.*at .*)\\(.*Native Method\\)$");
deleteLines.addElement("^\\tat $"); // rare case of incomplete stack trace line
deleteLines.addElement("optimizer estimated cost");
deleteLines.addElement("optimizer estimated row count");
deleteLines.addElement("Using executables built for native_threads");
deleteLines.addElement("Estimate of memory used");
deleteLines.addElement("Size of merge runs");
deleteLines.addElement("Number of merge runs");
deleteLines.addElement("Sort type");
deleteLines.addElement("Optimization started at .*$");
deleteLines.addElement("WARNING 02000: No row was found for FETCH, UPDATE or DELETE");
// deleteLines for stack traces from j9 jvm to match those above for other jvms
deleteLines.addElement("Stack trace:");
deleteLines.addElement("^.*java/.*\\<init\\>\\(.*\\)V");
deleteLines.addElement("^.*org/apache/derby/.*\\(.*\\).*$");
// next for j9 stack trace with jarfiles test run.
deleteLines.addElement("^.*java/.*\\(.*\\).*$");
deleteLines.addElement("^\\[.*db2jcc.jar\\] [0-9].[1-9] - .*$");
deleteLines.addElement("^\\[.*db2jcc_license_c.jar\\] [1-9].[0-9] - .*$");
deleteLines.addElement("^XSDB.*$");
// JUnit noise
deleteLines.addElement("^\\.*$");
deleteLines.addElement("^Time: [0-9].*$");
deleteLines.addElement("^OK \\(.*$");
// Vectors for substitutions
Vector<String> searchStrings = new Vector<String>();
searchStrings.addElement("^Transaction:\\(.*\\) *\\|");
searchStrings.addElement("^Read [0-9]* of [0-9]* bytes$");
searchStrings.addElement("Directory .*connect.wombat.seg0");
//DERBY-4588 - filter out specific class and object id
searchStrings.addElement("with class loader .*,");
// Filter for constraint names - bug 5622 - our internal constraint names are too long. To be db2 compatible, we have reworked them.
StringBuffer constraintNameFilter = new StringBuffer();
constraintNameFilter.append("SQL[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]");
searchStrings.addElement(constraintNameFilter.toString());
// Filter for uuids
StringBuffer uuidFilter = new StringBuffer();
uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-");
uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]");
searchStrings.addElement(uuidFilter.toString());
// Filter for timestamps
StringBuffer timestampFilter = new StringBuffer();
timestampFilter.append( "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " );
timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
searchStrings.addElement( timestampFilter.toString() );
// 3 digit year
timestampFilter = new StringBuffer();
timestampFilter.append( "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " );
timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
searchStrings.addElement( timestampFilter.toString() );
// ibm13 year
timestampFilter = new StringBuffer();
timestampFilter.append( "[0-9]-[0-9][0-9]-[0-9][0-9] " );
timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" );
searchStrings.addElement( timestampFilter.toString() );
// Filter remove transaction id's from deadlock messages
searchStrings.addElement("^ Waiting XID : \\{.*\\}");
searchStrings.addElement("^ Granted XID : .*$");
searchStrings.addElement("^The selected victim is XID : .*");
// Filters for build numbers
searchStrings.addElement("(beta - )\\(([0-9]*)\\)");
searchStrings.addElement("CostEstimateImpl: .*");
// Filter for xa tests for the numbers representing the db name (it can change)
searchStrings.addElement("^Transaction ([0-9])* : \\(([0-9]*)\\,([0-9a-f]*)\\,([0-9a-f]*)\\)");
// Filter for optimizer number for zindexesLevel1 test (due to a change in display width for the test)
searchStrings.addElement("^Modifying access paths using optimizer .[0-9]*");
searchStrings.addElement("CDWS[0-9]*");
searchStrings.addElement("IXWS[0-9]*");
// for j9, to eliminate intermittent failures due to this problem in j9:
searchStrings.addElement("FAILED STACK MAP");
if (isJCC)
{
searchStrings.addElement("[ ]*\\|");
searchStrings.addElement("^--*");
}
//Filter to suppress absould paths in error message for roll forward recovery tests
searchStrings.addElement("Directory.*.wombat.already.exists");
searchStrings.addElement("Directory.*.extinout/crwombatlog/log.*.exists");
// Filter for "DB2ConnectionCorrelator" text that can be printed as
// part of some JCC error messages.
searchStrings.addElement(" DB2ConnectionCorrelator: [0-9A-Z.]*");
// Filter for SAX exception name diffs between jvms.
searchStrings.addElement("org.xml.sax.SAX.*$");
// Filter out localhost, or hostName
searchStrings.addElement(hostName);
if ( isJDBC4 )
{
// Filters for the sql exception class names which appear in
// exception messages. These are different in JDBC3 and JDBC4.
searchStrings.addElement("java.sql.SQLDataException:");
searchStrings.addElement("java.sql.SQLDataSetSyncException:");
searchStrings.addElement("java.sql.SQLException:");
searchStrings.addElement("java.sql.SQLFeatureNotSupportedException:");
searchStrings.addElement("java.sql.SQLIntegrityConstraintViolationException:");
searchStrings.addElement("java.sql.SQLInvalidAuthorizationSpecException:");
searchStrings.addElement("java.sql.SQLNonTransientConnectionException:");
searchStrings.addElement("java.sql.SQLNonTransientException:");
searchStrings.addElement("java.sql.SQLRuntimeException:");
searchStrings.addElement("java.sql.SQLSyntaxErrorException:");
searchStrings.addElement("java.sql.SQLTimeoutException:");
searchStrings.addElement("java.sql.SQLTransactionRollbackException:");
searchStrings.addElement("java.sql.SQLTransientConnectionException:");
searchStrings.addElement("java.sql.SQLTransientException:");
// The JDBC4 error from the driver is a little chattier
searchStrings.addElement("No suitable driver found for [0-9A-Za-z:]*");
searchStrings.addElement("No suitable driver;[0-9A-Za-z:=]*");
searchStrings.addElement("SQL Exception: No suitable driver");
// Timestamp diagnostic looks a little different under jdk16
searchStrings.addElement("\\[\\.fffffffff\\]");
}
Vector<String> subStrings = new Vector<String>();
subStrings.addElement("Transaction:(XXX)|");
subStrings.addElement("Read ... bytes");
subStrings.addElement("Directory DBLOCATION/seg0");
subStrings.addElement("with class loader XXXX, ");
subStrings.addElement("xxxxGENERATED-IDxxxx");
subStrings.addElement("xxxxFILTERED-UUIDxxxx");
subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx");
// remove transaction id's from deadlock messages
subStrings.addElement(" Waiting XID : {WWW,QQQ}");
subStrings.addElement(" Granted XID : {GGG.QQQ}...");
subStrings.addElement("The selected victim is XID : VVV");
// sub build numbers
subStrings.addElement("$1(xxXXxxFILTERED-BUILD-NUMBERxxXXxx)");
subStrings.addElement("CostEstimateImpl: xxXXxxFILTERED-INFORMATIONxxXXxx");
// sub for db name in xa tests (it can change)
subStrings.addElement("Transaction $1 : ($2,FILTERED,FILTERED)");
// sub for optimizer number for zindexesLevel1 test
subStrings.addElement("Modifying access paths using optimizer FILTERED_NUMBER");
subStrings.addElement("CDWSno");
subStrings.addElement("IXWSno");
// for j9, to eliminate intermittent failures due to this problem in j9:
subStrings.addElement("");
// for JCC replace multiple blanks with one blank to handle differences
// in display width
if (isJCC)
{
subStrings.addElement(" |");
subStrings.addElement("-----");
}
subStrings.addElement("Directory DBLOCATION/wombat already exists");
subStrings.addElement("Directory 'extinout<sp>crwombatlog<sp>log' exists");
// ignore the 'DB2ConnectionCorrelator' thing altogether.
subStrings.addElement("");
// Filter for SAX exception name diffs between jvms.
subStrings.addElement("xxxFILTERED-SAX-EXCEPTIONxxx'.");
// Filter out localhost, or hostName
subStrings.addElement("xxxFILTERED_HOSTNAMExxx");
if ( isJDBC4 )
{
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement(SQL_EXCEPTION_FILTERED_SUBSTITUTION);
subStrings.addElement("No suitable driver");
subStrings.addElement("No suitable driver");
subStrings.addElement("java.sql.SQLException: No suitable driver");
subStrings.addElement(".fffffffff");
}
doWork(srcFile, dstFile, null, deleteLines, searchStrings, subStrings, isSed, isI18N);
} // end exec
// This just does JCC changes on the output master file
public void execJCC(InputStream is, File dstFile)
throws IOException
{
// Vector for storing lines to be deleted
Vector<String> deleteLines = new Vector<String>();
// Vectors for substitutions
Vector<String> searchStrings = new Vector<String>();
searchStrings.addElement("[ ]*\\|");
searchStrings.addElement("^--*");
Vector<String> subStrings = new Vector<String>();
// true and false show up as 1 and 0 in JCC.
//because they have no boolean support
subStrings.addElement(" |");
subStrings.addElement("-----");
doWork(null, dstFile, is, deleteLines, searchStrings, subStrings, null);
}
private void doWork(File srcFile, File dstFile, InputStream is,
Vector<String> deleteLines, Vector<String> searchStrings,
Vector<String> subStrings, InputStream isSed)
throws IOException
{
doWork(srcFile, dstFile, is, deleteLines, searchStrings, subStrings, isSed, false);
}
private void doWork(File srcFile, File dstFile, InputStream is,
Vector<String> deleteLines, Vector<String> searchStrings,
Vector<String> subStrings, InputStream isSed, boolean isI18N)
throws IOException
{
BufferedReader inFile;
PrintWriter outFile;
// ---------------------------------
// Try loading the sed properties if they exist (see jdbc_sed.properties as an example)
if ( isSed != null )
{
Properties sedp = new Properties();
sedp.load(isSed);
for (String key : sedp.stringPropertyNames())
{
if (key.equals("substitute"))
{
String value = sedp.getProperty(key);
// value string contains a comma separated list of patterns
StringTokenizer st = new StringTokenizer(value,",");
String patternName = "";
String patName = "";
String subName = "";
while (st.hasMoreTokens())
{
patternName = st.nextToken();
// pattern;substitute
StringTokenizer st2 = new StringTokenizer(patternName,";");
patName = st2.nextToken();
subName = st2.nextToken();
if (!patName.equals("") && !subName.equals(""))
{
searchStrings.addElement(patName);
subStrings.addElement(subName);
}
//System.out.println("pattern = " + patName + " substitute " + subName);
}
}
else if (key.equals("delete"))
{
String value = sedp.getProperty(key);
// value string contains a comma separated list of patterns
StringTokenizer st = new StringTokenizer(value,",");
String patternName = "";
while (st.hasMoreTokens())
{
patternName = st.nextToken();
deleteLines.addElement(patternName);
}
}
}
}
// ---------------------------------
// Define the input and output files based on args
if (is == null && isI18N) {
// read UTF-8 encoded file
InputStream fs = new FileInputStream(srcFile);
inFile = new BufferedReader(new InputStreamReader(fs, "UTF-8"));
} else if (is == null) {
// read the file using the default encoding
inFile = new BufferedReader(new FileReader(srcFile));
} else {
inFile = new BufferedReader(new InputStreamReader(is, "UTF-8"));
}
outFile = new PrintWriter
( new BufferedWriter(new FileWriter(dstFile), 10000), true );
// Attempt to compile the patterns for deletes
List<Pattern> deletePatterns = deleteLines.stream()
.map(Pattern::compile).collect(Collectors.toList());
// Attempt to compile the patterns for substitutes
List<Pattern> substitutePatterns = searchStrings.stream()
.map(Pattern::compile).collect(Collectors.toList());
String str;
int j;
int lineCount = 0;
// Read the input file
while ( (str = inFile.readLine()) != null )
{
lineCount++;
//System.out.println("***Line no: " + lineCount);
//System.out.println("***Line is: " + str);
boolean lineDeleted = false;
// First delete any nulls (Cafe 1.8 leaves nulls)
if (str.length() == 1)
{
if (str.charAt(0) == (char) 0)
{
// Skip this line, don't write it
//System.out.println("Skip this line...");
lineDeleted = true;
}
}
// Now determine if & if so, replace, any non-ascii characters
// We do this because non-ascii characters in .sql files will
// result in different characters depending on encoding, and
// encoding may be different on different os's
if (isI18N)
{
boolean hasNonAscii = false;
// check for any characters in the control range
for (int si = 0; si < str.length(); si++)
{
char c = str.charAt(si);
if (c < (char) 0x20 || c >= (char) 0x7f)
{
hasNonAscii = true;
break;
}
}
if (hasNonAscii)
{
StringBuffer sb = new StringBuffer();
for (int si = 0; si < str.length(); si++)
{
char c = str.charAt(si);
if (c < (char) 0x20 || c >= (char) 0x7f)
{
sb.append(' ');
// Encoded Character:> ... <
sb.append("EnC:>");
sb.append((int) str.charAt(si));
sb.append("< ");
}
else
sb.append(c);
}
str = sb.toString();
}
}
// Determine if this line should be deleted for delete pattern match
if ( lineDeleted == false )
{
final String s = str;
lineDeleted =
deletePatterns.stream().anyMatch(p -> p.matcher(s).find());
}
// Determine if any substitutions are needed
if (lineDeleted == false)
{
for (j = 0; j < substitutePatterns.size(); j++)
{
Pattern patt = substitutePatterns.get(j);
//System.out.println("Pattern string is " + patt);
String sub = subStrings.get(j);
//System.out.println("Substitute str = " + sub);
str = patt.matcher(str).replaceAll(sub);
}
//System.out.println("Write the str: " + str);
outFile.println(str);
}// end if
} // end while
inFile.close();
outFile.flush();
outFile.close();
}// end doWork
}
|