aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-25 16:19:05 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-25 18:31:17 +0100
commite22d090fd5027686d0486186b821672c8fdd8a10 (patch)
tree6a3611a2d246222c3016daef928557ffed532b6d /sonar-batch/src
parentaf6bce24d8d249cebd1fae4a93d172d2ca7196c0 (diff)
downloadsonarqube-e22d090fd5027686d0486186b821672c8fdd8a10.tar.gz
sonarqube-e22d090fd5027686d0486186b821672c8fdd8a10.zip
SONAR-5927 Fix 404 when analyzing new file
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java25
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java (renamed from sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java)8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java27
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java33
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java21
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/scan/LastLineHashesTest.java)10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/IncrementalModeMediumTest.java27
14 files changed, 108 insertions, 84 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
index 7cf0bd61ef8..011329d9421 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
@@ -29,29 +29,17 @@ import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.internal.TempFolderCleaner;
import org.sonar.batch.components.PastSnapshotFinder;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion;
-import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.deprecated.components.*;
+import org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader;
+import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
import org.sonar.batch.platform.DefaultServer;
-import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
-import org.sonar.batch.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.batch.repository.DefaultServerIssuesLoader;
-import org.sonar.batch.repository.GlobalRepositoriesLoader;
-import org.sonar.batch.repository.GlobalRepositoriesProvider;
-import org.sonar.batch.repository.ProjectRepositoriesLoader;
-import org.sonar.batch.repository.ServerIssuesLoader;
+import org.sonar.batch.repository.*;
import org.sonar.batch.repository.user.UserRepository;
import org.sonar.core.cluster.NullQueue;
import org.sonar.core.config.Logback;
import org.sonar.core.i18n.DefaultI18n;
import org.sonar.core.i18n.RuleI18nManager;
-import org.sonar.core.persistence.DaoUtils;
-import org.sonar.core.persistence.DatabaseVersion;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.persistence.SemaphoreUpdater;
-import org.sonar.core.persistence.SemaphoresImpl;
+import org.sonar.core.persistence.*;
import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.rule.CacheRuleFinder;
import org.sonar.core.user.HibernateUserFinder;
@@ -119,6 +107,9 @@ public class GlobalContainer extends ComponentContainer {
if (getComponentByType(ServerIssuesLoader.class) == null) {
add(DefaultServerIssuesLoader.class);
}
+ if (getComponentByType(ServerLineHashesLoader.class) == null) {
+ add(DefaultServerLineHashesLoader.class);
+ }
}
private void addDatabaseComponents() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
index ed359265713..f7fced2829d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastLineHashes.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoader.java
@@ -17,23 +17,23 @@
* 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.batch.scan;
+package org.sonar.batch.issue.tracking;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterators;
-import org.sonar.api.BatchComponent;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.batch.bootstrap.ServerClient;
-public class LastLineHashes implements BatchComponent {
+public class DefaultServerLineHashesLoader implements ServerLineHashesLoader {
private final ServerClient server;
- public LastLineHashes(ServerClient server) {
+ public DefaultServerLineHashesLoader(ServerClient server) {
this.server = server;
}
+ @Override
public String[] getLineHashes(String fileKey) {
String hashesFromWs = loadHashesFromWs(fileKey);
return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
index 406c9d0518f..7c05341ffe1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java
@@ -49,7 +49,6 @@ import org.sonar.api.rules.RuleFinder;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.batch.scan.LastLineHashes;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.core.issue.db.IssueChangeDto;
@@ -68,7 +67,7 @@ public class IssueTrackingDecorator implements Decorator {
private final IssueCache issueCache;
private final InitialOpenIssuesStack initialOpenIssues;
private final IssueTracking tracking;
- private final LastLineHashes lastLineHashes;
+ private final ServerLineHashesLoader lastLineHashes;
private final IssueHandlers handlers;
private final IssueWorkflow workflow;
private final IssueUpdater updater;
@@ -80,7 +79,7 @@ public class IssueTrackingDecorator implements Decorator {
private final Project project;
public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking,
- LastLineHashes lastLineHashes,
+ ServerLineHashesLoader lastLineHashes,
IssueHandlers handlers, IssueWorkflow workflow,
IssueUpdater updater,
Project project,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
index 9b5b26f730b..0086ab704fa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java
@@ -38,7 +38,6 @@ import org.sonar.batch.index.BatchResource;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.protocol.input.ProjectRepositories;
-import org.sonar.batch.scan.LastLineHashes;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.issue.IssueUpdater;
@@ -56,7 +55,7 @@ public class LocalIssueTracking implements BatchComponent {
private final IssueCache issueCache;
private final IssueTracking tracking;
- private final LastLineHashes lastLineHashes;
+ private final ServerLineHashesLoader lastLineHashes;
private final IssueWorkflow workflow;
private final IssueUpdater updater;
private final IssueChangeContext changeContext;
@@ -68,7 +67,7 @@ public class LocalIssueTracking implements BatchComponent {
private final AnalysisMode analysisMode;
public LocalIssueTracking(ResourceCache resourceCache, IssueCache issueCache, IssueTracking tracking,
- LastLineHashes lastLineHashes, IssueWorkflow workflow, IssueUpdater updater,
+ ServerLineHashesLoader lastLineHashes, IssueWorkflow workflow, IssueUpdater updater,
ActiveRules activeRules, InputPathCache inputPathCache, ServerIssueRepository serverIssueRepository,
ProjectRepositories projectRepositories, AnalysisMode analysisMode) {
this.resourceCache = resourceCache;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
index 6fa0e45c368..98719ce179b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerIssueRepository.java
@@ -24,6 +24,8 @@ import org.sonar.api.BatchComponent;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
@@ -33,11 +35,13 @@ import org.sonar.batch.index.Caches;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
import org.sonar.batch.repository.ServerIssuesLoader;
+import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.component.ComponentKeys;
import javax.annotation.Nullable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
@@ -51,13 +55,16 @@ public class ServerIssueRepository implements BatchComponent {
private final ProjectReactor reactor;
private final ResourceCache resourceCache;
private final AnalysisMode analysisMode;
+ private final InputPathCache inputPathCache;
- public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, ResourceCache resourceCache, AnalysisMode analysisMode) {
+ public ServerIssueRepository(Caches caches, ServerIssuesLoader previousIssuesLoader, ProjectReactor reactor, ResourceCache resourceCache,
+ AnalysisMode analysisMode, InputPathCache inputPathCache) {
this.caches = caches;
this.previousIssuesLoader = previousIssuesLoader;
this.reactor = reactor;
this.resourceCache = resourceCache;
this.analysisMode = analysisMode;
+ this.inputPathCache = inputPathCache;
}
public void load() {
@@ -93,6 +100,10 @@ public class ServerIssueRepository implements BatchComponent {
if (!component.isFile()) {
throw new UnsupportedOperationException("Incremental mode should only get issues on files");
}
+ InputFile inputFile = (InputFile) inputPathCache.getInputPath(component);
+ if (inputFile.status() == Status.ADDED) {
+ return Collections.emptyList();
+ }
Profiler profiler = Profiler.create(LOG).startInfo("Load server issues for " + component.resource().getPath());
final List<ServerIssue> result = new ArrayList<>();
previousIssuesLoader.load(component.key(), new Function<ServerIssue, Void>() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
new file mode 100644
index 00000000000..857bdb2fdaf
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/ServerLineHashesLoader.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.batch.issue.tracking;
+
+import org.sonar.api.BatchComponent;
+
+public interface ServerLineHashesLoader extends BatchComponent {
+
+ String[] getLineHashes(String fileKey);
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
index 8151f4184f4..28ed758d9d9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/SourceHashHolder.java
@@ -22,7 +22,6 @@ package org.sonar.batch.issue.tracking;
import com.google.common.collect.ImmutableSet;
import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.batch.scan.LastLineHashes;
import javax.annotation.CheckForNull;
@@ -30,13 +29,13 @@ import java.util.Collection;
public class SourceHashHolder {
- private final LastLineHashes lastSnapshots;
+ private final ServerLineHashesLoader lastSnapshots;
private FileHashes hashedReference;
private FileHashes hashedSource;
private DefaultInputFile inputFile;
- public SourceHashHolder(DefaultInputFile inputFile, LastLineHashes lastSnapshots) {
+ public SourceHashHolder(DefaultInputFile inputFile, ServerLineHashesLoader lastSnapshots) {
this.inputFile = inputFile;
this.lastSnapshots = lastSnapshots;
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index f7517a7be8f..389e9dfd5b8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -33,11 +33,9 @@ import org.sonar.batch.bootstrap.PluginsRepository;
import org.sonar.batch.bootstrap.TaskProperties;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.issue.tracking.ServerLineHashesLoader;
+import org.sonar.batch.protocol.input.*;
import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
-import org.sonar.batch.protocol.input.FileData;
-import org.sonar.batch.protocol.input.GlobalRepositories;
-import org.sonar.batch.protocol.input.ProjectRepositories;
import org.sonar.batch.repository.GlobalRepositoriesLoader;
import org.sonar.batch.repository.ProjectRepositoriesLoader;
import org.sonar.batch.repository.ServerIssuesLoader;
@@ -49,12 +47,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
/**
* Main utility class for writing batch medium tests.
@@ -77,6 +70,7 @@ public class BatchMediumTester {
private final FakeProjectRepositoriesLoader projectRefProvider = new FakeProjectRepositoriesLoader();
private final FakePluginsRepository pluginsReferential = new FakePluginsRepository();
private final FakeServerIssuesLoader serverIssues = new FakeServerIssuesLoader();
+ private final FakeServerLineHashesLoader serverLineHashes = new FakeServerLineHashesLoader();
private final Map<String, String> bootstrapProperties = new HashMap<String, String>();
public BatchMediumTester build() {
@@ -141,6 +135,11 @@ public class BatchMediumTester {
return this;
}
+ public BatchMediumTesterBuilder mockLineHashes(String fileKey, String[] lineHashes) {
+ serverLineHashes.byKey.put(fileKey, lineHashes);
+ return this;
+ }
+
}
public void start() {
@@ -160,6 +159,7 @@ public class BatchMediumTester {
builder.globalRefProvider,
builder.projectRefProvider,
builder.serverIssues,
+ builder.serverLineHashes,
new DefaultDebtModel())
.setBootstrapProperties(builder.bootstrapProperties)
.build();
@@ -326,4 +326,17 @@ public class BatchMediumTester {
}
+ private static class FakeServerLineHashesLoader implements ServerLineHashesLoader {
+ private Map<String, String[]> byKey = new HashMap<String, String[]>();
+
+ @Override
+ public String[] getLineHashes(String fileKey) {
+ if (byKey.containsKey(fileKey)) {
+ return byKey.get(fileKey);
+ } else {
+ throw new IllegalStateException("You forgot to mock line hashes for " + fileKey);
+ }
+ }
+ }
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 0cc044e2036..eeb15214e81 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -34,30 +34,14 @@ import org.sonar.api.utils.SonarException;
import org.sonar.batch.DefaultFileLinesContextFactory;
import org.sonar.batch.ProjectConfigurator;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.bootstrap.DefaultAnalysisMode;
-import org.sonar.batch.bootstrap.ExtensionInstaller;
-import org.sonar.batch.bootstrap.ExtensionMatcher;
-import org.sonar.batch.bootstrap.ExtensionUtils;
-import org.sonar.batch.bootstrap.MetricProvider;
+import org.sonar.batch.bootstrap.*;
import org.sonar.batch.debt.DebtModelProvider;
import org.sonar.batch.debt.IssueChangelogDebtCalculator;
import org.sonar.batch.dependency.DependencyCache;
import org.sonar.batch.deprecated.components.DefaultResourceCreationLock;
import org.sonar.batch.deprecated.components.PeriodsDefinition;
import org.sonar.batch.duplication.DuplicationCache;
-import org.sonar.batch.index.Caches;
-import org.sonar.batch.index.ComponentDataCache;
-import org.sonar.batch.index.DefaultIndex;
-import org.sonar.batch.index.DependencyPersister;
-import org.sonar.batch.index.DuplicationPersister;
-import org.sonar.batch.index.EventPersister;
-import org.sonar.batch.index.LinkPersister;
-import org.sonar.batch.index.MeasurePersister;
-import org.sonar.batch.index.ResourceCache;
-import org.sonar.batch.index.ResourceKeyMigration;
-import org.sonar.batch.index.ResourcePersister;
-import org.sonar.batch.index.SourceDataFactory;
-import org.sonar.batch.index.SourcePersister;
+import org.sonar.batch.index.*;
import org.sonar.batch.issue.DefaultProjectIssues;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.issue.tracking.InitialOpenIssuesStack;
@@ -144,7 +128,6 @@ public class ProjectScanContainer extends ComponentContainer {
ProjectConfigurator.class,
DefaultIndex.class,
DefaultFileLinesContextFactory.class,
- LastLineHashes.class,
Caches.class,
ResourceCache.class,
ComponentDataCache.class,
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastLineHashesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
index de9abac80a0..28d9b251ec9 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastLineHashesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/DefaultServerLineHashesLoaderTest.java
@@ -17,7 +17,7 @@
* 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.batch.scan;
+package org.sonar.batch.issue.tracking;
import org.junit.Before;
import org.junit.Rule;
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-public class LastLineHashesTest {
+public class DefaultServerLineHashesLoaderTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -49,7 +49,7 @@ public class LastLineHashesTest {
ServerClient server = mock(ServerClient.class);
when(server.request(anyString())).thenReturn("ae12\n\n43fb");
- LastLineHashes lastSnapshots = new LastLineHashes(server);
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server);
String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Bar.c");
assertThat(hashes).containsOnly("ae12", "", "43fb");
@@ -61,7 +61,7 @@ public class LastLineHashesTest {
ServerClient server = mock(ServerClient.class);
when(server.request(anyString())).thenReturn("ae12\n\n43fb");
- LastLineHashes lastSnapshots = new LastLineHashes(server);
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server);
String[] hashes = lastSnapshots.getLineHashes("myproject:org/foo/Foo Bar.c");
assertThat(hashes).containsOnly("ae12", "", "43fb");
@@ -73,7 +73,7 @@ public class LastLineHashesTest {
ServerClient server = mock(ServerClient.class);
when(server.request(anyString())).thenThrow(new HttpDownloader.HttpException(new URI(""), 500));
- LastLineHashes lastSnapshots = new LastLineHashes(server);
+ ServerLineHashesLoader lastSnapshots = new DefaultServerLineHashesLoader(server);
thrown.expect(HttpDownloader.HttpException.class);
lastSnapshots.getLineHashes("foo");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
index cd3746ef401..e4dc6d3099f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
@@ -44,7 +44,6 @@ import org.sonar.api.rules.RuleFinder;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.System2;
import org.sonar.batch.issue.IssueCache;
-import org.sonar.batch.scan.LastLineHashes;
import org.sonar.batch.scan.filesystem.InputFileMetadata;
import org.sonar.batch.scan.filesystem.InputPathCache;
import org.sonar.core.issue.IssueUpdater;
@@ -84,7 +83,7 @@ public class IssueTrackingDecoratorTest {
IssueCache issueCache = mock(IssueCache.class, RETURNS_MOCKS);
InitialOpenIssuesStack initialOpenIssues = mock(InitialOpenIssuesStack.class);
IssueTracking tracking = mock(IssueTracking.class, RETURNS_MOCKS);
- LastLineHashes lastSnapshots = mock(LastLineHashes.class);
+ ServerLineHashesLoader lastSnapshots = mock(ServerLineHashesLoader.class);
IssueHandlers handlers = mock(IssueHandlers.class);
IssueWorkflow workflow = mock(IssueWorkflow.class);
IssueUpdater updater = mock(IssueUpdater.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
index a58f1bb7068..332356c9279 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
@@ -36,7 +36,6 @@ import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
-import org.sonar.batch.scan.LastLineHashes;
import org.sonar.core.issue.db.IssueDto;
import java.io.File;
@@ -58,12 +57,12 @@ public class IssueTrackingTest {
IssueTracking tracking;
Resource project;
SourceHashHolder sourceHashHolder;
- LastLineHashes lastSnapshots;
+ ServerLineHashesLoader lastSnapshots;
long violationId = 0;
@Before
public void before() {
- lastSnapshots = mock(LastLineHashes.class);
+ lastSnapshots = mock(ServerLineHashesLoader.class);
project = mock(Project.class);
tracking = new IssueTracking();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
index 59371ca4947..3488e9d25e4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
@@ -28,7 +28,6 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.batch.scan.LastLineHashes;
import java.io.File;
@@ -45,14 +44,14 @@ public class SourceHashHolderTest {
SourceHashHolder sourceHashHolder;
- LastLineHashes lastSnapshots;
+ ServerLineHashesLoader lastSnapshots;
DefaultInputFile file;
private File ioFile;
@Before
public void setUp() throws Exception {
- lastSnapshots = mock(LastLineHashes.class);
+ lastSnapshots = mock(ServerLineHashesLoader.class);
file = mock(DefaultInputFile.class);
ioFile = temp.newFile();
when(file.file()).thenReturn(ioFile);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/IncrementalModeMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/IncrementalModeMediumTest.java
index f1b91f30b68..ffc8451d9cb 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/IncrementalModeMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/IncrementalModeMediumTest.java
@@ -59,15 +59,18 @@ public class IncrementalModeMediumTest {
}
}
- public BatchMediumTester tester = BatchMediumTester.builder()
+ public BatchMediumTester tester = BatchMediumTester
+ .builder()
.bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_INCREMENTAL))
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
.activateRule(new ActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", null, "xoo"))
.activateRule(new ActiveRule("manual", "MyManualIssue", null, "My manual issue", "MAJOR", null, null))
.setPreviousAnalysisDate(new Date())
- .addFileData("sample", "xources/hello/HelloJava.xoo", new FileData(DigestUtils.md5Hex(SAMPLE_CONTENT), false, null, null, null))
- // Existing issue
+ .addFileData("sample", "src/sample.xoo", new FileData(DigestUtils.md5Hex(SAMPLE_CONTENT), false, null, null, null))
+ .mockLineHashes("sample:src/sample.xoo",
+ new String[] {DigestUtils.md5Hex("Samplecontent"), DigestUtils.md5Hex("oldcode"), DigestUtils.md5Hex("4"), DigestUtils.md5Hex("lines")})
+ // Remote open issue => will be tracked and not new
.mockServerIssue(org.sonar.batch.protocol.input.BatchInput.ServerIssue.newBuilder().setKey("xyz")
.setModuleKey("sample")
.setPath("src/sample.xoo")
@@ -79,16 +82,17 @@ public class IncrementalModeMediumTest {
.setChecksum(DigestUtils.md5Hex("Samplecontent"))
.setStatus("OPEN")
.build())
- // Resolved issue
+ // Remote open issue that no more exists => will be closed
.mockServerIssue(org.sonar.batch.protocol.input.BatchInput.ServerIssue.newBuilder().setKey("resolved")
.setModuleKey("sample")
.setPath("src/sample.xoo")
.setRuleRepository("xoo")
- .setRuleKey("OneIssuePerLine")
- .setLine(1)
+ .setRuleKey("OneIssuePerFile")
+ .setMsg("An issue that is no more detected")
+ .setLine(2)
.setSeverity(Severity.MAJOR)
.setCreationDate(date("14/03/2004"))
- .setChecksum(DigestUtils.md5Hex("dontexist"))
+ .setChecksum(DigestUtils.md5Hex("oldcode"))
.setStatus("OPEN")
.build())
// Manual issue
@@ -97,10 +101,10 @@ public class IncrementalModeMediumTest {
.setPath("src/sample.xoo")
.setRuleRepository("manual")
.setRuleKey("MyManualIssue")
- .setLine(1)
+ .setLine(4)
.setSeverity(Severity.MAJOR)
.setCreationDate(date("14/03/2004"))
- .setChecksum(DigestUtils.md5Hex("Samplecontent"))
+ .setChecksum(DigestUtils.md5Hex("lines"))
.setStatus("OPEN")
.build())
.build();
@@ -122,7 +126,7 @@ public class IncrementalModeMediumTest {
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
- FileUtils.write(xooFile, SAMPLE_CONTENT);
+ FileUtils.write(xooFile, SAMPLE_CONTENT + "\nmodification");
TaskResult result = tester.newTask()
.properties(ImmutableMap.<String, String>builder()
@@ -140,6 +144,7 @@ public class IncrementalModeMediumTest {
int openIssues = 0;
int resolvedIssue = 0;
for (Issue issue : result.issues()) {
+ System.out.println(issue.key() + " " + issue.line() + " " + issue.status());
if (issue.isNew()) {
newIssues++;
} else if (issue.resolution() != null) {
@@ -148,7 +153,7 @@ public class IncrementalModeMediumTest {
openIssues++;
}
}
- assertThat(newIssues).isEqualTo(3);
+ assertThat(newIssues).isEqualTo(4);
assertThat(openIssues).isEqualTo(2);
assertThat(resolvedIssue).isEqualTo(1);
}