diff options
author | Yegor Kozlov <yegor@apache.org> | 2020-09-16 15:48:27 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2020-09-16 15:48:27 +0000 |
commit | 60dc4f42954b6cdf5e23a8c1ee0fb86632209e52 (patch) | |
tree | 6d5496c76482c8b79d8537ce4167adddf6ce9e97 | |
parent | 69ddd04bd8a27d498dcaa333c28cd9976c14074f (diff) | |
download | poi-60dc4f42954b6cdf5e23a8c1ee0fb86632209e52.tar.gz poi-60dc4f42954b6cdf5e23a8c1ee0fb86632209e52.zip |
Bug 57857 POI OSGi bundle
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1881771 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | maven/ooxml-schemas.pom | 2 | ||||
-rw-r--r-- | maven/poi-ooxml-schemas.pom | 2 | ||||
-rw-r--r-- | osgi/README.md | 58 | ||||
-rw-r--r-- | osgi/build.xml | 67 | ||||
-rw-r--r-- | osgi/bundle.info | 38 | ||||
-rw-r--r-- | osgi/pom.xml | 403 | ||||
-rw-r--r-- | osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java (renamed from osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java) | 59 | ||||
-rw-r--r-- | osgi/test-bundles.xml | 34 |
8 files changed, 310 insertions, 353 deletions
diff --git a/maven/ooxml-schemas.pom b/maven/ooxml-schemas.pom index ae4621e9a1..2a3116cdb4 100644 --- a/maven/ooxml-schemas.pom +++ b/maven/ooxml-schemas.pom @@ -64,7 +64,7 @@ <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> - <version>2.6.0</version> + <version>4.0.0</version> </dependency> </dependencies> </project> diff --git a/maven/poi-ooxml-schemas.pom b/maven/poi-ooxml-schemas.pom index 1aa4eb1024..7ae6765394 100644 --- a/maven/poi-ooxml-schemas.pom +++ b/maven/poi-ooxml-schemas.pom @@ -70,7 +70,7 @@ <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> - <version>3.1.0</version> + <version>4.0.0</version> </dependency> </dependencies> </project> diff --git a/osgi/README.md b/osgi/README.md new file mode 100644 index 0000000000..bca3ccfc6a --- /dev/null +++ b/osgi/README.md @@ -0,0 +1,58 @@ +# Apache POI OSGi Bundle + +The POI bundle is an Uber jar which exports all the POI classes, XML Beans, OOXML Schemas and required dependencies. The current size is around 21 MB. +The bundle is self-contained and can be used out of the box in a bare OSGi container. + +## Embedded Dependencies +The bundle embeds all the jars from lib/main: + +- SparseBitSet +- curvesapi +- commons-math3 +- commons-compress +- commons-collections4 +- commons-codec + +## Optional Dependencies + +1. Apache Batik +Required to render WMF/EMF images. The OSGi bundle is provided by ServiceMix and available in Maven Central: https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.batik/1.13_1 +2. Saxon +Required if using as the XSLT and XQuery Processor engine in XML Beans. +Available in Maven Central: https://mvnrepository.com/artifact/net.sf.saxon/saxon/8.9.0.4-osgi +3. Apache XML Security for Java, Bouncy Castle and XML Commons Resolver +These are required to sign or validate signed Office documents. The OSGi bundles are available in Maven Central: + + - Apache XML Security for Java: https://mvnrepository.com/artifact/org.apache.santuario/xmlsec/2.2.0 + + - XML Commons Resolver: https://mvnrepository.com/artifact/xml-resolver/xml-resolver/1.2-osgi + + - Bouncy Castle: https://mvnrepository.com/artifact/org.bouncycastle/bcprov-ext-jdk15on/1.66, https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on/1.66 + +## Blocked Imports + +The Bundle Maven Plugin performs a thorough inspection of the dependencies on external packages and by default includes them all in the <Import-Package> section. + +Transitive dependencies from XML Beans not required by POI: + + - !com.github.javaparser.*, + - !org.apache.tools.ant.* + +Optional codecs pulled by Commons-Compress. Not used by POI + + - !com.github.luben.zstd.*, + - !org.tukaani.xz.*, + - !org.brotli.dec.*, + +Internal APIs which are no more in JPMS + + - !sun.misc.* + +## Integration Testing + +The project tests the bundle using the Pax Exam framework which executes junit tests within an OSGi container started by Maven. The current version uses the Apache Felix driver but the framework should not matter, same tests will pass with the Karaf or Equinox drivers. + +When running integration tests Maven starts a bare Apache Felix OSGi container, deploys the POI bundle and runs a few simple tests to validate the code is working fine, e.g. create a spreadsheet, serialize it to a byte array and read back. + + + diff --git a/osgi/build.xml b/osgi/build.xml deleted file mode 100644 index 364d41bb5c..0000000000 --- a/osgi/build.xml +++ /dev/null @@ -1,67 +0,0 @@ -<?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. ---> - -<!-- POI OSGi Bundle System --> -<project name="POI OSGi Bundle" default="bundle" basedir=".."> - <description>The Apache POI OSGi Bundle System.</description> - - <property name="bundle.lib" location="osgi/lib"/> - - <!-- TODO Import these from the parent build file --> - <property name="repository.m2" value="https://repo1.maven.org"/> - <property name="version.id" value="5.0.0-SNAPSHOT"/> - <property name="dist.dir" value="build/dist"/> - - <!-- jars in the /lib directory, see the fetch-bundle-jars target--> - <property name="bundle.bnd.jar" location="${bundle.lib}/bnd-1.50.0.jar"/> - <property name="bundle.bnd.url" value="${repository.m2}/maven2/biz/aQute/bnd/1.50.0/bnd-1.50.0.jar"/> - <import file="../build.xml"/> - - <target name="check-bundle-jars"> - <condition property="jars.bundle.present"> - <available file="${bundle.bnd.jar}"/> - </condition> - </target> - - <target name="fetch-bundle-jars" unless="jars.bundle.present"> - <mkdir dir="${bundle.lib}"/> - <antcall target="downloadfile"> - <param name="sourcefile" value="${bundle.bnd.url}"/> - <param name="destfile" value="${bundle.bnd.jar}"/> - </antcall> - </target> - -<!-- - <target name="bundle" depends="init, check-bundle-jars, fetch-bundle-jars, jar"> ---> - <target name="bundle" depends="init, check-bundle-jars, fetch-bundle-jars"> - <taskdef resource="aQute/bnd/ant/taskdef.properties" classpath="${bundle.bnd.jar}"/> - <mkdir dir="build/osgi"/> - <bnd - classpath="${dist.dir}/poi-${version.id}-${DSTAMP}.jar,${dist.dir}/poi-scratchpad-${version.id}-${DSTAMP}.jar,${dist.dir}/poi-ooxml-${version.id}-${DSTAMP}.jar" - eclipse="false" - failok="false" - exceptions="true" - output="build/osgi" - files="test.bnd"/> - <!-- TODO Include the settings from http://svn.apache.org/repos/asf/servicemix/smx4/bundles/trunk/poi-3.9/pom.xml --> - <!-- TODO Make this actually spit out an OSGi Jar --> - </target> -</project> diff --git a/osgi/bundle.info b/osgi/bundle.info deleted file mode 100644 index bad445c3c1..0000000000 --- a/osgi/bundle.info +++ /dev/null @@ -1,38 +0,0 @@ -\u001B[1mSYNOPSIS\u001B[0m - ${project.description} - - Original Maven URLs: - \u001B[33mmvn:${pkgGroupId}/poi/${pkgVersion}\u001B[0m - \u001B[33mmvn:${pkgGroupId}/poi-ooxml/${pkgVersion}\u001B[0m - \u001B[33mmvn:${pkgGroupId}/poi-scratchpad/${pkgVersion}\u001B[0m - -\u001B[1mDESCRIPTION\u001B[0m - The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based - upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can - read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using - Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and - OLE2 formats and welcome others to participate. - - OLE2 files include most Microsoft Office files such as XLS, DOC, and PPT as well as MFC serialization API based file - formats. The project provides APIs for the OLE2 Filesystem (POIFS) and OLE2 Document Properties (HPSF). - - Office OpenXML Format is the new standards based XML file format found in Microsoft Office 2007 and 2008. This - includes XLSX, DOCX and PPTX. The project provides a low level API to support the Open Packaging Conventions using - openxml4j. - - For each MS Office application there exists a component module that attempts to provide a common high level Java api - to both OLE2 and OOXML document formats. This is most developed for Excel workbooks (SS=HSSF+XSSF). Work is - progressing for Word documents (HWPF+XWPF) and PowerPoint presentations (HSLF+XSLF). - - The project has recently added support for Outlook (HSMF). Microsoft opened the specifications to this format in - October 2007. We would welcome contributions. - - There are also projects for Visio (HDGF), TNEF (HMEF), and Publisher (HPBF). - - As a general policy we collaborate as much as possible with other projects to provide this functionality. - Examples include: Cocoon for which there are serializers for HSSF; Open Office.org with whom we collaborate in - documenting the XLS format; and Tika / Lucene, for which we provide format interpretors. - When practical, we donate components directly to those projects for POI-enabling them. - -\u001B[1mSEE ALSO\u001B[0m - \u001B[36mhttps://poi.apache.org/\u001B[0m diff --git a/osgi/pom.xml b/osgi/pom.xml index 01777f3c0f..ea41afa72a 100644 --- a/osgi/pom.xml +++ b/osgi/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="ISO-8859-1"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -8,7 +8,7 @@ "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 + 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 @@ -17,209 +17,214 @@ specific language governing permissions and limitations under the License. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.poi</groupId> + <artifactId>poi-bundle</artifactId> + <packaging>bundle</packaging> + <version>5.0.0-SNAPSHOT</version> - <parent> - <groupId>org.apache</groupId> - <artifactId>apache</artifactId> - <version>10</version> - <relativePath /> - </parent> + <name>Apache POI OSGi bundle</name> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <poi.version>5.0.0-SNAPSHOT</poi.version> + <pax.exam.version>4.12.0</pax.exam.version> + </properties> - <groupId>org.apache.poi</groupId> - <artifactId>poi-bundle</artifactId> - <packaging>bundle</packaging> - <name>Apache POI OSGi bundle</name> - <description> - OSGi bundle that contains Apache POI, and the dependencies. - </description> - <url>https://poi.apache.org/</url> - <version>${poi.version}</version> - - <properties> - <maven.compiler.source>1.6</maven.compiler.source> - <maven.compiler.target>1.6</maven.compiler.target> - <pax.exam.version>4.4.0</pax.exam.version> - </properties> - - <dependencies> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>poi</artifactId> - <version>${poi.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>poi-scratchpad</artifactId> - <version>${poi.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>poi-ooxml</artifactId> - <version>${poi.version}</version> - </dependency> - - <!-- Test dependencies --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13</version> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-junit4</artifactId> - <version>${pax.exam.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-container-native</artifactId> - <version>${pax.exam.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.framework</artifactId> - <version>4.6.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-link-assembly</artifactId> - <version>${pax.exam.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.ops4j.pax.url</groupId> - <artifactId>pax-url-aether</artifactId> - <version>2.3.0</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - <version>1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <version>5.0.0</version> - <scope>provided</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Activator> - org.apache.poi.osgi.Activator - </Bundle-Activator> - <Embed-Dependency> - poi;inline=true, - poi-scratchpad;inline=true, - poi-ooxml;inline=true, - poi-ooxml-schemas, - xmlbeans - </Embed-Dependency> - <Embed-Transitive>true</Embed-Transitive> - <Bundle-DocURL>${project.url}</Bundle-DocURL> - <Export-Package> - org.apache.poi.* - </Export-Package> - <Import-Package> - !org.junit, - *, - org.apache.xmlbeans.impl.xpath.saxon;resolution:=optional, - org.apache.xmlbeans.impl.xquery.saxon;resolution:=optional, - org.bouncycastle.cert;resolution:=optional, - org.bouncycastle.cert.ocsp;resolution:=optional, - org.bouncycastle.cms.bc;resolution:=optional, - org.bouncycastle.cert.jcajce;resolution:=optional, - org.bouncycastle.operator;resolution:=optional, - org.bouncycastle.operator.bc;resolution:=optional, - org.bouncycastle.tsp;resolution:=optional, - org.openxmlformats.schemas.officeDocument.x2006.math;resolution:=optional, - org.openxmlformats.schemas.schemaLibrary.x2006.main;resolution:=optional, - schemasMicrosoftComOfficePowerpoint;resolution:=optional, - schemasMicrosoftComOfficeWord;resolution:=optional, - </Import-Package> - </instructions> - </configuration> - </plugin> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.2</version> - <configuration> - <source>${maven.compiler.source}</source> - <target>${maven.compiler.target}</target> - </configuration> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>java6</id> - <activation> - <jdk>[1.6,)</jdk> - </activation> - <build> + <build> <plugins> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <phase>pre-integration-test</phase> - <goals> - <goal>single</goal> - </goals> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>4.2.1</version> + <extensions>true</extensions> <configuration> - <descriptor>test-bundles.xml</descriptor> - <finalName>test</finalName> - <attach>false</attach> + <instructions> + <Export-Package> + org.apache.poi.*, + org.openxmlformats.schemas.*, + com.microsoft.schemas.*, + org.w3.x2000.x09.xmldsig.*, + org.etsi.uri.x01903.v13.*, + org.apache.xmlbeans.*, + org.apache.commons.compress.*, + com.zaxxer.sparsebits.*, + com.graphbuilder.* + </Export-Package> + <Import-Package> + !org.apache.poi.*, + !org.openxmlformats.schemas.*, + !com.microsoft.schemas.*, + !org.w3.x2000.x09.xmldsig.*, + !org.etsi.uri.x01903.*, + !org.apache.xmlbeans.*, + !org.apache.commons.compress.*, + !com.zaxxer.sparsebits.*, + !com.graphbuilder.*, + org.apache.batik.*;resolution:=optional, + net.sf.saxon.*;resolution:=optional, + !com.github.javaparser.*, + !org.apache.tools.ant.*, + !sun.misc.*, + org.apache.jcp.xml.dsig.internal.dom;resolution:=optional, + org.apache.xml.resolver.*;resolution:=optional, + org.apache.xml.security.*;resolution:=optional, + org.bouncycastle.*;resolution:=optional, + !com.github.luben.zstd.*, + !org.tukaani.xz.*, + !org.brotli.dec.*, + * + </Import-Package> + <Embed-Dependency> + poi;inline=true, + poi-scratchpad;inline=true, + poi-ooxml;inline=true, + poi-ooxml-schemas;inline=true, + xmlbeans;inline=true, + SparseBitSet, + curvesapi, + commons-math3, + commons-compress, + commons-collections4, + commons-codec + </Embed-Dependency> + <Embed-Directory>lib</Embed-Directory> + <Embed-Transitive>true</Embed-Transitive> + </instructions> </configuration> - </execution> - </executions> - </plugin> - <plugin> - <artifactId>maven-failsafe-plugin</artifactId> - <version>2.10</version> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - <configuration> - <systemPropertyVariables> - <org.ops4j.pax.logging.DefaultServiceLog.level> - WARN - </org.ops4j.pax.logging.DefaultServiceLog.level> - </systemPropertyVariables> - </configuration> - </plugin> + </plugin> + <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.22.1</version> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + <configuration> + <systemProperties> + <property> + <name>bundle.filename</name> + <value>${basedir}/target/${project.build.finalName}.jar</value> + </property> + </systemProperties> + </configuration> + </plugin> </plugins> - </build> - </profile> - </profiles> + </build> + <dependencies> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>${poi.version}</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml</artifactId> + <version>${poi.version}</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-scratchpad</artifactId> + <version>${poi.version}</version> + </dependency> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi-ooxml-schemas</artifactId> + <version>${poi.version}</version> + </dependency> + + <!-- Pax Exam Testing --> - <organization> - <name>The Apache Software Founation</name> - <url>http://www.apache.org</url> - </organization> - <scm> - <url>https://svn.apache.org/viewvc/poi/trunk/osgi</url> - <connection>scm:svn:https://svn.apache.org/repos/asf/poi/trunk/osgi</connection> - <developerConnection>scm:svn:https://svn.apache.org/repos/asf/poi/trunk/osgi</developerConnection> - </scm> + <!-- an OSGi framework --> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>4.3.1</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>6.0.3</version> + <scope>test</scope> + </dependency> + + <!-- JUnit --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + <version>4.12</version> + </dependency> + + <!-- Pax Exam --> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam</artifactId> + <version>${pax.exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + <version>${pax.exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-cm</artifactId> + <version>${pax.exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-forked</artifactId> + <version>${pax.exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.url</groupId> + <artifactId>pax-url-link</artifactId> + <scope>test</scope> + <version>2.5.2</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.url</groupId> + <artifactId>pax-url-classpath</artifactId> + <scope>test</scope> + <version>2.5.2</version> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-link-assembly</artifactId> + <version>${pax.exam.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.25</version> + <scope>test</scope> + </dependency> + </dependencies> </project> + diff --git a/osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java index 738d96b994..ea139e7e50 100644 --- a/osgi/src/test/java/org/apache/poi/osgi/TestOSGiBundle.java +++ b/osgi/src/test/java/org/apache/poi/osgi/OSGiSpreadsheetIT.java @@ -28,11 +28,15 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; -import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Configuration; @@ -40,9 +44,9 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerMethod; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Test to ensure that all our main formats can create, write @@ -50,35 +54,64 @@ import org.osgi.framework.ServiceReference; */ @RunWith(PaxExam.class) @ExamReactorStrategy(PerMethod.class) -public class TestOSGiBundle { +public class OSGiSpreadsheetIT { + private final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final File TARGET = new File("target"); + public static final String POI_BUNDLE_SYMBOLIC_NAME = "org.apache.poi.bundle"; @Inject private BundleContext bc; @Configuration - public Option[] configuration() throws IOException, URISyntaxException { - File base = new File(TARGET, "test-bundles"); + public Option[] configuration() throws IOException { + String bundlePath = System.getProperty("bundle.filename"); return options( junitBundles(), - bundle(new File(base, "poi-bundle.jar").toURI().toURL().toString())); + bundle(new File(bundlePath).toURI().toURL().toString())); } @Test - public void testHSSF() throws Exception { - HSSFWorkbook wb = new HSSFWorkbook(); - HSSFSheet s = wb.createSheet("OSGi"); + public void testBundleLoaded() { + boolean hasBundle = Arrays.stream(bc.getBundles()).anyMatch(b -> + POI_BUNDLE_SYMBOLIC_NAME.equals(b.getSymbolicName())); + assertTrue(POI_BUNDLE_SYMBOLIC_NAME + " not found", hasBundle); + } + + // create a workbook, validate and write back + void testWorkbook(Workbook wb) throws Exception { + logger.info("testing " + wb.getClass().getSimpleName()); + + Sheet s = wb.createSheet("OSGi"); s.createRow(0).createCell(0).setCellValue("With OSGi"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); wb.write(baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - wb = new HSSFWorkbook(bais); + if(wb instanceof HSSFWorkbook) + wb = new HSSFWorkbook(bais); + else + wb = new XSSFWorkbook(bais); assertEquals(1, wb.getNumberOfSheets()); s = wb.getSheet("OSGi"); assertEquals("With OSGi", s.getRow(0).getCell(0).toString()); + + + } + + @Test + public void testHSSF() throws Exception { + testWorkbook(new HSSFWorkbook()); + } + + @Test + public void testXSSF() throws Exception { + testWorkbook(new XSSFWorkbook()); + } + + @Test + public void testSXSSF() throws Exception { + testWorkbook(new SXSSFWorkbook()); } } diff --git a/osgi/test-bundles.xml b/osgi/test-bundles.xml deleted file mode 100644 index 11502761e6..0000000000 --- a/osgi/test-bundles.xml +++ /dev/null @@ -1,34 +0,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. - --> -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> - <id>bundles</id> - <formats> - <format>dir</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <dependencySets> - <dependencySet> - <outputDirectory/> - <outputFileNameMapping>${artifact.artifactId}.jar</outputFileNameMapping> - <includes> - <include>org.apache.poi:poi-bundle</include> - </includes> - </dependencySet> - </dependencySets> -</assembly> |