diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-07 21:33:46 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-07 21:59:56 +0100 |
commit | fa34983b28926de6f1fee2794195401a81b73b3f (patch) | |
tree | 7e5c67261d04c0aa8db63b5158bf9c62ce774dfa | |
parent | 8338c86d2fc5d50f2058d1fc00b536c821c263c8 (diff) | |
download | sonarqube-fa34983b28926de6f1fee2794195401a81b73b3f.tar.gz sonarqube-fa34983b28926de6f1fee2794195401a81b73b3f.zip |
SONAR-6014 Fix issue when saving dependencies
3 files changed, 25 insertions, 14 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java index 9b618b7b4e8..34624780916 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/design/MavenDependenciesSensor.java @@ -54,6 +54,7 @@ import org.sonar.api.resources.Library; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.utils.SonarException; +import org.sonar.batch.index.ResourcePersister; import java.lang.reflect.Type; import java.util.ArrayList; @@ -67,16 +68,17 @@ public class MavenDependenciesSensor implements Sensor { private static final Logger LOG = LoggerFactory.getLogger(MavenDependenciesSensor.class); - private ArtifactRepository localRepository; - private ArtifactFactory artifactFactory; - private ArtifactMetadataSource artifactMetadataSource; - private ArtifactCollector artifactCollector; - private DependencyTreeBuilder treeBuilder; - private SonarIndex index; - private Settings settings; + private final ArtifactRepository localRepository; + private final ArtifactFactory artifactFactory; + private final ArtifactMetadataSource artifactMetadataSource; + private final ArtifactCollector artifactCollector; + private final DependencyTreeBuilder treeBuilder; + private final SonarIndex index; + private final Settings settings; + private final ResourcePersister resourcePersister; public MavenDependenciesSensor(Settings settings, ArtifactRepository localRepository, ArtifactFactory artifactFactory, ArtifactMetadataSource artifactMetadataSource, - ArtifactCollector artifactCollector, DependencyTreeBuilder treeBuilder, SonarIndex index) { + ArtifactCollector artifactCollector, DependencyTreeBuilder treeBuilder, SonarIndex index, ResourcePersister resourcePersister) { this.settings = settings; this.localRepository = localRepository; this.artifactFactory = artifactFactory; @@ -84,14 +86,14 @@ public class MavenDependenciesSensor implements Sensor { this.artifactCollector = artifactCollector; this.index = index; this.treeBuilder = treeBuilder; + this.resourcePersister = resourcePersister; } /** * Used with SQ Maven plugin 2.5+ */ - public MavenDependenciesSensor(Settings settings, SonarIndex index) { - this.settings = settings; - this.index = index; + public MavenDependenciesSensor(Settings settings, SonarIndex index, ResourcePersister resourcePersister) { + this(settings, null, null, null, null, null, index, resourcePersister); } @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index df0979454f5..ffefb356858 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -74,11 +74,19 @@ public final class ResourcePersister implements ScanPersister { } for (BatchResource lib : resourceCache.allLibraries()) { - Snapshot s = persistLibrary(projectTree.getRootProject().getAnalysisDate(), (Library) lib.resource()); - lib.setSnapshot(s); + if (lib.snapshot() != null) { + // already persisted + continue; + } + persistLibrary(lib); } } + private void persistLibrary(BatchResource lib) { + Snapshot s = persistLibrary(projectTree.getRootProject().getAnalysisDate(), (Library) lib.resource()); + lib.setSnapshot(s); + } + private void persist(BatchResource batchResource) { if (batchResource.snapshot() != null) { // already persisted diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java index 504b82981a0..b05067227d9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/design/MavenDependenciesSensorTest.java @@ -29,6 +29,7 @@ import org.sonar.api.config.Settings; import org.sonar.api.design.Dependency; import org.sonar.api.resources.Library; import org.sonar.api.resources.Project; +import org.sonar.batch.index.ResourcePersister; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -47,7 +48,7 @@ public class MavenDependenciesSensorTest { public void prepare() { settings = new Settings(); sonarIndex = mock(SonarIndex.class); - sensor = new MavenDependenciesSensor(settings, sonarIndex); + sensor = new MavenDependenciesSensor(settings, sonarIndex, mock(ResourcePersister.class)); sensorContext = mock(SensorContext.class); when(sensorContext.getResource(any(Library.class))).thenAnswer(new Answer<Library>() { public Library answer(InvocationOnMock invocation) throws Throwable { |