|
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 643-649
Link Here
|
| 643 |
// TODO: shouldn't the filter for the group be constructed from os, ws, arch, nl |
641 |
// TODO: shouldn't the filter for the group be constructed from os, ws, arch, nl |
| 644 |
// of the feature? |
642 |
// of the feature? |
| 645 |
// iu.setFilter(filter); |
643 |
// iu.setFilter(filter); |
| 646 |
iu.setCapabilities(new ProvidedCapability[] {createSelfCapability(id, version)}); |
644 |
|
|
|
645 |
// Create set of provided capabilities |
| 646 |
ArrayList providedCapabilities = new ArrayList(); |
| 647 |
providedCapabilities.add(createSelfCapability(id, version)); |
| 648 |
|
| 649 |
Map manifestLocalizations = feature.getLocalizations(); |
| 650 |
if (manifestLocalizations != null) { |
| 651 |
for (Iterator iter = manifestLocalizations.keySet().iterator(); iter.hasNext();) { |
| 652 |
Locale locale = (Locale) iter.next(); |
| 653 |
Properties translatedStrings = (Properties) manifestLocalizations.get(locale); |
| 654 |
Enumeration propertyKeys = translatedStrings.propertyNames(); |
| 655 |
while (propertyKeys.hasMoreElements()) { |
| 656 |
String nextKey = (String) propertyKeys.nextElement(); |
| 657 |
iu.setProperty(locale.toString() + '.' + nextKey, translatedStrings.getProperty(nextKey)); |
| 658 |
} |
| 659 |
providedCapabilities.add(makeTranslationCapability(id, locale)); |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
iu.setCapabilities((ProvidedCapability[]) providedCapabilities.toArray(new ProvidedCapability[providedCapabilities.size()])); |
| 647 |
|
664 |
|
| 648 |
if (extraProperties != null) { |
665 |
if (extraProperties != null) { |
| 649 |
Enumeration e = extraProperties.propertyNames(); |
666 |
Enumeration e = extraProperties.propertyNames(); |
|
Lines 663-672
Link Here
|
| 663 |
Version version = new Version(feature.getVersion()); |
680 |
Version version = new Version(feature.getVersion()); |
| 664 |
iu.setVersion(version); |
681 |
iu.setVersion(version); |
| 665 |
iu.setProperty(IInstallableUnit.PROP_NAME, feature.getLabel()); |
682 |
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) |
683 |
if (feature.getLicense() != null) |
| 671 |
iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense())); |
684 |
iu.setLicense(new License(feature.getLicenseURL(), feature.getLicense())); |
| 672 |
if (feature.getCopyright() != null) |
685 |
if (feature.getCopyright() != null) |
|
Lines 1098-1106
Link Here
|
| 1098 |
|
1111 |
|
| 1099 |
if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$ |
1112 |
if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$ |
| 1100 |
bundleLocation.isFile()) { |
1113 |
bundleLocation.isFile()) { |
| 1101 |
localizations = getJarManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
1114 |
localizations = LocalizationHelper.getJarPropertyLocalizations(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
|
|
1115 |
//localizations = getJarManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
| 1102 |
} else { |
1116 |
} else { |
| 1103 |
localizations = getDirManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
1117 |
localizations = LocalizationHelper.getDirPropertyLocalizations(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
|
|
1118 |
// localizations = getDirManifestLocalization(bundleLocation, bundleLocalization, defaultLocale, bundleManifestValues); |
| 1104 |
} |
1119 |
} |
| 1105 |
|
1120 |
|
| 1106 |
return localizations; |
1121 |
return localizations; |
|
Lines 1129-1293
Link Here
|
| 1129 |
|
1144 |
|
| 1130 |
if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$ |
1145 |
if ("jar".equalsIgnoreCase(new Path(bundleLocation.getName()).getFileExtension()) && //$NON-NLS-1$ |
| 1131 |
bundleLocation.isFile()) { |
1146 |
bundleLocation.isFile()) { |
| 1132 |
localizations = getJarManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues); |
1147 |
localizations = LocalizationHelper.getJarPropertyLocalizations(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues); |
|
|
1148 |
//localizations = getJarManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues); |
| 1133 |
} else { |
1149 |
} else { |
| 1134 |
localizations = getDirManifestLocalization(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues); |
1150 |
localizations = LocalizationHelper.getDirPropertyLocalizations(bundleLocation, hostBundleLocalization, defaultLocale, hostBundleManifestValues); |
| 1135 |
} |
1151 |
// 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 |
} |
1152 |
} |
| 1181 |
|
1153 |
|
| 1182 |
return localizations; |
1154 |
return localizations; |
| 1183 |
} |
1155 |
} |
| 1184 |
|
1156 |
|
| 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 |
} |
| 1218 |
|
| 1219 |
return localizations; |
| 1220 |
} |
| 1221 |
|
| 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 |
} |
1157 |
} |