]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2261 Exclusion patterns must be trimmed
authorEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 28 Apr 2011 14:46:35 +0000 (18:46 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Thu, 28 Apr 2011 21:16:09 +0000 (01:16 +0400)
Trim them on Java and Ruby side.

sonar-batch/src/main/java/org/sonar/batch/ProjectBuilder.java
sonar-batch/src/test/java/org/sonar/batch/ProjectBuilderTest.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb

index 5d3fba8733129cbacf4bb37daf05009109e6b67a..b281c467154cc932eb3442831525620902e9d524 100644 (file)
@@ -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;
   }
 
index ffa872b0e1b18814367741fe9c811179ffe28dca..18c42efa52f275a9cdfc383c816b3858754e3cd7 100644 (file)
  */
 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();
index cb68a4218cbb9d81b5ff48ccca19d810cb6c5a9a..24b1d8aa46ead14a42fd8125170b35f3d6323cd4 100644 (file)
@@ -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