close fileinputstream on second exception in ZipPackage

build.xml fix - maven artifacts aren't included in src-package

git-svn-id: https://svn.apache.org/repos/asf/poi/tags/REL_3_15_BETA1@1738389 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-04-09 21:44:49 +00:00
parent 43a46caef2
commit 10371649cb
3 changed files with 197 additions and 123 deletions

190
build.xml
View File

@ -42,6 +42,7 @@ under the License.
<description>The Apache POI project Ant build.</description>
<property name="version.id" value="3.15-beta1"/>
<property name="release.rc" value="RC1"/>
<property environment="env"/>
<!-- the repository to download jars from -->
@ -1636,19 +1637,47 @@ under the License.
</target>
<target name="assemble" depends="jar,jar-src,jar-javadocs">
<property name="zipdir" value="${jar.name}-${version.id}"/>
<mappedresources id="legal-files" cache="true">
<fileset dir="legal"/>
<globmapper from="*" to="${zipdir}/*"/>
</mappedresources>
<!-- jars to include in binary assemblies -->
<patternset id="bin.dist.jars">
<include name="${jar.name}-${version.id}-${DSTAMP}.jar"/>
<include name="${jar.name}-scratchpad-${version.id}-${DSTAMP}.jar"/>
<include name="${jar.name}-ooxml-${version.id}-${DSTAMP}.jar"/>
<include name="${jar.name}-examples-${version.id}-${DSTAMP}.jar"/>
<include name="${jar.name}-ooxml-schemas-${version.id}-${DSTAMP}.jar"/>
<include name="${jar.name}-excelant-${version.id}-${DSTAMP}.jar"/>
</patternset>
<union id="bin-files" cache="true">
<mappedresources refid="legal-files"/>
<mappedresources cache="true">
<fileset dir="${main.lib}">
<include name="commons-codec-*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="junit-*.jar"/>
<include name="log4j-*.jar"/>
</fileset>
<globmapper from="*" to="${zipdir}/lib/*"/>
</mappedresources>
<mappedresources cache="true">
<fileset dir="${ooxml.lib}" includes="xmlbeans-2.6.0.jar.orig,curvesapi-*.jar"/>
<regexpmapper from="^(.*\.jar)(\.orig)?$$" to="${zipdir}/ooxml-lib/\1"/>
</mappedresources>
<mappedresources cache="true">
<fileset dir="${dist.dir}/maven" includes="**/*.jar" excludes="**/*-javadoc.jar,**/*-sources.jar"/>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="${zipdir}/*"/>
</chainedmapper>
</mappedresources>
<mappedresources cache="true">
<fileset dir="${build.site}"/>
<globmapper from="*" to="${zipdir}/docs/*"/>
</mappedresources>
</union>
<!-- patterns to exclude from source assemblies -->
<patternset id="src.dist.patterns"
excludes="build/**,
<union id="src-files" cache="true">
<mappedresources refid="legal-files"/>
<mappedresources cache="true">
<fileset dir="." excludes="build/**,
dist*/**,
maven/**,
lib/**,
@ -1666,71 +1695,31 @@ under the License.
.classpath,
.settings/**,
.project"/>
<property name="zipdir" value="${jar.name}-${version.id}"/>
<globmapper from="*" to="${zipdir}/*"/>
</mappedresources>
</union>
<zip destfile="${dist.dir}/${jar.name}-bin-${version.id}-${DSTAMP}.zip">
<zipfileset dir="legal/" prefix="${zipdir}"/>
<zipfileset dir="${main.lib}" prefix="${zipdir}/lib">
<include name="commons-codec-*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="junit-*.jar"/>
<include name="log4j-*.jar"/>
</zipfileset>
<zipfileset dir="${ooxml.lib}" prefix="${zipdir}/ooxml-lib">
<include name="xmlbeans-2.6*.jar"/>
<include name="curvesapi-*.jar"/>
</zipfileset>
<zipfileset dir="${dist.dir}" prefix="${zipdir}">
<patternset refid="bin.dist.jars"/>
</zipfileset>
<zipfileset dir="${build.site}" prefix="${zipdir}/docs"/>
<union refid="bin-files"/>
</zip>
<tar destfile="${dist.dir}/${jar.name}-bin-${version.id}-${DSTAMP}.tar.gz" longfile="gnu" compression="gzip">
<union refid="bin-files"/>
</tar>
<zip destfile="${dist.dir}/${jar.name}-src-${version.id}-${DSTAMP}.zip">
<zipfileset dir="legal/" prefix="${zipdir}" />
<zipfileset dir="." prefix="${zipdir}">
<patternset refid="src.dist.patterns"/>
</zipfileset>
<union refid="src-files"/>
</zip>
<tar destfile="${dist.dir}/${jar.name}-bin-${version.id}-${DSTAMP}.tar.gz"
longfile="gnu"
compression="gzip">
<tarfileset dir="legal/" prefix="${zipdir}"/>
<zipfileset dir="${main.lib}" prefix="${zipdir}/lib">
<include name="commons-codec-*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="junit-*.jar"/>
<include name="log4j-*.jar"/>
</zipfileset>
<tarfileset dir="${ooxml.lib}" prefix="${zipdir}/ooxml-lib">
<include name="xmlbeans-2.6*.jar"/>
<include name="curvesapi-*.jar"/>
</tarfileset>
<tarfileset dir="${build.site}" prefix="${zipdir}/docs"/>
<tarfileset dir="${dist.dir}" prefix="${zipdir}">
<patternset refid="bin.dist.jars"/>
</tarfileset>
<tar destfile="${dist.dir}/${jar.name}-src-${version.id}-${DSTAMP}.tar.gz" longfile="gnu" compression="gzip">
<union refid="src-files"/>
</tar>
<tar destfile="${dist.dir}/${jar.name}-src-${version.id}-${DSTAMP}.tar.gz"
longfile="gnu"
compression="gzip">
<tarfileset dir="legal/" prefix="${zipdir}" />
<tarfileset dir="." prefix="${zipdir}">
<patternset refid="src.dist.patterns"/>
</tarfileset>
</tar>
<!-- script to create signatures and hashes -->
<copy file="maven/multisign.sh" todir="${dist.dir}"/>
<echo>Creating Maven POMs</echo>
<antcall target="maven-poms"/>
<echo>Distribution located in ${dist.dir}</echo>
<echo>Use ${dist.dir}/multisign.sh to create md5 checksums and GPG signatures</echo>
<echo>Use "ant dist-checksum" to create md5/sha1 checksums and GPG signatures</echo>
</target>
<target name="osgi" depends="mvn-install">
@ -2025,8 +2014,33 @@ under the License.
<nexus-upload artifactId="poi-scratchpad"/>
</target>
<!-- experimentel release preparation ... tbd. ... -->
<target name="release-prep" depends="init,fetch-svn-jars,load-maven-server-settings">
<target name="-init-svn" depends="init,fetch-svn-jars,load-maven-server-settings">
<!-- JAVA_HOME needs to point to a JRE/JDK7+, otherwise the svn/https connection throws a "Could not generate DH keypair"-->
<fail message="Environment needs to point to a java 7+">
<condition>
<or>
<equals arg1="${ant.java.version}" arg2="1.6"/>
<equals arg1="${ant.java.version}" arg2="1.5"/>
</or>
</condition>
</fail>
<path id="path.svnant">
<fileset dir="${compile.lib}/svnant" includes="*.jar"/>
</path>
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="path.svnant"/>
<svnSetting
svnkit="true"
javahl="false"
username="${settings.apache-id.username}"
password="${settings.apache-id.password}"
id="svn.settings"
/>
</target>
<!-- experimental release preparation ... tbd. ... -->
<target name="release-prep1" depends="-init-svn" description="update the documentation and create the svn tag - needs Java7+">
<local name="tstamp_rel"/>
<local name="tstamp_next"/>
<local name="rel_next"/>
@ -2057,19 +2071,6 @@ under the License.
<fixcrlf srcdir="." includes="src/documentation/content/xdocs/status.xml" eol="unix" eof="remove" />
<path id="path.svnant">
<fileset dir="${compile.lib}/svnant" includes="*.jar"/>
</path>
<taskdef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="path.svnant"/>
<svnSetting
svnkit="true"
javahl="false"
username="${settings.apache-id.username}"
password="${settings.apache-id.password}"
id="svn.settings"
/>
<!-- can't combine updating and pinning of the documentation ... so we need two commits -->
<!-- (revision)properties can't be set and read within one svn block -->
<echo message="updating build.xml and status.xml"/>
@ -2119,6 +2120,41 @@ under the License.
<dirset dir="src"/>
</commit>
</svn>
<mkdir dir="build/release"/>
<svn refid="svn.settings">
<checkout url="https://svn.apache.org/repos/asf/poi/tags/${RELEASE_TAG}" destPath="build/release"/>
</svn>
</target>
<target name="release-prep2" depends="init" description="compile the freshly checked out svn tag and upload it to the nexus - needs a JDK6">
<!-- JAVA_HOME needs to point to a JDK6, otherwise the ant invocation is failing on a missing javac -->
<fail message="Environment needs to point to a java 6 jdk">
<condition>
<not><equals arg1="${ant.java.version}" arg2="1.6"/></not>
</condition>
</fail>
<local name="DSTAMP"/>
<tstamp>
<format property="DSTAMP" pattern="yyyyMMdd" offset="7" unit="day"/>
</tstamp>
<ant dir="build/release" inheritAll="false" inheritRefs="false" useNativeBasedir="true">
<property name="DSTAMP" value="${DSTAMP}"/>
<target name="dist" />
<target name="dist-nexus" />
</ant>
</target>
<target name="release-prep3" depends="-init-svn" description="write the dist to the release candidate repo - needs Java7+">
<svn refid="svn.settings">
<import path="build/release/build/dist"
url="https://dist.apache.org/repos/dist/dev/poi"
newEntry="${version.id}-${release.rc}"
message="release candidate POI ${version.id}"/>
</svn>
</target>
<target name="-update-build.xml">

View File

@ -131,12 +131,28 @@ public final class ZipPackage extends Package {
// some zips can't be opened via ZipFile in JDK6, as the central directory
// contains either non-latin entries or the compression type can't be handled
// the workaround is to iterate over the stream and not the directory
FileInputStream fis;
FileInputStream fis = null;
ThresholdInputStream zis = null;
try {
fis = new FileInputStream(file);
ThresholdInputStream zis = ZipHelper.openZipStream(fis);
zis = ZipHelper.openZipStream(fis);
ze = new ZipInputStreamZipEntrySource(zis);
} catch (IOException e2) {
if (zis != null) {
try {
zis.close();
} catch (IOException e3) {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
" and couldn't close the file input stream", e);
}
} else if (fis != null) {
try {
fis.close();
} catch (IOException e3) {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
" and couldn't close the file input stream", e);
}
}
throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
}
}

View File

@ -25,8 +25,10 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@ -174,4 +176,24 @@ public class TestZipPackage {
SlideShow<?,?> ppt = SlideShowFactory.create(f, null, true);
ppt.close();
}
@Test
public void testClosingStreamOnException() throws IOException {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("dcterms_bug_56479.zip");
File tmp = File.createTempFile("poi-test-truncated-zip", "");
OutputStream os = new FileOutputStream(tmp);
for (int i = 0; i < 100; i++) {
os.write(is.read());
}
os.flush();
os.close();
is.close();
try {
OPCPackage.open(tmp, PackageAccess.READ);
} catch (Exception e) {
}
assertTrue("Can't delete tmp file", tmp.delete());
}
}