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.design.Dependency;
023 import org.sonar.api.measures.Measure;
024 import org.sonar.api.measures.MeasuresFilter;
025 import org.sonar.api.resources.Project;
026 import org.sonar.api.resources.ProjectLink;
027 import org.sonar.api.resources.Resource;
028 import org.sonar.api.rules.Violation;
029 import org.sonar.api.violations.ViolationQuery;
030 import org.sonar.graph.DirectedGraphAccessor;
031
032 import javax.annotation.CheckForNull;
033
034 import java.util.Collection;
035 import java.util.Date;
036 import java.util.List;
037 import java.util.Set;
038
039 /**
040 * @deprecated since 4.5.2 should not be used by plugins.
041 */
042 @Deprecated
043 public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> {
044
045 /**
046 * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
047 * If the method resource.getParent() does not return null, then this parent will be indexed too.
048 *
049 * @return false if the resource is excluded
050 * @since 2.6
051 */
052 public abstract boolean index(Resource resource);
053
054 /**
055 * Indexes a resource. This method does nothing if the resource is already indexed.
056 *
057 * @param resource the resource to index. Not nullable
058 * @param parentReference a reference to the indexed parent. If null, the resource is indexed as a direct child of project.
059 * @return false if the parent is not indexed or if the resource is excluded
060 * @since 2.6
061 */
062 public abstract boolean index(Resource resource, Resource parentReference);
063
064 /**
065 * Returns true if the referenced resource is excluded. An excluded resource is not indexed.
066 * @since 2.6
067 */
068 public abstract boolean isExcluded(Resource reference);
069
070 /**
071 * @since 2.6
072 */
073 public abstract boolean isIndexed(Resource reference, boolean acceptExcluded);
074
075 /**
076 * Search for an indexed resource.
077 *
078 * @param reference the resource reference
079 * @return the indexed resource, null if it's not indexed
080 * @since 1.10. Generic types since 2.6.
081 */
082 public abstract <R extends Resource> R getResource(R reference);
083
084 /**
085 * @since 2.6
086 */
087 public abstract Resource getParent(Resource reference);
088
089 /**
090 * @since 2.6
091 */
092
093 public abstract Collection<Resource> getChildren(Resource reference);
094
095 /**
096 * Save the source code of a file. The file must be have been indexed before.
097 * Note: the source stream is not closed.
098 *
099 * @throws org.sonar.api.resources.DuplicatedSourceException
100 * if the source has already been set on this resource
101 * @deprecated since 4.2 should not be used by plugins
102 */
103 @Deprecated
104 public abstract void setSource(Resource reference, String source);
105
106 /**
107 * @return source code associated with a specified resource, <code>null</code> if not available
108 * (for example when sonar.importSources=false)
109 * @since 2.9
110 */
111 @CheckForNull
112 public abstract String getSource(Resource resource);
113
114 public abstract Project getProject();
115
116 public final Collection<Resource> getResources() {
117 return getVertices();
118 }
119
120 /**
121 * Indexes the resource.
122 * @return the indexed resource, even if it's excluded
123 * @deprecated since 2.6. Use methods index()
124 */
125 @Deprecated
126 public abstract Resource addResource(Resource resource);
127
128 @CheckForNull
129 public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric);
130
131 @CheckForNull
132 public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
133
134 /**
135 * Returns the violations that match the {@link ViolationQuery} parameters.
136 *
137 * @since 2.8
138 * @param violationQuery
139 * the request parameters specified as a {@link ViolationQuery}
140 * @return the list of violations that match those parameters
141 * @deprecated in 3.6
142 */
143 @Deprecated
144 public abstract List<Violation> getViolations(ViolationQuery violationQuery);
145
146 /**
147 * Returns all the active (= non switched-off) violations found on the given resource. Equivalent to
148 * {@link #getViolations(ViolationQuery)} called with <code>ViolationQuery.create().forResource(resource).ignoreSwitchedOff(true)</code>
149 * as a parameter.
150 *
151 * @since 2.7
152 * @return the list of violations
153 * @deprecated in 3.6
154 */
155 @Deprecated
156 public final List<Violation> getViolations(Resource resource) {
157 return getViolations(ViolationQuery.create().forResource(resource));
158 }
159
160 /**
161 * @since 2.5
162 * @deprecated in 3.6
163 */
164 @Deprecated
165 public abstract void addViolation(Violation violation, boolean force);
166
167 /**
168 * @deprecated in 3.6
169 */
170 @Deprecated
171 public final void addViolation(Violation violation) {
172 addViolation(violation, false);
173 }
174
175 /**
176 * Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
177 * indexed before. Next versions will deactivate this automatic indexation.
178 */
179 public abstract Measure addMeasure(Resource resource, Measure measure);
180
181 public abstract Dependency addDependency(Dependency dependency);
182
183 public abstract Set<Dependency> getDependencies();
184
185 public abstract void addLink(ProjectLink link);
186
187 public abstract void deleteLink(String key);
188
189 public abstract List<Event> getEvents(Resource resource);
190
191 public abstract void deleteEvent(Event event);
192
193 public abstract Event addEvent(Resource resource, String name, String description, String category, Date date);
194
195 public final Collection<Dependency> getOutgoingDependencies(Resource from) {
196 return getOutgoingEdges(from);
197 }
198
199 public final Collection<Dependency> getIncomingDependencies(Resource to) {
200 return getIncomingEdges(to);
201 }
202 }