Search in sources :

Example 1 with ScriptDTO

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);
    }
}
Also used : ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) Button(javafx.scene.control.Button) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage)

Example 2 with ScriptDTO

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());
}
Also used : OperatingSystem(org.phoenicis.entities.OperatingSystem) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) CategoryDTO(org.phoenicis.repository.dto.CategoryDTO) List(java.util.List) OperatingSystem(org.phoenicis.entities.OperatingSystem) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) Collectors(java.util.stream.Collectors) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ArrayList(java.util.ArrayList) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) ArrayList(java.util.ArrayList)

Example 3 with ScriptDTO

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();
}
Also used : ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) InputStream(java.io.InputStream) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder)

Example 4 with ScriptDTO

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;
}
Also used : ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) Resource(org.springframework.core.io.Resource)

Example 5 with ScriptDTO

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;
}
Also used : ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

ScriptDTO (org.phoenicis.repository.dto.ScriptDTO)6 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)3 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)3 ToStringBuilder (org.apache.commons.lang.builder.ToStringBuilder)2 AllAvailableArguments (com.github.jankroken.commandline.annotations.AllAvailableArguments)1 LongSwitch (com.github.jankroken.commandline.annotations.LongSwitch)1 Option (com.github.jankroken.commandline.annotations.Option)1 ShortSwitch (com.github.jankroken.commandline.annotations.ShortSwitch)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 Tooltip (javafx.scene.control.Tooltip)1 OperatingSystem (org.phoenicis.entities.OperatingSystem)1 ErrorMessage (org.phoenicis.javafx.views.common.ErrorMessage)1