From 1a040e4b0ae38783c54df52a16fb737ea9ba5e7a Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Fri, 16 Nov 2018 15:39:51 +0000 Subject: [PATCH] Try to fix ImageIO cache error git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846723 13f79535-47bb-0310-9956-ffa450edef68 --- sonar/main/pom.xml | 2 +- sonar/ooxml/pom.xml | 2 +- sonar/pom.xml | 2 +- .../hssf/usermodel/TestHSSFPictureData.java | 24 +++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sonar/main/pom.xml b/sonar/main/pom.xml index d188c14f5..b4ed72f4a 100644 --- a/sonar/main/pom.xml +++ b/sonar/main/pom.xml @@ -103,7 +103,7 @@ maven-surefire-plugin ${maven.plugin.surefire.version} - @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow + @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow diff --git a/sonar/ooxml/pom.xml b/sonar/ooxml/pom.xml index c61f42ecd..fad8ac564 100644 --- a/sonar/ooxml/pom.xml +++ b/sonar/ooxml/pom.xml @@ -93,7 +93,7 @@ maven-surefire-plugin ${maven.plugin.surefire.version} - @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow + @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow diff --git a/sonar/pom.xml b/sonar/pom.xml index 0316403a0..87c2daf37 100644 --- a/sonar/pom.xml +++ b/sonar/pom.xml @@ -117,7 +117,7 @@ org.apache.poi.util.NullLogger - @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp + @{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp **/All*Tests.java diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java index d82423b86..c65b0252d 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java @@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.IOException; import java.util.List; @@ -27,7 +28,6 @@ import javax.imageio.ImageIO; import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.junit.AfterClass; import org.junit.BeforeClass; /** @@ -37,19 +37,19 @@ import org.junit.BeforeClass; * @author Yegor Kozlov (yegor at apache dot org) * @author Trejkaz (trejkaz at trypticon dot org) */ -public final class TestHSSFPictureData extends TestCase { - private static boolean cacheBefore = ImageIO.getUseCache(); - +public final class TestHSSFPictureData extends TestCase{ @BeforeClass public static void setUpClass() { - // disable cache to avoid strange errors related to temporary directories in CI-builds - ImageIO.setUseCache(false); - } - - @AfterClass - public static void tearDownClass() { - // reset image cache to previous state - ImageIO.setUseCache(cacheBefore); + final String tmpDirProperty = System.getProperty("java.io.tmpdir"); + if(tmpDirProperty == null || "".equals(tmpDirProperty)) { + return; + } + // ensure that temp-dir exists because ImageIO requires it + final File tmpDir = new File(tmpDirProperty); + if(!tmpDir.exists() && !tmpDir.mkdirs()) { + throw new IllegalStateException("Could not create temporary directory " + tmpDirProperty + ", full path " + tmpDir.getAbsolutePath()); + } + ImageIO.setCacheDirectory(tmpDir); } public void testPictures() throws IOException {