001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.api.batch;
021
022 import org.sonar.api.batch.fs.InputFile;
023 import org.sonar.api.design.Dependency;
024 import org.sonar.api.measures.Measure;
025 import org.sonar.api.measures.MeasuresFilter;
026 import org.sonar.api.resources.Project;
027 import org.sonar.api.resources.ProjectLink;
028 import org.sonar.api.resources.Resource;
029 import org.sonar.api.rules.Violation;
030 import org.sonar.api.violations.ViolationQuery;
031 import org.sonar.graph.DirectedGraphAccessor;
032
033 import javax.annotation.CheckForNull;
034
035 import java.util.Collection;
036 import java.util.Date;
037 import java.util.List;
038 import java.util.Set;
039
040 /**
041 * @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
042 */
043 @Deprecated
044 public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> {
045
046 /**
047 * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
048 * If the method resource.getParent() does not return null, then this parent will be indexed too.
049 *
050 * @return false if the resource is excluded
051 * @since 2.6
052 */
053 public abstract boolean index(Resource resource);
054
055 /**
056 * Indexes a resource. This method does nothing if the resource is already indexed.
057 *
058 * @param resource the resource to index. Not nullable
059 * @param parentReference a reference to the indexed parent. If null, the resource is indexed as a direct child of project.
060 * @return false if the parent is not indexed or if the resource is excluded
061 * @since 2.6
062 */
063 public abstract boolean index(Resource resource, Resource parentReference);
064
065 /**
066 * Returns true if the referenced resource is excluded. An excluded resource is not indexed.
067 * @since 2.6
068 */
069 public abstract boolean isExcluded(Resource reference);
070
071 /**
072 * @since 2.6
073 */
074 public abstract boolean isIndexed(Resource reference, boolean acceptExcluded);
075
076 /**
077 * Search for an indexed resource.
078 *
079 * @param reference the resource reference
080 * @return the indexed resource, null if it's not indexed
081 * @since 1.10. Generic types since 2.6.
082 */
083 public abstract <R extends Resource> R getResource(R reference);
084
085 /**
086 * @since 2.6
087 */
088 public abstract Resource getParent(Resource reference);
089
090 /**
091 * @since 2.6
092 */
093
094 public abstract Collection<Resource> getChildren(Resource reference);
095
096 /**
097 * @return source code associated with a specified resource, <code>null</code> if not available
098 * (for example if resource is not a file)
099 * @since 2.9
100 * @deprecated since 5.0 sources are no more stored in SQ as a single blob. Use {@link InputFile#file()} to read file content from disk.
101 */
102 @Deprecated
103 @CheckForNull
104 public abstract String getSource(Resource resource);
105
106 public abstract Project getProject();
107
108 public final Collection<Resource> getResources() {
109 return getVertices();
110 }
111
112 /**
113 * Indexes the resource.
114 * @return the indexed resource, even if it's excluded
115 * @deprecated since 2.6. Use methods index()
116 */
117 @Deprecated
118 public abstract Resource addResource(Resource resource);
119
120 @CheckForNull
121 public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric);
122
123 @CheckForNull
124 public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
125
126 /**
127 * Returns the violations that match the {@link ViolationQuery} parameters.
128 *
129 * @since 2.8
130 * @param violationQuery
131 * the request parameters specified as a {@link ViolationQuery}
132 * @return the list of violations that match those parameters
133 * @deprecated in 3.6
134 */
135 @Deprecated
136 public abstract List<Violation> getViolations(ViolationQuery violationQuery);
137
138 /**
139 * Returns all the active (= non switched-off) violations found on the given resource. Equivalent to
140 * {@link #getViolations(ViolationQuery)} called with <code>ViolationQuery.create().forResource(resource).ignoreSwitchedOff(true)</code>
141 * as a parameter.
142 *
143 * @since 2.7
144 * @return the list of violations
145 * @deprecated in 3.6
146 */
147 @Deprecated
148 public final List<Violation> getViolations(Resource resource) {
149 return getViolations(ViolationQuery.create().forResource(resource));
150 }
151
152 /**
153 * @since 2.5
154 * @deprecated in 3.6
155 */
156 @Deprecated
157 public abstract void addViolation(Violation violation, boolean force);
158
159 /**
160 * @deprecated in 3.6
161 */
162 @Deprecated
163 public final void addViolation(Violation violation) {
164 addViolation(violation, false);
165 }
166
167 /**
168 * Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
169 * indexed before. Next versions will deactivate this automatic indexation.
170 */
171 public abstract Measure addMeasure(Resource resource, Measure measure);
172
173 public abstract Dependency addDependency(Dependency dependency);
174
175 public abstract Set<Dependency> getDependencies();
176
177 public abstract void addLink(ProjectLink link);
178
179 public abstract void deleteLink(String key);
180
181 public abstract List<Event> getEvents(Resource resource);
182
183 public abstract void deleteEvent(Event event);
184
185 public abstract Event addEvent(Resource resource, String name, String description, String category, Date date);
186
187 public final Collection<Dependency> getOutgoingDependencies(Resource from) {
188 return getOutgoingEdges(from);
189 }
190
191 public final Collection<Dependency> getIncomingDependencies(Resource to) {
192 return getIncomingEdges(to);
193 }
194 }