diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-05 17:27:48 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-09-05 17:28:31 +0400 |
commit | 9d067cff77e01462cee0a60742410fc375197ca5 (patch) | |
tree | 3fd44d8676a7e79beebe7a1b5bab397f955b204d /plugins | |
parent | 66dcfc8adc7b36d31e0fd80353066a2d6938cd98 (diff) | |
download | sonarqube-9d067cff77e01462cee0a60742410fc375197ca5.tar.gz sonarqube-9d067cff77e01462cee0a60742410fc375197ca5.zip |
SONAR-1091 Disable CPD over different projects, when dry run
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java index e99cd441e9f..46d876a6dc5 100644 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java @@ -62,6 +62,13 @@ public class SonarEngine implements CpdEngine { private final ResourcePersister resourcePersister; private final DatabaseSession dbSession; + /** + * For dry run, where is no access to database. + */ + public SonarEngine() { + this(null, null); + } + public SonarEngine(ResourcePersister resourcePersister, DatabaseSession dbSession) { this.resourcePersister = resourcePersister; this.dbSession = dbSession; @@ -71,8 +78,12 @@ public class SonarEngine implements CpdEngine { return Java.INSTANCE.equals(language); } - private static boolean isCrossProject(Project project) { - return project.getConfiguration().getBoolean("sonar.cpd.cross_project", false); + /** + * @return true, if was enabled by user and database is available + */ + private boolean isCrossProject(Project project) { + return project.getConfiguration().getBoolean("sonar.cpd.cross_project", false) + && resourcePersister != null && dbSession != null; } private static String getFullKey(Project project, Resource resource) { @@ -92,9 +103,10 @@ public class SonarEngine implements CpdEngine { // Create index final SonarCloneIndex index; if (isCrossProject(project)) { - Logs.INFO.info("Enabled cross-project analysis"); + Logs.INFO.info("Cross-project analysis enabled"); index = new SonarCloneIndex(new DbCloneIndex(dbSession, resourcePersister, project)); } else { + Logs.INFO.info("Cross-project analysis disabled"); index = new SonarCloneIndex(); } |