do not delete temp directory
This commit is contained in:
parent
5d33823074
commit
d79e19c005
6 changed files with 67 additions and 48 deletions
|
@ -1,6 +1,6 @@
|
||||||
group = org.xbib.graphics
|
group = org.xbib.graphics
|
||||||
name = graphics
|
name = graphics
|
||||||
version = 4.0.3
|
version = 4.0.4
|
||||||
|
|
||||||
gradle.wrapper.version = 6.6.1
|
gradle.wrapper.version = 6.6.1
|
||||||
pdfbox.version = 2.0.23
|
pdfbox.version = 2.0.23
|
||||||
|
@ -9,7 +9,7 @@ zxing.version = 3.3.1
|
||||||
reflections.version = 0.9.11
|
reflections.version = 0.9.11
|
||||||
jfreechart.version = 1.5.1
|
jfreechart.version = 1.5.1
|
||||||
batik.version = 1.13
|
batik.version = 1.13
|
||||||
junit.version = 5.7.1
|
junit.version = 5.7.2
|
||||||
junit4.version = 4.13.2
|
junit4.version = 4.13.2
|
||||||
groovy.version = 2.5.12
|
groovy.version = 2.5.12
|
||||||
spock.version = 1.3-groovy-2.5
|
spock.version = 1.3-groovy-2.5
|
||||||
|
|
|
@ -13,8 +13,10 @@ test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
failFast = false
|
failFast = false
|
||||||
environment 'TMPDIR', '/var/tmp/gs'
|
environment 'TMPDIR', '/var/tmp/gs'
|
||||||
|
file('/var/tmp/gs').mkdirs()
|
||||||
systemProperty 'java.awt.headless', 'true'
|
systemProperty 'java.awt.headless', 'true'
|
||||||
systemProperty 'java.io.tmpdir', '/var/tmp/'
|
systemProperty 'java.io.tmpdir', '/var/tmp/'
|
||||||
|
systemProperty 'jna.tmpdir', '/var/tmp/'
|
||||||
systemProperty 'jna.debug', 'false'
|
systemProperty 'jna.debug', 'false'
|
||||||
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
|
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
|
||||||
testLogging {
|
testLogging {
|
||||||
|
|
|
@ -12,8 +12,10 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries {
|
public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries {
|
||||||
|
|
||||||
protected List<?> xData; // can be Number or Instant
|
protected List<?> xData;
|
||||||
|
|
||||||
protected List<? extends Number> yData;
|
protected List<? extends Number> yData;
|
||||||
|
|
||||||
protected List<? extends Number> extraValues;
|
protected List<? extends Number> extraValues;
|
||||||
|
|
||||||
public AxesChartSeriesNumericalNoErrorBars(String name,
|
public AxesChartSeriesNumericalNoErrorBars(String name,
|
||||||
|
@ -30,11 +32,9 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void calculateMinMax() {
|
protected void calculateMinMax() {
|
||||||
// xData
|
|
||||||
List<Double> xMinMax = findMinMax(xData);
|
List<Double> xMinMax = findMinMax(xData);
|
||||||
setXMin(xMinMax.get(0));
|
setXMin(xMinMax.get(0));
|
||||||
setXMax(xMinMax.get(1));
|
setXMax(xMinMax.get(1));
|
||||||
// yData
|
|
||||||
List<Double> yMinMax;
|
List<Double> yMinMax;
|
||||||
if (extraValues == null) {
|
if (extraValues == null) {
|
||||||
yMinMax = findMinMax(yData);
|
yMinMax = findMinMax(yData);
|
||||||
|
@ -46,6 +46,9 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Double> findMinMax(List<?> data) {
|
List<Double> findMinMax(List<?> data) {
|
||||||
|
if (data == null) {
|
||||||
|
return Arrays.asList(null, null);
|
||||||
|
}
|
||||||
Double min = null;
|
Double min = null;
|
||||||
Double max = null;
|
Double max = null;
|
||||||
for (Object dataPoint : data) {
|
for (Object dataPoint : data) {
|
||||||
|
@ -113,7 +116,10 @@ public abstract class AxesChartSeriesNumericalNoErrorBars extends MarkerSeries {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Double> findMinMaxWithErrorBars(List<? extends Number> data,
|
private List<Double> findMinMaxWithErrorBars(List<? extends Number> data,
|
||||||
List<? extends Number> errorBars) {
|
List<? extends Number> errorBars) {
|
||||||
|
if (data == null) {
|
||||||
|
return Arrays.asList(Double.MAX_VALUE, Double.MAX_VALUE);
|
||||||
|
}
|
||||||
double min = Double.MAX_VALUE;
|
double min = Double.MAX_VALUE;
|
||||||
double max = -Double.MAX_VALUE;
|
double max = -Double.MAX_VALUE;
|
||||||
for (int i = 0; i < data.size(); i++) {
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.xbib.graphics.chart.legend.LegendRenderType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Series containing X and Y data to be plotted on a Chart
|
* A Series containing X and Y data to be plotted on a Chart.
|
||||||
*/
|
*/
|
||||||
public class XYSeries extends AxesChartSeriesNumericalNoErrorBars {
|
public class XYSeries extends AxesChartSeriesNumericalNoErrorBars {
|
||||||
|
|
||||||
|
@ -33,6 +33,4 @@ public class XYSeries extends AxesChartSeriesNumericalNoErrorBars {
|
||||||
public LegendRenderType getLegendRenderType() {
|
public LegendRenderType getLegendRenderType() {
|
||||||
return xySeriesRenderStyle.getLegendRenderType();
|
return xySeriesRenderStyle.getLegendRenderType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ package org.xbib.graphics.chart;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.xbib.graphics.chart.io.VectorGraphicsFormat;
|
import org.xbib.graphics.chart.io.VectorGraphicsFormat;
|
||||||
|
import org.xbib.graphics.chart.legend.LegendPosition;
|
||||||
import org.xbib.graphics.chart.theme.MatlabTheme;
|
import org.xbib.graphics.chart.theme.MatlabTheme;
|
||||||
import org.xbib.graphics.chart.xy.XYChart;
|
import org.xbib.graphics.chart.xy.XYChart;
|
||||||
import org.xbib.graphics.chart.xy.XYChartBuilder;
|
import org.xbib.graphics.chart.xy.XYChartBuilder;
|
||||||
|
@ -16,7 +17,7 @@ import java.util.List;
|
||||||
public class MatlabTest {
|
public class MatlabTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatlabInstants() throws IOException {
|
public void testMatlabInstantsWithDoubles() throws IOException {
|
||||||
XYChart chart = new XYChartBuilder().width(800).height(600)
|
XYChart chart = new XYChartBuilder().width(800).height(600)
|
||||||
.theme(new MatlabTheme())
|
.theme(new MatlabTheme())
|
||||||
.title("Matlab Theme")
|
.title("Matlab Theme")
|
||||||
|
@ -61,7 +62,53 @@ public class MatlabTest {
|
||||||
chart.addSeries("downloads", xData, y1Data);
|
chart.addSeries("downloads", xData, y1Data);
|
||||||
chart.addSeries("price", xData, y2Data);
|
chart.addSeries("price", xData, y2Data);
|
||||||
|
|
||||||
chart.write(Files.newOutputStream(Paths.get("build/matlab.svg")),
|
chart.write(Files.newOutputStream(Paths.get("build/matlab1.svg")),
|
||||||
VectorGraphicsFormat.SVG);
|
VectorGraphicsFormat.SVG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatlabInstantsWitInts() throws IOException {
|
||||||
|
XYChart chart = new XYChartBuilder()
|
||||||
|
.width(800)
|
||||||
|
.height(600)
|
||||||
|
.theme(new MatlabTheme())
|
||||||
|
.title("Matlab Style Demo")
|
||||||
|
.xAxisTitle("X")
|
||||||
|
.yAxisTitle("Y")
|
||||||
|
.build();
|
||||||
|
chart.getStyler().setLegendPosition(LegendPosition.OutsideE);
|
||||||
|
chart.getStyler().setDatePattern("LLL yyyy");
|
||||||
|
chart.getStyler().setPlotGridLinesVisible(true);
|
||||||
|
chart.getStyler().setYAxisMin(0.0d);
|
||||||
|
|
||||||
|
List<Instant> xData = new ArrayList<>();
|
||||||
|
List<Integer> y1Data = new ArrayList<>();
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-01-01T00:00:00Z"));
|
||||||
|
y1Data.add(120);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-02-01T00:00:00Z"));
|
||||||
|
y1Data.add(165);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-03-01T00:00:00Z"));
|
||||||
|
y1Data.add(210);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-04-01T00:00:00Z"));
|
||||||
|
y1Data.add(400);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-05-01T00:00:00Z"));
|
||||||
|
y1Data.add(80);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-06-01T00:00:00Z"));
|
||||||
|
y1Data.add(200);
|
||||||
|
|
||||||
|
xData.add(Instant.parse("2012-07-01T00:00:00Z"));
|
||||||
|
y1Data.add(300);
|
||||||
|
|
||||||
|
chart.addSeries("Anzahl", xData, y1Data);
|
||||||
|
|
||||||
|
chart.write(Files.newOutputStream(Paths.get("build/matlab2.svg")),
|
||||||
|
VectorGraphicsFormat.SVG);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,9 @@ import org.xbib.graphics.ghostscript.internal.NullOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.NoSuchFileException;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -99,7 +95,6 @@ public class Ghostscript {
|
||||||
nativeInstanceByRef = null;
|
nativeInstanceByRef = null;
|
||||||
}
|
}
|
||||||
instance = null;
|
instance = null;
|
||||||
deleteTmp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,38 +321,9 @@ public class Ghostscript {
|
||||||
throw new IllegalStateException("no TEMP/TMPDIR environment set for ghostscript");
|
throw new IllegalStateException("no TEMP/TMPDIR environment set for ghostscript");
|
||||||
}
|
}
|
||||||
tmpDir = Paths.get(tmp);
|
tmpDir = Paths.get(tmp);
|
||||||
deleteTmp();
|
|
||||||
Files.createDirectories(tmpDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void deleteTmp() throws IOException {
|
|
||||||
if (tmpDir == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Files.exists(tmpDir)) {
|
if (!Files.exists(tmpDir)) {
|
||||||
return;
|
Files.createDirectories(tmpDir);
|
||||||
}
|
|
||||||
try {
|
|
||||||
Files.walkFileTree(tmpDir, new SimpleFileVisitor<>() {
|
|
||||||
@Override
|
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
||||||
logger.info("deleting " + file);
|
|
||||||
Files.deleteIfExists(file);
|
|
||||||
return FileVisitResult.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
||||||
logger.info("deleting " + dir);
|
|
||||||
Files.deleteIfExists(dir);
|
|
||||||
return FileVisitResult.CONTINUE;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (NoSuchFileException e) {
|
|
||||||
logger.log(Level.WARNING, e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
logger.info("deleting " + tmpDir);
|
|
||||||
Files.deleteIfExists(tmpDir);
|
|
||||||
}
|
}
|
||||||
|
// never delete TMPDIR or TEMP automatically, it might be a shared directory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue