use of org.phoenicis.repository.dto.ScriptDTO in project POL-POM-5 by PlayOnLinux.
the class AppPanel method refreshScripts.
/**
* Refreshes the shown scripts.
* When this method is called it begins by clearing the <code>scriptGrid</code>.
* Afterwards this method refills it.
*/
private void refreshScripts() {
scriptGrid.getChildren().clear();
for (int i = 0; i < filteredScripts.size(); i++) {
ScriptDTO script = filteredScripts.get(i);
Label scriptName = new Label(script.getScriptName());
if (settingsManager.isViewScriptSource()) {
final Tooltip tooltip = new Tooltip(tr("Source: {0}", script.getScriptSource()));
Tooltip.install(scriptName, tooltip);
}
Button installButton = new Button(tr("Install"));
installButton.setOnMouseClicked(evt -> {
try {
onScriptInstall.accept(script);
} catch (IllegalArgumentException e) {
LOGGER.error("Failed to get script", e);
new ErrorMessage(tr("Error while trying to download the installer"), e).show();
}
});
scriptGrid.addRow(i, scriptName, installButton);
GridPane.setHgrow(scriptName, Priority.ALWAYS);
}
}
use of org.phoenicis.repository.dto.ScriptDTO in project POL-POM-5 by PlayOnLinux.
the class FilterRepository method fetchInstallableApplications.
@Override
public List<CategoryDTO> fetchInstallableApplications() {
final OperatingSystem currentOperatingSystem = operatingSystemFetcher.fetchCurrentOperationSystem();
final List<CategoryDTO> categories = repository.fetchInstallableApplications();
return categories.stream().map(category -> {
final List<ApplicationDTO> applications = new ArrayList<>();
for (ApplicationDTO application : category.getApplications()) {
List<ScriptDTO> scripts = application.getScripts();
if (!enforceIncompatibleOperatingSystems) {
scripts = application.getScripts().stream().filter(script -> script.getCompatibleOperatingSystems() == null || script.getCompatibleOperatingSystems().contains(currentOperatingSystem)).collect(Collectors.toList());
}
if (!scripts.isEmpty()) {
applications.add(new ApplicationDTO.Builder(application).withScripts(scripts).build());
}
}
return new CategoryDTO.Builder(category).withApplications(applications).build();
}).filter(category -> !category.getApplications().isEmpty()).collect(Collectors.toList());
}
use of org.phoenicis.repository.dto.ScriptDTO in project POL-POM-5 by PlayOnLinux.
the class ClasspathRepository method buildScript.
private ScriptDTO buildScript(String categoryFileName, String applicationFileName, String scriptFileName) throws IOException {
final String scriptJsonFile = packagePath + "/" + categoryFileName + "/" + applicationFileName + "/" + scriptFileName + "/script.json";
final InputStream scriptJsonInputStream = getClass().getResourceAsStream(scriptJsonFile);
final InputStream scriptFile = getClass().getResourceAsStream(packagePath + "/" + categoryFileName + "/" + applicationFileName + "/" + scriptFileName + "/script.js");
if (scriptJsonInputStream == null) {
return null;
}
return new ScriptDTO.Builder(objectMapper.readValue(scriptJsonInputStream, ScriptDTO.class)).withScript(new String(IOUtils.toByteArray(scriptFile))).build();
}
use of org.phoenicis.repository.dto.ScriptDTO in project POL-POM-5 by PlayOnLinux.
the class ClasspathRepository method buildScripts.
private List<ScriptDTO> buildScripts(String categoryFileName, String applicationFileName) throws IOException {
final String applicationScanClassPath = packagePath + "/" + categoryFileName + "/" + applicationFileName;
Resource[] resources = resourceResolver.getResources(applicationScanClassPath + "/*");
final List<ScriptDTO> scriptDTOs = new ArrayList<>();
for (Resource resource : resources) {
final String fileName = resource.getFilename();
if (!"resources".equals(fileName) && !"miniatures".equals(fileName) && !"application.json".equals(fileName)) {
final ScriptDTO script = buildScript(categoryFileName, applicationFileName, fileName);
scriptDTOs.add(script);
}
}
Collections.sort(scriptDTOs, Comparator.comparing(ScriptDTO::getScriptName));
return scriptDTOs;
}
use of org.phoenicis.repository.dto.ScriptDTO in project POL-POM-5 by PlayOnLinux.
the class LocalRepository method fetchScripts.
private List<ScriptDTO> fetchScripts(File applicationDirectory) {
final File[] scriptDirectories = applicationDirectory.listFiles();
if (scriptDirectories == null) {
return Collections.emptyList();
}
final List<ScriptDTO> results = new ArrayList<>();
for (File scriptDirectory : scriptDirectories) {
if (scriptDirectory.isDirectory() && !"miniatures".equals(scriptDirectory.getName()) && !"resources".equals(scriptDirectory.getName())) {
final ScriptDTO.Builder scriptDTOBuilder = new ScriptDTO.Builder(unSerializeScript(new File(scriptDirectory, "script.json")));
scriptDTOBuilder.withScriptSource(repositorySource);
if (StringUtils.isBlank(scriptDTOBuilder.getScriptName())) {
scriptDTOBuilder.withScriptName(scriptDirectory.getName());
}
final File scriptFile = new File(scriptDirectory, "script.js");
if (scriptFile.exists()) {
try {
scriptDTOBuilder.withScript(new String(IOUtils.toByteArray(new FileInputStream(scriptFile))));
} catch (IOException e) {
LOGGER.warn("Script not found", e);
}
}
results.add(scriptDTOBuilder.build());
}
}
return results;
}
Aggregations