MigrationToPreferences

Usage of Preferences API

Use Preferences javadoc and NbPreferences javadoc
3 trees are ready to use:

  • Preferences.userRoot() - per user
  • Preferences.systemRoot() - per system
  • NbPreferences.root() - per userdir, makes sense if you want participate on publicly exposed preferences (typical usage NbPreferences.root().absolutePath(code_name_base_of_friend_module))

Additional factory methods:

  • Preferences.userNodeForPackage(Class c)
  • Preferences.systemNodeForPackage(Class c)
  • NbPreferences.forModule(Class c) returns preference node which absolute path depends whether class provided as a parameter was loaded as a part of any module or not. If so, then absolute path corresponds to slashified code name base of module. If not, then absolute path corresponds to class's package


Do not use Preferences for serialization again because not designed for it - relatively small data can be put in (< 8kB)!

Migration

Learn from what has already be done, go through individual fixed issues in umbrella issue #77030 and look at their commits to have clear idea what must be done.

Migration steps

  1. remove dependency on Options API
  2. compile to find affected classes
  3. ensure yourself to have dependency on Utilities API > 7.4
  4. rewrite individual subclasses of SystemOption by usage of Preferences API
  5. remove SystemOption registration in mf-layer
  6. remove settings file addresssed from mf-layer
  7. remove registration of representing Node in Tools/Options(Advanced settings)
  8. remove related BeanInfo if exists
  9. replace old advanced settings UI with new panel
  10. ensure import from previous version (upgrader)
  11. answer arch questions
  12. run commit validation
  13. check that the startup warning disappeared
  14. check that import of setting works fine

Dependency changes

Steps 1.,3. - use apisupport in NetBeans and don't forget modify golden files to ensure that commit validation will pass.

Affected files:

  • /cvs/yourmodule/nbproject/project.xml
  • /cvs/ide/golden/*.* - typically deps.txt


Registrations in mf-layer

Steps 5.,6.,7. (example)- remove settings registration in Services folder:

-     <folder name="Services"/>
-         <file name="org-netbeans-modules-derby-DerbyOptions.settings" url="DerbyOptions.settings"/>
-     </folder>

remove registration of representing Node in UI/Services folder:

-     <folder name="Services">
-         <folder name="IDEConfiguration">
-             <folder name="ServerAndExternalToolSettings">
-                    <file name="org-netbeans-modules-derby-DerbyOptions.shadow">
-                        <attr name="originalFile" stringvalue="Services/org-netbeans-modules-derby-DerbyOptions.settings"/>
-                    </file>
-             </folder>
-         </folder>
-     </folder>


Affected files:

  • /cvs/yourmodule/src/org/netbeans/modules/yourmodule/YourOptions.settings - remove if exists
  • /cvs/yourmodule/src/org/netbeans/modules/yourmodule/layer.xml

Remove related BeanInfo if exists

Step 8. - original purpose of BeanIno was:

  • additional information for serialization, deserialization of SystemOption
  • additional information for properties introspection for Advanced Tools/Options UI

Can be easily deleted.

Affected files:

  • /cvs/yourmodule/src/org/netbeans/modules/yourmodule/YourOptionsBeanInfo.java


Replace old advanced settings UI with new panel

Step 9. - see Options Dialog SPI, discuss with HIE
Use apisupport in NetBeans to get skeleton for implementation for free.

Ensure import from previous version (upgrader)

Step 10. - needs following steps:


Affected files:

  • /cvs/ide/launcher/upgrade/src/org/netbeans/upgrade/systemoptions/systemoptionsimport
  • /cvs/ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/systemoptions/YourOptionsTest.java
  • /cvs/ide/launcher/upgrade/test/unit/src/org/netbeans/upgrade/systemoptions/YourOptionsTest.settings


Answer arch questions

Setp 11. - modify current architecture QA document

<answer id="resources-preferences">
  <api group="preferences" name="org.netbeans.modules.derby" type="export" category="private">
      <table>
          <tbody>
              <tr>
                  <th>key</th>
                  <th>description</th>
                  <th>read</th>
                  <th>write</th>
              </tr>
              <tr>
                  <td>location</td>
                  <td>Derby location or an empty string if the Derby location is not set>/td>
                  <td>x</td>
                  <td>x</td>
              </tr>
              <tr>
                  <td>systemHome</td>
                  <td>Derby system home or an empty string if the system home is not set</td>
                  <td>x</td>
                  <td>x</td>
              </tr>
          </tbody>
      </table>
  </api>
 </answer>

Check that the startup warning disappeared

Step 13. - run netbeans and check that the following messsage disappeared

[[Exec | exec]] WARNING [Org.netbeans.core.modules]: the module org.netbeans.modules.websvc.wsitconf uses org.openide.options which is deprecated: Use org.openide.util.NbPreferences instead.

Check that import of setting works fine

Step 14. - locate your preferences in userdir

config/
|-- Preferences
|   `-- org
|       |-- netbeans
|       |   `-- modules
|       |       |-- autoupdate.properties
|       |       |-- derby.properties
|       |       `-- projectui.properties
|       `-- openide
|           `-- explorer.properties


check its content that it contains all expected properties:

#Tue May 22 19:36:36 CEST 2007
lastSelectedProjectType=emptyRuby
lastSelectedProjectCategory=Ruby
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo