use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.
the class ClasspathRepository method buildApplication.
private ApplicationDTO buildApplication(String typeId, String categoryId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
try {
final String applicationDirectory = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName;
File applicationJson = new File(applicationDirectory, "application.json");
final ApplicationDTO applicationDTO = objectMapper.readValue(getClass().getResourceAsStream(applicationJson.getAbsolutePath()), ApplicationDTO.class);
ApplicationDTO.Builder applicationDTOBuilder = new ApplicationDTO.Builder(applicationDTO).withTypeId(typeId).withCategoryId(categoryId);
if (StringUtils.isBlank(applicationDTOBuilder.getId())) {
if (!StringUtils.isBlank(applicationDTOBuilder.getName())) {
applicationDTOBuilder.withId(applicationDTOBuilder.getName().replaceAll(INVALID_ID_CHARS_REGEX, ""));
} else {
applicationDTOBuilder.withId(applicationFileName.replaceAll(INVALID_ID_CHARS_REGEX, ""));
}
}
applicationDTOBuilder.withScripts(buildScripts(applicationDTOBuilder.getTypeId(), applicationDTOBuilder.getCategoryId(), applicationDTOBuilder.getId(), typeFileName, categoryFileName, applicationFileName)).withMiniatures(buildMiniatures(typeFileName, categoryFileName, applicationFileName));
return applicationDTOBuilder.build();
} catch (IOException e) {
throw new RepositoryException("Could not build application", e);
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.
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);
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.
the class LocalRepository method fetchInstallableApplications.
@Override
public RepositoryDTO fetchInstallableApplications() {
if (!repositoryDirectory.exists()) {
throw new RepositoryException(String.format("Repository %s directory does not exist.", repositoryDirectory));
}
final File[] typeDirectories = repositoryDirectory.listFiles();
if (typeDirectories == null) {
return new RepositoryDTO.Builder().build();
}
LOGGER.info("Reading directory : " + repositoryDirectory);
final RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder().withName(repositoryDirectory.getName()).withTypes(fetchTypes(typeDirectories));
final File i18nDirectory = new File(repositoryDirectory, "i18n");
if (i18nDirectory.exists()) {
final File[] translationFiles = i18nDirectory.listFiles((dir, name) -> name.endsWith(Locale.getDefault().getLanguage() + ".properties"));
Properties mergedProperties = new Properties();
for (File translationFile : translationFiles) {
try {
Properties langProperties = new Properties();
langProperties.load(new FileInputStream(translationFile));
mergedProperties.putAll(langProperties);
} catch (IOException e) {
LOGGER.error("Could not read translation properties", e);
}
}
repositoryDTOBuilder.withTranslations(new TranslationDTO.Builder().withLanguage(Locale.getDefault().getLanguage()).withProperties(mergedProperties).build());
Localisation.setAdditionalTranslations(new PropertiesResourceBundle(mergedProperties));
}
return repositoryDTOBuilder.build();
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PlayOnLinux.
the class GitRepository method cloneOrUpdateWithLock.
private void cloneOrUpdateWithLock() throws RepositoryException {
synchronized (mutex) {
try {
LOGGER.info("Begin fetching process of '{}' to '{}'", this.repositoryUri, this.localFolder.getAbsolutePath());
boolean lockFileExists = this.lockFile.exists();
// check that the repository lock file exists
if (!lockFileExists) {
LOGGER.info("Creating lock file '{}' for git-repository '{}'", this.lockFile.getAbsolutePath(), this.repositoryUri);
try {
this.lockFile.getParentFile().mkdirs();
this.lockFile.createNewFile();
} catch (IOException e) {
final String message = String.format("Couldn't create lock file '%s'", this.lockFile.getAbsolutePath());
throw new RepositoryException(message, e);
}
}
try (FileOutputStream lockFileStream = new FileOutputStream(lockFile, true)) {
try (FileLock ignored = lockFileStream.getChannel().lock()) {
cloneOrUpdate();
}
}
} catch (IOException e) {
throw new RepositoryException("An unknown error occurred", e);
}
}
}
use of org.phoenicis.repository.RepositoryException in project POL-POM-5 by PhoenicisOrg.
the class ClasspathRepository method buildApplication.
private ApplicationDTO buildApplication(String typeId, String categoryId, String typeFileName, String categoryFileName, String applicationFileName) throws RepositoryException {
try {
final String applicationDirectory = packagePath + "/" + typeFileName + "/" + categoryFileName + "/" + applicationFileName;
File applicationJson = new File(applicationDirectory, "application.json");
final ApplicationDTO applicationDTO = objectMapper.readValue(getClass().getResourceAsStream(applicationJson.getAbsolutePath()), ApplicationDTO.class);
ApplicationDTO.Builder applicationDTOBuilder = new ApplicationDTO.Builder(applicationDTO).withTypeId(typeId).withCategoryId(categoryId);
if (StringUtils.isBlank(applicationDTOBuilder.getId())) {
if (!StringUtils.isBlank(applicationDTOBuilder.getName())) {
applicationDTOBuilder.withId(applicationDTOBuilder.getName().replaceAll(INVALID_ID_CHARS_REGEX, ""));
} else {
applicationDTOBuilder.withId(applicationFileName.replaceAll(INVALID_ID_CHARS_REGEX, ""));
}
}
applicationDTOBuilder.withScripts(buildScripts(applicationDTOBuilder.getTypeId(), applicationDTOBuilder.getCategoryId(), applicationDTOBuilder.getId(), typeFileName, categoryFileName, applicationFileName)).withMiniatures(buildMiniatures(typeFileName, categoryFileName, applicationFileName));
return applicationDTOBuilder.build();
} catch (IOException e) {
throw new RepositoryException("Could not build application", e);
}
}
Aggregations