Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.events; 16 : 17 : import com.google.common.collect.ImmutableListMultimap; 18 : import com.google.gerrit.entities.Project; 19 : import com.google.gerrit.server.IdentifiedUser; 20 : import java.io.IOException; 21 : import org.eclipse.jgit.lib.Config; 22 : import org.eclipse.jgit.lib.ObjectId; 23 : import org.eclipse.jgit.lib.ObjectReader; 24 : import org.eclipse.jgit.revwalk.RevCommit; 25 : import org.eclipse.jgit.revwalk.RevWalk; 26 : import org.eclipse.jgit.transport.ReceiveCommand; 27 : 28 : public class CommitReceivedEvent extends RefEvent implements AutoCloseable { 29 : static final String TYPE = "commit-received"; 30 : public ReceiveCommand command; 31 : public Project project; 32 : public String refName; 33 : public ImmutableListMultimap<String, String> pushOptions; 34 : public Config repoConfig; 35 : public RevWalk revWalk; 36 : public RevCommit commit; 37 : public IdentifiedUser user; 38 : 39 : public CommitReceivedEvent() { 40 110 : super(TYPE); 41 110 : } 42 : 43 : public CommitReceivedEvent( 44 : ReceiveCommand command, 45 : Project project, 46 : String refName, 47 : ImmutableListMultimap<String, String> pushOptions, 48 : Config repoConfig, 49 : ObjectReader reader, 50 : ObjectId commitId, 51 : IdentifiedUser user) 52 : throws IOException { 53 110 : this(); 54 110 : this.command = command; 55 110 : this.project = project; 56 110 : this.refName = refName; 57 110 : this.pushOptions = pushOptions; 58 110 : this.repoConfig = repoConfig; 59 110 : this.revWalk = new RevWalk(reader); 60 110 : this.commit = revWalk.parseCommit(commitId); 61 110 : this.user = user; 62 110 : revWalk.parseBody(commit); 63 110 : } 64 : 65 : @Override 66 : public Project.NameKey getProjectNameKey() { 67 110 : return project.getNameKey(); 68 : } 69 : 70 : @Override 71 : public String getRefName() { 72 110 : return refName; 73 : } 74 : 75 : @Override 76 : public void close() { 77 110 : revWalk.close(); 78 110 : } 79 : }