View | Details | Raw Unified | Return to bug 125965
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (-3 / +29 lines)
Lines 15-20 Link Here
15
15
16
import org.eclipse.core.resources.*;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.internal.core.JavaModelManager;
21
import org.eclipse.jdt.internal.core.JavaModelManager;
Lines 136-142 Link Here
136
// All specified tests which do not belong to the class are skipped...
137
// All specified tests which do not belong to the class are skipped...
137
static {
138
static {
138
	// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
139
	// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
139
//		TESTS_NAMES = new String[] { "testVariableInitializer10" };
140
//		TESTS_NAMES = new String[] { "testVariableInitializer11" };
140
	// Numbers of tests to run: "test<number>" will be run for each number of this array
141
	// Numbers of tests to run: "test<number>" will be run for each number of this array
141
//		TESTS_NUMBERS = new int[] { 2, 12 };
142
//		TESTS_NUMBERS = new int[] { 2, 12 };
142
	// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
143
	// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
Lines 883-891 Link Here
883
		VariablesInitializer.reset();
884
		VariablesInitializer.reset();
884
	}
885
	}
885
}
886
}
887
/**
888
 * Bug 125965: [prefs] "Export/Import preferences" should let user to choose wich preference to export/import
889
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=125965"
890
 */
891
public void testVariableInitializer11() throws CoreException {
892
	try {
893
		// Create initializer
894
		String varName = "TEST_LIB";
895
		String initialValue = "/P1/lib.jar";
896
		String newValue = "/tmp/file.jar";
897
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {varName, initialValue}));
898
		assertEquals("JavaCore classpath value should have been initialized", JavaCore.getClasspathVariable(varName).toString(), initialValue);
899
		
900
		// Modify preference
901
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
902
		IEclipsePreferences preferences = manager.getInstancePreferences();
903
		preferences.put(JavaModelManager.CP_VARIABLE_PREFERENCES_PREFIX+varName, newValue);
904
	
905
		// verify that JavaCore preferences have been reset
906
		assertEquals("JavaCore classpath value should be unchanged", JavaCore.getClasspathVariable(varName).toString(), initialValue);
907
		assertEquals("JavaCore preferences value should be unchanged", preferences.get(varName, "X"), initialValue);
908
	} finally {
909
		VariablesInitializer.reset();
910
	}
911
}
886
912
887
/*
913
/**
888
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61872
914
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=61872"
889
 */
915
 */
890
public void testUserLibraryInitializer1() throws CoreException {
916
public void testUserLibraryInitializer1() throws CoreException {
891
	try {
917
	try {
(-)model/org/eclipse/jdt/core/JavaCore.java (+1 lines)
Lines 1577-1582 Link Here
1577
						"	variable: " + variableName +'\n' + //$NON-NLS-1$
1577
						"	variable: " + variableName +'\n' + //$NON-NLS-1$
1578
						"	variable path: " + variablePath); //$NON-NLS-1$
1578
						"	variable path: " + variablePath); //$NON-NLS-1$
1579
				}
1579
				}
1580
				JavaModelManager.getJavaModelManager().initializedVariables.add(variableName);
1580
				ok = true;
1581
				ok = true;
1581
			} catch (RuntimeException e) {
1582
			} catch (RuntimeException e) {
1582
				if (JavaModelManager.CP_RESOLVE_VERBOSE) {
1583
				if (JavaModelManager.CP_RESOLVE_VERBOSE) {
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-8 / +17 lines)
Lines 83-88 Link Here
83
	 * Classpath variables pool
83
	 * Classpath variables pool
84
	 */
84
	 */
85
	public HashMap variables = new HashMap(5);
85
	public HashMap variables = new HashMap(5);
86
	public HashSet initializedVariables = new HashSet(5);
86
	public HashMap previousSessionVariables = new HashMap(5);
87
	public HashMap previousSessionVariables = new HashMap(5);
87
	private ThreadLocal variableInitializationInProgress = new ThreadLocal();
88
	private ThreadLocal variableInitializationInProgress = new ThreadLocal();
88
		
89
		
Lines 999-1009 Link Here
999
			String propertyName = event.getKey();
1000
			String propertyName = event.getKey();
1000
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1001
			if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1001
				String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1002
				String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1002
				String newValue = (String)event.getNewValue();
1003
				JavaModelManager manager = getJavaModelManager();
1003
				if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1004
				if (manager.initializedVariables.contains(varName)) {
1004
					getJavaModelManager().variables.put(varName, new Path(newValue));
1005
					// revert preference value as we will not apply it to JavaCore classpath variable
1006
					manager.getInstancePreferences().put(varName, (String)event.getOldValue());
1005
				} else {
1007
				} else {
1006
					getJavaModelManager().variables.remove(varName);
1008
					String newValue = (String)event.getNewValue();
1009
					if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1010
						manager.variables.put(varName, new Path(newValue));
1011
					} else {
1012
						manager.variables.remove(varName);
1013
					}
1007
				}
1014
				}
1008
			}
1015
			}
1009
			if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
1016
			if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
Lines 3865-3872 Link Here
3865
		}
3872
		}
3866
		return result;
3873
		return result;
3867
	}
3874
	}
3868
	
3875
3869
	public synchronized void variablePut(String variableName, IPath variablePath){		
3876
	public synchronized void variablePut(String variableName, IPath variablePath) {
3870
3877
3871
		// set/unset the initialization in progress
3878
		// set/unset the initialization in progress
3872
		HashSet initializations = variableInitializationInProgress();
3879
		HashSet initializations = variableInitializationInProgress();
Lines 3891-3900 Link Here
3891
		}
3898
		}
3892
	
3899
	
3893
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
3900
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
3894
		if (variablePath == null)
3901
		if (variablePath == null) {
3895
			getInstancePreferences().remove(variableKey);
3902
			getInstancePreferences().remove(variableKey);
3896
		else
3903
			this.initializedVariables.remove(variableName);
3904
		} else {
3897
			getInstancePreferences().put(variableKey, variablePath.toString());
3905
			getInstancePreferences().put(variableKey, variablePath.toString());
3906
		}
3898
		try {
3907
		try {
3899
			getInstancePreferences().flush();
3908
			getInstancePreferences().flush();
3900
		} catch (BackingStoreException e) {
3909
		} catch (BackingStoreException e) {

Return to bug 125965