Skip to content
Permalink
Browse files

Fix issue #183 by fixing use of the RuntimeRegistry and making sure r…

…untime.close is called appropriately
  • Loading branch information
ndw committed Apr 6, 2015
1 parent 79ab225 commit 46726f099076d3a624968d6f329ce345d893eebe
@@ -297,21 +297,21 @@ public XProcRuntime(XProcRuntime runtime) {
exFuncs.add(new VersionAvailable(this));
exFuncs.add(new XPathVersionAvailable(this));

reset();
}

public void resetExtensionFunctions() {
for (XProcExtensionFunctionDefinition xf : exFuncs) {
processor.registerExtensionFunction(xf);
}

reset();
}

public void close() {
HttpClientUtils.closeQuietly(httpClient);
httpClient = null;

for (XProcExtensionFunctionDefinition xf : exFuncs) {
xf.close();
}
HttpClientUtils.closeQuietly(httpClient);
httpClient = null;
exFuncs = null;
}

public XProcConfigurer getConfigurer() {
@@ -73,6 +73,7 @@
private XProcRuntime runtime = null;
private Logger logger = LoggerFactory.getLogger(Main.class);
private boolean debug = false;
private int chaseMemoryLeaks = 0;

/**
* @param args the command line arguments
@@ -94,10 +95,22 @@ public void run(String[] args) throws IOException {

try {
XProcConfiguration config = userArgs.createConfiguration();

if (run(userArgs, config)) {
// It's just sooo much nicer if there's a newline at the end.
System.out.println();
runtime = new XProcRuntime(config);
debug = config.debug;

if (chaseMemoryLeaks != 0) {
while (chaseMemoryLeaks > 0) {
System.err.println("Checking for memory leaks, running " + chaseMemoryLeaks);
run(userArgs, config);
//System.out.println("Hit enter to run again: ");
//System.in.read();
chaseMemoryLeaks--;
}
} else {
if (run(userArgs, config)) {
// It's just sooo much nicer if there's a newline at the end.
System.out.println();
}
}

} catch (UnsupportedOperationException uoe) {
@@ -137,9 +150,6 @@ public void run(String[] args) throws IOException {
}

boolean run(UserArgs userArgs, XProcConfiguration config) throws SaxonApiException, IOException, URISyntaxException {
runtime = new XProcRuntime(config);
debug = config.debug;

if (userArgs.isShowVersion()) {
XProcConfiguration.showVersion(runtime);
}
@@ -165,6 +165,7 @@ public static void main(String[] args) throws SaxonApiException, IOException, UR

RunTestReport test = new RunTestReport(runtime, new DefaultTestReporter(runtime));
test.runTests(tests);
runtime.close();
}

public void runTests(Vector<String> tests) {
@@ -109,7 +109,6 @@ public void run() throws SaxonApiException {
XdmNode piperoot = S9apiUtils.getDocumentElement(pipedoc);

XProcRuntime innerRuntime = new XProcRuntime(runtime);
innerRuntime.resetExtensionFunctions();

QName stepName = getOption(_step, (QName) null);
XPipeline pipeline = null;
@@ -273,7 +272,5 @@ public void run() throws SaxonApiException {
result.write(tree.getResult());
}
}

runtime.resetExtensionFunctions();
}
}
@@ -13,6 +13,10 @@
XProcConfiguration config = new XProcConfiguration("he", true);
XProcRuntime runtime = new XProcRuntime(config);

public void close() {
runtime.close();
}

protected RunTestReport reporter = new RunTestReport(runtime, new DefaultTestReporter(runtime));

public void runTest(String test) {
@@ -1,5 +1,6 @@
package com.xmlcalabash.testsuite;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -20,6 +21,11 @@ public static void setupClass() {
suiteRunner = new SuiteRunner();
}

@AfterClass
public static void teardownClass() {
suiteRunner.close();
}

@Ignore
public void testAll() {
suiteRunner.runTest(TESTROOT + "test-suite.xml");
@@ -1,5 +1,6 @@
package com.xmlcalabash.testsuite;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -19,6 +20,11 @@ public static void setupClass() {
suiteRunner = new SuiteRunner();
}

@AfterClass
public static void teardownClass() {
suiteRunner.close();
}

@Ignore
public void testAll() {
suiteRunner.runTest(TESTROOT + "test-suite.xml");
@@ -1,6 +1,6 @@
package com.xmlcalabash.testsuite;

import com.xmlcalabash.testsuite.SuiteRunner;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -17,6 +17,11 @@ public static void setupClass() {
suiteRunner = new SuiteRunner();
}

@AfterClass
public static void teardownClass() {
suiteRunner.close();
}

@Ignore
public void testAll() {
suiteRunner.runTest(TESTROOT + "test-suite.xml");
@@ -1,5 +1,6 @@
package com.xmlcalabash.testsuite;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -20,6 +21,11 @@ public static void setupClass() {
suiteRunner = new SuiteRunner();
}

@AfterClass
public static void teardownClass() {
suiteRunner.close();
}

@Ignore
public void testAll() {
suiteRunner.runTest(TESTROOT + "test-suite.xml");
@@ -1,5 +1,6 @@
package com.xmlcalabash.testsuite;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -20,6 +21,11 @@ public static void setupClass() {
suiteRunner = new SuiteRunner();
}

@AfterClass
public static void teardownClass() {
suiteRunner.close();
}

@Ignore
public void testAll() {
suiteRunner.runTest(TESTROOT + "test-suite.xml");

0 comments on commit 46726f0

Please sign in to comment.
You can’t perform that action at this time.