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
130
131
132
133
|
/*
* 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.BatchExtensionDictionnary;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.batch.DefaultProfileLoader;
import org.sonar.batch.DefaultProjectClasspath;
import org.sonar.batch.DefaultProjectFileSystem2;
import org.sonar.batch.DefaultSensorContext;
import org.sonar.batch.DefaultTimeMachine;
import org.sonar.batch.ProfileProvider;
import org.sonar.batch.ProjectTree;
import org.sonar.batch.ResourceFilters;
import org.sonar.batch.ViolationFilters;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.batch.config.ProjectSettings;
import org.sonar.batch.config.UnsupportedProperties;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.index.DefaultIndex;
import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.batch.phases.Phases;
import org.sonar.batch.phases.PhasesTimeProfiler;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.jpa.dao.ProfilesDao;
import org.sonar.jpa.dao.RulesDao;
public class ProjectModule extends Module {
private static final Logger LOG = LoggerFactory.getLogger(ProjectModule.class);
private Project project;
public ProjectModule(Project project) {
this.project = project;
}
@Override
protected void configure() {
logSettings();
addCoreComponents();
addProjectComponents();
addProjectPluginExtensions();
}
private void addProjectComponents() {
ProjectDefinition projectDefinition = container.getComponentByType(ProjectTree.class).getProjectDefinition(project);
container.addSingleton(projectDefinition);
container.addSingleton(project);
container.addSingleton(project.getConfiguration());
container.addSingleton(ProjectSettings.class);
container.addSingleton(UnsupportedProperties.class);
for (Object component : projectDefinition.getContainerExtensions()) {
container.addSingleton(component);
}
container.addSingleton(Languages.class);
container.addSingleton(DefaultProjectClasspath.class);
container.addSingleton(DefaultProjectFileSystem2.class);
container.addSingleton(RulesDao.class);
// the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor)
container.addSingleton(container.getComponentByType(DefaultResourcePersister.class).getSnapshot(project));
container.addSingleton(TimeMachineConfiguration.class);
container.addSingleton(org.sonar.api.database.daos.MeasuresDao.class);
container.addSingleton(ProfilesDao.class);
container.addSingleton(DefaultSensorContext.class);
container.addSingleton(BatchExtensionDictionnary.class);
container.addSingleton(DefaultTimeMachine.class);
container.addSingleton(ViolationFilters.class);
container.addSingleton(ResourceFilters.class);
container.addSingleton(DefaultModelFinder.class);
container.addSingleton(DefaultProfileLoader.class);
container.addPicoAdapter(new ProfileProvider());
}
private void addCoreComponents() {
container.addSingleton(EventBus.class);
container.addSingleton(Phases.class);
container.addSingleton(PhasesTimeProfiler.class);
for (Class clazz : Phases.getPhaseClasses()) {
container.addSingleton(clazz);
}
}
private void addProjectPluginExtensions() {
ExtensionInstaller installer = container.getComponentByType(ExtensionInstaller.class);
installer.install(container, InstantiationStrategy.PROJECT);
}
private void logSettings() {
// TODO move these logs in a dedicated component
LOG.info("------------- Analyzing {}", project.getName());
}
/**
* Analyze project
*/
@Override
protected void doStart() {
DefaultIndex index = container.getComponentByType(DefaultIndex.class);
index.setCurrentProject(project,
container.getComponentByType(ResourceFilters.class),
container.getComponentByType(ViolationFilters.class),
container.getComponentByType(RulesProfile.class));
container.getComponentByType(Phases.class).execute(project);
}
}
|