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.plugins; 16 : 17 : import com.google.gerrit.server.GerritPersonIdent; 18 : import com.google.gerrit.server.GerritPersonIdentProvider; 19 : import com.google.gerrit.server.config.AnonymousCowardName; 20 : import com.google.gerrit.server.config.GerritIsReplica; 21 : import com.google.gerrit.server.config.GerritIsReplicaProvider; 22 : import com.google.gerrit.server.config.GerritServerConfig; 23 : import com.google.gerrit.server.config.SitePath; 24 : import com.google.gerrit.server.config.SitePaths; 25 : import com.google.gerrit.server.config.TrackingFooters; 26 : import com.google.gerrit.server.git.GitRepositoryManager; 27 : import com.google.gerrit.server.securestore.SecureStore; 28 : import com.google.inject.AbstractModule; 29 : import com.google.inject.Inject; 30 : import com.google.inject.Provides; 31 : import com.google.inject.Singleton; 32 : import java.nio.file.Path; 33 : import org.eclipse.jgit.lib.Config; 34 : import org.eclipse.jgit.lib.PersonIdent; 35 : 36 : /** 37 : * Copies critical objects from the {@code dbInjector} into a plugin. 38 : * 39 : * <p>Most explicit bindings are copied automatically from the cfgInjector and sysInjector to be 40 : * made available to a plugin's private world. This module is necessary to get things bound in the 41 : * dbInjector that are not otherwise easily available, but that a plugin author might expect to 42 : * exist. 43 : */ 44 : @Singleton 45 : class CopyConfigModule extends AbstractModule { 46 : @Inject @SitePath private Path sitePath; 47 : 48 : @Provides 49 : @SitePath 50 : Path getSitePath() { 51 0 : return sitePath; 52 : } 53 : 54 : @Inject private SitePaths sitePaths; 55 : 56 : @Provides 57 : SitePaths getSitePaths() { 58 0 : return sitePaths; 59 : } 60 : 61 : @Inject private TrackingFooters trackingFooters; 62 : 63 : @Provides 64 : TrackingFooters getTrackingFooters() { 65 0 : return trackingFooters; 66 : } 67 : 68 : @Inject @GerritServerConfig private Config gerritServerConfig; 69 : 70 : @Provides 71 : @GerritServerConfig 72 : Config getGerritServerConfig() { 73 3 : return gerritServerConfig; 74 : } 75 : 76 : @Inject private GitRepositoryManager gitRepositoryManager; 77 : 78 : @Provides 79 : GitRepositoryManager getGitRepositoryManager() { 80 3 : return gitRepositoryManager; 81 : } 82 : 83 : @Inject @AnonymousCowardName private String anonymousCowardName; 84 : 85 : @Provides 86 : @AnonymousCowardName 87 : String getAnonymousCowardName() { 88 2 : return anonymousCowardName; 89 : } 90 : 91 : @Inject private GerritPersonIdentProvider serverIdentProvider; 92 : 93 : @Provides 94 : @GerritPersonIdent 95 : PersonIdent getServerIdent() { 96 0 : return serverIdentProvider.get(); 97 : } 98 : 99 : @Inject private SecureStore secureStore; 100 : 101 : @Provides 102 : SecureStore getSecureStore() { 103 0 : return secureStore; 104 : } 105 : 106 : @Inject private GerritIsReplicaProvider isReplicaProvider; 107 : 108 : @Provides 109 : @GerritIsReplica 110 : boolean getIsReplica() { 111 0 : return isReplicaProvider.get(); 112 : } 113 : 114 : @Inject 115 149 : CopyConfigModule() {} 116 : 117 : @Override 118 149 : protected void configure() {} 119 : }