public static void reconfigure(FileBasedRepositoryConfiguration fileBasedRepositoryConfiguration) { RepositoryFactory.fileBasedRepositoryConfiguration = fileBasedRepositoryConfiguration; RepositoryFactory.gitBasedRepositoryConfiguration = null; RepositoryFactory.jCloudsConfiguration = null; repository = new FilebasedRepository(fileBasedRepositoryConfiguration); }
protected static Path determineAndCreateRepositoryPath() { Path repositoryPath; if (SystemUtils.IS_OS_WINDOWS) { if (Files.exists(Constants.GLOBAL_REPO_PATH_WINDOWS)) { repositoryPath = Constants.GLOBAL_REPO_PATH_WINDOWS; } else { repositoryPath = createDefaultRepositoryPath(); } } else { repositoryPath = createDefaultRepositoryPath(); } return repositoryPath; }
@Override public void rename(DefinitionsChildId oldId, DefinitionsChildId newId) throws IOException { this.duplicate(oldId, newId, true); }
/** * @param fileBasedRepositoryConfiguration configuration of the filebased repository. The contained repositoryPath * may be null */ public FilebasedRepository(FileBasedRepositoryConfiguration fileBasedRepositoryConfiguration) { Objects.requireNonNull(fileBasedRepositoryConfiguration); this.repositoryRoot = getRepositoryRoot(fileBasedRepositoryConfiguration); this.fileSystem = this.repositoryRoot.getFileSystem(); this.provider = this.fileSystem.provider(); LOGGER.debug("Repository root: {}", this.repositoryRoot); }
@Override public NamespaceManager getNamespaceManager() { NamespaceManager manager; RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new NamespacesId()); manager = new JsonBasedNamespaceManager(ref2AbsolutePath(ref).toFile()); Configuration configuration = this.getConfiguration(new NamespacesId()); if (!configuration.isEmpty()) { ConfigurationBasedNamespaceManager old = new ConfigurationBasedNamespaceManager(configuration); manager.replaceAll(old.getAllNamespaces()); try { forceDelete(BackendUtils.getRefOfConfiguration(new NamespacesId())); } catch (IOException e) { LOGGER.error("Could not remove old namespace configuration.", e); } } return manager; }
private static Path createDefaultRepositoryPath() { File repo = null; boolean operationalFileSystemAccess; try { repo = FilebasedRepository.getDefaultRepositoryFilePath(); operationalFileSystemAccess = true; } catch (NullPointerException e) { // it seems, we run at a system, where we do not have any filesystem // access operationalFileSystemAccess = false; } // operationalFileSystemAccess = false; Path repositoryPath; if (operationalFileSystemAccess) { try { org.apache.commons.io.FileUtils.forceMkdir(repo); } catch (IOException e) { FilebasedRepository.LOGGER.error("Could not create directory", e); } repositoryPath = repo.toPath(); } else { // we do not have access to the file system throw new IllegalStateException("No write access to file system"); } return repositoryPath; }
public static Path getRepositoryRoot(FileBasedRepositoryConfiguration fileBasedRepositoryConfiguration) { if (fileBasedRepositoryConfiguration.getRepositoryPath().isPresent()) { return makeAbsoluteAndCreateRepositoryPath(fileBasedRepositoryConfiguration.getRepositoryPath().get()); } else { return determineAndCreateRepositoryPath(); } }
public List<ComplianceRuleId> getRuleIds(TServiceTemplate serviceTemplate) { List<ComplianceRuleId> complianceRules = new ArrayList<>(); Namespace namespace = new Namespace(serviceTemplate.getTargetNamespace(), false); Collection<Namespace> componentsNamespaces = RepositoryFactory.getRepository().getComponentsNamespaces(ComplianceRuleId.class); List<Namespace> relevantNamespaces = componentsNamespaces.stream() .filter(ns -> namespace.getDecoded().startsWith( ns.getDecoded().split("/compliancerules")[0] ) ).collect(Collectors.toList()); for (Namespace space : relevantNamespaces) { complianceRules.addAll((Collection<? extends ComplianceRuleId>) ((FilebasedRepository) RepositoryFactory.getRepository()).getAllIdsInNamespace(ComplianceRuleId.class, space)); } return complianceRules; }
public static void main(String[] args) throws Exception { // Initialize repository new Prefs(true); Server server = createHttpServer(); server.start(); IRepository repository = RepositoryFactory.getRepository(); if (repository instanceof FilebasedRepository) { LOGGER.debug("Using path " + ((FilebasedRepository) repository).getRepositoryRoot()); } else { LOGGER.debug("Repository is not filebased"); } // Waits until server is finished. // Will never happen, thus user has to press Ctrl+C. // See also https://stackoverflow.com/a/14981621/873282. server.join(); } }
File propFile = new File(FilebasedRepository.getDefaultRepositoryFilePath(), "winery.properties"); Prefs.LOGGER.info("Trying " + propFile.getAbsolutePath()); if (propFile.exists()) {
System.out.println("Using repository path " + ((FilebasedRepository) repository).getRepositoryRoot() + "..."); } else { System.out.println("Using non-filebased repository");
public static IRepository getRepository(FileBasedRepositoryConfiguration fileBasedRepositoryConfiguration) { // FIXME: currently, the CSAR export does not reuse the repository instance returned here. Thus, we have to reconfigure the repository. // This should be fixed by always passing IRepository when working with the repository reconfigure(fileBasedRepositoryConfiguration); return new FilebasedRepository(Objects.requireNonNull(fileBasedRepositoryConfiguration)); } }
@Override public void duplicate(DefinitionsChildId from, DefinitionsChildId newId) throws IOException { this.duplicate(from, newId, false); }
/** * Reconfigures based on Environment */ public static void reconfigure() throws Exception { final Optional<JCloudsConfiguration> jCloudsConfiguration = Environment.getJCloudsConfiguration(); if (jCloudsConfiguration.isPresent()) { reconfigure(jCloudsConfiguration.get()); } else { final Optional<GitBasedRepositoryConfiguration> gitBasedRepositoryConfiguration = Environment.getGitBasedRepositoryConfiguration(); final FileBasedRepositoryConfiguration filebasedRepositoryConfiguration = Environment.getFilebasedRepositoryConfiguration().orElse(new FileBasedRepositoryConfiguration()); // Determine whether the filebased repository could be git repository. // We do not use JGit's capabilities, but do it just by checking for the existance of a ".git" directory. final Path repositoryRoot = FilebasedRepository.getRepositoryRoot(filebasedRepositoryConfiguration); final Path gitDirectory = repositoryRoot.resolve(".git"); boolean isGit = (Files.exists(gitDirectory) && Files.isDirectory(gitDirectory)); if (gitBasedRepositoryConfiguration.isPresent()) { reconfigure(gitBasedRepositoryConfiguration.get()); } else if (isGit) { reconfigure(new GitBasedRepositoryConfiguration(false, filebasedRepositoryConfiguration)); } else { reconfigure(filebasedRepositoryConfiguration); } } }