"PERIOD4_DATE" BIGINT,
"PERIOD5_MODE" VARCHAR(100),
"PERIOD5_PARAM" VARCHAR(100),
- "PERIOD5_DATE" BIGINT,
- "INCREMENTAL" BOOLEAN DEFAULT FALSE
+ "PERIOD5_DATE" BIGINT
);
CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID");
CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID");
public class CeTaskCharacteristicDto {
- public static final String INCREMENTAL_KEY = "incremental";
public static final String BRANCH_KEY = "branch";
public static final String BRANCH_TYPE_KEY = "branchType";
private String periodMode;
private String periodParam;
private Long periodDate;
- private boolean incremental = false;
public Long getId() {
return id;
return this;
}
- public boolean getIncremental() {
- return incremental;
- }
-
- public SnapshotDto setIncremental(boolean incremental) {
- this.incremental = incremental;
- return this;
- }
-
/**
* @return analysis date
*/
s.version as version,
s.period1_mode as periodMode,
s.period1_param as periodParam,
- s.period1_date as periodDate,
- s.incremental as incremental
+ s.period1_date as periodDate
</sql>
<sql id="viewsSnapshotColumns">
version,
period1_mode,
period1_param,
- period1_date,
- incremental)
+ period1_date)
values (
#{uuid, jdbcType=VARCHAR},
#{componentUuid, jdbcType=VARCHAR},
#{version, jdbcType=VARCHAR},
#{periodMode, jdbcType=VARCHAR},
#{periodParam, jdbcType=VARCHAR},
- #{periodDate, jdbcType=BIGINT},
- #{incremental, jdbcType=BOOLEAN})
+ #{periodDate, jdbcType=BIGINT})
</insert>
</mapper>
.setPeriodParam("30")
.setPeriodDate(1500000000001L)
.setVersion("2.1-SNAPSHOT")
- .setIncremental(false)
.setBuildDate(1500000000006L)
.setCreatedAt(1403042400000L));
assertThat(result.getBuildDate()).isEqualTo(1500000000006L);
assertThat(result.getCreatedAt()).isEqualTo(1403042400000L);
assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT");
- assertThat(result.getIncremental()).isFalse();
-
assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse();
}
.setPeriodDate(1500000000001L)
.setVersion("2.1-SNAPSHOT")
.setBuildDate(1500000000006L)
- .setIncremental(true)
.setCreatedAt(1403042400000L));
assertThat(dto.getId()).isNotNull();
assertThat(dto.getBuildDate()).isEqualTo(1500000000006L);
assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L);
assertThat(dto.getVersion()).isEqualTo("2.1-SNAPSHOT");
- assertThat(dto.getIncremental()).isTrue();
}
.setPeriodMode("days1")
.setPeriodParam("30")
.setPeriodDate(1_500_000_000_001L)
- .setBuildDate(1_500_000_000_006L)
- .setIncremental(false);
+ .setBuildDate(1_500_000_000_006L);
}
private CeActivityDto insertActivity(SnapshotDto analysis, CeActivityDto.Status status) {
.setVersion("1.0")
.setPeriodMode("mode1")
.setPeriodParam("param1")
- .setIncremental(true)
.setPeriodDate(parseDate("2014-06-01").getTime());
assertThat(snapshotDto.getId()).isEqualTo(10L);
assertThat(snapshotDto.getVersion()).isEqualTo("1.0");
assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1");
assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1");
- assertThat(snapshotDto.getIncremental()).isTrue();
assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime());
}
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!--switched_off="[null]" permanent_id="[null]" FAILURE_LEVEL="2"-->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<project_measures ID="1"
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<project_measures ID="2"
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- Open issue on file -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- Open issue on file -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshot with status "unprocessed" -> to be deleted -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- delete only resource 1 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- delete only resource 1 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- to be deleted -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshots to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshots to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshot to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
<!-- snapshot to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
- incremental="[false]"
/>
</dataset>
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.platform.db.migration.version.v66;
-
-import java.sql.SQLException;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
-import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-public class AddIncrementalColumnToSnapshotsTable extends DdlChange {
-
- public AddIncrementalColumnToSnapshotsTable(Database db) {
- super(db);
- }
-
- @Override
- public void execute(Context context) throws SQLException {
- context.execute(new AddColumnsBuilder(getDialect(), "snapshots")
- .addColumn(BooleanColumnDef.newBooleanColumnDefBuilder()
- .setColumnName("incremental")
- .setDefaultValue(false)
- .build())
- .build());
- }
-
-}
@Override
public void addSteps(MigrationStepRegistry registry) {
registry
- .add(1800, "Add incremental column to snapshots table", AddIncrementalColumnToSnapshotsTable.class)
.add(1801, "Create table CE task characteristics", CreateTableCeTaskCharacteristics.class)
.add(1802, "Delete leak settings on views", DeleteLeakSettingsOnViews.class)
.add(1803, "Fix empty USERS.EXTERNAL_IDENTITY and USERS.EXTERNAL_IDENTITY_PROVIDER", FixEmptyIdentityProviderInUsers.class)
.add(1806, "Create table project_branches", CreateTableProjectBranches.class)
.add(1807, "Add on project_branches key", AddIndexOnProjectBranchesKey.class)
.add(1808, "Add branch column to projects table", AddBranchColumnToProjectsTable.class)
- .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class)
- ;
+ .add(1809, "Populate project_branches with existing main branches", PopulateMainProjectBranches.class);
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.platform.db.migration.version.v66;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.db.CoreDbTester;
-
-public class AddIncrementalColumnToSnapshotsTableTest {
- @Rule
- public CoreDbTester db = CoreDbTester.createForSchema(AddIncrementalColumnToSnapshotsTableTest.class, "old_snapshots.sql");
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private AddIncrementalColumnToSnapshotsTable underTest = new AddIncrementalColumnToSnapshotsTable(db.database());
-
- @Test
- public void migration_adds_column_to_empty_table() throws SQLException {
- underTest.execute();
-
- verifyAddedColumns();
- }
-
- @Test
- public void migration_is_not_reentrant() throws SQLException {
- underTest.execute();
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Fail to execute ");
- underTest.execute();
- }
-
- private void verifyAddedColumns() {
- db.assertColumnDefinition("snapshots", "incremental", Types.BOOLEAN, null, true);
- }
-
-}
private DbVersion66 underTest = new DbVersion66();
@Test
- public void migrationNumber_starts_at_1800() {
- verifyMinimumMigrationNumber(underTest, 1800);
+ public void migrationNumber_starts_at_1801() {
+ verifyMinimumMigrationNumber(underTest, 1801);
}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 10);
+ verifyMigrationCount(underTest, 9);
}
}
.setResponseExample(getClass().getResource("activity-example.json"))
.setHandler(this)
.setChangelog(
- new Change("5.5", "it's no more possible to specify the page parameter.<"),
+ new Change("5.5", "it's no more possible to specify the page parameter."),
new Change("6.1", "field \"logs\" is deprecated and its value is always false"),
- new Change("6.6", "field \"incremental\" is added"),
new Change("6.6", "fields \"branch\" and \"branchType\" added"))
.setSince("5.2");
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.KeyExamples;
+import org.sonarqube.ws.WsCe.ProjectResponse;
import static org.sonar.db.Pagination.forPage;
import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
-import static org.sonarqube.ws.WsCe.ProjectResponse;
import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
.setResponseExample(getClass().getResource("component-example.json"))
.setChangelog(
new Change("6.1", "field \"logs\" is deprecated and its value is always false"),
- new Change("6.6", "field \"incremental\" is added"),
new Change("6.6", "fields \"branch\" and \"branchType\" added"))
.setHandler(this);
*/
package org.sonar.server.ce.ws;
-import static org.sonar.server.ws.WsUtils.checkRequest;
-
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
-
import org.apache.commons.lang.StringUtils;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.server.ws.WsUtils;
import org.sonarqube.ws.WsCe;
+import static org.sonar.server.ws.WsUtils.checkRequest;
+
public class SubmitAction implements CeWsAction {
private static final String PARAM_ORGANIZATION_KEY = "organization";
.createParam(PARAM_ANALYSIS_CHARACTERISTIC)
.setRequired(false)
.setDescription("Optional characteristic of the analysis. Can be repeated to define multiple characteristics.")
- .setExampleValue("incremental=true")
+ .setExampleValue("branchType=long")
.setSince("6.6");
}
.setResponseExample(getClass().getResource("task-example.json"))
.setSince("5.2")
.setChangelog(
- new Change("6.6", "field \"incremental\" is added"),
new Change("6.6", "fields \"branch\" and \"branchType\" added"))
.setHandler(this);
builder.setSubmittedAt(formatDateTime(new Date(dto.getCreatedAt())));
setNullable(dto.getStartedAt(), builder::setStartedAt, DateUtils::formatDateTime);
setNullable(computeExecutionTimeMs(dto), builder::setExecutionTimeMs);
- setIncremental(builder, dto.getUuid(), componentDtoCache);
setBranch(builder, dto.getUuid(), componentDtoCache);
return builder.build();
}
if (analysisUuid != null) {
builder.setAnalysisId(analysisUuid);
}
- setIncremental(builder, dto.getUuid(), componentDtoCache);
setBranch(builder, dto.getUuid(), componentDtoCache);
setNullable(analysisUuid, builder::setAnalysisId);
setNullable(dto.getSubmitterLogin(), builder::setSubmitterLogin);
return builder;
}
- private static WsCe.Task.Builder setIncremental(WsCe.Task.Builder builder, String taskUuid, DtoCache componentDtoCache) {
- builder.setIncremental(componentDtoCache.hasIncrementalCharacteristic(taskUuid));
- return builder;
- }
-
private static WsCe.Task.Builder setBranch(WsCe.Task.Builder builder, String taskUuid, DtoCache componentDtoCache) {
componentDtoCache.getBranchName(taskUuid).ifPresent(
b -> {
return organizationDto.getKey();
}
- boolean hasIncrementalCharacteristic(String taskUuid) {
- return characteristicsByTaskUuid.get(taskUuid).stream()
- .filter(c -> c.getKey().equals(CeTaskCharacteristicDto.INCREMENTAL_KEY))
- .anyMatch(c -> c.getValue().equals("true"));
- }
-
Optional<String> getBranchName(String taskUuid) {
return characteristicsByTaskUuid.get(taskUuid).stream()
.filter(c -> c.getKey().equals(CeTaskCharacteristicDto.BRANCH_KEY))
*/
boolean isFirstAnalysis();
- /**
- * Whether this is an incremental analysis or a full analysis.
- */
- boolean isIncrementalAnalysis();
-
/**
* Return the last analysis of the project.
* If it's the first analysis, it will return null.
import java.util.Optional;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import org.sonar.db.component.BranchType;
import org.sonar.server.computation.util.InitializedProperty;
import org.sonar.server.qualityprofile.QualityProfile;
private final InitializedProperty<Organization> organization = new InitializedProperty<>();
private final InitializedProperty<String> uuid = new InitializedProperty<>();
private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
- private final InitializedProperty<Boolean> incrementalAnalysis = new InitializedProperty<>();
private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>();
private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
private final InitializedProperty<Branch> branch = new InitializedProperty<>();
return getBaseAnalysis() == null;
}
- @Override
- public MutableAnalysisMetadataHolder setIncrementalAnalysis(boolean isIncrementalAnalysis) {
- checkState(!incrementalAnalysis.isInitialized(), "Incremental analysis flag has already been set");
- this.incrementalAnalysis.setProperty(isIncrementalAnalysis);
- return this;
- }
-
- @Override
- public boolean isIncrementalAnalysis() {
- checkState(incrementalAnalysis.isInitialized(), "Incremental analysis flag has not been set");
- return this.incrementalAnalysis.getProperty();
- }
-
@Override
public MutableAnalysisMetadataHolder setBaseAnalysis(@Nullable Analysis baseAnalysis) {
checkState(!this.baseProjectSnapshot.isInitialized(), "Base project snapshot has already been set");
*/
MutableAnalysisMetadataHolder setAnalysisDate(long date);
- /**
- * @throws IllegalStateException if it has already been set
- */
- MutableAnalysisMetadataHolder setIncrementalAnalysis(boolean isIncrementalAnalysis);
-
/**
* @throws IllegalStateException if baseAnalysis has already been set
*/
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.duplication;
-
-public interface IncrementalDuplicationMeasures {
- void execute();
-}
*/
package org.sonar.server.computation.task.projectanalysis.issue;
-import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
-
-import java.util.Collection;
-import java.util.List;
import java.util.Map;
-
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
import org.sonar.server.util.cache.DiskCache;
+import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
+
public class IntegrateIssuesVisitor extends TypeAwareVisitorAdapter {
private final IssueCache issueCache;
private final IssueLifecycle issueLifecycle;
private final IssueVisitors issueVisitors;
- private final ComponentIssuesLoader issuesLoader;
- private final AnalysisMetadataHolder analysisMetadataHolder;
private final IssueTrackingDelegator issueTracking;
- public IntegrateIssuesVisitor(IssueCache issueCache, IssueLifecycle issueLifecycle, IssueVisitors issueVisitors, ComponentIssuesLoader issuesLoader,
- AnalysisMetadataHolder analysisMetadataHolder, IssueTrackingDelegator issueTracking) {
+ public IntegrateIssuesVisitor(IssueCache issueCache, IssueLifecycle issueLifecycle, IssueVisitors issueVisitors, IssueTrackingDelegator issueTracking) {
super(CrawlerDepthLimit.FILE, POST_ORDER);
this.issueCache = issueCache;
this.issueLifecycle = issueLifecycle;
this.issueVisitors = issueVisitors;
- this.issuesLoader = issuesLoader;
- this.analysisMetadataHolder = analysisMetadataHolder;
this.issueTracking = issueTracking;
}
try (DiskCache<DefaultIssue>.DiskAppender cacheAppender = issueCache.newAppender()) {
issueVisitors.beforeComponent(component);
- if (isIncremental(component)) {
- // no tracking needed, simply re-use existing issues
- List<DefaultIssue> issues = issuesLoader.loadForComponentUuid(component.getUuid());
- reuseOpenIssues(component, issues, cacheAppender);
- } else {
- TrackingResult tracking = issueTracking.track(component);
- fillNewOpenIssues(component, tracking.newIssues(), cacheAppender);
- fillExistingOpenIssues(component, tracking.issuesToMerge(), cacheAppender);
- closeIssues(component, tracking.issuesToClose(), cacheAppender);
- copyIssues(component, tracking.issuesToCopy(), cacheAppender);
- }
+ TrackingResult tracking = issueTracking.track(component);
+ fillNewOpenIssues(component, tracking.newIssues(), cacheAppender);
+ fillExistingOpenIssues(component, tracking.issuesToMerge(), cacheAppender);
+ closeIssues(component, tracking.issuesToClose(), cacheAppender);
+ copyIssues(component, tracking.issuesToCopy(), cacheAppender);
issueVisitors.afterComponent(component);
} catch (Exception e) {
throw new IllegalStateException(String.format("Fail to process issues of component '%s'", component.getKey()), e);
}
}
- private boolean isIncremental(Component component) {
- return analysisMetadataHolder.isIncrementalAnalysis() && component.getStatus() == Status.SAME;
- }
-
private void fillNewOpenIssues(Component component, Iterable<DefaultIssue> issues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
for (DefaultIssue issue : issues) {
issueLifecycle.initNewOpenIssue(issue);
}
}
- private void reuseOpenIssues(Component component, Collection<DefaultIssue> issues, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
- for (DefaultIssue issue : issues) {
- process(component, issue, cacheAppender);
- }
- }
-
private void fillExistingOpenIssues(Component component, Map<DefaultIssue, DefaultIssue> matched, DiskCache<DefaultIssue>.DiskAppender cacheAppender) {
for (Map.Entry<DefaultIssue, DefaultIssue> entry : matched.entrySet()) {
DefaultIssue raw = entry.getKey();
* Sets the appropriate fields when an issue is :
* <ul>
* <li>newly created</li>
- * <li>reused in incremental analysis</li>
* <li>merged the related base issue</li>
* <li>relocated (only manual issues)</li>
* </ul>
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.measure;
-
-/**
- * Provided by the incremental plugin
- */
-public interface IncrementalMeasureTransition extends Runnable {
-
-}
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import javax.annotation.Nullable;
-
import org.sonar.api.measures.CoreMetrics;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationMeasures;
-import org.sonar.server.computation.task.projectanalysis.duplication.IncrementalDuplicationMeasures;
import org.sonar.server.computation.task.step.ComputationStep;
/**
* This step must be executed after {@link CommentMeasuresStep} as it depends on {@link CoreMetrics#COMMENT_LINES}
*/
public class DuplicationMeasuresStep implements ComputationStep {
- private final AnalysisMetadataHolder analysisMetadataHolder;
private final DuplicationMeasures defaultDuplicationMeasures;
- private final IncrementalDuplicationMeasures incrementalDuplicationsMeasures;
- public DuplicationMeasuresStep(AnalysisMetadataHolder analysisMetadataHolder, DuplicationMeasures defaultDuplicationMeasures,
- @Nullable IncrementalDuplicationMeasures incrementalDuplicationMeasures) {
- this.analysisMetadataHolder = analysisMetadataHolder;
+ public DuplicationMeasuresStep(DuplicationMeasures defaultDuplicationMeasures) {
this.defaultDuplicationMeasures = defaultDuplicationMeasures;
- this.incrementalDuplicationsMeasures = incrementalDuplicationMeasures;
- }
-
- /**
- * Constructor used by Pico in Views where no IncrementalDuplicationMeasures is available.
- */
- public DuplicationMeasuresStep(AnalysisMetadataHolder analysisMetadataHolder, DuplicationMeasures defaultDuplicationMeasures) {
- this(analysisMetadataHolder, defaultDuplicationMeasures, null);
}
@Override
@Override
public void execute() {
- if (analysisMetadataHolder.isIncrementalAnalysis()) {
- incrementalDuplicationsMeasures.execute();
- } else {
- defaultDuplicationMeasures.execute();
- }
+ defaultDuplicationMeasures.execute();
}
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.server.computation.task.projectanalysis.measure.IncrementalMeasureTransition;
-import org.sonar.server.computation.task.step.ComputationStep;
-
-public class IncrementalMeasureTransitionStep implements ComputationStep {
- private final AnalysisMetadataHolder analysisMetadataHolder;
- private final IncrementalMeasureTransition runnable;
-
- public IncrementalMeasureTransitionStep(AnalysisMetadataHolder analysisMetadataHolder) {
- this(analysisMetadataHolder, null);
- }
-
- public IncrementalMeasureTransitionStep(AnalysisMetadataHolder analysisMetadataHolder, IncrementalMeasureTransition runnable) {
- this.analysisMetadataHolder = analysisMetadataHolder;
- this.runnable = runnable;
- }
-
- @Override
- public void execute() {
- if (analysisMetadataHolder.isIncrementalAnalysis()) {
- runnable.run();
- }
- }
-
- @Override
- public String getDescription() {
- return "Incremental measure transition";
- }
-}
import javax.annotation.Nonnull;
import org.sonar.core.util.CloseableIterator;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
private final TreeRootHolder treeRootHolder;
private final BatchReportReader batchReportReader;
private final DuplicationRepository duplicationRepository;
- private final AnalysisMetadataHolder analysisMetadataHolder;
- public LoadDuplicationsFromReportStep(TreeRootHolder treeRootHolder, BatchReportReader batchReportReader,
- DuplicationRepository duplicationRepository, AnalysisMetadataHolder analysisMetadataHolder) {
+ public LoadDuplicationsFromReportStep(TreeRootHolder treeRootHolder, BatchReportReader batchReportReader, DuplicationRepository duplicationRepository) {
this.treeRootHolder = treeRootHolder;
this.batchReportReader = batchReportReader;
this.duplicationRepository = duplicationRepository;
- this.analysisMetadataHolder = analysisMetadataHolder;
}
@Override
@Override
public void execute() {
- if (!analysisMetadataHolder.isIncrementalAnalysis()) {
- new DepthTraversalTypeAwareCrawler(
- new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
- @Override
- public void visitFile(Component file) {
- try (CloseableIterator<ScannerReport.Duplication> duplications = batchReportReader.readComponentDuplications(file.getReportAttributes().getRef())) {
- int idGenerator = 1;
- while (duplications.hasNext()) {
- loadDuplications(file, duplications.next(), idGenerator);
- idGenerator++;
- }
+ new DepthTraversalTypeAwareCrawler(
+ new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
+ @Override
+ public void visitFile(Component file) {
+ try (CloseableIterator<ScannerReport.Duplication> duplications = batchReportReader.readComponentDuplications(file.getReportAttributes().getRef())) {
+ int idGenerator = 1;
+ while (duplications.hasNext()) {
+ loadDuplications(file, duplications.next(), idGenerator);
+ idGenerator++;
}
}
- }).visit(treeRootHolder.getRoot());
- }
+ }
+ }).visit(treeRootHolder.getRoot());
}
private void loadDuplications(Component file, ScannerReport.Duplication duplication, int id) {
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.qualityprofile.QualityProfile;
-import static java.util.stream.Collectors.toMap;
import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Maps.transformValues;
import static java.lang.String.format;
-import static org.apache.commons.lang.StringUtils.isNotEmpty;
+import static java.util.stream.Collectors.toMap;
import static org.sonar.core.util.stream.MoreCollectors.toList;
/**
loadMetadata(reportMetadata);
Organization organization = loadOrganization(reportMetadata);
loadProject(reportMetadata, organization);
- loadIncrementalMode(reportMetadata);
loadQualityProfiles(reportMetadata, organization);
branchLoader.load(reportMetadata);
}
return pluginInfo.getBasePlugin();
}
- private void loadIncrementalMode(ScannerReport.Metadata reportMetadata) {
- analysisMetadata.setIncrementalAnalysis(reportMetadata.getIncremental());
- }
-
/**
* Check that the Quality profiles sent by scanner correctly relate to the project organization.
*/
@Override
public void visitProject(Component project) {
- SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project, true, analysisMetadataHolder.isIncrementalAnalysis());
+ SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project, true);
updateSnapshotPeriods(snapshot);
persist(snapshot, dbSession);
}
@Override
public void visitView(Component view) {
- SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false, false);
+ SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false);
updateSnapshotPeriods(snapshot);
persist(snapshot, dbSession);
}
snapshotDto.setPeriodDate(period.getSnapshotDate());
}
- private SnapshotDto createAnalysis(String snapshotUuid, Component component, boolean setVersion, boolean incremental) {
+ private SnapshotDto createAnalysis(String snapshotUuid, Component component, boolean setVersion) {
String componentUuid = component.getUuid();
return new SnapshotDto()
.setUuid(snapshotUuid)
.setVersion(setVersion ? component.getReportAttributes().getVersion() : null)
.setComponentUuid(componentUuid)
- .setIncremental(incremental)
.setLast(false)
.setStatus(SnapshotDto.STATUS_UNPROCESSED)
.setCreatedAt(analysisDate)
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import java.util.List;
-import javax.annotation.Nullable;
import org.sonar.core.util.CloseableIterator;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.duplication.DuplicationUnitDto;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.server.computation.task.projectanalysis.analysis.Analysis;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
try (DbSession dbSession = dbClient.openSession(true)) {
Component project = treeRootHolder.getRoot();
- Analysis baseAnalysis = analysisMetadataHolder.getBaseAnalysis();
- String lastAnalysysUuid = (baseAnalysis != null) ? baseAnalysis.getUuid() : null;
- new DepthTraversalTypeAwareCrawler(new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid(), lastAnalysysUuid)).visit(project);
+ new DepthTraversalTypeAwareCrawler(new DuplicationVisitor(dbSession, analysisMetadataHolder.getUuid())).visit(project);
dbSession.commit();
}
}
private final DbSession session;
private final String analysisUuid;
- private final String lastAnalysisUuid;
- private DuplicationVisitor(DbSession session, String analysisUuid, @Nullable String lastAnalysisUuid) {
+ private DuplicationVisitor(DbSession session, String analysisUuid) {
super(CrawlerDepthLimit.FILE, PRE_ORDER);
this.session = session;
this.analysisUuid = analysisUuid;
- this.lastAnalysisUuid = lastAnalysisUuid;
}
@Override
}
private void visitComponent(Component component) {
- if (analysisMetadataHolder.isIncrementalAnalysis() && component.getStatus() == Status.SAME) {
- readFromDb(component);
- } else {
- readFromReport(component);
- }
+ readFromReport(component);
}
private void readFromReport(Component component) {
}
}
- private void readFromDb(Component component) {
- int indexInFile = 0;
- List<DuplicationUnitDto> units = dbClient.duplicationDao().selectComponent(session, component.getUuid(), lastAnalysisUuid);
- for (DuplicationUnitDto unit : units) {
- unit.setAnalysisUuid(analysisUuid);
- unit.setIndexInFile(indexInFile);
- dbClient.duplicationDao().insert(session, unit);
- indexInFile++;
- }
- }
}
@Override
import org.sonar.db.source.FileSourceDto;
import org.sonar.db.source.FileSourceDto.Type;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
private final SourceLinesRepository sourceLinesRepository;
private final ScmInfoRepository scmInfoRepository;
private final DuplicationRepository duplicationRepository;
- private final AnalysisMetadataHolder analysisMetadataHolder;
public PersistFileSourcesStep(DbClient dbClient, System2 system2, TreeRootHolder treeRootHolder, BatchReportReader reportReader, SourceLinesRepository sourceLinesRepository,
- ScmInfoRepository scmInfoRepository, DuplicationRepository duplicationRepository, AnalysisMetadataHolder analysisMetadataHolder) {
+ ScmInfoRepository scmInfoRepository, DuplicationRepository duplicationRepository) {
this.dbClient = dbClient;
this.system2 = system2;
this.treeRootHolder = treeRootHolder;
this.sourceLinesRepository = sourceLinesRepository;
this.scmInfoRepository = scmInfoRepository;
this.duplicationRepository = duplicationRepository;
- this.analysisMetadataHolder = analysisMetadataHolder;
}
@Override
@Override
public void visitFile(Component file) {
- if (analysisMetadataHolder.isIncrementalAnalysis() && file.getStatus() == Status.SAME) {
- return;
- }
-
try (CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file);
- LineReaders lineReaders = new LineReaders(reportReader, scmInfoRepository, duplicationRepository, file)) {
+ LineReaders lineReaders = new LineReaders(reportReader, scmInfoRepository, duplicationRepository, file)) {
ComputeFileSourceData computeFileSourceData = new ComputeFileSourceData(linesIterator, lineReaders.readers(), file.getFileAttributes().getLines());
ComputeFileSourceData.Data fileSourceData = computeFileSourceData.compute();
persistSource(fileSourceData, file.getUuid(), lineReaders.getLatestChange());
ValidateProjectStep.class,
LoadQualityProfilesStep.class,
-
- // copy data in the incremental mode
- IncrementalMeasureTransitionStep.class,
// load project related stuffs
LoadQualityGateStep.class,
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import static com.google.common.collect.FluentIterable.from;
-import static java.lang.String.format;
-import static org.sonar.api.utils.DateUtils.formatDateTime;
-
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
-
-import javax.annotation.Nullable;
-
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.MessageException;
import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.validation.ValidateIncremental;
import org.sonar.server.computation.task.step.ComputationStep;
-import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
+import static com.google.common.collect.FluentIterable.from;
+import static java.lang.String.format;
+import static org.sonar.api.utils.DateUtils.formatDateTime;
/**
* Validate project and modules. It will fail in the following cases :
private final BatchReportReader reportReader;
private final TreeRootHolder treeRootHolder;
private final AnalysisMetadataHolder analysisMetadataHolder;
- private final ValidateIncremental validateIncremental;
-
- public ValidateProjectStep(DbClient dbClient, BatchReportReader reportReader, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder) {
- this(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, null);
- }
public ValidateProjectStep(DbClient dbClient, BatchReportReader reportReader, TreeRootHolder treeRootHolder,
- AnalysisMetadataHolder analysisMetadataHolder, @Nullable ValidateIncremental validateIncremental) {
+ AnalysisMetadataHolder analysisMetadataHolder) {
this.dbClient = dbClient;
this.reportReader = reportReader;
this.treeRootHolder = treeRootHolder;
this.analysisMetadataHolder = analysisMetadataHolder;
- this.validateIncremental = validateIncremental;
}
@Override
public void visitProject(Component rawProject) {
this.rawProject = rawProject;
String rawProjectKey = rawProject.getKey();
- validateIncremental(rawProjectKey);
- validateNotIncrementalAndFirstAnalysis(rawProjectKey);
validateBatchKey(rawProject);
Optional<ComponentDto> baseProject = loadBaseComponent(rawProjectKey);
}
}
- private void validateIncremental(String rawProjectKey) {
- if (analysisMetadataHolder.isIncrementalAnalysis()) {
- if (validateIncremental == null) {
- validationMessages.add(format("Can't process an incremental analysis of the project \"%s\" because the incremental plugin is not loaded."
- + " Please install the plugin or launch a full analysis of the project.", rawProjectKey));
- } else if (!validateIncremental.execute()) {
- validationMessages.add(format("The installation of the incremental plugin is invalid. Can't process the incremental analysis "
- + "of the project \"%s\".", rawProjectKey));
- }
- }
- }
-
- private void validateNotIncrementalAndFirstAnalysis(String rawProjectKey) {
- if (analysisMetadataHolder.isIncrementalAnalysis() && analysisMetadataHolder.isFirstAnalysis()) {
- validationMessages.add(format("The project \"%s\" hasn't been analysed before and the first analysis can't be incremental."
- + " Please launch a full analysis of the project.", rawProjectKey));
- }
- }
-
private void validateProjectKey(Optional<ComponentDto> baseProject, String rawProjectKey) {
if (baseProject.isPresent() && !baseProject.get().projectUuid().equals(baseProject.get().uuid())) {
// Project key is already used as a module of another project
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.validation;
-
-public interface ValidateIncremental {
- boolean execute();
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.server.computation.task.projectanalysis.validation;
-
-import javax.annotation.ParametersAreNonnullByDefault;
import static org.sonar.db.ce.CeQueueDto.Status.PENDING;
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY;
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY;
-import static org.sonar.db.ce.CeTaskCharacteristicDto.INCREMENTAL_KEY;
import static org.sonar.db.component.BranchType.LONG;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY;
assertThat(task.hasAnalysisId()).isFalse();
assertThat(task.getExecutionTimeMs()).isEqualTo(500L);
assertThat(task.getLogs()).isFalse();
- assertThat(task.getIncremental()).isFalse();
task = activityResponse.getTasks(1);
assertThat(task.getId()).isEqualTo("T1");
assertThat(task.getComponentId()).isEqualTo(project1.uuid());
assertThat(task.getLogs()).isFalse();
assertThat(task.getOrganization()).isEqualTo(org1.getKey());
- assertThat(task.getIncremental()).isFalse();
}
@Test
assertThat(result.getTasksCount()).isEqualTo(2);
}
- @Test
- public void incremental_analysis_on_single_project() {
- ComponentDto project = db.components().insertPrivateProject();
- SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
- insertCharacteristic(activity, INCREMENTAL_KEY, "true");
- userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
-
- ActivityResponse activityResponse = call(ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, project.uuid()));
-
- assertThat(activityResponse.getTasksList())
- .extracting(Task::getId, Task::getIncremental)
- .containsExactlyInAnyOrder(tuple("T1", true));
- }
-
- @Test
- public void incremental_analysis_on_search_text() {
- ComponentDto project = db.components().insertPrivateProject();
- SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- SnapshotDto standardAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(false));
- CeActivityDto incrementalTask = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
- insertCharacteristic(incrementalTask, INCREMENTAL_KEY, "true");
- insertActivity("T2", project, SUCCESS, standardAnalysis);
- logInAsSystemAdministrator();
-
- ActivityResponse activityResponse = call(ws.newRequest()
- .setParam(PARAM_COMPONENT_QUERY, project.name()));
-
- assertThat(activityResponse.getTasksList())
- .extracting(Task::getId, Task::getIncremental)
- .containsExactlyInAnyOrder(
- tuple("T1", true),
- tuple("T2", false));
- }
-
- @Test
- public void incremental_analysis_on_search_uuid() {
- ComponentDto project = db.components().insertPrivateProject();
- SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
- insertCharacteristic(activity, INCREMENTAL_KEY, "true");
- logInAsSystemAdministrator();
-
- ActivityResponse activityResponse = call(ws.newRequest()
- .setParam(PARAM_COMPONENT_QUERY, "T1"));
-
- assertThat(activityResponse.getTasksList())
- .extracting(Task::getId, Task::getIncremental)
- .containsExactlyInAnyOrder(tuple("T1", true));
- }
-
- @Test
- public void incremental_on_in_queue_analysis() {
- ComponentDto project = db.components().insertPrivateProject();
- CeQueueDto queue1 = insertQueue("T1", project, PENDING);
- insertCharacteristic(queue1, INCREMENTAL_KEY, "true");
- CeQueueDto queue2 = insertQueue("T2", project, IN_PROGRESS);
- insertCharacteristic(queue2, INCREMENTAL_KEY, "true");
- userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
-
- ActivityResponse activityResponse = call(ws.newRequest()
- .setParam(PARAM_COMPONENT_ID, project.uuid())
- .setParam("status", "PENDING,FAILED,IN_PROGRESS"));
-
- assertThat(activityResponse.getTasksList())
- .extracting(Task::getId, Task::getIncremental)
- .containsExactlyInAnyOrder(
- tuple("T1", true),
- tuple("T2", true));
- }
-
@Test
public void long_living_branch_in_past_activity() {
logInAsSystemAdministrator();
import static org.sonar.db.ce.CeQueueDto.Status.PENDING;
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_KEY;
import static org.sonar.db.ce.CeTaskCharacteristicDto.BRANCH_TYPE_KEY;
-import static org.sonar.db.ce.CeTaskCharacteristicDto.INCREMENTAL_KEY;
import static org.sonar.db.component.BranchType.LONG;
import static org.sonar.db.component.BranchType.SHORT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
.extracting(WsCe.Task::getOrganization)
.containsOnly(organization.getKey());
assertThat(response.getCurrent().getOrganization()).isEqualTo(organization.getKey());
- assertThat(response.getCurrent().getIncremental()).isFalse();
}
@Test
assertThat(response.getCurrent().getId()).isEqualTo("T3");
}
- @Test
- public void incremental_analysis_by_component_key() {
- ComponentDto project = db.components().insertPrivateProject();
- userSession.logIn().addProjectPermission(UserRole.USER, project);
- SnapshotDto incrementalAnalysis = db.components().insertSnapshot(project, s -> s.setIncremental(true));
- CeActivityDto activity = insertActivity("T1", project, SUCCESS, incrementalAnalysis);
- insertCharacteristic(activity, INCREMENTAL_KEY, "true");
-
- WsCe.ProjectResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
- .executeProtobuf(WsCe.ProjectResponse.class);
-
- assertThat(response.getCurrent())
- .extracting(WsCe.Task::getId, WsCe.Task::getIncremental)
- .containsExactlyInAnyOrder("T1", true);
- }
-
- @Test
- public void incremental_on_in_queue_analysis() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
- userSession.addProjectPermission(UserRole.USER, project);
- CeQueueDto queue1 = insertQueue("T1", project, IN_PROGRESS);
- insertCharacteristic(queue1, INCREMENTAL_KEY, "true");
- CeQueueDto queue2 = insertQueue("T2", project, PENDING);
- insertCharacteristic(queue2, INCREMENTAL_KEY, "true");
-
- WsCe.ProjectResponse response = ws.newRequest()
- .setParam(PARAM_COMPONENT, project.getKey())
- .executeProtobuf(WsCe.ProjectResponse.class);
-
- assertThat(response.getQueueList())
- .extracting(WsCe.Task::getId, WsCe.Task::getIncremental)
- .containsOnly(
- tuple("T1", true),
- tuple("T2", true));
- }
-
@Test
public void long_living_branch_in_activity() {
ComponentDto project = db.components().insertMainBranch();
CeQueueDto shortLivingBranchQueue = insertQueue("Short", project, PENDING);
insertCharacteristic(shortLivingBranchQueue, BRANCH_KEY, shortLivingBranch.getBranch());
insertCharacteristic(shortLivingBranchQueue, BRANCH_TYPE_KEY, SHORT.name());
- CeQueueDto incrementalQueue = insertQueue("Incremental", project, PENDING);
- insertCharacteristic(incrementalQueue, INCREMENTAL_KEY, "true");
WsCe.ProjectResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, longLivingBranch.getKey())
.executeProtobuf(WsCe.ProjectResponse.class);
assertThat(response.getQueueList())
- .extracting(WsCe.Task::getId, WsCe.Task::getComponentKey, WsCe.Task::getBranch, WsCe.Task::getBranchType, WsCe.Task::getIncremental)
+ .extracting(WsCe.Task::getId, WsCe.Task::getComponentKey, WsCe.Task::getBranch, WsCe.Task::getBranchType)
.containsOnly(
- tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, false),
- tuple("Long", longLivingBranch.getKey(), longLivingBranch.getBranch(), Common.BranchType.LONG, false),
- tuple("Short", shortLivingBranch.getKey(), shortLivingBranch.getBranch(), Common.BranchType.SHORT, false),
- tuple("Incremental", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, true));
+ tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE),
+ tuple("Long", longLivingBranch.getKey(), longLivingBranch.getBranch(), Common.BranchType.LONG),
+ tuple("Short", shortLivingBranch.getKey(), shortLivingBranch.getBranch(), Common.BranchType.SHORT));
}
@Test
*/
package org.sonar.server.ce.ws;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyMapOf;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonarqube.ws.MediaTypes;
import org.sonarqube.ws.WsCe;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyMapOf;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class SubmitActionTest {
private static final CeTask A_CE_TASK = new CeTask.Builder()
when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), Matchers.isNull(String.class), eq("My Project"),
anyMapOf(String.class, String.class), any(InputStream.class))).thenReturn(A_CE_TASK);
- String[] characteristics = {"branch=branch1", "incremental=true", "key=value1=value2"};
+ String[] characteristics = {"branch=branch1", "key=value1=value2"};
WsCe.SubmitResponse submitResponse = tester.newRequest()
.setParam("projectKey", "my_project")
.setParam("projectName", "My Project")
verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), Matchers.isNull(String.class), eq("My Project"),
map.capture(), any(InputStream.class));
- assertThat(map.getValue()).containsOnly(entry("incremental", "true"), entry("branch", "branch1"), entry("key", "value1=value2"));
+ assertThat(map.getValue()).containsOnly(entry("branch", "branch1"), entry("key", "value1=value2"));
}
@Test
assertThat(taskResponse.getTask().getComponentName()).isEqualTo(project.name());
assertThat(taskResponse.getTask().hasExecutionTimeMs()).isFalse();
assertThat(taskResponse.getTask().getLogs()).isFalse();
- assertThat(taskResponse.getTask().getIncremental()).isFalse();
}
@Test
assertThat(task.getLogs()).isFalse();
}
- @Test
- public void incremental_on_queued_task() {
- logInAsRoot();
-
- ComponentDto project = db.components().insertPrivateProject();
- CeQueueDto queueDto = createAndPersistQueueTask(project);
- insertCharacteristic(queueDto, "incremental", "true");
-
- WsCe.TaskResponse taskResponse = ws.newRequest()
- .setParam("id", SOME_TASK_UUID)
- .executeProtobuf(WsCe.TaskResponse.class);
-
- assertThat(taskResponse.getTask().getIncremental()).isTrue();
- }
-
- @Test
- public void incremental_on_archived_task() {
- logInAsRoot();
-
- ComponentDto project = db.components().insertPrivateProject();
- db.components().insertSnapshot(project, s -> s.setIncremental(true));
- CeActivityDto activity = createAndPersistArchivedTask(project);
- insertCharacteristic(activity, "incremental", "true");
-
- WsCe.TaskResponse taskResponse = ws.newRequest()
- .setParam("id", SOME_TASK_UUID)
- .executeProtobuf(WsCe.TaskResponse.class);
-
- assertThat(taskResponse.getTask().getIncremental()).isTrue();
- }
-
@Test
public void long_living_branch_in_past_activity() {
logInAsRoot();
underTest.setCrossProjectDuplicationEnabled(false);
}
- @Test
- public void setIsIncrementalAnalysis_throws_ISE_when_called_twice() {
- AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setIncrementalAnalysis(true);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Incremental analysis flag has already been set");
- underTest.setIncrementalAnalysis(false);
- }
-
- @Test
- public void isIncrementalAnalysis_return_true() {
- AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
-
- underTest.setIncrementalAnalysis(true);
-
- assertThat(underTest.isIncrementalAnalysis()).isEqualTo(true);
- }
-
- @Test
- public void isIncrementalAnalysis_return_false() {
- AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
-
- underTest.setIncrementalAnalysis(false);
-
- assertThat(underTest.isIncrementalAnalysis()).isEqualTo(false);
- }
-
- @Test
- public void isIncrementalAnalysisEnabled_throws_ISE_when_holder_is_not_initialized() {
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Incremental analysis flag has not been set");
-
- new AnalysisMetadataHolderImpl().isIncrementalAnalysis();
- }
-
- @Test
- public void setIsIncrementalAnalys_throws_ISE_when_called_twice() {
- AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setIncrementalAnalysis(true);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Incremental analysis flag has already been set");
- underTest.setIncrementalAnalysis(false);
- }
-
@Test
public void set_branch() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
- private final InitializedProperty<Boolean> incremental = new InitializedProperty<>();
-
private final InitializedProperty<Analysis> baseAnalysis = new InitializedProperty<>();
private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
return pluginsByKey.getProperty();
}
- @Override
- public boolean isIncrementalAnalysis() {
- checkState(incremental.isInitialized(), "Incremental mode flag has not been set");
- return incremental.getProperty();
- }
-
- @Override
- public AnalysisMetadataHolderRule setIncrementalAnalysis(boolean isIncrementalAnalysis) {
- this.incremental.setProperty(isIncrementalAnalysis);
- return this;
- }
-
@Override
public boolean isShortLivingBranch() {
Branch property = this.branch.getProperty();
return delegate.getScannerPluginsByKey();
}
- @Override
- public boolean isIncrementalAnalysis() {
- return delegate.isIncrementalAnalysis();
- }
-
- @Override
- public MutableAnalysisMetadataHolder setIncrementalAnalysis(boolean isIncrementalAnalysis) {
- delegate.setIncrementalAnalysis(isIncrementalAnalysis);
- return this;
- }
-
@Override
public boolean isShortLivingBranch() {
return delegate.isShortLivingBranch();
*/
package org.sonar.server.computation.task.projectanalysis.issue;
-import static com.google.common.collect.Lists.newArrayList;
-import static java.util.Arrays.asList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.sonar.server.computation.task.projectanalysis.component.ReportComponent.builder;
-
+import com.google.common.base.Optional;
import java.util.List;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
import org.sonar.server.computation.task.projectanalysis.component.MergeBranchComponentUuids;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRulesHolderRule;
import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryRule;
-import com.google.common.base.Optional;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.sonar.server.computation.task.projectanalysis.component.ReportComponent.builder;
public class IntegrateIssuesVisitorTest {
trackingDelegator = new IssueTrackingDelegator(shortBranchTracker, mergeBranchTracker, tracker, analysisMetadataHolder);
treeRootHolder.setRoot(PROJECT);
issueCache = new IssueCache(temp.newFile(), System2.INSTANCE);
- when(analysisMetadataHolder.isIncrementalAnalysis()).thenReturn(false);
- when(analysisMetadataHolder.getBranch()).thenReturn(java.util.Optional.of(new DefaultBranchImpl()));
when(issueFilter.accept(any(DefaultIssue.class), eq(FILE))).thenReturn(true);
- underTest = new IntegrateIssuesVisitor(issueCache, issueLifecycle, issueVisitors, issuesLoader, analysisMetadataHolder, trackingDelegator);
- }
-
- @Test
- public void process_issues_on_incremental_mode() {
- when(analysisMetadataHolder.isIncrementalAnalysis()).thenReturn(true);
-
- Component file = builder(Component.Type.FILE, FILE_REF)
- .setKey(FILE_KEY)
- .setUuid(FILE_UUID)
- .setStatus(Status.SAME)
- .build();
-
- addBaseIssue(RuleTesting.XOO_X1);
-
- underTest.visitAny(file);
-
- verify(issueLifecycle).doAutomaticTransition(defaultIssueCaptor.capture());
- assertThat(defaultIssueCaptor.getValue().ruleKey().rule()).isEqualTo("x1");
-
- assertThat(newArrayList(issueCache.traverse())).hasSize(1);
+ underTest = new IntegrateIssuesVisitor(issueCache, issueLifecycle, issueVisitors, trackingDelegator);
}
@Test
import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.MergeBranchComponentUuids;
import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepositoryImpl.NoScmInfo;
import org.sonar.server.computation.task.projectanalysis.source.SourceHashRepositoryImpl;
private ScmInfoDbLoader underTest = new ScmInfoDbLoader(analysisMetadataHolder, dbTester.getDbClient(), sourceHashRepository, mergeBranchComponentUuids);
- @Test
- public void dont_check_hash_for_unmodified_files_incremental_analysis() {
- analysisMetadataHolder.setIncrementalAnalysis(true);
- analysisMetadataHolder.setBranch(null);
- analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
-
- addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
-
- Component file = builder(Component.Type.FILE, FILE_REF).setKey("FILE_KEY").setUuid("FILE_UUID").setStatus(Status.SAME).build();
- ScmInfo scmInfo = underTest.getScmInfoFromDb(file);
- assertThat(scmInfo.getAllChangesets()).hasSize(1);
-
- assertThat(logTester.logs(TRACE)).containsOnly("Reading SCM info from db for file 'FILE_UUID'");
- }
-
@Test
public void returns_ScmInfo_from_DB_if_hashes_are_the_same() throws Exception {
analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
analysisMetadataHolder.setBranch(null);
- analysisMetadataHolder.setIncrementalAnalysis(false);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
addFileSourceInReport(1);
public void read_from_merge_branch_if_no_base() {
analysisMetadataHolder.setBaseAnalysis(null);
analysisMetadataHolder.setBranch(branch);
- analysisMetadataHolder.setIncrementalAnalysis(false);
String mergeFileUuid = "mergeFileUuid";
when(mergeBranchComponentUuids.getUuid(FILE.getKey())).thenReturn(mergeFileUuid);
public void returns_absent_when_branch_and_source_is_different() {
analysisMetadataHolder.setBaseAnalysis(null);
analysisMetadataHolder.setBranch(branch);
- analysisMetadataHolder.setIncrementalAnalysis(false);
String mergeFileUuid = "mergeFileUuid";
when(mergeBranchComponentUuids.getUuid(FILE.getKey())).thenReturn(mergeFileUuid);
public void returns_absent_when__hashes_are_not_the_same() throws Exception {
analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
analysisMetadataHolder.setBranch(null);
- analysisMetadataHolder.setIncrementalAnalysis(false);
addFileSourceInReport(1);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1) + "_different");
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationMeasures;
-import org.sonar.server.computation.task.projectanalysis.duplication.IncrementalDuplicationMeasures;
import org.sonar.server.computation.task.step.ComputationStep;
+import static org.mockito.Mockito.verify;
+
public class DuplicationMeasuresStepTest extends BaseStepTest {
@Mock
private DuplicationMeasures defaultDuplicationMeasures;
- @Mock
- private IncrementalDuplicationMeasures incrementalDuplicationMeasures;
- @Rule
- public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
private DuplicationMeasuresStep underTest;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
- underTest = new DuplicationMeasuresStep(analysisMetadataHolder, defaultDuplicationMeasures, incrementalDuplicationMeasures);
- }
-
- @Test
- public void incremental_analysis_mode() {
- analysisMetadataHolder.setIncrementalAnalysis(true);
- underTest.execute();
- verify(incrementalDuplicationMeasures).execute();
- verifyZeroInteractions(defaultDuplicationMeasures);
+ underTest = new DuplicationMeasuresStep(defaultDuplicationMeasures);
}
@Test
public void full_analysis_mode() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
underTest.execute();
verify(defaultDuplicationMeasures).execute();
- verifyZeroInteractions(incrementalDuplicationMeasures);
}
@Override
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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 static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
-import org.sonar.server.computation.task.projectanalysis.measure.IncrementalMeasureTransition;
-import org.sonar.server.computation.task.step.ComputationStep;
-
-public class IncrementalMeasureTransitionStepTest extends BaseStepTest {
- @Rule
- public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
-
- IncrementalMeasureTransitionStep underTest = new IncrementalMeasureTransitionStep(analysisMetadataHolder);
-
- @Override
- protected ComputationStep step() {
- return underTest;
- }
-
- @Test
- public void skip_if_not_incremental() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
- underTest.execute();
- }
-
- @Test
- public void execute_if_incremental() {
- IncrementalMeasureTransition runnable = mock(IncrementalMeasureTransition.class);
- IncrementalMeasureTransitionStep underTest = new IncrementalMeasureTransitionStep(analysisMetadataHolder, runnable);
- analysisMetadataHolder.setIncrementalAnalysis(true);
-
- underTest.execute();
- verify(runnable).run();
- }
-
-}
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.VisitException;
import org.sonar.server.computation.task.projectanalysis.duplication.DetailedTextBlock;
import org.sonar.server.computation.task.projectanalysis.duplication.Duplicate;
builder(PROJECT, ROOT_REF)
.addChildren(
builder(FILE, FILE_1_REF).build(),
- builder(FILE, FILE_2_REF).build()
- )
- .build()
- );
+ builder(FILE, FILE_2_REF).build())
+ .build());
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
@Rule
public DuplicationRepositoryRule duplicationRepository = DuplicationRepositoryRule.create(treeRootHolder);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- @Rule
- public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
- private LoadDuplicationsFromReportStep underTest = new LoadDuplicationsFromReportStep(treeRootHolder, reportReader, duplicationRepository, analysisMetadataHolder);
+ private LoadDuplicationsFromReportStep underTest = new LoadDuplicationsFromReportStep(treeRootHolder, reportReader, duplicationRepository);
@Test
public void verify_description() {
assertThat(underTest.getDescription()).isEqualTo("Load inner file and in project duplications");
}
-
- @Test
- public void skip_if_incremental_analysis() {
- analysisMetadataHolder.setIncrementalAnalysis(true);
- reportReader.putDuplications(FILE_2_REF, createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 1)));
-
- underTest.execute();
-
- assertNoDuplication(FILE_2_REF);
- }
-
- @Test
- public void loads_no_duplications_if_reader_has_no_duplication() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
- underTest.execute();
-
- assertNoDuplication(FILE_1_REF);
- }
@Test
public void loads_duplication_without_otherFileRef_as_inner_duplication() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
reportReader.putDuplications(FILE_2_REF, createDuplication(singleLineTextRange(LINE), createInnerDuplicate(LINE + 1)));
underTest.execute();
@Test
public void loads_duplication_with_otherFileRef_as_inProject_duplication() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(LINE), createInProjectDuplicate(FILE_2_REF, LINE + 1)));
underTest.execute();
@Test
public void loads_multiple_duplications_with_multiple_duplicates() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
reportReader.putDuplications(
FILE_2_REF,
createDuplication(
createInProjectDuplicate(FILE_1_REF, OTHER_LINE)),
createDuplication(
singleLineTextRange(OTHER_LINE + 80),
- createInnerDuplicate(LINE), createInnerDuplicate(LINE + 10))
- );
+ createInnerDuplicate(LINE), createInnerDuplicate(LINE + 10)));
underTest.execute();
new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 10))),
duplication(
singleLineDetailedTextBlock(2, OTHER_LINE),
- new InProjectDuplicate(file1Component, singleLineTextBlock(OTHER_LINE))
- ),
+ new InProjectDuplicate(file1Component, singleLineTextBlock(OTHER_LINE))),
duplication(
singleLineDetailedTextBlock(3, OTHER_LINE + 80),
- new InnerDuplicate(singleLineTextBlock(LINE)), new InnerDuplicate(singleLineTextBlock(LINE + 10))
- )
- );
+ new InnerDuplicate(singleLineTextBlock(LINE)), new InnerDuplicate(singleLineTextBlock(LINE + 10))));
}
@Test
public void loads_never_consider_originals_from_batch_on_same_lines_as_the_equals() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
reportReader.putDuplications(
FILE_2_REF,
createDuplication(
createInnerDuplicate(LINE + 1), createInnerDuplicate(LINE + 2), createInProjectDuplicate(FILE_1_REF, LINE + 2)),
createDuplication(
singleLineTextRange(LINE),
- createInnerDuplicate(LINE + 2), createInnerDuplicate(LINE + 3), createInProjectDuplicate(FILE_1_REF, LINE + 2))
- );
+ createInnerDuplicate(LINE + 2), createInnerDuplicate(LINE + 3), createInProjectDuplicate(FILE_1_REF, LINE + 2)));
underTest.execute();
duplication(
singleLineDetailedTextBlock(1, LINE),
new InnerDuplicate(singleLineTextBlock(LINE + 1)), new InnerDuplicate(singleLineTextBlock(LINE + 2)),
- new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))
- ),
+ new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))),
duplication(
singleLineDetailedTextBlock(2, LINE),
new InnerDuplicate(singleLineTextBlock(LINE + 2)), new InnerDuplicate(singleLineTextBlock(LINE + 3)),
- new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))
- )
- );
+ new InProjectDuplicate(file1Component, singleLineTextBlock(LINE + 2))));
}
@Test
public void loads_duplication_with_otherFileRef_throws_IAE_if_component_does_not_exist() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
int line = 2;
reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(line), createInProjectDuplicate(666, line + 1)));
@Test
public void loads_duplication_with_otherFileRef_throws_IAE_if_references_itself() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
int line = 2;
reportReader.putDuplications(FILE_1_REF, createDuplication(singleLineTextRange(line), createInProjectDuplicate(FILE_1_REF, line + 1)));
assertThat(analysisMetadataHolder.isCrossProjectDuplicationEnabled()).isEqualTo(false);
}
- @Test
- public void set_incremental_analysis_to_true() {
- reportReader.setMetadata(
- newBatchReportBuilder()
- .setIncremental(true)
- .build());
-
- underTest.execute();
-
- assertThat(analysisMetadataHolder.isIncrementalAnalysis()).isTrue();
- }
-
- @Test
- public void set_incremental_analysis_to_false() {
- reportReader.setMetadata(
- newBatchReportBuilder()
- .setIncremental(false)
- .build());
-
- underTest.execute();
-
- assertThat(analysisMetadataHolder.isIncrementalAnalysis()).isFalse();
- }
-
@Test
public void set_cross_project_duplication_to_false_when_nothing_in_the_report() {
reportReader.setMetadata(
import org.mockito.MockitoAnnotations;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.duplication.DuplicationUnitDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.server.computation.task.projectanalysis.analysis.Analysis;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
when(baseAnalysis.getUuid()).thenReturn(BASE_ANALYSIS_UUID);
analysisMetadataHolder.setUuid(ANALYSIS_UUID);
analysisMetadataHolder.setBaseAnalysis(baseAnalysis);
- analysisMetadataHolder.setIncrementalAnalysis(false);
underTest = new PersistCrossProjectDuplicationIndexStep(crossProjectDuplicationStatusHolder, dbClient, treeRootHolder, analysisMetadataHolder, reportReader);
}
- @Test
- public void copy_base_analysis_in_incremental_mode() {
- when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
- analysisMetadataHolder.setIncrementalAnalysis(true);
- DuplicationUnitDto dup = new DuplicationUnitDto();
- dup.setAnalysisUuid(BASE_ANALYSIS_UUID);
- dup.setComponentUuid(FILE_2_UUID);
- dup.setEndLine(0);
- dup.setHash("asd");
- dup.setStartLine(0);
- dup.setId(1);
- dup.setIndexInFile(1);
- try (DbSession session = dbTester.getSession()) {
- dbClient.duplicationDao().insert(session, dup);
- session.commit();
- }
- assertThat(dbTester.countRowsOfTable("duplications_index")).isEqualTo(1);
- underTest.execute();
-
- Map<String, Object> dto = dbTester.selectFirst("select HASH, START_LINE, END_LINE, INDEX_IN_FILE, COMPONENT_UUID, ANALYSIS_UUID "
- + "from duplications_index where analysis_uuid = '" + ANALYSIS_UUID + "'");
- assertThat(dto.get("HASH")).isEqualTo("asd");
- assertThat(dto.get("START_LINE")).isEqualTo(0L);
- assertThat(dto.get("END_LINE")).isEqualTo(0L);
- assertThat(dto.get("INDEX_IN_FILE")).isEqualTo(0L);
- assertThat(dto.get("COMPONENT_UUID")).isEqualTo(FILE_2.getUuid());
- assertThat(dto.get("ANALYSIS_UUID")).isEqualTo(ANALYSIS_UUID);
- }
-
@Test
public void persist_cpd_text_block() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Arrays;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType;
-import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.FileAttributes;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryRule;
import org.sonar.server.computation.task.step.ComputationStep;
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class PersistFileSourcesStepTest extends BaseStepTest {
private static final int FILE1_REF = 3;
public SourceLinesRepositoryRule fileSourceRepository = new SourceLinesRepositoryRule();
@Rule
public DuplicationRepositoryRule duplicationRepository = DuplicationRepositoryRule.create(treeRootHolder);
- @Rule
- public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule().setIncrementalAnalysis(false);
private DbClient dbClient = dbTester.getDbClient();
private DbSession session = dbTester.getSession();
public void setup() {
when(system2.now()).thenReturn(NOW);
underTest = new PersistFileSourcesStep(dbClient, system2, treeRootHolder, reportReader, fileSourceRepository, scmInfoRepository,
- duplicationRepository, analysisMetadataHolder);
+ duplicationRepository);
}
@Override
assertThat(data.getLines(1).getSource()).isEqualTo("line2");
}
- @Test
- public void dont_persist_unchanged_sources_if_incremental() {
- analysisMetadataHolder.setIncrementalAnalysis(true);
- initIncrementalReport(2);
-
- underTest.execute();
- assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
- }
-
@Test
public void persist_source_hashes() {
initBasicReport(2);
assertThat(fileSourceDto.getRevision()).isNull();
}
- private void initIncrementalReport(int numberOfLines) {
- treeRootHolder.setRoot(ReportComponent
- .builder(Component.Type.PROJECT, 1)
- .setUuid(PROJECT_UUID)
- .setKey(PROJECT_KEY)
- .addChildren(
- ReportComponent
- .builder(Component.Type.MODULE, 2)
- .setUuid("MODULE")
- .setKey("MODULE_KEY")
- .addChildren(
- ReportComponent
- .builder(Component.Type.FILE, FILE1_REF)
- .setUuid(FILE1_UUID)
- .setKey("MODULE_KEY:src/Foo.java")
- .setFileAttributes(new FileAttributes(false, null, numberOfLines))
- .setStatus(Status.CHANGED)
- .build())
- .build(),
- ReportComponent
- .builder(Component.Type.FILE, FILE2_REF)
- .setUuid(FILE2_UUID)
- .setKey("MODULE_KEY:src/Foo2.java")
- .setStatus(Status.SAME).build())
- .build());
-
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .addChildRef(2)
- .build());
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(2)
- .setType(ComponentType.MODULE)
- .addChildRef(FILE1_REF)
- .build());
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(FILE1_REF)
- .setType(ComponentType.FILE)
- .setLines(numberOfLines)
- .build());
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(FILE2_REF)
- .setType(ComponentType.FILE)
- .setLines(numberOfLines)
- .build());
-
- for (int i = 1; i <= numberOfLines; i++) {
- fileSourceRepository.addLine(FILE1_REF, "line" + i);
- }
- }
-
private void initBasicReport(int numberOfLines) {
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(
ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(
@Test
public void persist_analysis() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
assertThat(projectSnapshot.getStatus()).isEqualTo("U");
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
- assertThat(projectSnapshot.getIncremental()).isFalse();
assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
@Test
public void persist_snapshots_with_leak_period() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
@Test
public void only_persist_snapshots_with_leak_period_on_project_and_module() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1"));
OrganizationDto organizationDto = dbTester.organizations().insert();
@Test
public void set_no_period_on_snapshots_when_no_period() {
- analysisMetadataHolder.setIncrementalAnalysis(false);
ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY).setName("Project");
dbClient.componentDao().insert(dbTester.getSession(), projectDto);
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto);
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Date;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
-import org.sonar.server.computation.task.projectanalysis.analysis.Analysis;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
-import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
-import org.sonar.server.computation.task.projectanalysis.validation.ValidateIncremental;
public class ValidateProjectStepTest {
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
.setAnalysisDate(new Date(DEFAULT_ANALYSIS_TIME))
- .setIncrementalAnalysis(false)
.setBranch(DEFAULT_BRANCH);
- public ValidateIncremental validateIncremental = mock(ValidateIncremental.class);
-
DbClient dbClient = dbTester.getDbClient();
- ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, validateIncremental);
+ ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
@Test
public void fail_if_root_component_is_not_a_project_in_db() {
underTest.execute();
}
- @Test
- public void fail_if_incremental_plugin_not_found() {
- ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, null);
-
- when(validateIncremental.execute()).thenReturn(false);
- analysisMetadataHolder.setBaseAnalysis(new Analysis.Builder().setId(1).setUuid("base").setCreatedAt(DEFAULT_ANALYSIS_TIME).build());
- analysisMetadataHolder.setIncrementalAnalysis(true);
-
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .addChildRef(2)
- .build());
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Validation of project failed:");
- thrown.expectMessage("Can't process an incremental analysis of the project \"PROJECT_KEY\" because the incremental plugin is not loaded");
-
- underTest.execute();
- }
-
- @Test
- public void fail_if_incremental_validation_fails() {
- when(validateIncremental.execute()).thenReturn(false);
- analysisMetadataHolder.setBaseAnalysis(new Analysis.Builder().setId(1).setUuid("base").setCreatedAt(DEFAULT_ANALYSIS_TIME).build());
- analysisMetadataHolder.setIncrementalAnalysis(true);
-
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .addChildRef(2)
- .build());
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Validation of project failed:");
- thrown.expectMessage("The installation of the incremental plugin is invalid");
-
- underTest.execute();
- }
-
- @Test
- public void fail_if_incremental_and_first_analysis() {
- when(validateIncremental.execute()).thenReturn(true);
- analysisMetadataHolder.setBaseAnalysis(null);
- analysisMetadataHolder.setIncrementalAnalysis(true);
-
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .addChildRef(2)
- .build());
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Validation of project failed:");
- thrown.expectMessage("hasn't been analysed before and the first analysis can't be incremental. Please launch a full analysis of the project.");
-
- underTest.execute();
- }
-}
\ No newline at end of file
+}
* Defines the base keys (defined by {@link #basePluginKey(PluginInfo, Map)}) of the plugins which are allowed to
* run a full server extensions.
*/
- private static final Set<String> PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>(
- asList("billing", "branch", "developer", "governance", "incremental", "license")));
+ private static final Set<String> PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>(asList("billing", "branch", "developer", "governance", "license")));
public static final Version COMPATIBILITY_MODE_MAX_VERSION = Version.create("5.2");
boolean isPublish();
- /**
- * When incremental analysis is enabled (means not all files of a project are analyzed)
- * @since 6.6
- */
- boolean isIncremental();
}
public class MockAnalysisMode implements AnalysisMode {
private boolean previewOrIssue = false;
- private boolean incremental = false;
@Override
public boolean isPreview() {
public boolean isPublish() {
return !previewOrIssue;
}
-
- @Override
- public boolean isIncremental() {
- return incremental;
- }
-
- public void setIncremental(boolean incremental) {
- this.incremental = incremental;
- }
}
package org.sonar.scanner.analysis;
import java.util.Map;
-import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.AnalysisMode;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.scan.branch.BranchConfiguration;
@Immutable
public class DefaultAnalysisMode implements AnalysisMode {
private static final Logger LOG = Loggers.get(DefaultAnalysisMode.class);
private static final String KEY_SCAN_ALL = "sonar.scanAllFiles";
- private static final String KEY_INCREMENTAL = "sonar.incremental";
private final Map<String, String> analysisProps;
private final GlobalAnalysisMode analysisMode;
private final BranchConfiguration branchConfig;
- private final ProjectRepositories projectRepos;
- private final IncrementalScannerHandler incrementalScannerHandler;
private boolean scanAllFiles;
- private boolean incremental;
- public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig, GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos) {
- this(props, branchConfig, analysisMode, projectRepos, null);
- }
-
- public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
- GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler incrementalScannerHandler) {
+ public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig, GlobalAnalysisMode analysisMode) {
this.branchConfig = branchConfig;
this.analysisMode = analysisMode;
- this.projectRepos = projectRepos;
- this.incrementalScannerHandler = incrementalScannerHandler;
this.analysisProps = props.properties();
load();
printFlags();
}
- @Override
- public boolean isIncremental() {
- return incremental;
- }
-
public boolean scanAllFiles() {
return scanAllFiles;
}
private void printFlags() {
- if (incremental) {
- LOG.info("Incremental mode");
- }
if (!scanAllFiles) {
LOG.info("Scanning only changed files");
}
private void load() {
String scanAllStr = analysisProps.get(KEY_SCAN_ALL);
- incremental = incremental();
- scanAllFiles = !incremental && !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
- }
-
- private boolean incremental() {
- String inc = analysisProps.get(KEY_INCREMENTAL);
- if ("true".equals(inc)) {
- if (incrementalScannerHandler == null || !incrementalScannerHandler.execute()) {
- throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
- }
-
- if (!analysisMode.isPublish()) {
- throw MessageException.of("Incremental analysis is only available in publish mode");
- }
-
- if (branchConfig.branchName() != null) {
- LOG.warn("Incremental analysis mode has been activated but it's not compatible with branches so a full analysis will be done.");
- return false;
- }
-
- if (!projectRepos.exists() || projectRepos.lastAnalysisDate() == null) {
- LOG.warn("Incremental analysis mode has been activated but the project was never analyzed before so a full analysis is about to be done.");
- return false;
- }
-
- LOG.debug("Reference analysis is {}", DateUtils.formatDateTime(projectRepos.lastAnalysisDate()));
- return true;
- }
-
- return false;
+ scanAllFiles = !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
}
@Override
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.scanner.analysis;
-
-public interface IncrementalScannerHandler {
- boolean execute();
-}
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.config.Configuration;
import org.sonar.scanner.ProjectAnalysisInfo;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.ScannerPlugin;
import org.sonar.scanner.bootstrap.ScannerPluginRepository;
import org.sonar.scanner.cpd.CpdSettings;
private final ProjectAnalysisInfo projectAnalysisInfo;
private final InputModuleHierarchy moduleHierarchy;
private final CpdSettings cpdSettings;
- private final DefaultAnalysisMode mode;
private final ScannerPluginRepository pluginRepository;
private final BranchConfiguration branchConfiguration;
public MetadataPublisher(ProjectAnalysisInfo projectAnalysisInfo, InputModuleHierarchy moduleHierarchy, Configuration settings,
- ModuleQProfiles qProfiles, CpdSettings cpdSettings, DefaultAnalysisMode mode, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
+ ModuleQProfiles qProfiles, CpdSettings cpdSettings, ScannerPluginRepository pluginRepository, BranchConfiguration branchConfiguration) {
this.projectAnalysisInfo = projectAnalysisInfo;
this.moduleHierarchy = moduleHierarchy;
this.settings = settings;
this.qProfiles = qProfiles;
this.cpdSettings = cpdSettings;
- this.mode = mode;
this.pluginRepository = pluginRepository;
this.branchConfiguration = branchConfiguration;
}
// Here we want key without branch
.setProjectKey(rootDef.getKey())
.setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled())
- .setRootComponentRef(rootProject.batchId())
- .setIncremental(mode.isIncremental());
+ .setRootComponentRef(rootProject.batchId());
settings.get(ORGANIZATION).ifPresent(builder::setOrganizationKey);
import org.sonar.api.utils.ZipUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
private final ReportPublisherStep[] publishers;
private final Server server;
private final BranchConfiguration branchConfiguration;
- private final DefaultAnalysisMode analysisFlags;
private Path reportDir;
private ScannerReportWriter writer;
- public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher, DefaultAnalysisMode analysisFlags,
+ public ReportPublisher(Configuration settings, ScannerWsClient wsClient, Server server, AnalysisContextReportPublisher contextPublisher,
InputModuleHierarchy moduleHierarchy, GlobalAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers, BranchConfiguration branchConfiguration) {
this.settings = settings;
this.wsClient = wsClient;
this.server = server;
this.contextPublisher = contextPublisher;
- this.analysisFlags = analysisFlags;
this.moduleHierarchy = moduleHierarchy;
this.analysisMode = analysisMode;
this.temp = temp;
.setParam("projectBranch", moduleHierarchy.root().getBranch())
.setPart("report", filePart);
- if (analysisFlags.isIncremental()) {
- post.setParam(CHARACTERISTIC, "incremental=true");
- }
-
String branchName = branchConfiguration.branchName();
if (branchName != null) {
post.setParam(CHARACTERISTIC, "branch=" + branchName);
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
import org.sonar.core.component.ComponentKeys;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchParamsValidator;
import org.sonar.scanner.scan.branch.DefaultBranchParamsValidator;
public class ProjectReactorValidator {
private final AnalysisMode mode;
private final BranchParamsValidator branchParamsValidator;
- private final DefaultAnalysisMode analysisFlags;
- public ProjectReactorValidator(AnalysisMode mode, DefaultAnalysisMode analysisFlags, BranchParamsValidator branchParamsValidator) {
+ public ProjectReactorValidator(AnalysisMode mode, BranchParamsValidator branchParamsValidator) {
this.mode = mode;
- this.analysisFlags = analysisFlags;
this.branchParamsValidator = branchParamsValidator;
}
- public ProjectReactorValidator(AnalysisMode mode, DefaultAnalysisMode analysisFlags) {
- this(mode, analysisFlags, new DefaultBranchParamsValidator());
+ public ProjectReactorValidator(AnalysisMode mode) {
+ this(mode, new DefaultBranchParamsValidator());
}
public void validate(ProjectReactor reactor) {
String deprecatedBranchName = reactor.getRoot().getBranch();
- branchParamsValidator.validate(validationMessages, deprecatedBranchName, analysisFlags.isIncremental());
+ branchParamsValidator.validate(validationMessages, deprecatedBranchName);
validateBranch(validationMessages, deprecatedBranchName);
if (!validationMessages.isEmpty()) {
@ScannerSide
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public interface BranchParamsValidator {
- void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode);
+ void validate(List<String> validationMessages, @Nullable String deprecatedBranchName);
}
public class DefaultBranchParamsValidator implements BranchParamsValidator {
@Override
- public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode) {
+ public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName) {
// no-op
}
}
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.FileExtensionPredicate;
import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchConfiguration;
/**
private final SetMultimap<String, InputFile> filesByNameCache = LinkedHashMultimap.create();
private final SetMultimap<String, InputFile> filesByExtensionCache = LinkedHashMultimap.create();
private final InputModule root;
- private final DefaultAnalysisMode analysisFlags;
private final BranchConfiguration branchConfiguration;
- public InputComponentStore(DefaultInputModule root, DefaultAnalysisMode analysisFlags, BranchConfiguration branchConfiguration) {
+ public InputComponentStore(DefaultInputModule root, BranchConfiguration branchConfiguration) {
this.root = root;
- this.analysisFlags = analysisFlags;
this.branchConfiguration = branchConfiguration;
this.put(root);
}
return inputFileCache.values().stream()
.map(f -> (DefaultInputFile) f)
.filter(DefaultInputFile::isPublished)
- .filter(f -> (!analysisFlags.isIncremental() && !branchConfiguration.isShortLivingBranch()) || f.status() != Status.SAME)::iterator;
+ .filter(f -> (!branchConfiguration.isShortLivingBranch()) || f.status() != Status.SAME)::iterator;
}
public Iterable<InputFile> allFiles() {
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchConfiguration;
public class InputComponentStoreProvider extends ProviderAdapter {
private InputComponentStore store;
- public InputComponentStore provide(InputModuleHierarchy hierarchy, DefaultAnalysisMode analysisFlags, BranchConfiguration branchConfiguration) {
+ public InputComponentStore provide(InputModuleHierarchy hierarchy, BranchConfiguration branchConfiguration) {
if (store == null) {
- store = new InputComponentStore(hierarchy.root(), analysisFlags, branchConfiguration);
+ store = new InputComponentStore(hierarchy.root(), branchConfiguration);
}
return store;
}
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.measure.MeasureCache;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
@Phase(name = Phase.Name.POST)
public final class ZeroCoverageSensor implements Sensor {
- private static final Logger LOG = Loggers.get(ZeroCoverageSensor.class);
-
private final MeasureCache measureCache;
- private final DefaultAnalysisMode analysisFlags;
- public ZeroCoverageSensor(MeasureCache measureCache, DefaultAnalysisMode analysisFlags) {
+ public ZeroCoverageSensor(MeasureCache measureCache) {
this.measureCache = measureCache;
- this.analysisFlags = analysisFlags;
}
@Override
@Override
public void execute(final SensorContext context) {
- if (analysisFlags.isIncremental()) {
- LOG.debug("Incremental mode: not forcing coverage to zero");
- return;
- }
FileSystem fs = context.fileSystem();
for (InputFile f : fs.inputFiles(fs.predicates().hasType(Type.MAIN))) {
if (((DefaultInputFile) f).isExcludedForCoverage()) {
package org.sonar.scanner.analysis;
import java.util.Collections;
-import java.util.Date;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultAnalysisModeTest {
private BranchConfiguration branchConfig;
- private ProjectRepositories projectRepos;
private GlobalAnalysisMode globalMode;
- private IncrementalScannerHandler incrementalScannerHandler;
@Before
public void setUp() {
branchConfig = mock(BranchConfiguration.class);
- projectRepos = mock(ProjectRepositories.class);
globalMode = mock(GlobalAnalysisMode.class);
- incrementalScannerHandler = mock(IncrementalScannerHandler.class);
}
@Rule
assertThat(mode.isPreview()).isTrue();
}
- @Test
- public void incremental_not_found() {
- AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
- thrown.expect(MessageException.class);
- thrown.expectMessage("Incremental mode is not available. Please contact your administrator.");
- createmode(analysisProps);
- }
-
- @Test
- public void no_incremental_if_not_publish() {
- when(incrementalScannerHandler.execute()).thenReturn(true);
- AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
- thrown.expect(MessageException.class);
- thrown.expectMessage("Incremental analysis is only available in publish mode");
- createmode(analysisProps);
- }
-
- @Test
- public void no_incremental_mode_if_branches() {
- when(globalMode.isPublish()).thenReturn(true);
- when(incrementalScannerHandler.execute()).thenReturn(true);
- when(branchConfig.branchName()).thenReturn("branch1");
- AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
- DefaultAnalysisMode analysisMode = createmode(analysisProps);
- assertThat(analysisMode.isIncremental()).isFalse();
- assertThat(analysisMode.scanAllFiles()).isTrue();
- }
-
- @Test
- public void no_incremental_mode_if_no_previous_analysis() {
- when(incrementalScannerHandler.execute()).thenReturn(true);
- when(globalMode.isPublish()).thenReturn(true);
- AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
- DefaultAnalysisMode analysisMode = createmode(analysisProps);
- assertThat(analysisMode.isIncremental()).isFalse();
- assertThat(analysisMode.scanAllFiles()).isTrue();
- }
-
- @Test
- public void incremental_mode() {
- when(incrementalScannerHandler.execute()).thenReturn(true);
- when(globalMode.isPublish()).thenReturn(true);
- when(projectRepos.lastAnalysisDate()).thenReturn(new Date());
- when(projectRepos.exists()).thenReturn(true);
- AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
- DefaultAnalysisMode analysisMode = createmode(analysisProps);
- assertThat(analysisMode.isIncremental()).isTrue();
- assertThat(analysisMode.scanAllFiles()).isFalse();
- }
-
@Test
public void scan_all_if_publish() {
when(globalMode.isIssues()).thenReturn(false);
}
private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) {
- return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, incrementalScannerHandler);
+ return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode);
}
}
import org.sonar.duplications.block.ByteArray;
import org.sonar.duplications.index.CloneGroup;
import org.sonar.duplications.index.ClonePart;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
import org.sonar.scanner.protocol.output.ScannerReport.Duplicate;
import org.sonar.scanner.protocol.output.ScannerReport.Duplication;
index = new SonarCpdBlockIndex(publisher, settings);
DefaultInputModule inputModule = TestInputFileBuilder.newDefaultInputModule("foo", baseDir);
- componentStore = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ componentStore = new InputComponentStore(inputModule, mock(BranchConfiguration.class));
executor = new CpdExecutor(settings, index, publisher, componentStore, branchConfig);
reader = new ScannerReportReader(outputDir);
import org.sonar.api.batch.postjob.issue.PostJobIssue;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.config.internal.MapSettings;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
import org.sonar.scanner.scan.branch.BranchConfiguration;
public void setUp() throws IOException {
issueCache = mock(IssueCache.class);
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule("foo", temp.newFolder());
- componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
settings = new MapSettings();
analysisMode = mock(AnalysisMode.class);
context = new DefaultPostJobContext(settings.asConfig(), settings, issueCache, componentStore, analysisMode);
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.protocol.output.ScannerReport.LineCoverage;
import org.sonar.scanner.protocol.output.ScannerReportReader;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).build();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
- InputComponentStore componentCache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ InputComponentStore componentCache = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.deprecated.test.TestPlanBuilder;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReportReader;
String moduleKey = "foo";
inputModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setPublish(true).build();
- InputComponentStore componentCache = new InputComponentStore(inputModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ InputComponentStore componentCache = new InputComponentStore(inputModule, mock(BranchConfiguration.class));
componentCache.put(inputFile);
measureCache = mock(MeasureCache.class);
when(measureCache.byComponentKey(anyString())).thenReturn(Collections.<DefaultMeasure<?>>emptyList());
when(inputModuleHierarchy.root()).thenReturn(rootModule);
analysisMode = mock(DefaultAnalysisMode.class);
branches = mock(BranchConfiguration.class);
- underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings, analysisMode,
+ underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings.asConfig(), qProfiles, cpdSettings,
pluginRepository, branches);
}
assertThat(metadata.getAnalysisDate()).isEqualTo(1234567L);
assertThat(metadata.getProjectKey()).isEqualTo("foo");
assertThat(metadata.getProjectKey()).isEqualTo("foo");
- assertThat(metadata.getIncremental()).isFalse();
assertThat(metadata.getQprofilesPerLanguage()).containsOnly(entry("java", org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile.newBuilder()
.setKey("q1")
.setName("Q1")
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.config.ScannerProperties;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.scan.branch.BranchConfiguration;
@Rule
public ExpectedException exception = ExpectedException.none();
- DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class);
GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class);
MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all()));
ScannerWsClient wsClient;
@Test
public void log_and_dump_information_about_report_uploading() throws IOException {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode,
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode,
mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration);
settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg");
@Test
public void parse_upload_error_message() throws IOException {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode,
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode,
mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration);
HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}");
WsResponse response = mock(WsResponse.class);
@Test
public void log_public_url_if_defined() throws IOException {
when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube");
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
underTest.logSuccess("TASK-123");
@Test
public void fail_if_public_url_malformed() throws IOException {
when(server.getPublicRootUrl()).thenReturn("invalid");
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
exception.expect(MessageException.class);
@Test
public void log_but_not_dump_information_when_report_is_not_uploaded() {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
underTest.logSuccess(/* report not uploaded, no server task */null);
settings.setProperty("sonar.scanner.keepReport", true);
Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
Files.createDirectory(reportDir);
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
underTest.start();
public void should_delete_report_by_default() throws IOException {
Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
Files.createDirectory(reportDir);
- ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher job = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0],
branchConfiguration);
@Test
public void test_ws_parameters() throws Exception {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
settings.setProperty(ScannerProperties.ORGANIZATION, "MyOrg");
entry("projectKey", "struts"));
}
- @Test
- public void test_send_incremental_characteristic() throws Exception {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
- new ReportPublisherStep[0], branchConfiguration);
-
- when(analysisFlags.isIncremental()).thenReturn(true);
- String orgName = "MyOrg";
- settings.setProperty(ScannerProperties.ORGANIZATION, orgName);
-
- WsResponse response = mock(WsResponse.class);
-
- PipedOutputStream out = new PipedOutputStream();
- PipedInputStream in = new PipedInputStream(out);
- WsCe.SubmitResponse.newBuilder().build().writeTo(out);
- out.close();
-
- when(response.failIfNotSuccessful()).thenReturn(response);
- when(response.contentStream()).thenReturn(in);
-
- when(wsClient.call(any(WsRequest.class))).thenReturn(response);
- underTest.upload(temp.newFile());
-
- ArgumentCaptor<WsRequest> capture = ArgumentCaptor.forClass(WsRequest.class);
- verify(wsClient).call(capture.capture());
-
- WsRequest wsRequest = capture.getValue();
- assertThat(wsRequest.getParameters().getKeys()).hasSize(3);
- assertThat(wsRequest.getParameters().getValues("organization")).containsExactly(orgName);
- assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("struts");
- assertThat(wsRequest.getParameters().getValues("characteristic"))
- .containsExactly("incremental=true");
- }
-
@Test
public void test_send_branches_characteristics() throws Exception {
- ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, analysisFlags, moduleHierarchy, mode, mock(TempFolder.class),
+ ReportPublisher underTest = new ReportPublisher(settings.asConfig(), wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class),
new ReportPublisherStep[0], branchConfiguration);
String orgName = "MyOrg";
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class SourcePublisherTest {
private File sourceFile;
private ScannerReportWriter writer;
private DefaultInputFile inputFile;
- private DefaultAnalysisMode analysisFlags;
@Before
public void prepare() throws IOException {
.build();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir);
- analysisFlags = mock(DefaultAnalysisMode.class);
- InputComponentStore componentStore = new InputComponentStore(rootModule, analysisFlags, mock(BranchConfiguration.class));
+ InputComponentStore componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
componentStore.put(inputFile);
publisher = new SourcePublisher(componentStore);
assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
}
- @Test
- public void publishChangedSourceInIncrementalMode() throws Exception {
- when(analysisFlags.isIncremental()).thenReturn(true);
- FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);
- inputFile.setStatus(Status.CHANGED);
-
- publisher.publish(writer);
-
- File out = writer.getSourceFile(inputFile.batchId());
- assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
- }
-
- @Test
- public void dontPublishUnchangedSourceInIncrementalMode() throws Exception {
- when(analysisFlags.isIncremental()).thenReturn(true);
- FileUtils.write(sourceFile, "foo", StandardCharsets.ISO_8859_1);
- inputFile.setStatus(Status.SAME);
-
- publisher.publish(writer);
-
- File out = writer.getSourceFile(inputFile.batchId());
- assertThat(out).doesNotExist();
- }
}
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import org.sonar.scanner.scan.filesystem.InputComponentStore;
private InputComponentStore componentStore;
public void createIndexer(DefaultInputModule rootModule) {
- componentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ componentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
tree = new DefaultComponentTree();
moduleHierarchy = mock(DefaultInputModuleHierarchy.class);
indexer = new ModuleIndexer(tree, componentStore, moduleHierarchy);
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public ExpectedException thrown = ExpectedException.none();
private AnalysisMode mode;
- private DefaultAnalysisMode analysisFlags;
private ProjectReactorValidator validator;
@Before
public void prepare() {
mode = mock(AnalysisMode.class);
- analysisFlags = mock(DefaultAnalysisMode.class);
- validator = new ProjectReactorValidator(mode, analysisFlags);
+ validator = new ProjectReactorValidator(mode);
}
@Test
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
- InputComponentStore cache = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ InputComponentStore cache = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
cache.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java")
static class InputComponentStoreTester extends InputComponentStore {
InputComponentStoreTester() throws IOException {
- super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ super(TestInputFileBuilder.newDefaultInputModule("root", temp.newFolder()), mock(BranchConfiguration.class));
}
InputFile addFile(String moduleKey, String relpath, String language) {
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.SensorStrategy;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
@Before
public void setUp() throws IOException {
DefaultInputModule root = TestInputFileBuilder.newDefaultInputModule(moduleKey, temp.newFolder());
- componentStore = new InputComponentStore(root, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ componentStore = new InputComponentStore(root, mock(BranchConfiguration.class));
}
@Test
import org.sonar.api.issue.Issue;
import org.sonar.api.platform.Server;
import org.sonar.api.rule.RuleKey;
-import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.issue.IssueCache;
import org.sonar.scanner.issue.tracking.TrackedIssue;
import org.sonar.scanner.scan.DefaultComponentTree;
DefaultComponentTree inputComponentTree = new DefaultComponentTree();
ProjectDefinition def = ProjectDefinition.create().setBaseDir(projectBaseDir).setWorkDir(temp.newFolder()).setKey("struts");
DefaultInputModule rootModule = new DefaultInputModule(def, 1);
- InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(DefaultAnalysisMode.class), mock(BranchConfiguration.class));
+ InputComponentStore inputComponentStore = new InputComponentStore(rootModule, mock(BranchConfiguration.class));
DefaultInputModule moduleA = new DefaultInputModule(ProjectDefinition.create().setKey("struts-core").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
inputComponentTree.index(moduleA, rootModule);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info 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.scanner.source;
-
-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.scanner.analysis.DefaultAnalysisMode;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ZeroCoverageSensorTest {
-
- @Rule
- public LogTester logTester = new LogTester();
-
- @Test
- public void dontForceCoverageInIncrementalMode() {
- DefaultAnalysisMode analysisFlags = mock(DefaultAnalysisMode.class);
- when(analysisFlags.isIncremental()).thenReturn(true);
- ZeroCoverageSensor zeroCoverageSensor = new ZeroCoverageSensor(null, analysisFlags);
- zeroCoverageSensor.execute(null);
- assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Incremental mode: not forcing coverage to zero");
- }
-
-}
bool cross_project_duplication_activated = 6;
map<string, QProfile> qprofiles_per_language = 7;
map<string, Plugin> plugins_by_key = 8;
- bool incremental = 9;
- string branch_name = 10;
- BranchType branch_type = 11;
- string merge_branch_name = 12;
+ string branch_name = 9;
+ BranchType branch_type = 10;
+ string merge_branch_name = 11;
message QProfile {
string key = 1;
FILE = 4;
}
- // For incremental mode
enum FileStatus {
UNAVAILABLE = 0;
SAME = 1;
optional string scannerContext = 18;
optional bool hasScannerContext = 19;
optional string organization = 20;
- optional bool incremental = 21;
- optional string branch = 22;
- optional sonarqube.ws.commons.BranchType branchType = 23;
+ optional string branch = 21;
+ optional sonarqube.ws.commons.BranchType branchType = 22;
}
enum TaskStatus {