001/*
002 * SonarQube
003 * Copyright (C) 2009-2016 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * This program 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 * This program 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 */
020package org.sonar.api.batch;
021
022import java.io.Serializable;
023import java.util.Collection;
024import javax.annotation.CheckForNull;
025import org.sonar.api.batch.fs.InputFile;
026import org.sonar.api.batch.fs.InputPath;
027import org.sonar.api.design.Dependency;
028import org.sonar.api.measures.Measure;
029import org.sonar.api.measures.MeasuresFilter;
030import org.sonar.api.measures.Metric;
031import org.sonar.api.resources.Resource;
032
033/**
034 * @since 1.10
035 */
036public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext {
037
038  /**
039   * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
040   *
041   * @return false if the resource is excluded
042   * @deprecated since 4.2 Resource indexing is done by the platform for all physical resources.
043   */
044  @Deprecated
045  boolean index(Resource resource);
046
047  /**
048   * Indexes a resource. This method does nothing if the resource is already indexed.
049   *
050   * @param resource        the resource to index. Not nullable
051   * @param parentReference a reference to the parent. If null, the the resource is indexed as a direct child of project.
052   * @return false if the parent is not indexed or if the resource is excluded
053   * @deprecated since 4.2 Resource indexing is done by the platform for all physical resources.
054   */
055  @Deprecated
056  boolean index(Resource resource, Resource parentReference);
057
058  /**
059   * Returns true if the referenced resource is indexed and excluded.
060   *
061   * @since 2.6
062   * @deprecated since 4.2 Excluded resources are not indexed.
063   */
064  @Deprecated
065  boolean isExcluded(Resource reference);
066
067  /**
068   * Returns true if the referenced resource is indexed.
069   *
070   * @since 2.6
071   * @deprecated since 4.2 Excluded resources are not indexed.
072   */
073  @Deprecated
074  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  @CheckForNull
084  <R extends Resource> R getResource(R reference);
085
086  /**
087   * @since 2.6
088   */
089  Resource getParent(Resource reference);
090
091  /**
092   * @since 2.6
093   */
094
095  Collection<Resource> getChildren(Resource reference);
096
097  // ----------- MEASURES ON PROJECT --------------
098
099  /**
100   * @deprecated since 5.1 Sensors should not read but only save data
101   */
102  @Deprecated
103  <G extends Serializable> Measure<G> getMeasure(Metric<G> metric);
104
105  /**
106   * @deprecated since 5.1 Sensors should not read but only save data
107   */
108  @Deprecated
109  <M> M getMeasures(MeasuresFilter<M> filter);
110
111  /**
112   * Add a measure on project
113   */
114  Measure saveMeasure(Measure measure);
115
116  /**
117   * Add a measure on project
118   */
119  Measure saveMeasure(Metric metric, Double value);
120
121  // ----------- MEASURES ON RESOURCES --------------
122
123  /**
124   * @deprecated since 5.1 Sensors should not read but only save data
125   */
126  @Deprecated
127  <G extends Serializable> Measure<G> getMeasure(Resource resource, Metric<G> metric);
128
129  /**
130   * Key is updated when saving the resource.
131   *
132   * @return the key as saved in database. Null if the resource is set as excluded.
133   * @deprecated use the methods index()
134   */
135  @Deprecated
136  String saveResource(Resource resource);
137
138  /**
139   * @deprecated since 5.1 Sensors should not read but only save data
140   */
141  @Deprecated
142  <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
143
144  /**
145   * Add or update a measure.
146   * <p>
147   * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as
148   * excluded.
149   * </p>
150   */
151  Measure saveMeasure(Resource resource, Metric metric, Double value);
152
153  /**
154   * Add or update a measure.
155   * <p>
156   * The resource is automatically saved, so there is no need to execute the method saveResource(). Does nothing if the resource is set as
157   * excluded.
158   * </p>
159   */
160  Measure saveMeasure(Resource resource, Measure measure);
161
162  // ----------- DEPENDENCIES BETWEEN RESOURCES --------------
163
164  /**
165   * @deprecated since 5.2 No more design features. No-op
166   */
167  @Deprecated
168  Dependency saveDependency(Dependency dependency);
169
170  // ----------- FILE SOURCES --------------
171
172  /**
173   * Save the source code of a file. The file must be have been indexed before.
174   *
175   * @throws org.sonar.api.resources.DuplicatedSourceException if the source has already been set on this resource
176   * @since 1.10. Returns a boolean since 2.6.
177   * @deprecated since 4.2 Source import is done by the platform
178   */
179  @Deprecated
180  void saveSource(Resource reference, String source);
181
182  /**
183   * Save measure on {@link InputFile}
184   * @since 4.2
185   */
186  Measure saveMeasure(InputFile inputFile, Metric metric, Double value);
187
188  /**
189   * Save measure on {@link InputFile}
190   * @since 4.2
191   */
192  Measure saveMeasure(InputFile inputFile, Measure measure);
193
194  /**
195   * Allow to get {@link Resource} corresponding to provided {@link InputPath}.
196   * @since 4.5.2
197   */
198  Resource getResource(InputPath inputPath);
199}