use of org.fagu.fmv.soft.find.Locator 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;
}
use of org.fagu.fmv.soft.find.Locator in project fmv by f-agu.
the class ProgramFilesLocatorSupplier method supplyIn.
/**
*/
public void supplyIn() {
if (locatorConsumer != null && locators != null) {
for (File programPath : getProgramPaths()) {
for (File folder : foldersToAnalyze.apply(programPath)) {
if (folder.exists()) {
Locator byPath = locators.byPath(folder.getAbsolutePath());
locatorConsumer.accept(Locators.named("win[" + programPath.getName() + "]", byPath));
}
}
}
}
}
use of org.fagu.fmv.soft.find.Locator 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);
}
Aggregations