# HG changeset patch # User alanb # Date 1458241445 0 # Node ID cb52aa47ff0adc52b01f6e039d27836cc286c1d6 # Parent a9614cbbeb3e1982042b3f24efa441f25cb6d404 8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, joehw Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java Thu Mar 17 19:04:05 2016 +0000 @@ -505,4 +505,15 @@ = "com.sun.org.apache.xalan.internal.xsltc.compiler.Fallback"; public static final int RTF_INITIAL_SIZE = 32; + + // the API packages used by generated translet classes + public static String[] PKGS_USED_BY_TRANSLET_CLASSES = { + "com.sun.org.apache.xalan.internal.lib", + "com.sun.org.apache.xalan.internal.xsltc", + "com.sun.org.apache.xalan.internal.xsltc.runtime", + "com.sun.org.apache.xalan.internal.xsltc.dom", + "com.sun.org.apache.xml.internal.serializer", + "com.sun.org.apache.xml.internal.dtm", + "com.sun.org.apache.xml.internal.dtm.ref", + }; } diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java Thu Mar 17 19:04:05 2016 +0000 @@ -47,6 +47,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import java.util.Objects; import java.util.Vector; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; @@ -115,7 +116,7 @@ private boolean _debug = false; // -x private String _jarFileName = null; // -j private String _className = null; // -o - private String _packageName = null; // -p + private String _packageName = "die.verwandlung"; // override with -p private File _destDir = null; // -d private int _outputType = FILE_OUTPUT; // by default @@ -724,7 +725,7 @@ * Set an optional package name for the translet and auxiliary classes */ public void setPackageName(String packageName) { - _packageName = packageName; + _packageName = Objects.requireNonNull(packageName); if (_className != null) setClassName(_className); } diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Thu Mar 17 19:04:05 2016 +0000 @@ -28,6 +28,7 @@ import com.sun.org.apache.xalan.internal.utils.SecuritySupport; import com.sun.org.apache.xalan.internal.xsltc.DOM; import com.sun.org.apache.xalan.internal.xsltc.Translet; +import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import java.io.IOException; @@ -36,8 +37,11 @@ import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; +import java.util.Arrays; +import java.util.Collections; import java.security.AccessController; import java.security.PrivilegedAction; +import java.lang.reflect.Module; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -47,6 +51,8 @@ import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.URIResolver; +import jdk.internal.module.Modules; + /** * @author Morten Jorgensen * @author G. Todd Millerj @@ -410,6 +416,31 @@ _auxClasses = new HashMap<>(); } + // create a module for the translet + Module xmlModule = TemplatesImpl.class.getModule(); + String pn = _tfactory.getPackageName(); + assert pn != null && pn.length() > 0; + + Module m = Modules.defineModule(loader, "jdk.translet", + Collections.singleton(pn)); + + // jdk.translate reads java.base && java.xml + Modules.addReads(m, Object.class.getModule()); + Modules.addReads(m, xmlModule); + + // jdk.translet needs access to runtime classes + Arrays.asList(Constants.PKGS_USED_BY_TRANSLET_CLASSES).forEach(p -> { + xmlModule.addExports(p, m); + }); + + // jdk.translate also needs to be loose as the XSL may bind to + // java types in an unnamed module + Modules.addReads(m, null); + + // java.xml needs to instanitate the translate class + xmlModule.addReads(m); + Modules.addExports(m, pn, xmlModule); + for (int i = 0; i < classCount; i++) { _class[i] = loader.defineClass(_bytecodes[i]); final Class superClass = _class[i].getSuperclass(); @@ -434,7 +465,7 @@ } catch (LinkageError e) { ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name); - throw new TransformerConfigurationException(err.toString()); + throw new TransformerConfigurationException(err.toString(), e); } } diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java Thu Mar 17 19:04:05 2016 +0000 @@ -137,7 +137,8 @@ /** * The package name prefix for all generated translet classes */ - private String _packageName = null; + private static final String DEFAULT_TRANSLATE_PACKAGE = "die.verwandlung"; + private String _packageName = DEFAULT_TRANSLATE_PACKAGE; /** * The jar file name which the translet classes are packaged into @@ -308,6 +309,13 @@ } /** + * Returns the package name. + */ + String getPackageName() { + return _packageName; + } + + /** * javax.xml.transform.sax.TransformerFactory implementation. * Returns the value set for a TransformerFactory attribute * @@ -884,7 +892,7 @@ String transletClassName = getTransletBaseName(source); if (_packageName != null) - transletClassName = _packageName + "." + transletClassName; + transletClassName = _packageName + "." + transletClassName; if (_jarFileName != null) bytecodes = getBytecodesFromJar(source, transletClassName); @@ -1286,7 +1294,7 @@ private void resetTransientAttributes() { _transletName = DEFAULT_TRANSLET_NAME; _destinationDirectory = null; - _packageName = null; + _packageName = DEFAULT_TRANSLATE_PACKAGE; _jarFileName = null; } diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/FunctionTable.java --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/FunctionTable.java Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/compiler/FunctionTable.java Thu Mar 17 19:04:05 2016 +0000 @@ -24,7 +24,6 @@ */ package com.sun.org.apache.xpath.internal.compiler; -import com.sun.org.apache.xpath.internal.Expression; import com.sun.org.apache.xpath.internal.functions.Function; import java.util.HashMap; import javax.xml.transform.TransformerException; @@ -341,11 +340,12 @@ throws javax.xml.transform.TransformerException { try{ - if (which < NUM_BUILT_IN_FUNCS) + if (which < NUM_BUILT_IN_FUNCS) { return (Function) m_functions[which].newInstance(); - else - return (Function) m_functions_customer[ - which-NUM_BUILT_IN_FUNCS].newInstance(); + } else { + Class c = m_functions_customer[which-NUM_BUILT_IN_FUNCS]; + return (Function) c.newInstance(); + } }catch (IllegalAccessException ex){ throw new TransformerException(ex.getMessage()); }catch (InstantiationException ex){ diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/java.xml/share/classes/module-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/src/java.xml/share/classes/module-info.java Thu Mar 17 19:04:05 2016 +0000 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module java.xml { + exports javax.xml; + exports javax.xml.catalog; + exports javax.xml.datatype; + exports javax.xml.namespace; + exports javax.xml.parsers; + exports javax.xml.stream; + exports javax.xml.stream.events; + exports javax.xml.stream.util; + exports javax.xml.transform; + exports javax.xml.transform.dom; + exports javax.xml.transform.sax; + exports javax.xml.transform.stax; + exports javax.xml.transform.stream; + exports javax.xml.validation; + exports javax.xml.xpath; + exports org.w3c.dom; + exports org.w3c.dom.bootstrap; + exports org.w3c.dom.events; + exports org.w3c.dom.ls; + exports org.w3c.dom.ranges; + exports org.w3c.dom.traversal; + exports org.w3c.dom.views; + exports org.xml.sax; + exports org.xml.sax.ext; + exports org.xml.sax.helpers; + exports com.sun.org.apache.xerces.internal.dom to + java.xml.ws; + exports com.sun.org.apache.xerces.internal.jaxp to + java.xml.ws; + exports com.sun.org.apache.xerces.internal.util to + java.xml.ws; + exports com.sun.org.apache.xml.internal.dtm to + java.xml.crypto; + exports com.sun.org.apache.xml.internal.resolver to + java.xml.ws, + jdk.xml.bind; + exports com.sun.org.apache.xml.internal.resolver.tools to + java.xml.ws, + jdk.xml.bind; + exports com.sun.org.apache.xml.internal.utils to + java.xml.crypto; + exports com.sun.org.apache.xpath.internal to + java.xml.crypto; + exports com.sun.org.apache.xpath.internal.compiler to + java.xml.crypto; + exports com.sun.org.apache.xpath.internal.functions to + java.xml.crypto; + exports com.sun.org.apache.xpath.internal.objects to + java.xml.crypto; + exports com.sun.org.apache.xpath.internal.res to + java.xml.crypto; + // reflection access from com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory + exports com.sun.xml.internal.stream.writers to java.xml.ws; + uses javax.xml.datatype.DatatypeFactory; + uses javax.xml.parsers.DocumentBuilderFactory; + uses javax.xml.parsers.SAXParserFactory; + uses javax.xml.stream.XMLEventFactory; + uses javax.xml.stream.XMLInputFactory; + uses javax.xml.stream.XMLOutputFactory; + uses javax.xml.transform.TransformerFactory; + uses javax.xml.validation.SchemaFactory; + uses javax.xml.xpath.XPathFactory; +} + diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/src/jdk.xml.dom/share/classes/module-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jaxp/src/jdk.xml.dom/share/classes/module-info.java Thu Mar 17 19:04:05 2016 +0000 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +module jdk.xml.dom { + requires public java.xml; + exports org.w3c.dom.css; + exports org.w3c.dom.html; + exports org.w3c.dom.stylesheets; + exports org.w3c.dom.xpath; +} + diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/test/TEST.ROOT --- a/jaxp/test/TEST.ROOT Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/test/TEST.ROOT Thu Mar 17 19:04:05 2016 +0000 @@ -18,4 +18,4 @@ groups=TEST.groups # Minimum jtreg version -requiredVersion=4.1 b12 +requiredVersion=4.2 b01 diff -r a9614cbbeb3e -r cb52aa47ff0a jaxp/test/javax/xml/jaxp/unittest/TEST.properties --- a/jaxp/test/javax/xml/jaxp/unittest/TEST.properties Tue Mar 15 13:48:24 2016 -0700 +++ b/jaxp/test/javax/xml/jaxp/unittest/TEST.properties Thu Mar 17 19:04:05 2016 +0000 @@ -4,5 +4,5 @@ lib.dirs = /javax/xml/jaxp/libs # Declare module dependency -modules=java.xml - +modules=java.xml/com.sun.org.apache.xerces.internal.jaxp \ + java.xml/com.sun.org.apache.xml.internal.serialize