/** * 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); }
@Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { validateGitFacade(); String branch = "master"; String path = null; try { gitFacade.writeFile(branch, path, new WriteCallback<Object>() { @Override public Object apply(WriteContext writeContext) throws IOException, GitAPIException { try { System.out.println("Invoking request on " + req.getServletPath() + " to git servlet"); GitServletFacade.super.service(req, resp); } catch (ServletException e) { throw new IOException(e); } return null; } }); } catch (GitAPIException e) { throw new IOException(e); } }
gitFacade.writeFile(branch, path, callback); } catch (GitAPIException e) { throw new ServletException("Failed to read file: " + path + " on branch " + branch + ". " + e, e);