From: Julien HENRY Date: Mon, 29 Aug 2016 15:01:13 +0000 (+0200) Subject: SONAR-7864 Drop org.sonar.api.scan.filesystem.ModuleFileSystem from API X-Git-Tag: 6.1-RC1~273 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1187%2Fhead;p=sonarqube.git SONAR-7864 Drop org.sonar.api.scan.filesystem.ModuleFileSystem from API SONAR-8038 Deprecate ProjectDefinition::getBuildDir --- diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java index 3e51d046716..ffd70020956 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/DeprecatedResourceApiSensor.java @@ -21,14 +21,14 @@ package org.sonar.xoo.rule; import java.io.File; import org.sonar.api.batch.Sensor; +import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.issue.Issuable; import org.sonar.api.resources.Directory; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; -import org.sonar.api.scan.filesystem.FileQuery; -import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.xoo.Xoo; @@ -36,26 +36,27 @@ import org.sonar.xoo.Xoo; public class DeprecatedResourceApiSensor implements Sensor { public static final String RULE_KEY = "DeprecatedResourceApi"; - private final ModuleFileSystem fileSystem; + private final FileSystem fs; private final ResourcePerspectives perspectives; private final ActiveRules activeRules; - public DeprecatedResourceApiSensor(ModuleFileSystem fileSystem, ResourcePerspectives perspectives, ActiveRules activeRules) { - this.fileSystem = fileSystem; + public DeprecatedResourceApiSensor(FileSystem fileSystem, ResourcePerspectives perspectives, ActiveRules activeRules) { + this.fs = fileSystem; this.perspectives = perspectives; this.activeRules = activeRules; } @Override public boolean shouldExecuteOnProject(Project project) { - return !fileSystem.files(FileQuery.onMain().onLanguage(Xoo.KEY)).isEmpty() && activeRules.find(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)) != null; + return fs.hasFiles(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY))) + && activeRules.find(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)) != null; } @Override public void analyse(Project module, org.sonar.api.batch.SensorContext context) { - for (File f : fileSystem.files(FileQuery.onMain().onLanguage(Xoo.KEY))) { - String relativePathFromSourceDir = new PathResolver().relativePath(fileSystem.baseDir(), f); - org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromSourceDir); + for (File f : fs.files(fs.predicates().and(fs.predicates().hasType(Type.MAIN), fs.predicates().hasLanguage(Xoo.KEY)))) { + String relativePathFromBaseDir = new PathResolver().relativePath(fs.baseDir(), f); + org.sonar.api.resources.File sonarFile = org.sonar.api.resources.File.create(relativePathFromBaseDir); Issuable issuable = perspectives.as(Issuable.class, sonarFile); issuable.addIssue(issuable.newIssueBuilder() .ruleKey(RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY)) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java index 2e5b8ec608c..4c08735f062 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java @@ -83,11 +83,19 @@ public class ProjectDefinition { return workDir; } + /** + * @deprecated since 6.1 notion of buildDir is not well defined + */ + @Deprecated public ProjectDefinition setBuildDir(File d) { this.buildDir = d; return this; } + /** + * @deprecated since 6.1 notion of buildDir is not well defined + */ + @Deprecated public File getBuildDir() { return buildDir; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileQuery.java deleted file mode 100644 index 0a28f44a3f4..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileQuery.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.scan.filesystem; - -import com.google.common.base.Function; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Collections2; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Sets; -import org.apache.commons.lang.builder.EqualsBuilder; - -import javax.annotation.Nullable; - -import java.io.FileFilter; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -/** - * @since 3.5 - * @deprecated in 4.2. Replaced by {@link org.sonar.api.batch.fs.FileSystem} and - * {@link org.sonar.api.batch.fs.FilePredicate} - */ -@Deprecated -public class FileQuery { - - private final ListMultimap attributes = ArrayListMultimap.create(); - private final Set inclusions = Sets.newHashSet(); - private final Set exclusions = Sets.newHashSet(); - - public static FileQuery on(FileType... types) { - FileQuery query = new FileQuery(); - for (FileType type : types) { - query.on("TYPE", type.typeValue()); - } - return query; - } - - public static FileQuery onSource() { - return onMain(); - } - - /** - * @since 4.2 - */ - public static FileQuery onMain() { - FileQuery query = new FileQuery(); - return query.on("TYPE", "MAIN"); - } - - public static FileQuery onTest() { - FileQuery query = new FileQuery(); - return query.on("TYPE", "TEST"); - } - - private FileQuery() { - } - - public FileQuery on(String attribute, String... values) { - for (String value : values) { - attributes.put(attribute, value); - } - return this; - } - - public Map> attributes() { - return attributes.asMap(); - } - - public Collection types() { - return Collections2.transform(attributes.get("TYPE"), new Function() { - @Override - public FileType apply(@Nullable String input) { - return input != null ? FileType.valueOf(input) : null; - } - }); - } - - public Collection typeAttributes() { - return attributes.get("TYPE"); - } - - public Collection languages() { - return attributes.get("LANG"); - } - - public FileQuery onLanguage(String... languages) { - return on("LANG", languages); - } - - public Collection inclusions() { - return inclusions; - } - - public FileQuery withInclusions(String... inclusions) { - this.inclusions.addAll(Arrays.asList(inclusions)); - return this; - } - - public Collection exclusions() { - return exclusions; - } - - public FileQuery withExclusions(String... exclusions) { - this.exclusions.addAll(Arrays.asList(exclusions)); - return this; - } - - public Collection filters() { - throw new UnsupportedOperationException("TODO"); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj == this) { - return true; - } - if (obj.getClass() != getClass()) { - return false; - } - FileQuery rhs = (FileQuery) obj; - return new EqualsBuilder() - .append(attributes, rhs.attributes) - .append(exclusions, rhs.exclusions) - .append(inclusions, rhs.inclusions) - .isEquals(); - } - -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java deleted file mode 100644 index 0a4a43483b6..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileSystemFilter.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.scan.filesystem; - -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.ExtensionPoint; -import org.sonar.api.batch.fs.InputFileFilter; - -import java.io.File; - -/** - * Extension point to exclude some files from project scan. Some use-cases : - *
    - *
  • exclude the files that are older than x days
  • - *
  • exclude the files which names start with Generated
  • - *
- * - * @since 3.5 - * @deprecated since 4.2 use {@link InputFileFilter} - */ -@Deprecated -@ScannerSide -@ExtensionPoint -public interface FileSystemFilter { - - /** - * Plugins must not implement this interface. It is provided at runtime. - */ - interface Context { - ModuleFileSystem fileSystem(); - - FileType type(); - - /** - * Changed in 5.1 as we don't keep track of relative path to source dir - * File path relative to module base directory. Never return null. - */ - String relativePath(); - - /** - * Absolute file path. Directory separator is slash, even on windows. Never return null. - */ - String canonicalPath(); - } - - boolean accept(File file, Context context); -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileType.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileType.java deleted file mode 100644 index e2221a51497..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/FileType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.scan.filesystem; - -/** - * @since 3.5 - * @deprecated in 4.2 - */ -@Deprecated -public enum FileType { - SOURCE("MAIN"), TEST("TEST"), MAIN("MAIN"); - - private String typeValue; - - FileType(String typeValue) { - this.typeValue = typeValue; - } - - public String typeValue() { - return typeValue; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java deleted file mode 100644 index a35ad1e8a5b..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.api.scan.filesystem; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; - -/** - * @since 3.5 - * @deprecated in 4.2. Replaced by {@link org.sonar.api.batch.fs.FileSystem} - */ -@Deprecated -@ScannerSide -public interface ModuleFileSystem { - - /** - * Base directory. - */ - File baseDir(); - - /** - * Optional directory used by the build tool to generate various kinds of data (test reports, temp files, ...). - * In Maven, it's given by the property ${project.build.directory}, which value is generally ${project.basedir}/target. - */ - @CheckForNull - File buildDir(); - - /** - * Source directories. - * @deprecated since 4.2 use {@link FileSystem#files(org.sonar.api.batch.fs.FilePredicate)} to get all files with type {@link InputFile.Type#MAIN}. - */ - List sourceDirs(); - - /** - * Test directories. Non-existing directories are excluded. - * Example in Maven : ${project.basedir}/src/test/java - * @deprecated since 4.2 use {@link FileSystem#files(org.sonar.api.batch.fs.FilePredicate)} to get all files with type {@link InputFile.Type#TEST}. - */ - List testDirs(); - - /** - * Optional directories that contain the compiled sources, for example java bytecode. - * Note that : - *
    - *
  • Maven projects have only a single binary directory, which is generally ${project.basedir}/target/classes
  • - *
  • Binary directories can be empty
  • - *
  • Test binary directories are not supported yet.
  • - *
- * @deprecated since 4.2 sonar.binaries will be converted to java specific property - */ - List binaryDirs(); - - /** - * Search for files. Never return null. - */ - List files(FileQuery query); - - /** - * Default charset for files of the module. If it's not defined, then - * return the platform default charset. - */ - Charset sourceCharset(); - - /** - * Working directory used by Sonar. This directory can be used for example to - * store intermediary reports. - */ - File workingDir(); -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java index 0a2148c762d..72f95401c53 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleScanContainer.java @@ -61,7 +61,6 @@ import org.sonar.scanner.rule.RuleFinderCompatibility; import org.sonar.scanner.rule.RulesProfileProvider; import org.sonar.scanner.scan.filesystem.ComponentIndexer; import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.scanner.scan.filesystem.DeprecatedFileFilters; import org.sonar.scanner.scan.filesystem.ExclusionFilters; import org.sonar.scanner.scan.filesystem.FileIndexer; import org.sonar.scanner.scan.filesystem.FileSystemLogger; @@ -123,7 +122,6 @@ public class ModuleScanContainer extends ComponentContainer { ModuleInputFileCache.class, FileExclusions.class, ExclusionFilters.class, - DeprecatedFileFilters.class, InputFileBuilderFactory.class, FileMetadata.class, StatusDetectionFactory.class, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java index 1f6738d716f..053e735ad01 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java @@ -70,6 +70,10 @@ public class ProjectReactorBuilder { private static final String MODULE_KEY_PROPERTY = "sonar.moduleKey"; protected static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir"; + /** + * @deprecated since 6.1 notion of buildDir is not well defined + */ + @Deprecated private static final String PROPERTY_PROJECT_BUILDDIR = "sonar.projectBuildDir"; private static final String PROPERTY_MODULES = "sonar.modules"; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java index cc1fa238669..5b1e1844d0b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystem.java @@ -20,41 +20,28 @@ package org.sonar.scanner.scan.filesystem; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import java.io.File; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; -import java.util.Map; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.InputFile.Status; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.config.Settings; import org.sonar.api.resources.Project; -import org.sonar.api.scan.filesystem.FileQuery; -import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.utils.MessageException; import org.sonar.scanner.analysis.DefaultAnalysisMode; /** * @since 3.5 */ -public class DefaultModuleFileSystem extends DefaultFileSystem implements ModuleFileSystem { +public class DefaultModuleFileSystem extends DefaultFileSystem { private String moduleKey; private FileIndexer indexer; private Settings settings; - private File buildDir; private List sourceDirsOrFiles = Lists.newArrayList(); private List testDirsOrFiles = Lists.newArrayList(); private ComponentIndexer componentIndexer; @@ -80,7 +67,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module this.settings = settings; this.indexer = indexer; setWorkDir(initializer.workingDir()); - this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); @@ -98,45 +84,14 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module return moduleKey; } - @Override - @CheckForNull - public File buildDir() { - return buildDir; - } - - @Override - public List sourceDirs() { - return keepOnlyDirs(sourceDirsOrFiles); - } - public List sources() { return sourceDirsOrFiles; } - @Override - public List testDirs() { - return keepOnlyDirs(testDirsOrFiles); - } - public List tests() { return testDirsOrFiles; } - private static List keepOnlyDirs(List dirsOrFiles) { - List result = new ArrayList<>(); - for (File f : dirsOrFiles) { - if (f.isDirectory()) { - result.add(f); - } - } - return result; - } - - @Override - public List binaryDirs() { - return Collections.emptyList(); - } - @Override public Charset encoding() { final Charset charset; @@ -154,59 +109,10 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module return !settings.hasKey(CoreProperties.ENCODING_PROPERTY); } - /** - * Should not be used - only for old plugins - * - * @deprecated since 4.0 - */ - @Deprecated - void addSourceDir(File dir) { - throw modificationNotPermitted(); - } - - /** - * Should not be used - only for old plugins - * - * @deprecated since 4.0 - */ - @Deprecated - void addTestDir(File dir) { - throw modificationNotPermitted(); - } - private static UnsupportedOperationException modificationNotPermitted() { return new UnsupportedOperationException("Modifications of the file system are not permitted"); } - /** - * @return - * @deprecated in 4.2. Replaced by {@link #encoding()} - */ - @Override - @Deprecated - public Charset sourceCharset() { - return encoding(); - } - - /** - * @deprecated in 4.2. Replaced by {@link #workDir()} - */ - @Deprecated - @Override - public File workingDir() { - return workDir(); - } - - @Override - public List files(FileQuery query) { - doPreloadFiles(); - Collection predicates = Lists.newArrayList(); - for (Map.Entry> entry : query.attributes().entrySet()) { - predicates.add(fromDeprecatedAttribute(entry.getKey(), entry.getValue())); - } - return ImmutableList.copyOf(files(predicates().and(predicates))); - } - @Override protected void doPreloadFiles() { if (!initialized) { @@ -225,42 +131,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module } } - private FilePredicate fromDeprecatedAttribute(String key, Collection value) { - if ("TYPE".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasType(org.sonar.api.batch.fs.InputFile.Type.valueOf(s)); - } - })); - } - if ("STATUS".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasStatus(org.sonar.api.batch.fs.InputFile.Status.valueOf(s)); - } - })); - } - if ("LANG".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : predicates().hasLanguage(s); - } - })); - } - if ("CMP_KEY".equals(key)) { - return predicates().or(Collections2.transform(value, new Function() { - @Override - public FilePredicate apply(@Nullable String s) { - return s == null ? predicates().all() : new AdditionalFilePredicates.KeyPredicate(s); - } - })); - } - throw new IllegalArgumentException("Unsupported file attribute: " + key); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFilters.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFilters.java deleted file mode 100644 index b32ecb5d98a..00000000000 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFilters.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.scanner.scan.filesystem; - -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFileFilter; -import org.sonar.api.scan.filesystem.FileSystemFilter; -import org.sonar.api.scan.filesystem.FileType; -import org.sonar.api.scan.filesystem.ModuleFileSystem; - -public class DeprecatedFileFilters implements InputFileFilter { - private final FileSystemFilter[] filters; - - public DeprecatedFileFilters(FileSystemFilter[] filters) { - this.filters = filters; - } - - public DeprecatedFileFilters() { - this(new FileSystemFilter[0]); - } - - @Override - public boolean accept(InputFile inputFile) { - if (filters.length > 0) { - DeprecatedContext context = new DeprecatedContext(inputFile); - for (FileSystemFilter filter : filters) { - if (!filter.accept(inputFile.file(), context)) { - return false; - } - } - } - return true; - } - - static class DeprecatedContext implements FileSystemFilter.Context { - private final InputFile inputFile; - - DeprecatedContext(InputFile inputFile) { - this.inputFile = inputFile; - } - - @Override - public ModuleFileSystem fileSystem() { - throw new UnsupportedOperationException("Not supported since 4.0"); - } - - @Override - public FileType type() { - String type = inputFile.type().name(); - return FileType.valueOf(type); - } - - @Override - public String relativePath() { - return inputFile.relativePath(); - } - - @Override - public String canonicalPath() { - return inputFile.absolutePath(); - } - } -} diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index 8b21817ae2d..75c9e927cc0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -20,18 +20,6 @@ package org.sonar.scanner.scan.filesystem; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.ScannerSide; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Type; -import org.sonar.api.batch.fs.InputFileFilter; -import org.sonar.api.batch.fs.internal.DefaultInputDir; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.scan.filesystem.PathResolver; -import org.sonar.api.utils.MessageException; -import org.sonar.scanner.util.ProgressReport; import java.io.File; import java.io.IOException; import java.nio.file.FileSystemLoopException; @@ -53,6 +41,18 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sonar.api.batch.ScannerSide; +import org.sonar.api.batch.bootstrap.ProjectDefinition; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.InputFile.Type; +import org.sonar.api.batch.fs.InputFileFilter; +import org.sonar.api.batch.fs.internal.DefaultInputDir; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.scan.filesystem.PathResolver; +import org.sonar.api.utils.MessageException; +import org.sonar.scanner.util.ProgressReport; /** * Index input files into {@link InputPathCache}. @@ -61,7 +61,7 @@ import java.util.concurrent.TimeUnit; public class FileIndexer { private static final Logger LOG = LoggerFactory.getLogger(FileIndexer.class); - private final List filters; + private final InputFileFilter[] filters; private final boolean isAggregator; private final ExclusionFilters exclusionFilters; private final InputFileBuilderFactory inputFileBuilderFactory; @@ -70,14 +70,17 @@ public class FileIndexer { private ExecutorService executorService; private List> tasks; - public FileIndexer(List filters, ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory, - ProjectDefinition def) { + public FileIndexer(ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory, ProjectDefinition def, InputFileFilter[] filters) { this.filters = filters; this.exclusionFilters = exclusionFilters; this.inputFileBuilderFactory = inputFileBuilderFactory; this.isAggregator = !def.getSubProjects().isEmpty(); } + public FileIndexer(ExclusionFilters exclusionFilters, InputFileBuilderFactory inputFileBuilderFactory, ProjectDefinition def) { + this(exclusionFilters, inputFileBuilderFactory, def, new InputFileFilter[0]); + } + void index(DefaultModuleFileSystem fileSystem) { if (isAggregator) { // No indexing for an aggregator module diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java index c6629174ef3..e0bdd64dc4b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializer.java @@ -20,17 +20,14 @@ package org.sonar.scanner.scan.filesystem; import com.google.common.collect.Lists; +import java.io.File; +import java.util.List; import org.apache.commons.io.FileUtils; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.TempFolder; -import javax.annotation.CheckForNull; - -import java.io.File; -import java.util.List; - /** * @since 3.5 */ @@ -39,13 +36,11 @@ public class ModuleFileSystemInitializer { private File baseDir; private File workingDir; - private File buildDir; private List sourceDirsOrFiles = Lists.newArrayList(); private List testDirsOrFiles = Lists.newArrayList(); public ModuleFileSystemInitializer(ProjectDefinition module, TempFolder tempUtils, PathResolver pathResolver) { baseDir = module.getBaseDir(); - buildDir = module.getBuildDir(); initWorkingDir(module, tempUtils); initSources(module, pathResolver); initTests(module, pathResolver); @@ -90,11 +85,6 @@ public class ModuleFileSystemInitializer { return workingDir; } - @CheckForNull - File buildDir() { - return buildDir; - } - List sources() { return sourceDirsOrFiles; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystemTest.java deleted file mode 100644 index b0982ee2de2..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DefaultModuleFileSystemTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.scanner.scan.filesystem; - -import com.google.common.collect.Lists; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Arrays; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.mockito.Mockito; -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputFile.Status; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.config.Settings; -import org.sonar.api.resources.Project; -import org.sonar.scanner.analysis.DefaultAnalysisMode; -import org.sonar.scanner.scan.filesystem.ComponentIndexer; -import org.sonar.scanner.scan.filesystem.DefaultModuleFileSystem; -import org.sonar.scanner.scan.filesystem.FileIndexer; -import org.sonar.scanner.scan.filesystem.ModuleFileSystemInitializer; -import org.sonar.scanner.scan.filesystem.ModuleInputFileCache; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.mockito.Mockito.when; - -public class DefaultModuleFileSystemTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Settings settings; - private FileIndexer fileIndexer; - private ModuleFileSystemInitializer initializer; - private ComponentIndexer componentIndexer; - private ModuleInputFileCache moduleInputFileCache; - private DefaultAnalysisMode mode; - - @Before - public void setUp() { - settings = new Settings(); - fileIndexer = mock(FileIndexer.class); - initializer = mock(ModuleFileSystemInitializer.class, Mockito.RETURNS_DEEP_STUBS); - componentIndexer = mock(ComponentIndexer.class); - moduleInputFileCache = mock(ModuleInputFileCache.class); - mode = mock(DefaultAnalysisMode.class); - } - - @Test - public void test_equals_and_hashCode() throws Exception { - DefaultModuleFileSystem foo1 = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - DefaultModuleFileSystem foo2 = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - DefaultModuleFileSystem bar = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("bar"), settings, fileIndexer, initializer, componentIndexer, mode); - DefaultModuleFileSystem branch = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("bar", "branch", "My project"), settings, fileIndexer, initializer, componentIndexer, mode); - - assertThat(foo1.moduleKey()).isEqualTo("foo"); - assertThat(branch.moduleKey()).isEqualTo("bar:branch"); - assertThat(foo1.equals(foo1)).isTrue(); - assertThat(foo1.equals(foo2)).isTrue(); - assertThat(foo1.equals(bar)).isFalse(); - assertThat(foo1.equals("foo")).isFalse(); - assertThat(foo1.hashCode()).isEqualTo(foo1.hashCode()); - assertThat(foo1.hashCode()).isEqualTo(foo2.hashCode()); - } - - @Test - public void default_source_encoding() { - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - assertThat(fs.sourceCharset()).isEqualTo(Charset.defaultCharset()); - assertThat(fs.isDefaultJvmEncoding()).isTrue(); - } - - @Test - public void source_encoding_is_set() { - settings.setProperty(CoreProperties.ENCODING_PROPERTY, "Cp1124"); - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - assertThat(fs.encoding()).isEqualTo(Charset.forName("Cp1124")); - assertThat(fs.sourceCharset()).isEqualTo(Charset.forName("Cp1124")); - - // This test fails when default Java encoding is "IBM AIX Ukraine". Sorry for that. - assertThat(fs.isDefaultJvmEncoding()).isFalse(); - } - - @Test - public void default_predicate_scan_only_changed() throws IOException { - when(mode.scanAllFiles()).thenReturn(false); - - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - File baseDir = temp.newFile(); - InputFile mainInput = new DefaultInputFile("foo", "Main.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.MAIN); - InputFile testInput = new DefaultInputFile("foo", "Test.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.TEST); - InputFile mainSameInput = new DefaultInputFile("foo", "MainSame.java").setModuleBaseDir(baseDir.toPath()) - .setType(InputFile.Type.TEST).setStatus(Status.SAME); - when(moduleInputFileCache.inputFiles()).thenReturn(Lists.newArrayList(mainInput, testInput, mainSameInput)); - - fs.index(); - Iterable inputFiles = fs.inputFiles(fs.predicates().all()); - assertThat(inputFiles).containsOnly(mainInput, testInput); - - Iterable allInputFiles = fs.inputFiles(); - assertThat(allInputFiles).containsOnly(mainInput, mainSameInput, testInput); - } - - @Test - public void test_dirs() throws IOException { - File basedir = temp.newFolder("base"); - File buildDir = temp.newFolder("build"); - File workingDir = temp.newFolder("work"); - File additionalFile = temp.newFile("Main.java"); - File additionalTest = temp.newFile("Test.java"); - when(initializer.baseDir()).thenReturn(basedir); - when(initializer.buildDir()).thenReturn(buildDir); - when(initializer.workingDir()).thenReturn(workingDir); - File javaSrc = new File(basedir, "src/main/java"); - javaSrc.mkdirs(); - File groovySrc = new File(basedir, "src/main/groovy"); - groovySrc.mkdirs(); - when(initializer.sources()).thenReturn(Arrays.asList(javaSrc, groovySrc, additionalFile)); - File javaTest = new File(basedir, "src/test/java"); - javaTest.mkdirs(); - when(initializer.tests()).thenReturn(Arrays.asList(javaTest, additionalTest)); - - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(basedir.getCanonicalPath()); - assertThat(fs.workDir().getCanonicalPath()).isEqualTo(workingDir.getCanonicalPath()); - assertThat(fs.buildDir().getCanonicalPath()).isEqualTo(buildDir.getCanonicalPath()); - assertThat(fs.sourceDirs()).hasSize(2); - assertThat(fs.testDirs()).hasSize(1); - } - - @Test - public void should_search_input_files() throws Exception { - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - File baseDir = temp.newFile(); - InputFile mainInput = new DefaultInputFile("foo", "Main.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.MAIN); - InputFile testInput = new DefaultInputFile("foo", "Test.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.TEST); - when(moduleInputFileCache.inputFiles()).thenReturn(Lists.newArrayList(mainInput, testInput)); - - fs.index(); - Iterable inputFiles = fs.inputFiles(fs.predicates().hasType(InputFile.Type.MAIN)); - assertThat(inputFiles).containsOnly(mainInput); - - Iterable files = fs.files(fs.predicates().hasType(InputFile.Type.MAIN)); - assertThat(files).containsOnly(new File(baseDir, "Main.java")); - } - - @Test - public void should_index() { - DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, - new Project("foo"), settings, fileIndexer, initializer, componentIndexer, mode); - - verifyZeroInteractions(fileIndexer); - - fs.index(); - verify(fileIndexer).index(fs); - verify(componentIndexer).execute(fs); - } - -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFiltersTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFiltersTest.java deleted file mode 100644 index 1108e0732ba..00000000000 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/DeprecatedFileFiltersTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.scanner.scan.filesystem; - -import org.apache.commons.io.FilenameUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.mockito.ArgumentCaptor; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.scan.filesystem.FileSystemFilter; -import org.sonar.api.scan.filesystem.FileType; -import org.sonar.scanner.scan.filesystem.DeprecatedFileFilters; -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class DeprecatedFileFiltersTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - FileSystemFilter filter = mock(FileSystemFilter.class); - - @Test - public void no_filters() { - DeprecatedFileFilters filters = new DeprecatedFileFilters(); - - InputFile inputFile = new DefaultInputFile("foo", "src/main/java/Foo.java"); - assertThat(filters.accept(inputFile)).isTrue(); - } - - @Test - public void at_least_one_filter() throws Exception { - DeprecatedFileFilters filters = new DeprecatedFileFilters(new FileSystemFilter[] {filter}); - - File basedir = temp.newFolder(); - File file = new File(basedir, "src/main/java/Foo.java"); - InputFile inputFile = new DefaultInputFile("foo", "src/main/java/Foo.java") - .setModuleBaseDir(basedir.toPath()) - .setType(InputFile.Type.MAIN); - when(filter.accept(eq(file), any(DeprecatedFileFilters.DeprecatedContext.class))).thenReturn(false); - - assertThat(filters.accept(inputFile)).isFalse(); - - ArgumentCaptor argument = ArgumentCaptor.forClass(DeprecatedFileFilters.DeprecatedContext.class); - verify(filter).accept(eq(file), argument.capture()); - - DeprecatedFileFilters.DeprecatedContext context = argument.getValue(); - assertThat(context.canonicalPath()).isEqualTo(FilenameUtils.separatorsToUnix(file.getAbsolutePath())); - assertThat(context.relativePath()).isEqualTo("src/main/java/Foo.java"); - assertThat(context.type()).isEqualTo(FileType.MAIN); - } -} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializerTest.java index 9be5891960f..7ee6ccba43e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/ModuleFileSystemInitializerTest.java @@ -19,6 +19,8 @@ */ package org.sonar.scanner.scan.filesystem; +import java.io.File; +import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.junit.Rule; @@ -27,9 +29,6 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.utils.TempFolder; -import org.sonar.scanner.scan.filesystem.ModuleFileSystemInitializer; -import java.io.File; -import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -58,7 +57,6 @@ public class ModuleFileSystemInitializerTest { @Test public void should_init_directories() throws IOException { File baseDir = temp.newFolder("base"); - File buildDir = temp.newFolder("build"); File sourceDir = new File(baseDir, "src/main/java"); FileUtils.forceMkdir(sourceDir); File testDir = new File(baseDir, "src/test/java"); @@ -68,14 +66,12 @@ public class ModuleFileSystemInitializerTest { ProjectDefinition project = ProjectDefinition.create() .setBaseDir(baseDir) - .setBuildDir(buildDir) .addSources("src/main/java", "src/main/unknown") .addTests("src/test/java", "src/test/unknown"); ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(project, mock(TempFolder.class), pathResolver); assertThat(initializer.baseDir().getCanonicalPath()).isEqualTo(baseDir.getCanonicalPath()); - assertThat(initializer.buildDir().getCanonicalPath()).isEqualTo(buildDir.getCanonicalPath()); assertThat(initializer.sources()).hasSize(1); assertThat(path(initializer.sources().get(0))).endsWith("src/main/java"); assertThat(initializer.tests()).hasSize(1);