if (shouldSave(lines)) {
String data = KeyValueFormat.format(lines);
Measure measure = new Measure(metricKey)
- .setPersistenceMode(PersistenceMode.DATABASE)
- .setData(data);
+ .setPersistenceMode(PersistenceMode.DATABASE)
+ .setData(data);
index.addMeasure(resource, measure);
entry.setValue(ImmutableMap.copyOf(lines));
}
@Override
public String toString() {
return Objects.toStringHelper(this)
- .add("map", map)
- .toString();
+ .add("map", map)
+ .toString();
}
}
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.measures.FileLinesContext;
import org.sonar.api.measures.FileLinesContextFactory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.InputFile;
+import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
private final SonarIndex index;
+ private Languages languages;
- public DefaultFileLinesContextFactory(SonarIndex index) {
+ public DefaultFileLinesContextFactory(SonarIndex index, Languages languages) {
this.index = index;
+ this.languages = languages;
}
+ @Override
public FileLinesContext createFor(Resource resource) {
// Reload resource in case it use deprecated key
resource = index.getResource(resource);
return new DefaultFileLinesContext(index, resource);
}
+ @Override
+ public FileLinesContext createFor(InputFile inputFile) {
+ // FIXME remove that once DefaultFileLinesContext accept an InputFile
+ String languageKey = inputFile.attribute(InputFile.ATTRIBUTE_LANGUAGE);
+ boolean unitTest = InputFile.TYPE_TEST.equals(inputFile.attribute(InputFile.ATTRIBUTE_TYPE));
+ Resource sonarFile;
+ if (Java.KEY.equals(languageKey)) {
+ sonarFile = JavaFile.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), unitTest);
+ } else {
+ sonarFile = File.create(inputFile.path(), inputFile.attribute(DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH), languages.get(languageKey), unitTest);
+ }
+ return new DefaultFileLinesContext(index, sonarFile);
+ }
+
}
*/
package org.sonar.batch.index;
-import org.sonar.api.scan.filesystem.InputFile;
-
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.InputFile;
public interface ResourcePersister {
Snapshot getSnapshotOrFail(InputFile resource);
/**
- * The current snapshot which is flagged as "last", different then the current analysis.
+ * The current snapshot which is flagged as "last", different than the current analysis.
* @param onlyOlder true if the result must be anterior to the snapshot parameter
*/
Snapshot getLastSnapshot(Snapshot snapshot, boolean onlyOlder);
* generally used to add measure at the lowest level of the resource tree. A sensor can access and save measures on the whole tree of
* resources.
* </p>
- *
+ *
* <p>
* For example the Cobertura Sensor parses Cobertura report and saves the first-level of measures on resources.
* </p>
- *
+ *
* <p>
* A particular attention should be given to resource exclusion. Sonar already manages exclusions at file level : if you try to save a
* measure on a resource that is excluded in the settings, then Sonar will not save the measure. When handling a plugin or an external tool,
* you should make sure that exclusions are passed if you are going to get back consolidated data.
* </p>
- *
+ *
* @since 1.10
*/
public interface Sensor extends BatchExtension, CheckProject {
/**
* Sensors that depend upon Squid must declare the following method :
- *
+ *
* <pre>
* @DependsUpon
* public String dependsUponSquidAnalysis() {
/**
* The method that is going to be run when the sensor is called
- *
- * @param project the project the sensor runs on
+ *
+ * @param module the module the sensor runs on
* @param context the context
*/
- void analyse(Project project, SensorContext context);
+ void analyse(Project module, SensorContext context);
}
import com.google.common.annotations.Beta;
import org.sonar.api.BatchComponent;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.InputFile;
/**
* <p>This interface is not intended to be implemented by clients.</p>
FileLinesContext createFor(Resource resource);
+ FileLinesContext createFor(InputFile inputFile);
+
}