fix ghostscript #21

Merged
kilian.schuettler1 merged 4 commits from serverbuild-test into main 2024-11-27 10:53:06 +01:00
2 changed files with 33 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.springframework.stereotype.Service;
@ -15,14 +16,12 @@ import com.knecon.fforesight.service.ocr.processor.model.ImageFile;
import com.knecon.fforesight.service.ocr.processor.model.PageBatch;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@SuppressWarnings("PMD") // can't figure out how to safely close the stdOut and stdError streams in line 72/74
public class GhostScriptService {
@ -34,6 +33,37 @@ public class GhostScriptService {
private Semaphore concurrencySemaphore = new Semaphore(3);
public GhostScriptService(OcrServiceSettings ocrServiceSettings) {
this.ocrServiceSettings = ocrServiceSettings;
assertGhostscriptIsInstalled();
}
private void assertGhostscriptIsInstalled() {
try {
Process p = Runtime.getRuntime().exec("gs -v");
InputStream stdOut = p.getInputStream();
InputStream errOut = p.getErrorStream();
assert p.waitFor(1, TimeUnit.SECONDS);
log.info("Ghostscript is installed.");
String out = new String(stdOut.readAllBytes());
String error = new String(errOut.readAllBytes());
for (String line : out.split("\n")) {
log.info(line);
}
if (!error.isBlank()) {
log.error(error);
}
} catch (Exception e) {
log.error("Ghostscript is not installed!");
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
@SneakyThrows
public void startBatchRender(PageBatch batch, ImageProcessingSupervisor supervisor, Consumer<ImageFile> successHandler, Consumer<String> errorHandler) {

View File

@ -1,5 +1,5 @@
# you can list packages
ghostscript=9.55.0~dfsg1-0ubuntu5.9
ghostscript=9.55.0~dfsg1-0ubuntu5.10
pkg-config
zip
unzip