Bug 138599 - [model][classpath] Need a way to mark a classpath variable as deprecated
Summary: [model][classpath] Need a way to mark a classpath variable as deprecated
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2006-04-26 06:56 EDT by Martin Aeschlimann CLA
Modified: 2009-04-01 12:48 EDT (History)
4 users (show)

See Also:


Attachments
Proposed patch (41.80 KB, patch)
2007-01-10 13:42 EST, Frederic Fusier CLA
no flags Details | Diff
Complete proposed patch (48.53 KB, patch)
2007-01-14 06:57 EST, Frederic Fusier CLA
no flags Details | Diff
Fixed complete proposed patch (69.89 KB, patch)
2007-01-16 13:10 EST, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (54.89 KB, patch)
2007-01-18 09:38 EST, Frederic Fusier CLA
no flags Details | Diff
Released patch (56.48 KB, patch)
2007-01-19 09:32 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2006-04-26 06:56:40 EDT
20060426

We want to make the JUNIT_HOME variable as deprecated as we introduced a new JUnit continer. Same probably for JRE_LIB where the JRE_CONTAINER should be used.

I suggest to add a new (optional) attribute to the 'classpathVariableInitializer' extension point:
'deprecated="JUNIT_HOME is deprecated, use the JUNIT container instead"'

That way we can also offer quick fixes that update the classpath.

See discussion in bug 137575
Comment 1 Frederic Fusier CLA 2006-10-27 06:15:13 EDT
Unfortunately, I had not enough time to implement this requirement for 3.3 M3.
Need to make decision for M4 if this bug will still stay in plan or not...
Comment 2 Frederic Fusier CLA 2006-12-08 04:17:01 EST
Martin,
Do you expect specific status for this while validating classpath entry using JavaConventions or you just need an API method on JavaCore?
Comment 3 Martin Aeschlimann CLA 2006-12-08 05:03:28 EST
On both: JavaConventions.validateClasspath should warn if it contains a deprecated variable.
But we also want renderer deprecated variables different in the seletion dialog and therefore need the info before applying it in a classpath.
With the request to make varibales read-only (bug 156226), I would introduce a new class ClasspathVariableDescription

JavaCore.getClasspathVariableDescription(String variable) : ClasspathVariableDescription

ClasspathVariableDescription
   getName() : String
   getValue() : String
   isDeprecated() : boolean
   isModifiable() : boolean

If a deprecated variable is in a classpath, the Java builder should also create a problem marker. We will then contribute a quick fix to -for example- replace the variable with a new container.
Comment 4 Philipe Mulet CLA 2006-12-08 06:27:25 EST
Marker creation will automatically arise from status change. Problem is that currently we do only have OK status and ERROR status. WARNING status is more tricky to achieve, though as Frederic suggested, this can be achieved through a multistatus.

Not sure about ClasspathVariableDescription. This seems like a bigger change than we need for a deprecated solution anyway. Can't we simply have managed variables be able to answer the question, and if so, simply add these new APIs on classpath variable initializers ? And these would be the APIs, we would use to compute the status anyway.
Comment 5 Martin Aeschlimann CLA 2006-12-08 06:47:43 EST
Yes, instead of having the deprecated/non modifiable information on the extension point, we could also have it on the ClasspathVariableInitializer, that's a good idea.
The only thing we must make sure is that ealy plugin-load is not a problem. In the variable selection UI, we would like to show all variables (an their values) and mark deprecated ones. So I guess as we already show values, the initializer would be loaded anyways.

Comment 6 Frederic Fusier CLA 2007-01-10 13:42:28 EST
Created attachment 56721 [details]
Proposed patch

So, here is the API proposal for this enhancement and bug 156226...

With this patch, I've verified that if I set added attributes for JUNIT_HOME and JUNIT_SRC_HOME as follows in org.eclipse.jdt.junit project:
<extension
  point="org.eclipse.jdt.core.classpathVariableInitializer">
  <classpathVariableInitializer
    class="org.eclipse.jdt.internal.junit.buildpath.JUnitHomeInitializer"
    deprecated="JUNIT_HOME is deprecated, use the JUNIT container instead"
    readOnly="true"
    variable="JUNIT_HOME">
  </classpathVariableInitializer>
  <classpathVariableInitializer
    class="org.eclipse.jdt.internal.junit.buildpath.JUnitHomeInitializer"
    deprecated="JUNIT_SRC_HOME is deprecated, use the JUNIT container instead"
    readOnly="true"
    variable="JUNIT_SRC_HOME">
  </classpathVariableInitializer>
</extension>

Then, ClasspathEntry.validateClasspathEntry(...) return an OK multi-status (ie isOK() returns true) which has 2 children warning status as children (ie. each status severity is equals to IStatus.WARNING).

Note that you can get the deprecated/read-only info through ClasspathInitializer using isDeprecated()/isReadOnly() or JavaCore API method isClasspathVariableDeprecated(String)/isClasspathVariableReadOnly(String)

I've run JDT/Core model tests and JDT/UI tests and everything is fine with this patch. But I have not written specific tests for these enhancements yet.
Comment 7 Jerome Lanneluc CLA 2007-01-11 06:36:56 EST
- ClasspathVariableInitializer#isDeprecated() and isReadOnly() are missing "@since 3.3" tags.
- JavaCore#isClasspathVariableDeprecated() and isClasspathVariableReadOnly() don't have Javadocs. Are these methods intended to be API ?
Comment 8 Frederic Fusier CLA 2007-01-14 06:57:54 EST
Created attachment 56879 [details]
Complete proposed patch

Here's implementation which should address these requirements including all feedback:
  - change returned multi-status to have with severity set to 'warning' when 
    variable is deprecated or read-only (although previous version was still
    'ok'). Also modified message to concatenate all status messages (separated
    with semi-colon - Note that OK status message is just removed as it is
    overridden by warning messages)
  - add missing javadoc and @since tags
  - add tests in ClasspathVariableInitializer

All JDT tests are OK.

Martin, please let me know if it's ok with you to release this implementation or if you think it needs more changes, thx
Comment 9 Frederic Fusier CLA 2007-01-16 13:10:49 EST
Created attachment 56978 [details]
Fixed complete proposed patch

This last fixes problem with message and code of multi-status + improve existing tests + add another one...
Comment 10 Frederic Fusier CLA 2007-01-18 09:38:43 EST
Created attachment 57080 [details]
New proposed patch

Here's a new patch written after last Martin's review.

Note that ClasspathVariableInitializer is now unchanged. Only JavaCore API methods have been kept and modified to return the deprecation message:

/**
 * Returns deprecation message of a given classpath variable.
 *
 * @param variableName
 * @return A string if the classpath variable is deprecated, <code>null</code> otherwise.
 * @since 3.3
 */
public static String getClasspathVariableDeprecationMessage(String variableName) 

/**
 * Returns whether a given classpath variable is read-only or not.
 *
 * @param variableName
 * @return <code>true</code> if the classpath variable is read-only,
 * 	<code>false</code> otherwise.
 * @since 3.3
 */
public static boolean isClasspathVariableReadOnly(String variableName)
Comment 11 Frederic Fusier CLA 2007-01-19 09:32:31 EST
Created attachment 57134 [details]
Released patch

Patch which will be released. It fixes last issue with read-only classpath variable which should not be warned when verified...
Comment 12 Martin Aeschlimann CLA 2007-01-19 09:40:03 EST
I filed bug 171049 against JDT/UI to use the new features.
Comment 13 Frederic Fusier CLA 2007-01-19 12:16:15 EST
Released for 3.3 M5 in HEAD stream.
Comment 14 Maxime Daniel CLA 2007-02-06 01:27:37 EST
Verified using build I20070205-1824.
Comment 15 Maxime Daniel CLA 2007-02-06 01:49:36 EST
Verified for 3.3 M5 using build I20070205-1824.