aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-01-14 15:05:49 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:14 +0100
commit2a1bb3adb010fdb65468808551fc7cc45fae4579 (patch)
treed809740461f3fdf6af5587976fb1b23867da714e
parenta670f22ca1ea07f1f24d3e89d5c0b1220c8185c2 (diff)
downloadsonarqube-2a1bb3adb010fdb65468808551fc7cc45fae4579.tar.gz
sonarqube-2a1bb3adb010fdb65468808551fc7cc45fae4579.zip
SONAR-11606 Stop excluding directories starting with a dot
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java16
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java13
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java24
3 files changed, 43 insertions, 10 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
index 21a243cbd63..8bdb040b0f0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/AbstractProjectOrModule.java
@@ -22,6 +22,7 @@ package org.sonar.api.batch.fs.internal;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.Collections;
@@ -30,12 +31,15 @@ import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.SystemUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
@Immutable
public abstract class AbstractProjectOrModule extends DefaultInputComponent {
-
+ private static final Logger LOGGER = Loggers.get(AbstractProjectOrModule.class);
private final Path baseDir;
private final Path workDir;
private final String name;
@@ -92,7 +96,15 @@ public abstract class AbstractProjectOrModule extends DefaultInputComponent {
private static Path initWorkingDir(ProjectDefinition module) {
File workingDirAsFile = module.getWorkDir();
- return workingDirAsFile.getAbsoluteFile().toPath().normalize();
+ Path workingDir = workingDirAsFile.getAbsoluteFile().toPath().normalize();
+ if (SystemUtils.IS_OS_WINDOWS) {
+ try {
+ Files.setAttribute(workingDir, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to set working directory hidden: {}", e.getMessage());
+ }
+ }
+ return workingDir;
}
/**
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java
index 67cf6e83785..30eaf20f736 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java
@@ -39,7 +39,7 @@ public class DefaultInputModuleTest {
public TemporaryFolder temp = new TemporaryFolder();
@Test
- public void testGetters() throws IOException {
+ public void check_getters() throws IOException {
ProjectDefinition def = ProjectDefinition.create();
def.setKey("moduleKey");
File baseDir = temp.newFolder();
@@ -68,4 +68,15 @@ public class DefaultInputModuleTest {
assertThat(module.isFile()).isFalse();
}
+ @Test
+ public void working_directory_should_be_hidden() throws IOException {
+ ProjectDefinition def = ProjectDefinition.create();
+ File workDir = temp.newFolder(".sonar");
+ def.setWorkDir(workDir);
+ File baseDir = temp.newFolder();
+ def.setBaseDir(baseDir);
+ DefaultInputModule module = new DefaultInputModule(def);
+ assertThat(workDir.isHidden()).isTrue();
+ }
+
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
index 788ee0d5887..9c13d0c2e1d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ProjectFileIndexer.java
@@ -25,8 +25,10 @@ import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
+import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.DosFileAttributes;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
@@ -35,6 +37,7 @@ import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.SystemUtils;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
@@ -190,12 +193,7 @@ public class ProjectFileIndexer {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
- Path fileName = dir.getFileName();
-
- if (fileName != null && fileName.toString().length() > 1 && fileName.toString().charAt(0) == '.') {
- return FileVisitResult.SKIP_SUBTREE;
- }
- if (Files.isHidden(dir)) {
+ if (isHidden(dir)) {
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
@@ -223,6 +221,18 @@ public class ProjectFileIndexer {
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
return FileVisitResult.CONTINUE;
}
- }
+ private boolean isHidden(Path path) throws IOException {
+ if (SystemUtils.IS_OS_WINDOWS) {
+ try {
+ DosFileAttributes dosFileAttributes = Files.readAttributes(path, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
+ return dosFileAttributes.isHidden();
+ } catch (UnsupportedOperationException e) {
+ return path.toFile().isHidden();
+ }
+ } else {
+ return Files.isHidden(path);
+ }
+ }
+ }
}