8142968: Module System implementation

Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282

Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Reviewed-by: alanb, mchung, joehw
This commit is contained in:
Alan Bateman 2016-03-17 19:04:05 +00:00
parent 3a5e11a3c0
commit 81f516c57b
9 changed files with 188 additions and 14 deletions
jaxp
src
java.xml/share/classes
com/sun/org/apache
module-info.java
jdk.xml.dom/share/classes
test
TEST.ROOT
javax/xml/jaxp/unittest

@ -505,4 +505,15 @@ public interface Constants extends InstructionConstants {
= "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",
};
}

@ -47,6 +47,7 @@ import java.util.Enumeration;
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 @@ public final class XSLTC {
private boolean _debug = false; // -x
private String _jarFileName = null; // -j <jar-file-name>
private String _className = null; // -o <class-name>
private String _packageName = null; // -p <package-name>
private String _packageName = "die.verwandlung"; // override with -p <package-name>
private File _destDir = null; // -d <directory-name>
private int _outputType = FILE_OUTPUT; // by default
@ -724,7 +725,7 @@ public final class XSLTC {
* 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);
}

@ -28,6 +28,7 @@ import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
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.ObjectInputStream;
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.Transformer;
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 @@ public final class TemplatesImpl implements Templates, Serializable {
_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 @@ public final class TemplatesImpl implements Templates, Serializable {
}
catch (LinkageError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
throw new TransformerConfigurationException(err.toString());
throw new TransformerConfigurationException(err.toString(), e);
}
}

@ -137,7 +137,8 @@ public class TransformerFactoryImpl
/**
* 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
@ -307,6 +308,13 @@ public class TransformerFactoryImpl
return _errorListener;
}
/**
* 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 @@ public class TransformerFactoryImpl
String transletClassName = getTransletBaseName(source);
if (_packageName != null)
transletClassName = _packageName + "." + transletClassName;
transletClassName = _packageName + "." + transletClassName;
if (_jarFileName != null)
bytecodes = getBytecodesFromJar(source, transletClassName);
@ -1286,7 +1294,7 @@ public class TransformerFactoryImpl
private void resetTransientAttributes() {
_transletName = DEFAULT_TRANSLET_NAME;
_destinationDirectory = null;
_packageName = null;
_packageName = DEFAULT_TRANSLATE_PACKAGE;
_jarFileName = null;
}

@ -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 @@ public class FunctionTable
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){

@ -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;
}

@ -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;
}

@ -18,4 +18,4 @@ othervm.dirs=javax/xml/jaxp
groups=TEST.groups
# Minimum jtreg version
requiredVersion=4.1 b12
requiredVersion=4.2 b01

@ -4,5 +4,5 @@ TestNG.dirs = .
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