+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.step;
-
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.core.util.CloseableIterator;
-import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
-import org.sonar.server.computation.task.step.ComputationStep;
-
-public class LogScannerContextStep implements ComputationStep {
-
- private static final Logger LOGGER = Loggers.get(LogScannerContextStep.class);
-
- private final BatchReportReader reportReader;
-
- public LogScannerContextStep(BatchReportReader reportReader) {
- this.reportReader = reportReader;
- }
-
- @Override
- public void execute() {
- CloseableIterator<String> logs = reportReader.readScannerLogs();
- try {
- while (logs.hasNext()) {
- LOGGER.debug(logs.next());
- }
- } finally {
- logs.close();
- }
- }
-
- @Override
- public String getDescription() {
- return "Log scanner context";
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.step;
+
+import org.sonar.core.util.CloseableIterator;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
+import org.sonar.server.computation.task.step.ComputationStep;
+
+public class PersistScannerContextStep implements ComputationStep {
+ private final BatchReportReader reportReader;
+ private final AnalysisMetadataHolder analysisMetadataHolder;
+ private final DbClient dbClient;
+
+ public PersistScannerContextStep(BatchReportReader reportReader, AnalysisMetadataHolder analysisMetadataHolder, DbClient dbClient) {
+ this.reportReader = reportReader;
+ this.analysisMetadataHolder = analysisMetadataHolder;
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public void execute() {
+ try (CloseableIterator<String> logsIterator = reportReader.readScannerLogs()) {
+ if (logsIterator.hasNext()) {
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ dbClient.scannerContextDao().insert(dbSession, analysisMetadataHolder.getUuid(), logsIterator);
+ dbSession.commit();
+ }
+ }
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return "Persist scanner context";
+ }
+}
private static final List<Class<? extends ComputationStep>> STEPS = Arrays.asList(
ExtractReportStep.class,
- LogScannerContextStep.class,
GenerateAnalysisUuid.class,
// Builds Component tree
PersistFileSourcesStep.class,
PersistTestsStep.class,
PersistCrossProjectDuplicationIndexStep.class,
+ PersistScannerContextStep.class,
EnableAnalysisStep.class,
UpdateQualityProfilesLastUsedDateStep.class,
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.Protobuf;
import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.WsCe;
+import static java.util.Collections.singleton;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
dbTester.commit();
}
- private void persist(CeActivityDto activityDto) {
+ private CeActivityDto persist(CeActivityDto activityDto) {
dbTester.getDbClient().ceActivityDao().insert(dbTester.getSession(), activityDto);
dbTester.commit();
+ return activityDto;
+ }
+
+ private void persistScannerContext(String analysisUuid, String scannerContext) {
+ dbTester.getDbClient().scannerContextDao().insert(dbTester.getSession(), analysisUuid, CloseableIterator.from(singleton(scannerContext).iterator()));
+ dbTester.commit();
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.step;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class LogScannerContextStepTest {
-
- @Rule
- public BatchReportReaderRule reportReader = new BatchReportReaderRule();
-
- @Rule
- public LogTester logTester = new LogTester();
-
- LogScannerContextStep underTest = new LogScannerContextStep(reportReader);
-
- @Test
- public void log_scanner_logs() {
- reportReader.setScannerLogs(asList("log1", "log2"));
-
- underTest.execute();
-
- assertThat(logTester.logs(LoggerLevel.DEBUG)).containsExactly("log1", "log2");
- }
-
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.step;
+
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
+import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PersistScannerContextStepTest {
+ private static final String ANALYSIS_UUID = "UUID";
+
+ @ClassRule
+ public static final DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ @Rule
+ public BatchReportReaderRule reportReader = new BatchReportReaderRule();
+ @Rule
+ public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
+ .setUuid(ANALYSIS_UUID);
+
+ private DbClient dbClient = dbTester.getDbClient();
+ private PersistScannerContextStep underTest = new PersistScannerContextStep(reportReader, analysisMetadataHolder, dbClient);
+
+ @Test
+ public void getDescription() {
+ assertThat(underTest.getDescription()).isEqualTo("Persist scanner context");
+ }
+
+ @Test
+ public void log_scanner_logs() {
+ reportReader.setScannerLogs(asList("log1", "log2"));
+
+ underTest.execute();
+
+ assertThat(dbClient.scannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID))
+ .contains("log1" + '\n' + "log2");
+ }
+
+}
@Test
public void instances_throws_ISE_if_container_does_not_have_second_step() throws Exception {
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Component not found: class org.sonar.server.computation.task.projectanalysis.step.LogScannerContextStep");
+ expectedException.expectMessage("Component not found: class org.sonar.server.computation.task.projectanalysis.step.GenerateAnalysisUuid");
final ExtractReportStep reportExtractionStep = mock(ExtractReportStep.class);
ComponentContainer componentContainer = new ComponentContainer() {
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
-import com.google.common.collect.FluentIterable;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.internal.TestSystem2;
+import org.sonar.core.util.CloseableIterator;
+import org.sonar.core.util.stream.Collectors;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
private static final String AN_ANALYSIS_UUID = "U1";
- TestSystem2 system2 = new TestSystem2().setNow(1_450_000_000_000L);
+ private TestSystem2 system2 = new TestSystem2().setNow(1_450_000_000_000L);
@Rule
public DbTester db = DbTester.create(system2);
- DbSession dbSession = db.getSession();
- CeActivityDao underTest = new CeActivityDao(system2);
+ private DbSession dbSession = db.getSession();
+ private CeActivityDao underTest = new CeActivityDao(system2);
@Test
public void test_insert() {
return dto;
}
- private void insertWithCreationDate(String uuid, long date) {
+ private CeActivityDto insertWithCreationDate(String uuid, long date) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(uuid);
queueDto.setTaskType("fake");
dto.setStatus(CeActivityDto.Status.SUCCESS);
system2.setNow(date);
underTest.insert(db.getSession(), dto);
+ return dto;
+ }
+
+ private void insertScannerContext(String analysisUuid) {
+ db.getDbClient().scannerContextDao().insert(dbSession, analysisUuid, CloseableIterator.from(singletonList("scanner context of " + analysisUuid).iterator()));
+ dbSession.commit();
}
private List<String> selectPageOfUuids(int offset, int pageSize) {
- return FluentIterable.from(underTest.selectByQuery(db.getSession(), new CeTaskQuery(), offset, pageSize)).transform(CeActivityToUuid.INSTANCE).toList();
+ return underTest.selectByQuery(db.getSession(), new CeTaskQuery(), offset, pageSize).stream()
+ .map(CeActivityToUuid.INSTANCE::apply)
+ .collect(Collectors.toList());
}
private enum CeActivityToUuid implements Function<CeActivityDto, String> {