Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 93829 Details for
Bug 222309
Review of the metadata translation support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Initial patch for metadata localizations changes items 2 - 7
222309Patch0.txt (text/plain), 19.69 KB, created by
Dave Stevenson
on 2008-03-27 13:58:10 EDT
(
hide
)
Description:
Initial patch for metadata localizations changes items 2 - 7
Filename:
MIME Type:
Creator:
Dave Stevenson
Created:
2008-03-27 13:58:10 EDT
Size:
19.69 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.metadata.generator >Index: src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java,v >retrieving revision 1.37 >diff -u -r1.37 MetadataGeneratorHelper.java >--- src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java 24 Mar 2008 19:10:25 -0000 1.37 >+++ src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java 27 Mar 2008 17:39:12 -0000 >@@ -39,6 +39,7 @@ > /** > * A capability namespace representing the type of Eclipse resource (bundle, feature, source bundle, etc) > * @see RequiredCapability#getNamespace() >+ * @see ProvidedCapability#getNamespace() > */ > public static final String NAMESPACE_ECLIPSE_TYPE = "org.eclipse.equinox.p2.eclipse.type"; //$NON-NLS-1$ > >@@ -46,6 +47,7 @@ > * A capability name in the {@link #NAMESPACE_ECLIPSE_TYPE} namespace > * representing and OSGi bundle resource > * @see RequiredCapability#getName() >+ * @see ProvidedCapability#getName() > */ > public static final String TYPE_ECLIPSE_BUNDLE = "bundle"; //$NON-NLS-1$ > /** >@@ -63,11 +65,12 @@ > public static final String TYPE_ECLIPSE_SOURCE = "source"; //$NON-NLS-1$ > > /** >- * A capability name in the {@link #NAMESPACE_ECLIPSE_TYPE} namespace >- * representing localized manifest properties >- * @see RequiredCapability#getName() >+ * A capability namespace representing the localization (translation) >+ * of strings from a specified IU in a specified locale >+ * @see RequiredCapability#getNamespace() >+ * @see ProvidedCapability#getNamespace() > */ >- public static final String TYPE_ECLIPSE_MANIFEST_LOCALIZATION = "manifest.localization"; //$NON-NLS-1$ >+ public static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$ > > // Only certain properties in the bundle manifest are assumed to be localized. > public static final String[] BUNDLE_LOCALIZED_PROPERTIES = {Constants.BUNDLE_NAME, Constants.BUNDLE_DESCRIPTION, Constants.BUNDLE_VENDOR, Constants.BUNDLE_CONTACTADDRESS, Constants.BUNDLE_DOCURL, Constants.BUNDLE_UPDATELOCATION}; >@@ -106,7 +109,6 @@ > public static final ProvidedCapability BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_BUNDLE, new Version(1, 0, 0)); > public static final ProvidedCapability FEATURE_CAPABILITY = MetadataFactory.createProvidedCapability(NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_FEATURE, new Version(1, 0, 0)); > public static final ProvidedCapability SOURCE_BUNDLE_CAPABILITY = MetadataFactory.createProvidedCapability(NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_SOURCE, new Version(1, 0, 0)); >- public static final ProvidedCapability MANIFEST_LOCALIZATION_CAPABILITY = MetadataFactory.createProvidedCapability(NAMESPACE_ECLIPSE_TYPE, TYPE_ECLIPSE_MANIFEST_LOCALIZATION, new Version(1, 0, 0)); > > static final String DEFAULT_BUNDLE_LOCALIZATION = "plugin"; //$NON-NLS-1$ > static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$ >@@ -173,23 +175,16 @@ > return MetadataFactory.createInstallableUnit(cu); > } > >- public static IInstallableUnit createBundleIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key, Set localizationIUs) { >- IInstallableUnit bundleIU = createBundleIU(bd, manifest, isFolderPlugin, key); >- >+ public static IInstallableUnit createBundleIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key) { >+ Map manifestLocalizations = null; > if (manifest != null && bd.getLocation() != null) { >- String bundleLocalization = (String) manifest.get(Constants.BUNDLE_LOCALIZATION); >- if (bundleLocalization == null) { >- bundleLocalization = DEFAULT_BUNDLE_LOCALIZATION; >- } >- Map manifestLocalizations = getManifestLocalizations(manifest, new File(bd.getLocation())); >- if (manifestLocalizations != null) { >- localizationIUs.addAll(createLocalizationFragmentsForBundle(bd, manifestLocalizations)); >- } >+ manifestLocalizations = getManifestLocalizations(manifest, new File(bd.getLocation())); > } >- return bundleIU; >+ >+ return createBundleIU(bd, manifest, isFolderPlugin, key, manifestLocalizations); > } > >- public static IInstallableUnit createBundleIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key) { >+ public static IInstallableUnit createBundleIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key, Map manifestLocalizations) { > boolean isBinaryBundle = true; > if (manifest != null && manifest.containsKey("Eclipse-SourceBundle")) { //$NON-NLS-1$ > isBinaryBundle = false; >@@ -250,6 +245,20 @@ > > if (isFragment) > providedCapabilities.add(MetadataFactory.createProvidedCapability(CAPABILITY_NS_OSGI_FRAGMENT, bd.getHost().getName(), bd.getVersion())); >+ >+ if (manifestLocalizations != null) { >+ for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) { >+ Locale locale = (Locale) iter.next(); >+ Properties translatedStrings = (Properties) manifestLocalizations.get(locale); >+ Enumeration propertyKeys = translatedStrings.propertyNames(); >+ while (propertyKeys.hasMoreElements()) { >+ String nextKey = (String) propertyKeys.nextElement(); >+ iu.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey)); >+ } >+ providedCapabilities.add(makeTranslationCapability(bd.getSymbolicName(), locale)); >+ } >+ } >+ > iu.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); > > iu.setArtifacts(new IArtifactKey[] {key}); >@@ -284,57 +293,42 @@ > return MetadataFactory.createInstallableUnit(iu); > } > >- private static List createLocalizationFragmentsForBundle(BundleDescription bd, Map manifestLocalizations) { >- List localizationFragments = new ArrayList(manifestLocalizations.size()); >- for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) { >- Locale locale = (Locale) iter.next(); >- Properties localizedStrings = (Properties) manifestLocalizations.get(locale); >- IInstallableUnitFragment nextLocaleFragment = createLocalizationFragmentOfBundle(bd, locale, localizedStrings); >- localizationFragments.add(nextLocaleFragment); >- } >- return localizationFragments; >- } >- > /* > * @param bd >- * @param locale >- * @param localizedStrings >+ * @param manifestLocalizations map from locale to translated properties > * @return installableUnitFragment > */ >- private static IInstallableUnitFragment createLocalizationFragmentOfBundle(BundleDescription bd, Locale locale, Properties localizedStrings) { >- InstallableUnitFragmentDescription fragment = new MetadataFactory.InstallableUnitFragmentDescription(); >- String fragmentId = makeLocalizationFragmentId(bd.getSymbolicName(), locale); >- fragment.setId(fragmentId); >- fragment.setVersion(bd.getVersion()); >- >- RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(NAMESPACE_ECLIPSE_TYPE, bd.getSymbolicName(), new VersionRange(bd.getVersion(), true, bd.getVersion(), true), null, false, false)}; >- fragment.setHost(hostReqs); >- >- fragment.setSingleton(true); >- >- Enumeration propertyKeys = localizedStrings.propertyNames(); >- while (propertyKeys.hasMoreElements()) { >- String nextKey = (String) propertyKeys.nextElement(); >- fragment.setProperty(nextKey, localizedStrings.getProperty(nextKey)); >- } >- // TODO: do we need any capabilities? >- // Create set of provided capabilities It's just a tag indicating a localization fragment. >- ArrayList providedCapabilities = new ArrayList(1); >- providedCapabilities.add(MANIFEST_LOCALIZATION_CAPABILITY); >- fragment.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); >- >- return MetadataFactory.createInstallableUnitFragment(fragment); >- } >- >- public static void createHostLocalizationFragments(BundleDescription bd, String hostId, String[] hostBundleManifestValues, Set localizationIUs) { >+ // private static IInstallableUnitFragment createLocalizationFragmentOfBundle(BundleDescription bd, Map manifestLocalizations) { >+ // InstallableUnitFragmentDescription fragment = new MetadataFactory.InstallableUnitFragmentDescription(); >+ // String fragmentId = makeBundleLocalizationFragmentId(bd.getSymbolicName()); >+ // fragment.setId(fragmentId); >+ // fragment.setVersion(bd.getVersion()); >+ // >+ // RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(NAMESPACE_ECLIPSE_TYPE, bd.getSymbolicName(), new VersionRange(bd.getVersion(), true, bd.getVersion(), true), null, false, false, false)}; >+ // fragment.setHost(hostReqs); >+ // >+ // fragment.setSingleton(true); >+ // >+ // ArrayList providedCapabilities = new ArrayList(manifestLocalizations.size()); >+ // for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) { >+ // Locale locale = (Locale) iter.next(); >+ // Properties translatedStrings = (Properties) manifestLocalizations.get(locale); >+ // Enumeration propertyKeys = translatedStrings.propertyNames(); >+ // while (propertyKeys.hasMoreElements()) { >+ // String nextKey = (String) propertyKeys.nextElement(); >+ // fragment.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey)); >+ // } >+ // providedCapabilities.add(makeTranslationCapability(bd.getSymbolicName(), locale)); >+ // } >+ // fragment.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); >+ // >+ // return MetadataFactory.createInstallableUnitFragment(fragment); >+ // } >+ public static void createHostLocalizationFragment(IInstallableUnit bundleIU, BundleDescription bd, String hostId, String[] hostBundleManifestValues, Set localizationIUs) { > Map hostLocalizations = getHostLocalizations(new File(bd.getLocation()), hostBundleManifestValues); > if (hostLocalizations != null) { >- for (Iterator iter = hostLocalizations.keySet().iterator(); iter.hasNext();) { >- Locale locale = (Locale) iter.next(); >- Properties localizedStrings = (Properties) hostLocalizations.get(locale); >- IInstallableUnitFragment nextLocaleFragment = createLocalizationFragmentOfHost(hostId, hostBundleManifestValues, bd, locale, localizedStrings); >- localizationIUs.add(nextLocaleFragment); >- } >+ IInstallableUnitFragment localizationFragment = createLocalizationFragmentOfHost(bd, hostId, hostBundleManifestValues, hostLocalizations); >+ localizationIUs.add(localizationFragment); > } > } > >@@ -345,29 +339,31 @@ > * @param localizedStrings > * @return installableUnitFragment > */ >- private static IInstallableUnitFragment createLocalizationFragmentOfHost(String hostId, String[] hostManifestValues, BundleDescription bd, Locale locale, Properties localizedStrings) { >+ private static IInstallableUnitFragment createLocalizationFragmentOfHost(BundleDescription bd, String hostId, String[] hostManifestValues, Map hostLocalizations) { > InstallableUnitFragmentDescription fragment = new MetadataFactory.InstallableUnitFragmentDescription(); >- HostSpecification hostSpec = bd.getHost(); >- String fragmentId = makeLocalizationFragmentId(hostId, locale); >+ String fragmentId = makeHostLocalizationFragmentId(bd.getSymbolicName()); > fragment.setId(fragmentId); > fragment.setVersion(bd.getVersion()); // TODO: is this a meaningful version? > >- RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(NAMESPACE_ECLIPSE_TYPE, hostSpec.getName(), hostSpec.getVersionRange(), null, false, false)}; >+ HostSpecification hostSpec = bd.getHost(); >+ RequiredCapability[] hostReqs = new RequiredCapability[] {MetadataFactory.createRequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, hostSpec.getName(), hostSpec.getVersionRange(), null, false, false, false)}; > fragment.setHost(hostReqs); > > fragment.setSingleton(true); > >- for (int i = 0; i < BUNDLE_LOCALIZED_PROPERTIES.length; i++) { >- String nextKey = hostManifestValues[i]; >- String localizedValue = null; >- if (nextKey != null && (localizedValue = localizedStrings.getProperty(nextKey)) != null) { >- fragment.setProperty(nextKey, localizedValue); >+ // Create a provided capability for each locale and add the translated properties. >+ ArrayList providedCapabilities = new ArrayList(hostLocalizations.keySet().size()); >+ for (Iterator iter = hostLocalizations.keySet().iterator(); iter.hasNext();) { >+ Locale locale = (Locale) iter.next(); >+ Properties translatedStrings = (Properties) hostLocalizations.get(locale); >+ >+ Enumeration propertyKeys = translatedStrings.propertyNames(); >+ while (propertyKeys.hasMoreElements()) { >+ String nextKey = (String) propertyKeys.nextElement(); >+ fragment.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey)); > } >+ providedCapabilities.add(makeTranslationCapability(hostId, locale)); > } >- // TODO: do we need any capabilities? It's just a tag indicating a localization fragment. >- // Create set of provided capabilities >- ArrayList providedCapabilities = new ArrayList(1); >- providedCapabilities.add(MANIFEST_LOCALIZATION_CAPABILITY); > fragment.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); > > return MetadataFactory.createInstallableUnitFragment(fragment); >@@ -375,14 +371,23 @@ > > /** > * @param id >- * @param locale >- * @return the id for the fragment contain the localized properties >- * for the manifest of the bundle with the given id >- * in the given locale. >+ * @return the id for the iu fragment containing the localized properties >+ * for the bundle with the given id >+ */ >+ // private static String makeBundleLocalizationFragmentId(String id) { >+ // return id + ".translated_properties"; //$NON-NLS-1$ >+ // } >+ /** >+ * @param id >+ * @return the id for the iu fragment containing localized properties >+ * for the fragment with the given id. > */ >- private static String makeLocalizationFragmentId(String id, Locale locale) { >- String localeString = (!DEFAULT_LOCALE.equals(locale) ? '_' + locale.toString() : ""); //$NON-NLS-1$ >- return id + "_manifest" + localeString + "_properties"; //$NON-NLS-1$ //$NON-NLS-2$ >+ private static String makeHostLocalizationFragmentId(String id) { >+ return id + ".translated_host_properties"; //$NON-NLS-1$ >+ } >+ >+ private static ProvidedCapability makeTranslationCapability(String hostId, Locale locale) { >+ return MetadataFactory.createProvidedCapability(NAMESPACE_IU_LOCALIZATION, locale.toString(), new Version(1, 0, 0)); > } > > /** >@@ -531,30 +536,12 @@ > } > > public static IInstallableUnit[] createEclipseIU(BundleDescription bd, Map manifest, boolean isFolderPlugin, IArtifactKey key, Properties extraProperties) { >- ArrayList iusCreated = new ArrayList(4); >+ ArrayList iusCreated = new ArrayList(1); > > IInstallableUnit iu = createBundleIU(bd, manifest, isFolderPlugin, key); > addExtraProperties(iu, extraProperties); > iusCreated.add(iu); > >- if (manifest != null) { >- String bundleLocalization = null; >- if (bd.getHost() == null) // not a fragment >- bundleLocalization = (String) manifest.get(Constants.BUNDLE_LOCALIZATION); >- if (bundleLocalization == null) >- bundleLocalization = DEFAULT_BUNDLE_LOCALIZATION; >- >- Map manifestLocalizations = getManifestLocalizations(manifest, new File(bd.getLocation())); >- >- if (manifestLocalizations != null) { >- List localizationFragments = createLocalizationFragmentsForBundle(bd, manifestLocalizations); >- for (Iterator iter = localizationFragments.iterator(); iter.hasNext();) { >- addExtraProperties((IInstallableUnit) iter.next(), extraProperties); >- } >- iusCreated.addAll(localizationFragments); >- } >- } >- > return (IInstallableUnit[]) (iusCreated.toArray(new IInstallableUnit[iusCreated.size()])); > } > >Index: src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.metadata.generator/src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java,v >retrieving revision 1.37 >diff -u -r1.37 Generator.java >--- src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java 24 Mar 2008 18:36:41 -0000 1.37 >+++ src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java 27 Mar 2008 17:39:12 -0000 >@@ -355,7 +355,7 @@ > } > } > >- IInstallableUnit bundleIU = MetadataGeneratorHelper.createBundleIU(bd, bundleManifest, isDir, key, localizationIUs); >+ IInstallableUnit bundleIU = MetadataGeneratorHelper.createBundleIU(bd, bundleManifest, isDir, key); > > if (isFragment(bd)) { > // TODO: Can NL fragments be multi-host? What special handling >@@ -365,7 +365,7 @@ > String[] cachedValues = (String[]) bundleLocalizationMap.get(hostKey); > > if (cachedValues != null) { >- MetadataGeneratorHelper.createHostLocalizationFragments(bd, hostId, cachedValues, localizationIUs); >+ MetadataGeneratorHelper.createHostLocalizationFragment(bundleIU, bd, hostId, cachedValues, localizationIUs); > } > } > >#P org.eclipse.equinox.p2.ui >Index: src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java,v >retrieving revision 1.1 >diff -u -r1.1 IUPropertyUtils.java >--- src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java 29 Feb 2008 04:36:44 -0000 1.1 >+++ src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java 27 Mar 2008 17:39:13 -0000 >@@ -20,6 +20,8 @@ > > public class IUPropertyUtils { > >+ static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$ >+ > public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) { > String value = iu.getProperty(propertyKey); > if (value == null || value.length() <= 1 || value.charAt(0) != '%') >@@ -43,11 +45,15 @@ > } > } > >+ String defaultKey = DEFAULT_LOCALE.toString() + '.' + actualKey; >+ String defaultValue = iu.getProperty(defaultKey); >+ if (defaultValue != null) >+ return defaultValue; >+ > return value; > } > >- private static final String MANIFEST_NAME = "_manifest"; //$NON-NLS-1$ >- private static final String PROPERTIES_NAME = "_properties"; //$NON-NLS-1$ >+ private static final String TRANSLATED_PROPERTIES_NAME = "_translated_properties"; //$NON-NLS-1$ > > /** > */ >@@ -57,14 +63,14 @@ > ArrayList result = new ArrayList(4); > int lastSeparator; > while (true) { >- result.add(id + MANIFEST_NAME + '_' + nl + PROPERTIES_NAME); >+ result.add(id + '_' + nl + TRANSLATED_PROPERTIES_NAME); > lastSeparator = nl.lastIndexOf('_'); > if (lastSeparator == -1) > break; > nl = nl.substring(0, lastSeparator); > } >- //add the empty suffix last (most general) >- result.add(id + MANIFEST_NAME + PROPERTIES_NAME); >+ // Add the empty suffix last (most general) >+ result.add(id + TRANSLATED_PROPERTIES_NAME); > return (String[]) result.toArray(new String[result.size()]); > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 222309
: 93829 |
94301
|
99221
|
99406
|
100028
|
100281