Line data Source code
1 : // Copyright (C) 2009 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; 16 : 17 : import static com.google.common.base.MoreObjects.firstNonNull; 18 : 19 : import com.google.gerrit.server.config.GerritServerConfig; 20 : import com.google.inject.Inject; 21 : import com.google.inject.Provider; 22 : import com.google.inject.Singleton; 23 : import org.eclipse.jgit.lib.Config; 24 : import org.eclipse.jgit.lib.PersonIdent; 25 : import org.eclipse.jgit.lib.UserConfig; 26 : 27 : /** Provides {@link PersonIdent} annotated with {@link GerritPersonIdent}. */ 28 : @Singleton 29 : public class GerritPersonIdentProvider implements Provider<PersonIdent> { 30 : private final String name; 31 : private final String email; 32 : 33 : @Inject 34 151 : public GerritPersonIdentProvider(@GerritServerConfig Config cfg) { 35 151 : StringBuilder name = new StringBuilder(); 36 151 : PersonIdent.appendSanitized( 37 151 : name, firstNonNull(cfg.getString("user", null, "name"), "Gerrit Code Review")); 38 151 : this.name = name.toString(); 39 : 40 151 : StringBuilder email = new StringBuilder(); 41 151 : PersonIdent.appendSanitized(email, cfg.get(UserConfig.KEY).getCommitterEmail()); 42 151 : this.email = email.toString(); 43 151 : } 44 : 45 : @Override 46 : public PersonIdent get() { 47 151 : return new PersonIdent(name, email); 48 : } 49 : }