Search in sources :

Example 1 with Founds

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

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

the class SoftSearch method search.

/**
 * @return
 */
public Soft search() {
    SoftLocator locator = getLocator();
    Founds founds = locator.find();
    return createAndfireEventFound(founds, locator);
}
Also used : SoftLocator(org.fagu.fmv.soft.find.SoftLocator) Founds(org.fagu.fmv.soft.find.Founds)

Example 3 with Founds

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

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

the class SoftSearch method search.

/**
 * @param softTester
 * @return
 */
public Soft search(SoftTester softTester) {
    checkUsed();
    SoftLocator locator = getLocator();
    Founds founds = locator.find(softTester);
    return createAndfireEventFound(founds, locator);
}
Also used : SoftLocator(org.fagu.fmv.soft.find.SoftLocator) Founds(org.fagu.fmv.soft.find.Founds)

Example 5 with Founds

use of org.fagu.fmv.soft.find.Founds 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)6 SoftFound (org.fagu.fmv.soft.find.SoftFound)3 SoftLocator (org.fagu.fmv.soft.find.SoftLocator)3 IOException (java.io.IOException)2 SoftProvider (org.fagu.fmv.soft.find.SoftProvider)2 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 TreeSet (java.util.TreeSet)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1