import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.measures.PersistenceMode;
+import org.sonar.api.technicaldebt.batch.Characteristic;
+import org.sonar.api.technicaldebt.batch.Requirement;
import org.sonar.api.technicaldebt.batch.TechnicalDebtModel;
class MeasureValueCoder implements ValueCoder {
value.put(m.getVariation4());
value.put(m.getVariation5());
value.putString(m.getUrl());
- value.put(m.getCharacteristic() != null ? m.getCharacteristic().id() : null);
- value.put(m.getRequirement() != null ? m.getRequirement().id() : null);
- value.put(m.getPersonId() != null ? m.getPersonId().intValue() : null);
- value.putString(m.getPersistenceMode() != null ? m.getPersistenceMode().name() : null);
+ Characteristic characteristic = m.getCharacteristic();
+ value.put(characteristic != null ? characteristic.id() : null);
+ Requirement requirement = m.getRequirement();
+ value.put(requirement != null ? requirement.id() : null);
+ Integer personId = m.getPersonId();
+ value.put(personId != null ? personId.intValue() : null);
+ PersistenceMode persistenceMode = m.getPersistenceMode();
+ value.putString(persistenceMode != null ? persistenceMode.name() : null);
}
public Object get(Value value, Class clazz, CoderContext context) {
return this;
}
- public ActivityDto setExecutionTime(Integer executionTime) {
- return this;
- }
-
public String getData() {
return data;
}
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeFalse;
public class CommandExecutorTest {
@Test
public void should_consume_StdOut_and_StdErr() throws Exception {
// too many false-positives on MS windows
- assumeFalse(SystemUtils.IS_OS_WINDOWS);
-
- final StringBuilder stdOutBuilder = new StringBuilder();
- StreamConsumer stdOutConsumer = new StreamConsumer() {
- public void consumeLine(String line) {
- stdOutBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
- }
- };
- final StringBuilder stdErrBuilder = new StringBuilder();
- StreamConsumer stdErrConsumer = new StreamConsumer() {
- public void consumeLine(String line) {
- stdErrBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
- }
- };
- Command command = Command.create(getScript("output")).setDirectory(workDir);
- int exitCode = CommandExecutor.create().execute(command, stdOutConsumer, stdErrConsumer, 1000L);
- assertThat(exitCode).isEqualTo(0);
-
- String stdOut = stdOutBuilder.toString();
- String stdErr = stdErrBuilder.toString();
- assertThat(stdOut).contains("stdOut: first line");
- assertThat(stdOut).contains("stdOut: second line");
- assertThat(stdErr).contains("stdErr: first line");
- assertThat(stdErr).contains("stdErr: second line");
+ if (!SystemUtils.IS_OS_WINDOWS) {
+ final StringBuilder stdOutBuilder = new StringBuilder();
+ StreamConsumer stdOutConsumer = new StreamConsumer() {
+ public void consumeLine(String line) {
+ stdOutBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
+ }
+ };
+ final StringBuilder stdErrBuilder = new StringBuilder();
+ StreamConsumer stdErrConsumer = new StreamConsumer() {
+ public void consumeLine(String line) {
+ stdErrBuilder.append(line).append(SystemUtils.LINE_SEPARATOR);
+ }
+ };
+ Command command = Command.create(getScript("output")).setDirectory(workDir);
+ int exitCode = CommandExecutor.create().execute(command, stdOutConsumer, stdErrConsumer, 1000L);
+ assertThat(exitCode).isEqualTo(0);
+
+ String stdOut = stdOutBuilder.toString();
+ String stdErr = stdErrBuilder.toString();
+ assertThat(stdOut).contains("stdOut: first line");
+ assertThat(stdOut).contains("stdOut: second line");
+ assertThat(stdErr).contains("stdErr: first line");
+ assertThat(stdErr).contains("stdErr: second line");
+ }
}
@Test
* Log service is used to log Activity classes which represents an event to DB and Index.
*
* @see org.sonar.core.activity.ActivityLog
- * @since 4.4
*/
public class ActivityService {
}
public void write(DbSession session, Activity.Type type, String message) {
- this.write(session, type, message, null);
- }
-
- public void write(DbSession session, Activity.Type type, String message, Integer time) {
- this.save(session, ActivityDto.createFor(message)
- .setType(type)
- .setExecutionTime(time));
+ save(session, ActivityDto.createFor(message).setType(type));
}
public <L extends ActivityLog> void write(DbSession session, Activity.Type type, List<L> logs) {
public Result<Activity> search(ActivityQuery query, QueryOptions options) {
ActivityIndex index = indexClient.get(ActivityIndex.class);
- return
- new Result<Activity>(index, index.search(query, options));
+ return new Result<Activity>(index, index.search(query, options));
}
}
@Override
public Type type() {
- return Type.valueOf((String) this.getNullableField(ActivityNormalizer.LogFields.TYPE.field()));
+ return Type.valueOf((String) getField(ActivityNormalizer.LogFields.TYPE.field()));
}
@Override
import org.sonar.server.search.QueryOptions;
import org.sonar.server.search.Result;
+import javax.annotation.Nullable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
}
public SearchResponse search(ActivityQuery query, QueryOptions options) {
- return this.search(query, options, null);
+ return search(query, options, null);
}
public SearchResponse search(ActivityQuery query, QueryOptions options,
- FilterBuilder domainFilter) {
+ @Nullable FilterBuilder domainFilter) {
// Prepare query
SearchRequestBuilder esSearch = getClient()
.setHandler(new RequestHandler() {
@Override
public void handle(Request request, Response response) throws Exception {
- Controller controller = context.controller(request.mandatoryParam("controller"));
+ String controllerKey = request.mandatoryParam("controller");
+ Controller controller = context.controller(controllerKey);
+ if (controller == null) {
+ throw new IllegalArgumentException("Controller does not exist: " + controllerKey);
+ }
String actionKey = request.mandatoryParam("action");
Action action = controller.action(actionKey);
if (action == null) {