diff options
author | Jenkins CI <ci@sonarsource.com> | 2014-12-19 11:28:14 +0100 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2014-12-19 11:28:14 +0100 |
commit | 4742f1a30dfa08e9cc30b793c310bb693ce14e44 (patch) | |
tree | 2a2d9bab25f7e58ec123c6047d3d7948eb9a5546 | |
parent | 4f18574ffcc8ff822afaa40a9a12c690b2fa6fad (diff) | |
parent | 863d26c40c1bb032733e912d5dcd8c883e8c1c4b (diff) | |
download | sonarqube-4742f1a30dfa08e9cc30b793c310bb693ce14e44.tar.gz sonarqube-4742f1a30dfa08e9cc30b793c310bb693ce14e44.zip |
Automatic merge from branch-5.0
* origin/branch-5.0:
SONAR-5878 Fix regression when parsing project properties
Fix navigation between issues in a big file
6 files changed, 96 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee b/server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee index 8454e60e12b..88dbf3311a3 100644 --- a/server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee +++ b/server/sonar-web/src/main/coffee/issues/component-viewer/main.coffee @@ -90,7 +90,7 @@ define [ selected = @options.app.state.get 'selectedIndex' selectedIssue = @options.app.issues.at selected if selectedIssue.get('component') == @model.get('key') - @scrollToLine selectedIssue.get('line') + @scrollToIssue selectedIssue.get('key') else @unbindShortcuts() @options.app.controller.showComponentViewer selectedIssue @@ -115,14 +115,8 @@ define [ scrollToIssue: (key) -> el = @$("#issue-#{key}") if el.length > 0 - viewTop = el.offset().top - viewBottom = viewTop + el.outerHeight() - windowTop = $(window).scrollTop() - windowBottom = windowTop + $(window).height() - if viewTop < windowTop - $(window).scrollTop viewTop - TOP_OFFSET - if viewBottom > windowBottom - $(window).scrollTop $(window).scrollTop() - windowBottom + viewBottom + BOTTOM_OFFSET + line = el.closest('[data-line-number]').data 'line-number' + this.scrollToLine line else @unbindShortcuts() selected = @options.app.state.get 'selectedIndex' diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index fbed697fec7..9171c69330a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -44,6 +44,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -136,7 +138,10 @@ public class ProjectReactorBuilder { parentProperties.remove(key); } } - String[] moduleIds = getListFromProperty(currentModuleProperties, PROPERTY_MODULES); + List<String> moduleIds = new ArrayList<String>(Arrays.asList(getListFromProperty(currentModuleProperties, PROPERTY_MODULES))); + // Sort module by reverse lexicographic order to avoid issue when one module id is a prefix of another one + Collections.sort(moduleIds); + Collections.reverse(moduleIds); Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>(); for (String moduleId : moduleIds) { result.putAll(extractPropertiesByModule(moduleId, currentModuleProperties)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java index 8c427e20723..03f9c522e2c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java @@ -565,6 +565,72 @@ public class ProjectReactorBuilderTest { assertThat(buildDir.getName()).isEqualTo("build"); } + @Test + public void doNotMixPropertiesWhenModuleKeyIsPrefixOfAnother() throws IOException { + ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-same-prefix"); + + // CHECK ROOT + assertThat(rootProject.getKey()).isEqualTo("com.foo.project"); + assertThat(rootProject.getName()).isEqualTo("Foo Project"); + assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); + assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); + // root project must not contain some properties - even if they are defined in the root properties file + assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); + assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); + assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); + // and module properties must have been cleaned + assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + // Check baseDir and workDir + assertThat(rootProject.getBaseDir().getCanonicalFile()) + .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix")); + assertThat(rootProject.getWorkDir().getCanonicalFile()) + .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar")); + + // CHECK MODULES + List<ProjectDefinition> modules = rootProject.getSubProjects(); + assertThat(modules.size()).isEqualTo(2); + + // Module 1 + ProjectDefinition module1 = modules.get(0); + assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1")); + assertThat(module1.getKey()).isEqualTo("com.foo.project:module1"); + assertThat(module1.getName()).isEqualTo("module1"); + assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); + // Description should not be inherited from parent if not set + assertThat(module1.getDescription()).isNull(); + assertThat(module1.getSourceDirs()).contains("sources"); + assertThat(module1.getTestDirs()).contains("tests"); + assertThat(module1.getBinaries()).contains("target/classes"); + // and module properties must have been cleaned + assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + // Check baseDir and workDir + assertThat(module1.getBaseDir().getCanonicalFile()) + .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1")); + assertThat(module1.getWorkDir().getCanonicalFile()) + .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_module1")); + + // Module 1 Feature + ProjectDefinition module1Feature = modules.get(1); + assertThat(module1Feature.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature")); + assertThat(module1Feature.getKey()).isEqualTo("com.foo.project:com.foo.project.module1.feature"); + assertThat(module1Feature.getName()).isEqualTo("Foo Module 1 Feature"); + assertThat(module1Feature.getVersion()).isEqualTo("1.0-SNAPSHOT"); + assertThat(module1Feature.getDescription()).isEqualTo("Description of Module 1 Feature"); + assertThat(module1Feature.getSourceDirs()).contains("src"); + assertThat(module1Feature.getTestDirs()).contains("tests"); + assertThat(module1Feature.getBinaries()).contains("target/classes"); + // and module properties must have been cleaned + assertThat(module1Feature.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module1Feature.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + // Check baseDir and workDir + assertThat(module1Feature.getBaseDir().getCanonicalFile()) + .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature")); + assertThat(module1Feature.getWorkDir().getCanonicalFile()) + .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_com.foo.project.module1.feature")); + } + private Map<String, String> loadPropsFromFile(String filePath) throws IOException { Properties props = new Properties(); FileInputStream fileInputStream = null; diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1.feature/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1.feature/src/Fake.java new file mode 100644 index 00000000000..b2e6462a3f9 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1.feature/src/Fake.java @@ -0,0 +1 @@ +Fake diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1/sources/Fake.java new file mode 100644 index 00000000000..b2e6462a3f9 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/module1/sources/Fake.java @@ -0,0 +1 @@ +Fake diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/sonar-project.properties new file mode 100644 index 00000000000..2a6221a3757 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-definitions-same-prefix/sonar-project.properties @@ -0,0 +1,19 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=sources +sonar.tests=tests +sonar.binaries=target/classes + +sonar.modules=module1,\ + module1.feature + +# Mandatory properties for module1 are all inferred from the module ID + +module1.feature.sonar.projectKey=com.foo.project.module1.feature +module1.feature.sonar.projectName=Foo Module 1 Feature +# redefine some properties +module1.feature.sonar.projectDescription=Description of Module 1 Feature +module1.feature.sonar.sources=src |