Search in sources :

Example 6 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class XpdfExceptionKnowAnalyzeTestCase method extract.

// *************************************
/**
 * @param srcResource
 * @throws IOException
 */
private void extract(String srcResource, String expectedMessage) throws IOException {
    File folder = new File(System.getProperty("java.io.tmpdir"), "xpdf-info-test");
    try {
        FileUtils.deleteDirectory(folder);
        folder.mkdirs();
        File srcFile = srcResource != null ? extractResource(folder, srcResource) : folder;
        try {
            Soft pdfInfoSoft = PdfInfo.search();
            pdfInfoSoft.withParameters(srcFile.getAbsolutePath()).workingDirectory(srcFile.getParentFile()).execute();
            fail();
        } catch (FMVExecuteException e) {
            if (e.isKnown()) {
                assertEquals(expectedMessage, e.getExceptionKnown().toString());
            } else {
                throw e;
            }
        }
    } finally {
        FileUtils.deleteDirectory(folder);
    }
}
Also used : FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) File(java.io.File) Soft(org.fagu.fmv.soft.Soft)

Example 7 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class SoftFoundHealthIndicator method doHealthCheck.

/**
 * @see org.springframework.boot.actuate.health.AbstractHealthIndicator#doHealthCheck(org.springframework.boot.actuate.health.Health.Builder)
 */
@Override
protected void doHealthCheck(Builder builder) throws Exception {
    Collection<Soft> softs = Softs.getHealthIndicators();
    if (softs.isEmpty()) {
        builder.unknown();
        return;
    }
    builder.up();
    for (Soft soft : softs) {
        String msg = soft.toString();
        SoftFound softFound = soft.getFounds().getFirstFound();
        if (soft.isFound()) {
            // recheck soft
            softFound = soft.reFind();
        }
        if (softFound != null && !softFound.isFound()) {
            builder.down();
            StringJoiner joiner = new StringJoiner(", ");
            soft.getFounds().forEach(f -> {
                String reason = f.getReason();
                if (StringUtils.isNotBlank(reason)) {
                    joiner.add(reason);
                }
            });
            if (joiner.length() > 0) {
                msg += ": " + joiner.toString();
            }
        } else if (softFound == null) {
            builder.down();
        }
        builder.withDetail(soft.getName(), msg);
    }
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Soft(org.fagu.fmv.soft.Soft) StringJoiner(java.util.StringJoiner)

Example 8 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class SoftInfoContributor method content.

// *********************************************
/**
 * @return
 */
private Map<String, String> content() {
    Map<String, String> map = new HashMap<>();
    for (Soft soft : Softs.getInfoContributors()) {
        String msg = null;
        if (soft.isFound()) {
            StringBuilder buf = new StringBuilder(100);
            SoftInfo softInfo = soft.getFirstInfo();
            if (softInfo instanceof VersionSoftInfo) {
                ((VersionSoftInfo) softInfo).getVersion().ifPresent(v -> buf.append(v).append(", "));
            }
            if (softInfo instanceof VersionDateSoftInfo) {
                ((VersionDateSoftInfo) softInfo).getDate().ifPresent(d -> {
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    buf.append(dateFormat.format(d)).append(", ");
                });
            }
            buf.append(soft.getFile().getAbsolutePath());
            msg = buf.toString();
        } else {
            StringJoiner joiner = new StringJoiner(" ; ");
            for (SoftFound softFound : soft.getFounds()) {
                StringBuilder buf = new StringBuilder();
                FoundReason foundReason = softFound != null ? softFound.getFoundReason() : FoundReasons.NOT_FOUND;
                buf.append(foundReason.name());
                String reason = softFound.getReason();
                if (reason != null) {
                    buf.append(": ").append(reason);
                }
                joiner.add(buf.toString());
            }
            msg = joiner.toString();
        }
        map.put(soft.getName(), msg);
    }
    return map;
}
Also used : VersionSoftInfo(org.fagu.fmv.soft.find.info.VersionSoftInfo) SoftInfo(org.fagu.fmv.soft.find.SoftInfo) VersionDateSoftInfo(org.fagu.fmv.soft.find.info.VersionDateSoftInfo) VersionSoftInfo(org.fagu.fmv.soft.find.info.VersionSoftInfo) FoundReason(org.fagu.fmv.soft.find.FoundReason) HashMap(java.util.HashMap) SoftFound(org.fagu.fmv.soft.find.SoftFound) VersionDateSoftInfo(org.fagu.fmv.soft.find.info.VersionDateSoftInfo) Soft(org.fagu.fmv.soft.Soft) SimpleDateFormat(java.text.SimpleDateFormat) StringJoiner(java.util.StringJoiner)

Example 9 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class IMReducer method reduceMedia.

/**
 * @see org.fagu.fmv.mymedia.reduce.Reducer#reduceMedia(java.io.File, String, Logger)
 */
@Override
public Reduced reduceMedia(File srcFile, String consolePrefixMessage, Logger logger) throws IOException {
    File destFile = getTempFile(srcFile, format);
    IMOperation op = new IMOperation();
    op.image(srcFile, "[0]").autoOrient().quality(quality).image(destFile);
    Soft convertSoft = Convert.search();
    convertSoft.withParameters(op.toList()).logCommandLine(line -> logger.log("Exec: " + line)).execute();
    return new Reduced(destFile, false);
}
Also used : Soft(org.fagu.fmv.soft.Soft) Convert(org.fagu.fmv.im.soft.Convert) IMOperation(org.fagu.fmv.im.IMOperation) Logger(org.fagu.fmv.mymedia.logger.Logger) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) Loggers(org.fagu.fmv.mymedia.logger.Loggers) IMOperation(org.fagu.fmv.im.IMOperation) File(java.io.File) Soft(org.fagu.fmv.soft.Soft)

Example 10 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class GSExceptionKnowAnalyzeTestCase method testMerge.

/**
 * @throws IOException
 */
@Test
public // @Ignore
void testMerge() throws IOException {
    File folder = new File(System.getProperty("java.io.tmpdir"), "gs-merge-test");
    FileUtils.deleteDirectory(folder);
    folder.mkdirs();
    try {
        try {
            Soft gsSoft = GS.search();
            File viewJpegPSFile = new File(new File(gsSoft.getFile().getParentFile().getParentFile(), "lib"), "viewjpeg.ps");
            File srcFile = Resource.extract(folder, "cheese.zip");
            File outFile = new File(srcFile.getPath() + ".pdf");
            List<String> parameters = new ArrayList<>();
            parameters.add("-sDEVICE=pdfwrite");
            parameters.add("-dPDFSETTINGS=/prepress");
            parameters.add("-o");
            parameters.add(outFile.getAbsolutePath());
            parameters.add(viewJpegPSFile.getAbsolutePath());
            parameters.add("-c");
            parameters.add("(" + srcFile.getName() + ") viewJPEG showpage");
            gsSoft.withParameters(parameters).workingDirectory(srcFile.getParentFile()).execute();
        } catch (FMVExecuteException e) {
            if (e.isKnown()) {
                assertEquals("ddd", e.getExceptionKnown().toString());
            } else {
                throw e;
            }
        }
    } finally {
        FileUtils.deleteDirectory(folder);
    }
}
Also used : FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) ArrayList(java.util.ArrayList) File(java.io.File) Soft(org.fagu.fmv.soft.Soft) Test(org.junit.Test)

Aggregations

Soft (org.fagu.fmv.soft.Soft)12 File (java.io.File)8 Test (org.junit.Test)7 SoftFound (org.fagu.fmv.soft.find.SoftFound)4 FMVExecuteException (org.fagu.fmv.soft.exec.exception.FMVExecuteException)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 StringJoiner (java.util.StringJoiner)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 FileUtils (org.apache.commons.io.FileUtils)1 IMOperation (org.fagu.fmv.im.IMOperation)1 Convert (org.fagu.fmv.im.soft.Convert)1 Logger (org.fagu.fmv.mymedia.logger.Logger)1 Loggers (org.fagu.fmv.mymedia.logger.Loggers)1