From 1e243282c96a4cdd11ff12782aecf0ea606b4342 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Thu, 8 Jan 2015 09:10:00 +0100 Subject: [PATCH] SONAR-6014 Fix persistence of dependencies --- .../org/sonar/batch/design/MavenDependenciesSensor.java | 5 ++++- .../sonar/batch/design/MavenDependenciesSensorTest.java | 8 ++++---- 2 files changed, 8 insertions(+), 5 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 a6de27c9ef2..cd1698281f1 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 @@ -238,7 +238,9 @@ public class MavenDependenciesSensor implements Sensor { Resource result = context.getResource(project); if (result == null || !((Project) result).getAnalysisVersion().equals(dependency.version())) { Library lib = new Library(project.getKey(), dependency.version()); - context.saveResource(lib); + index.addResource(lib); + // Temporary hack since we need snapshot id to persist dependencies + resourcePersister.persist(); result = context.getResource(lib); } return result; @@ -259,6 +261,7 @@ public class MavenDependenciesSensor implements Sensor { if (result == null || !((Project) result).getAnalysisVersion().equals(artifact.getBaseVersion())) { Library lib = Library.createFromMavenIds(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); index.addResource(lib); + // Temporary hack since we need snapshot id to persist dependencies resourcePersister.persist(); result = context.getResource(lib); } 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 b05067227d9..bdad05d8fd5 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 @@ -78,13 +78,13 @@ public class MavenDependenciesSensorTest { sensor.analyse(project, sensorContext); Library antlr = new Library("antlr:antlr", "2.7.2"); - verify(sensorContext).saveResource(eq(antlr)); + verify(sonarIndex).addResource(eq(antlr)); Library commonsFU = new Library("commons-fileupload:commons-fileupload", "1.1.1"); - verify(sensorContext).saveResource(eq(commonsFU)); + verify(sonarIndex).addResource(eq(commonsFU)); Library commonsIo = new Library("commons-io:commons-io", "1.1"); - verify(sensorContext).saveResource(eq(commonsIo)); + verify(sonarIndex).addResource(eq(commonsIo)); Library junit = new Library("junit:junit", "3.8.1"); - verify(sensorContext).saveResource(eq(junit)); + verify(sonarIndex).addResource(eq(junit)); verify(sensorContext).saveDependency(new Dependency(project, antlr).setUsage("compile").setWeight(1)); verify(sensorContext).saveDependency(new Dependency(commonsFU, commonsIo).setUsage("compile").setWeight(1)); -- 2.39.5