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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube 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.
*
* SonarQube 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 this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.batch;
import org.sonar.api.batch.Event;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectLink;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
public class DefaultSensorContext implements SensorContext {
private SonarIndex index;
private Project project;
public DefaultSensorContext(SonarIndex index, Project project) {
this.index = index;
this.project = project;
}
public Project getProject() {
return project;
}
public boolean index(Resource resource) {
return index.index(resource);
}
public boolean index(Resource resource, Resource parentReference) {
return index.index(resource, parentReference);
}
public boolean isExcluded(Resource reference) {
return index.isExcluded(reference);
}
public boolean isIndexed(Resource reference, boolean acceptExcluded) {
return index.isIndexed(reference, acceptExcluded);
}
public Resource getParent(Resource reference) {
return index.getParent(reference);
}
public Collection<Resource> getChildren(Resource reference) {
return index.getChildren(reference);
}
public Measure getMeasure(Metric metric) {
return index.getMeasure(project, metric);
}
public <M> M getMeasures(MeasuresFilter<M> filter) {
return index.getMeasures(project, filter);
}
public Measure saveMeasure(Measure measure) {
return index.addMeasure(project, measure);
}
public Measure saveMeasure(Metric metric, Double value) {
return index.addMeasure(project, new Measure(metric, value));
}
public Measure getMeasure(Resource resource, Metric metric) {
return index.getMeasure(resource, metric);
}
public String saveResource(Resource resource) {
Resource persistedResource = index.addResource(resource);
if (persistedResource != null) {
return persistedResource.getEffectiveKey();
}
return null;
}
public boolean saveResource(Resource resource, Resource parentReference) {
return index.index(resource, parentReference);
}
public Resource getResource(Resource resource) {
return index.getResource(resource);
}
public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
return index.getMeasures(resource, filter);
}
public Measure saveMeasure(Resource resource, Metric metric, Double value) {
return index.addMeasure(resourceOrProject(resource), new Measure(metric, value));
}
public Measure saveMeasure(Resource resource, Measure measure) {
return index.addMeasure(resourceOrProject(resource), measure);
}
public void saveViolation(Violation violation, boolean force) {
if (violation.getResource() == null) {
violation.setResource(resourceOrProject(violation.getResource()));
}
index.addViolation(violation, force);
}
public void saveViolation(Violation violation) {
saveViolation(violation, false);
}
public void saveViolations(Collection<Violation> violations) {
if (violations != null) {
for (Violation violation : violations) {
saveViolation(violation);
}
}
}
public Dependency saveDependency(Dependency dependency) {
return index.addDependency(dependency);
}
public Set<Dependency> getDependencies() {
return index.getDependencies();
}
public Collection<Dependency> getIncomingDependencies(Resource to) {
return index.getIncomingEdges(resourceOrProject(to));
}
public Collection<Dependency> getOutgoingDependencies(Resource from) {
return index.getOutgoingEdges(resourceOrProject(from));
}
public void saveSource(Resource reference, String source) {
index.setSource(reference, source);
}
public void saveLink(ProjectLink link) {
index.addLink(link);
}
public void deleteLink(String key) {
index.deleteLink(key);
}
public List<Event> getEvents(Resource resource) {
return index.getEvents(resource);
}
public Event createEvent(Resource resource, String name, String description, String category, Date date) {
return index.addEvent(resource, name, description, category, date);
}
public void deleteEvent(Event event) {
index.deleteEvent(event);
}
private Resource resourceOrProject(Resource resource) {
return resource!=null ? resource : project;
}
}
|