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 234154 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/MetadataGeneratorHelper.java (-3 / +24 lines)
Lines 403-411 Link Here
403
	 */
403
	 */
404
	public static IInstallableUnit createCategoryIU(SiteCategory category, Set featureIUs, IInstallableUnit parentCategory) {
404
	public static IInstallableUnit createCategoryIU(SiteCategory category, Set featureIUs, IInstallableUnit parentCategory) {
405
		InstallableUnitDescription cat = new MetadataFactory.InstallableUnitDescription();
405
		InstallableUnitDescription cat = new MetadataFactory.InstallableUnitDescription();
406
		cat.setSingleton(true);
406
		String categoryId = category.getName();
407
		cat.setId(category.getName());
407
		cat.setId(categoryId);
408
		cat.setVersion(Version.emptyVersion);
408
		cat.setVersion(Version.emptyVersion);
409
		cat.setSingleton(true);
409
		cat.setProperty(IInstallableUnit.PROP_NAME, category.getLabel());
410
		cat.setProperty(IInstallableUnit.PROP_NAME, category.getLabel());
410
		cat.setProperty(IInstallableUnit.PROP_DESCRIPTION, category.getDescription());
411
		cat.setProperty(IInstallableUnit.PROP_DESCRIPTION, category.getDescription());
411
412
Lines 420-426 Link Here
420
			reqsConfigurationUnits.add(MetadataFactory.createRequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, parentCategory.getId(), VersionRange.emptyRange, parentCategory.getFilter(), false, false));
421
			reqsConfigurationUnits.add(MetadataFactory.createRequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, parentCategory.getId(), VersionRange.emptyRange, parentCategory.getFilter(), false, false));
421
		}
422
		}
422
		cat.setRequiredCapabilities((RequiredCapability[]) reqsConfigurationUnits.toArray(new RequiredCapability[reqsConfigurationUnits.size()]));
423
		cat.setRequiredCapabilities((RequiredCapability[]) reqsConfigurationUnits.toArray(new RequiredCapability[reqsConfigurationUnits.size()]));
423
		cat.setCapabilities(new ProvidedCapability[] {MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, category.getName(), Version.emptyVersion)});
424
425
		// Create set of provided capabilities
426
		ArrayList providedCapabilities = new ArrayList();
427
		providedCapabilities.add(createSelfCapability(categoryId, Version.emptyVersion));
428
429
		Map localizations = category.getLocalizations();
430
		if (localizations != null) {
431
			for (Iterator iter = localizations.keySet().iterator(); iter.hasNext();) {
432
				Locale locale = (Locale) iter.next();
433
				Properties translatedStrings = (Properties) localizations.get(locale);
434
				Enumeration propertyKeys = translatedStrings.propertyNames();
435
				while (propertyKeys.hasMoreElements()) {
436
					String nextKey = (String) propertyKeys.nextElement();
437
					cat.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey));
438
				}
439
				providedCapabilities.add(makeTranslationCapability(categoryId, locale));
440
			}
441
		}
442
443
		cat.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()]));
444
424
		cat.setArtifacts(new IArtifactKey[0]);
445
		cat.setArtifacts(new IArtifactKey[0]);
425
		cat.setProperty(IInstallableUnit.PROP_TYPE_CATEGORY, "true"); //$NON-NLS-1$
446
		cat.setProperty(IInstallableUnit.PROP_TYPE_CATEGORY, "true"); //$NON-NLS-1$
426
		return MetadataFactory.createInstallableUnit(cat);
447
		return MetadataFactory.createInstallableUnit(cat);
(-)src/org/eclipse/equinox/internal/provisional/p2/metadata/generator/Generator.java (+18 lines)
Lines 107-112 Link Here
107
107
108
	static final String DEFAULT_BUNDLE_LOCALIZATION = "plugin"; //$NON-NLS-1$	
108
	static final String DEFAULT_BUNDLE_LOCALIZATION = "plugin"; //$NON-NLS-1$	
109
109
110
	private static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
111
110
	protected final IGeneratorInfo info;
112
	protected final IGeneratorInfo info;
111
113
112
	private GeneratorResult incrementalResult = null;
114
	private GeneratorResult incrementalResult = null;
Lines 1148-1153 Link Here
1148
			for (int i = 0; i < associatedSites.length; i++)
1150
			for (int i = 0; i < associatedSites.length; i++)
1149
				generateSiteReference(associatedSites[i].getURL(), null, true);
1151
				generateSiteReference(associatedSites[i].getURL(), null, true);
1150
1152
1153
		if (PROTOCOL_FILE.equals(siteLocation.getProtocol())) {
1154
			File siteFile = new File(siteLocation.getFile());
1155
			if (siteFile.exists()) {
1156
				File siteParent = siteFile.getParentFile();
1157
1158
				List messageKeys = site.getMessageKeys();
1159
				if (siteParent.isDirectory()) {
1160
					String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]);
1161
					site.setLocalizations(LocalizationHelper.getDirPropertyLocalizations(siteParent, "site", null, keyStrings)); //$NON-NLS-1$
1162
				} else if (siteFile.getName().endsWith(".jar")) { //$NON-NLS-1$
1163
					String[] keyStrings = (String[]) messageKeys.toArray(new String[messageKeys.size()]);
1164
					site.setLocalizations(LocalizationHelper.getJarPropertyLocalizations(siteParent, "feature", null, keyStrings)); //$NON-NLS-1$
1165
				}
1166
			}
1167
		}
1168
1151
		SiteFeature[] features = site.getFeatures();
1169
		SiteFeature[] features = site.getFeatures();
1152
		for (int i = 0; i < features.length; i++) {
1170
		for (int i = 0; i < features.length; i++) {
1153
			//add a mapping for each category this feature belongs to
1171
			//add a mapping for each category this feature belongs to
(-)src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteCategory.java (+24 lines)
Lines 13-18 Link Here
13
import java.net.MalformedURLException;
13
import java.net.MalformedURLException;
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Comparator;
15
import java.util.Comparator;
16
import java.util.Map;
16
17
17
/**
18
/**
18
 * A category in an update site.
19
 * A category in an update site.
Lines 25-30 Link Here
25
	private String description;
26
	private String description;
26
	private String label;
27
	private String label;
27
	private String name;
28
	private String name;
29
	private Map localizations;
28
30
29
	/**
31
	/**
30
	 * Returns a comparator for category models.
32
	 * Returns a comparator for category models.
Lines 100-105 Link Here
100
	}
102
	}
101
103
102
	/**
104
	/**
105
	 * Gets the localizations for the site as a map from locale
106
	 * to the set of translated properties for that locale.
107
	 * 
108
	 * @return a map from locale to property set
109
	 * @since 3.4
110
	 */
111
	public Map getLocalizations() {
112
		return this.localizations;
113
	}
114
115
	/**
103
	 * Retrieve the name of the category.
116
	 * Retrieve the name of the category.
104
	 * 
117
	 * 
105
	 * @return category name, or <code>null</code>.
118
	 * @return category name, or <code>null</code>.
Lines 162-167 Link Here
162
	}
175
	}
163
176
164
	/**
177
	/**
178
	 * Sets the localizations for the site as a map from locale
179
	 * to the set of translated properties for that locale.
180
	 * 
181
	 * @param localizations as a map from locale to property set
182
	 * @since 3.4
183
	 */
184
	public void setLocalizations(Map localizations) {
185
		this.localizations = localizations;
186
	}
187
188
	/**
165
	 * Sets the category name.
189
	 * Sets the category name.
166
	 * Throws a runtime exception if this object is marked read-only.
190
	 * Throws a runtime exception if this object is marked read-only.
167
	 * 
191
	 * 
(-)src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteModel.java (-1 / +56 lines)
Lines 40-45 Link Here
40
	private String type;
40
	private String type;
41
	private URLEntry[] associateSites;
41
	private URLEntry[] associateSites;
42
	private String digestURLString;
42
	private String digestURLString;
43
	private List messageKeys;
44
	private Map localizations;
43
45
44
	/**
46
	/**
45
	 * Creates an uninitialized site model object.
47
	 * Creates an uninitialized site model object.
Lines 72-79 Link Here
72
	public void addCategory(SiteCategory category) {
74
	public void addCategory(SiteCategory category) {
73
		if (categories == null)
75
		if (categories == null)
74
			categories = new HashMap();
76
			categories = new HashMap();
75
		if (!categories.containsKey(category.getName()))
77
		if (!categories.containsKey(category.getName())) {
76
			categories.put(category.getName(), category);
78
			categories.put(category.getName(), category);
79
			if (localizations != null && !localizations.isEmpty())
80
				category.setLocalizations(localizations);
81
		}
77
	}
82
	}
78
83
79
	/**
84
	/**
Lines 167-172 Link Here
167
	}
172
	}
168
173
169
	/**
174
	/**
175
	 * Gets the localizations for the site as a map from locale
176
	 * to the set of translated properties for that locale.
177
	 * 
178
	 * @return a map from locale to property set
179
	 * @since 3.4
180
	 */
181
	public Map getLocalizations() {
182
		return this.localizations;
183
	}
184
185
	/**
170
	 * Returns the resolved URL for the site.
186
	 * Returns the resolved URL for the site.
171
	 * 
187
	 * 
172
	 * @return url, or <code>null</code>
188
	 * @return url, or <code>null</code>
Lines 192-197 Link Here
192
	}
208
	}
193
209
194
	/**
210
	/**
211
	 * Return the keys for translatable strings
212
	 *
213
	 * @return the list of keys for translatable strings; may be null
214
	 * @since 3.4
215
	 */
216
	public List getMessageKeys() {
217
		return messageKeys;
218
	}
219
220
	/**
195
	 * Return an array of update site mirrors
221
	 * Return an array of update site mirrors
196
	 * 
222
	 * 
197
	 * @return an array of mirror entries, or an empty array.
223
	 * @return an array of mirror entries, or an empty array.
Lines 278-283 Link Here
278
	}
304
	}
279
305
280
	/**
306
	/**
307
	 * Sets the localizations for the site as a map from locale
308
	 * to the set of translated properties for that locale.
309
	 * 
310
	 * @param localizations as a map from locale to property set
311
	 * @since 3.4
312
	 */
313
	public void setLocalizations(Map localizations) {
314
		this.localizations = localizations;
315
		if (localizations != null && !localizations.isEmpty() && //
316
				categories != null && !categories.isEmpty()) {
317
			for (Iterator catIter = categories.entrySet().iterator(); catIter.hasNext();) {
318
				Map.Entry entry = (Map.Entry) catIter.next();
319
				SiteCategory category = (SiteCategory) entry.getValue();
320
				category.setLocalizations(localizations);
321
			}
322
		}
323
	}
324
325
	/**
281
	 * Sets the unresolved URL for the site.
326
	 * Sets the unresolved URL for the site.
282
	 * 
327
	 * 
283
	 * @param locationURLString url for the site (as a string)
328
	 * @param locationURLString url for the site (as a string)
Lines 288-293 Link Here
288
	}
333
	}
289
334
290
	/**
335
	/**
336
	 * Sets keys for translatable strings
337
	 * 
338
	 * @param keys for translatable strings
339
	 * @since 3.4
340
	 */
341
	public void setMessageKeys(List keys) {
342
		this.messageKeys = keys;
343
	}
344
345
	/**
291
	 * Sets additional mirror sites
346
	 * Sets additional mirror sites
292
	 * 
347
	 * 
293
	 * @param mirrors additional update site mirrors
348
	 * @param mirrors additional update site mirrors
(-)src/org/eclipse/equinox/internal/p2/metadata/generator/features/DefaultSiteParser.java (-2 / +16 lines)
Lines 66-71 Link Here
66
	// Current State Information
66
	// Current State Information
67
	Stack stateStack = new Stack();
67
	Stack stateStack = new Stack();
68
68
69
	// List of string keys for translated strings
70
	private final List messageKeys = new ArrayList(4);
71
69
	private MultiStatus status;
72
	private MultiStatus status;
70
73
71
	/*
74
	/*
Lines 548-554 Link Here
548
		if (objectStack.isEmpty())
551
		if (objectStack.isEmpty())
549
			throw new SAXException(Messages.DefaultSiteParser_NoSiteTag);
552
			throw new SAXException(Messages.DefaultSiteParser_NoSiteTag);
550
		if (objectStack.peek() instanceof SiteModel) {
553
		if (objectStack.peek() instanceof SiteModel) {
551
			return (SiteModel) objectStack.pop();
554
			SiteModel site = (SiteModel) objectStack.pop();
555
			site.setMessageKeys(messageKeys);
556
			return site;
552
		}
557
		}
553
		String stack = ""; //$NON-NLS-1$
558
		String stack = ""; //$NON-NLS-1$
554
		Iterator iter = objectStack.iterator();
559
		Iterator iter = objectStack.iterator();
Lines 602-608 Link Here
602
	private void processCategoryDef(Attributes attributes) {
607
	private void processCategoryDef(Attributes attributes) {
603
		SiteCategory category = new SiteCategory();
608
		SiteCategory category = new SiteCategory();
604
		String name = attributes.getValue("name"); //$NON-NLS-1$
609
		String name = attributes.getValue("name"); //$NON-NLS-1$
610
		checkTranslated(name);
605
		String label = attributes.getValue("label"); //$NON-NLS-1$
611
		String label = attributes.getValue("label"); //$NON-NLS-1$
612
		checkTranslated(label);
606
		category.setName(name);
613
		category.setName(name);
607
		category.setLabel(label);
614
		category.setLabel(label);
608
615
Lines 658-663 Link Here
658
		if (label != null) {
665
		if (label != null) {
659
			if ("".equals(label.trim())) //$NON-NLS-1$
666
			if ("".equals(label.trim())) //$NON-NLS-1$
660
				label = null;
667
				label = null;
668
			checkTranslated(label);
661
		}
669
		}
662
		feature.setLabel(label);
670
		feature.setLabel(label);
663
671
Lines 753-759 Link Here
753
			site.setSupportsPack200(true);
761
			site.setSupportsPack200(true);
754
		}
762
		}
755
763
756
		String digestURL = attributes.getValue("digestURL");
764
		String digestURL = attributes.getValue("digestURL"); //$NON-NLS-1$
757
		if (digestURL != null)
765
		if (digestURL != null)
758
			site.setDigestURLString(digestURL);
766
			site.setDigestURLString(digestURL);
759
767
Lines 844-847 Link Here
844
		return Character.isWhitespace(str.charAt(str.length() - 1));
852
		return Character.isWhitespace(str.charAt(str.length() - 1));
845
	}
853
	}
846
854
855
	// Add translatable strings from the site.xml
856
	// to the list of message keys.
857
	private void checkTranslated(String value) {
858
		if (value != null && value.length() > 1 && value.startsWith("%")) //$NON-NLS-1$
859
			messageKeys.add(value.substring(1));
860
	}
847
}
861
}

Return to bug 234154