Search in sources :

Example 1 with FoundReason

use of org.fagu.fmv.soft.find.FoundReason 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 2 with FoundReason

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

the class SoftLogger method toLine.

/**
 * @param line
 * @param softProvider
 * @param softFound
 * @param formatConsumer
 */
private void toLine(StringBuilder line, SoftProvider softProvider, SoftFound softFound, Consumer<String> formatConsumer) {
    if (softFound != null) {
        String info = softFound.getInfo();
        if (softFound.isFound()) {
            appendFile(line, softFound);
            if (StringUtils.isNotBlank(info)) {
                line.append(' ').append('(').append(info).append(')');
            }
            formatConsumer.accept(line.toString());
            return;
        }
        appendFile(line, softFound);
        FoundReason foundReason = softFound.getFoundReason();
        if (foundReason == FoundReasons.BAD_VERSION) {
            line.append(" (find version ").append(info != null ? info : "?").append(" but I need another version: ");
            line.append(softFound.getReason()).append(')');
            formatConsumer.accept(line.toString());
            return;
        }
        String reason = softFound.getReason();
        if (StringUtils.isNotBlank(reason)) {
            line.append(": ").append(reason);
        }
        formatConsumer.accept(line.toString());
        String downloadURL = softProvider.getDownloadURL();
        if (StringUtils.isNotBlank(downloadURL)) {
            formatConsumer.accept("   Download at: " + downloadURL);
        }
        String minVersion = softProvider.getMinVersion();
        if (StringUtils.isNotBlank(minVersion)) {
            formatConsumer.accept("   Minimum version: " + minVersion);
        }
    }
}
Also used : FoundReason(org.fagu.fmv.soft.find.FoundReason)

Aggregations

FoundReason (org.fagu.fmv.soft.find.FoundReason)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 StringJoiner (java.util.StringJoiner)1 Soft (org.fagu.fmv.soft.Soft)1 SoftFound (org.fagu.fmv.soft.find.SoftFound)1 SoftInfo (org.fagu.fmv.soft.find.SoftInfo)1 VersionDateSoftInfo (org.fagu.fmv.soft.find.info.VersionDateSoftInfo)1 VersionSoftInfo (org.fagu.fmv.soft.find.info.VersionSoftInfo)1