]> source.dussan.org Git - poi.git/commitdiff
Try to fix ImageIO cache error
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 16 Nov 2018 15:39:51 +0000 (15:39 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 16 Nov 2018 15:39:51 +0000 (15:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846723 13f79535-47bb-0310-9956-ffa450edef68

sonar/main/pom.xml
sonar/ooxml/pom.xml
sonar/pom.xml
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPictureData.java

index d188c14f560ba8e1e2f4e3d14f47558d5527f5ea..b4ed72f4a1d3a6405bbd5c4f510429d8c315a853 100644 (file)
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>${maven.plugin.surefire.version}</version>
                 <configuration>
-                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow</argLine>
+                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow</argLine>
                 </configuration>
             </plugin>
                </plugins>
index c61f42ecde4b1cfe1925134eea995f930a958f78..fad8ac56429db5d86ba83709b5232f371829981c 100644 (file)
@@ -93,7 +93,7 @@
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>${maven.plugin.surefire.version}</version>
                 <configuration>
-                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp -XX:-OmitStackTraceInFastThrow</argLine>
+                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp -XX:-OmitStackTraceInFastThrow</argLine>
                 </configuration>
             </plugin>
         </plugins>
index 0316403a05fa186196b501ae51b3a574179ee4e8..87c2daf37cacdd316ee4277a3d4e7a3b408c4a39 100644 (file)
                         <org.apache.poi.util.POILogger>org.apache.poi.util.NullLogger</org.apache.poi.util.POILogger>
                     </systemPropertyVariables>
                     <!-- use to following to analyze OOM issues:       -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -->
-                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=target/tmp
+                    <argLine>@{argLine} -Duser.language=en -Duser.country=US -Xmx1024m -Djava.io.tmpdir=${basedir}/target/tmp
                     </argLine>
                     <excludes>
                         <exclude>**/All*Tests.java</exclude>
index d82423b86e1e2387a13fb322eeed8e31d96f3e7b..c65b0252d8702fe829804a85cfd8216610dac838 100644 (file)
@@ -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 {