private static void initaliseGitStuff() throws Exception { GitFacade gitFacade = new GitFacade(); gitFacade.setCloneRemoteRepoOnStartup(false); gitFacade.setPullOnStartup(false); gitFacade.setConfigDirName("hawtio-config"); String importUrls = System.getenv("JUBE_IMPORT_URLS"); if (importUrls != null) { gitFacade.setInitialImportURLs(importUrls); } gitFacade.init(); }
public CommitInfo call() throws Exception { checkoutBranch(git, branch); File rootDir = getRootGitDirectory(); return doCreateDirectory(git, rootDir, branch, path, personIdent, commitMessage); } });
public GitFacade getGit() { if (git == null) { LOG.info("No GitFacade injected! Defaulting to the singleton"); git = GitFacade.getSingleton(); } return git; }
@Override public T call() throws Exception { return doReadFile(git, getRootGitDirectory(), branch, pathOrEmpty, callback); } });
@Override public T call() throws Exception { return doWriteFile(git, getRootGitDirectory(), branch, pathOrEmpty, callback); } });
/** * Note we pass in the {@link io.hawt.aether.AetherFacade} to ensure that the mvn: URL handler is initialised first before we * start to lazily create the git repository * * @param importUrls the list of app zips URLs to be imported to the library on startup. Supports mvn:group/artifact/version/type/classifier formats in addition to http:, file: etc. */ @Produces @Singleton public GitFacade createGit(@ConfigProperty(name = "IMPORT_APP_URLS") String importUrls, AetherFacade aether) throws Exception { GitFacade git = new GitFacade(); System.out.println("Importing urls: " + importUrls); git.setInitialImportURLs(importUrls); git.setCloneRemoteRepoOnStartup(false); File configDir = new File("library"); if (configDir.exists()) { Files.recursiveDelete(configDir); } configDir.mkdirs(); git.setConfigDirectory(configDir); git.init(); System.out.println("Created library at at: " + configDir.getAbsolutePath()); return git; }
public void initialiseGitRepo() throws IOException, GitAPIException { File confDir = getRootGitDirectory(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); File gitDir = new File(confDir, ".git"); if (!gitDir.exists()) { String repo = getRemoteRepository(); if (Strings.isNotBlank(repo) && isCloneRemoteRepoOnStartup()) { boolean cloneAll = isCloneAllBranches(); LOG.info("Cloning git repo " + repo + " into directory " + confDir.getCanonicalPath() + " cloneAllBranches: " + cloneAll); CloneCommand command = Git.cloneRepository().setCredentialsProvider(getCredentials()). setCloneAllBranches(cloneAll).setURI(repo).setDirectory(confDir).setRemote(remote); try { } else if (!isCloneRemoteRepoOnStartup()) { LOG.info("Clone git repo on startup disabled"); configureBranch(branch); importInitialContent(git, confDir, branch); } else { Repository repository = builder.setGitDir(gitDir) if (isPullOnStartup()) { doPull(); } else { LOG.info("git pull from remote config repo on startup is disabled");
public void contextInitialized(ServletContextEvent servletContextEvent) { try { ServletContext context = servletContextEvent.getServletContext(); String configDir = context.getInitParameter("hawtio.config.dir"); if (configDir != null) { helper.setConfigDirectory(new File(configDir)); } String repo = context.getInitParameter("hawtio.config.repo"); if (repo != null) { helper.setRemoteRepository(repo); } String cloneRemoteRepoOnStartup = context.getInitParameter("hawtio.config.cloneOnStartup"); if (cloneRemoteRepoOnStartup != null && cloneRemoteRepoOnStartup.equals("false")) { helper.setCloneRemoteRepoOnStartup(false); } helper.init(); } catch (Exception e) { throw createServletException(e); } }
@Override public String iconPath(final String branch, final String kubernetesId) throws Exception { GitFacade facade = getGit(); return facade.readFile(branch, "/", new Function<File, String>() { @Override public String apply(File rootFolder) { return doFindIconPath(rootFolder, kubernetesId); } }); }
public CommitInfo call() throws Exception { checkoutBranch(git, branch); File rootDir = getRootGitDirectory(); return doWrite(git, rootDir, branch, path, data, personIdent, commitMessage); } });
@Override public void init(final ServletConfig config) throws ServletException { gitFacade = GitFacade.getSingleton(); validateGitFacade(); String basePath = gitFacade.getRootGitDirectory().getAbsoluteFile().getParentFile().getAbsolutePath(); System.out.println("Exposing git base path at: " + basePath); final Hashtable<String,String> initParams = new Hashtable<>(); initParams.put("base-path", basePath); initParams.put("repository-root", basePath); initParams.put("export-all", "true"); ServletConfig gitConfig = new ServletConfig() { @Override public String getServletName() { return config.getServletName(); } @Override public ServletContext getServletContext() { return config.getServletContext(); } @Override public String getInitParameter(String paramName) { return initParams.get(paramName); } @Override public Enumeration<String> getInitParameterNames() { return initParams.keys(); } }; super.init(gitConfig); }
protected void doPull() { CredentialsProvider cp = getCredentials(); try { Repository repository = git.getRepository(); StoredConfig config = repository.getConfig(); String url = config.getString("remote", "origin", "url"); if (Strings.isBlank(url)) { logPull("No remote repository defined for the git repository at " + getRootGitDirectory().getCanonicalPath() + " so not doing a pull"); return; } String branch = repository.getBranch(); String mergeUrl = config.getString("branch", branch, "merge"); if (Strings.isBlank(mergeUrl)) { logPull("No merge spec for branch." + branch + ".merge in the git repository at " + getRootGitDirectory().getCanonicalPath() + " so not doing a pull"); return; } logPull("Performing a pull in git repository " + getRootGitDirectory().getCanonicalPath() + " on remote URL: " + url); git.pull().setCredentialsProvider(cp).setRebase(true).call(); } catch (Throwable e) { String credText = ""; if (cp instanceof UsernamePasswordCredentialsProvider) { } LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage() + ". This exception is ignored.", e); } finally { firstPull = false; } }
@Override public FileInfo call() throws Exception { File rootDir = getRootGitDirectory(); return doExists(git, rootDir, branch, pathOrEmpty, false); } });
@Override public String call() throws Exception { File rootDir = getRootGitDirectory(); return doReadJsonChildContent(git, rootDir, branch, path, fileNameWildcard, search); } });
public RevCommit call() throws Exception { File rootDir = getRootGitDirectory(); return doRename(git, rootDir, branch, oldPath, newPath, commitMessage, personIdent); } });
public RevCommit call() throws Exception { Git aGit = git; File rootDir = getRootGitDirectory(); return doRemove(aGit, rootDir, branch, path, commitMessage, personIdent); } });
@Override public FileContents call() throws Exception { return doRead(git, getRootGitDirectory(), branch, pathOrEmpty); } });
@Override public List<String> call() throws Exception { File rootDir = getRootGitDirectory(); return doCompletePath(git, rootDir, branch, completionText, directoriesOnly); } });
@Override public Void call() throws Exception { Git aGit = git; File rootDir = getRootGitDirectory(); return doRevert(aGit, rootDir, branch, objectId, blobPath, commitMessage, personIdent); } });
/** * Uploads a list of files to the given branch and path */ public void uploadFiles(String branch, String path, final boolean unzip, final Map<String, File> uploadFiles) throws IOException, GitAPIException { LOG.info("uploadFiles: branch: " + branch + " path: " + path + " unzip: " + unzip + " uploadFiles: " + uploadFiles); WriteCallback<Object> callback = new WriteCallback<Object>() { @Override public Object apply(WriteContext context) throws IOException, GitAPIException { File folder = context.getFile(); // lets copy the files into the folder so we can add them to git List<File> copiedFiles = new ArrayList<>(); Set<Map.Entry<String, File>> entries = uploadFiles.entrySet(); for (Map.Entry<String, File> entry : entries) { String name = entry.getKey(); File uploadFile = entry.getValue(); File copiedFile = new File(folder, name); Files.copy(uploadFile, copiedFile); copiedFiles.add(copiedFile); } doUploadFiles(context, folder, unzip, copiedFiles); return null; } }; writeFile(branch, path, callback); }