Search in sources :

Example 6 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