diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-28 18:46:35 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-04-29 01:16:09 +0400 |
commit | f33d88a2158097053b9451905efb1cefdba8b180 (patch) | |
tree | 0fe6ed6182778adf1a4d9bfed72eecbdb08ce70b | |
parent | 04b6ae40d1d27fe040484c578b642af6dfe21d56 (diff) | |
download | sonarqube-f33d88a2158097053b9451905efb1cefdba8b180.tar.gz sonarqube-f33d88a2158097053b9451905efb1cefdba8b180.zip |
SONAR-2261 Exclusion patterns must be trimmed
Trim them on Java and Ruby side.
3 files changed, 28 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java index 5d3fba87331..b281c467154 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java @@ -102,6 +102,9 @@ public class ProjectBuilder { if (exclusionPatterns == null) { exclusionPatterns = new String[0]; } + for (int i = 0; i < exclusionPatterns.length; i++) { + exclusionPatterns[i] = StringUtils.trim(exclusionPatterns[i]); + } return exclusionPatterns; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java index ffa872b0e1b..18c42efa52f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java @@ -19,22 +19,22 @@ */ package org.sonar.batch; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.apache.commons.configuration.PropertiesConfiguration; import org.junit.Before; import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.jpa.test.AbstractDbUnitTestCase; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; +import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.text.SimpleDateFormat; import java.util.Date; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class ProjectBuilderTest extends AbstractDbUnitTestCase { private ProjectBuilder builder = null; @@ -66,6 +66,23 @@ public class ProjectBuilderTest extends AbstractDbUnitTestCase { assertThat(project.getExclusionPatterns()[2], is("*/bar")); } + /** + * See http://jira.codehaus.org/browse/SONAR-2261 + * Note that several exclusions separated by comma would be correctly trimmed by commons-configuration library. + * So issue is only with a single pattern, which contains spaces. + */ + @Test + public void trimExclusionPatterns() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, " foo "); + + Project project = new Project("key"); + builder.configure(project, configuration); + + assertThat(project.getExclusionPatterns().length, is(1)); + assertThat(project.getExclusionPatterns()[0], is("foo")); + } + @Test public void getLanguageFromConfiguration() { PropertiesConfiguration configuration = new PropertiesConfiguration(); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index cb68a4218cb..24b1d8aa46e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -165,7 +165,8 @@ class ProjectController < ApplicationController if patterns.empty? Property.clear('sonar.exclusions', @project.id) else - Property.set('sonar.exclusions', patterns.join(','), @project.id) + # Trim spaces in patterns before merging into one String - see http://jira.codehaus.org/browse/SONAR-2261 + Property.set('sonar.exclusions', patterns.collect{|x| x.strip}.join(','), @project.id) end flash[:notice]='Filters added' redirect_to :action => 'settings', :id => @project.id |