### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java,v retrieving revision 1.51 diff -u -r1.51 ClasspathInitializerTests.java --- src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java 8 Aug 2007 15:28:12 -0000 1.51 +++ src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java 18 Aug 2007 17:52:48 -0000 @@ -1317,6 +1317,50 @@ } /** + * @bug 186113: [model] classpath variable deprecation messages not initialized when called + * @test a) Verify that deprecation message can be get through {@link JavaCore#getClasspathVariableDeprecationMessage(String)} + * even if the variable initializer was not called before + * b) Verify that message is not stored in cache when variable is not initialized (othwerise we could not free it up...) + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186113" + */ +public void testVariableInitializerBug186113a() throws CoreException { + assertEquals("Invalid deprecation message!", + "Test deprecated flag", + JavaCore.getClasspathVariableDeprecationMessage("TEST_DEPRECATED") + ); +} +public void testVariableInitializerBug186113b() throws CoreException { + JavaCore.getClasspathVariableDeprecationMessage("TEST_DEPRECATED"); + assertNull("Deprecation message should not have been stored!", JavaModelManager.getJavaModelManager().deprecatedVariables.get("TEST_DEPRECATED")); +} + +/** + * @bug 200449: [model] classpath variable deprecation messages not initialized when called + * @test a) Verify that deprecation message is well stored in cache when variable is iniatialized + * b) Verify that deprecation message is well removed in cache when variable is removed + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=200449" + */ +public void testVariableInitializerBug200449() throws CoreException { + try { + // Create initializer + String varName = "TEST_DEPRECATED"; + String filePath = "/P1/lib.jar"; + VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {varName, filePath})); + JavaCore.getClasspathVariable(varName); // init variable + + // Verify that deprecation message has been stored + assertNotNull("Deprecation message should have been stored!", JavaModelManager.getJavaModelManager().deprecatedVariables.get("TEST_DEPRECATED")); + } finally { + VariablesInitializer.reset(); + deleteProject("P1"); + } +} +public void testVariableInitializerBug200449b() throws CoreException { + // Verify that deprecated variable has been removed + assertNull("Deprecation message should have been removed!", JavaModelManager.getJavaModelManager().deprecatedVariables.get("TEST_DEPRECATED")); +} + +/** * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=61872" */ public void testUserLibraryInitializer1() throws CoreException { #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.373 diff -u -r1.373 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 17 Aug 2007 11:23:07 -0000 1.373 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 18 Aug 2007 17:53:12 -0000 @@ -175,7 +175,7 @@ public IPath getPath() { return null; } public String toString() { return getDescription(); } }; - + private static final String BUFFER_MANAGER_DEBUG = JavaCore.PLUGIN_ID + "/debug/buffermanager" ; //$NON-NLS-1$ private static final String INDEX_MANAGER_DEBUG = JavaCore.PLUGIN_ID + "/debug/indexmanager" ; //$NON-NLS-1$ private static final String COMPILER_DEBUG = JavaCore.PLUGIN_ID + "/debug/compiler" ; //$NON-NLS-1$ @@ -4274,6 +4274,9 @@ // if path is null, record that the variable was removed to avoid asking the initializer to initialize it again // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=112609 this.variables.put(variableName, CP_ENTRY_IGNORE_PATH); + // clean other variables caches + this.variablesWithInitializer.remove(variableName); + this.deprecatedVariables.remove(variableName); } else { this.variables.put(variableName, variablePath); } @@ -4285,7 +4288,6 @@ public void variablePreferencesPut(String variableName, IPath variablePath) { String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName; if (variablePath == null) { - this.variablesWithInitializer.remove(variableName); getInstancePreferences().remove(variableKey); } else { getInstancePreferences().put(variableKey, variablePath.toString()); Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.577 diff -u -r1.577 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 1 Jun 2007 13:52:19 -0000 1.577 +++ model/org/eclipse/jdt/core/JavaCore.java 18 Aug 2007 17:53:03 -0000 @@ -1749,10 +1749,47 @@ * * @param variableName * @return A string if the classpath variable is deprecated, null otherwise. + * {@link JavaModelManager#VARIABLE_INITIALIZATION_IN_PROGRESS_MESSAGE} special + * string is returned when classpath variable was not initialized or if its initialization is not finished. * @since 3.3 */ public static String getClasspathVariableDeprecationMessage(String variableName) { - return (String) JavaModelManager.getJavaModelManager().deprecatedVariables.get(variableName); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + + // Returns the stored deprecation message + String message = (String) manager.deprecatedVariables.get(variableName); + if (message != null) { + return message; + } + + // If the variable has been already initialized, then there's no deprecation message + IPath variablePath = manager.variableGet(variableName); + if (variablePath != null && variablePath != JavaModelManager.VARIABLE_INITIALIZATION_IN_PROGRESS) { + return null; + } + + // Search for extension point to get the possible deprecation message + Plugin jdtCorePlugin = JavaCore.getPlugin(); + if (jdtCorePlugin == null) return null; + + IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID); + if (extension != null) { + IExtension[] extensions = extension.getExtensions(); + for(int i = 0; i < extensions.length; i++){ + IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); + for(int j = 0; j < configElements.length; j++){ + IConfigurationElement configElement = configElements[j]; + String varAttribute = configElement.getAttribute("variable"); //$NON-NLS-1$ + if (variableName.equals(varAttribute)) { + String deprecatedAttribute = configElement.getAttribute("deprecated"); //$NON-NLS-1$ + if (deprecatedAttribute != null) { + return deprecatedAttribute; + } + } + } + } + } + return null; } /**