*/
SonarProduct getRuntimeProduct();
+ /**
+ * Test if a cancellation of the analysis was requested. Sensors should periodically test this flag
+ * and gracefully stop if value is true. For example it could be tested between each processed file.
+ * @since 6.0
+ */
+ boolean isCancelled();
+
// ----------- MEASURES --------------
/**
*/
NewSymbolTable newSymbolTable();
- // ------------ TESTS ------------
+ // ------------ COVERAGE ------------
/**
* Builder to define coverage in a file.
*/
NewCpdTokens newCpdTokens();
+ // ------------ ANALYSIS ERROR ------------
+
/**
* Builder to declare errors that happened while processing a source file.
* Don't forget to call {@link NewAnalisisError#save()}.
* @since 6.0
*/
NewAnalysisError newAnalysisError();
+
}
private InMemorySensorStorage sensorStorage;
private InputModule module;
private SonarQubeVersion sqVersion;
+ private boolean cancelled;
private SensorContextTester(Path moduleBaseDir) {
this.settings = new Settings();
return this;
}
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ public void setCancelled(boolean cancelled) {
+ this.cancelled = cancelled;
+ }
+
@Override
public InputModule module() {
return module;
public Collection<Issue> allIssues() {
return sensorStorage.allIssues;
}
-
+
public Collection<AnalysisError> allAnalysisErrors() {
return sensorStorage.allAnalysisErrors;
}
public NewSymbolTable newSymbolTable() {
return new DefaultSymbolTable(sensorStorage);
}
-
+
@Override
public NewAnalysisError newAnalysisError() {
return new DefaultAnalysisError(sensorStorage);
.addToken(inputFile.newRange(0, 6), "public")
.save();
}
+
+ @Test
+ public void testCacnellation() {
+ assertThat(tester.isCancelled()).isFalse();
+ tester.setCancelled(true);
+ assertThat(tester.isCancelled()).isTrue();
+ }
}
return NO_OP_NEW_ANALYSIS_ERROR;
}
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
}
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.Version;
-import org.sonar.scanner.sensor.DefaultSensorContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
assertThat(adaptor.newIssue()).isNotNull();
assertThat(adaptor.newMeasure()).isNotNull();
+
+ assertThat(adaptor.isCancelled()).isFalse();
}
}