Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "ICU4J"

(Migration from java.text/java.util to com.ibm.icu.text/com.ibm.icu.util)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
ICU4J is a set of Java libraries that provides more comprehensive support for Unicode, software globalization, and internationalization.  In order to provide this functionality to the Eclipse community, ICU4J was added to the Eclipse platform build in 3.2. You will see it in the build as a plugin named com.ibm.icu.
+
Eclipse Platform is moving away from usage of ICU4J. See [https://bugs.eclipse.org/bugs/show_bug.cgi?id=562582] for details.
  
==Replacement Plug-in==
+
[[Category:Eclipse_Project| ]]
The Eclipse SDK will be adopting the ICU4J APIs for Eclipse 3.2.  The addition of the ICU4J plug-in adds on the order of 3MB worth of code.  Some applications may not want to absorb ICU4J if the priority is size over adopting the ICU4J function.  If this is the case for your application, you can download the replacement plug-in (<strong>com.ibm.icu.base</strong>) from an [http://download.eclipse.org/tools/orbit/downloads/ Orbit p2 repository], (See [[#Note on getting replacement plug-in from Orbit|Note]], below) remove the <strong>com.ibm.icu</strong> plug-in and its source counterpart, and drop in the replacement plug-in.  This is required because the Platform adopted the ICU APIs for 3.2 and so just removing the ICU plug-in will result in compilation errors.  The replacement plug-in is about 100KB in size and simply calls through to the java.* packages (default JDK implementation) of the most commonly used classes and APIs in ICU4J.  The classes that are implemented in the replacement plug-in are as follows:
+
 
+
*BreakIterator
+
*CollationKey
+
*Collator
+
*DateFormat
+
*DateFormatSymbols
+
*DecimalFormat
+
*DecimalFormatSymbols
+
*NumberFormat
+
*SimpleDateFormat
+
*Calendar
+
*TimeZone
+
*ULocale
+
*MessageFormat
+
 
+
 
+
If your application needs to be compatible between both the ICU4J plug-in and the replacement plug-in (most often for size reasons), we recommend you only use the API in the classes from this list.  If ICU4J is guaranteed to always be present in the application then you can safely use any of the ICU4J APIs.  The replacement plug-in will be built separately and available as a download on the build pages, but this is still work in progress.  You can however, start using the ICU4J APIs since the ICU4J plug-in is currently in the SDK build as of M4 (and beyond).
+
 
+
If you choose to adopt ICU4J, it is recommended that, in your plug-in manifest file, instead of using the <strong>Require-Bundle</strong> header to specify the dependency on ICU4J (e.g.)
+
 
+
<strong>Require-Bundle</strong>: com.ibm.icu
+
 
+
you use the <strong>Import-Package</strong> header to specify your plug-in's dependency on ICU4J (e.g.).
+
 
+
<strong>Import-Package</strong>: com.ibm.icu.text,
+
com.ibm.icu.util
+
 
+
This is to ensure you will not encounter compile or runtime errors if you decide to use the replacement plug-in instead of the full ICU4J plug-in, or vice-versa.
+
 
+
=== Note on getting replacement plug-in from Orbit ===
+
 
+
There several ways to get and use the "replacement bundle" from Orbit, depending on your builds, packaging, etc.
+
 
+
One way is to refer to the specific Orbit repository you'd like to use, along with the bundle name and exact version. For example, a section of a PDE .target file might be similar to:
+
 
+
<pre><nowiki>
+
    <location  includeAllPlatforms="true" includeMode="slicer" type="InstallableUnit">
+
      <unit id="com.ibm.icu.base" version="52.1.0.v201404241930" />
+
      <unit id="com.ibm.icu.base.source" version="52.1.0.v201404241930" />
+
      <repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/" />
+
    </location>
+
</nowiki></pre>
+
 
+
Or, you can download the actual bundles individually and put or use them however that would fit in with your builds or use-cases, Orbit makes each bundle available via http, as can be see on each download page, such as, at the time of this writing, the latest available is at
+
 
+
<nowiki>http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/</nowiki>
+
 
+
or for the replacement bundle and it's source, the URLs would be
+
 
+
<nowiki>http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/plugins/com.ibm.icu_52.1.0.v201404241930.jar
+
http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/plugins/com.ibm.icu.base.source_52.1.0.v201404171520.jar</nowiki>
+
 
+
For anyone who still uses map files, Orbit also makes it's builds available from a generated map file, such as see the link on it's download page titled "[http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/orbitBundles-R20140525021250.p2.map map file in p2 format]".
+
 
+
One final method will be mention, for anyone using BND or similar technology, an [http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/index.xml.gz OSGi repository index] is made available on each download page.
+
 
+
==Effect on JFace - ViewerSorter and StructuredViewer==
+
In order to support ICU4J in JFace, some creative API additions were made without actually referencing classes in the ICU4J plug-in in the API.  This resulted in the addition of:
+
 
+
1. a new class called org.eclipse.jface.viewers.ViewerComparator, of which org.eclipse.jface.viewers.Viewer Sorter is now a subclass
+
 
+
2. two new methods to StructuredViewer, to support the addition of the ViewerComparator class
+
 
+
 
+
<strong>Rationale</strong>
+
 
+
The ViewerSorter class has a public method getCollator() that returns a java.text.Collator.  Since this method is API it could not simply be changed to use an ICU Collator.  Also, ICU classes cannot be part of the API (signatures) as a direct plug-in dependency on ICU would prevent JFace from being used standalone (with SWT).  To accomodate these constraints, the ViewerComparator class that uses a java.util.Comparator, rather than an ICU Collator, was added.  This was done because ICU's Collator class implements java.util.Comparator, so StructuredViewers now have the option to use ICU's Collator rather than the java.text.Collator, but JFace doesn't have to add a dependency on the ICU4J plug-in. 
+
 
+
The two new methods added to StructuredViewer support using ICU's Collator to sort the contents of the Viewer via a ViewerComparator, rather than a ViewerSorter.  It is recommended that StructuredViewers now use these methods to get/set the viewer's sorter, instead of the getSorter() and setSorter(ViewerSorter) methods.
+
<pre>
+
/**
+
* Return this viewer's comparator used to sort elements.
+
* This method should be used instead of <code>getSorter()</code>.
+
*
+
* @return a viewer comparator, or <code>null</code> if none
+
*
+
* @since 3.2
+
*/
+
public ViewerComparator getComparator()
+
 
+
/**
+
* Sets this viewer's comparator to be used for sorting elements, and triggers refiltering and
+
* resorting of this viewer's element.  <code>null</code> turns sorting off.
+
* To get the viewer's comparator, call <code>getComparator()</code>.
+
* <p>
+
* IMPORTANT: This method was introduced in 3.2. If a reference to this viewer object
+
* is passed to clients who call <code>getSorter()<code>, null may be returned from
+
* from that method even though the viewer is sorting its elements using the
+
* viewer's comparator.
+
* </p>
+
*
+
* @param comparator a viewer comparator, or <code>null</code> if none
+
*
+
* @since 3.2
+
*/
+
public void setComparator(ViewerComparator comparator)
+
</pre>
+
 
+
==ICU4J Usage in Eclipse==
+
Link to a [[ICU4J Usage in Eclipse | table]] that lists all the plugins in the Eclipse SDK that have a dependency on ICU4J.
+
 
+
==More Info==
+
For more information about ICU4J visit the official home page:
+
 
+
http://www.icu-project.org/
+
 
+
[[Category:Eclipse_Project| ]][[Category:Eclipse_Platform_Releng| ]][[Category: Orbit| ]]
+

Latest revision as of 04:07, 27 November 2020

Eclipse Platform is moving away from usage of ICU4J. See [1] for details.

Back to the top