aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src')
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java16
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java43
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/JGitCleanupService.java47
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java35
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/CliService.java16
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/ScaExecutor.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectData.java12
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java15
-rw-r--r--sonar-scanner-engine/src/main/resources/logback.xml13
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/CliServiceTest.java102
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/ScaExecutorTest.java20
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectDataTest.java48
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.bat2
-rwxr-xr-xsonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.sh2
15 files changed, 265 insertions, 112 deletions
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
index 63317e362b9..6cfd6ea5f94 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/bootstrap/BootstrapMediumIT.java
@@ -117,7 +117,7 @@ class BootstrapMediumIT {
void should_fail_if_invalid_json_input() {
var in = new ByteArrayInputStream("}".getBytes());
- var exitCode = ScannerMain.run(in);
+ var exitCode = ScannerMain.run(in, System.out);
assertThat(exitCode).isEqualTo(1);
assertThat(logTester.getLogs(Level.ERROR)).hasSize(1);
@@ -128,7 +128,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_null_property_key() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"value": "aValueWithoutKey"}]}""".getBytes()));
+ {"scannerProperties": [{"value": "aValueWithoutKey"}]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null key. Value='aValueWithoutKey'");
}
@@ -136,7 +136,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_null_property_value() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"key": "aKey", "value": null}]}""".getBytes()));
+ {"scannerProperties": [{"key": "aKey", "value": null}]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null value. Key='aKey'");
}
@@ -144,7 +144,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_not_provided_property_value() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"key": "aKey"}]}""".getBytes()));
+ {"scannerProperties": [{"key": "aKey"}]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Ignoring property with null value. Key='aKey'");
}
@@ -152,7 +152,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_duplicate_property_keys() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"key": "aKey", "value": "aValue"}, {"key": "aKey", "value": "aValue"}]}""".getBytes()));
+ {"scannerProperties": [{"key": "aKey", "value": "aValue"}, {"key": "aKey", "value": "aValue"}]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Duplicated properties. Key='aKey'");
}
@@ -160,7 +160,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_null_property() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{"key": "aKey", "value": "aValue"},]}""".getBytes()));
+ {"scannerProperties": [{"key": "aKey", "value": "aValue"},]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Ignoring null or empty property");
}
@@ -168,7 +168,7 @@ class BootstrapMediumIT {
@Test
void should_warn_if_empty_property() {
ScannerMain.run(new ByteArrayInputStream("""
- {"scannerProperties": [{}]}""".getBytes()));
+ {"scannerProperties": [{}]}""".getBytes()), System.out);
assertThat(logTester.logs(Level.WARN)).contains("Ignoring null or empty property");
}
@@ -229,7 +229,7 @@ class BootstrapMediumIT {
}
private int runScannerEngine(ScannerProperties scannerProperties) {
- return ScannerMain.run(new ByteArrayInputStream(scannerProperties.toJson().getBytes()));
+ return ScannerMain.run(new ByteArrayInputStream(scannerProperties.toJson().getBytes()), System.out);
}
static class ScannerProperties {
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java
index 04eff59c778..babeadf518e 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumIT.java
@@ -1358,6 +1358,7 @@ class FileSystemMediumIT {
.addRules(new XooRulesDefinition())
.addActiveRule("xoo", "OneIssuePerFile", null, "Issue Per File", "MAJOR", null, "xoo")
.newAnalysis(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.exclusions", "**/*.ignore")
.property("sonar.oneIssuePerFile.enableHiddenFileProcessing", "true");
if (setHiddenFileScanningExplicitly) {
@@ -1385,6 +1386,7 @@ class FileSystemMediumIT {
.addRules(new XooRulesDefinition())
.addActiveRule("xoo", "OneIssuePerFile", null, "Issue Per File", "MAJOR", null, "xoo")
.newAnalysis(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.exclusions", "**/*.ignore")
.property("sonar.oneIssuePerFile.enableHiddenFileProcessing", "false")
.execute();
@@ -1410,6 +1412,7 @@ class FileSystemMediumIT {
.addRules(new XooRulesDefinition())
.addActiveRule("xoo", "OneIssuePerFile", null, "Issue Per File", "MAJOR", null, "xoo")
.newAnalysis(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.exclusions", "**/*.ignore")
.property("sonar.scanner.excludeHiddenFiles", "true")
// hidden files are not scanned, so issues can't be raised on them regardless if the sensor wants to process them
.property("sonar.oneIssuePerFile.enableHiddenFileProcessing", String.valueOf(sensorHiddenFileProcessingEnabled))
@@ -1490,6 +1493,46 @@ class FileSystemMediumIT {
assertHiddenFileScan(result, "moduleB/src/.xoo", true, true);
}
+ @Test
+ void shouldScanAndAnalyzeAllHiddenFilesWithRespectToExclusions() throws IOException {
+ prepareHiddenFileProject();
+ File projectDir = new File("test-resources/mediumtest/xoo/sample-with-hidden-files");
+
+
+ AnalysisResult result = tester
+ .addRules(new XooRulesDefinition())
+ .addActiveRule("xoo", "OneIssuePerFile", null, "Issue Per File", "MAJOR", null, "xoo")
+ .newAnalysis(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.scm.provider", "xoo")
+ .property("sonar.oneIssuePerFile.enableHiddenFileProcessing", "true")
+ .property("sonar.exclusions", "**/.nestedHidden/**,**/*.ignore")
+ .execute();
+
+ Set<String> excludedFiles = Set.of(
+ // sonar.exclusions
+ "xources/.hidden/.nestedHidden/.xoo",
+ "xources/.hidden/.nestedHidden/Class.xoo",
+ "xources/.hidden/.nestedHidden/visibleInHiddenFolder/.xoo",
+ "xources/.hidden/.nestedHidden/visibleInHiddenFolder/.xoo.ignore",
+ "xources/.hidden/.nestedHidden/visibleInHiddenFolder/Class.xoo",
+ // scm ignore
+ "xources/nonHidden/.hiddenInVisibleFolder/.xoo");
+
+ for (Map.Entry<String, Boolean> pathToHiddenStatus : hiddenFileProjectExpectedHiddenStatus().entrySet()) {
+ String filePath = pathToHiddenStatus.getKey();
+ boolean expectedIsHidden = pathToHiddenStatus.getValue();
+
+ if (excludedFiles.contains(filePath)) {
+ assertThat(result.inputFile(filePath)).isNull();
+ } else {
+ assertHiddenFileScan(result, filePath, expectedIsHidden, true);
+ // we expect the sensor to process all non-excluded files, regardless of visibility
+ assertFileIssue(result, filePath, true);
+ }
+ }
+ assertThat(result.inputFiles()).hasSize(5);
+ }
+
private File createModuleWithSubdirectory(String moduleName, String subDirName) {
File moduleBaseDir = new File(baseDir, moduleName);
File srcDir = moduleBaseDir.toPath().resolve(subDirName).toFile();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/JGitCleanupService.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/JGitCleanupService.java
new file mode 100644
index 00000000000..28e052cfa4e
--- /dev/null
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/JGitCleanupService.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2025 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.bootstrap;
+
+import java.lang.reflect.Method;
+import org.eclipse.jgit.internal.util.CleanupService;
+
+/**
+ * Normally, JGit terminates with a shutdown hook. Since we also want to support running the Scanner Engine in the same JVM, this allows triggering shutdown manually.
+ */
+class JGitCleanupService implements AutoCloseable {
+
+ private final Method shutDownMethod;
+ private final CleanupService cleanupService;
+
+ public JGitCleanupService() {
+ cleanupService = new CleanupService();
+ try {
+ shutDownMethod = CleanupService.class.getDeclaredMethod("shutDown");
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Unable to find method 'shutDown' on JGit CleanupService", e);
+ }
+ shutDownMethod.setAccessible(true);
+ }
+
+ @Override
+ public void close() throws Exception {
+ shutDownMethod.invoke(cleanupService);
+ }
+}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
index 7e27a45e4cf..bd8d5b9b99c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerMain.java
@@ -21,11 +21,14 @@ package org.sonar.scanner.bootstrap;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.OutputStreamAppender;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
@@ -50,11 +53,13 @@ public class ScannerMain {
private static final String SCANNER_APP_VERSION_KEY = "sonar.scanner.appVersion";
public static void main(String... args) {
- System.exit(run(System.in));
+ System.exit(run(System.in, System.out));
}
- public static int run(InputStream in) {
- try {
+ public static int run(InputStream in, OutputStream out) {
+ try (var ignored = new JGitCleanupService()) {
+ configureLogOutput(out);
+
LOG.info("Starting SonarScanner Engine...");
LOG.atInfo().log(ScannerMain::java);
@@ -71,6 +76,8 @@ public class ScannerMain {
} catch (Throwable throwable) {
handleException(throwable);
return 1;
+ } finally {
+ stopLogback();
}
}
@@ -156,6 +163,28 @@ public class ScannerMain {
rootLogger.setLevel(Level.toLevel(verbose ? LEVEL_ROOT_VERBOSE : LEVEL_ROOT_DEFAULT));
}
+ private static void configureLogOutput(OutputStream out) {
+ var loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
+ var encoder = new ScannerLogbackEncoder();
+ encoder.setContext(loggerContext);
+ encoder.start();
+
+ var appender = new OutputStreamAppender<ILoggingEvent>();
+ appender.setEncoder(encoder);
+ appender.setContext(loggerContext);
+ appender.setOutputStream(out);
+ appender.start();
+
+ var rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
+ rootLogger.addAppender(appender);
+ rootLogger.setLevel(Level.toLevel(LEVEL_ROOT_DEFAULT));
+ }
+
+ private static void stopLogback() {
+ var loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
+ loggerContext.stop();
+ }
+
private static class Input {
@SerializedName("scannerProperties")
private List<ScannerProperty> scannerProperties;
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/CliService.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/CliService.java
index 1b2346f2b62..6b3418a8f6a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/CliService.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/CliService.java
@@ -76,19 +76,19 @@ public class CliService {
this.projectExclusionFilters = projectExclusionFilters;
}
- public File generateManifestsZip(DefaultInputModule module, File cliExecutable, DefaultConfiguration configuration) throws IOException, IllegalStateException {
+ public File generateManifestsArchive(DefaultInputModule module, File cliExecutable, DefaultConfiguration configuration) throws IOException, IllegalStateException {
long startTime = system2.now();
boolean success = false;
try {
- String zipName = "dependency-files.zip";
- Path zipPath = module.getWorkDir().resolve(zipName);
+ String archiveName = "dependency-files.tar.xz";
+ Path archivePath = module.getWorkDir().resolve(archiveName);
List<String> args = new ArrayList<>();
args.add(cliExecutable.getAbsolutePath());
args.add("projects");
args.add("save-lockfiles");
- args.add("--zip");
- args.add("--zip-filename");
- args.add(zipPath.toAbsolutePath().toString());
+ args.add("--xz");
+ args.add("--xz-filename");
+ args.add(archivePath.toAbsolutePath().toString());
args.add("--directory");
args.add(module.getBaseDir().toString());
args.add("--recursive");
@@ -117,9 +117,9 @@ public class CliService {
Consumer<String> logConsumer = LOG.atLevel(Level.INFO)::log;
processWrapperFactory.create(module.getWorkDir(), logConsumer, logConsumer, envProperties, args.toArray(new String[0])).execute();
- LOG.info("Generated manifests zip file: {}", zipName);
+ LOG.info("Generated manifests archive file: {}", archiveName);
success = true;
- return zipPath.toFile();
+ return archivePath.toFile();
} finally {
telemetryCache.put("scanner.sca.execution.cli.duration", String.valueOf(system2.now() - startTime));
telemetryCache.put("scanner.sca.execution.cli.success", String.valueOf(success));
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/ScaExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/ScaExecutor.java
index 52a99673e43..143e144c2dc 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/ScaExecutor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sca/ScaExecutor.java
@@ -75,7 +75,7 @@ public class ScaExecutor {
LOG.info("Collecting manifests for the dependency analysis...");
if (cliFile.exists()) {
try {
- File generatedZip = cliService.generateManifestsZip(root, cliFile, configuration);
+ File generatedZip = cliService.generateManifestsArchive(root, cliFile, configuration);
LOG.debug("Zip ready for report: {}", generatedZip);
reportPublisher.getWriter().writeScaFile(generatedZip);
LOG.debug("Manifest zip written to report");
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 d73924c17e0..0961edbd985 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
@@ -94,8 +94,8 @@ public class FileIndexer {
// This should be fast; language should be cached from preprocessing step
Language language = langDetection.language(sourceFile, projectRelativePath);
- // cached from directory file visitation
- boolean isHidden = hiddenFilesProjectData.isMarkedAsHiddenFile(sourceFile, module);
+ // cached from directory file visitation, after querying the data is removed to reduce memory consumption
+ boolean isHidden = hiddenFilesProjectData.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(sourceFile, module);
DefaultIndexedFile indexedFile = new DefaultIndexedFile(
sourceFile,
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectData.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectData.java
index e2d5f57acae..d779a054455 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectData.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectData.java
@@ -44,12 +44,16 @@ public class HiddenFilesProjectData {
hiddenFilesByModule.computeIfAbsent(module, k -> new HashSet<>()).add(file);
}
- public boolean isMarkedAsHiddenFile(Path file, DefaultInputModule module) {
+ /**
+ * To alleviate additional strain on the memory, we remove the visibility information for <code>hiddenFilesByModule</code> mapdirectly after querying,
+ * as we don't need it afterward.
+ */
+ public boolean getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(Path file, DefaultInputModule module) {
Set<Path> hiddenFilesPerModule = hiddenFilesByModule.get(module);
- if (hiddenFilesPerModule == null) {
- return false;
+ if (hiddenFilesPerModule != null) {
+ return hiddenFilesPerModule.remove(file);
}
- return hiddenFilesPerModule.contains(file);
+ return false;
}
public Path getCachedSonarUserHomePath() throws IOException {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java
index 216f86c4f11..3e7b655589c 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFilePreprocessor.java
@@ -160,7 +160,11 @@ public class ProjectFilePreprocessor {
processedFiles.addAll(processDirectory(module, moduleConfiguration, moduleExclusionFilters, dirOrFile, type, exclusionCounter));
} else {
filePreprocessor.processFile(module, moduleExclusionFilters, dirOrFile, type, exclusionCounter, ignoreCommand)
- .ifPresent(processedFiles::add);
+ .ifPresentOrElse(
+ processedFiles::add,
+ // If the file is not processed, we don't need to save visibility data and can remove it
+ () -> hiddenFilesProjectData.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(dirOrFile, module)
+ );
}
}
} catch (IOException e) {
@@ -173,8 +177,13 @@ public class ProjectFilePreprocessor {
InputFile.Type type, ExclusionCounter exclusionCounter) throws IOException {
List<Path> processedFiles = new ArrayList<>();
Files.walkFileTree(path.normalize(), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
- new DirectoryFileVisitor(file -> filePreprocessor.processFile(module, moduleExclusionFilters, file, type, exclusionCounter,
- ignoreCommand).ifPresent(processedFiles::add), module, moduleConfiguration, moduleExclusionFilters, inputModuleHierarchy, type, hiddenFilesProjectData));
+ new DirectoryFileVisitor(file -> filePreprocessor
+ .processFile(module, moduleExclusionFilters, file, type, exclusionCounter, ignoreCommand)
+ .ifPresentOrElse(
+ processedFiles::add,
+ // If the file is not processed, we don't need to save visibility data and can remove it
+ () -> hiddenFilesProjectData.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(file, module)),
+ module, moduleConfiguration, moduleExclusionFilters, inputModuleHierarchy, type, hiddenFilesProjectData));
return processedFiles;
}
diff --git a/sonar-scanner-engine/src/main/resources/logback.xml b/sonar-scanner-engine/src/main/resources/logback.xml
index ccd0dfe09b9..ddc2805f08a 100644
--- a/sonar-scanner-engine/src/main/resources/logback.xml
+++ b/sonar-scanner-engine/src/main/resources/logback.xml
@@ -1,17 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
-<!-- This logback configuration is used when the scanner engine is bootstrapped using the SonarScannerCli class. -->
+<!-- This logback configuration is used when the scanner engine is bootstrapped using the ScannerMain class. -->
<configuration scan="false">
- <import class="ch.qos.logback.core.ConsoleAppender"/>
-
- <appender name="STDOUT" class="ConsoleAppender">
- <encoder class="org.sonar.scanner.bootstrap.ScannerLogbackEncoder"/>
- </appender>
-
- <root level="info">
- <appender-ref ref="STDOUT"/>
- </root>
<!-- BeanUtils generate too many DEBUG logs when sonar.verbose is set -->
<logger name="org.apache.commons.beanutils.converters" level="WARN"/>
@@ -31,4 +22,4 @@
<logger name="nl.altindag.ssl.util.CertificateUtils" level="INFO"/>
-</configuration> \ No newline at end of file
+</configuration>
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/CliServiceTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/CliServiceTest.java
index 86958228c34..33cf6c146e6 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/CliServiceTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/CliServiceTest.java
@@ -103,22 +103,22 @@ class CliServiceTest {
}
@Test
- void generateZip_shouldCallProcessCorrectly_andRegisterTelemetry() throws IOException, URISyntaxException {
+ void generateManifestsArchive_shouldCallProcessCorrectly_andRegisterTelemetry() throws IOException, URISyntaxException {
assertThat(rootModuleDir.resolve("test_file").toFile().createNewFile()).isTrue();
when(configuration.getProperties()).thenReturn(Map.of(CliService.SCA_EXCLUSIONS_KEY, "foo,bar,baz/**"));
when(configuration.getStringArray(CliService.SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"foo", "bar", "baz/**"});
- File producedZip = underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ File producedArchive = underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
- assertThat(producedZip).exists();
+ assertThat(producedArchive).exists();
var expectedArguments = List.of(
"projects",
"save-lockfiles",
- "--zip",
- "--zip-filename",
- rootInputModule.getWorkDir().resolve("dependency-files.zip").toString(),
+ "--xz",
+ "--xz-filename",
+ rootInputModule.getWorkDir().resolve("dependency-files.tar.xz").toString(),
"--directory",
rootInputModule.getBaseDir().toString(),
"--recursive",
@@ -129,26 +129,26 @@ class CliServiceTest {
.contains("Arguments Passed In: " + String.join(" ", expectedArguments))
.contains("TIDELIFT_SKIP_UPDATE_CHECK=1")
.contains("TIDELIFT_ALLOW_MANIFEST_FAILURES=1")
- .contains("Generated manifests zip file: " + producedZip.getName());
+ .contains("Generated manifests archive file: " + producedArchive.getName());
assertThat(telemetryCache.getAll()).containsKey("scanner.sca.execution.cli.duration").isNotNull();
assertThat(telemetryCache.getAll()).containsEntry("scanner.sca.execution.cli.success", "true");
}
@Test
- void generateZip_whenDebugLogLevelAndScaDebugNotEnabled_shouldWriteDebugLogsToDebugStream() throws IOException, URISyntaxException {
+ void generateManifestsArchive_whenDebugLogLevelAndScaDebugNotEnabled_shouldWriteDebugLogsToDebugStream() throws IOException, URISyntaxException {
logTester.setLevel(DEBUG);
assertThat(rootModuleDir.resolve("test_file").toFile().createNewFile()).isTrue();
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
var expectedArguments = List.of(
"projects",
"save-lockfiles",
- "--zip",
- "--zip-filename",
- rootInputModule.getWorkDir().resolve("dependency-files.zip").toString(),
+ "--xz",
+ "--xz-filename",
+ rootInputModule.getWorkDir().resolve("dependency-files.tar.xz").toString(),
"--directory",
rootInputModule.getBaseDir().toString(),
"--recursive",
@@ -161,17 +161,17 @@ class CliServiceTest {
}
@Test
- void generateZip_whenScaDebugEnabled_shouldWriteDebugLogsToInfoStream() throws IOException, URISyntaxException {
+ void generateManifestsArchive_whenScaDebugEnabled_shouldWriteDebugLogsToInfoStream() throws IOException, URISyntaxException {
assertThat(rootModuleDir.resolve("test_file").toFile().createNewFile()).isTrue();
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
var expectedArguments = List.of(
"projects",
"save-lockfiles",
- "--zip",
- "--zip-filename",
- rootInputModule.getWorkDir().resolve("dependency-files.zip").toString(),
+ "--xz",
+ "--xz-filename",
+ rootInputModule.getWorkDir().resolve("dependency-files.tar.xz").toString(),
"--directory",
rootInputModule.getBaseDir().toString(),
"--recursive",
@@ -183,8 +183,8 @@ class CliServiceTest {
}
@Test
- void generateZip_shouldSendSQEnvVars() throws IOException, URISyntaxException {
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ void generateManifestsArchive_shouldSendSQEnvVars() throws IOException, URISyntaxException {
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
assertThat(logTester.logs(INFO))
.contains("TIDELIFT_CLI_INSIDE_SCANNER_ENGINE=1")
@@ -192,15 +192,15 @@ class CliServiceTest {
}
@Test
- void generateZip_includesIgnoredPathsFromGitProvider() throws Exception {
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ void generateManifestsArchive_includesIgnoredPathsFromGitProvider() throws Exception {
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
var expectedArguments = List.of(
"projects",
"save-lockfiles",
- "--zip",
- "--zip-filename",
- rootInputModule.getWorkDir().resolve("dependency-files.zip").toString(),
+ "--xz",
+ "--xz-filename",
+ rootInputModule.getWorkDir().resolve("dependency-files.tar.xz").toString(),
"--directory",
rootInputModule.getBaseDir().toString(),
"--recursive",
@@ -217,61 +217,61 @@ class CliServiceTest {
}
@Test
- void generateZip_withNoScm_doesNotIncludeScmIgnoredPaths() throws Exception {
+ void generateManifestsArchive_withNoScm_doesNotIncludeScmIgnoredPaths() throws Exception {
when(scmConfiguration.provider()).thenReturn(null);
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude .scannerwork/**");
}
@Test
- void generateZip_withNonGit_doesNotIncludeScmIgnoredPaths() throws Exception {
+ void generateManifestsArchive_withNonGit_doesNotIncludeScmIgnoredPaths() throws Exception {
when(scmProvider.key()).thenReturn("notgit");
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude .scannerwork/**");
}
@Test
- void generateZip_withScmExclusionDisabled_doesNotIncludeScmIgnoredPaths() throws Exception {
+ void generateManifestsArchive_withScmExclusionDisabled_doesNotIncludeScmIgnoredPaths() throws Exception {
when(scmConfiguration.isExclusionDisabled()).thenReturn(true);
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude .scannerwork/**");
}
@Test
- void generateZip_withNoScmIgnores_doesNotIncludeScmIgnoredPaths() throws Exception {
+ void generateManifestsArchive_withNoScmIgnores_doesNotIncludeScmIgnoredPaths() throws Exception {
jGitUtilsMock.when(() -> JGitUtils.getAllIgnoredPaths(any(Path.class))).thenReturn(List.of());
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude .scannerwork/**");
}
@Test
- void generateZip_withExcludedManifests_appendsScmIgnoredPaths() throws Exception {
+ void generateManifestsArchive_withExcludedManifests_appendsScmIgnoredPaths() throws Exception {
when(configuration.getStringArray(CliService.SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"**/test/**"});
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude **/test/**,ignored.txt,.scannerwork/**");
}
@Test
- void generateZip_withExcludedManifestsContainingBadCharacters_handlesTheBadCharacters() throws Exception {
+ void generateManifestsArchive_withExcludedManifestsContainingBadCharacters_handlesTheBadCharacters() throws Exception {
when(configuration.getStringArray(CliService.SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {
"**/test/**", "**/path with spaces/**", "**/path'with'quotes/**", "**/path\"with\"double\"quotes/**"});
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
@@ -280,41 +280,41 @@ class CliServiceTest {
""".strip();
if (SystemUtils.IS_OS_WINDOWS) {
expectedExcludeFlag = """
- --exclude "**/test/**,**/path with spaces/**,**/path'with'quotes/**,"**/path""with""double""quotes/**",ignored.txt
- """.strip();
+ --exclude "**/test/**,**/path with spaces/**,**/path'with'quotes/**,"**/path""with""double""quotes/**",ignored.txt
+ """.strip();
}
assertThat(capturedArgs).contains(expectedExcludeFlag);
}
@Test
- void generateZip_withExcludedManifestsContainingDupes_dedupes() throws Exception {
+ void generateManifestsArchive_withExcludedManifestsContainingDupes_dedupes() throws Exception {
when(configuration.getStringArray(CliService.SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"**/test1/**", "**/test2/**", "**/test1/**"});
when(configuration.getStringArray(CliService.LEGACY_SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"**/test1/**", "**/test3/**"});
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude **/test1/**,**/test2/**,**/test3/**,ignored.txt,.scannerwork/**");
}
@Test
- void generateZip_withExcludedManifestsAndSonarExcludesContainingDupes_mergesAndDedupes() throws Exception {
+ void generateManifestsArchive_withExcludedManifestsAndSonarExcludesContainingDupes_mergesAndDedupes() throws Exception {
when(projectExclusionFilters.getExclusionsConfig(InputFile.Type.MAIN)).thenReturn(new String[] {"**/test1/**", "**/test4/**"});
when(configuration.getStringArray(CliService.SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"**/test1/**", "**/test2/**", "**/test1/**"});
when(configuration.getStringArray(CliService.LEGACY_SCA_EXCLUSIONS_KEY)).thenReturn(new String[] {"**/test1/**", "**/test3/**"});
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude **/test1/**,**/test4/**,**/test2/**,**/test3/**,ignored.txt,.scannerwork/**");
}
@Test
- void generateZip_withScmIgnoresContainingBadCharacters_handlesTheBadCharacters() throws Exception {
+ void generateManifestsArchive_withScmIgnoresContainingBadCharacters_handlesTheBadCharacters() throws Exception {
jGitUtilsMock.when(() -> JGitUtils.getAllIgnoredPaths(any(Path.class)))
.thenReturn(List.of("**/test/**", "**/path with spaces/**", "**/path'with'quotes/**", "**/path\"with\"double\"quotes/**"));
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
@@ -323,14 +323,14 @@ class CliServiceTest {
""".strip();
if (SystemUtils.IS_OS_WINDOWS) {
expectedExcludeFlag = """
- --exclude "**/test/**,**/path with spaces/**,**/path'with'quotes/**,"**/path""with""double""quotes/**"
- """.strip();
+ --exclude "**/test/**,**/path with spaces/**,**/path'with'quotes/**,"**/path""with""double""quotes/**"
+ """.strip();
}
assertThat(capturedArgs).contains(expectedExcludeFlag);
}
@Test
- void generateZip_withIgnoredDirectories_GlobifiesDirectories() throws Exception {
+ void generateManifestsArchive_withIgnoredDirectories_GlobifiesDirectories() throws Exception {
String ignoredDirectory = "directory1";
Files.createDirectories(rootModuleDir.resolve(ignoredDirectory));
String ignoredFile = "directory2/file.txt";
@@ -339,18 +339,18 @@ class CliServiceTest {
Files.createFile(ignoredFilePath);
jGitUtilsMock.when(() -> JGitUtils.getAllIgnoredPaths(any(Path.class))).thenReturn(List.of(ignoredDirectory, ignoredFile));
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
assertThat(capturedArgs).contains("--exclude directory1/**,directory2/file.txt");
}
@Test
- void generateZip_withExternalWorkDir_DoesNotExcludeWorkingDir() throws URISyntaxException, IOException {
+ void generateManifestsArchive_withExternalWorkDir_DoesNotExcludeWorkingDir() throws URISyntaxException, IOException {
Path externalWorkDir = Files.createTempDirectory("externalWorkDir");
try {
rootInputModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(rootModuleDir.toFile()).setWorkDir(externalWorkDir.toFile()));
- underTest.generateManifestsZip(rootInputModule, scriptDir(), configuration);
+ underTest.generateManifestsArchive(rootInputModule, scriptDir(), configuration);
String capturedArgs = logTester.logs().stream().filter(log -> log.contains("Arguments Passed In:")).findFirst().get();
// externalWorkDir is not present in the exclude flag
@@ -363,7 +363,7 @@ class CliServiceTest {
private URL scriptUrl() {
// There is a custom test Bash script available in src/test/resources/org/sonar/scanner/sca that
// will serve as our "CLI". This script will output some messages about what arguments were passed
- // to it and will try to generate a zip file in the location the process specifies. This allows us
+ // to it and will try to generate an archive file in the location the process specifies. This allows us
// to simulate a real CLI call without needing an OS specific CLI executable to run on a real project.
URL scriptUrl = CliServiceTest.class.getResource(SystemUtils.IS_OS_WINDOWS ? "echo_args.bat" : "echo_args.sh");
assertThat(scriptUrl).isNotNull();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/ScaExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/ScaExecutorTest.java
index c4eecd73d65..ebe6007a1c1 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/ScaExecutorTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sca/ScaExecutorTest.java
@@ -70,14 +70,14 @@ class ScaExecutorTest {
File mockManifestZip = Files.newTemporaryFile();
ScannerReportWriter mockReportWriter = mock(ScannerReportWriter.class);
when(cliCacheService.cacheCli()).thenReturn(mockCliFile);
- when(cliService.generateManifestsZip(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
+ when(cliService.generateManifestsArchive(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
when(reportPublisher.getWriter()).thenReturn(mockReportWriter);
logTester.setLevel(Level.DEBUG);
underTest.execute(root);
- verify(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ verify(cliService).generateManifestsArchive(root, mockCliFile, configuration);
verify(mockReportWriter).writeScaFile(mockManifestZip);
assertThat(logTester.logs(Level.DEBUG)).contains("Zip ready for report: " + mockManifestZip);
assertThat(logTester.logs(Level.DEBUG)).contains("Manifest zip written to report");
@@ -87,13 +87,13 @@ class ScaExecutorTest {
void execute_whenIOException_shouldHandleException() throws IOException {
File mockCliFile = Files.newTemporaryFile();
when(cliCacheService.cacheCli()).thenReturn(mockCliFile);
- doThrow(IOException.class).when(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ doThrow(IOException.class).when(cliService).generateManifestsArchive(root, mockCliFile, configuration);
logTester.setLevel(Level.INFO);
underTest.execute(root);
- verify(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ verify(cliService).generateManifestsArchive(root, mockCliFile, configuration);
assertThat(logTester.logs(Level.ERROR)).contains("Error gathering manifests");
}
@@ -101,13 +101,13 @@ class ScaExecutorTest {
void execute_whenIllegalStateException_shouldHandleException() throws IOException {
File mockCliFile = Files.newTemporaryFile();
when(cliCacheService.cacheCli()).thenReturn(mockCliFile);
- doThrow(IllegalStateException.class).when(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ doThrow(IllegalStateException.class).when(cliService).generateManifestsArchive(root, mockCliFile, configuration);
logTester.setLevel(Level.INFO);
underTest.execute(root);
- verify(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ verify(cliService).generateManifestsArchive(root, mockCliFile, configuration);
assertThat(logTester.logs(Level.ERROR)).contains("Error gathering manifests");
}
@@ -118,7 +118,7 @@ class ScaExecutorTest {
underTest.execute(root);
- verify(cliService, never()).generateManifestsZip(root, mockCliFile, configuration);
+ verify(cliService, never()).generateManifestsArchive(root, mockCliFile, configuration);
}
@Test
@@ -150,13 +150,13 @@ class ScaExecutorTest {
File mockManifestZip = Files.newTemporaryFile();
ScannerReportWriter mockReportWriter = mock(ScannerReportWriter.class);
when(cliCacheService.cacheCli()).thenReturn(mockCliFile);
- when(cliService.generateManifestsZip(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
+ when(cliService.generateManifestsArchive(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
when(reportPublisher.getWriter()).thenReturn(mockReportWriter);
logTester.setLevel(Level.DEBUG);
underTest.execute(root);
- verify(cliService).generateManifestsZip(root, mockCliFile, configuration);
+ verify(cliService).generateManifestsArchive(root, mockCliFile, configuration);
verify(mockReportWriter).writeScaFile(mockManifestZip);
assertThat(logTester.logs(Level.DEBUG)).contains("Zip ready for report: " + mockManifestZip);
assertThat(logTester.logs(Level.DEBUG)).contains("Manifest zip written to report");
@@ -168,7 +168,7 @@ class ScaExecutorTest {
File mockManifestZip = Files.newTemporaryFile();
ScannerReportWriter mockReportWriter = mock(ScannerReportWriter.class);
when(cliCacheService.cacheCli()).thenReturn(mockCliFile);
- when(cliService.generateManifestsZip(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
+ when(cliService.generateManifestsArchive(root, mockCliFile, configuration)).thenReturn(mockManifestZip);
when(reportPublisher.getWriter()).thenReturn(mockReportWriter);
logTester.setLevel(Level.INFO);
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectDataTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectDataTest.java
index ad3edf95428..d5a6e4ff843 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectDataTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/HiddenFilesProjectDataTest.java
@@ -73,10 +73,10 @@ public class HiddenFilesProjectDataTest {
underTest.markAsHiddenFile(myFile2, inputModule);
assertThat(underTest.hiddenFilesByModule).hasSize(1);
- assertThat(underTest.isMarkedAsHiddenFile(myFile, inputModule)).isTrue();
- assertThat(underTest.isMarkedAsHiddenFile(myFile2, inputModule)).isTrue();
- assertThat(underTest.isMarkedAsHiddenFile(myFile, secondInputModule)).isFalse();
- assertThat(underTest.isMarkedAsHiddenFile(myFile2, secondInputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, inputModule)).isTrue();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, inputModule)).isTrue();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, secondInputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, secondInputModule)).isFalse();
}
@Test
@@ -87,10 +87,10 @@ public class HiddenFilesProjectDataTest {
underTest.markAsHiddenFile(myFile2, secondInputModule);
assertThat(underTest.hiddenFilesByModule).hasSize(2);
- assertThat(underTest.isMarkedAsHiddenFile(myFile, inputModule)).isTrue();
- assertThat(underTest.isMarkedAsHiddenFile(myFile2, inputModule)).isFalse();
- assertThat(underTest.isMarkedAsHiddenFile(myFile, secondInputModule)).isFalse();
- assertThat(underTest.isMarkedAsHiddenFile(myFile2, secondInputModule)).isTrue();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, inputModule)).isTrue();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, inputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, secondInputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, secondInputModule)).isTrue();
}
@Test
@@ -100,7 +100,7 @@ public class HiddenFilesProjectDataTest {
underTest.markAsHiddenFile(myFile, inputModule);
assertThat(underTest.hiddenFilesByModule).isNotEmpty();
- assertThat(underTest.isMarkedAsHiddenFile(notMarkedFile, secondInputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(notMarkedFile, secondInputModule)).isFalse();
}
@Test
@@ -117,6 +117,36 @@ public class HiddenFilesProjectDataTest {
}
@Test
+ public void shouldRemoveVisibilityAfterQuerying() {
+ Path myFile = Path.of("myFile");
+ Path myFile2 = Path.of("myFile2");
+ underTest.markAsHiddenFile(myFile, inputModule);
+ underTest.markAsHiddenFile(myFile2, inputModule);
+
+ assertThat(underTest.hiddenFilesByModule).hasSize(1);
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, inputModule)).isTrue();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, inputModule)).isTrue();
+
+ assertThat(underTest.hiddenFilesByModule).hasSize(1);
+ assertThat(underTest.hiddenFilesByModule.get(inputModule)).isEmpty();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, inputModule)).isFalse();
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile2, inputModule)).isFalse();
+ }
+
+ @Test
+ public void shouldOnlyRemoveModuleIfAllFilesAreRemoved() {
+ Path myFile = Path.of("myFile");
+ Path myFile2 = Path.of("myFile2");
+ underTest.markAsHiddenFile(myFile, inputModule);
+ underTest.markAsHiddenFile(myFile2, inputModule);
+
+ assertThat(underTest.hiddenFilesByModule).hasSize(1);
+ assertThat(underTest.getIsMarkedAsHiddenFileAndRemoveVisibilityInformation(myFile, inputModule)).isTrue();
+
+ assertThat(underTest.hiddenFilesByModule).isNotEmpty();
+ }
+
+ @Test
public void shouldNotFailOnUserPathResolving() throws IOException {
Path expectedPath = sonarUserHome.getPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toAbsolutePath().normalize();
assertThat(underTest.getCachedSonarUserHomePath()).isEqualTo(expectedPath);
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.bat b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.bat
index 5677cf5c437..577375b330d 100644
--- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.bat
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.bat
@@ -6,7 +6,7 @@ set "POSITIONAL_ARGS="
:loop
if "%~1"=="" goto endloop
-if "%~1"=="--zip-filename" (
+if "%~1"=="--xz-filename" (
set "FILENAME=%~2"
shift
shift
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.sh b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.sh
index 881be2eaac5..f7feed1f501 100755
--- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.sh
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/sca/echo_args.sh
@@ -6,7 +6,7 @@ POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
- --zip-filename)
+ --xz-filename)
FILENAME="$2"
shift
shift