diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2022-10-26 16:17:06 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-26 20:03:10 +0000 |
commit | dc592db7bb160b5c43fae1fcfd7e222ed0c875a1 (patch) | |
tree | 70715bcd8c0432c19edceb3f9ba523fcb9117ee0 /sonar-scanner-engine/src/main/java | |
parent | d4c9abe2a0a04d6a974c12d6ad06a17eb1ace4a8 (diff) | |
download | sonarqube-dc592db7bb160b5c43fae1fcfd7e222ed0c875a1.tar.gz sonarqube-dc592db7bb160b5c43fae1fcfd7e222ed0c875a1.zip |
SONAR-11096 Discard files from analysis scope greater 20MB
SONAR-11096 Discard files from analysis scope greater when than 20 MB
- introduce property 'sonar.filesize.limit'
Diffstat (limited to 'sonar-scanner-engine/src/main/java')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java | 5 | ||||
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java index 250d9d22482..095887f8159 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ScanProperties.java @@ -27,6 +27,7 @@ import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; import static org.sonar.core.config.ScannerProperties.BRANCH_NAME; +import static org.sonar.core.config.ScannerProperties.FILE_SIZE_LIMIT; /** * Properties that can be passed to the scanners and are not exposed in SonarQube. @@ -93,6 +94,10 @@ public class ScanProperties { return configuration.getInt(REPORT_PUBLISH_TIMEOUT_IN_SEC).orElse(60); } + public long fileSizeLimit() { + return configuration.getInt(FILE_SIZE_LIMIT).orElse(20); + } + /** * This should be called in the beginning of the analysis to fail fast */ 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 f62617d166a..caf0ad0d76f 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,6 +20,7 @@ package org.sonar.scanner.scan.filesystem; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.Arrays; @@ -119,6 +120,12 @@ public class FileIndexer { return; } + long maxFileSize = properties.fileSizeLimit(); + if (Files.size(realAbsoluteFile) > maxFileSize * 1024L * 1024L) { + LOG.warn("File '{}' is bigger than {}MB and as consequence is removed from the analysis scope.", realAbsoluteFile.toAbsolutePath(), maxFileSize); + return; + } + Language language = langDetection.language(realAbsoluteFile, projectRelativePath); if (ignoreCommand != null && ignoreCommand.isIgnored(realAbsoluteFile)) { @@ -141,7 +148,7 @@ public class FileIndexer { DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> metadataGenerator.setMetadata(module.key(), f, module.getEncoding())); if (language != null && language.isPublishAllFiles()) { - inputFile.setPublished(true); + inputFile.setPublished(true); } if (!accept(inputFile)) { return; |