Search in sources :

Example 1 with SoftFound

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

the class FFSoftProvider method createParser.

// ***********************************************************************
/**
 * @param file
 * @return
 */
Parser createParser(File file) {
    return new Parser() {

        private static final String CONFIGURATION_START_PATTERN = "configuration:";

        private Version version = null;

        private Date builtDate = null;

        // configuration
        private Set<String> configuration = null;

        // lib versions
        private Map<String, Version> libVersions = new HashMap<>();

        private SoftFound softFound;

        @Override
        public void readLine(final String lineIn) {
            if (StringUtils.isBlank(lineIn) || softFound != null) {
                return;
            }
            String line = lineIn.trim();
            // version
            Matcher matcher = FF_FIRSTLINE_PATTERN.matcher(line);
            if (matcher.matches()) {
                String parsedTool = matcher.group(1).trim();
                if (parsedTool.equalsIgnoreCase(getName())) {
                    version = getVersion(matcher.group(2).trim());
                    return;
                }
                softFound = SoftFound.foundError(file, "Wrong tool, need " + getName() + " and found " + parsedTool + ": " + line);
            }
            // configuration
            if (line.startsWith(CONFIGURATION_START_PATTERN)) {
                configuration = getConfiguration(StringUtils.substringAfter(line, CONFIGURATION_START_PATTERN).trim());
                return;
            }
            // built
            matcher = BUILD_PATTERN.matcher(line);
            if (matcher.matches()) {
                builtDate = getBuiltDate(matcher);
                return;
            }
            // lib versions
            matcher = LIBVERSION_PATTERN.matcher(line);
            if (matcher.matches()) {
                addLibVersions(libVersions, matcher);
            }
        }

        @Override
        public SoftFound closeAndParse(String cmdLineStr, int exitValue) throws IOException {
            if (softFound != null) {
                return softFound;
            }
            Integer builtVersion = null;
            if (version != null && version.size() == 1) {
                final int minBuildVersion = 100;
                int major = version.getFieldValue(VersionUnit.VF_0_MAJOR, 0);
                // N-70767-gd24af70
                if (major > minBuildVersion) {
                    builtVersion = major;
                    version = null;
                }
            }
            FFInfo ffInfo = new FFInfo(file, version, getName(), builtDate, builtVersion, configuration, libVersions);
            return FFSoftPolicy.toSoftFound(ffInfo);
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Version(org.fagu.version.Version) Matcher(java.util.regex.Matcher) SoftFound(org.fagu.fmv.soft.find.SoftFound) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) Parser(org.fagu.fmv.soft.find.ExecSoftFoundFactory.Parser)

Example 2 with SoftFound

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

the class ConvertSoftProviderTestCase method test.

@Test
@Ignore
public void test() {
    Soft soft = Convert.search();
    for (SoftFound softFound : soft.getFounds()) {
        System.out.println(softFound.getLocalizedBy());
        System.out.println(softFound + " / " + softFound.getReason());
        System.out.println();
    }
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Soft(org.fagu.fmv.soft.Soft) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with SoftFound

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

the class IMInfoTestCase method assertInfo.

/**
 * @param firstLine
 * @param expectedVersion
 * @param expectedDate
 * @param expectedInfo
 * @throws IOException
 */
private void assertInfo(Parser parser, Version expectedVersion, Date expectedDate, String expectedInfo) throws IOException {
    SoftFound softFound = parser.closeAndParse("", 0);
    VersionDateSoftInfo imInfo = (VersionDateSoftInfo) softFound.getSoftInfo();
    assertEquals(expectedVersion, imInfo.getVersion().orElse(null));
    assertEquals(expectedDate, imInfo.getDate().orElse(null));
    assertEquals(expectedInfo, imInfo.getInfo());
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) VersionDateSoftInfo(org.fagu.fmv.soft.find.info.VersionDateSoftInfo)

Example 4 with SoftFound

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

the class GSSoftProviderTestCase method assertInfo.

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

Example 5 with SoftFound

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

the class JavaSoftProviderTestCase 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)

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