diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-04 21:15:35 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-11-05 09:34:47 +0100 |
commit | e7885c175b5e078bd93a58650d99a32224b3679b (patch) | |
tree | cd238ec9eb4c74bcc915b200815c11fff69f6bf0 /sonar-batch/src/main | |
parent | e2379a7ffa7e879ededf5f160f55eba26a785a6c (diff) | |
download | sonarqube-e7885c175b5e078bd93a58650d99a32224b3679b.tar.gz sonarqube-e7885c175b5e078bd93a58650d99a32224b3679b.zip |
SONAR-6658 Remove ProjectClasspath, ProjectFileSystem, sonar.binaries, sonar.libraries
Diffstat (limited to 'sonar-batch/src/main')
4 files changed, 12 insertions, 305 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 92cf55036ed..89d6beb5f48 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -60,16 +60,18 @@ public class DefaultIndex extends SonarIndex { private final BatchComponentCache componentCache; private final MeasureCache measureCache; - private DefaultSensorStorage sensorStorage; + private final PathResolver pathResolver; + private final DefaultProjectTree projectTree; // caches + private DefaultSensorStorage sensorStorage; private Project currentProject; private Map<Resource, Bucket> buckets = Maps.newLinkedHashMap(); - private DefaultProjectTree projectTree; - public DefaultIndex(BatchComponentCache componentCache, DefaultProjectTree projectTree, MeasureCache measureCache) { + public DefaultIndex(BatchComponentCache componentCache, DefaultProjectTree projectTree, MeasureCache measureCache, PathResolver pathResolver) { this.componentCache = componentCache; this.projectTree = projectTree; this.measureCache = measureCache; + this.pathResolver = pathResolver; } public void start() { @@ -329,14 +331,16 @@ public class DefaultIndex extends SonarIndex { } if (relativePathFromSourceDir != null) { // Resolve using deprecated key - List<java.io.File> dirs; + List<String> dirs; + ProjectDefinition projectDef = projectTree.getProjectDefinition(getProject()); if (isTest) { - dirs = getProject().getFileSystem().getTestDirs(); + dirs = projectDef.getTestDirs(); } else { - dirs = getProject().getFileSystem().getSourceDirs(); + dirs = projectDef.getSourceDirs(); } - for (java.io.File src : dirs) { - java.io.File abs = new java.io.File(src, relativePathFromSourceDir); + for (String src : dirs) { + java.io.File dirOrFile = pathResolver.relativeFile(projectDef.getBaseDir(), src); + java.io.File abs = new java.io.File(dirOrFile, relativePathFromSourceDir); Bucket b = getBucket(isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject())); if (b != null) { return b; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index baa19bd268a..eeab1e08c2f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -22,7 +22,6 @@ package org.sonar.batch.scan; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.ProjectClasspath; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.rule.CheckFactory; @@ -68,7 +67,6 @@ import org.sonar.batch.scan.filesystem.InputFileBuilderFactory; import org.sonar.batch.scan.filesystem.LanguageDetectionFactory; import org.sonar.batch.scan.filesystem.ModuleFileSystemInitializer; import org.sonar.batch.scan.filesystem.ModuleInputFileCache; -import org.sonar.batch.scan.filesystem.ProjectFileSystemAdapter; import org.sonar.batch.scan.filesystem.StatusDetectionFactory; import org.sonar.batch.scan.report.IssuesReports; import org.sonar.batch.sensor.DefaultSensorContext; @@ -131,8 +129,6 @@ public class ModuleScanContainer extends ComponentContainer { FileSystemLogger.class, DefaultModuleFileSystem.class, ModuleFileSystemInitializer.class, - ProjectFileSystemAdapter.class, - ProjectClasspath.class, QProfileVerifier.class, SensorOptimizer.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index 7a2b7dba935..4e24730a816 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -23,10 +23,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import java.io.File; -import java.io.FileFilter; import java.io.IOException; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; @@ -35,10 +33,6 @@ import java.util.Map; import java.util.Map.Entry; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.apache.commons.io.filefilter.AndFileFilter; -import org.apache.commons.io.filefilter.FileFileFilter; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; @@ -85,8 +79,6 @@ public class ProjectReactorBuilder { */ private static final String PROPERTY_SOURCES = "sonar.sources"; private static final String PROPERTY_TESTS = "sonar.tests"; - private static final String PROPERTY_BINARIES = "sonar.binaries"; - private static final String PROPERTY_LIBRARIES = "sonar.libraries"; /** * Array of all mandatory properties required for a project without child. @@ -336,22 +328,9 @@ public class ProjectReactorBuilder { if (!props.containsKey(PROPERTY_MODULES)) { // SONARPLUGINS-2285 Not an aggregator project so we can validate that paths are correct if defined - // We need to resolve patterns that may have been used in "sonar.libraries" - for (String pattern : getListFromProperty(props, PROPERTY_LIBRARIES)) { - File[] files = getLibraries(baseDir, pattern); - if (files == null || files.length == 0) { - LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, PROPERTY_LIBRARIES, projectId)); - throw new IllegalStateException("No files nor directories matching '" + pattern + "' in directory " + baseDir); - } - } - // Check sonar.tests String[] testPaths = getListFromProperty(props, PROPERTY_TESTS); checkExistenceOfPaths(projectId, baseDir, testPaths, PROPERTY_TESTS); - - // Check sonar.binaries - String[] binDirs = getListFromProperty(props, PROPERTY_BINARIES); - checkExistenceOfDirectories(projectId, baseDir, binDirs, PROPERTY_BINARIES); } } @@ -376,16 +355,6 @@ public class ProjectReactorBuilder { // We need to check the existence of source directories String[] sourcePaths = getListFromProperty(properties, PROPERTY_SOURCES); checkExistenceOfPaths(project.getKey(), project.getBaseDir(), sourcePaths, PROPERTY_SOURCES); - - // And we need to resolve patterns that may have been used in "sonar.libraries" - List<String> libPaths = Lists.newArrayList(); - for (String pattern : getListFromProperty(properties, PROPERTY_LIBRARIES)) { - for (File file : getLibraries(project.getBaseDir(), pattern)) { - libPaths.add(file.getAbsolutePath()); - } - } - properties.remove(PROPERTY_LIBRARIES); - properties.put(PROPERTY_LIBRARIES, StringUtils.join(libPaths, ",")); } @VisibleForTesting @@ -406,8 +375,6 @@ public class ProjectReactorBuilder { // "aggregator" project must not have the following properties: properties.remove(PROPERTY_SOURCES); properties.remove(PROPERTY_TESTS); - properties.remove(PROPERTY_BINARIES); - properties.remove(PROPERTY_LIBRARIES); } @VisibleForTesting @@ -422,19 +389,6 @@ public class ProjectReactorBuilder { } @VisibleForTesting - protected static void checkExistenceOfDirectories(String moduleRef, File baseDir, String[] dirPaths, String propName) { - for (String path : dirPaths) { - File sourceFolder = resolvePath(baseDir, path); - if (!sourceFolder.isDirectory()) { - LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, propName, moduleRef)); - throw new IllegalStateException("The folder '" + path + "' does not exist for '" + moduleRef + - "' (base directory = " + baseDir.getAbsolutePath() + ")"); - } - } - - } - - @VisibleForTesting protected static void checkExistenceOfPaths(String moduleRef, File baseDir, String[] paths, String propName) { for (String path : paths) { File sourceFolder = resolvePath(baseDir, path); @@ -447,34 +401,6 @@ public class ProjectReactorBuilder { } - /** - * Returns files matching specified pattern. - */ - @VisibleForTesting - protected static File[] getLibraries(File baseDir, String pattern) { - final int i = Math.max(pattern.lastIndexOf('/'), pattern.lastIndexOf('\\')); - final String dirPath; - final String filePattern; - if (i == -1) { - dirPath = "."; - filePattern = pattern; - } else { - dirPath = pattern.substring(0, i); - filePattern = pattern.substring(i + 1); - } - List<IOFileFilter> filters = new ArrayList<>(); - if (pattern.indexOf('*') >= 0) { - filters.add(FileFileFilter.FILE); - } - filters.add(new WildcardFileFilter(filePattern)); - File dir = resolvePath(baseDir, dirPath); - File[] files = dir.listFiles((FileFilter) new AndFileFilter(filters)); - if (files == null) { - files = new File[0]; - } - return files; - } - protected static File resolvePath(File baseDir, String path) { File file = new File(path); if (!file.isAbsolute()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java deleted file mode 100644 index 20390af7c84..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.batch.scan.filesystem; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.CharEncoding; -import org.sonar.api.batch.fs.FilePredicate; -import org.sonar.api.resources.InputFile; -import org.sonar.api.resources.Java; -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; - -/** - * Adapter for keeping the backward-compatibility of the deprecated component {@link org.sonar.api.resources.ProjectFileSystem} - * - * @since 3.5 - */ -public class ProjectFileSystemAdapter implements ProjectFileSystem { - - private final DefaultModuleFileSystem target; - private final PathResolver pathResolver = new PathResolver(); - - public ProjectFileSystemAdapter(DefaultModuleFileSystem target, Project project) { - this.target = target; - - // previously MavenProjectBuilder was responsible for creation of ProjectFileSystem - project.setFileSystem(this); - } - - public void start() { - // used to avoid NPE in Project#getFileSystem() - } - - @Override - public Charset getSourceCharset() { - return target.sourceCharset(); - } - - @Override - public File getBasedir() { - return target.baseDir(); - } - - @Override - public File getBuildDir() { - File dir = target.buildDir(); - if (dir == null) { - // emulate build dir to keep backward-compatibility - dir = new File(getSonarWorkingDirectory(), "build"); - } - return dir; - } - - @Override - public File getBuildOutputDir() { - File dir = Iterables.getFirst(target.binaryDirs(), null); - if (dir == null) { - // emulate binary dir - dir = new File(getBuildDir(), "classes"); - } - - return dir; - } - - @Override - public List<File> getSourceDirs() { - return target.sourceDirs(); - } - - @Override - public ProjectFileSystem addSourceDir(File dir) { - target.addSourceDir(dir); - return this; - } - - @Override - public List<File> getTestDirs() { - return target.testDirs(); - } - - @Override - public ProjectFileSystem addTestDir(File dir) { - target.addTestDir(dir); - return this; - } - - @Override - public File getReportOutputDir() { - // emulate Maven report output dir - return new File(getBuildDir(), "site"); - } - - @Override - public File getSonarWorkingDirectory() { - return target.workDir(); - } - - @Override - public File resolvePath(String path) { - File file = new File(path); - if (!file.isAbsolute()) { - try { - file = new File(getBasedir(), path).getCanonicalFile(); - } catch (IOException e) { - throw new SonarException("Unable to resolve path '" + path + "'", e); - } - } - return file; - } - - @Override - public List<File> getSourceFiles(Language... langs) { - return Lists.newArrayList(target.files(target.predicates().and( - target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.MAIN), - newHasLanguagesPredicate(langs)))); - } - - @Override - public List<File> getJavaSourceFiles() { - return getSourceFiles(Java.INSTANCE); - } - - @Override - public boolean hasJavaSourceFiles() { - return !getJavaSourceFiles().isEmpty(); - } - - @Override - public List<File> getTestFiles(Language... langs) { - return Lists.newArrayList(target.files(target.predicates().and( - target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.TEST), - newHasLanguagesPredicate(langs)))); - } - - @Override - public boolean hasTestFiles(Language lang) { - return target.hasFiles(target.predicates().and( - target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.TEST), - target.predicates().hasLanguage(lang.getKey()))); - } - - @Override - public File writeToWorkingDirectory(String content, String fileName) throws IOException { - File file = new File(target.workDir(), fileName); - FileUtils.writeStringToFile(file, content, CharEncoding.UTF_8); - return file; - } - - @Override - public File getFileFromBuildDirectory(String filename) { - File file = new File(getBuildDir(), filename); - return file.exists() ? file : null; - } - - @Override - public Resource toResource(File file) { - if (file == null || !file.exists()) { - return null; - } - String relativePath = pathResolver.relativePath(getBasedir(), file); - if (relativePath == null) { - return null; - } - return file.isFile() ? org.sonar.api.resources.File.create(relativePath) : org.sonar.api.resources.Directory.create(relativePath); - } - - @Override - public List<InputFile> mainFiles(String... langs) { - return Lists.newArrayList((Iterable) target.inputFiles(target.predicates().and( - target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.MAIN), - target.predicates().hasLanguages(Arrays.asList(langs)) - ))); - - } - - @Override - public List<InputFile> testFiles(String... langs) { - return Lists.newArrayList((Iterable) target.inputFiles(target.predicates().and( - target.predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.TEST), - target.predicates().hasLanguages(Arrays.asList(langs)) - ))); - } - - private FilePredicate newHasLanguagesPredicate(Language... languages) { - List<FilePredicate> list = Lists.newArrayList(); - for (Language language : languages) { - list.add(target.predicates().hasLanguage(language.getKey())); - } - return target.predicates().or(list); - } -} |