*/
package org.sonar.server.tester;
-import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
return this;
}
- public ServerTester addPluginJar(File jar) {
- Preconditions.checkArgument(jar.exists() && jar.isFile(), "Plugin JAR file does not exist: " + jar.getAbsolutePath());
- try {
- File pluginsDir = new File(homeDir, "extensions/plugins");
- FileUtils.forceMkdir(pluginsDir);
- FileUtils.copyFileToDirectory(jar, pluginsDir);
- return this;
- } catch (Exception e) {
- throw new IllegalStateException("Fail to copy plugin JAR file: " + jar.getAbsolutePath(), e);
- }
- }
-
/**
* Set a property available for startup. Must be called before {@link #start()}. Does not affect
* Elasticsearch server.
}
}
- private void checkInSafeMode() {
- if (platform == null || !platform.isInSafeMode()) {
- throw new IllegalStateException("Not in safe mode");
- }
- }
-
- private void checkNotInSafeMode() {
- if (platform != null && platform.isInSafeMode()) {
- throw new IllegalStateException("Already in safe mode");
- }
- }
-
public static class Xoo implements Language {
public static final String KEY = "xoo";
serverLineHashes.byKey.put(fileKey, lineHashes);
return this;
}
-
- public BatchMediumTesterBuilder registerMetrics(List<Metric> metrics) {
- for (Metric<?> m : metrics) {
- registerMetric(m);
- }
- return this;
- }
-
}
public void start() {
}
}
- public void expectBetween(String label, long val, long min, long max) {
- if (ENABLED) {
- checkThat(label, val, Matchers.allOf(Matchers.greaterThan(min), Matchers.lessThan(max)));
- }
- }
-
public void expectLessThanOrEqualTo(String label, long val, long max) {
if (ENABLED) {
checkThat(label, val, Matchers.lessThan(max));
import org.sonar.xoo.XooPlugin;
import java.io.File;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
@Rule
public LogTester logTester = new LogTester();
- private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
-
- private static Long date(String date) {
- try {
- return sdf.parse(date).getTime();
- } catch (ParseException e) {
- throw new IllegalStateException(e);
- }
- }
-
public BatchMediumTester tester = BatchMediumTester.builder()
.bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW))
.registerPlugin("xoo", new XooPlugin())
int openIssues = 0;
int resolvedIssue = 0;
for (Issue issue : result.issues()) {
- System.out.println(issue.key() + " " + issue.line() + " " + issue.status());
if (issue.isNew()) {
newIssues++;
} else if (issue.resolution() != null) {
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.BatchMediumTester.TaskBuilder;
-import org.sonar.batch.mediumtest.TaskResult;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.Changesets.Changeset;
File baseDir = prepareProject();
- TaskResult result = tester.newTask()
+ tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
.put("sonar.projectBaseDir", baseDir.getAbsolutePath())
// Clear file content
FileUtils.write(new File(baseDir, "src/sample.xoo"), "");
- TaskResult result = tester.newTask()
+ tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
.put("sonar.projectBaseDir", baseDir.getAbsolutePath())
BatchReport.Changesets changesets = getChangesets(baseDir, 0);
assertThat(changesets).isNull();
-
}
@Test
File baseDir = prepareProject();
- TaskResult result = tester.newTask()
+ tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
.put("sonar.projectBaseDir", baseDir.getAbsolutePath())