Skip to content

Commit

Permalink
DERBY-6868: Remove the dependency on Jakarta ORO
Browse files Browse the repository at this point in the history
Rewrite the Sed class so that it uses java.util.regex instead of
Jakarta ORO for regular expression matching and substitution.

Remove tools/java/jakarta-oro-2.0.8.jar and all references to it.

git-svn-id: https://svn.apache.org/repos/asf/db/derby/code/trunk@1729326 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kahatlen committed Feb 9, 2016
1 parent 0d57d84 commit 949e80b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 139 deletions.
1 change: 0 additions & 1 deletion build.xml
Expand Up @@ -2706,7 +2706,6 @@
<fileset dir="${derby.junit.test.jars}" includes="*.jar"/>
<pathelement path="${derby.junit.classpath}"/>
<pathelement location="${javatools.dir}/junit.jar"/>
<pathelement location="${javatools.dir}/jakarta-oro-2.0.8.jar"/>
</path>
<echo message="Classpath used for derbyall: ${toString:derbyall.classpath}"/>
<mkdir dir="junit_${derby.junit.timestamp}/derbyall"/>
Expand Down
13 changes: 2 additions & 11 deletions java/testing/README.htm
Expand Up @@ -216,15 +216,6 @@ <h3><a name="2.1_running_with_derby_classes_"></a>2.1 running tests</h3>
<p style="margin-bottom: 0in;">set $CLASSPATH to include the
following jars: </p>
<ul>
<li>
<p style="margin-bottom: 0in;"><font size="2">jakarta-oro-2.0.8.jar</font>
&nbsp;&nbsp;&nbsp; <font size="2">oromatcher, obtain from the svn source tree, or from <a
href="http://jakarta.apache.org/oro/index.html">http://jakarta.apache.org/oro/index.html</a>,
or follow this link for <a
href="http://apache.roweboat.net/jakarta/oro/source/jakarta-oro-2.0.8.zip">zip</a>
file, or <a
href="http://apache.roweboat.net/jakarta/oro/source/jakarta-oro-2.0.8.tar.gz">tar</a>.gz)</font></p>
</li>
<li>
<p style="margin-bottom: 0in;"><font size="2">derbyTesting.jar<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font size="2">test files and
Expand Down Expand Up @@ -264,11 +255,11 @@ <h3><a name="2.1_running_with_derby_classes_"></a>2.1 running tests</h3>
<p><font size="2">(note that $jardir is only a convenience
variable that points to the directory containing the Derby jar files,
and $tstjardir ia a convenience variable that points to the directory
containing the jar files for Jakarta ORO and JUnit):<br>
containing the jar file for JUnit):<br>
set jardir=/local/derbyjar<br>
set tstjardir=/local/testingjars<br>
set
CLASSPATH="$jardir/derbyrun.jar:$jardir/derbyTesting.jar:$tstjardir/jakarta-oro-2.0.8.jar:$tstjardir/junit.jar"</font><br>
CLASSPATH="$jardir/derbyrun.jar:$jardir/derbyTesting.jar:$tstjardir/junit.jar"</font><br>
<font size="2">set PATH=/local/jdk141/bin:$PATH</font></p>
</td>
</tr>
Expand Down
129 changes: 21 additions & 108 deletions java/testing/org/apache/derbyTesting/functionTests/harness/Sed.java
Expand Up @@ -25,17 +25,18 @@ Licensed to the Apache Software Foundation (ASF) under one or more
* Sed.java
*
* This is a version of "sed" in Java for the Derby Function Tests,
* written using the OROMatcher Perl5 regular expression classes.
* 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 org.apache.oro.text.regex.*;
import java.util.Enumeration;
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
Expand Down Expand Up @@ -148,7 +149,7 @@ public static void main(String[] args) throws Exception {
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("^ Waiting XID : \\{.*\\}");
searchStrings.addElement("^ Granted XID : .*$");
searchStrings.addElement("^The selected victim is XID : .*");
// Filters for build numbers
Expand Down Expand Up @@ -313,17 +314,8 @@ private void doWork(File srcFile, File dstFile, InputStream is,
Vector<String> subStrings, InputStream isSed, boolean isI18N)
throws IOException
{

boolean lineDeleted = false;
PatternMatcher matcher;
Perl5Compiler pcompiler;
PatternMatcherInput input;
BufferedReader inFile;
PrintWriter outFile;
String result = "";
String regex;
Vector<Pattern> delPatternVector = new Vector<Pattern>();
Vector<Pattern> subPatternVector = new Vector<Pattern>();

// ---------------------------------
// Try loading the sed properties if they exist (see jdbc_sed.properties as an example)
Expand All @@ -332,9 +324,8 @@ private void doWork(File srcFile, File dstFile, InputStream is,
Properties sedp = new Properties();

sedp.load(isSed);
for (Enumeration e = sedp.propertyNames(); e.hasMoreElements(); )
for (String key : sedp.stringPropertyNames())
{
String key = (String)e.nextElement();
if (key.equals("substitute"))
{
String value = sedp.getProperty(key);
Expand Down Expand Up @@ -374,10 +365,6 @@ else if (key.equals("delete"))
}
// ---------------------------------

//Create Perl5Compiler and Perl5Matcher
pcompiler = new Perl5Compiler();
matcher = new Perl5Matcher();

// Define the input and output files based on args
if (is == null && isI18N) {
// read UTF-8 encoded file
Expand All @@ -393,42 +380,12 @@ else if (key.equals("delete"))
( new BufferedWriter(new FileWriter(dstFile), 10000), true );

// Attempt to compile the patterns for deletes
for (int i = 0; i < deleteLines.size(); i++)
{
try
{
regex = (String)deleteLines.elementAt(i);
//System.out.println("The pattern: " + regex);
Pattern pattern = pcompiler.compile(regex);
if (pattern == null)
System.out.println("pattern is null");
delPatternVector.addElement(pattern);
}
catch(MalformedPatternException e)
{
System.out.println("Bad pattern.");
System.out.println(e.getMessage());
}
}
List<Pattern> deletePatterns = deleteLines.stream()
.map(Pattern::compile).collect(Collectors.toList());

// Attempt to compile the patterns for substitutes
for (int i = 0; i < searchStrings.size(); i++)
{
try
{
regex = (String)searchStrings.elementAt(i);
//System.out.println("The pattern: " + regex);
Pattern pattern = pcompiler.compile(regex);
if (pattern == null)
System.out.println("pattern is null");
subPatternVector.addElement(pattern);
}
catch(MalformedPatternException e)
{
System.out.println("Bad pattern.");
System.out.println(e.getMessage());
}
}
List<Pattern> substitutePatterns = searchStrings.stream()
.map(Pattern::compile).collect(Collectors.toList());

String str;
int j;
Expand All @@ -440,7 +397,7 @@ else if (key.equals("delete"))

//System.out.println("***Line no: " + lineCount);
//System.out.println("***Line is: " + str);
lineDeleted = false;
boolean lineDeleted = false;

// First delete any nulls (Cafe 1.8 leaves nulls)
if (str.length() == 1)
Expand Down Expand Up @@ -495,68 +452,24 @@ else if (key.equals("delete"))
// Determine if this line should be deleted for delete pattern match
if ( lineDeleted == false )
{
for (j = 0; j < delPatternVector.size(); j++)
{
if ( matcher.contains( str, (Pattern)delPatternVector.elementAt(j) ) )
{
//System.out.println("***Match found to delete line***");
String tmpp = ((Pattern)delPatternVector.elementAt(j)).getPattern();
//System.out.println("***Pattern is: " + tmpp);

// In this case we are removing the line, so don't write it out
lineDeleted = true;
break;
}
}
final String s = str;
lineDeleted =
deletePatterns.stream().anyMatch(p -> p.matcher(s).find());
}

// Determine if any substitutions are needed
if (lineDeleted == false)
{
Substitution substitution;
StringSubstitution strsub = new StringSubstitution("");
Perl5Substitution perlsub = new Perl5Substitution("");
boolean subDone = false;
for (j = 0; j < subPatternVector.size(); j++)
for (j = 0; j < substitutePatterns.size(); j++)
{
input = new PatternMatcherInput(str);
Pattern patt = (Pattern)subPatternVector.elementAt(j);
String pstr = patt.getPattern();
//System.out.println("Pattern string is " + pstr);
String sub = (String)subStrings.elementAt(j);
if (sub.indexOf("$") > 0)
{
perlsub.setSubstitution(sub);
substitution = (Substitution)perlsub;
} else {
strsub.setSubstitution(sub);
substitution = (Substitution)strsub;
}
Pattern patt = substitutePatterns.get(j);
//System.out.println("Pattern string is " + patt);
String sub = subStrings.get(j);
//System.out.println("Substitute str = " + sub);
if ( matcher.contains( input, patt ) )
{
MatchResult mr = matcher.getMatch();
//System.out.println("***Match found for substitute***");
// In this case we do a substitute
result = Util.substitute(matcher, patt, substitution, str,
Util.SUBSTITUTE_ALL);
//System.out.println("New string: " + result);
//outFile.println(result);
str = result;
subDone = true;
}
}
if (subDone)
{
//System.out.println("write the subbed line");
outFile.println(result);
}
else
{
//System.out.println("Write the str: " + str);
outFile.println(str);
outFile.flush();
str = patt.matcher(str).replaceAll(sub);
}
//System.out.println("Write the str: " + str);
outFile.println(str);
}// end if
} // end while
inFile.close();
Expand Down
Expand Up @@ -78,7 +78,6 @@
srcdir="${derby.testing.src.dir}"
destdir="${out.dir}">
<classpath>
<pathelement location="${oro}"/>
<pathelement path="${junit}"/>
</classpath>
<include name="${this.dir}/*.java"/>
Expand Down
Expand Up @@ -55,7 +55,6 @@
srcdir="${derby.testing.src.dir}"
destdir="${out.dir}">
<classpath>
<pathelement location="${oro}"/>
<pathelement path="${junit}"/>
</classpath>
<include name="${this.dir}/*.java"/>
Expand Down
3 changes: 1 addition & 2 deletions tools/ant/properties/extrapath.properties
Expand Up @@ -22,7 +22,6 @@
#
# Extra jars/zips/classes
#
oro=${javatools.dir}/jakarta-oro-2.0.8.jar
servlet24=${javatools.dir}/geronimo-spec-servlet-2.4-rc4.jar
osgi=${out.felix.dir}
javacc=${javatools.dir}/javacc.jar
Expand All @@ -37,4 +36,4 @@ json_simple=${javatools.dir}/json_simple-1.1.jar
#
# Base JavaDoc collection, used for both product and test JavaDocs.
#
jars.javadoc=${osgi};${oro};${servlet24}:${lucene_core}:${lucene_a_co}:${lucene_qp}:${json_simple}
jars.javadoc=${osgi};${servlet24}:${lucene_core}:${lucene_a_co}:${lucene_qp}:${json_simple}
2 changes: 1 addition & 1 deletion tools/ide/netbeans/nbproject/project.xml
Expand Up @@ -262,7 +262,7 @@
<package-root>${project.dir}/java/tools</package-root>
<package-root>${project.dir}/generated/java</package-root>
<package-root>${project.dir}/java/optional</package-root>
<classpath mode="compile">${project.dir}/tools/java/geronimo-spec-servlet-2.4-rc4.jar:${project.dir}/tools/java/jakarta-oro-2.0.8.jar:${project.dir}/tools/java/javacc.jar:${project.dir}/tools/java/junit.jar:${ant.core.lib}:${project.dir}/classes/stubs/felix:${project.dir}/tools/java/lucene-analyzers-common.jar:${project.dir}/tools/java/lucene-core.jar:${project.dir}/tools/java/lucene-queryparser.jar</classpath>
<classpath mode="compile">${project.dir}/tools/java/geronimo-spec-servlet-2.4-rc4.jar:${project.dir}/tools/java/javacc.jar:${project.dir}/tools/java/junit.jar:${ant.core.lib}:${project.dir}/classes/stubs/felix:${project.dir}/tools/java/lucene-analyzers-common.jar:${project.dir}/tools/java/lucene-core.jar:${project.dir}/tools/java/lucene-queryparser.jar</classpath>
<built-to>${project.dir}/jars/sane/derby.jar</built-to>
<built-to>${project.dir}/jars/sane/derbyTesting.jar</built-to>
<built-to>${project.dir}/jars/sane/derbyclient.jar</built-to>
Expand Down
Binary file removed tools/java/jakarta-oro-2.0.8.jar
Binary file not shown.
12 changes: 0 additions & 12 deletions tools/release/build.xml
Expand Up @@ -260,8 +260,6 @@
<zipfileset dir="${basedir}/jars/insane" prefix="${derby.bin}/test" includes="derbyTesting.jar"/>
<zipfileset dir="${basedir}/java/testing" prefix="${derby.bin}/test"
includes="README.htm"/>
<zipfileset dir="${basedir}/tools/java" prefix="${derby.bin}/test"
includes="jakarta-oro-2.0.8.jar"/>
</zip>
</target>

Expand Down Expand Up @@ -318,8 +316,6 @@
<tarfileset dir="${basedir}/jars/insane" prefix="${derby.bin}/test" includes="derbyTesting.jar"/>
<tarfileset dir="${basedir}/java/testing" prefix="${derby.bin}/test"
includes="README.htm"/>
<tarfileset dir="${basedir}/tools/java" prefix="${derby.bin}/test"
includes="jakarta-oro-2.0.8.jar"/>
</tar>
</target>

Expand All @@ -335,8 +331,6 @@
<zipfileset dir="${basedir}/jars/insane" prefix="${derby.lib}/test" includes="derbyTesting.jar"/>
<zipfileset dir="${basedir}/java/testing" prefix="${derby.lib}/test"
includes="README.htm"/>
<zipfileset dir="${basedir}/tools/java" prefix="${derby.lib}/test"
includes="jakarta-oro-2.0.8.jar"/>
</zip>
</target>
<target name="lib.tgz">
Expand All @@ -349,8 +343,6 @@
<tarfileset dir="${basedir}/jars/insane" prefix="${derby.lib}/test" includes="derbyTesting.jar"/>
<tarfileset dir="${basedir}/java/testing" prefix="${derby.lib}/test"
includes="README.htm"/>
<tarfileset dir="${basedir}/tools/java" prefix="${derby.lib}/test"
includes="jakarta-oro-2.0.8.jar"/>
</tar>
</target>

Expand All @@ -366,8 +358,6 @@
<zipfileset dir="${basedir}/jars/sane" prefix="${derby.lib-debug}/test" includes="derbyTesting.jar"/>
<zipfileset dir="${basedir}/java/testing" prefix="${derby.lib-debug}/test"
includes="README.htm"/>
<zipfileset dir="${basedir}/tools/java" prefix="${derby.lib-debug}/test"
includes="jakarta-oro-2.0.8.jar"/>
</zip>
</target>
<target name="lib-debug.tgz">
Expand All @@ -380,8 +370,6 @@
<tarfileset dir="${basedir}/jars/sane" prefix="${derby.lib-debug}/test" includes="derbyTesting.jar"/>
<tarfileset dir="${basedir}/java/testing" prefix="${derby.lib-debug}/test"
includes="README.htm"/>
<tarfileset dir="${basedir}/tools/java" prefix="${derby.lib-debug}/test"
includes="jakarta-oro-2.0.8.jar"/>
</tar>
</target>

Expand Down
3 changes: 1 addition & 2 deletions tools/testing/reporting/TEMPLATES/testenv.sh
Expand Up @@ -24,7 +24,6 @@ export ROOT=${derby_source}

JARDIR=$ROOT/jars/insane # Change if you use sane
DBTOOLDIR=$ROOT/tools/java
ORO=$DBTOOLDIR/jakarta-oro-2.0.8.jar
JUNIT=$DBTOOLDIR/junit.jar

DERBY=$JARDIR/derby.jar
Expand All @@ -49,7 +48,7 @@ $JARDIR/derbyLocale_pt_BR.jar:\
$JARDIR/derbyLocale_zh_CN.jar:\
$JARDIR/derbyLocale_zh_TW.jar

export CLASSPATH=$DERBY:$DERBYCLIENT:$DERBYTOOLS:$DERBYNET:$DB2JCC:$DERBYTESTING:$DERBYRUN:$ORO:$JUNIT:$LOCALES
export CLASSPATH=$DERBY:$DERBYCLIENT:$DERBYTOOLS:$DERBYNET:$DB2JCC:$DERBYTESTING:$DERBYRUN:$JUNIT:$LOCALES

# At least needed on SunOs/x86:
export LC_CTYPE=en_US
Expand Down

0 comments on commit 949e80b

Please sign in to comment.