From 95b0c1146fbe5a5721caa5b1cc3740ff77c46ec6 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 21 Feb 2013 10:22:15 +0100 Subject: [PATCH] Improve FileSystem classes for unit tests --- .../filesystem/SimpleModuleFileSystem.java | 79 +++++++++++++++++++ .../org/sonar/api/test/MavenTestUtils.java | 3 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 sonar-plugin-api/src/test/java/org/sonar/api/scan/filesystem/SimpleModuleFileSystem.java 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 sourceDirs() { + return Arrays.asList(new File(baseDir, "src")); + } + + public List testDirs() { + return Arrays.asList(new File(baseDir, "test")); + } + + public List binaryDirs() { + return Arrays.asList(new File(baseDir, "binary")); + } + + public List 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 getSourceFiles(Language... langs) { -- 2.39.5