]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 support cross-project duplications in multi-lang project
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 18 Mar 2014 15:14:05 +0000 (16:14 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 18 Mar 2014 15:14:05 +0000 (16:14 +0100)
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarBridgeEngine.java
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java

index cf6af57a06c166e67279a01f6de2a4f3217a6590..7c24a89bb3a47ed96dd3ea80e60c0f661853620b 100644 (file)
@@ -101,7 +101,7 @@ public class SonarBridgeEngine extends CpdEngine {
     }
 
     // Create index
-    SonarDuplicationsIndex index = indexFactory.create(project);
+    SonarDuplicationsIndex index = indexFactory.create(project, languageKey);
 
     TokenizerBridge bridge = new TokenizerBridge(mapping.getTokenizer(), fs.encoding().name(), getBlockSize(project, languageKey));
     for (InputFile inputFile : sourceFiles) {
index c1890f4a08cd7a82f3ec53b1a49b3ec5a14fde64..8255053db315636e1beea341a3c48740ac33494c 100644 (file)
@@ -102,12 +102,12 @@ public class SonarEngine extends CpdEngine {
     if (sourceFiles.isEmpty()) {
       return;
     }
-    SonarDuplicationsIndex index = createIndex(project, sourceFiles);
+    SonarDuplicationsIndex index = createIndex(project, languageKey, sourceFiles);
     detect(index, context, sourceFiles);
   }
 
-  private SonarDuplicationsIndex createIndex(Project project, Iterable<InputFile> sourceFiles) {
-    final SonarDuplicationsIndex index = indexFactory.create(project);
+  private SonarDuplicationsIndex createIndex(Project project, String language, Iterable<InputFile> sourceFiles) {
+    final SonarDuplicationsIndex index = indexFactory.create(project, language);
 
     TokenChunker tokenChunker = JavaTokenProducer.build();
     StatementChunker statementChunker = JavaStatementBuilder.build();
index d91b4c229548d7560e362c1d8e86d45f7718abc0..2b587690753fc2d8a794bac8f01f7d9f7efa31a9 100644 (file)
@@ -46,14 +46,15 @@ public class DbDuplicationsIndex {
 
   private DuplicationDao dao;
 
-  public DbDuplicationsIndex(ResourcePersister resourcePersister, Project currentProject, DuplicationDao dao) {
+  public DbDuplicationsIndex(ResourcePersister resourcePersister, Project currentProject, DuplicationDao dao,
+                             String language) {
     this.dao = dao;
     this.resourcePersister = resourcePersister;
     Snapshot currentSnapshot = resourcePersister.getSnapshotOrFail(currentProject);
     Snapshot lastSnapshot = resourcePersister.getLastSnapshot(currentSnapshot, false);
     this.currentProjectSnapshotId = currentSnapshot.getId();
     this.lastSnapshotId = lastSnapshot == null ? null : lastSnapshot.getId();
-    this.languageKey = currentProject.getLanguageKey();
+    this.languageKey = language;
   }
 
   int getSnapshotIdFor(InputFile inputFile) {
index 4a242726e63f285e3c5f90420aae368527f13a9b..f6f8981f6c1aa3247e1d370397918fbdae0cc33e 100644 (file)
@@ -44,9 +44,9 @@ public class IndexFactory implements BatchExtension {
     this.dao = dao;
   }
 
-  public SonarDuplicationsIndex create(Project project) {
+  public SonarDuplicationsIndex create(Project project, String languageKey) {
     if (verifyCrossProject(project, LOG)) {
-      return new SonarDuplicationsIndex(new DbDuplicationsIndex(resourcePersister, project, dao));
+      return new SonarDuplicationsIndex(new DbDuplicationsIndex(resourcePersister, project, dao, languageKey));
     }
     return new SonarDuplicationsIndex();
   }