Search in sources :

Example 1 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.

the class ClasspathRepository method buildCategory.

private CategoryDTO buildCategory(String typeId, String typeFileName, String categoryFileName) throws RepositoryException {
    try {
        final String jsonCategoryPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/category.json";
        final URL jsonCategoryFile = getClass().getResource(jsonCategoryPath);
        if (jsonCategoryFile != null) {
            final CategoryDTO categoryDTO = objectMapper.readValue(jsonCategoryFile, CategoryDTO.class);
            CategoryDTO.Builder categoryDTOBuilder = new CategoryDTO.Builder(categoryDTO).withTypeId(typeId).withId(categoryFileName);
            categoryDTOBuilder.withApplications(buildApplications(categoryDTOBuilder.getTypeId(), categoryDTOBuilder.getId(), typeFileName, categoryFileName));
            try {
                categoryDTOBuilder.withIcon(new URI(packagePath + "/" + typeFileName + "/" + categoryFileName + "/icon.png"));
            } catch (URISyntaxException e) {
                LOGGER.warn("Invalid icon path", e);
            }
            return categoryDTOBuilder.build();
        } else {
            LOGGER.debug(String.format("category.json %s for classpath repository does not exist", jsonCategoryPath));
            return new CategoryDTO.Builder().build();
        }
    } catch (IOException e) {
        throw new RepositoryException("Could not build category", e);
    }
}
Also used : ToStringBuilder(org.apache.commons.lang.builder.ToStringBuilder) HashCodeBuilder(org.apache.commons.lang.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) RepositoryException(org.phoenicis.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL)

Example 2 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.

the class ClasspathRepository method buildScripts.

private List<ScriptDTO> buildScripts(String typeId, String categoryId, String applicationId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
    try {
        final String applicationScanClassPath = packagePath + "/" + typeFileName + "/" + 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(typeId, categoryId, applicationId, typeFileName, categoryFileName, applicationFileName, fileName);
                scriptDTOs.add(script);
            }
        }
        scriptDTOs.sort(Comparator.comparing(ScriptDTO::getScriptName));
        return scriptDTOs;
    } catch (IOException e) {
        throw new RepositoryException("Could not build scripts", e);
    }
}
Also used : Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException)

Example 3 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project phoenicis by PhoenicisOrg.

the class GitRepository method fetchInstallableApplications.

@Override
public synchronized RepositoryDTO fetchInstallableApplications() {
    LOGGER.info("Begin fetching process of " + this);
    boolean folderExists = this.localFolder.exists();
    // check that the repository folder exists
    if (!folderExists) {
        LOGGER.info("Creating local folder for " + this);
        if (!this.localFolder.mkdirs()) {
            throw new RepositoryException("Couldn't create local folder for " + this);
        }
    }
    RepositoryDTO result = null;
    Git gitRepository = null;
    try {
        /*
             * if the repository folder previously didn't exist, clone the
             * repository now and checkout the correct branch
             */
        if (!folderExists) {
            LOGGER.info("Cloning " + this);
            gitRepository = Git.cloneRepository().setURI(this.repositoryUri.toString()).setDirectory(this.localFolder).setBranch(this.branch).call();
        } else /*
             * otherwise open the folder and pull the newest updates from the
             * repository
             */
        {
            LOGGER.info("Opening " + this);
            gitRepository = Git.open(localFolder);
            LOGGER.info("Pulling new commits from " + this);
            gitRepository.pull().call();
        }
        result = localRepositoryFactory.createInstance(this.localFolder, this.repositoryUri).fetchInstallableApplications();
    } catch (RepositoryNotFoundException | GitAPIException e) {
        throw new RepositoryException(String.format("Folder '%s' is no git-repository", this.localFolder.getAbsolutePath()), e);
    } catch (IOException e) {
        throw new RepositoryException("An unknown error occurred", e);
    } finally {
        // close repository to free resources
        if (gitRepository != null) {
            gitRepository.close();
        }
    }
    return result;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) RepositoryException(org.phoenicis.repository.RepositoryException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) RepositoryDTO(org.phoenicis.repository.dto.RepositoryDTO)

Example 4 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.

the class ClasspathRepository method buildApplications.

private List<ApplicationDTO> buildApplications(String typeId, String categoryId, String typeFileName, String categoryFileName) throws RepositoryException {
    try {
        final String categoryScanClassPath = packagePath + "/" + typeFileName + "/" + categoryFileName;
        Resource[] resources = resourceResolver.getResources(categoryScanClassPath + "/*");
        final List<ApplicationDTO> applicationDTOS = new ArrayList<>();
        for (Resource resource : resources) {
            final String fileName = resource.getFilename();
            if (!"icon.png".equals(fileName) && !"category.json".equals(fileName)) {
                final ApplicationDTO application = buildApplication(typeId, categoryId, typeFileName, categoryFileName, fileName);
                if (!application.getScripts().isEmpty()) {
                    applicationDTOS.add(application);
                }
            }
        }
        applicationDTOS.sort(Comparator.comparing(ApplicationDTO::getName));
        return applicationDTOS;
    } catch (IOException e) {
        throw new RepositoryException("Could not build applications", e);
    }
}
Also used : Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) RepositoryException(org.phoenicis.repository.RepositoryException) IOException(java.io.IOException)

Example 5 with RepositoryException

use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.

the class ClasspathRepository method buildCategory.

private CategoryDTO buildCategory(String typeId, String typeFileName, String categoryFileName) throws RepositoryException {
    try {
        final String jsonCategoryPath = packagePath + "/" + typeFileName + "/" + categoryFileName + "/category.json";
        final URL jsonCategoryFile = getClass().getResource(jsonCategoryPath);
        if (jsonCategoryFile != null) {
            final CategoryDTO categoryDTO = objectMapper.readValue(jsonCategoryFile, CategoryDTO.class);
            CategoryDTO.Builder categoryDTOBuilder = new CategoryDTO.Builder(categoryDTO).withTypeId(typeId);
            if (StringUtils.isBlank(categoryDTO.getId())) {
                if (!StringUtils.isBlank(categoryDTO.getName())) {
                    categoryDTOBuilder.withId(categoryDTO.getName().replaceAll(INVALID_ID_CHARS_REGEX, ""));
                } else {
                    categoryDTOBuilder.withId(categoryFileName.replaceAll(INVALID_ID_CHARS_REGEX, ""));
                }
            }
            categoryDTOBuilder.withApplications(buildApplications(categoryDTOBuilder.getTypeId(), categoryDTOBuilder.getId(), typeFileName, categoryFileName));
            try {
                categoryDTOBuilder.withIcon(new URI(packagePath + "/" + typeFileName + "/" + categoryFileName + "/icon.png"));
            } catch (URISyntaxException e) {
                LOGGER.warn("Invalid icon path", e);
            }
            return categoryDTOBuilder.build();
        } else {
            LOGGER.debug(String.format("category.json %s for classpath repository does not exist", jsonCategoryPath));
            return new CategoryDTO.Builder().build();
        }
    } catch (IOException e) {
        throw new RepositoryException("Could not build category", e);
    }
}
Also used : RepositoryException(org.phoenicis.repository.RepositoryException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL)

Aggregations

RepositoryException (org.phoenicis.repository.RepositoryException)34 IOException (java.io.IOException)32 URI (java.net.URI)12 URISyntaxException (java.net.URISyntaxException)12 URL (java.net.URL)12 ArrayList (java.util.ArrayList)12 Resource (org.springframework.core.io.Resource)12 EqualsBuilder (org.apache.commons.lang.builder.EqualsBuilder)11 HashCodeBuilder (org.apache.commons.lang.builder.HashCodeBuilder)11 ToStringBuilder (org.apache.commons.lang.builder.ToStringBuilder)11 File (java.io.File)9 InputStream (java.io.InputStream)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FileInputStream (java.io.FileInputStream)3 Arrays (java.util.Arrays)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IOUtils (org.apache.commons.compress.utils.IOUtils)3 StringUtils (org.apache.commons.lang.StringUtils)3