blob: f5bfb3eadd4c906de9891e29dfda0e85c18c974f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2012 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.batch.bootstrap;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.UriReader;
import org.sonar.batch.FakeMavenPluginExecutor;
import org.sonar.batch.MavenPluginExecutor;
import org.sonar.batch.RemoteServerMetadata;
import org.sonar.batch.ServerMetadata;
import org.sonar.batch.config.BatchDatabaseSettingsLoader;
import org.sonar.batch.config.BatchSettings;
import org.sonar.batch.local.LocalDatabase;
import org.sonar.core.config.Logback;
import org.sonar.core.i18n.I18nManager;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.persistence.DaoUtils;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.MyBatis;
import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
import java.net.URLClassLoader;
/**
* Level 1 components
*/
public class BootstrapModule extends Module {
private Object[] boostrapperComponents;
private ProjectReactor reactor;
public BootstrapModule(ProjectReactor reactor, Object... boostrapperComponents) {
this.reactor = reactor;
this.boostrapperComponents = boostrapperComponents;
}
@Override
protected void configure() {
addCoreSingleton(reactor);
addCoreSingleton(new PropertiesConfiguration());
addCoreSingleton(BatchSettings.class);
addCoreSingleton(DryRun.class);
addCoreSingleton(Logback.class);
addCoreSingleton(ServerMetadata.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(TempDirectories.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(UriReader.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
addCoreSingleton(JdbcDriverHolder.class);
addCoreSingleton(EmailSettings.class);
addCoreSingleton(I18nManager.class);
addCoreSingleton(RuleI18nManager.class);
URLClassLoader bootstrapClassLoader = getComponentByType(JdbcDriverHolder.class).getClassLoader();
// set as the current context classloader for hibernate, else it does not find the JDBC driver.
Thread.currentThread().setContextClassLoader(bootstrapClassLoader);
addCoreSingleton(RemoteServerMetadata.class);
// local mode
addCoreSingleton(LocalMode.class);
addCoreSingleton(LocalDatabase.class);
// mybatis
addCoreSingleton(BatchDatabase.class);
addCoreSingleton(MyBatis.class);
addCoreSingleton(DatabaseVersion.class);
for (Class daoClass : DaoUtils.getDaoClasses()) {
addCoreSingleton(daoClass);
}
// hibernate
addCoreSingleton(DefaultDatabaseConnector.class);
addCoreSingleton(ThreadLocalDatabaseSessionFactory.class);
addAdapter(new DatabaseSessionProvider());
addCoreSingleton(DatabaseBatchCompatibility.class);
for (Object component : boostrapperComponents) {
addCoreSingleton(component);
}
if (!isMavenPluginExecutorRegistered()) {
addCoreSingleton(FakeMavenPluginExecutor.class);
}
addCoreSingleton(BatchPluginRepository.class);
addCoreSingleton(BatchExtensionInstaller.class);
addCoreSingleton(BatchDatabaseSettingsLoader.class);
}
boolean isMavenPluginExecutorRegistered() {
if (boostrapperComponents != null) {
for (Object component : boostrapperComponents) {
if (component instanceof Class && MavenPluginExecutor.class.isAssignableFrom((Class<?>) component)) {
return true;
}
}
}
return false;
}
@Override
protected void doStart() {
boolean dryRun = getComponentByType(DryRun.class).isEnabled();
Module batchComponents = installChild(new BatchModule(dryRun));
batchComponents.start();
}
}
|