aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-18 14:22:09 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-18 14:22:09 +0100
commit7975f4777901956c93ca2f08606415840a682816 (patch)
treeaf1c621fe3e9ad66d6189c5266fa5f0cf9c3bf23 /sonar-batch
parent5a1634e38b510c684868cfe96185929622010ece (diff)
downloadsonarqube-7975f4777901956c93ca2f08606415840a682816.tar.gz
sonarqube-7975f4777901956c93ca2f08606415840a682816.zip
Fix inclusions by absolute path and improve documentation
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PathPattern.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java14
4 files changed, 27 insertions, 14 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index 73ba970889d..4d29ee9f8ab 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -94,7 +94,7 @@ public class DefaultModuleFileSystem implements ModuleFileSystem {
}
boolean isDefaultSourceCharset() {
- return settings.hasKey(CoreProperties.ENCODING_PROPERTY);
+ return !settings.hasKey(CoreProperties.ENCODING_PROPERTY);
}
public File workingDir() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
index 7abfac92823..959b63e28c7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ExclusionFilters.java
@@ -91,9 +91,9 @@ public class ExclusionFilters implements FileSystemFilter, ResourceFilter, Batch
private boolean isIgnoredFileResource(Resource resource) {
PathPattern[] inclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testInclusions : sourceInclusions);
if (inclusionPatterns.length > 0) {
- boolean matchInclusion = false;
+ boolean matchInclusion = true;
for (PathPattern pattern : inclusionPatterns) {
- matchInclusion |= pattern.match(resource);
+ matchInclusion &= (!pattern.supportResource() || pattern.match(resource));
}
if (!matchInclusion) {
return true;
@@ -101,7 +101,7 @@ public class ExclusionFilters implements FileSystemFilter, ResourceFilter, Batch
}
PathPattern[] exclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testExclusions : sourceExclusions);
for (PathPattern pattern : exclusionPatterns) {
- if (pattern.match(resource)) {
+ if (pattern.supportResource() && pattern.match(resource)) {
return true;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PathPattern.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PathPattern.java
index 7df5d1c945a..e7614d585b6 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PathPattern.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/PathPattern.java
@@ -35,17 +35,20 @@ abstract class PathPattern {
abstract boolean match(Resource resource);
+ abstract boolean supportResource();
+
static PathPattern create(String s) {
- if (StringUtils.startsWithIgnoreCase(s, "file:")) {
- return new AbsolutePathPattern(StringUtils.substring(s, "file:".length()));
+ String trimmed = StringUtils.trim(s);
+ if (StringUtils.startsWithIgnoreCase(trimmed, "file:")) {
+ return new AbsolutePathPattern(StringUtils.substring(trimmed, "file:".length()));
}
- return new RelativePathPattern(s);
+ return new RelativePathPattern(trimmed);
}
static PathPattern[] create(String[] s) {
PathPattern[] result = new PathPattern[s.length];
for (int i = 0; i < s.length; i++) {
- result[i] = PathPattern.create(s[i]);
+ result[i] = create(s[i]);
}
return result;
}
@@ -63,6 +66,10 @@ abstract class PathPattern {
return false;
}
+ boolean supportResource() {
+ return false;
+ }
+
@Override
public String toString() {
return "file:" + pattern.toString();
@@ -82,6 +89,10 @@ abstract class PathPattern {
return resource.matchFilePattern(pattern.toString());
}
+ boolean supportResource() {
+ return true;
+ }
+
@Override
public String toString() {
return pattern.toString();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
index afc4009f67b..74aa5bd264a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
@@ -78,19 +78,21 @@ public class DefaultModuleFileSystemTest {
.setSettings(new Settings());
assertThat(fileSystem.sourceCharset()).isEqualTo(Charset.defaultCharset());
+ assertThat(fileSystem.isDefaultSourceCharset()).isTrue();
}
@Test
- public void source_encoding_is_set() {
- File basedir = temp.newFolder("base");
+ public void source_encoding_is_set() {
+ File basedir = temp.newFolder("base");
Settings settings = new Settings();
settings.setProperty(CoreProperties.ENCODING_PROPERTY, "UTF-8");
DefaultModuleFileSystem fileSystem = new DefaultModuleFileSystem()
- .setBaseDir(basedir)
- .setSettings(settings);
+ .setBaseDir(basedir)
+ .setSettings(settings);
- assertThat(fileSystem.sourceCharset()).isEqualTo(Charset.forName("UTF-8"));
- }
+ assertThat(fileSystem.sourceCharset()).isEqualTo(Charset.forName("UTF-8"));
+ assertThat(fileSystem.isDefaultSourceCharset()).isFalse();
+ }
@Test
public void should_exclude_dirs_starting_with_dot() throws IOException {