(XMLBEANS-536) - change metadata path from schemaorg_apache_xmlbeans to org.apache.xmlbeans.metadata
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1879015 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/build.xml b/build.xml
index 87a6c69..13d8079 100644
--- a/build.xml
+++ b/build.xml
@@ -13,7 +13,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project name="XMLBeans" default="process-resources" basedir="." xmlns:unless="ant:unless">
+<project name="XMLBeans" default="process-resources" basedir="."
+ xmlns:mvn="antlib:org.apache.maven.artifact.ant"
+ xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="build.compiler" value="javac1.8"/>
<property name="ant.build.javac.source" value="1.8"/>
@@ -86,7 +88,7 @@
<path id="xmlbeans-test">
<pathelement location="build/classes"/>
<pathelement location="build/generated-resources"/>
- <dirset dir="resources" includes="*"/>
+ <dirset dir="resources" includes="*" excludes="maven"/>
<pathelement location="${saxon.jar}"/>
<pathelement location="test/lib/w3c_domts.jar"/>
<pathelement location="${junit.jar}"/>
@@ -186,7 +188,7 @@
<mkdir dir="${srcDir}"/>
<mkdir dir="${rscDir}"/>
- <uptodate property="up2date" targetfile="${rscDir}/schemaorg_apache_xmlbeans/system/@{schemaName}/TypeSystemHolder.class">
+ <uptodate property="up2date" targetfile="${rscDir}/org/apache/xmlbeans/system/@{schemaName}/TypeSystemHolder.class">
<srcresources>
<filelist dir="${basedir}" files="@{src}"/>
</srcresources>
@@ -196,6 +198,29 @@
<jvmarg value="-ea"/>
<arg line="-name @{schemaName} -srconly -noann -d ${rscDir} -src ${srcDir} @{src}"/>
</java>
+
+ </sequential>
+ </macrodef>
+
+ <macrodef name="replaceHolder">
+ <attribute name="srcDir"/>
+ <attribute name="rscDir"/>
+ <attribute name="schemaName"/>
+ <sequential>
+ <!-- if replaceHolder: copy TypeSystemHolder and replace package name, then compile -->
+ <mkdir dir="@{srcDir}/org/apache/xmlbeans/metadata/system/@{schemaName}"/>
+ <copy file="src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java" todir="@{srcDir}/org/apache/xmlbeans/metadata/system/@{schemaName}">
+ <filterchain>
+ <replacestring from="package org.apache.xmlbeans.impl.schema" to="package org.apache.xmlbeans.metadata.system.@{schemaName}"/>
+ </filterchain>
+ </copy>
+
+ <javac destdir="@{rscDir}" debug="true" debuglevel="lines,vars,source" includeantruntime="true">
+ <src path="@{srcDir}/org/apache/xmlbeans/metadata/system/@{schemaName}"/>
+ <classpath>
+ <pathelement location="${old.xmlbeans.jar}"/>
+ </classpath>
+ </javac>
</sequential>
</macrodef>
@@ -203,18 +228,15 @@
<attribute name="classpathref"/>
<attribute name="dest"/>
<sequential>
- <schemaComp schemaName="sXMLLANG" src="src/xmlschema/schema" dest="@{dest}" classpathref="@{classpathref}" />
- <schemaComp schemaName="sXMLSCHEMA" src="src/xsdschema/schema" dest="@{dest}" classpathref="@{classpathref}" />
- <schemaComp schemaName="sXMLCONFIG" src="src/configschema/schema" dest="@{dest}" classpathref="@{classpathref}" />
- <schemaComp schemaName="sXMLTOOLS" src="src/toolschema" dest="@{dest}" classpathref="@{classpathref}" />
+ <schemaComp schemaName="sXMLLANG" src="src/xmlschema/schema" dest="@{dest}" classpathref="@{classpathref}"/>
+ <schemaComp schemaName="sXMLSCHEMA" src="src/xsdschema/schema" dest="@{dest}" classpathref="@{classpathref}"/>
+ <schemaComp schemaName="sXMLCONFIG" src="src/configschema/schema" dest="@{dest}" classpathref="@{classpathref}"/>
+ <schemaComp schemaName="sXMLTOOLS" src="src/toolschema" dest="@{dest}" classpathref="@{classpathref}"/>
</sequential>
</macrodef>
<target name="process-resources" depends="-fetch-jars" description="Generate sources and resources based on schema files">
- <mkdir dir="build/classes"/>
- <mkdir dir="build/generated-sources"/>
-
<!-- Note that this is tricky because it bootstraps xmlbeans on itself. -->
<!-- The basic strategy is to rely on the oldxbeans.jar checked into lib -->
@@ -224,21 +246,41 @@
<schemaCompProd classpathref="oldxbean" dest="build/bootstrap"/>
+ <move file="build/bootstrap/generated-resources/schemaorg_apache_xmlbeans" tofile="build/bootstrap/generated-resources/org/apache/xmlbeans/metadata"/>
+
+ <replaceHolder srcDir="build/bootstrap/generated-sources" rscDir="build/bootstrap/generated-resources" schemaName="sXMLLANG"/>
+ <replaceHolder srcDir="build/bootstrap/generated-sources" rscDir="build/bootstrap/generated-resources" schemaName="sXMLSCHEMA"/>
+ <replaceHolder srcDir="build/bootstrap/generated-sources" rscDir="build/bootstrap/generated-resources" schemaName="sXMLCONFIG"/>
+ <replaceHolder srcDir="build/bootstrap/generated-sources" rscDir="build/bootstrap/generated-resources" schemaName="sXMLTOOLS"/>
+
+ <replace dir="build/bootstrap/generated-sources" token="schemaorg_apache_xmlbeans" value="org.apache.xmlbeans.metadata" includes="**/*.java"/>
+
+ <mkdir dir="build/classes"/>
+ <mkdir dir="build/generated-sources"/>
<javac destdir="build/classes" debug="true" debuglevel="lines,vars,source" includeantruntime="true">
<src refid="sources"/>
<src path="build/bootstrap/generated-sources"/>
+ <src path="src/typeholder"/>
<classpath>
<path refid="oldxbean"/>
<pathelement location="${saxon.jar}"/>
<pathelement location="${javaparser.core.jar}"/>
</classpath>
</javac>
+ <mkdir dir="build/generated-resources/org/apache/xmlbeans/impl/schema"/>
+
+ <!-- need to provide the template also in classes - generated-resources will be ignored on bootstrapping -->
+ <move file="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.class"
+ tofile="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template"/>
+
+ <copy file="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template"
+ todir="build/generated-resources/org/apache/xmlbeans/impl/schema"/>
<!-- now generate new xmlbeans re-/sources and remove the traces of the oldxbean generated re-/sources -->
<path id="oldschemas">
<pathelement location="build/classes"/>
<pathelement location="build/bootstrap/generated-resources"/>
- <dirset dir="resources" includes="*"/>
+ <dirset dir="resources" includes="*" excludes="maven"/>
</path>
<schemaCompProd classpathref="oldschemas" dest="build"/>
@@ -425,11 +467,11 @@
<target name="package" depends="compile,javadocs" description="Builds our jars in the build directory">
<jar jarfile="build/xmlbeans-${version.base}.jar" update="false" index="true">
- <fileset dir="build/classes"/>
+ <fileset dir="build/classes" excludes="org/apache/xmlbeans/impl/schema/TypeSystemHolder.template"/>
<fileset dir="." includes="LICENSE.txt,NOTICE.txt"/>
<fileset dir="build/generated-resources"/>
<mappedresources>
- <fileset dir="resources"/>
+ <fileset dir="resources" excludes="maven"/>
<cutdirsmapper dirs="1"/>
</mappedresources>
<manifest>
@@ -457,16 +499,24 @@
</manifest>
</jar>
- <jar jarfile="build/xmlbeans-${version.base}-sources.jar" update="false" index="false">
+ <chainedmapper id="src-mapper">
+ <cutdirsmapper dirs="1"/>
+ <firstmatchmapper>
+ <globmapper from="schema/*" to="org/apache/xmlbeans/src/*"/>
+ <identitymapper />
+ </firstmatchmapper>
+ </chainedmapper>
+
+ <jar jarfile="build/xmlbeans-${version.base}-sources.jar" update="false" index="false" duplicate="preserve">
<fileset dir="." includes="LICENSE.txt,NOTICE.txt"/>
<mappedresources>
<fileset dir="src" excludes="toolschema/**,shell/**"/>
- <cutdirsmapper dirs="1"/>
+ <mapper refid="src-mapper"/>
</mappedresources>
- <zipfileset dir="src/toolschema" prefix="schema"/>
+ <zipfileset dir="src/toolschema" prefix="org/apache/xmlbeans/src" excludes="**/*.xsd"/>
<mappedresources>
- <fileset dir="build" includes="generated-sources/**,generated-resources/**"/>
- <cutdirsmapper dirs="1"/>
+ <fileset dir="build" includes="generated-sources/**,generated-resources/**" excludes="**/*.xsb,**/*.class"/>
+ <mapper refid="src-mapper"/>
</mappedresources>
<manifest>
@@ -602,4 +652,30 @@
<target name="jenkins"
depends="test,package,rat-check"
description="Combines all targets that are executed in CI runs"/>
-</project>
+
+
+ <available property="maven.ant.tasks.present" classname="org.apache.maven.artifact.ant.Pom"/>
+ <target name="maven.ant.tasks-check">
+ <fail unless="maven.ant.tasks.present">
+ Maven ant tasks not found.
+ Please make sure the maven-ant-tasks jar is in ANT_HOME/lib, or made
+ available to Ant using other mechanisms like -lib or CLASSPATH.
+
+ You can download the Maven Ant Tasks from https://maven.apache.org/ant-tasks/download.html
+ </fail>
+ </target>
+
+ <target name="mvn-install" depends="maven.ant.tasks-check,package" description="Install XmlBeans artifacts into the local repository. Equivalent of 'mvn install'">
+ <copy file="${basedir}/resources/maven/pom.xml" todir="${basedir}/build" filtering="true">
+ <filterset>
+ <filter token="VERSION" value="${version.base}"/>
+ </filterset>
+ </copy>
+
+ <mvn:install file="${basedir}/build/xmlbeans-${version.base}.jar">
+ <pom file="${basedir}/build/pom.xml"/>
+ <attach file="${basedir}/build/xmlbeans-${version.base}-sources.jar" type="jar" classifier="sources"/>
+ <attach file="${basedir}/build/xmlbeans-${version.base}-javadoc.jar" type="jar" classifier="javadoc"/>
+ </mvn:install>
+ </target>
+</project>
\ No newline at end of file
diff --git a/resources/maven/pom.xml b/resources/maven/pom.xml
new file mode 100644
index 0000000..b2bd8cc
--- /dev/null
+++ b/resources/maven/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>xmlbeans</artifactId>
+ <version>@VERSION@</version>
+
+ <name>XmlBeans</name>
+ <description>XmlBeans main jar</description>
+ <url>https://xmlbeans.apache.org/</url>
+
+ <issueManagement>
+ <system>jira</system>
+ <url>https://issues.apache.org/jira/browse/XMLBEANS</url>
+ </issueManagement>
+
+ <mailingLists>
+ <mailingList>
+ <name>POI Users List</name>
+ <subscribe>user-subscribe@poi.apache.org</subscribe>
+ <unsubscribe>user-unsubscribe@poi.apache.org</unsubscribe>
+ <archive>http://mail-archives.apache.org/mod_mbox/poi-user/</archive>
+ </mailingList>
+ <mailingList>
+ <name>POI Developer List</name>
+ <subscribe>dev-subscribe@poi.apache.org</subscribe>
+ <unsubscribe>dev-unsubscribe@poi.apache.org</unsubscribe>
+ <archive>http://mail-archives.apache.org/mod_mbox/poi-dev/</archive>
+ </mailingList>
+ </mailingLists>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:svn:https://svn.apache.org/repos/asf/xmlbeans/</connection>
+ <developerConnection>scm:svn:https://${maven.username}@svn.apache.org/repos/asf/xmlbeans/</developerConnection>
+ <url>https://svn.apache.org/repos/asf/xmlbeans/</url>
+ </scm>
+
+ <organization>
+ <name>XmlBeans</name>
+ <url>https://xmlbeans.apache.org/</url>
+ </organization>
+
+ <developers>
+ <developer>
+ <name>Cezar Andrei</name>
+ <id>cezar</id>
+ <email>cezar.andrei@no#spam#!gma|l.com</email>
+ <organization></organization>
+ </developer>
+ <developer>
+ <name>Radu Preotiuc</name>
+ <id>radup</id>
+ <email>radupr@nos#pam.gm@il.com</email>
+ <organization></organization>
+ </developer>
+ <developer>
+ <name>Radu Preotiuc</name>
+ <id>radup</id>
+ <email>radu.preotiuc-pietro@nos#pam.bea.com</email>
+ <organization></organization>
+ </developer>
+ <developer>
+ <name>Wing Yew Poon</name>
+ <id>wpoon</id>
+ <email>wing-yew.poon@nos#pam.oracle.com</email>
+ <organization></organization>
+ </developer>
+ <developer>
+ <name>Jacob Danner</name>
+ <id>jdanner</id>
+ <email>jacob.danner@nos#pam.oracle.com</email>
+ <organization></organization>
+ </developer>
+ <developer>
+ <name>POI Team</name>
+ <id>poi</id>
+ <email>user@poi.apache.org</email>
+ <organization>Apache POI</organization>
+ </developer>
+ </developers>
+
+ <dependencies/>
+
+</project>
diff --git a/resources/typeimpl/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template b/resources/typeimpl/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template
deleted file mode 100644
index 89fe7c4..0000000
--- a/resources/typeimpl/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template
+++ /dev/null
Binary files differ
diff --git a/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java b/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
index 9b754e3..774484c 100644
--- a/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
+++ b/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
@@ -16,6 +16,7 @@
package org.apache.xmlbeans.impl.schema;
import org.apache.xmlbeans.SchemaTypeSystem;
+import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
/**
* This class is the hook which causes the SchemaTypeSystem to be loaded when
@@ -35,45 +36,15 @@
// !!! If you modify this class, you will have to run bootstrap.
// !!! If this scares you, turn back now !!!
//
-public class TypeSystemHolder
-{
- private TypeSystemHolder() { }
+public final class TypeSystemHolder extends SchemaTypeSystemImpl {
+ // TODO: provide parameter-less parent constructor
+ private TypeSystemHolder() { super(TypeSystemHolder.class); }
- public static final SchemaTypeSystem typeSystem = loadTypeSystem();
+ // the type system
+ public static final TypeSystemHolder typeSystem = new TypeSystemHolder();
// Commenting out this line has the effect of not loading all components in a
// typesystem upfront, but just as they are needed, which may improve
// performance significantly
//static { typeSystem.resolve(); }
-
- private static final SchemaTypeSystem loadTypeSystem()
- {
- try
- {
- // The fact that we are using TypeSystemHolder.class.getClassLoader()
- // to load the SchemaTypeSystem class means that the TypeSystemHolder's
- // classloader MUST be a descendant of the XmlBeans classloader, even
- // though it can be different.
- // In other words, each Schema type has only one copy per VM, not one
- // copy per copy of XmlBeans in use, therefore this implies that
- // there either must be one copy of XmlBeans in the VM or copies in
- // different classloaders will each need a different copy of one
- // Schema type, which seems a reasonable restriction, but needs to be
- // understood nevertheless
- return (SchemaTypeSystem)
- Class.forName(
- "org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl",
- true, TypeSystemHolder.class.getClassLoader())
- .getConstructor(new Class[] { Class.class })
- .newInstance(new java.lang.Object[] { TypeSystemHolder.class });
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException("Cannot load org.apache.xmlbeans.impl.SchemaTypeSystemImpl: make sure xbean.jar is on the classpath.", e);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Could not instantiate SchemaTypeSystemImpl (" + e.toString() + "): is the version of xbean.jar correct?", e);
- }
- }
}
diff --git a/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java b/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
index ef5ca91..70773c7 100644
--- a/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
+++ b/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
@@ -15,18 +15,12 @@
package org.apache.xmlbeans.impl.schema;
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaGlobalElement;
-import org.apache.xmlbeans.SchemaGlobalAttribute;
-import org.apache.xmlbeans.SchemaModelGroup;
-import org.apache.xmlbeans.SchemaAttributeGroup;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.SchemaIdentityConstraint;
-import org.apache.xmlbeans.ResourceLoader;
+import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.common.SystemCache;
import org.apache.xmlbeans.impl.common.QNameHelper;
import org.apache.xmlbeans.impl.common.XBeanDebug;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+
import javax.xml.namespace.QName;
import java.io.InputStream;
@@ -44,7 +38,7 @@
public class SchemaTypeLoaderImpl extends SchemaTypeLoaderBase {
private ResourceLoader _resourceLoader;
private ClassLoader _classLoader;
- private SchemaTypeLoader[] _searchPath;
+ private final SchemaTypeLoader[] _searchPath;
private Map _classpathTypeSystems;
private Map _classLoaderTypeSystems;
@@ -62,6 +56,12 @@
public static String METADATA_PACKAGE_LOAD = METADATA_PACKAGE_GEN;
private static final Object CACHED_NOT_FOUND = new Object();
+ private static final String[] basePackage = { "org.apache.xmlbeans.metadata", "schemaorg_apache_xmlbeans" };
+ private static final String[] baseSchemas = { "sXMLCONFIG", "sXMLLANG", "sXMLSCHEMA", "sXMLTOOLS" };
+
+
+
+
private static class SchemaTypeLoaderCache extends SystemCache
{
// The following maintains a cache of SchemaTypeLoaders per ClassLoader per Thread.
@@ -168,44 +168,30 @@
* @since XmlBeans 3.1.0
*/
public static SchemaTypeLoader build(final SchemaTypeLoader[] searchPath, ResourceLoader resourceLoader, ClassLoader classLoader, String metadataPath) {
- final SchemaTypeLoader[] sp;
+ // assemble a flattened search path with no duplicates
+ SubLoaderList list = new SubLoaderList();
- if (searchPath == null) {
- // if the metadata directory is customized, fallback to the xmlbeans typesystems
- final boolean isDefaultPath = (metadataPath == null || ("schema" + METADATA_PACKAGE_GEN).equals(metadataPath));
- if (isDefaultPath) {
- sp = null;
- } else {
- String[] baseHolder = {
- "schemaorg_apache_xmlbeans.system.sXMLCONFIG.TypeSystemHolder",
- "schemaorg_apache_xmlbeans.system.sXMLLANG.TypeSystemHolder",
- "schemaorg_apache_xmlbeans.system.sXMLSCHEMA.TypeSystemHolder",
- "schemaorg_apache_xmlbeans.system.sXMLTOOLS.TypeSystemHolder"
- };
+ list.add(searchPath);
- sp = new SchemaTypeLoader[baseHolder.length];
- for (int i=0; i<baseHolder.length; i++) {
- try {
- Class cls = Class.forName(baseHolder[i]);
- sp[i] = (SchemaTypeLoader)cls.getDeclaredField("typeSystem").get(null);
- } catch (Exception e) {
- System.out.println("throw runtime: "+e.toString());
- throw new RuntimeException(e);
- }
+ ClassLoader cl = (classLoader == null) ? SchemaDocument.class.getClassLoader() : classLoader;
+
+ for (String prefix : basePackage) {
+ for (String holder : baseSchemas) {
+ String clName = prefix + ".system." + holder + ".TypeSystemHolder";
+ if (cl.getResource(clName.replace(".","/")+".class") == null) {
+ // if the first class isn't found in the package, continue with the next package
+ break;
+ }
+ try {
+ Class cls = Class.forName(clName, true, cl);
+ list.add((SchemaTypeLoader)cls.getDeclaredField("typeSystem").get(null));
+ } catch (Exception e) {
+ throw new XmlRuntimeException(e);
}
}
- } else {
- // assemble a flattened search path with no duplicates
- SubLoaderList list = new SubLoaderList();
- list.add(searchPath);
- sp = list.toArray();
}
- if (sp != null && sp.length == 1 && resourceLoader == null && classLoader == null) {
- return sp[0];
- }
-
- return new SchemaTypeLoaderImpl(sp, resourceLoader, classLoader, metadataPath);
+ return new SchemaTypeLoaderImpl(list.toArray(), resourceLoader, classLoader, metadataPath);
}
/**
@@ -262,17 +248,26 @@
*/
private SchemaTypeLoaderImpl(SchemaTypeLoader[] searchPath, ResourceLoader resourceLoader, ClassLoader classLoader, String metadataPath)
{
- if (searchPath == null)
- _searchPath = EMPTY_SCHEMATYPELOADER_ARRAY;
- else
- _searchPath = searchPath;
+ _searchPath = (searchPath == null) ? EMPTY_SCHEMATYPELOADER_ARRAY : searchPath;
_resourceLoader = resourceLoader;
_classLoader = classLoader;
- this._metadataPath = (metadataPath == null) ? "schema" + METADATA_PACKAGE_LOAD : metadataPath;
+
+ if (metadataPath != null) {
+ this._metadataPath = metadataPath;
+ } else {
+ final String path26 = "schema" + METADATA_PACKAGE_LOAD.replace("/","_");
+ this._metadataPath = (isPath30(_classLoader)) ? METADATA_PACKAGE_LOAD : path26;
+ }
initCaches();
}
+ private static boolean isPath30(ClassLoader loader) {
+ final String path30 = METADATA_PACKAGE_LOAD + "/system";
+ final ClassLoader cl = (loader != null) ? loader : SchemaDocument.class.getClassLoader();
+ return cl.getResource(path30) != null;
+ }
+
/**
* Initializes the caches.
*/
diff --git a/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java b/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
index b1606ca..12c1b93 100644
--- a/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
+++ b/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
@@ -74,6 +74,8 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -136,11 +138,16 @@
static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
/**
+ * regex to identify the type system holder package namespace
+ */
+ private static final Pattern packPat = Pattern.compile("^(.+)(\\.[^.]+){2}$");
+
+ /**
* This is to support the feature of a separate/private XMLBeans
* distribution that will not colide with the public org apache
* xmlbeans one.
* METADATA_PACKAGE_GEN will be "" for the original and something like
- * com_mycompany_private_xmlbeans for a private distribution of XMLBeans.
+ * com.mycompany.private.xmlbeans for a private distribution of XMLBeans.
*
* There are two properties:
* METADATA_PACKAGE_GEN - used for generating metadata
@@ -149,17 +156,18 @@
* repackage process scomp needs to load from old package and generate into
* a new package.
*/
- public static String METADATA_PACKAGE_GEN;
- static
- {
- // fix for maven classloader
- Package stsPackage = SchemaTypeSystem.class.getPackage();
- String stsPackageName = (stsPackage==null) ?
- SchemaTypeSystem.class.getName().substring(0, SchemaTypeSystem.class.getName().lastIndexOf(".")) :
- stsPackage.getName();
-
- METADATA_PACKAGE_GEN = stsPackageName.replaceAll("\\.", "_");
- }
+ public static String METADATA_PACKAGE_GEN = "org/apache/xmlbeans/metadata";
+// public static String METADATA_PACKAGE_GEN;
+// static
+// {
+// // fix for maven classloader
+// Package stsPackage = SchemaTypeSystem.class.getPackage();
+// String stsPackageName = (stsPackage==null) ?
+// SchemaTypeSystem.class.getName().substring(0, SchemaTypeSystem.class.getName().lastIndexOf(".")) :
+// stsPackage.getName();
+//
+// METADATA_PACKAGE_GEN = stsPackageName.replace('.', '/') + "/metadata";
+// }
private static String nameToPathString(String nameForSystem)
{
@@ -171,8 +179,32 @@
return nameForSystem;
}
- public SchemaTypeSystemImpl(Class indexclass)
- {
+ protected SchemaTypeSystemImpl() {
+ String fullname = getClass().getName();
+ _name = fullname.substring(0, fullname.lastIndexOf('.'));
+ XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Loading type system " + _name, 1);
+ _basePackage = nameToPathString(_name);
+ _classloader = getClass().getClassLoader();
+ _linker = this;
+ _resourceLoader = new ClassLoaderResourceLoader(_classloader);
+ try
+ {
+ initFromHeader();
+ }
+ catch (RuntimeException e)
+ {
+ XBeanDebug.logException(e);
+ throw e;
+ }
+ catch (Error e)
+ {
+ XBeanDebug.logException(e);
+ throw e;
+ }
+ XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Finished loading type system " + _name, -1);
+ }
+
+ public SchemaTypeSystemImpl(Class indexclass) {
String fullname = indexclass.getName();
_name = fullname.substring(0, fullname.lastIndexOf('.'));
XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Loading type system " + _name, 1);
@@ -235,7 +267,7 @@
Class c = Class.forName(name + "." + SchemaTypeCodePrinter.INDEX_CLASSNAME, true, loader);
return (SchemaTypeSystemImpl)c.getField("typeSystem").get(null);
}
- catch (Exception e)
+ catch (Throwable e)
{
return null;
}
@@ -905,8 +937,7 @@
}
}
- public SchemaTypeSystemImpl(String nameForSystem)
- {
+ public SchemaTypeSystemImpl(String nameForSystem) {
// if we have no name, select a random one
if (nameForSystem == null)
{
@@ -916,10 +947,9 @@
nameForSystem = "s" + new String(HexBin.encode(bytes));
}
- _name = getMetadataPath().replace('/','.') + ".system." + nameForSystem;
+ _name = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN.replace('/','.') + ".system." + nameForSystem;
_basePackage = nameToPathString(_name);
_classloader = null;
- //System.out.println(" _base: " + _basePackage);
}
public void loadFromBuilder(SchemaGlobalElement[] globalElements,
@@ -976,10 +1006,10 @@
SchemaDependencies getDependencies()
{ return _deps; }
-
+
// EXPERIMENTAL
public boolean isIncomplete() { return _incomplete; }
-
+
// EXPERIMENTAL
void setIncomplete(boolean incomplete) { _incomplete = incomplete; }
@@ -1243,9 +1273,9 @@
}
- private String _name;
+ private final String _name;
private String _basePackage;
-
+
// EXPERIMENTAL: recovery from compilation errors and partial type systems
private boolean _incomplete = false;
@@ -3818,8 +3848,9 @@
*
* @since XmlBeans 3.1.0
*/
- protected String getMetadataPath() {
- return "schema" + METADATA_PACKAGE_GEN;
+ public String getMetadataPath() {
+ Matcher m = packPat.matcher(_name);
+ m.find();
+ return m.group(1).replace('.','/');
}
-
}
diff --git a/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java b/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
index b8837ea..504eb46 100644
--- a/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
+++ b/src/xmlcomp/org/apache/xmlbeans/impl/tool/Diff.java
@@ -99,14 +99,14 @@
{
ZipEntry ze = (ZipEntry) entries1.nextElement();
String name = ze.getName();
- if (name.startsWith("schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
+ if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
list1.add(ze);
}
for (; entries2.hasMoreElements(); )
{
ZipEntry ze = (ZipEntry) entries2.nextElement();
String name = ze.getName();
- if (name.startsWith("schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
+ if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
list2.add(ze);
}
ZipEntry[] files1 = (ZipEntry[]) list1.toArray(new ZipEntry[list1.size()]);
@@ -171,8 +171,8 @@
* Navigate three directories deep to get to the type system.
* Assume the schema[METADATA_PACKAGE_LOAD]/system/* structure
*/
- File temp1 = new File(dir1, "schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
- File temp2 = new File(dir2, "schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
+ File temp1 = new File(dir1, SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
+ File temp2 = new File(dir2, SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
if (temp1.exists() && temp2.exists())
{
File[] files1 = temp1.listFiles();
diff --git a/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java b/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
index 589de3a..4e10920 100644
--- a/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
+++ b/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
@@ -73,6 +73,7 @@
System.out.println(" -src [dir] - target directory for generated .java files");
System.out.println(" -srconly - do not compile .java files or jar the output.");
System.out.println(" -out [xmltypes.jar] - the name of the output jar");
+ System.out.println(" -name - the name of the schema type - defaults to autogenerated name");
System.out.println(" -dl - permit network downloads for imports and includes (default is off)");
System.out.println(" -noupa - do not enforce the unique particle attribution rule");
System.out.println(" -nopvr - do not enforce the particle valid (restriction) rule");
@@ -661,12 +662,12 @@
{
return compiler;
}
-
+
public void setCompiler(String compiler)
{
this.compiler = compiler;
}
-
+
public String getJavaSource()
{
return javasource;
@@ -1024,12 +1025,13 @@
{
SchemaTypeLoaderImpl.METADATA_PACKAGE_LOAD = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN;
- String stsPackage = SchemaTypeSystem.class.getPackage().getName();
Repackager repackager = new Repackager( repackage );
- SchemaTypeSystemImpl.METADATA_PACKAGE_GEN = repackager.repackage(new StringBuffer(stsPackage)).toString().replace('.','_');
+ StringBuffer sb = new StringBuffer(SchemaTypeLoaderImpl.METADATA_PACKAGE_LOAD);
+ sb = repackager.repackage(sb);
+ SchemaTypeSystemImpl.METADATA_PACKAGE_GEN = sb.toString();
- System.out.println("\n\n\n" + stsPackage + ".SchemaCompiler Metadata LOAD:" + SchemaTypeLoaderImpl.METADATA_PACKAGE_LOAD + " GEN:" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN);
+ System.out.println("SchemaCompiler Metadata LOAD:" + SchemaTypeLoaderImpl.METADATA_PACKAGE_LOAD + " GEN:" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN);
}
SchemaCodePrinter codePrinter = params.getSchemaCodePrinter();
@@ -1057,7 +1059,7 @@
boolean result = true;
- File schemasDir = IOUtil.createDir(classesDir, "schema" + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/src");
+ File schemasDir = IOUtil.createDir(classesDir, SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/src");
// build the in-memory type system
XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
diff --git a/src/xmlcomp/org/apache/xmlbeans/impl/tool/XMLBean.java b/src/xmlcomp/org/apache/xmlbeans/impl/tool/XMLBean.java
index 40a69c9..2c28290 100644
--- a/src/xmlcomp/org/apache/xmlbeans/impl/tool/XMLBean.java
+++ b/src/xmlcomp/org/apache/xmlbeans/impl/tool/XMLBean.java
@@ -84,7 +84,8 @@
memoryInitialSize,
memoryMaximumSize,
catalog,
- javasource;
+ javasource,
+ repackage;
private List extensions = new ArrayList();
@@ -238,6 +239,7 @@
params.setNoVDoc(novdoc);
params.setNoExt(noext);
params.setJavaSource(javasource);
+ params.setRepackage(repackage);
success = SchemaCompiler.compile(params);
if (success && !srconly) {
@@ -305,7 +307,7 @@
//interrupted means cancel
if (e instanceof InterruptedException || failonerror)
throw new BuildException(e);
-
+
log("Exception while building schemas: " + e.getMessage(), Project.MSG_ERR);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
@@ -824,6 +826,14 @@
this.catalog = catalog;
}
+ public String getRepackage() {
+ return repackage;
+ }
+
+ public void setRepackage(String repackage) {
+ this.repackage = repackage;
+ }
+
private static URI uriFromFile(File f)
{
if (f == null)
diff --git a/test/src/compile/scomp/checkin/CompilationTests.java b/test/src/compile/scomp/checkin/CompilationTests.java
index 20b3f41..b04cc9f 100644
--- a/test/src/compile/scomp/checkin/CompilationTests.java
+++ b/test/src/compile/scomp/checkin/CompilationTests.java
@@ -26,19 +26,21 @@
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
-import tools.util.TestRunUtil;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
public class CompilationTests {
@@ -195,14 +197,13 @@
}
@Test
- @Ignore
public void testSimple() throws Throwable {
deltree(xbeanOutput("compile/scomp/simple"));
// First, compile schema
// First, compile schema
- File inputfile1 = xbeanCase("../../simple/person.xsd");
- File inputfile2 = xbeanCase("../../simple/simplec.xsd");
+ File inputfile1 = xbeanCase("../../simple/person/person.xsd");
+ File inputfile2 = xbeanCase("../../simple/person/simplec.xsd");
File srcdir = xbeanOutput("simple/simpletypes/src");
@@ -217,16 +218,18 @@
assertTrue("Build failed", SchemaCompiler.compile(params));
// Then, compile java classes
- File javasrc = xbeanCase("simple/javasrc");
+ File javasrc = new File("test/src/scomp/simple");
File javaclasses = xbeanOutput("compile/scomp/simple/javaclasses");
javaclasses.mkdirs();
- List<File> testcp = Arrays.asList(CodeGenUtil.systemClasspath());
+ List<File> testcp = new ArrayList<File>(Arrays.asList(CodeGenUtil.systemClasspath()));
testcp.add(outputjar);
CodeGenUtil.externalCompile(Arrays.asList(javasrc), javaclasses, testcp.toArray(new File[0]), true);
// Then run the test
- testcp.add(javaclasses);
- TestRunUtil.run("SimplePersonTest", new File[]{outputjar, javaclasses});
+ URLClassLoader childcl = new URLClassLoader(new URL[]{outputjar.toURI().toURL()}, CompilationTests.class.getClassLoader());
+ Class<?> cl = childcl.loadClass("scomp.simple.SimplePersonTest");
+ Result result = JUnitCore.runClasses(cl);
+ assertEquals(0, result.getFailureCount());
}
@Test
@@ -269,7 +272,6 @@
}
@Test
- @Ignore
public void testPricequote() throws Throwable {
deltree(xbeanOutput("compile/scomp/pricequote"));
// First, compile schema
@@ -278,7 +280,7 @@
File outputjar = xbeanOutput("compile/scomp/pricequote/pricequote.jar");
SchemaCompiler.Parameters params = new SchemaCompiler.Parameters();
params.setXsdFiles(new File[]{
- xbeanCase("compile/scomp/pricequote/PriceQuote.xsd")});
+ xbeanCase("pricequote/PriceQuote.xsd")});
params.setSrcDir(srcdir);
params.setClassesDir(classesdir);
params.setOutputJar(outputjar);
@@ -363,7 +365,6 @@
};
@Test
- @Ignore
public void testFinal() throws Throwable {
SchemaDocument[] schemas = new SchemaDocument[invalidSchemas.length];
diff --git a/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java b/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java
index ab49f41..a82fd31 100644
--- a/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java
+++ b/test/src/compile/scomp/checkin/XmlBeansCompCheckinTests.java
@@ -37,16 +37,16 @@
final Vector expSrcType = new Vector();
public XmlBeansCompCheckinTests() {
- expBinType.add("schemaorg_apache_xmlbeans/system/apiCompile/atypedb57type.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/system/apiCompile/elname429edoctype.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/system/apiCompile/elnameelement.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/system/apiCompile/index.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/element/http_3A_2F_2Fbaz/elName.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/type/http_3A_2F_2Fbaz/aType.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/namespace/http_3A_2F_2Fbaz/xmlns.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/javaname/baz/ElNameDocument.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/javaname/baz/AType.xsb");
- expBinType.add("schemaorg_apache_xmlbeans/system/apiCompile/TypeSystemHolder.class");
+ expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/atypedb57type.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/elname429edoctype.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/elnameelement.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/index.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/element/http_3A_2F_2Fbaz/elName.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/type/http_3A_2F_2Fbaz/aType.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/namespace/http_3A_2F_2Fbaz/xmlns.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/javaname/baz/ElNameDocument.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/javaname/baz/AType.xsb");
+ expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/TypeSystemHolder.class");
expSrcType.add("baz.AType");
expSrcType.add("baz.impl.ATypeImpl");
diff --git a/test/src/compile/scomp/som/common/SomTestBase.java b/test/src/compile/scomp/som/common/SomTestBase.java
index 5658d18..e5de084 100644
--- a/test/src/compile/scomp/som/common/SomTestBase.java
+++ b/test/src/compile/scomp/som/common/SomTestBase.java
@@ -303,7 +303,7 @@
public boolean checkPSOMSave(SchemaTypeSystem tgtSTS)
{
- String outDirName = tgtSTS.getName().split("schemaorg_apache_xmlbeans.system.")[1];
+ String outDirName = tgtSTS.getName().split("org.apache.xmlbeans.metadata.system.")[1];
String outDirNameWithPath = somOutputRootDir + P + runid + P + outDirName;
// call the save
diff --git a/test/src/misc/detailed/JiraRegressionSchemaCompilerTest.java b/test/src/misc/detailed/JiraRegressionSchemaCompilerTest.java
index 62e15d5..1ccfef2 100644
--- a/test/src/misc/detailed/JiraRegressionSchemaCompilerTest.java
+++ b/test/src/misc/detailed/JiraRegressionSchemaCompilerTest.java
@@ -39,6 +39,7 @@
params.setErrorListener(errors);
params.setSrcDir(new File(schemaCompOutputDirPath + outputDirName + P + "src"));
params.setClassesDir(new File(schemaCompOutputDirPath + outputDirName + P + "classes"));
+ params.setQuiet(true);
SchemaCompiler.compile(params);
return errors;
}
diff --git a/test/src/schemas/defaults.xsd b/test/src/schemas/defaults.xsd
deleted file mode 100644
index 6de0224..0000000
--- a/test/src/schemas/defaults.xsd
+++ /dev/null
@@ -1,32 +0,0 @@
-<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:tns="http://openuri.org/def"
- targetNamespace="http://openuri.org/def"
- elementFormDefault="qualified">
-<!--
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- -->
- <xs:element name="defaults">
- <xs:complexType>
- <xs:sequence>
- </xs:sequence>
- <xs:attribute ref="tns:cool"/>
- </xs:complexType>
- </xs:element>
-
- <xs:attribute name="cool" type="xs:int" default="783"/>
-
-</xs:schema>
diff --git a/test/tools/src/tools/util/TestRunUtil.java b/test/tools/src/tools/util/TestRunUtil.java
deleted file mode 100755
index d4ef949..0000000
--- a/test/tools/src/tools/util/TestRunUtil.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tools.util;
-
-import java.io.File;
-import java.net.URLClassLoader;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-
-public class TestRunUtil
-{
- /**
- * Runs method that must be declared "static void test()" on the given
- * class, with the given additional jars or directories on the classpath.
- */
- public static void run(String classname, File[] classpath) throws Throwable
- {
- // System.err.println("Running " + classname + " with classpath:");
- for (int i = 0; i < classpath.length; i++)
- {
- // System.err.println(classpath[i]);
- if (!classpath[i].exists())
- throw new IllegalArgumentException("Classpath component " + classpath + " cannot be found!");
- }
-
- URL[] extracp = new URL[classpath.length];
- for (int i = 0; i < classpath.length; i++)
- {
- try
- {
- extracp[i] = classpath[i].toURL();
- }
- catch (MalformedURLException e)
- {
- throw new IllegalArgumentException("Malformed classpath filename");
- }
- }
-
- ClassLoader curcl = Thread.currentThread().getContextClassLoader();
-
- try
- {
- ClassLoader childcl = new URLClassLoader(extracp);
- Class javaClass = childcl.loadClass(classname);
- Class testClass = childcl.loadClass("org.openuri.mytest.CustomerDocument");
- if (testClass == null)
- throw new IllegalStateException();
- Method meth = javaClass.getMethod("test", new Class[0]); // should be static
- Thread.currentThread().setContextClassLoader(childcl);
- meth.invoke(null, new Object[0]);
- }
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("class not found");
- }
- catch (NoSuchMethodException e)
- {
- throw new IllegalArgumentException("no test() method found");
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("could not invoke static public test method");
- }
- catch (InvocationTargetException e)
- {
- throw e.getCause();
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(curcl);
- }
- }
-}