commit | author | age
|
cacf8b
|
1 |
/* |
JM |
2 |
* Copyright 2013 gitblit.com. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
package com.gitblit; |
|
17 |
|
|
18 |
import javax.inject.Singleton; |
|
19 |
|
04a985
|
20 |
import com.gitblit.manager.AuthenticationManager; |
269c50
|
21 |
import com.gitblit.manager.FederationManager; |
04a985
|
22 |
import com.gitblit.manager.IAuthenticationManager; |
cacf8b
|
23 |
import com.gitblit.manager.IFederationManager; |
3a9e76
|
24 |
import com.gitblit.manager.IGitblit; |
cacf8b
|
25 |
import com.gitblit.manager.INotificationManager; |
41a7e4
|
26 |
import com.gitblit.manager.IPluginManager; |
cacf8b
|
27 |
import com.gitblit.manager.IProjectManager; |
JM |
28 |
import com.gitblit.manager.IRepositoryManager; |
|
29 |
import com.gitblit.manager.IRuntimeManager; |
|
30 |
import com.gitblit.manager.IUserManager; |
bdfdc9
|
31 |
import com.gitblit.manager.NotificationManager; |
41a7e4
|
32 |
import com.gitblit.manager.PluginManager; |
a1f27e
|
33 |
import com.gitblit.manager.ProjectManager; |
95cdba
|
34 |
import com.gitblit.manager.RepositoryManager; |
e24670
|
35 |
import com.gitblit.manager.RuntimeManager; |
8f1c9f
|
36 |
import com.gitblit.manager.UserManager; |
245836
|
37 |
import com.gitblit.transport.ssh.FileKeyManager; |
JM |
38 |
import com.gitblit.transport.ssh.IPublicKeyManager; |
|
39 |
import com.gitblit.transport.ssh.MemoryKeyManager; |
|
40 |
import com.gitblit.transport.ssh.NullKeyManager; |
|
41 |
import com.gitblit.utils.StringUtils; |
cacf8b
|
42 |
import com.gitblit.wicket.GitBlitWebApp; |
JM |
43 |
|
|
44 |
import dagger.Module; |
|
45 |
import dagger.Provides; |
|
46 |
|
|
47 |
/** |
|
48 |
* DaggerModule references all injectable objects. |
|
49 |
* |
|
50 |
* @author James Moger |
|
51 |
* |
|
52 |
*/ |
|
53 |
@Module( |
269c50
|
54 |
library = true, |
cacf8b
|
55 |
injects = { |
e24670
|
56 |
IStoredSettings.class, |
JM |
57 |
|
cacf8b
|
58 |
// core managers |
JM |
59 |
IRuntimeManager.class, |
41a7e4
|
60 |
IPluginManager.class, |
cacf8b
|
61 |
INotificationManager.class, |
JM |
62 |
IUserManager.class, |
04a985
|
63 |
IAuthenticationManager.class, |
245836
|
64 |
IPublicKeyManager.class, |
cacf8b
|
65 |
IRepositoryManager.class, |
JM |
66 |
IProjectManager.class, |
|
67 |
IFederationManager.class, |
|
68 |
|
325396
|
69 |
// the monolithic manager |
3a9e76
|
70 |
IGitblit.class, |
325396
|
71 |
|
65d5bb
|
72 |
// the Gitblit Wicket app |
JM |
73 |
GitBlitWebApp.class |
245836
|
74 |
} |
cacf8b
|
75 |
) |
JM |
76 |
public class DaggerModule { |
|
77 |
|
e24670
|
78 |
@Provides @Singleton IStoredSettings provideSettings() { |
JM |
79 |
return new FileSettings(); |
|
80 |
} |
|
81 |
|
|
82 |
@Provides @Singleton IRuntimeManager provideRuntimeManager(IStoredSettings settings) { |
|
83 |
return new RuntimeManager(settings); |
cacf8b
|
84 |
} |
JM |
85 |
|
41a7e4
|
86 |
@Provides @Singleton IPluginManager providePluginManager(IRuntimeManager runtimeManager) { |
JM |
87 |
return new PluginManager(runtimeManager); |
|
88 |
} |
|
89 |
|
bdfdc9
|
90 |
@Provides @Singleton INotificationManager provideNotificationManager(IStoredSettings settings) { |
JM |
91 |
return new NotificationManager(settings); |
cacf8b
|
92 |
} |
JM |
93 |
|
ca4d98
|
94 |
@Provides @Singleton IUserManager provideUserManager( |
JM |
95 |
IRuntimeManager runtimeManager, |
|
96 |
IPluginManager pluginManager) { |
|
97 |
|
|
98 |
return new UserManager(runtimeManager, pluginManager); |
cacf8b
|
99 |
} |
JM |
100 |
|
04a985
|
101 |
@Provides @Singleton IAuthenticationManager provideAuthenticationManager( |
aa6d43
|
102 |
IRuntimeManager runtimeManager, |
JM |
103 |
IUserManager userManager) { |
|
104 |
|
04a985
|
105 |
return new AuthenticationManager( |
aa6d43
|
106 |
runtimeManager, |
JM |
107 |
userManager); |
245836
|
108 |
} |
JM |
109 |
|
|
110 |
@Provides @Singleton IPublicKeyManager providePublicKeyManager( |
|
111 |
IStoredSettings settings, |
|
112 |
IRuntimeManager runtimeManager) { |
|
113 |
|
|
114 |
String clazz = settings.getString(Keys.git.sshKeysManager, FileKeyManager.class.getName()); |
|
115 |
if (StringUtils.isEmpty(clazz)) { |
|
116 |
clazz = FileKeyManager.class.getName(); |
|
117 |
} |
|
118 |
if (FileKeyManager.class.getName().equals(clazz)) { |
|
119 |
return new FileKeyManager(runtimeManager); |
|
120 |
} else if (NullKeyManager.class.getName().equals(clazz)) { |
|
121 |
return new NullKeyManager(); |
|
122 |
} else if (MemoryKeyManager.class.getName().equals(clazz)) { |
|
123 |
return new MemoryKeyManager(); |
|
124 |
} else { |
|
125 |
try { |
|
126 |
Class<?> mgrClass = Class.forName(clazz); |
|
127 |
return (IPublicKeyManager) mgrClass.newInstance(); |
|
128 |
} catch (Exception e) { |
|
129 |
|
|
130 |
} |
|
131 |
return null; |
|
132 |
} |
cacf8b
|
133 |
} |
JM |
134 |
|
95cdba
|
135 |
@Provides @Singleton IRepositoryManager provideRepositoryManager( |
JM |
136 |
IRuntimeManager runtimeManager, |
ca4d98
|
137 |
IPluginManager pluginManager, |
95cdba
|
138 |
IUserManager userManager) { |
JM |
139 |
|
|
140 |
return new RepositoryManager( |
|
141 |
runtimeManager, |
ca4d98
|
142 |
pluginManager, |
95cdba
|
143 |
userManager); |
cacf8b
|
144 |
} |
JM |
145 |
|
a1f27e
|
146 |
@Provides @Singleton IProjectManager provideProjectManager( |
JM |
147 |
IRuntimeManager runtimeManager, |
|
148 |
IUserManager userManager, |
|
149 |
IRepositoryManager repositoryManager) { |
|
150 |
|
|
151 |
return new ProjectManager( |
|
152 |
runtimeManager, |
|
153 |
userManager, |
|
154 |
repositoryManager); |
cacf8b
|
155 |
} |
JM |
156 |
|
269c50
|
157 |
@Provides @Singleton IFederationManager provideFederationManager( |
JM |
158 |
IRuntimeManager runtimeManager, |
|
159 |
INotificationManager notificationManager, |
|
160 |
IRepositoryManager repositoryManager) { |
|
161 |
|
|
162 |
return new FederationManager( |
|
163 |
runtimeManager, |
|
164 |
notificationManager, |
|
165 |
repositoryManager); |
cacf8b
|
166 |
} |
JM |
167 |
|
3a9e76
|
168 |
@Provides @Singleton IGitblit provideGitblit( |
325396
|
169 |
IRuntimeManager runtimeManager, |
41a7e4
|
170 |
IPluginManager pluginManager, |
325396
|
171 |
INotificationManager notificationManager, |
JM |
172 |
IUserManager userManager, |
04a985
|
173 |
IAuthenticationManager authenticationManager, |
245836
|
174 |
IPublicKeyManager publicKeyManager, |
325396
|
175 |
IRepositoryManager repositoryManager, |
JM |
176 |
IProjectManager projectManager, |
41a7e4
|
177 |
IFederationManager federationManager) { |
325396
|
178 |
|
8d8809
|
179 |
return new GitBlit( |
325396
|
180 |
runtimeManager, |
41a7e4
|
181 |
pluginManager, |
325396
|
182 |
notificationManager, |
JM |
183 |
userManager, |
04a985
|
184 |
authenticationManager, |
245836
|
185 |
publicKeyManager, |
325396
|
186 |
repositoryManager, |
JM |
187 |
projectManager, |
41a7e4
|
188 |
federationManager); |
325396
|
189 |
} |
JM |
190 |
|
cc47aa
|
191 |
@Provides @Singleton GitBlitWebApp provideWebApplication( |
cacf8b
|
192 |
IRuntimeManager runtimeManager, |
a7af19
|
193 |
IPluginManager pluginManager, |
cacf8b
|
194 |
INotificationManager notificationManager, |
JM |
195 |
IUserManager userManager, |
04a985
|
196 |
IAuthenticationManager authenticationManager, |
245836
|
197 |
IPublicKeyManager publicKeyManager, |
cacf8b
|
198 |
IRepositoryManager repositoryManager, |
JM |
199 |
IProjectManager projectManager, |
3a9e76
|
200 |
IFederationManager federationManager, |
JM |
201 |
IGitblit gitblit) { |
cacf8b
|
202 |
|
JM |
203 |
return new GitBlitWebApp( |
|
204 |
runtimeManager, |
a7af19
|
205 |
pluginManager, |
cacf8b
|
206 |
notificationManager, |
JM |
207 |
userManager, |
04a985
|
208 |
authenticationManager, |
245836
|
209 |
publicKeyManager, |
cacf8b
|
210 |
repositoryManager, |
JM |
211 |
projectManager, |
3a9e76
|
212 |
federationManager, |
JM |
213 |
gitblit); |
cc47aa
|
214 |
} |
cacf8b
|
215 |
} |