/** * Method returns a GitUtil wrapping the master repository. * * @return - GitUtil */ @SneakyThrows public GitUtil masterRepository() { return buildGitUtil(casProperties.getVersionControl().getServicesRepo()); }
/** * If a syncScript is configured it will be executed. * * @throws SyncScriptFailureException - failed. */ private void runSyncScript() throws SyncScriptFailureException { if (managementProperties.getVersionControl().getSyncScript() != null) { try { val status = Runtime.getRuntime().exec(managementProperties.getVersionControl().getSyncScript()).waitFor(); if (status > 0) { LOGGER.error("SyncScript returned value > 0"); throw new SyncScriptFailureException(); } } catch (final IOException e) { LOGGER.error(e.getMessage(), e); throw new SyncScriptFailureException(); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw new SyncScriptFailureException(); } } }
/** * Clones the master repository into the passed in directory. * * @param clone - String representing dir to create the clone * @return - GitUtil */ public GitUtil clone(final String clone) { try { val uri = casProperties.getVersionControl().getServicesRepo() + REPO_DIR; LOGGER.debug("Cloning repository [{}] to path [{}]", uri, clone); return new GitUtil(Git.cloneRepository() .setURI(uri) .setDirectory(new File(clone)) .call()); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); return null; } } }
/** * Init repository. */ @PostConstruct public void initRepository() { val servicesRepo = Paths.get(managementProperties.getVersionControl().getServicesRepo()); if (!Files.exists(servicesRepo)) { try { Git.init().setDirectory(servicesRepo.toFile()).call().commit().setMessage("Created").call(); } catch (final Exception e) { return; } try (GitUtil git = repositoryFactory.masterRepository()) { val manager = new VersionControlServicesManager(createJSONServiceManager(git), namingStrategy, git); manager.loadFrom(servicesManager); git.addWorkingChanges(); git.commit("Initial commit"); git.setPublished(); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } } }