ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r1158470 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/taskdefs/optional/ src/main/org/apache/tools/ant/taskdefs/optional/junit/ src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/
Date Tue, 16 Aug 2011 23:08:11 GMT
Author: jglick
Date: Tue Aug 16 23:08:11 2011
New Revision: 1158470

URL: http://svn.apache.org/viewvc?rev=1158470&view=rev
Log:
#51668: JAXP regression preventing <junitreport> from working in JDK 7 w/ SecurityManager.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1158470&r1=1158469&r2=1158470&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Aug 16 23:08:11 2011
@@ -13,6 +13,9 @@ Changes that could break older environme
 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
    Bugzilla Report 50515.
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java?rev=1158470&r1=1158469&r2=1158470&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java Tue Aug
16 23:08:11 2011
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Field;
 import java.util.Hashtable;
 import java.util.Vector;
 import java.util.Enumeration;
@@ -417,6 +418,17 @@ public class TraXLiaison implements XSLT
                 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);
 
         // specific attributes for the transformer
@@ -431,6 +443,11 @@ public class TraXLiaison implements XSLT
         }
         return tfactory;
     }
+    /**
+     * Not part of any stable API.
+     * @see #51668
+     */
+    public static final ThreadLocal/*<Boolean>*/ DISABLE_SECURE_PROCESSING = new ThreadLocal();
 
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java?rev=1158470&r1=1158469&r2=1158470&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
Tue Aug 16 23:08:11 2011
@@ -38,6 +38,7 @@ import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.XSLTProcess;
 import org.apache.tools.ant.taskdefs.Delete;
 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.FileUtils;
 import org.apache.tools.ant.types.EnumeratedAttribute;
@@ -260,10 +261,13 @@ public class AggregateTransformer {
         paramx.setName("output.dir");
         paramx.setExpression(toDir.getAbsolutePath());
         final long t0 = System.currentTimeMillis();
+        TraXLiaison.DISABLE_SECURE_PROCESSING.set(Boolean.TRUE);
         try {
             xsltTask.execute();
         } catch (Exception e) {
             throw new BuildException("Errors while applying transformations: " + e.getMessage(),
e);
+        } finally {
+            TraXLiaison.DISABLE_SECURE_PROCESSING.set(null);
         }
         final long dt = System.currentTimeMillis() - t0;
         task.log("Transform time: " + dt + "ms");

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java?rev=1158470&r1=1158469&r2=1158470&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
(original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
Tue Aug 16 23:08:11 2011
@@ -19,7 +19,9 @@
 package org.apache.tools.ant.taskdefs.optional.junit;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.PrintWriter;
+import java.security.Permission;
 import junit.framework.TestCase;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Delete;
@@ -32,11 +34,17 @@ public class XMLResultAggregatorTest ext
     }
 
     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");
         new Delete() {{removeDir(d);}}; // is there no utility method for this?
         assertTrue(d.getAbsolutePath(), d.mkdir());
         File xml = new File(d, "x.xml");
-        PrintWriter pw = new PrintWriter(xml);
+        PrintWriter pw = new PrintWriter(new FileOutputStream(xml));
         try {
             pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>");
             pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>");
@@ -55,6 +63,20 @@ public class XMLResultAggregatorTest ext
         Project project = new Project();
         project.init();
         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();
         assertTrue(new File(d, "index.html").isFile());
     }



Mime
View raw message