Skip to content

Commit

Permalink
#58617 - Add custom safe XmlBeans type loader / rename vendor specifi…
Browse files Browse the repository at this point in the history
…c schema packages

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715555 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kiwiwings committed Nov 21, 2015
1 parent 7458fdc commit 47b5cde
Show file tree
Hide file tree
Showing 66 changed files with 791 additions and 672 deletions.
1 change: 1 addition & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.sonar.ide.eclipse.core.sonarNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
167 changes: 100 additions & 67 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ under the License.
<property name="ooxml.xsds.url.1"
value="http://www.ecma-international.org/publications/files/ECMA-ST/Office%20Open%20XML%201st%20edition%20Part%204%20(PDF).zip"/>
<property name="ooxml.xsds.src.dir" location="build/ooxml-xsds-src"/>
<property name="ooxml.xsds.src.jar" location="${ooxml.lib}/ooxml-schemas-1.2-sources.jar"/>
<property name="ooxml.xsds.jar" location="${ooxml.lib}/ooxml-schemas-1.2.jar"/>
<property name="ooxml.xsds.src.jar" location="${ooxml.lib}/ooxml-schemas-1.3-sources.jar"/>
<property name="ooxml.xsds.jar" location="${ooxml.lib}/ooxml-schemas-1.3.jar"/>

<!-- additional schemas are packed into the poi schemas jar, -->
<!-- so we don't have to care about a seperate versioning of the original ooxml schemas -->
Expand All @@ -226,6 +226,8 @@ under the License.
<property name="ooxml.security.jar" location="${ooxml.lib}/ooxml-security-1.0.jar"/>
<property name="ooxml.security.xsd.dir" location="src/ooxml/resources/org/apache/poi/poifs/crypt"/>
<property name="ooxml.visio.xsd.dir" location="src/ooxml/resources/org/apache/poi/xdgf"/>
<property name="ooxml.schema.xsdconfig.dir" location="src/ooxml/resources/org/apache/poi/schemas"/>


<property name="maven.ooxml.xsds.version.id" value="1.0"/>
<property name="maven.ooxml.xsds.jar" value="ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
Expand Down Expand Up @@ -657,77 +659,108 @@ under the License.
</or>
</condition>
</target>

<macrodef name="compile-ooxml-xmlbean">
<attribute name="classes-jar"/>
<attribute name="sources-jar"/>
<attribute name="noupa" default="false"/>
<attribute name="nopvr" default="false"/>
<element name="xsds"/>
<sequential>
<!-- We need a fair amount of memory to compile the xml schema, -->
<!-- but limit it in case it goes wrong! -->
<!-- Pick the right amount based on 32 vs 64 bit jvm -->
<condition property="ooxml.memory" value="768m" else="512m">
<equals arg1="${sun.arch.data.model}" arg2="64" />
</condition>

<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpath="${ooxml.xmlbeans23.jar}"/>

<property name="xmlbean.xsds.dir" location="build/xmlbean-xsds"/>
<property name="xmlbean.sources.dir" location="build/xmlbean-sources"/>
<property name="xmlbean.classes.dir" location="build/xmlbean-classes"/>
<delete dir="${xmlbean.xsds.dir}"/>
<mkdir dir="${xmlbean.xsds.dir}"/>
<delete dir="${xmlbean.sources.dir}"/>
<mkdir dir="${xmlbean.sources.dir}"/>
<delete dir="${xmlbean.classes.dir}"/>
<mkdir dir="${xmlbean.classes.dir}"/>

<copy todir="${xmlbean.xsds.dir}">
<xsds/>
</copy>

<!-- javasource > 1.5 will not generate all array accessor -->
<xmlbean
schema="${xmlbean.xsds.dir}"
srcgendir="${xmlbean.sources.dir}"
classgendir="${xmlbean.classes.dir}"
destfile="${xmlbean.xsds.dir}.jar"
srconly="true"
javasource="1.5"
failonerror="true"
fork="true"
memoryMaximumSize="${ooxml.memory}"
noupa="@{noupa}"
nopvr="@{nopvr}"
>
<classpath refid="ooxml.classpath"/>
</xmlbean>

<replace dir="${xmlbean.sources.dir}" includes="**/*.java" excludes="**/impl/**">
<replacetoken>org.apache.xmlbeans.XmlBeans.getContextTypeLoader()</replacetoken>
<replacevalue>org.apache.poi.POIXMLTypeLoader</replacevalue>
</replace>

<copy todir="${xmlbean.sources.dir}">
<fileset dir="src/ooxml/java" includes="org/apache/poi/POIXMLTypeLoader.java"/>
</copy>

<javac target="${jdk.version.class}"
source="${jdk.version.source}"
srcdir="${xmlbean.sources.dir}"
destdir="${xmlbean.classes.dir}"
encoding="${java.source.encoding}"
fork="yes"
optimize="true"
memoryMaximumSize="${ooxml.memory}"
includeantruntime="false">
<!-- debug="${compile.debug}" -->
<classpath refid="ooxml.classpath"/>
</javac>

<jar basedir="${xmlbean.classes.dir}" destfile="@{classes-jar}" excludes="org/apache/**" level="9" />
<jar basedir="${xmlbean.sources.dir}" destfile="@{sources-jar}" excludes="org/apache/**" level="9" />

<delete file="${xmlbean.xsds.dir}.jar"/>
<delete dir="${xmlbean.xsds.dir}"/>
<delete dir="${xmlbean.sources.dir}"/>
<delete dir="${xmlbean.classes.dir}"/>
</sequential>
</macrodef>

<target name="compile-ooxml-xsds" unless="ooxml-compiled-xsds.present"
depends="init,check-compiled-ooxml-xsds"
description="Unpacks the OOXML xsd files, and compiles them into XmlBeans">
<taskdef name="xmlbean"
classname="org.apache.xmlbeans.impl.tool.XMLBean"
classpath="${ooxml.xmlbeans23.jar}"/>

<!-- We need a fair amount of memory to compile the xml schema, -->
<!-- but limit it in case it goes wrong! -->
<!-- Pick the right amount based on 32 vs 64 bit jvm -->
<condition property="ooxml.memory" value="768m" else="512m">
<equals arg1="${sun.arch.data.model}" arg2="64" />
</condition>

<property name="ooxml.xsds.tmp.dir" location="build/ooxml-xsds"/>
<mkdir dir="${ooxml.xsds.tmp.dir}"/>
<unzip src="${ooxml.lib}/${ooxml.xsds.izip.1}" dest="${ooxml.xsds.tmp.dir}"/>
<copy todir="${ooxml.xsds.tmp.dir}">
<fileset dir="${ooxml.visio.xsd.dir}"/>
</copy>
<xmlbean
schema="${ooxml.xsds.tmp.dir}"
srcgendir="${ooxml.xsds.src.dir}"
optimize="yes"
destfile="${ooxml.xsds.jar}"
javasource="1.5"
failonerror="true"
fork="true"
memoryMaximumSize="${ooxml.memory}"
>
<classpath refid="ooxml.classpath"/>
</xmlbean>

<!-- Now make a jar of the schema sources -->
<jar
basedir="${ooxml.xsds.src.dir}"
destfile="${ooxml.xsds.src.jar}"
/>

<compile-ooxml-xmlbean classes-jar="${ooxml.xsds.jar}" sources-jar="${ooxml.xsds.src.jar}">
<xsds>
<zipfileset src="${ooxml.lib}/${ooxml.xsds.izip.1}"/>
<fileset dir="${ooxml.visio.xsd.dir}"/>
<fileset dir="${ooxml.schema.xsdconfig.dir}"/>
</xsds>
</compile-ooxml-xmlbean>
<!-- Now do the same for the security schemas -->
<property name="ooxml.enc.xsds.tmp.dir" location="build/ooxml-security-xsds"/>
<mkdir dir="${ooxml.enc.xsds.tmp.dir}"/>
<unzip src="${ooxml.lib}/${ooxml.xsds.izip.2}" dest="${ooxml.enc.xsds.tmp.dir}"/>

<copy todir="${ooxml.enc.xsds.tmp.dir}">
<fileset dir="${ooxml.lib}" includes="dc*.xsd,xmldsig*.xsd,XAdES*.xsd"/>
<fileset dir="${ooxml.security.xsd.dir}"/>
</copy>

<!-- noupa/nopvr is set because of the dublincore schemas -->
<!-- https://issues.apache.org/jira/browse/XMLBEANS-340 -->
<!-- javasource > 1.5 will not generate all array accessor -->
<xmlbean
schema="${ooxml.enc.xsds.tmp.dir}"
srcgendir="${ooxml.security.src.dir}"
optimize="yes"
destfile="${ooxml.security.jar}"
javasource="1.5"
failonerror="true"
fork="true"
memoryMaximumSize="${ooxml.memory}"
noupa="true"
nopvr="true"
>
<classpath refid="ooxml.classpath"/>
</xmlbean>

<jar
basedir="${ooxml.security.src.dir}"
destfile="${ooxml.security.src.jar}"
/>
<compile-ooxml-xmlbean classes-jar="${ooxml.security.jar}" sources-jar="${ooxml.security.src.jar}" noupa="true" nopvr="true">
<xsds>
<zipfileset src="${ooxml.lib}/${ooxml.xsds.izip.2}"/>
<fileset dir="${ooxml.lib}" includes="dc*.xsd,xmldsig*.xsd,XAdES*.xsd"/>
<fileset dir="${ooxml.security.xsd.dir}"/>
</xsds>
</compile-ooxml-xmlbean>
</target>

<target name="compile" depends="init, compile-main,
Expand Down
30 changes: 14 additions & 16 deletions sonar/ooxml-schema-encryption/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.14-beta1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>poi-ooxml-schema-encryption</artifactId>
<packaging>jar</packaging>

<name>Apach POI - Openxmlformats Encryption Schema package</name>
<name>Apache POI - Openxmlformats Encryption Schema package</name>

<properties>
<!-- see http://docs.codehaus.org/display/SONAR/Narrowing+the+Focus for details of this property -->
Expand All @@ -21,28 +22,25 @@
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>unzip-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="target/schemas">
<fileset dir="../../src/ooxml/resources/org/apache/poi/poifs/crypt" includes="encryption*.*"/>
</copy>
</target>
</configuration>
</execution>
</executions>
<configuration>
<schemaDirectory>../../src/ooxml/resources/org/apache/poi/poifs/crypt</schemaDirectory>
<sourceSchemas>
<sourceSchema>encryptionInfo.xsd</sourceSchema>
</sourceSchemas>
<xmlConfigs>
<xmlConfig implementation="java.io.File">../../src/ooxml/resources/org/apache/poi/poifs/crypt/encryptionInfo.xsdconfig</xmlConfig>
</xmlConfigs>
<javaSource>1.5</javaSource>
<optimize>yes</optimize>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
33 changes: 7 additions & 26 deletions sonar/ooxml-schema-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.14-beta1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>poi-ooxml-schema-security</artifactId>
<packaging>jar</packaging>

<name>Apach POI - Openxmlformats Security-Schema package</name>
<name>Apache POI - Openxmlformats Security-Schema package</name>

<properties>
<!-- see http://docs.codehaus.org/display/SONAR/Narrowing+the+Focus for details of this property -->
<sonar.exclusions>target/generated-sources/*</sonar.exclusions>
<maven.compiler.fork>true</maven.compiler.fork>
<xmlbeans.noUpa>true</xmlbeans.noUpa>
<xmlbeans.noPvr>true</xmlbeans.noPvr>
</properties>

<build>
<plugins>
<!-- Download and unpack the OfficeOpenXML Schema and use xmlbeans to create classes from the XSDs -->
Expand Down Expand Up @@ -104,6 +106,9 @@
<execution>
<id>unzip-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="unzip schemas" />
Expand All @@ -112,34 +117,10 @@
todir="target/schemas"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>target/schemas</schemaDirectory>
<noUpa>true</noUpa>
<noPvr>true</noPvr>
<noJavac>true</noJavac>
<javaSource>1.5</javaSource>
<optimize>yes</optimize>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Loading

0 comments on commit 47b5cde

Please sign in to comment.