List of usage examples for org.eclipse.jgit.transport PostReceiveHook PostReceiveHook
PostReceiveHook
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemProvider.java
License:Apache License
private void buildAndStartDeamon() { deamonService = new Daemon(new InetSocketAddress(DEAMON_HOST, DEAMON_PORT)); deamonService.getService("git-receive-pack").setEnabled(DEAMON_UPLOAD); deamonService.setRepositoryResolver(new RepositoryResolverImpl()); deamonService.setReceivePackFactory(new ReceivePackFactory<DaemonClient>() { @Override/* www . ja v a 2s.co m*/ public ReceivePack create(final DaemonClient req, final Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { return new ReceivePack(db) { { final ClusterService clusterService = clusterMap.get(db); final JGitFileSystem fs = repoIndex.get(db); final String treeRef = "master"; final ObjectId oldHead = JGitUtil.getTreeRefObjectId(db, treeRef); setPreReceiveHook(new PreReceiveHook() { @Override public void onPreReceive(final ReceivePack rp, final Collection<ReceiveCommand> commands) { if (clusterService != null) { clusterService.lock(); } } }); setPostReceiveHook(new PostReceiveHook() { @Override public void onPostReceive(final ReceivePack rp, final Collection<ReceiveCommand> commands) { final ObjectId newHead = JGitUtil.getTreeRefObjectId(db, treeRef); notifyDiffs(fs, treeRef, oldHead, newHead); if (clusterService != null) { clusterService.broadcast(new MessageType() { @Override public String toString() { return "SYNC_FS"; } @Override public int hashCode() { return "SYNC_FS".hashCode(); } }, new HashMap<String, String>() { { put("fs_scheme", "git"); put("fs_id", fs.id()); put("fs_uri", fs.toString()); } }); clusterService.unlock(); } } }); } }; } }); try { deamonService.start(); } catch (java.io.IOException e) { throw new IOException(e); } }
From source file:org.uberfire.java.nio.fs.jgit.JGitFileSystemProvider.java
License:Apache License
private void buildAndStartSSH() { final ReceivePackFactory receivePackFactory = new ReceivePackFactory<BaseGitCommand>() { @Override//from w ww. j a v a2 s . c o m public ReceivePack create(final BaseGitCommand req, final Repository db) throws ServiceNotEnabledException, ServiceNotAuthorizedException { return new ReceivePack(db) { { final ClusterService clusterService = clusterMap.get(db); final JGitFileSystem fs = repoIndex.get(db); final Map<String, ObjectId> oldTreeRefs = new HashMap<String, ObjectId>(); setPreReceiveHook(new PreReceiveHook() { @Override public void onPreReceive(final ReceivePack rp, final Collection<ReceiveCommand> commands) { if (clusterService != null) { clusterService.lock(); } for (final ReceiveCommand command : commands) { oldTreeRefs.put(command.getRefName(), JGitUtil.getTreeRefObjectId(db, command.getRefName())); } } }); setPostReceiveHook(new PostReceiveHook() { @Override public void onPostReceive(final ReceivePack rp, final Collection<ReceiveCommand> commands) { for (Map.Entry<String, ObjectId> oldTreeRef : oldTreeRefs.entrySet()) { notifyDiffs(fs, oldTreeRef.getKey(), "<ssh>", req.getUser().getName(), oldTreeRef.getValue(), JGitUtil.getTreeRefObjectId(db, oldTreeRef.getKey())); } if (clusterService != null) { //TODO {porcelli} hack, that should be addressed in future clusterService.broadcast(DEFAULT_IO_SERVICE_NAME, new MessageType() { @Override public String toString() { return "SYNC_FS"; } @Override public int hashCode() { return "SYNC_FS".hashCode(); } }, new HashMap<String, String>() { { put("fs_scheme", "git"); put("fs_id", fs.id()); put("fs_uri", fs.toString()); } }); clusterService.unlock(); } } }); } }; } }; gitSSHService = new GitSSHService(); gitSSHService.setup(SSH_FILE_CERT_DIR, SSH_HOST_ADDR, SSH_PORT, authenticationManager, authorizationManager, receivePackFactory, new RepositoryResolverImpl<BaseGitCommand>()); gitSSHService.start(); }
From source file:org.webcat.core.git.http.ReceivePackRequestHandler.java
License:Open Source License
/** * Handles the request and generates the ReceivePack response. * * @param request the request//from ww w . ja va2 s. com * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE); if (RECEIVE_PACK_REQUEST_TYPE.equals(contentType)) { final Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); ReceivePack rp = new ReceivePack(repo); rp.setBiDirectionalPipe(false); rp.setPostReceiveHook(new PostReceiveHook() { public void onPostReceive(ReceivePack pack, Collection<ReceiveCommand> commands) { // Once the pack is received, force a pull of the working // copy so that anyone using Web-DAV will get synched. GitUtilities.workingCopyForRepository(repo, true); } }); response.setHeader(RECEIVE_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE); InputStream input = RequestUtils.inputStreamForRequest(request); SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response); rp.receive(input, output, null); output.close(); } else { response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE); } }