Search in sources :

Example 1 with Locators

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

the class JavaSoftProvider method getSoftLocator.

/**
 * @see org.fagu.fmv.soft.find.SoftProvider#getSoftLocator()
 */
@Override
public SoftLocator getSoftLocator() {
    SoftLocator softLocator = new SoftLocator(getName()) {

        /**
         * @see org.fagu.fmv.soft.find.SoftLocator#getLocators(java.lang.String, org.fagu.fmv.soft.find.Locators,
         *      java.io.FileFilter)
         */
        @Override
        protected List<Locator> getLocators(Locators loc) {
            List<Locator> list = super.getLocators(loc);
            Locators locators = createLocators();
            list.add(0, locators.byPropertyPath("java.home"));
            if (SystemUtils.IS_OS_WINDOWS) {
                ProgramFilesLocatorSupplier.with(list::add, locators).find(programFile -> {
                    List<File> files = new ArrayList<>();
                    File[] javaFolders = programFile.listFiles(f -> "java".equalsIgnoreCase(f.getName()));
                    if (javaFolders != null) {
                        for (File folder : javaFolders) {
                            File[] subFolders = folder.listFiles();
                            if (subFolders != null) {
                                for (File subFolder : subFolders) {
                                    files.add(subFolder);
                                    files.add(new File(subFolder, "bin"));
                                }
                            }
                        }
                    }
                    return files;
                }).supplyIn();
            }
            return list;
        }
    };
    softLocator.setSoftPolicy(getSoftPolicy());
    softLocator.setEnvName("JAVA_HOME");
    return softLocator;
}
Also used : SoftFoundFactory(org.fagu.fmv.soft.find.SoftFoundFactory) SoftLocator(org.fagu.fmv.soft.find.SoftLocator) VersionParserManager(org.fagu.version.VersionParserManager) Locators(org.fagu.fmv.soft.find.Locators) SoftPolicy(org.fagu.fmv.soft.find.SoftPolicy) SystemUtils(org.apache.commons.lang3.SystemUtils) Locator(org.fagu.fmv.soft.find.Locator) ProgramFilesLocatorSupplier(org.fagu.fmv.soft.win32.ProgramFilesLocatorSupplier) File(java.io.File) ArrayList(java.util.ArrayList) SoftProvider(org.fagu.fmv.soft.find.SoftProvider) VersionSoftPolicy.minVersion(org.fagu.fmv.soft.find.policy.VersionSoftPolicy.minVersion) List(java.util.List) Matcher(java.util.regex.Matcher) VersionSoftPolicy(org.fagu.fmv.soft.find.policy.VersionSoftPolicy) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Pattern(java.util.regex.Pattern) SoftLocator(org.fagu.fmv.soft.find.SoftLocator) Locator(org.fagu.fmv.soft.find.Locator) SoftLocator(org.fagu.fmv.soft.find.SoftLocator) Locators(org.fagu.fmv.soft.find.Locators) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 2 with Locators

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

the class Soft method withExecFile.

// =============
/**
 * @param execFile
 * @return
 * @throws IOException
 */
public static Soft withExecFile(String execFile) throws IOException {
    File file = new File(execFile);
    if (!execFile.contains("/") && !execFile.contains("\\") && !file.exists()) {
        // search in ENV PATH
        Locators locators = new Locators(PlateformFileFilter.getFileFilter(execFile));
        Locator locator = locators.byEnvPath();
        List<File> locatedFiles = locator.locate(null);
        if (locatedFiles.isEmpty()) {
            throw new FileNotFoundException(execFile);
        }
        Collections.sort(locatedFiles);
        file = locatedFiles.get(0);
    }
    return withExecFile(file);
}
Also used : Locator(org.fagu.fmv.soft.find.Locator) Locators(org.fagu.fmv.soft.find.Locators) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Aggregations

File (java.io.File)2 Locator (org.fagu.fmv.soft.find.Locator)2 Locators (org.fagu.fmv.soft.find.Locators)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ObjectUtils (org.apache.commons.lang3.ObjectUtils)1 SystemUtils (org.apache.commons.lang3.SystemUtils)1 SoftFoundFactory (org.fagu.fmv.soft.find.SoftFoundFactory)1 SoftLocator (org.fagu.fmv.soft.find.SoftLocator)1 SoftPolicy (org.fagu.fmv.soft.find.SoftPolicy)1 SoftProvider (org.fagu.fmv.soft.find.SoftProvider)1 VersionSoftPolicy (org.fagu.fmv.soft.find.policy.VersionSoftPolicy)1 VersionSoftPolicy.minVersion (org.fagu.fmv.soft.find.policy.VersionSoftPolicy.minVersion)1 ProgramFilesLocatorSupplier (org.fagu.fmv.soft.win32.ProgramFilesLocatorSupplier)1 VersionParserManager (org.fagu.version.VersionParserManager)1