Try to fix ImageIO cache error

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1846723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-11-16 15:39:51 +00:00
parent 95416d6f05
commit 1a040e4b0a
4 changed files with 15 additions and 15 deletions

View File

@ -103,7 +103,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version> <version>${maven.plugin.surefire.version}</version>
<configuration> <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> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -93,7 +93,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven.plugin.surefire.version}</version> <version>${maven.plugin.surefire.version}</version>
<configuration> <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> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -117,7 +117,7 @@
<org.apache.poi.util.POILogger>org.apache.poi.util.NullLogger</org.apache.poi.util.POILogger> <org.apache.poi.util.POILogger>org.apache.poi.util.NullLogger</org.apache.poi.util.POILogger>
</systemPropertyVariables> </systemPropertyVariables>
<!-- use to following to analyze OOM issues: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp --> <!-- 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> </argLine>
<excludes> <excludes>
<exclude>**/All*Tests.java</exclude> <exclude>**/All*Tests.java</exclude>

View File

@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -27,7 +28,6 @@ import javax.imageio.ImageIO;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/** /**
@ -37,19 +37,19 @@ import org.junit.BeforeClass;
* @author Yegor Kozlov (yegor at apache dot org) * @author Yegor Kozlov (yegor at apache dot org)
* @author Trejkaz (trejkaz at trypticon dot org) * @author Trejkaz (trejkaz at trypticon dot org)
*/ */
public final class TestHSSFPictureData extends TestCase { public final class TestHSSFPictureData extends TestCase{
private static boolean cacheBefore = ImageIO.getUseCache();
@BeforeClass @BeforeClass
public static void setUpClass() { public static void setUpClass() {
// disable cache to avoid strange errors related to temporary directories in CI-builds final String tmpDirProperty = System.getProperty("java.io.tmpdir");
ImageIO.setUseCache(false); if(tmpDirProperty == null || "".equals(tmpDirProperty)) {
} return;
}
@AfterClass // ensure that temp-dir exists because ImageIO requires it
public static void tearDownClass() { final File tmpDir = new File(tmpDirProperty);
// reset image cache to previous state if(!tmpDir.exists() && !tmpDir.mkdirs()) {
ImageIO.setUseCache(cacheBefore); throw new IllegalStateException("Could not create temporary directory " + tmpDirProperty + ", full path " + tmpDir.getAbsolutePath());
}
ImageIO.setCacheDirectory(tmpDir);
} }
public void testPictures() throws IOException { public void testPictures() throws IOException {