Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.ui.ide.application;singleton:=true
Bundle-Version: 1.6.0.qualifier
Bundle-Version: 1.6.100.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.21.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.19.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.208.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.209.0,4.0.0)",
org.eclipse.ui.navigator.resources;bundle-version="[3.9.0,4.0.0)",
org.eclipse.core.net;bundle-version="[1.5.0,2.0.0)",
org.eclipse.core.filesystem;bundle-version="1.10.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2020 IBM Corporation and others.
* Copyright (c) 2003, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -24,11 +24,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -42,7 +40,6 @@
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.equinox.app.IApplication;
Expand All @@ -65,6 +62,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.WorkspaceLock;
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
Expand All @@ -89,19 +87,10 @@ public class IDEApplication implements IApplication, IExecutableExtension {

private static final String VERSION_FILENAME = "version.ini"; //$NON-NLS-1$

private static final Path LOCK_INFO_FILE = Path.of(METADATA_FOLDER, ".lock_info"); //$NON-NLS-1$

private static final String DISPLAY_VAR = "DISPLAY"; //$NON-NLS-1$

private static final String HOST_NAME_VAR = "HOSTNAME"; //$NON-NLS-1$

private static final String PROCESS_ID = "process-id"; //$NON-NLS-1$

private static final String DISPLAY = "display"; //$NON-NLS-1$

private static final String HOST = "host"; //$NON-NLS-1$

private static final String USER = "user"; //$NON-NLS-1$

private static final String USER_NAME = "user.name"; //$NON-NLS-1$

Expand Down Expand Up @@ -223,12 +212,13 @@ public void setInitializationData(IConfigurationElement config,
}

/**
* Return <code>null</code> if a valid workspace path has been set and an exit code otherwise.
* Prompt for and set the path if possible and required.
* Returns <code>null</code> if a valid workspace has been selected or locked
* successfully, and an exit code otherwise. Prompts for and sets the workspace
* path if required.
*
* @param applicationArguments the command line arguments
* @return <code>null</code> if a valid instance location has been set and an exit code
* otherwise
* @return <code>null</code> if a valid instance location has been set and an
* exit code otherwise
*/
@SuppressWarnings("rawtypes")
protected Object checkInstanceLocation(Shell shell, Map applicationArguments) {
Expand Down Expand Up @@ -273,29 +263,29 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) {
return EXIT_WORKSPACE_LOCKED;
}

String wsLockedError = NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage,
workspaceDirectory.getAbsolutePath());
// check if there is a lock info then append it to error message.
String lockInfo = getWorkspaceLockInfo(instanceLoc.getURL());
if (lockInfo != null && !lockInfo.isBlank()) {
wsLockedError = wsLockedError + System.lineSeparator() + System.lineSeparator()
+ NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Message, lockInfo);
String lockInfo = WorkspaceLock.getWorkspaceLockDetails(instanceLoc.getURL());
if (lockInfo != null) {
hideSplash(shell);
WorkspaceLock.showWorkspaceLockedDialog(shell, workspaceDirectory.getAbsolutePath(),
lockInfo);
} else {
hideSplash(shell);
MessageDialog.openError(shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
MessageDialog.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle,
wsLockedError);
} else {
hideSplash(shell);
MessageDialog.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}
} catch (IOException e) {
IDEWorkbenchPlugin.log("Could not obtain lock for workspace location", //$NON-NLS-1$
e);
MessageDialog
.openError(
hideSplash(shell);
IDEWorkbenchPlugin.log("Could not obtain lock for workspace location", e); //$NON-NLS-1$
MessageDialog.openError(
shell,
IDEWorkbenchMessages.InternalError,
e.getMessage());
Expand All @@ -311,12 +301,10 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) {
// -data is specified but invalid according to checkValidWorkspace(): re-launch
ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc.getDefault());

boolean parentShellVisible = false;
if (isValid(shell)) {
parentShellVisible = shell.getVisible();
// bug 455162, bug 427393: hide the splash if the workspace
// prompt dialog should be opened
if (parentShellVisible && launchData.getShowDialog()) {
if (shell.getVisible() && launchData.getShowDialog()) {
shell.setVisible(false);
}
}
Expand Down Expand Up @@ -349,7 +337,15 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) {
try {
if (instanceLoc.isSet()) {
// restart with new location
return Workbench.setRestartArguments(workspaceUrl.getFile());
Object workbenchExitCode = Workbench.setRestartArguments(workspaceUrl.getFile());
// "null" workbenchExitCode indicates an error: application is running in
// development mode and doesn't support restart.
if (workbenchExitCode == null) {
// No error to show, it was shown in Workbench.setRestartArguments() already.
// Just exit.
return EXIT_OK;
}
return workbenchExitCode;
}

// the operation will fail if the url is not a valid
Expand All @@ -360,25 +356,18 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) {
writeWsLockInfo(instanceLoc.getURL());
return null;
}
} catch (IllegalStateException e) {
} catch (IOException | IllegalStateException e) {
MessageDialog
.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
return EXIT_OK;
} catch (IOException e) {
MessageDialog
.openError(
shell,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
}

// by this point it has been determined that the workspace is
// already in use -- force the user to choose again

String lockInfo = getWorkspaceLockInfo(workspaceUrl);
String lockInfo = WorkspaceLock.getWorkspaceLockDetails(workspaceUrl);

MessageDialog dialog = new MessageDialog(null, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle,
null, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getFile()),
Expand Down Expand Up @@ -412,49 +401,6 @@ protected Control createCustomArea(Composite parent) {
}
}

/**
* Read workspace lock file and parse all the properties present. Based on the
* eclipse version and operating system some or all the properties may not
* present. In such scenario it will return empty string.
*
* @return Previous lock owner details.
*/
protected String getWorkspaceLockInfo(URL workspaceUrl) {
try {
Path lockFile = getLockInfoFile(workspaceUrl);
if (!Files.exists(lockFile)) {
return null;
}

StringBuilder sb = new StringBuilder();
Properties props = new Properties();
try (InputStream is = Files.newInputStream(lockFile)) {
props.load(is);
String prop = props.getProperty(USER);
if (prop != null) {
sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_User, prop));
}
prop = props.getProperty(HOST);
if (prop != null) {
sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Host, prop));
}
prop = props.getProperty(DISPLAY);
if (prop != null) {
sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Disp, prop));
}
prop = props.getProperty(PROCESS_ID);
if (prop != null) {
sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_P_Id, prop));
}
return sb.toString();
}
} catch (Exception e) {
IDEWorkbenchPlugin.log("Could not read lock info file: ", e); //$NON-NLS-1$

}
return null;
}

/**
* Write lock owner details onto workspace lock file. Data includes user, host,
* display and current java process id.
Expand All @@ -464,19 +410,19 @@ protected void writeWsLockInfo(URL workspaceUrl) {

String user = System.getProperty(USER_NAME);
if (user != null) {
props.setProperty(USER, user);
props.setProperty(WorkspaceLock.USER, user);
}
String host = getHostName();
if (host != null) {
props.setProperty(HOST, host);
props.setProperty(WorkspaceLock.HOST, host);
}
String display = getDisplay();
if (display != null) {
props.setProperty(DISPLAY, display);
props.setProperty(WorkspaceLock.DISPLAY, display);
}
String pid = getProcessId();
if (pid != null) {
props.setProperty(PROCESS_ID, pid);
props.setProperty(WorkspaceLock.PROCESS_ID, pid);
}

if (props.isEmpty()) {
Expand Down Expand Up @@ -532,28 +478,14 @@ private String getHostName() {
return hostName;
}

/**
* Returns the .lock_info file. Does not check if it exists.
*
* @param workspaceUrl
* @return .lock_info file.
*/
private static Path getLockInfoFile(URL workspaceUrl) {
try {
return Path.of(URIUtil.toURI(workspaceUrl)).resolve(LOCK_INFO_FILE);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}

/**
* Creates the .lock_info file if it does not exist.
*
* @param workspaceUrl
* @return .lock_info file.
*/
private static Path createLockInfoFile(URL workspaceUrl) throws Exception {
Path lockInfoFile = getLockInfoFile(workspaceUrl);
Path lockInfoFile = WorkspaceLock.getLockInfoFile(workspaceUrl);
if (!Files.exists(lockInfoFile)) {
Files.createFile(lockInfoFile);
}
Expand Down Expand Up @@ -736,9 +668,7 @@ protected Shell getParentShell() {
}
};
// hide splash if any
if (isValid(shell)) {
shell.setVisible(false);
}
hideSplash(shell);

int returnCode = dialog.open();
if (returnCode == IDialogConstants.RETRY_ID || returnCode == SWT.DEFAULT) {
Expand All @@ -759,6 +689,12 @@ protected Shell getParentShell() {
return ReturnCode.VALID;
}

protected void hideSplash(Shell shell) {
if (isValid(shell)) {
shell.setVisible(false);
}
}

/**
* Compares the version of the workspace with the specified URL, to the version
* of the running IDE.
Expand Down Expand Up @@ -929,4 +865,4 @@ public void stop() {
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2017 IBM Corporation and others.
* Copyright (c) 2005, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1050,8 +1050,6 @@ public class IDEWorkbenchMessages extends NLS {
public static String IDEApplication_workspaceInvalidMessage;
public static String IDEApplication_workspaceCannotBeSetTitle;
public static String IDEApplication_workspaceCannotBeSetMessage;
public static String IDEApplication_workspaceCannotLockTitle;
public static String IDEApplication_workspaceCannotLockMessage;
public static String IDEApplication_versionTitle_newerWorkspace;
public static String IDEApplication_versionTitle_olderWorkspace;
public static String IDEApplication_versionMessage_newerWorkspace;
Expand Down Expand Up @@ -1147,13 +1145,7 @@ public class IDEWorkbenchMessages extends NLS {

public static String WorkbenchPreference_maxSimultaneousBuilds;
public static String WorkbenchPreference_maxSimultaneousBuildIntervalError;

public static String IDEApplication_Ws_Lock_Owner_User;
public static String IDEApplication_Ws_Lock_Owner_Host;
public static String IDEApplication_Ws_Lock_Owner_Disp;
public static String IDEApplication_Ws_Lock_Owner_P_Id;
public static String IDEApplication_Ws_Lock_Owner_Message;

static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, IDEWorkbenchMessages.class);
Expand Down
Loading
Loading