*/
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;
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();
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