Search in sources :

Example 1 with SoftProvider

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

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

the class Soft method withExecFile.

/**
 * @param softName
 * @return
 */
public static Soft withExecFile(File file) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getAbsolutePath());
    }
    if (!file.isFile()) {
        throw new IOException("It's not a file: " + file.getAbsolutePath());
    }
    Path path = file.toPath();
    if (!Files.isExecutable(path)) {
        throw new IOException("Cannot execute: " + file.getAbsolutePath());
    }
    SoftProvider softProvider = new SoftProvider(file.getName(), null) {

        @Override
        public SoftFoundFactory createSoftFoundFactory() {
            throw new RuntimeException("Not available !");
        }
    };
    TreeSet<SoftFound> founds = new TreeSet<>(Collections.singleton(SoftFound.found(file)));
    return new Soft(new Founds(softProvider.getName(), founds, null), softProvider);
}
Also used : Path(java.nio.file.Path) SoftFound(org.fagu.fmv.soft.find.SoftFound) TreeSet(java.util.TreeSet) Founds(org.fagu.fmv.soft.find.Founds) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SoftProvider(org.fagu.fmv.soft.find.SoftProvider)

Aggregations

Founds (org.fagu.fmv.soft.find.Founds)2 SoftFound (org.fagu.fmv.soft.find.SoftFound)2 SoftProvider (org.fagu.fmv.soft.find.SoftProvider)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 TreeSet (java.util.TreeSet)1