summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-21 10:22:15 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-21 10:22:31 +0100
commit95b0c1146fbe5a5721caa5b1cc3740ff77c46ec6 (patch)
tree859c8799b9847d3d472117d7521f7dca8cf12606
parent5a4782df34c85ca03afc186a6b63f27aa4603618 (diff)
downloadsonarqube-95b0c1146fbe5a5721caa5b1cc3740ff77c46ec6.tar.gz
sonarqube-95b0c1146fbe5a5721caa5b1cc3740ff77c46ec6.zip
Improve FileSystem classes for unit tests
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java79
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java3
2 files changed, 81 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java
new file mode 100644
index 00000000000..cf87c1dfd1c
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java
@@ -0,0 +1,79 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.scan.filesystem;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.CharEncoding;
+import org.apache.commons.lang.NotImplementedException;
+import org.sonar.api.resources.InputFile;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.ProjectFileSystem;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.SonarException;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @since 3.5
+ */
+public class SimpleModuleFileSystem implements ModuleFileSystem {
+ private File baseDir;
+
+ public SimpleModuleFileSystem(File baseDir) {
+ this.baseDir = baseDir;
+ }
+
+ public File baseDir() {
+ return baseDir;
+ }
+
+ public File buildDir() {
+ return new File(baseDir, "build");
+ }
+
+ public List<File> sourceDirs() {
+ return Arrays.asList(new File(baseDir, "src"));
+ }
+
+ public List<File> testDirs() {
+ return Arrays.asList(new File(baseDir, "test"));
+ }
+
+ public List<File> binaryDirs() {
+ return Arrays.asList(new File(baseDir, "binary"));
+ }
+
+ public List<File> files(FileQuery query) {
+ return Collections.emptyList();
+ }
+
+ public Charset sourceCharset() {
+ return Charset.forName(CharEncoding.UTF_8);
+ }
+
+ public File workingDir() {
+ return new File(baseDir, "work");
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java b/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java
index 0b86e3bb661..faa990bde66 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/test/MavenTestUtils.java
@@ -33,6 +33,7 @@ import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.resources.Resource;
+import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.SonarException;
import java.io.File;
@@ -148,7 +149,7 @@ public final class MavenTestUtils {
}
public File resolvePath(String path) {
- throw new UnsupportedOperationException();
+ return new PathResolver().relativeFile(getBasedir(), path);
}
public List<File> getSourceFiles(Language... langs) {