Browse Source

#51668: JAXP regression preventing <junitreport> from working in JDK 7 w/ SecurityManager.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1158470 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 14 years ago
parent
commit
735f3fca3e
4 changed files with 47 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +17
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  3. +4
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
  4. +23
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java

+ 3
- 0
WHATSNEW View File

@@ -13,6 +13,9 @@ Changes that could break older environments:
Fixed bugs: Fixed bugs:
----------- -----------


* <junitreport> did not work in embedded environments on JDK 7.
Bugzilla Report 51668.

* Encoding of unicode escape sequences by the property file task * Encoding of unicode escape sequences by the property file task
Bugzilla Report 50515. Bugzilla Report 50515.




+ 17
- 0
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
@@ -417,6 +418,17 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware
throw new BuildException(e); throw new BuildException(e);
} }
} }

if (Boolean.TRUE.equals(DISABLE_SECURE_PROCESSING.get())) {
try {
Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
_isNotSecureProcessing.setAccessible(true);
_isNotSecureProcessing.set(tfactory, Boolean.TRUE);
} catch (Exception x) {
project.log(x.toString(), Project.MSG_DEBUG);
}
}

tfactory.setErrorListener(this); tfactory.setErrorListener(this);


// specific attributes for the transformer // specific attributes for the transformer
@@ -431,6 +443,11 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware
} }
return tfactory; return tfactory;
} }
/**
* Not part of any stable API.
* @see #51668
*/
public static final ThreadLocal/*<Boolean>*/ DISABLE_SECURE_PROCESSING = new ThreadLocal();




/** /**


+ 4
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java View File

@@ -38,6 +38,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.XSLTProcess; import org.apache.tools.ant.taskdefs.XSLTProcess;
import org.apache.tools.ant.taskdefs.Delete; import org.apache.tools.ant.taskdefs.Delete;
import org.apache.tools.ant.taskdefs.TempFile; import org.apache.tools.ant.taskdefs.TempFile;
import org.apache.tools.ant.taskdefs.optional.TraXLiaison;
import org.apache.tools.ant.util.JAXPUtils; import org.apache.tools.ant.util.JAXPUtils;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -260,10 +261,13 @@ public class AggregateTransformer {
paramx.setName("output.dir"); paramx.setName("output.dir");
paramx.setExpression(toDir.getAbsolutePath()); paramx.setExpression(toDir.getAbsolutePath());
final long t0 = System.currentTimeMillis(); final long t0 = System.currentTimeMillis();
TraXLiaison.DISABLE_SECURE_PROCESSING.set(Boolean.TRUE);
try { try {
xsltTask.execute(); xsltTask.execute();
} catch (Exception e) { } catch (Exception e) {
throw new BuildException("Errors while applying transformations: " + e.getMessage(), e); throw new BuildException("Errors while applying transformations: " + e.getMessage(), e);
} finally {
TraXLiaison.DISABLE_SECURE_PROCESSING.set(null);
} }
final long dt = System.currentTimeMillis() - t0; final long dt = System.currentTimeMillis() - t0;
task.log("Transform time: " + dt + "ms"); task.log("Transform time: " + dt + "ms");


+ 23
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java View File

@@ -19,7 +19,9 @@
package org.apache.tools.ant.taskdefs.optional.junit; package org.apache.tools.ant.taskdefs.optional.junit;


import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.security.Permission;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Delete; import org.apache.tools.ant.taskdefs.Delete;
@@ -32,11 +34,17 @@ public class XMLResultAggregatorTest extends TestCase {
} }


public void testFrames() throws Exception { public void testFrames() throws Exception {
// For now, skip this test on JDK 6 (and below); see below for why:
try {
Class.forName("java.nio.file.Files");
} catch (ClassNotFoundException x) {
return;
}
final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest");
new Delete() {{removeDir(d);}}; // is there no utility method for this? new Delete() {{removeDir(d);}}; // is there no utility method for this?
assertTrue(d.getAbsolutePath(), d.mkdir()); assertTrue(d.getAbsolutePath(), d.mkdir());
File xml = new File(d, "x.xml"); File xml = new File(d, "x.xml");
PrintWriter pw = new PrintWriter(xml);
PrintWriter pw = new PrintWriter(new FileOutputStream(xml));
try { try {
pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>"); pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>");
pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>"); pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>");
@@ -55,6 +63,20 @@ public class XMLResultAggregatorTest extends TestCase {
Project project = new Project(); Project project = new Project();
project.init(); project.init();
task.setProject(project); task.setProject(project);
/* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD:
Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
public InputStream getResourceAsStream(String name) {
if (name.startsWith("META-INF/services/")) {
return new ByteArrayInputStream(new byte[0]);
}
return super.getResourceAsStream(name);
}
});
*/
// Use the JRE's Xerces, not lib/optional/xerces.jar:
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent());
// Tickle #51668:
System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
task.execute(); task.execute();
assertTrue(new File(d, "index.html").isFile()); assertTrue(new File(d, "index.html").isFile());
} }


Loading…
Cancel
Save