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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

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

3
import java.io.File;
4
import java.io.RandomAccessFile;
5
import java.nio.channels.FileLock;
6

7
/**
8
 * 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}
9
 * 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.
10
 */
11
public class EclipseWorkspaceLockChecker {
×
12

13
  /**
14
   * @param args the command-line arguments. There is currently only one argument defined which is the path to the lock file.
15
   */
16
  public static void main(String[] args) {
17

18
    EclipseWorkspaceLockChecker lockChecker = new EclipseWorkspaceLockChecker();
×
19
    int exitCode = lockChecker.run(args);
×
20
    System.exit(exitCode);
×
21
  }
×
22

23
  private int run(String[] args) {
24

25
    if (args.length != 1) {
×
26
      System.out.println("Usage: " + EclipseWorkspaceLockChecker.class.getSimpleName() + " <path2workspace>");
×
27
      return -1;
×
28
    }
29
    File lockfile = new File(args[0]);
×
30
    boolean locked = isLocked(lockfile);
×
31
    if (locked) {
×
32
      return 1;
×
33
    }
34
    return 0;
×
35
  }
36

37
  /**
38
   * @param lockfile the {@link File} pointing to the lockfile to check.
39
   * @return {@code true} if the given {@link File} is locked, {@code false} otherwise.
40
   */
41
  public static boolean isLocked(File lockfile) {
42

43
    if (lockfile.isFile()) {
×
44
      try (RandomAccessFile raFile = new RandomAccessFile(lockfile, "rw")) {
×
45
        FileLock fileLock = raFile.getChannel().tryLock(0, 1, false);
×
46
        // success, file was not locked so we immediately unlock again...
47
        fileLock.release();
×
48
        return false;
×
49
      } catch (Exception e) {
×
50
        return true;
×
51
      }
52
    }
53
    return false;
×
54
  }
55

56
}
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

© 2025 Coveralls, Inc