Search in sources :

Example 6 with SoftFound

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

the class JavaSoftProviderTestCase method testFind.

/**
 */
@Test
@Ignore
public void testFind() {
    Soft java = Java.search();
    for (SoftFound softFound : java.getFounds()) {
        System.out.println(softFound);
    }
    System.out.println();
    System.out.println(java);
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Soft(org.fagu.fmv.soft.Soft) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with SoftFound

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

the class PdfInfoSoftProviderTestCase method assertInfo.

/**
 * @param parser
 * @param expectedVersion
 * @throws IOException
 */
private void assertInfo(Parser parser, Version expectedVersion) throws IOException {
    SoftFound softFound = parser.closeAndParse("", 0);
    VersionSoftInfo softInfo = (VersionSoftInfo) softFound.getSoftInfo();
    assertEquals(expectedVersion, softInfo.getVersion().orElse(null));
}
Also used : VersionSoftInfo(org.fagu.fmv.soft.find.info.VersionSoftInfo) SoftFound(org.fagu.fmv.soft.find.SoftFound)

Example 8 with SoftFound

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

the class SoftLogger method logDetails.

/**
 * @param formatConsumer
 */
public SoftLogger logDetails(Consumer<String> formatConsumer) {
    int maxLength = getNameMaxLength() + 3;
    for (Soft soft : softs) {
        Founds founds = soft.getFounds();
        String name = soft.getName();
        SoftFound firstFound = founds.getFirstFound();
        SoftProvider softProvider = soft.getSoftProvider();
        if (founds.isFound()) {
            toLine(startLine(maxLength, name, firstFound), softProvider, firstFound, formatConsumer);
        } else {
            if (founds.isEmpty()) {
                toLine(startLine(maxLength, name, firstFound), softProvider, SoftFound.notFound(), formatConsumer);
            } else {
                int index = 0;
                for (SoftFound softFound : founds) {
                    toLine(startLine(maxLength, 0 == index++ ? name : null, softFound), softProvider, softFound, formatConsumer);
                }
            }
            String downloadURL = softProvider.getDownloadURL();
            if (downloadURL != null && !"".equals(downloadURL.trim())) {
                formatConsumer.accept("    Download " + name + " at " + downloadURL + " and add the path in your system environment PATH");
            }
        }
    }
    return this;
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Founds(org.fagu.fmv.soft.find.Founds) SoftProvider(org.fagu.fmv.soft.find.SoftProvider)

Example 9 with SoftFound

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

the class SoftSearch method search.

/**
 * @param softFoundFactory
 * @return
 */
public Soft search(SoftFoundFactory softFoundFactory) {
    checkUsed();
    SoftLocator locator = getLocator();
    Founds founds = locator.find((file, loc, softPol) -> {
        try {
            SoftFound softFound = softFoundFactory.create(file, loc, softPol);
            if (softFound == null) {
                return SoftFound.foundBadSoft(file);
            }
            return softFound;
        } catch (IOException e) {
            return SoftFound.foundError(file, e.getMessage()).setLocalizedBy(locator.toString());
        }
    });
    return createAndfireEventFound(founds, locator);
}
Also used : SoftLocator(org.fagu.fmv.soft.find.SoftLocator) SoftFound(org.fagu.fmv.soft.find.SoftFound) Founds(org.fagu.fmv.soft.find.Founds) IOException(java.io.IOException)

Example 10 with SoftFound

use of org.fagu.fmv.soft.find.SoftFound 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)

Aggregations

SoftFound (org.fagu.fmv.soft.find.SoftFound)22 Test (org.junit.Test)8 VersionSoftInfo (org.fagu.fmv.soft.find.info.VersionSoftInfo)5 Soft (org.fagu.fmv.soft.Soft)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Founds (org.fagu.fmv.soft.find.Founds)3 VersionDateSoftInfo (org.fagu.fmv.soft.find.info.VersionDateSoftInfo)3 Ignore (org.junit.Ignore)3 HashMap (java.util.HashMap)2 StringJoiner (java.util.StringJoiner)2 Parser (org.fagu.fmv.soft.find.ExecSoftFoundFactory.Parser)2 SoftProvider (org.fagu.fmv.soft.find.SoftProvider)2 Version (org.fagu.version.Version)2 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1