Skip to content

Commit e6c1136

Browse files
committed
Remove outdated legacy migration code in workspace chooser
Remove the XML file-based persistence fallback that was introduced in 2004 to migrate from a custom XML file to the configuration area preference store. After 21 years any user who has launched Eclipse even once has been migrated. Removed: readPersistedData_file(), compatibleFileProtocol(), getPersistenceUrl(), the XML tag constants interface, and the related PERS_FOLDER, PERS_FILENAME, PERS_ENCODING_VERSION constants. See vogella#9
1 parent 94eabfd commit e6c1136

File tree

1 file changed

+0
-212
lines changed

1 file changed

+0
-212
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceData.java

Lines changed: 0 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@
1717
package org.eclipse.ui.internal.ide;
1818

1919
import java.io.File;
20-
import java.io.FileReader;
21-
import java.io.IOException;
22-
import java.io.Reader;
2320
import java.net.URL;
2421
import java.util.StringTokenizer;
2522

2623
import org.eclipse.core.runtime.IPath;
27-
import org.eclipse.core.runtime.Platform;
2824
import org.eclipse.core.runtime.preferences.ConfigurationScope;
2925
import org.eclipse.jface.preference.IPreferenceStore;
30-
import org.eclipse.osgi.service.datalocation.Location;
31-
import org.eclipse.ui.IMemento;
32-
import org.eclipse.ui.WorkbenchException;
33-
import org.eclipse.ui.XMLMemento;
3426
import org.eclipse.ui.ide.IDE;
3527
import org.eclipse.ui.preferences.ScopedPreferenceStore;
3628
import org.osgi.service.prefs.BackingStoreException;
@@ -46,25 +38,6 @@ public class ChooseWorkspaceData {
4638
*/
4739
private static final int RECENT_MAX_LENGTH = 10;
4840

49-
/**
50-
* The directory within the config area that will be used for the
51-
* receiver's persisted data.
52-
*/
53-
private static final String PERS_FOLDER = "org.eclipse.ui.ide"; //$NON-NLS-1$
54-
55-
/**
56-
* The name of the file within the config area that will be used for
57-
* the recever's persisted data.
58-
* @see PERS_FOLDER
59-
*/
60-
private static final String PERS_FILENAME = "recentWorkspaces.xml"; //$NON-NLS-1$
61-
62-
/**
63-
* In the past a file was used to store persist these values. This file was written
64-
* with this value as its protocol identifier.
65-
*/
66-
private static final int PERS_ENCODING_VERSION = 1;
67-
6841
/**
6942
* This is the first version of the encode/decode protocol that uses the
7043
* configuration area preference store for persistence. The only encoding
@@ -92,25 +65,6 @@ public class ChooseWorkspaceData {
9265

9366
private String[] recentWorkspaces;
9467

95-
// xml tags
96-
private static interface XML {
97-
public static final String PROTOCOL = "protocol"; //$NON-NLS-1$
98-
99-
public static final String VERSION = "version"; //$NON-NLS-1$
100-
101-
public static final String ALWAYS_ASK = "alwaysAsk"; //$NON-NLS-1$
102-
103-
public static final String SHOW_DIALOG = "showDialog"; //$NON-NLS-1$
104-
105-
public static final String WORKSPACE = "workspace"; //$NON-NLS-1$
106-
107-
public static final String RECENT_WORKSPACES = "recentWorkspaces"; //$NON-NLS-1$
108-
109-
public static final String MAX_LENGTH = "maxLength"; //$NON-NLS-1$
110-
111-
public static final String PATH = "path"; //$NON-NLS-1$
112-
}
113-
11468
/**
11569
* Creates a new instance, loading persistent data if its found.
11670
*/
@@ -278,105 +232,12 @@ public void writePersistedData() {
278232
}
279233
}
280234

281-
/**
282-
* Look for and read data that might have been persisted from some previous
283-
* run. Leave the receiver in a default state if no persistent data is
284-
* found.
285-
*
286-
* @return true if a file was successfully read and false otherwise
287-
*/
288-
private boolean readPersistedData_file() {
289-
URL persUrl = null;
290-
291-
Location configLoc = Platform.getConfigurationLocation();
292-
if (configLoc != null) {
293-
persUrl = getPersistenceUrl(configLoc.getURL(), false);
294-
}
295-
296-
try {
297-
// inside try to get the safe default creation in the finally
298-
// clause
299-
if (persUrl == null) {
300-
return false;
301-
}
302-
303-
// E.g.,
304-
// <launchWorkspaceData>
305-
// <protocol version="1"/>
306-
// <alwaysAsk showDialog="1"/>
307-
// <recentWorkspaces maxLength="5">
308-
// <workspace path="C:\eclipse\workspace0"/>
309-
// <workspace path="C:\eclipse\workspace1"/>
310-
// </recentWorkspaces>
311-
// </launchWorkspaceData>
312-
313-
XMLMemento memento;
314-
try (Reader reader = new FileReader(persUrl.getFile())) {
315-
memento = XMLMemento.createReadRoot(reader);
316-
}
317-
if (memento == null || !compatibleFileProtocol(memento)) {
318-
return false;
319-
}
320-
321-
IMemento alwaysAskTag = memento.getChild(XML.ALWAYS_ASK);
322-
showDialog = alwaysAskTag == null ? true : alwaysAskTag.getInteger(
323-
XML.SHOW_DIALOG).intValue() == 1;
324-
325-
IMemento recent = memento.getChild(XML.RECENT_WORKSPACES);
326-
if (recent == null) {
327-
return false;
328-
}
329-
330-
Integer maxLength = recent.getInteger(XML.MAX_LENGTH);
331-
int max = RECENT_MAX_LENGTH;
332-
if (maxLength != null) {
333-
max = maxLength.intValue();
334-
}
335-
336-
IMemento indices[] = recent.getChildren(XML.WORKSPACE);
337-
if (indices == null || indices.length <= 0) {
338-
return false;
339-
}
340-
341-
// if a user has edited maxLength to be shorter than the listed
342-
// indices, accept the list (its tougher for them to retype a long
343-
// list of paths than to update a max number)
344-
max = Math.max(max, indices.length);
345-
346-
recentWorkspaces = new String[max];
347-
for (int i = 0; i < indices.length; ++i) {
348-
String path = indices[i].getString(XML.PATH);
349-
if (path == null) {
350-
break;
351-
}
352-
recentWorkspaces[i] = path;
353-
}
354-
} catch (IOException | WorkbenchException e) {
355-
// cannot log because instance area has not been set
356-
return false;
357-
} finally {
358-
// create safe default if needed
359-
if (recentWorkspaces == null) {
360-
recentWorkspaces = new String[RECENT_MAX_LENGTH];
361-
}
362-
}
363-
364-
return true;
365-
}
366-
367235
/**
368236
* Return the current (persisted) value of the "showDialog on startup"
369237
* preference. Return the global default if the file cannot be accessed.
370238
*/
371239
public static boolean getShowDialogValue() {
372-
// TODO See the long comment in #readPersistedData -- when the
373-
// transition time is over this method can be changed to
374-
// read the preference directly.
375-
376240
ChooseWorkspaceData data = new ChooseWorkspaceData(""); //$NON-NLS-1$
377-
378-
// return either the value in the file or true, which is the global
379-
// default
380241
return data.readPersistedData() ? data.showDialog : true;
381242
}
382243

@@ -385,13 +246,7 @@ public static boolean getShowDialogValue() {
385246
* preference. Return the global default if the file cannot be accessed.
386247
*/
387248
public static void setShowDialogValue(boolean showDialog) {
388-
// TODO See the long comment in #readPersistedData -- when the
389-
// transition time is over this method can be changed to
390-
// read the preference directly.
391-
392249
ChooseWorkspaceData data = new ChooseWorkspaceData(""); //$NON-NLS-1$
393-
394-
// update the value and write the new settings
395250
data.showDialog = showDialog;
396251
data.writePersistedData();
397252
}
@@ -400,33 +255,14 @@ public static void setShowDialogValue(boolean showDialog) {
400255
* Look in the config area preference store for the list of recently used
401256
* workspaces.
402257
*
403-
* NOTE: During the transition phase the file will be checked if no config
404-
* preferences are found.
405-
*
406258
* @return true if the values were successfully retrieved and false
407259
* otherwise
408260
*/
409261
public boolean readPersistedData() {
410262
IPreferenceStore store = new ScopedPreferenceStore(ConfigurationScope.INSTANCE,
411263
IDEWorkbenchPlugin.IDE_WORKBENCH);
412264

413-
// The old way was to store this information in a file, the new is to
414-
// use the configuration area preference store. To help users with the
415-
// transition, this code always looks for values in the preference
416-
// store; they are used if found. If there aren't any related
417-
// preferences, then the file method is used instead. This class always
418-
// writes to the preference store, so the fall-back should be needed no
419-
// more than once per-user, per-configuration.
420-
421-
// This code always sets the value of the protocol to a non-zero value
422-
// (currently at 2). If the value comes back as the default (0), then
423-
// none of the preferences were set, revert to the file method.
424-
425265
int protocol = store.getInt(IDE.Preferences.RECENT_WORKSPACES_PROTOCOL);
426-
if (protocol == IPreferenceStore.INT_DEFAULT_DEFAULT
427-
&& readPersistedData_file()) {
428-
return true;
429-
}
430266

431267
// 2. get value for showDialog
432268
showDialog = store.getBoolean(IDE.Preferences.SHOW_WORKSPACE_SELECTION_DIALOG);
@@ -504,52 +340,4 @@ private static String[] decodeStoredWorkspacePaths(int protocol, int max, String
504340
return paths;
505341
}
506342

507-
/**
508-
* Returns true if the protocol used to encode the argument memento is
509-
* compatible with the receiver's implementation and false otherwise.
510-
*/
511-
private static boolean compatibleFileProtocol(IMemento memento) {
512-
IMemento protocolMemento = memento.getChild(XML.PROTOCOL);
513-
if (protocolMemento == null) {
514-
return false;
515-
}
516-
517-
Integer version = protocolMemento.getInteger(XML.VERSION);
518-
return version != null && version.intValue() == PERS_ENCODING_VERSION;
519-
}
520-
521-
/**
522-
* The workspace data is stored in the well known file pointed to by the result
523-
* of this method.
524-
* @param create If the directory and file does not exist this parameter
525-
* controls whether it will be created.
526-
* @return An url to the file and null if it does not exist or could not
527-
* be created.
528-
*/
529-
private static URL getPersistenceUrl(URL baseUrl, boolean create) {
530-
if (baseUrl == null) {
531-
return null;
532-
}
533-
534-
try {
535-
// make sure the directory exists
536-
URL url = new URL(baseUrl, PERS_FOLDER);
537-
File dir = new File(url.getFile());
538-
if (!dir.exists() && (!create || !dir.mkdir())) {
539-
return null;
540-
}
541-
542-
// make sure the file exists
543-
url = new URL(dir.toURL(), PERS_FILENAME);
544-
File persFile = new File(url.getFile());
545-
if (!persFile.exists() && (!create || !persFile.createNewFile())) {
546-
return null;
547-
}
548-
549-
return persFile.toURL();
550-
} catch (IOException e) {
551-
// cannot log because instance area has not been set
552-
return null;
553-
}
554-
}
555343
}

0 commit comments

Comments
 (0)