• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 28869352089

07 Jul 2026 01:19PM UTC coverage: 72.075% (+0.009%) from 72.066%
28869352089

Pull #2128

github

web-flow
Merge 144db54d3 into 2cf3f5070
Pull Request #2128: #2123: configure Checkstyle suppression for legitimate System.out usages

4858 of 7434 branches covered (65.35%)

Branch coverage included in aggregate %.

12435 of 16559 relevant lines covered (75.1%)

3.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.29
cli/src/main/java/com/devonfw/tools/ide/locking/EclipseWorkspaceLockChecker.java
1
package com.devonfw.tools.ide.locking;
2

3
import java.io.RandomAccessFile;
4
import java.nio.channels.FileLock;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7

8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
10

11
/**
12
 * Program to check if eclipse workspace is locked. A successful exit (code {@code 0}) indicates that the workspace is free. Otherwise the exit code {@code 1}
13
 * is used to indicate that the workspace is locked. In case of an error (e.g. invalid CLI arguments) the exit code {@code -1} is used.
14
 */
15
public class EclipseWorkspaceLockChecker {
×
16

17
  private static final Logger LOG = LoggerFactory.getLogger(EclipseWorkspaceLockChecker.class);
4✔
18

19
  /**
20
   * @param args the command-line arguments. There is currently only one argument defined which is the path to the lock file.
21
   */
22
  public static void main(String[] args) {
23

24
    EclipseWorkspaceLockChecker lockChecker = new EclipseWorkspaceLockChecker();
×
25
    int exitCode = lockChecker.run(args);
×
26
    System.exit(exitCode);
×
27
  }
×
28

29
  private int run(String[] args) {
30

31
    if (args.length != 1) {
×
32
      LOG.error("Usage: {} <path2workspace>", EclipseWorkspaceLockChecker.class.getSimpleName());
×
33
      return -1;
×
34
    }
35
    Path lockfile = Path.of(args[0]);
×
36
    boolean locked = isLocked(lockfile);
×
37
    if (locked) {
×
38
      return 1;
×
39
    }
40
    return 0;
×
41
  }
42

43
  /**
44
   * @param lockfile the {@link Path} pointing to the lockfile to check.
45
   * @return {@code true} if the given {@link Path} is locked, {@code false} otherwise.
46
   */
47
  public static boolean isLocked(Path lockfile) {
48

49
    if (Files.isRegularFile(lockfile)) {
5✔
50
      try (RandomAccessFile raFile = new RandomAccessFile(lockfile.toFile(), "rw")) {
7✔
51
        FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);
7✔
52
        // success, file was not locked so we immediately unlock again...
53
        fileLock.release();
2✔
54
        return false;
4✔
55
      } catch (Exception e) {
1✔
56
        return true;
2✔
57
      }
58
    }
59
    return false;
2✔
60
  }
61

62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc