Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 222309 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java (-166 / +60 lines)
Lines 12-19 Link Here
12
package org.eclipse.equinox.internal.provisional.p2.metadata.generator;
12
package org.eclipse.equinox.internal.provisional.p2.metadata.generator;
13
13
14
import java.io.*;
14
import java.io.*;
15
import java.net.URL;
16
import java.net.URLConnection;
17
import java.util.*;
15
import java.util.*;
18
import java.util.zip.ZipEntry;
16
import java.util.zip.ZipEntry;
19
import java.util.zip.ZipFile;
17
import java.util.zip.ZipFile;
Lines 22-27 Link Here
22
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
20
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
23
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
21
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
24
import org.eclipse.equinox.internal.p2.metadata.generator.Activator;
22
import org.eclipse.equinox.internal.p2.metadata.generator.Activator;
23
import org.eclipse.equinox.internal.p2.metadata.generator.LocalizationHelper;
25
import org.eclipse.equinox.internal.p2.metadata.generator.features.SiteCategory;
24
import org.eclipse.equinox.internal.p2.metadata.generator.features.SiteCategory;
26
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
25
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
27
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
26
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
Lines 112-118 Link Here
112
111
113
	static final String DEFAULT_BUNDLE_LOCALIZATION = "plugin"; //$NON-NLS-1$	
112
	static final String DEFAULT_BUNDLE_LOCALIZATION = "plugin"; //$NON-NLS-1$	
114
	static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$
113
	static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$
115
	static final String MANIFEST_LOCALIZATIONS = "eclipse.p2.manifest.localizations"; //$NON-NLS-1$
116
114
117
	static final String BUNDLE_ADVICE_FILE = "META-INF/p2.inf"; //$NON-NLS-1$
115
	static final String BUNDLE_ADVICE_FILE = "META-INF/p2.inf"; //$NON-NLS-1$
118
	static final String ADVICE_INSTRUCTIONS_PREFIX = "instructions."; //$NON-NLS-1$
116
	static final String ADVICE_INSTRUCTIONS_PREFIX = "instructions."; //$NON-NLS-1$
Lines 562-567 Link Here
562
		Version version = new Version(feature.getVersion());
560
		Version version = new Version(feature.getVersion());
563
		iu.setVersion(version);
561
		iu.setVersion(version);
564
		iu.setUpdateDescriptor(MetadataFactory.createUpdateDescriptor(id, new VersionRange(new Version(0, 0, 0), true, new Version(feature.getVersion()), false), IUpdateDescriptor.NORMAL, null));
562
		iu.setUpdateDescriptor(MetadataFactory.createUpdateDescriptor(id, new VersionRange(new Version(0, 0, 0), true, new Version(feature.getVersion()), false), IUpdateDescriptor.NORMAL, null));
563
		iu.setProperty(IInstallableUnit.PROP_NAME, feature.getLabel());
564
		if (feature.getDescription() != null)
565
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION, feature.getDescription());
566
		if (feature.getDescriptionURL() != null)
567
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION_URL, feature.getDescriptionURL());
568
		if (feature.getProviderName() != null)
569
			iu.setProperty(IInstallableUnit.PROP_PROVIDER, feature.getProviderName());
565
		if (feature.getLicense() != null)
570
		if (feature.getLicense() != null)
566
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
571
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
567
		if (feature.getCopyright() != null)
572
		if (feature.getCopyright() != null)
Lines 585-591 Link Here
585
			iu.setProperty(ECLIPSE_INSTALL_HANDLER_PROP, installHandlerProperty);
590
			iu.setProperty(ECLIPSE_INSTALL_HANDLER_PROP, installHandlerProperty);
586
		}
591
		}
587
592
588
		iu.setCapabilities(new ProvidedCapability[] {createSelfCapability(id, version), FEATURE_CAPABILITY, MetadataFactory.createProvidedCapability(CAPABILITY_NS_UPDATE_FEATURE, feature.getId(), version)});
593
		// Create set of provided capabilities
594
		ArrayList providedCapabilities = new ArrayList();
595
		providedCapabilities.add(createSelfCapability(id, version));
596
		providedCapabilities.add(FEATURE_CAPABILITY);
597
		providedCapabilities.add(MetadataFactory.createProvidedCapability(CAPABILITY_NS_UPDATE_FEATURE, feature.getId(), version));
598
589
		iu.setArtifacts(new IArtifactKey[] {createFeatureArtifactKey(feature.getId(), version.toString())});
599
		iu.setArtifacts(new IArtifactKey[] {createFeatureArtifactKey(feature.getId(), version.toString())});
590
600
591
		if (isExploded) {
601
		if (isExploded) {
Lines 596-601 Link Here
596
			iu.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData));
606
			iu.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData));
597
		}
607
		}
598
608
609
		Map localizations = feature.getLocalizations();
610
		if (localizations != null) {
611
			for (Iterator iter = localizations.keySet().iterator(); iter.hasNext();) {
612
				Locale locale = (Locale) iter.next();
613
				Properties translatedStrings = (Properties) localizations.get(locale);
614
				Enumeration propertyKeys = translatedStrings.propertyNames();
615
				while (propertyKeys.hasMoreElements()) {
616
					String nextKey = (String) propertyKeys.nextElement();
617
					iu.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey));
618
				}
619
				providedCapabilities.add(makeTranslationCapability(id, locale));
620
			}
621
		}
622
623
		iu.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()]));
624
599
		if (extraProperties != null) {
625
		if (extraProperties != null) {
600
			Enumeration e = extraProperties.propertyNames();
626
			Enumeration e = extraProperties.propertyNames();
601
			while (e.hasMoreElements()) {
627
			while (e.hasMoreElements()) {
Lines 624-629 Link Here
624
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION, feature.getDescription());
650
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION, feature.getDescription());
625
		if (feature.getDescriptionURL() != null)
651
		if (feature.getDescriptionURL() != null)
626
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION_URL, feature.getDescriptionURL());
652
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION_URL, feature.getDescriptionURL());
653
		if (feature.getProviderName() != null)
654
			iu.setProperty(IInstallableUnit.PROP_PROVIDER, feature.getProviderName());
627
		if (feature.getLicense() != null)
655
		if (feature.getLicense() != null)
628
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
656
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
629
		if (feature.getCopyright() != null)
657
		if (feature.getCopyright() != null)
Lines 643-649 Link Here
643
		// TODO: shouldn't the filter for the group be constructed from os, ws, arch, nl
671
		// TODO: shouldn't the filter for the group be constructed from os, ws, arch, nl
644
		// 		 of the feature?
672
		// 		 of the feature?
645
		// iu.setFilter(filter);
673
		// iu.setFilter(filter);
646
		iu.setCapabilities(new ProvidedCapability[] {createSelfCapability(id, version)});
674
675
		// Create set of provided capabilities
676
		ArrayList providedCapabilities = new ArrayList();
677
		providedCapabilities.add(createSelfCapability(id, version));
678
679
		Map localizations = feature.getLocalizations();
680
		if (localizations != null) {
681
			for (Iterator iter = localizations.keySet().iterator(); iter.hasNext();) {
682
				Locale locale = (Locale) iter.next();
683
				Properties translatedStrings = (Properties) localizations.get(locale);
684
				Enumeration propertyKeys = translatedStrings.propertyNames();
685
				while (propertyKeys.hasMoreElements()) {
686
					String nextKey = (String) propertyKeys.nextElement();
687
					iu.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey));
688
				}
689
				providedCapabilities.add(makeTranslationCapability(id, locale));
690
			}
691
		}
692
693
		iu.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()]));
647
694
648
		if (extraProperties != null) {
695
		if (extraProperties != null) {
649
			Enumeration e = extraProperties.propertyNames();
696
			Enumeration e = extraProperties.propertyNames();
Lines 663-672 Link Here
663
		Version version = new Version(feature.getVersion());
710
		Version version = new Version(feature.getVersion());
664
		iu.setVersion(version);
711
		iu.setVersion(version);
665
		iu.setProperty(IInstallableUnit.PROP_NAME, feature.getLabel());
712
		iu.setProperty(IInstallableUnit.PROP_NAME, feature.getLabel());
666
		if (feature.getDescription() != null)
667
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION, feature.getDescription());
668
		if (feature.getDescriptionURL() != null)
669
			iu.setProperty(IInstallableUnit.PROP_DESCRIPTION_URL, feature.getDescriptionURL());
670
		if (feature.getLicense() != null)
713
		if (feature.getLicense() != null)
671
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
714
			iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense()));
672
		if (feature.getCopyright() != null)
715
		if (feature.getCopyright() != null)
Lines 1098-1106 Link Here
1098
1141
1099
		if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$
1142
		if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$
1100
				bundleLocation.isFile()) {
1143
				bundleLocation.isFile()) {
1101
			localizations = getJarManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1144
			localizations = LocalizationHelper.getJarPropertyLocalizations(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1145
			//localizations = getJarManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1102
		} else {
1146
		} else {
1103
			localizations = getDirManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1147
			localizations = LocalizationHelper.getDirPropertyLocalizations(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1148
			// localizations = getDirManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues);
1104
		}
1149
		}
1105
1150
1106
		return localizations;
1151
		return localizations;
Lines 1129-1293 Link Here
1129
1174
1130
		if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$
1175
		if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$
1131
				bundleLocation.isFile()) {
1176
				bundleLocation.isFile()) {
1132
			localizations = getJarManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1177
			localizations = LocalizationHelper.getJarPropertyLocalizations(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1178
			//localizations = getJarManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1133
		} else {
1179
		} else {
1134
			localizations = getDirManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1180
			localizations = LocalizationHelper.getDirPropertyLocalizations(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1135
		}
1181
			// localizations = getDirManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues);
1136
1137
		return localizations;
1138
	}
1139
1140
	private static Map getJarManifestLocalization(File bundleLocation, String bundleLocalization, Locale defaultLocale, String[] bundleManifestValues) {
1141
		ZipFile jarFile = null;
1142
		Map localizations = new HashMap(4);
1143
		try {
1144
			jarFile = new ZipFile(bundleLocation, ZipFile.OPEN_READ);
1145
			for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) {
1146
				ZipEntry nextEntry = (ZipEntry) entries.nextElement();
1147
				String nextName = nextEntry.getName();
1148
				String localeString = getLocaleString(nextName, bundleLocalization);
1149
1150
				if (!nextEntry.isDirectory() && localeString != null) {
1151
					Locale nextLocale = getLocale(localeString);
1152
					InputStream stream = null;
1153
					try {
1154
						stream = jarFile.getInputStream(nextEntry);
1155
						Properties properties = new Properties();
1156
						properties.load(stream);
1157
						Properties localizedStrings = getLocalizedProperties(bundleManifestValues, properties);
1158
						if (localizedStrings.size() > 0) {
1159
							localizations.put(nextLocale, localizedStrings);
1160
							if (DEFAULT_LOCALE.equals(nextLocale) && defaultLocale != null) {
1161
								localizations.put(nextLocale, localizedStrings);
1162
							}
1163
						}
1164
					} finally {
1165
						if (stream != null)
1166
							stream.close();
1167
					}
1168
				}
1169
			}
1170
		} catch (IOException ioe) {
1171
			ioe.printStackTrace();
1172
		} finally {
1173
			if (jarFile != null) {
1174
				try {
1175
					jarFile.close();
1176
				} catch (IOException ioe) {
1177
					// do nothing
1178
				}
1179
			}
1180
		}
1181
1182
		return localizations;
1183
	}
1184
1185
	private static Map getDirManifestLocalization(File bundleLocation, String bundleLocalization, Locale defaultLocale, String[] hostBundleManifestValues) {
1186
		File localizationPath = new File(bundleLocation, bundleLocalization);
1187
		File localizationDir = localizationPath.getParentFile();
1188
		final String localizationFile = localizationPath.getName();
1189
		MetadataGeneratorHelper foo = new MetadataGeneratorHelper();
1190
		String[] localizationFiles = localizationDir.list(foo.new LocalizationFileFilter() {
1191
			public boolean accept(File directory, String filename) {
1192
				return (getLocaleString(filename, localizationFile) != null ? true : false);
1193
			}
1194
		});
1195
1196
		HashMap localizations = null;
1197
1198
		if (localizationFiles != null) {
1199
			localizations = new HashMap(localizationFiles.length);
1200
			for (int i = 0; i < localizationFiles.length; i++) {
1201
				String nextFile = localizationFiles[i];
1202
				Locale nextLocale = getLocale(getLocaleString(nextFile, localizationFile));
1203
1204
				try {
1205
					Properties properties = loadProperties(bundleLocation, nextFile);
1206
					Properties localizedStrings = getLocalizedProperties(hostBundleManifestValues, properties);
1207
					if (localizedStrings.size() > 0) {
1208
						localizations.put(nextLocale, localizedStrings);
1209
						if (DEFAULT_LOCALE.equals(nextLocale) && defaultLocale != null) {
1210
							localizations.put(nextLocale, localizedStrings);
1211
						}
1212
					}
1213
				} catch (IOException ioe) {
1214
					ioe.printStackTrace();
1215
				}
1216
			}
1217
		}
1182
		}
1218
1183
1219
		return localizations;
1184
		return localizations;
1220
	}
1185
	}
1221
1186
1222
	private abstract class LocalizationFileFilter implements FilenameFilter {
1223
1224
		public LocalizationFileFilter() {
1225
			// Nothing to do
1226
		}
1227
1228
		/* (non-Javadoc)
1229
		 * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
1230
		 */
1231
		public abstract boolean accept(File directory, String filename);
1232
	}
1233
1234
	static public String getLocaleString(String filename, String filenamePrefix) {
1235
		String localeString = null;
1236
		if (filename.startsWith(filenamePrefix) && filename.endsWith(PROPERTIES_FILE_EXTENSION)) {
1237
			if (filename.length() > filenamePrefix.length() + PROPERTIES_FILE_EXTENSION.length()) {
1238
				localeString = filename.substring(filenamePrefix.length() + 1, filename.length() - PROPERTIES_FILE_EXTENSION.length());
1239
			} else {
1240
				localeString = ""; //$NON-NLS-1$
1241
			}
1242
		}
1243
		return localeString;
1244
	}
1245
1246
	private static Properties loadProperties(File bundleLocation, String localizationFile) throws IOException {
1247
		Properties result = new Properties();
1248
		InputStream propertyStream = null;
1249
		try {
1250
			try {
1251
				if (bundleLocation.isDirectory())
1252
					propertyStream = new FileInputStream(new File(bundleLocation, localizationFile));
1253
				else {
1254
					URLConnection connection = new URL("jar:" + bundleLocation.toURL().toExternalForm() + "!/" + localizationFile).openConnection(); //$NON-NLS-1$ //$NON-NLS-2$
1255
					connection.setUseCaches(false);
1256
					propertyStream = connection.getInputStream();
1257
				}
1258
			} catch (FileNotFoundException e) {
1259
				// if there is no messages file then just return;
1260
				return result;
1261
			}
1262
			result.load(propertyStream);
1263
		} finally {
1264
			if (propertyStream != null)
1265
				propertyStream.close();
1266
		}
1267
		return result;
1268
	}
1269
1270
	static private Locale getLocale(String localeString) {
1271
		Locale locale = DEFAULT_LOCALE;
1272
		if (localeString.length() == 5 && localeString.indexOf('_') == 2) {
1273
			locale = new Locale(localeString.substring(0, 2), localeString.substring(3, 5));
1274
		} else if (localeString.length() == 2) {
1275
			locale = new Locale(localeString.substring(0, 2));
1276
		}
1277
		return locale;
1278
	}
1279
1280
	static private Properties getLocalizedProperties(String[] bundleManifestKeys, Properties properties) {
1281
		Properties localizedProperties = new Properties();
1282
		for (int i = 0; i < BUNDLE_LOCALIZED_PROPERTIES.length; i++) {
1283
			String key = bundleManifestKeys[i];
1284
			if (key != null) {
1285
				String localizedValue = properties.getProperty(key);
1286
				if (localizedValue != null)
1287
					localizedProperties.put(key, localizedValue);
1288
			}
1289
		}
1290
		return localizedProperties;
1291
	}
1292
1293
}
1187
}
(-)src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Feature.java (-3 / +15 lines)
Lines 11-16 Link Here
11
package org.eclipse.equinox.internal.provisional.p2.metadata.generator;
11
package org.eclipse.equinox.internal.provisional.p2.metadata.generator;
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Map;
14
15
15
/**
16
/**
16
 * 
17
 * 
Lines 43-48 Link Here
43
44
44
	private String location;
45
	private String location;
45
46
47
	private Map localizations;
48
46
	public Feature(String id, String version) {
49
	public Feature(String id, String version) {
47
		if (id == null)
50
		if (id == null)
48
			throw new IllegalArgumentException();
51
			throw new IllegalArgumentException();
Lines 50-63 Link Here
50
		this.version = version;
53
		this.version = version;
51
	}
54
	}
52
55
53
	public void addDiscoverySite(String label, String url) {
56
	public void addDiscoverySite(String siteLabel, String url) {
54
		if (label == null && url == null)
57
		if (siteLabel == null && url == null)
55
			return;
58
			return;
56
59
57
		if (this.discoverySites == null)
60
		if (this.discoverySites == null)
58
			this.discoverySites = new ArrayList();
61
			this.discoverySites = new ArrayList();
59
62
60
		URLEntry entry = new URLEntry(url, label);
63
		URLEntry entry = new URLEntry(url, siteLabel);
61
		this.discoverySites.add(entry);
64
		this.discoverySites.add(entry);
62
	}
65
	}
63
66
Lines 143-148 Link Here
143
		return null;
146
		return null;
144
	}
147
	}
145
148
149
	public Map getLocalizations() {
150
		return this.localizations;
151
	}
152
146
	public String getLocation() {
153
	public String getLocation() {
147
		return this.location;
154
		return this.location;
148
	}
155
	}
Lines 242-247 Link Here
242
		this.license.setURL(licenseURL);
249
		this.license.setURL(licenseURL);
243
	}
250
	}
244
251
252
	public void setLocalizations(Map localizations) {
253
		this.localizations = localizations;
254
	}
255
245
	public void setLocation(String location) {
256
	public void setLocation(String location) {
246
		this.location = location;
257
		this.location = location;
247
	}
258
	}
Lines 263-268 Link Here
263
	}
274
	}
264
275
265
	public void setURL(String value) {
276
	public void setURL(String value) {
277
		//
266
	}
278
	}
267
279
268
	public void setVersion(String version) {
280
	public void setVersion(String version) {
(-)src/org/eclipse/equinox/internal/p2/metadata/generator/features/FeatureParser.java (-19 / +30 lines)
Lines 12-18 Link Here
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Properties;
15
import java.util.*;
16
import java.util.jar.JarEntry;
16
import java.util.jar.JarEntry;
17
import java.util.jar.JarFile;
17
import java.util.jar.JarFile;
18
import javax.xml.parsers.*;
18
import javax.xml.parsers.*;
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
21
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
22
import org.eclipse.equinox.internal.p2.metadata.generator.Activator;
22
import org.eclipse.equinox.internal.p2.metadata.generator.Activator;
23
import org.eclipse.equinox.internal.p2.metadata.generator.LocalizationHelper;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.Feature;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.Feature;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.FeatureEntry;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.generator.FeatureEntry;
25
import org.eclipse.osgi.util.NLS;
26
import org.eclipse.osgi.util.NLS;
Lines 41-46 Link Here
41
	private StringBuffer characters = null;
42
	private StringBuffer characters = null;
42
43
43
	private Properties messages = null;
44
	private Properties messages = null;
45
	private List messageKeys = null;
44
46
45
	public FeatureParser() {
47
	public FeatureParser() {
46
		this(true);
48
		this(true);
Lines 87-103 Link Here
87
		return result;
89
		return result;
88
	}
90
	}
89
91
90
	private Properties loadProperties(File directory) {
92
	private void loadProperties(File directory, Properties properties) {
91
		//skip directories that don't contain a feature.properties file
93
		//skip directories that don't contain a feature.properties file
92
		File file = new File(directory, "feature.properties"); //$NON-NLS-1$
94
		File file = new File(directory, "feature.properties"); //$NON-NLS-1$
93
		if (!file.exists())
95
		if (!file.exists())
94
			return null;
96
			return;
95
		try {
97
		try {
96
			InputStream input = new BufferedInputStream(new FileInputStream(file));
98
			InputStream input = new BufferedInputStream(new FileInputStream(file));
97
			try {
99
			try {
98
				Properties result = new Properties();
100
				properties.load(input);
99
				result.load(input);
100
				return result;
101
			} finally {
101
			} finally {
102
				if (input != null)
102
				if (input != null)
103
					input.close();
103
					input.close();
Lines 105-123 Link Here
105
		} catch (IOException e) {
105
		} catch (IOException e) {
106
			e.printStackTrace();
106
			e.printStackTrace();
107
		}
107
		}
108
		return null;
109
	}
108
	}
110
109
111
	private Properties loadProperties(JarFile jar) {
110
	private void loadProperties(JarFile jar, Properties properties) {
112
		JarEntry entry = jar.getJarEntry("feature.properties"); //$NON-NLS-1$
111
		JarEntry entry = jar.getJarEntry("feature.properties"); //$NON-NLS-1$
113
		if (entry == null)
112
		if (entry == null)
114
			return null;
113
			return;
115
		try {
114
		try {
116
			InputStream input = new BufferedInputStream(jar.getInputStream(entry));
115
			InputStream input = new BufferedInputStream(jar.getInputStream(entry));
117
			try {
116
			try {
118
				Properties result = new Properties();
117
				properties.load(input);
119
				result.load(input);
120
				return result;
121
			} finally {
118
			} finally {
122
				if (input != null)
119
				if (input != null)
123
					input.close();
120
					input.close();
Lines 125-131 Link Here
125
		} catch (IOException e) {
122
		} catch (IOException e) {
126
			e.printStackTrace();
123
			e.printStackTrace();
127
		}
124
		}
128
		return null;
129
	}
125
	}
130
126
131
	private String localize(String value) {
127
	private String localize(String value) {
Lines 133-139 Link Here
133
			return value;
129
			return value;
134
		if (!value.startsWith("%")) //$NON-NLS-1$
130
		if (!value.startsWith("%")) //$NON-NLS-1$
135
			return value;
131
			return value;
136
		return messages.getProperty(value.substring(1), value);
132
		String key = value.substring(1);
133
		messageKeys.add(key);
134
		return value;
137
	}
135
	}
138
136
139
	/**
137
	/**
Lines 146-160 Link Here
146
	public Feature parse(File location) {
144
	public Feature parse(File location) {
147
		if (!location.exists())
145
		if (!location.exists())
148
			return null;
146
			return null;
147
148
		Feature feature = null;
149
		Properties properties = new Properties();
150
149
		if (location.isDirectory()) {
151
		if (location.isDirectory()) {
150
			//skip directories that don't contain a feature.xml file
152
			//skip directories that don't contain a feature.xml file
151
			File file = new File(location, "feature.xml"); //$NON-NLS-1$
153
			File file = new File(location, "feature.xml"); //$NON-NLS-1$
152
			if (!file.exists())
154
			if (!file.exists())
153
				return null;
155
				return null;
154
			Properties properties = loadProperties(location);
156
			loadProperties(location, properties);
155
			try {
157
			try {
156
				InputStream input = new BufferedInputStream(new FileInputStream(file));
158
				InputStream input = new BufferedInputStream(new FileInputStream(file));
157
				return parse(input, properties);
159
				feature = parse(input, properties);
160
				if (feature != null) {
161
					String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]);
162
					feature.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(location, "feature", null, keyStrings)); //$NON-NLS-1$
163
				}
158
			} catch (FileNotFoundException e) {
164
			} catch (FileNotFoundException e) {
159
				e.printStackTrace();
165
				e.printStackTrace();
160
			}
166
			}
Lines 162-173 Link Here
162
			JarFile jar = null;
168
			JarFile jar = null;
163
			try {
169
			try {
164
				jar = new JarFile(location);
170
				jar = new JarFile(location);
165
				Properties properties = loadProperties(jar);
171
				loadProperties(jar, properties);
166
				JarEntry entry = jar.getJarEntry("feature.xml"); //$NON-NLS-1$
172
				JarEntry entry = jar.getJarEntry("feature.xml"); //$NON-NLS-1$
167
				if (entry == null)
173
				if (entry == null)
168
					return null;
174
					return null;
169
				InputStream input = new BufferedInputStream(jar.getInputStream(entry));
175
				InputStream input = new BufferedInputStream(jar.getInputStream(entry));
170
				return parse(input, properties);
176
				feature = parse(input, properties);
177
				if (feature != null) {
178
					String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]);
179
					feature.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(location, "feature", null, keyStrings)); //$NON-NLS-1$
180
				}
171
			} catch (IOException e) {
181
			} catch (IOException e) {
172
				e.printStackTrace();
182
				e.printStackTrace();
173
			} catch (SecurityException e) {
183
			} catch (SecurityException e) {
Lines 181-187 Link Here
181
				}
191
				}
182
			}
192
			}
183
		}
193
		}
184
		return null;
194
		return feature;
185
	}
195
	}
186
196
187
	/**
197
	/**
Lines 190-195 Link Here
190
	 */
200
	 */
191
	public Feature parse(InputStream in, Properties messages) {
201
	public Feature parse(InputStream in, Properties messages) {
192
		this.messages = messages;
202
		this.messages = messages;
203
		this.messageKeys = new ArrayList(messages.size());
193
		result = null;
204
		result = null;
194
		try {
205
		try {
195
			parser.parse(new InputSource(in), this);
206
			parser.parse(new InputSource(in), this);
(-)src/org/eclipse/equinox/internal/p2/metadata/generator/LocalizationHelper.java (+200 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.metadata.generator;
12
13
import java.io.*;
14
import java.net.URL;
15
import java.net.URLConnection;
16
import java.util.*;
17
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipFile;
19
20
/**
21
 * 	Helper functions supporting the processing of localized
22
 * 	property files.
23
 *
24
 */
25
public final class LocalizationHelper {
26
27
	private static final String PROPERTIES_FILE_EXTENSION = ".properties"; //$NON-NLS-1$
28
	private static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$
29
	private static LocalizationHelper instance = new LocalizationHelper();
30
31
	// Extract the locale string from the properties file with the given filename
32
	// where the locale string follows the given prefix. For example, return "zh_HK"
33
	// from filename == "plugin_zh_HK.properties" and prefix == "plugin". 
34
	static public String getLocaleString(String filename, String prefix) {
35
		String localeString = null;
36
		if (filename.startsWith(prefix) && filename.endsWith(PROPERTIES_FILE_EXTENSION)) {
37
			if (filename.length() > prefix.length() + PROPERTIES_FILE_EXTENSION.length()) {
38
				localeString = filename.substring(prefix.length() + 1, filename.length() - PROPERTIES_FILE_EXTENSION.length());
39
			} else {
40
				localeString = ""; //$NON-NLS-1$
41
			}
42
		}
43
		return localeString;
44
	}
45
46
	// Get the locale corresponding to the given locale string
47
	static public Locale getLocale(String localeString) {
48
		Locale locale = DEFAULT_LOCALE;
49
		if (localeString.length() == 5 && localeString.indexOf('_') == 2) {
50
			locale = new Locale(localeString.substring(0, 2), localeString.substring(3, 5));
51
		} else if (localeString.length() == 2) {
52
			locale = new Locale(localeString.substring(0, 2));
53
		}
54
		return locale;
55
	}
56
57
	// For the given root directory and path to localization files within that directory
58
	// get a map from locale to property set for the localization property files.
59
	public static Map getDirPropertyLocalizations(File root, String localizationPath, Locale defaultLocale, String[] propertyKeys) {
60
		File fullPath = new File(root, localizationPath);
61
		File localizationDir = fullPath.getParentFile();
62
		final String localizationFile = fullPath.getName();
63
		String[] localizationFiles = LocalizationHelper.getLocalizationFiles(localizationDir, localizationFile);
64
65
		HashMap localizations = null;
66
67
		if (localizationFiles != null) {
68
			localizations = new HashMap(localizationFiles.length);
69
			for (int i = 0; i < localizationFiles.length; i++) {
70
				String nextFile = localizationFiles[i];
71
				Locale nextLocale = getLocale(LocalizationHelper.getLocaleString(nextFile, localizationFile));
72
73
				try {
74
					Properties properties = loadProperties(root, nextFile);
75
					Properties localizedStrings = getLocalizedProperties(propertyKeys, properties);
76
					if (localizedStrings.size() > 0) {
77
						localizations.put(nextLocale, localizedStrings);
78
						if (DEFAULT_LOCALE.equals(nextLocale) && defaultLocale != null) {
79
							localizations.put(nextLocale, localizedStrings);
80
						}
81
					}
82
				} catch (IOException ioe) {
83
					ioe.printStackTrace();
84
				}
85
			}
86
		}
87
88
		return localizations;
89
	}
90
91
	public static Map getJarPropertyLocalizations(File root, String localizationPath, Locale defaultLocale, String[] propertyKeys) {
92
		ZipFile jarFile = null;
93
		Map localizations = new HashMap(4);
94
		try {
95
			jarFile = new ZipFile(root, ZipFile.OPEN_READ);
96
			for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) {
97
				ZipEntry nextEntry = (ZipEntry) entries.nextElement();
98
				String nextName = nextEntry.getName();
99
				String localeString = LocalizationHelper.getLocaleString(nextName, localizationPath);
100
101
				if (!nextEntry.isDirectory() && localeString != null) {
102
					Locale nextLocale = LocalizationHelper.getLocale(localeString);
103
					InputStream stream = null;
104
					try {
105
						stream = jarFile.getInputStream(nextEntry);
106
						Properties properties = new Properties();
107
						properties.load(stream);
108
						Properties localizedStrings = LocalizationHelper.getLocalizedProperties(propertyKeys, properties);
109
						if (localizedStrings.size() > 0) {
110
							localizations.put(nextLocale, localizedStrings);
111
							if (DEFAULT_LOCALE.equals(nextLocale) && defaultLocale != null) {
112
								localizations.put(nextLocale, localizedStrings);
113
							}
114
						}
115
					} finally {
116
						if (stream != null)
117
							stream.close();
118
					}
119
				}
120
			}
121
		} catch (IOException ioe) {
122
			ioe.printStackTrace();
123
		} finally {
124
			if (jarFile != null) {
125
				try {
126
					jarFile.close();
127
				} catch (IOException ioe) {
128
					// do nothing
129
				}
130
			}
131
		}
132
133
		return localizations;
134
	}
135
136
	// Load a property set from given root and file with the given name
137
	private static Properties loadProperties(File root, String propertyFilename) throws IOException {
138
		Properties result = new Properties();
139
		InputStream propertyStream = null;
140
		try {
141
			try {
142
				if (root.isDirectory())
143
					propertyStream = new FileInputStream(new File(root, propertyFilename));
144
				else {
145
					URLConnection connection = new URL("jar:" + root.toURL().toExternalForm() + "!/" + propertyFilename).openConnection(); //$NON-NLS-1$ //$NON-NLS-2$
146
					connection.setUseCaches(false);
147
					propertyStream = connection.getInputStream();
148
				}
149
			} catch (FileNotFoundException e) {
150
				// if there is no messages file then just return;
151
				return result;
152
			}
153
			result.load(propertyStream);
154
		} finally {
155
			if (propertyStream != null)
156
				propertyStream.close();
157
		}
158
		return result;
159
	}
160
161
	// Given a list of keys and the corresponding localized property set,
162
	// return a new property set with those keys and the localized values. 
163
	static public Properties getLocalizedProperties(String[] propertyKeys, Properties properties) {
164
		Properties localizedProperties = new Properties();
165
		for (int i = 0; i < propertyKeys.length; i++) {
166
			String key = propertyKeys[i];
167
			if (key != null) {
168
				String localizedValue = properties.getProperty(key);
169
				if (localizedValue != null)
170
					localizedProperties.put(key, localizedValue);
171
			}
172
		}
173
		return localizedProperties;
174
	}
175
176
	public static String[] getLocalizationFiles(File localizationDir, final String filenamePrefix) {
177
		return localizationDir.list(instance.new FileFilter() {
178
			public boolean accept(File directory, String filename) {
179
				return (getLocaleString(filename, filenamePrefix) != null ? true : false);
180
			}
181
		});
182
	}
183
184
	private abstract class FileFilter implements FilenameFilter {
185
186
		public FileFilter() {
187
			// Nothing to do
188
		}
189
190
		/* (non-Javadoc)
191
		 * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
192
		 */
193
		public abstract boolean accept(File directory, String filename);
194
	}
195
196
	private LocalizationHelper() {
197
		//
198
	}
199
200
}
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/query/IUPropertyUtils.java (-6 / +61 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.provisional.p2.ui.query;
11
package org.eclipse.equinox.internal.provisional.p2.ui.query;
12
12
13
import java.net.URL;
13
import java.util.*;
14
import java.util.*;
14
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
15
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
15
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
16
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
Lines 24-35 Link Here
24
	static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$
25
	static final Locale DEFAULT_LOCALE = new Locale("df", "LT"); //$NON-NLS-1$//$NON-NLS-2$
25
	static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$
26
	static final String NAMESPACE_IU_LOCALIZATION = "org.eclipse.equinox.p2.localization"; //$NON-NLS-1$
26
27
28
	// Get the license in the default locale.
29
	public static License getLicense(IInstallableUnit iu) {
30
		return getLicense(iu, getCurrentLocale());
31
	}
32
33
	// Get the copyright in the default locale.
34
	public static Copyright getCopyright(IInstallableUnit iu) {
35
		return getCopyright(iu, getCurrentLocale());
36
	}
37
38
	// Get a property in the default locale
39
	public static String getIUProperty(IInstallableUnit iu, String propertyKey) {
40
		return getIUProperty(iu, propertyKey, getCurrentLocale());
41
	}
42
43
	public static License getLicense(IInstallableUnit iu, Locale locale) {
44
		License license = iu.getLicense();
45
		String body = (license != null ? license.getBody() : null);
46
		if (body == null || body.length() <= 1 || body.charAt(0) != '%')
47
			return license;
48
		final String actualKey = body.substring(1); // Strip off the %
49
		body = getLocalizedIUProperty(iu, actualKey, locale);
50
		URL url = license.getURL();
51
		return new License((url != null ? url.toExternalForm() : null), body);
52
	}
53
54
	public static Copyright getCopyright(IInstallableUnit iu, Locale locale) {
55
		Copyright copyright = iu.getCopyright();
56
		String body = (copyright != null ? copyright.getBody() : null);
57
		if (body == null || body.length() <= 1 || body.charAt(0) != '%')
58
			return copyright;
59
		final String actualKey = body.substring(1); // Strip off the %
60
		body = getLocalizedIUProperty(iu, actualKey, locale);
61
		URL url = copyright.getURL();
62
		return new Copyright((url != null ? url.toExternalForm() : null), body);
63
	}
64
27
	public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) {
65
	public static String getIUProperty(IInstallableUnit iu, String propertyKey, Locale locale) {
28
		String value = iu.getProperty(propertyKey);
66
		String value = iu.getProperty(propertyKey);
29
		if (value == null || value.length() <= 1 || value.charAt(0) != '%')
67
		if (value == null || value.length() <= 1 || value.charAt(0) != '%')
30
			return value;
68
			return value;
31
		// else have a localizable property
69
		// else have a localizable property
32
		final String actualKey = value.substring(1); // Strip off the %
70
		final String actualKey = value.substring(1); // Strip off the %
71
		return getLocalizedIUProperty(iu, actualKey, locale);
72
	}
73
74
	private static String getLocalizedIUProperty(IInstallableUnit iu, String actualKey, Locale locale) {
75
		// Short circuit query if iu provides value for matching locale	
76
		String localizedKey = makeLocalizedKey(actualKey, locale.toString());
77
		String localizedValue = iu.getProperty(localizedKey);
78
		if (localizedValue != null)
79
			return localizedValue;
80
33
		final List locales = buildLocaleVariants(locale);
81
		final List locales = buildLocaleVariants(locale);
34
		final IInstallableUnit theUnit = iu;
82
		final IInstallableUnit theUnit = iu;
35
83
Lines 89-100 Link Here
89
			}
137
			}
90
		}
138
		}
91
139
92
		String defaultKey = makeLocalizedKey(actualKey, DEFAULT_LOCALE.toString());
140
		for (Iterator iter = locales.iterator(); iter.hasNext();) {
93
		String defaultValue = iu.getProperty(defaultKey);
141
			String nextLocale = (String) iter.next();
94
		if (defaultValue != null)
142
			String localeKey = makeLocalizedKey(actualKey, nextLocale);
95
			return defaultValue;
143
			String nextValue = iu.getProperty(localeKey);
144
			if (nextValue != null)
145
				return nextValue;
146
		}
96
147
97
		return value;
148
		return actualKey;
98
	}
149
	}
99
150
100
	/**
151
	/**
Lines 111-117 Link Here
111
			nl = nl.substring(0, lastSeparator);
162
			nl = nl.substring(0, lastSeparator);
112
		}
163
		}
113
		// Add the default locale (most general)
164
		// Add the default locale (most general)
114
		result.add(DEFAULT_LOCALE);
165
		result.add(DEFAULT_LOCALE.toString());
115
		return result;
166
		return result;
116
	}
167
	}
117
168
Lines 119-122 Link Here
119
		return localeImage + '.' + actualKey;
170
		return localeImage + '.' + actualKey;
120
	}
171
	}
121
172
173
	private static Locale getCurrentLocale() {
174
		return Locale.getDefault();
175
	}
176
122
}
177
}
(-)src/org/eclipse/equinox/internal/p2/ui/dialogs/ProfileModificationWizardPage.java (-1 / +3 lines)
Lines 25-30 Link Here
25
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
25
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
26
import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningOperationRunner;
26
import org.eclipse.equinox.internal.provisional.p2.ui.ProvisioningOperationRunner;
27
import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProfileModificationOperation;
27
import org.eclipse.equinox.internal.provisional.p2.ui.operations.ProfileModificationOperation;
28
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
28
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.*;
29
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.*;
29
import org.eclipse.jface.dialogs.Dialog;
30
import org.eclipse.jface.dialogs.Dialog;
30
import org.eclipse.jface.dialogs.IMessageProvider;
31
import org.eclipse.jface.dialogs.IMessageProvider;
Lines 329-335 Link Here
329
	}
330
	}
330
331
331
	protected String getIUDescription(IInstallableUnit iu) {
332
	protected String getIUDescription(IInstallableUnit iu) {
332
		String description = iu.getProperty(IInstallableUnit.PROP_DESCRIPTION);
333
		// Get the iu description in the default locale
334
		String description = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION);
333
		if (description == null)
335
		if (description == null)
334
			description = ""; //$NON-NLS-1$
336
			description = ""; //$NON-NLS-1$
335
		return description;
337
		return description;
(-)src/org/eclipse/equinox/internal/p2/ui/viewers/IUDetailsLabelProvider.java (-1 / +3 lines)
Lines 22-27 Link Here
22
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
22
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
23
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUIImages;
23
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUIImages;
24
import org.eclipse.equinox.internal.provisional.p2.ui.model.IUElement;
24
import org.eclipse.equinox.internal.provisional.p2.ui.model.IUElement;
25
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
25
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.IUColumnConfig;
26
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.IUColumnConfig;
26
import org.eclipse.jface.viewers.*;
27
import org.eclipse.jface.viewers.*;
27
import org.eclipse.osgi.util.NLS;
28
import org.eclipse.osgi.util.NLS;
Lines 88-94 Link Here
88
			case IUColumnConfig.COLUMN_ID :
89
			case IUColumnConfig.COLUMN_ID :
89
				return iu.getId();
90
				return iu.getId();
90
			case IUColumnConfig.COLUMN_NAME :
91
			case IUColumnConfig.COLUMN_NAME :
91
				String name = iu.getProperty(IInstallableUnit.PROP_NAME);
92
				// Get the iu name in the current locale
93
				String name = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME);
92
				if (name != null)
94
				if (name != null)
93
					return name;
95
					return name;
94
				return BLANK;
96
				return BLANK;
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IULicensePropertyPage.java (-2 / +3 lines)
Lines 14-19 Link Here
14
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
14
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.License;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.License;
17
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionAdapter;
Lines 30-37 Link Here
30
public class IULicensePropertyPage extends IUPropertyPage {
31
public class IULicensePropertyPage extends IUPropertyPage {
31
32
32
	protected Control createIUPage(Composite parent, IInstallableUnit iu) {
33
	protected Control createIUPage(Composite parent, IInstallableUnit iu) {
33
34
		// Get the license in the default locale
34
		final License license = iu.getLicense();
35
		final License license = IUPropertyUtils.getLicense(iu);
35
		if (license != null && license.getBody().length() > 0) {
36
		if (license != null && license.getBody().length() > 0) {
36
			Composite composite = new Composite(parent, SWT.NONE);
37
			Composite composite = new Composite(parent, SWT.NONE);
37
			GridLayout layout = new GridLayout();
38
			GridLayout layout = new GridLayout();
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/AvailableIUPatternFilter.java (-1 / +3 lines)
Lines 13-18 Link Here
13
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
13
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
14
import org.eclipse.equinox.internal.provisional.p2.ui.model.CategoryElement;
14
import org.eclipse.equinox.internal.provisional.p2.ui.model.CategoryElement;
15
import org.eclipse.equinox.internal.provisional.p2.ui.model.IUElement;
15
import org.eclipse.equinox.internal.provisional.p2.ui.model.IUElement;
16
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
16
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.IUColumnConfig;
17
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.IUColumnConfig;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.ui.dialogs.PatternFilter;
19
import org.eclipse.ui.dialogs.PatternFilter;
Lines 89-95 Link Here
89
		if (element instanceof IUElement) {
90
		if (element instanceof IUElement) {
90
			IInstallableUnit iu = ((IUElement) element).getIU();
91
			IInstallableUnit iu = ((IUElement) element).getIU();
91
			if (checkName) {
92
			if (checkName) {
92
				text = iu.getProperty(IInstallableUnit.PROP_NAME);
93
				// Get the iu name in the default locale
94
				text = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME);
93
				if (text != null && wordMatches(text))
95
				if (text != null && wordMatches(text))
94
					return true;
96
					return true;
95
			}
97
			}
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUCopyrightPropertyPage.java (-1 / +3 lines)
Lines 14-19 Link Here
14
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
14
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.Copyright;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.Copyright;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
17
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionAdapter;
Lines 30-36 Link Here
30
public class IUCopyrightPropertyPage extends IUPropertyPage {
31
public class IUCopyrightPropertyPage extends IUPropertyPage {
31
32
32
	protected Control createIUPage(Composite parent, IInstallableUnit iu) {
33
	protected Control createIUPage(Composite parent, IInstallableUnit iu) {
33
		final Copyright copyright = iu.getCopyright();
34
		// Get the copyright in the current locale
35
		final Copyright copyright = IUPropertyUtils.getCopyright(iu);
34
		if (copyright != null && copyright.getBody().length() > 0) {
36
		if (copyright != null && copyright.getBody().length() > 0) {
35
			Composite composite = new Composite(parent, SWT.NONE);
37
			Composite composite = new Composite(parent, SWT.NONE);
36
			GridLayout layout = new GridLayout();
38
			GridLayout layout = new GridLayout();
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/dialogs/IUGeneralInfoPropertyPage.java (-7 / +6 lines)
Lines 12-18 Link Here
12
12
13
import java.net.MalformedURLException;
13
import java.net.MalformedURLException;
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Locale;
16
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
15
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
17
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
16
import org.eclipse.equinox.internal.p2.ui.dialogs.IUPropertyPage;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
17
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
Lines 54-71 Link Here
54
		layout.marginHeight = 0;
53
		layout.marginHeight = 0;
55
		composite.setLayout(layout);
54
		composite.setLayout(layout);
56
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
55
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
57
		Locale currentLocale = Locale.getDefault();
56
		// Get general info in the default locale
58
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME, currentLocale));
57
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_NameLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME));
59
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId());
58
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_IdentifierLabel, iu.getId());
60
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString());
59
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_VersionLabel, iu.getVersion().toString());
61
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER, currentLocale));
60
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ProviderLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_PROVIDER));
62
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_CONTACT, currentLocale));
61
		addField(composite, ProvUIMessages.IUGeneralInfoPropertyPage_ContactLabel, IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_CONTACT));
63
62
64
	}
63
	}
65
64
66
	private void createDescriptionSection(Composite parent, IInstallableUnit iu) {
65
	private void createDescriptionSection(Composite parent, IInstallableUnit iu) {
67
		Locale currentLocale = Locale.getDefault();
66
		// Get the iu description in the default locale
68
		String description = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION, currentLocale);
67
		String description = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_DESCRIPTION);
69
		if (description != null && description.length() > 0) {
68
		if (description != null && description.length() > 0) {
70
			Group group = new Group(parent, SWT.NONE);
69
			Group group = new Group(parent, SWT.NONE);
71
			group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);
70
			group.setText(ProvUIMessages.IUGeneralInfoPropertyPage_DescriptionLabel);
(-)src/org/eclipse/equinox/internal/p2/ui/PlanStatusHelper.java (-1 / +3 lines)
Lines 17-22 Link Here
17
import org.eclipse.equinox.internal.provisional.p2.engine.Operand;
17
import org.eclipse.equinox.internal.provisional.p2.engine.Operand;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
19
import org.eclipse.equinox.internal.provisional.p2.ui.IStatusCodes;
19
import org.eclipse.equinox.internal.provisional.p2.ui.IStatusCodes;
20
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.osgi.util.NLS;
21
22
22
/**
23
/**
Lines 83-89 Link Here
83
	private static String getIUString(IInstallableUnit iu) {
84
	private static String getIUString(IInstallableUnit iu) {
84
		if (iu == null)
85
		if (iu == null)
85
			return ProvUIMessages.PlanStatusHelper_Items;
86
			return ProvUIMessages.PlanStatusHelper_Items;
86
		String name = iu.getProperty(IInstallableUnit.PROP_NAME);
87
		// Get the iu name in the default locale
88
		String name = IUPropertyUtils.getIUProperty(iu, IInstallableUnit.PROP_NAME);
87
		if (name != null)
89
		if (name != null)
88
			return name;
90
			return name;
89
		return iu.getId();
91
		return iu.getId();
(-)src/org/eclipse/equinox/internal/provisional/p2/ui/viewers/IUComparator.java (-2 / +4 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
13
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
14
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
14
import org.eclipse.equinox.internal.provisional.p2.ui.ProvUI;
15
import org.eclipse.equinox.internal.provisional.p2.ui.query.IUPropertyUtils;
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.jface.viewers.ViewerComparator;
17
import org.eclipse.jface.viewers.ViewerComparator;
17
18
Lines 33-42 Link Here
33
34
34
		String key1, key2;
35
		String key1, key2;
35
		if (key == IU_NAME) {
36
		if (key == IU_NAME) {
36
			key1 = iu1.getProperty(IInstallableUnit.PROP_NAME);
37
			// Compare the iu names in the default locale
38
			key1 = IUPropertyUtils.getIUProperty(iu1, IInstallableUnit.PROP_NAME);
37
			if (key1 == null)
39
			if (key1 == null)
38
				key1 = ""; //$NON-NLS-1$
40
				key1 = ""; //$NON-NLS-1$
39
			key2 = iu2.getProperty(IInstallableUnit.PROP_NAME);
41
			key2 = IUPropertyUtils.getIUProperty(iu2, IInstallableUnit.PROP_NAME);
40
			if (key2 == null)
42
			if (key2 == null)
41
				key2 = ""; //$NON-NLS-1$
43
				key2 = ""; //$NON-NLS-1$
42
		} else {
44
		} else {

Return to bug 222309