Class WorkspaceLock

java.lang.Object
org.eclipse.ui.internal.WorkspaceLock

public class WorkspaceLock extends Object
Utility class for reading and presenting workspace lock information.

This class is used during two different phases of the Eclipse application lifecycle:

  • before the Workbench is created (no workbench windows exist, such as when the Workspace Launcher dialog is displayed)
  • after the Workbench has been created and workbench windows are available

To support both environments, this class does not rely on workbench-specific APIs such as PlatformUI.getWorkbench() or IWorkbenchWindow, nor on any API that requires an initialized workbench window. Only SWT-level constructs (for example, Display and Shell) and core/runtime APIs are used.

  • Field Details

  • Constructor Details

    • WorkspaceLock

      public WorkspaceLock()
  • Method Details

    • getWorkspaceLockDetails

      public static String getWorkspaceLockDetails(URL workspaceUrl)
      Read workspace lock file of the selected workspace if it is locked by another Eclipse application and parse all the properties present. Based on the Eclipse version and operating system some or all the properties may be not present. In such scenario empty string may be returned.
      Parameters:
      workspaceUrl - the URL of workspace to check for lock details
      Returns:
      null if workspace is not locked, empty string if workspace is locked but no details are available (or lock file is not accessible), or a formatted string with lock details
    • getLockInfoFile

      public static Path getLockInfoFile(URL workspaceUrl)
      Returns the lock info file (the file where information about last workspace lock owner is saved).
      Parameters:
      workspaceUrl - the URL of selected workspace
      Returns:
      the path to the .lock_info file within the specified workspace, or null if the workspace URL cannot be converted to a valid URI
    • getLockFile

      public static Path getLockFile(URL workspaceUrl)
      Returns the workspace lock file for given workspace URL (the file which is actually locked if an Eclipse application is using this workspace).
      Parameters:
      workspaceUrl - the URL of selected workspace
      Returns:
      the path to the .lock file within the specified workspace, or null if the workspace URL cannot be converted to a valid URI
    • showWorkspaceLockedDialog

      public static void showWorkspaceLockedDialog(Shell shell, String workspacePath, String workspaceLockOwner)
      Opens an error dialog indicating that the selected workspace is locked by another Eclipse instance.

      This method works in both early startup (before the Workbench is created) and in normal runtime (after Workbench windows exist).

      Parameters:
      shell - the parent Shell for the dialog, or null if no workbench window is available
      workspacePath - the absolute path of the workspace that could not be locked
      workspaceLockOwner - a formatted description of the existing lock owner
    • isWorkspaceLocked

      public static boolean isWorkspaceLocked(URL workspaceUrl)
      Checks if the given workspace path is locked by another Eclipse instance.
      Parameters:
      workspaceUrl - the URL of workspace to check for lock
      Returns:
      true if the workspace is locked, false otherwise