Search in sources :

Example 16 with SoftFound

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

Example 17 with SoftFound

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

the class VersionSoftPolicy method toSoftFound.

/**
 * @see org.fagu.fmv.soft.find.SoftPolicy#toSoftFound(org.fagu.fmv.soft.find.SoftInfo)
 */
@Override
public SoftFound toSoftFound(Object object) {
    VersionSoftInfo versionSoftInfo = (VersionSoftInfo) object;
    if (list.isEmpty()) {
        throw new IllegalStateException("No validator defined !");
    }
    // system properties
    SoftFound byPropertiesFound = byProperties(versionSoftInfo);
    if (byPropertiesFound != null && byPropertiesFound.isFound()) {
        return byPropertiesFound;
    }
    // defined
    return byDefined(versionSoftInfo);
}
Also used : VersionSoftInfo(org.fagu.fmv.soft.find.info.VersionSoftInfo) SoftFound(org.fagu.fmv.soft.find.SoftFound)

Example 18 with SoftFound

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

the class VersionPolicyTestCase method testAllOS_VersionV2_versionV1.

/**
 */
@Test
public void testAllOS_VersionV2_versionV1() {
    SoftFound softFound = new VersionSoftPolicy().onAllPlatforms(minVersion(Version.V2)).toSoftFound(versionSoftInfo(Version.V1));
    assertFalse(softFound.isFound());
    assertEquals(FoundReasons.BAD_VERSION, softFound.getFoundReason());
    assertEquals(">= v2", softFound.getReason());
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Test(org.junit.Test)

Example 19 with SoftFound

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

the class VersionPolicyTestCase method testAllOS_VersionV2_versionV3.

/**
 */
@Test
public void testAllOS_VersionV2_versionV3() {
    SoftFound softFound = new VersionSoftPolicy().onAllPlatforms(minVersion(Version.V2)).toSoftFound(versionSoftInfo(Version.V3));
    assertTrue(softFound.isFound());
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Test(org.junit.Test)

Example 20 with SoftFound

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

the class SoftTestCase method test1.

@Test
@Ignore
public void test1() throws Exception {
    SoftFoundFactory ffSoftFoundFactory = ExecSoftFoundFactory.forProvider(new TestSoftProvider("ffprout")).withParameters("-version").parseFactory((file, softPolicy) -> new Parser() {

        private Integer build;

        @Override
        public void readLine(String line) {
            if (line.startsWith("ff")) {
                build = Integer.parseInt(StringUtils.substringBetween(line, "N-", "-"));
            }
        }

        @Override
        public SoftFound closeAndParse(String cmdLineStr, int exitValue) throws IOException {
            if (build == null) {
                return SoftFound.foundBadSoft(file);
            }
            // return SoftFound.found(file, new TestSoftInfo(build));
            return SoftFound.foundBadVersion(new TestSoftInfo(49), "85");
        }
    }).build();
    // SoftFoundFactory identifyFoundFactory = ExecSoftFoundFactory.withParameters("-version").parseFactory(file ->
    // new Parser() {
    // 
    // @Override
    // public void readLine(String line) {}
    // 
    // @Override
    // public SoftFound closeAndParse(String cmdLineStr, int exitValue) throws IOException {
    // return SoftFound.foundBadVersion(new TestSoftInfo(49), "85");
    // }
    // }).build();
    Soft soft = Soft.with(new TestSoftProvider("ffprout")).search(ffSoftFoundFactory);
    // Soft ffprobeSoft = Soft.with("ffprobe").search(ffSoftFoundFactory);
    // Soft identifySoft = Soft.withName("identify").search(identifyFoundFactory);
    SoftLogger softFormatter = new SoftLogger(Arrays.asList(soft));
    // SoftLogger softFormatter = new SoftLogger(Arrays.asList(ffprobeSoft, identifySoft, ffmpegSoft));
    softFormatter.logDetails(System.out::println);
    // System.out.println(soft.getFounds());
    // System.out.println(soft.getFile());
    soft.withParameters("").execute();
}
Also used : SoftFoundFactory(org.fagu.fmv.soft.find.SoftFoundFactory) Arrays(java.util.Arrays) ExecSoftFoundFactory(org.fagu.fmv.soft.find.ExecSoftFoundFactory) Date(java.util.Date) SoftFound(org.fagu.fmv.soft.find.SoftFound) IOException(java.io.IOException) Test(org.junit.Test) StringUtils(org.apache.commons.lang3.StringUtils) Executors(java.util.concurrent.Executors) Future(java.util.concurrent.Future) Executed(org.fagu.fmv.soft.SoftExecutor.Executed) Parser(org.fagu.fmv.soft.find.ExecSoftFoundFactory.Parser) Ignore(org.junit.Ignore) ExecutorService(java.util.concurrent.ExecutorService) SoftFoundFactory(org.fagu.fmv.soft.find.SoftFoundFactory) ExecSoftFoundFactory(org.fagu.fmv.soft.find.ExecSoftFoundFactory) Parser(org.fagu.fmv.soft.find.ExecSoftFoundFactory.Parser) Ignore(org.junit.Ignore) Test(org.junit.Test)

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