ICU-5720 Add data version to ICU4J.

X-SVN-Rev: 26491
This commit is contained in:
Michael Ow 2009-08-13 18:03:37 +00:00
parent da54f7cdee
commit 5f2ff249fd
7 changed files with 114 additions and 9 deletions

View file

@ -0,0 +1,97 @@
/*
*******************************************************************************
* Copyright (C) 2009, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
package com.ibm.icu.impl;
import com.ibm.icu.util.VersionInfo;
import com.ibm.icu.util.UResourceBundle;
import java.util.MissingResourceException;
public final class ICUDataVersion {
private static final String U_ICU_VERSION_BUNDLE = "icuver";
private static final String U_ICU_STD_BUNDLE = "icustd";
private static final String U_ICU_DATA_KEY = "DataVersion";
/**
* This function loads up icuver and compares the data version to the wired-in ICU_DATA_VERSION.
* If icuver shows something less than ICU_DATA_VERSION it returns TRUE, else FALSE. The version
* found will be returned in the first fillin parameter (if non-null), and *isModified will be set
* to TRUE if "icustd" is NOT found. Thus, if the data has been repackaged or modified, "icustd"
* (standard ICU) will be missing, and the function will alert the caller that the data is not standard.
*
* @param dataVersionFillin icuver data version information to be filled in if not-null
* @param status stores the error code from the calls to resource bundle
*
* @return TRUE if ICU_DATA_VERSION is newer than icuver, else FALSE
*
* @draft ICU 4.4
*/
public static boolean isDataOlder(VersionInfo dataVersionFillin) {
boolean result = true;
VersionInfo dataVersion = getDataVersion();
if (dataVersion!= null) {
if (dataVersion.compareTo(VersionInfo.ICU_DATA_VERSION) != -1) {
result = false;
}
if (dataVersionFillin != null) {
dataVersionFillin = VersionInfo.getInstance(dataVersion.toString());
}
}
return result;
}
/**
* This function tests whether "icustd" is available in the data. If the data has been repackaged or modified, "icustd"
* (standard ICU) will be missing, and the function will alert the caller that the data is not standard.
*
* @return TRUE if data has been modified, else FALSE
*
* @draft ICU 4.4
*/
public static boolean isDataModified() {
if (hasICUSTDBundle()) {
return false;
}
return true;
}
/**
* This function retrieves the data version from icuver and returns a VersionInfo object with that version information.
*
* @return Current icu data version
*
* @draft ICU 4.4
*/
public static VersionInfo getDataVersion() {
UResourceBundle icudatares = null;
try {
icudatares = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, ICUDataVersion.U_ICU_VERSION_BUNDLE, ICUResourceBundle.ICU_DATA_CLASS_LOADER);
icudatares = icudatares.get(ICUDataVersion.U_ICU_DATA_KEY);
} catch (MissingResourceException ex) {
return null;
}
return VersionInfo.getInstance(icudatares.getString());
}
private static boolean hasICUSTDBundle() {
try {
UResourceBundle.getBundleInstance(ICUDataVersion.U_ICU_STD_BUNDLE);
} catch (MissingResourceException ex) {
return false;
}
return true;
}
}

View file

@ -42,7 +42,7 @@ public class ICUResourceBundle extends UResourceBundle {
/**
* The data path to be used with getBundleInstance API
*/
public static final String ICU_BUNDLE = "data/icudt" + VersionInfo.ICU_DATA_VERSION;
public static final String ICU_BUNDLE = "data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH;
/**
* The base name of ICU data to be used with getBundleInstance API

View file

@ -861,7 +861,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
public static synchronized String getTZDataVersion() {
if (TZDATA_VERSION == null) {
UResourceBundle tzbundle = UResourceBundle.getBundleInstance(
"com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION, "zoneinfo");
"com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH, "zoneinfo");
TZDATA_VERSION = tzbundle.getString("TZVersion");
}
return TZDATA_VERSION;

View file

@ -406,7 +406,7 @@ public class VTimeZone extends BasicTimeZone {
// Initialize ICU_TZVERSION
try {
UResourceBundle tzbundle = UResourceBundle.getBundleInstance(
"com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION, "zoneinfo");
"com/ibm/icu/impl/data/icudt" + VersionInfo.ICU_DATA_VERSION_PATH, "zoneinfo");
ICU_TZVERSION = tzbundle.getString("TZVersion");
} catch (MissingResourceException e) {
///CLOVER:OFF

View file

@ -126,11 +126,18 @@ public final class VersionInfo implements Comparable<VersionInfo>
public static final VersionInfo ICU_VERSION;
/**
* Data version string for ICU's internal data
* Data version string for ICU's internal data.
* Used for appending to data path (e.g. icudt43b)
* @internal
* @deprecated This API is ICU internal only.
*/
public static final String ICU_DATA_VERSION = "43b";
public static final String ICU_DATA_VERSION_PATH = "43b";
/**
* Data version in ICU4J.
* @draft ICU 4.4
*/
public static final VersionInfo ICU_DATA_VERSION;
/**
* ICU4J collator runtime version
@ -453,6 +460,7 @@ public final class VersionInfo implements Comparable<VersionInfo>
UNICODE_5_0 = getInstance(5, 0, 0, 0);
UNICODE_5_1 = getInstance(5, 1, 0, 0);
ICU_VERSION = getInstance(4, 3, 2, 0);
ICU_DATA_VERSION = getInstance(4, 3, 2, 0);
UCOL_RUNTIME_VERSION = getInstance(6);
UCOL_BUILDER_VERSION = getInstance(7);
UCOL_TAILORINGS_VERSION = getInstance(1);

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c2cc70dea00dfd051df385d5c42102b57e144410814901a64026f2b71db44940
size 6407935
oid sha256:2e0e9765959db0043f13753f536fdd17f5c3575134c62e2fc3605f0468ec9e0d
size 6408404

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c4530426df37d8a0f3d5d66ba23fcbe059faeae9abd211d4205659ab21a34eb0
size 720074
oid sha256:02091ec2784bdaf2c4f03191092760c4729c3724ed78dab3efe23733227b4fe9
size 717064