View | Details | Raw Unified | Return to bug 154984 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/UserLibraryManager.java (-13 / +29 lines)
Lines 42-47 Link Here
42
	public final static String CP_ENTRY_IGNORE = "##<cp entry ignore>##"; //$NON-NLS-1$
42
	public final static String CP_ENTRY_IGNORE = "##<cp entry ignore>##"; //$NON-NLS-1$
43
43
44
	private static Map userLibraries;
44
	private static Map userLibraries;
45
	private static boolean userLibrariesInitialized = false;
45
	private static final boolean logProblems= false;
46
	private static final boolean logProblems= false;
46
	private static IEclipsePreferences.IPreferenceChangeListener listener= new IEclipsePreferences.IPreferenceChangeListener() {
47
	private static IEclipsePreferences.IPreferenceChangeListener listener= new IEclipsePreferences.IPreferenceChangeListener() {
47
48
Lines 49-55 Link Here
49
			String key= event.getKey();
50
			String key= event.getKey();
50
			if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
51
			if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
51
				try {
52
				try {
52
					recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true);
53
					recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true, true);
53
				} catch (JavaModelException e) {
54
				} catch (JavaModelException e) {
54
					if (logProblems) {
55
					if (logProblems) {
55
						Util.log(e, "Exception while rebinding user library '"+ key.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()) +"'."); //$NON-NLS-1$ //$NON-NLS-2$
56
						Util.log(e, "Exception while rebinding user library '"+ key.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()) +"'."); //$NON-NLS-1$ //$NON-NLS-2$
Lines 74-79 Link Here
74
		return (String[]) set.toArray(new String[set.size()]);
75
		return (String[]) set.toArray(new String[set.size()]);
75
	}
76
	}
76
	
77
	
78
	private static synchronized void allocateUserLibraries() {
79
		if (userLibraries == null) {
80
			userLibraries = new HashMap();
81
		}
82
	}
83
	
77
	/**
84
	/**
78
	 * Gets the library for a given name or <code>null</code> if no such library exists.
85
	 * Gets the library for a given name or <code>null</code> if no such library exists.
79
	 * @param name The name of the library
86
	 * @param name The name of the library
Lines 102-108 Link Here
102
		try {
109
		try {
103
			int last= newNames.length - 1;
110
			int last= newNames.length - 1;
104
			for (int i= 0; i < newLibs.length; i++) {
111
			for (int i= 0; i < newLibs.length; i++) {
105
				internalSetUserLibrary(newNames[i], newLibs[i], i == last, true, new SubProgressMonitor(monitor, 1));
112
				internalSetUserLibrary(newNames[i], newLibs[i], i == last, true, true, new SubProgressMonitor(monitor, 1));
106
			}
113
			}
107
		} finally {
114
		} finally {
108
			monitor.done();
115
			monitor.done();
Lines 118-129 Link Here
118
	 * @throws JavaModelException
125
	 * @throws JavaModelException
119
	 */
126
	 */
120
	public static void setUserLibrary(String name, UserLibrary library, IProgressMonitor monitor) throws JavaModelException {
127
	public static void setUserLibrary(String name, UserLibrary library, IProgressMonitor monitor) throws JavaModelException {
121
		internalSetUserLibrary(name, library, true, true, monitor);
128
		internalSetUserLibrary(name, library, true, true, true, monitor);
122
	}
129
	}
123
	
130
	
124
	static Map getLibraryMap() {
131
	static Map getLibraryMap() {
125
		if (userLibraries == null) {
132
		if (! userLibrariesInitialized) {
126
			userLibraries= new HashMap();
133
			allocateUserLibraries();
134
			
127
			// load variables and containers from preferences into cache
135
			// load variables and containers from preferences into cache
128
			IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
136
			IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
129
			instancePreferences.addPreferenceChangeListener(listener);
137
			instancePreferences.addPreferenceChangeListener(listener);
Lines 137-143 Link Here
137
						try {
145
						try {
138
							String propertyValue = instancePreferences.get(propertyName, null);
146
							String propertyValue = instancePreferences.get(propertyName, null);
139
							if (propertyValue != null)
147
							if (propertyValue != null)
140
								recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false);
148
								recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false, false);
141
						} catch (JavaModelException e) {
149
						} catch (JavaModelException e) {
142
							// won't happen: no rebinding
150
							// won't happen: no rebinding
143
						}
151
						}
Lines 146-183 Link Here
146
			} catch (BackingStoreException e) {
154
			} catch (BackingStoreException e) {
147
				// nothing to do in this case
155
				// nothing to do in this case
148
			}
156
			}
157
			userLibrariesInitialized = true;
149
		}
158
		}
150
		return userLibraries;
159
		return userLibraries;
151
	}
160
	}
152
	
161
	
153
	static void recreatePersistedUserLibraryEntry(String propertyName, String savedString, boolean save, boolean rebind) throws JavaModelException {
162
	static void recreatePersistedUserLibraryEntry(String propertyName, String savedString, boolean save, boolean rebind, boolean getLibraryMap) throws JavaModelException {
154
		String libName= propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length());
163
		String libName= propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length());
155
		if (savedString == null || savedString.equals(CP_ENTRY_IGNORE)) {
164
		if (savedString == null || savedString.equals(CP_ENTRY_IGNORE)) {
156
			internalSetUserLibrary(libName, null, save, rebind, null);
165
			internalSetUserLibrary(libName, null, save, rebind, getLibraryMap, null);
157
		} else {
166
		} else {
158
			try {
167
			try {
159
				StringReader reader = new StringReader(savedString);
168
				StringReader reader = new StringReader(savedString);
160
				UserLibrary library= UserLibrary.createFromString(reader);
169
				UserLibrary library= UserLibrary.createFromString(reader);
161
				internalSetUserLibrary(libName, library, save, rebind, null);
170
				internalSetUserLibrary(libName, library, save, rebind, getLibraryMap, null);
162
			} catch (IOException e) {
171
			} catch (IOException e) {
163
				if (logProblems) {
172
				if (logProblems) {
164
					Util.log(e, "Exception while retrieving user library '"+ propertyName +"', library will be removed."); //$NON-NLS-1$ //$NON-NLS-2$
173
					Util.log(e, "Exception while retrieving user library '"+ propertyName +"', library will be removed."); //$NON-NLS-1$ //$NON-NLS-2$
165
				}
174
				}
166
				internalSetUserLibrary(libName, null, save, rebind, null);
175
				internalSetUserLibrary(libName, null, save, rebind, getLibraryMap, null);
167
			}
176
			}
168
		}
177
		}
169
	}
178
	}
170
179
171
180
172
181
173
	static void internalSetUserLibrary(String name, UserLibrary library, boolean save, boolean rebind, IProgressMonitor monitor) throws JavaModelException {
182
	static void internalSetUserLibrary(String name, UserLibrary library, boolean save, boolean rebind, boolean getLibraryMap, IProgressMonitor monitor) throws JavaModelException {
183
		if (getLibraryMap) {
184
			if (! userLibrariesInitialized) {
185
				getLibraryMap();
186
			}
187
		} else if (userLibraries == null) { // should not happen except on direct external call
188
			allocateUserLibraries();
189
		}
174
		if (library == null) {
190
		if (library == null) {
175
			Object previous= getLibraryMap().remove(name);
191
			Object previous= userLibraries.remove(name);
176
			if (previous == null) {
192
			if (previous == null) {
177
				return; // no change
193
				return; // no change
178
			}
194
			}
179
		} else {
195
		} else {
180
			Object previous= getLibraryMap().put(name, library);
196
			Object previous= userLibraries.put(name, library);
181
			if (library.equals(previous)) {
197
			if (library.equals(previous)) {
182
				return; // no change
198
				return; // no change
183
			}
199
			}

Return to bug 154984