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

devonfw / IDEasy / 7256888795

19 Dec 2023 03:13AM UTC coverage: 46.638%. First build
7256888795

Pull #150

github

web-flow
Merge a0eb88fa8 into 1d60d9c17
Pull Request #150: #102: implement update commandlet

1031 of 2451 branches covered (0.0%)

Branch coverage included in aggregate %.

2742 of 5639 relevant lines covered (48.63%)

2.0 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
9
 * free. Otherwise the exit code {@code 1} is used to indicate that the workspace is locked. In case of an error (e.g.
10
 * invalid CLI arguments) the exit code {@code -1} is used.
11
 */
12
public class EclipseWorkspaceLockChecker {
×
13

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

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

25
  private int run(String[] args) {
26

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

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

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

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