private final FakeSonarRuntime sonarRuntime = new FakeSonarRuntime();
private final CeTaskReportDataHolder reportMetadataHolder = new CeTaskReportDataHolderExt();
private final FakeLanguagesLoader languagesLoader = new FakeLanguagesLoader();
+ private final FakeLanguagesProvider languagesProvider = new FakeLanguagesProvider();
private LogOutput logOutput = null;
private static void createWorkingDirs() throws IOException {
public void addLanguage(String key, String name, String... suffixes) {
languagesLoader.addLanguage(key, name, suffixes, new String[0]);
+ languagesProvider.addLanguage(key, name, true);
}
public void addLanguage(String key, String name, boolean publishAllFiles, String... suffixes) {
- languagesLoader.addLanguage(key, name, suffixes, new String[0], publishAllFiles);
+ languagesLoader.addLanguage(key, name, suffixes, new String[0]);
+ languagesProvider.addLanguage(key, name, publishAllFiles);
}
public static class AnalysisBuilder {
tester.sonarRuntime,
tester.reportMetadataHolder,
tester.languagesLoader,
+ tester.languagesProvider,
result);
if (tester.logOutput != null) {
builder.setLogOutput(tester.logOutput);
private final Map<String, Language> languageMap = new HashMap<>();
public FakeLanguagesLoader() {
- languageMap.put("xoo", new Language(new FakeLanguage("xoo", "xoo", new String[] { ".xoo" }, new String[0], true)));
+ languageMap.put("xoo", new Language(new SupportedLanguageDto("xoo", "xoo", new String[] { ".xoo" }, new String[0])));
}
public FakeLanguagesLoader(Languages languages) {
for (org.sonar.api.resources.Language language : languages.all()) {
- languageMap.put(language.getKey(), new Language(new FakeLanguage(language.getKey(), language.getName(), language.getFileSuffixes(), language.filenamePatterns(), true)));
+ languageMap.put(language.getKey(), new Language(new SupportedLanguageDto(language.getKey(), language.getName(), language.getFileSuffixes(), language.filenamePatterns())));
}
}
@Override
}
public void addLanguage(String key, String name, String[] suffixes, String[] filenamePatterns) {
- languageMap.put(key, new Language(new FakeLanguage(key, name, suffixes, filenamePatterns, true)));
+ languageMap.put(key, new Language(new SupportedLanguageDto(key, name, suffixes, filenamePatterns)));
}
- public void addLanguage(String key, String name, String[] suffixes, String[] filenamePatterns, boolean publishAllFiles) {
- languageMap.put(key, new Language(new FakeLanguage(key, name, suffixes, filenamePatterns, publishAllFiles)));
- }
-
- private static class FakeLanguage extends SupportedLanguageDto {
-
- private final boolean publishAllFiles;
-
- public FakeLanguage(String key, String name, String[] fileSuffixes, String[] filenamePatterns, boolean publishAllFiles) {
- super(key, name, fileSuffixes, filenamePatterns);
- this.publishAllFiles = publishAllFiles;
- }
-
- @Override
- public boolean publishAllFiles() {
- return publishAllFiles;
- }
- }
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info 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.mediumtest;
+
+import javax.annotation.Priority;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Languages;
+import org.springframework.context.annotation.Bean;
+
+@Priority(1)
+public class FakeLanguagesProvider {
+
+ private Languages languages = new Languages();
+
+ @Bean("Languages")
+ public Languages provide() {
+ return this.languages;
+ }
+
+ public void addLanguage(String key, String name, boolean publishAllFiles) {
+ this.languages.add(new FakeLanguage(key, name, publishAllFiles));
+ }
+
+ private static class FakeLanguage implements Language {
+
+ private final String name;
+ private final String key;
+ private final boolean publishAllFiles;
+
+ public FakeLanguage(String key, String name, boolean publishAllFiles) {
+ this.name = name;
+ this.key = key;
+ this.publishAllFiles = publishAllFiles;
+ }
+
+ @Override
+ public String getKey() {
+ return this.key;
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String[] getFileSuffixes() {
+ return new String[0];
+ }
+
+ @Override
+ public boolean publishAllFiles() {
+ return this.publishAllFiles;
+ }
+ }
+
+
+}
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.DefaultInputProject;
import org.sonar.api.batch.fs.internal.SensorStrategy;
+import org.sonar.api.resources.Languages;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
import org.sonar.scanner.repository.language.Language;
private final LanguageDetection langDetection;
private final StatusDetection statusDetection;
private final ScmChangedFiles scmChangedFiles;
-
private final ModuleRelativePathWarner moduleRelativePathWarner;
private final InputFileFilterRepository inputFileFilterRepository;
+ private final Languages languages;
public FileIndexer(DefaultInputProject project, ScannerComponentIdGenerator scannerComponentIdGenerator, InputComponentStore componentStore,
ProjectCoverageAndDuplicationExclusions projectCoverageAndDuplicationExclusions, IssueExclusionsLoader issueExclusionsLoader,
MetadataGenerator metadataGenerator, SensorStrategy sensorStrategy, LanguageDetection languageDetection, ScanProperties properties,
- ScmChangedFiles scmChangedFiles, StatusDetection statusDetection, ModuleRelativePathWarner moduleRelativePathWarner, InputFileFilterRepository inputFileFilterRepository) {
+ ScmChangedFiles scmChangedFiles, StatusDetection statusDetection, ModuleRelativePathWarner moduleRelativePathWarner,
+ InputFileFilterRepository inputFileFilterRepository, Languages languages) {
this.project = project;
this.scannerComponentIdGenerator = scannerComponentIdGenerator;
this.componentStore = componentStore;
this.statusDetection = statusDetection;
this.moduleRelativePathWarner = moduleRelativePathWarner;
this.inputFileFilterRepository = inputFileFilterRepository;
+ this.languages = languages;
}
void indexFile(DefaultInputModule module, ModuleCoverageAndDuplicationExclusions moduleCoverageAndDuplicationExclusions, Path sourceFile,
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.key(), f, module.getEncoding()),
f -> f.setStatus(statusDetection.findStatusFromScm(f)));
- if (language != null && language.isPublishAllFiles()) {
+ if (language != null && isPublishAllFiles(language.key())) {
inputFile.setPublished(true);
}
if (!accept(inputFile)) {
progressReport.message(count + " " + pluralizeFiles(count) + " indexed... (last one was " + inputFile.getProjectRelativePath() + ")");
}
+ private boolean isPublishAllFiles(String languageKey) {
+ if (languages.get(languageKey) != null) {
+ return languages.get(languageKey).publishAllFiles();
+ }
+ return false;
+ }
+
private void checkIfAlreadyIndexed(DefaultInputFile inputFile) {
if (componentStore.inputFile(inputFile.getProjectRelativePath()) != null) {
throw MessageException.of("File " + inputFile + " can't be indexed twice. Please check that inclusion/exclusion patterns produce "