|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2003, 2020 IBM Corporation and others. |
| 2 | + * Copyright (c) 2003, 2025 IBM Corporation and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials |
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0 |
|
24 | 24 | import java.io.FileInputStream; |
25 | 25 | import java.io.FileOutputStream; |
26 | 26 | import java.io.IOException; |
27 | | -import java.io.InputStream; |
28 | 27 | import java.io.OutputStream; |
29 | 28 | import java.net.InetAddress; |
30 | 29 | import java.net.MalformedURLException; |
31 | | -import java.net.URISyntaxException; |
32 | 30 | import java.net.URL; |
33 | 31 | import java.nio.file.Files; |
34 | 32 | import java.nio.file.Path; |
|
42 | 40 | import org.eclipse.core.runtime.OperationCanceledException; |
43 | 41 | import org.eclipse.core.runtime.Platform; |
44 | 42 | import org.eclipse.core.runtime.Status; |
45 | | -import org.eclipse.core.runtime.URIUtil; |
46 | 43 | import org.eclipse.core.runtime.jobs.Job; |
47 | 44 | import org.eclipse.core.runtime.preferences.ConfigurationScope; |
48 | 45 | import org.eclipse.equinox.app.IApplication; |
@@ -89,8 +86,6 @@ public class IDEApplication implements IApplication, IExecutableExtension { |
89 | 86 |
|
90 | 87 | private static final String VERSION_FILENAME = "version.ini"; //$NON-NLS-1$ |
91 | 88 |
|
92 | | - private static final Path LOCK_INFO_FILE = Path.of(METADATA_FOLDER, ".lock_info"); //$NON-NLS-1$ |
93 | | - |
94 | 89 | private static final String DISPLAY_VAR = "DISPLAY"; //$NON-NLS-1$ |
95 | 90 |
|
96 | 91 | private static final String HOST_NAME_VAR = "HOSTNAME"; //$NON-NLS-1$ |
@@ -223,12 +218,13 @@ public void setInitializationData(IConfigurationElement config, |
223 | 218 | } |
224 | 219 |
|
225 | 220 | /** |
226 | | - * Return <code>null</code> if a valid workspace path has been set and an exit code otherwise. |
227 | | - * Prompt for and set the path if possible and required. |
| 221 | + * Returns <code>null</code> if a valid workspace has been selected or locked |
| 222 | + * successfully, and an exit code otherwise. Prompts for and sets the workspace |
| 223 | + * path if required. |
228 | 224 | * |
229 | 225 | * @param applicationArguments the command line arguments |
230 | | - * @return <code>null</code> if a valid instance location has been set and an exit code |
231 | | - * otherwise |
| 226 | + * @return <code>null</code> if a valid instance location has been set and an |
| 227 | + * exit code otherwise |
232 | 228 | */ |
233 | 229 | @SuppressWarnings("rawtypes") |
234 | 230 | protected Object checkInstanceLocation(Shell shell, Map applicationArguments) { |
@@ -273,18 +269,11 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) { |
273 | 269 | return EXIT_WORKSPACE_LOCKED; |
274 | 270 | } |
275 | 271 |
|
276 | | - String wsLockedError = NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage, |
277 | | - workspaceDirectory.getAbsolutePath()); |
278 | 272 | // check if there is a lock info then append it to error message. |
279 | | - String lockInfo = getWorkspaceLockInfo(instanceLoc.getURL()); |
280 | | - if (lockInfo != null && !lockInfo.isBlank()) { |
281 | | - wsLockedError = wsLockedError + System.lineSeparator() + System.lineSeparator() |
282 | | - + NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Message, lockInfo); |
| 273 | + String lockInfo = Workbench.getWorkspaceLockDetails(instanceLoc.getURL()); |
| 274 | + if (lockInfo != null) { |
| 275 | + Workbench.showWorkspaceLockedDialog(workspaceDirectory.getAbsolutePath(), lockInfo); |
283 | 276 | } |
284 | | - MessageDialog.openError( |
285 | | - shell, |
286 | | - IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle, |
287 | | - wsLockedError); |
288 | 277 | } else { |
289 | 278 | MessageDialog.openError( |
290 | 279 | shell, |
@@ -378,7 +367,7 @@ protected Object checkInstanceLocation(Shell shell, Map applicationArguments) { |
378 | 367 | // by this point it has been determined that the workspace is |
379 | 368 | // already in use -- force the user to choose again |
380 | 369 |
|
381 | | - String lockInfo = getWorkspaceLockInfo(workspaceUrl); |
| 370 | + String lockInfo = Workbench.getWorkspaceLockDetails(workspaceUrl); |
382 | 371 |
|
383 | 372 | MessageDialog dialog = new MessageDialog(null, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle, |
384 | 373 | null, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getFile()), |
@@ -412,49 +401,6 @@ protected Control createCustomArea(Composite parent) { |
412 | 401 | } |
413 | 402 | } |
414 | 403 |
|
415 | | - /** |
416 | | - * Read workspace lock file and parse all the properties present. Based on the |
417 | | - * eclipse version and operating system some or all the properties may not |
418 | | - * present. In such scenario it will return empty string. |
419 | | - * |
420 | | - * @return Previous lock owner details. |
421 | | - */ |
422 | | - protected String getWorkspaceLockInfo(URL workspaceUrl) { |
423 | | - try { |
424 | | - Path lockFile = getLockInfoFile(workspaceUrl); |
425 | | - if (!Files.exists(lockFile)) { |
426 | | - return null; |
427 | | - } |
428 | | - |
429 | | - StringBuilder sb = new StringBuilder(); |
430 | | - Properties props = new Properties(); |
431 | | - try (InputStream is = Files.newInputStream(lockFile)) { |
432 | | - props.load(is); |
433 | | - String prop = props.getProperty(USER); |
434 | | - if (prop != null) { |
435 | | - sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_User, prop)); |
436 | | - } |
437 | | - prop = props.getProperty(HOST); |
438 | | - if (prop != null) { |
439 | | - sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Host, prop)); |
440 | | - } |
441 | | - prop = props.getProperty(DISPLAY); |
442 | | - if (prop != null) { |
443 | | - sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_Disp, prop)); |
444 | | - } |
445 | | - prop = props.getProperty(PROCESS_ID); |
446 | | - if (prop != null) { |
447 | | - sb.append(NLS.bind(IDEWorkbenchMessages.IDEApplication_Ws_Lock_Owner_P_Id, prop)); |
448 | | - } |
449 | | - return sb.toString(); |
450 | | - } |
451 | | - } catch (Exception e) { |
452 | | - IDEWorkbenchPlugin.log("Could not read lock info file: ", e); //$NON-NLS-1$ |
453 | | - |
454 | | - } |
455 | | - return null; |
456 | | - } |
457 | | - |
458 | 404 | /** |
459 | 405 | * Write lock owner details onto workspace lock file. Data includes user, host, |
460 | 406 | * display and current java process id. |
@@ -532,28 +478,14 @@ private String getHostName() { |
532 | 478 | return hostName; |
533 | 479 | } |
534 | 480 |
|
535 | | - /** |
536 | | - * Returns the .lock_info file. Does not check if it exists. |
537 | | - * |
538 | | - * @param workspaceUrl |
539 | | - * @return .lock_info file. |
540 | | - */ |
541 | | - private static Path getLockInfoFile(URL workspaceUrl) { |
542 | | - try { |
543 | | - return Path.of(URIUtil.toURI(workspaceUrl)).resolve(LOCK_INFO_FILE); |
544 | | - } catch (URISyntaxException e) { |
545 | | - throw new IllegalArgumentException(e); |
546 | | - } |
547 | | - } |
548 | | - |
549 | 481 | /** |
550 | 482 | * Creates the .lock_info file if it does not exist. |
551 | 483 | * |
552 | 484 | * @param workspaceUrl |
553 | 485 | * @return .lock_info file. |
554 | 486 | */ |
555 | 487 | private static Path createLockInfoFile(URL workspaceUrl) throws Exception { |
556 | | - Path lockInfoFile = getLockInfoFile(workspaceUrl); |
| 488 | + Path lockInfoFile = Workbench.getLockInfoFile(workspaceUrl); |
557 | 489 | if (!Files.exists(lockInfoFile)) { |
558 | 490 | Files.createFile(lockInfoFile); |
559 | 491 | } |
|
0 commit comments