diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-02 10:11:08 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-04 10:33:16 +0200 |
commit | fd72aa9a5891a306b225f1a08136e09745cc10fd (patch) | |
tree | 93e89b1524dcf23594dba01bc2b1a273a8f15ff1 /sonar-batch | |
parent | 4cb2a976809bcd5c999aa2342480cb20c59df9e3 (diff) | |
download | sonarqube-fd72aa9a5891a306b225f1a08136e09745cc10fd.tar.gz sonarqube-fd72aa9a5891a306b225f1a08136e09745cc10fd.zip |
Hide project lock on windows
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java index ce62584abc9..f12751f9be6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java @@ -31,6 +31,7 @@ import java.nio.channels.FileLock; import java.nio.channels.OverlappingFileLockException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.attribute.DosFileAttributeView; public class ProjectLock implements Startable { private static final Logger LOG = LoggerFactory.getLogger(ProjectLock.class); @@ -50,18 +51,31 @@ public class ProjectLock implements Startable { try { lockRandomAccessFile = new RandomAccessFile(lockFilePath.toFile(), "rw"); lockChannel = lockRandomAccessFile.getChannel(); + hideLockFileWindows(lockFilePath); lockFile = lockChannel.tryLock(0, 1024, false); if (lockFile == null) { failAlreadyInProgress(null); } + } catch (OverlappingFileLockException e) { failAlreadyInProgress(e); } catch (IOException e) { throw new IllegalStateException("Failed to create project lock in " + lockFilePath.toString(), e); } } - + + private static void hideLockFileWindows(Path p) { + try { + DosFileAttributeView fileAttrView = Files.getFileAttributeView(p, DosFileAttributeView.class); + if (fileAttrView != null) { + fileAttrView.setHidden(true); + } + } catch (IOException e) { + throw new IllegalStateException("Failed to hide file: " + p.toString(), e); + } + } + private static void failAlreadyInProgress(Exception e) { throw new IllegalStateException("Another SonarQube analysis is already in progress for this project", e); } @@ -92,11 +106,11 @@ public class ProjectLock implements Startable { LOG.error("Error closing file", e); } } - + try { Files.delete(lockFilePath); } catch (IOException e) { - //ignore, as an error happens if another process just started to acquire the same lock + // ignore, as an error happens if another process just started to acquire the same lock LOG.debug("Couldn't delete lock file: " + lockFilePath.toString(), e); } } |