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