blob: f0aebff7be34cf1a09f32935fd820976cb6c5e6f [file] [log] [blame]
gobrien1a8e02f2008-01-30 01:46:26 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2008 Eclipse Foundation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Eclipse Foundation - Initial API and implementation
droy133e7462008-05-13 17:37:24 +000011 * Motoki MORT mori-m@mxa.nes.nec.co.jp - patch, bug 227366
kitlo9c7c62a2008-10-05 16:05:19 +000012 * Kit Lo (IBM) - patch, bug 217339, generate pseudo translations language packs
13 * Kit Lo (IBM) - patch, bug 234430, need language packs by means of other than update site
kitlo7f522672008-10-21 14:15:54 +000014 * Kit Lo (IBM) - patch, bug 251536, newline char missing after copyright comment on first line
kitlo1173dbd2008-10-21 15:58:36 +000015 * Kit Lo (IBM) - patch, bug 238580, language packs should not include strings that are marked "non-translatable"
kitlo5c9da712008-10-27 12:45:40 +000016 * Kit Lo (IBM) - patch, bug 252140, Illegal token characters in babel fragment names
atoulmedbda4272009-01-20 06:04:22 +000017 * Antoine Toulme (Intalio, Inc) - patch, bug 256430, Fragments with no host jeopardize Eclipse installation
kitlo47df0c62009-01-22 15:16:18 +000018 * Kit Lo (IBM) - patch, bug 261739, Inconsistent use of language names
kitlo8d7c0532009-03-14 23:57:49 +000019 * Sean Flanigan (Red Hat) - patch, bug 261584, wrong output folder
kitlocc405032009-04-04 01:10:30 +000020 * Kit Lo (IBM) - patch, bug 270456, Unable to use Babel PTT to verify PDE in the eclipse SDK
kitloe3fea252010-01-25 02:13:49 +000021 * Kit Lo (IBM) - Bug 299402, Extract properties files from Eclipse project update sites for translation
kitlo58d8a5a2008-09-24 20:08:44 +000022 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000023
24/*
kitlo58d8a5a2008-09-24 20:08:44 +000025 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000026 */
atoulme3fa5f5c2009-01-20 21:26:16 +000027define("METADATA_GENERATOR_LOCATION", "/home/genie/eclipse"); // you might want to read this value from a config file. Not sure yet.
gobrienb854dcb2008-01-30 18:50:45 +000028
droyaa172502009-05-06 20:50:07 +000029ini_set("memory_limit", "512M");
atoulme3ac52612009-02-02 13:14:39 +000030require(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme12882d52009-01-26 18:39:17 +000031require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy3081da02009-05-11 15:54:56 +000032
kitlo22479022010-01-25 03:22:33 +000033# Get all release trains
kitloe3fea252010-01-25 02:13:49 +000034$dbc = new DBConnection();
35$dbh = $dbc->connect();
36$result = mysql_query("SELECT * FROM release_trains ORDER BY train_version DESC");
37$train_result = array();
38while ($train_row = mysql_fetch_assoc($result)) {
39 $train_result[$train_row['train_id']] = $train_row['train_version'];
40}
droy3081da02009-05-11 15:54:56 +000041
42# Command-line parameter for the release train
43# bug 272958
droyc6eb7ac2009-05-12 17:25:46 +000044# b: build id
45# t: (optional: train id)
46
47$options = getopt("b:t:");
droy3081da02009-05-11 15:54:56 +000048$argv_train = "";
droyc6eb7ac2009-05-12 17:25:46 +000049if(isset($options['t'])) {
50 $argv_train = $options['t'];
droy3081da02009-05-11 15:54:56 +000051 if(array_key_exists($argv_train, $train_result)) {
52 # Picked a valid train .. remove all others
53 foreach ($train_result as $train_id => $train_version) {
54 if($train_id != $argv_train) {
55 unset($train_result[$train_id]);
56 }
57 }
58 }
59}
60
droyc6eb7ac2009-05-12 17:25:46 +000061$buildid = "";
62if(!isset($options['b'])) {
63 usage();
64 exit();
65}
66else {
67 $buildid = $options['b'];
68}
69
atoulme3ac52612009-02-02 13:14:39 +000070$work_dir = $addon->callHook('babel_working');
atoulme12882d52009-01-26 18:39:17 +000071
atoulme3ac52612009-02-02 13:14:39 +000072global $addon;
73$context = $addon->callHook('context');
gobrienb854dcb2008-01-30 18:50:45 +000074
kitlo9c7c62a2008-10-05 16:05:19 +000075$work_context_dir = $work_dir . $context . "/";
76$tmp_dir = $work_context_dir . "tmp/";
77$babel_language_packs_dir = $work_context_dir . "babel_language_packs/";
78$output_dir = $work_context_dir . "output/";
atoulme3ac52612009-02-02 13:14:39 +000079$source_files_dir = dirname(__FILE__) . "/source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000080
gobrien1a8e02f2008-01-30 01:46:26 +000081$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000082$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000083
kitlo82c999e2010-01-25 14:55:33 +000084$rm_command = "rm -rf $work_context_dir" . "*";
droyd157aac2008-10-07 21:14:33 +000085exec($rm_command);
droy082976e2008-10-07 21:02:23 +000086exec("mkdir -p $output_dir");
87
droy3081da02009-05-11 15:54:56 +000088echo "Requested builds: ";
kitlo78f97432009-03-17 22:28:58 +000089foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000090 echo $train_id . " ";
91}
92echo "\n";
kitlo78f97432009-03-17 22:28:58 +000093
droy3081da02009-05-11 15:54:56 +000094# Loop through the trains
95foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000096 echo "Generating update site for: $train_id\n";
droy3081da02009-05-11 15:54:56 +000097
98 /*
99 * Create language pack links file
100 */
101 exec("mkdir -p $babel_language_packs_dir");
102 $language_pack_links_file = fopen("${babel_language_packs_dir}${train_id}.php", "w");
droyc6eb7ac2009-05-12 17:25:46 +0000103 fwrite($language_pack_links_file, "<?php\n");
droy260639a2009-05-28 20:02:21 +0000104 # Uncomment if each train is in its own directory: fwrite($language_pack_links_file, "\$language_pack_leader = \"${train_id}\";\n");
105 fwrite($language_pack_links_file, "\$language_pack_leader = \".\";\n");
droy58951f72009-05-13 18:12:20 +0000106 fwrite($language_pack_links_file, "?>\n");
droyc6eb7ac2009-05-12 17:25:46 +0000107 # copy page_header.html here
108 $header = file_get_contents("${source_files_dir}page_header.html");
109 fwrite($language_pack_links_file, $header);
kitloe3fea252010-01-25 02:13:49 +0000110 fwrite($language_pack_links_file, "\n\t<h1>Babel Language Packs for " . ucfirst($train_id) . "</h1>" .
droyc6eb7ac2009-05-12 17:25:46 +0000111 "\n\t<h2>Build ID: $buildid</h2>" .
droy3081da02009-05-11 15:54:56 +0000112 "\n\t<p>The following language packs are based on the community translations entered into the <a href='http://babel.eclipse.org/'>Babel Translation Tool</a>, and may not be complete or entirely accurate. If you find missing or incorrect translations, please use the <a href='http://babel.eclipse.org/'>Babel Translation Tool</a> to update them." .
kitloe3fea252010-01-25 02:13:49 +0000113 "\n\tAll downloads are provided under the terms and conditions of the <a href='http://www.eclipse.org/legal/epl/notice.php'>Eclipse Foundation Software User Agreement</a> unless otherwise specified.</p>" .
114 "\n\t<p>Go to: ");
115
kitlo9c7c62a2008-10-05 16:05:19 +0000116 $train_version_timestamp = "$train_version.v$timestamp";
kitloe3fea252010-01-25 02:13:49 +0000117 $language_pack_links_file_buffer = "";
kitlo9c7c62a2008-10-05 16:05:19 +0000118 $site_xml = "";
kitlo58d8a5a2008-09-24 20:08:44 +0000119
kitlo78f97432009-03-17 22:28:58 +0000120 $output_dir_for_train = $output_dir . $train_id . "/";
kitlo58d8a5a2008-09-24 20:08:44 +0000121 exec("mkdir $output_dir_for_train");
122 exec("mkdir ${output_dir_for_train}features/");
123 exec("mkdir ${output_dir_for_train}plugins/");
124
droy68864612009-04-14 15:44:05 +0000125 $sql = "SELECT language_id, iso_code, IF(locale <> '', CONCAT(CONCAT(CONCAT(name, ' ('), locale), ')'), name) as name, is_active, IF(language_id = 1,1,0) AS sorthack FROM languages ORDER BY sorthack, name ASC";
126 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000127 if($language_result === FALSE) {
kitloe3fea252010-01-25 02:13:49 +0000128 # we may have lost the database connection with our shell-outs
droyb3ff2742009-04-08 19:28:32 +0000129 # bug 271685
130 $dbh = $dbc->connect();
droy68864612009-04-14 15:44:05 +0000131 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000132 }
kitlo9c7c62a2008-10-05 16:05:19 +0000133 while (($language_row = mysql_fetch_assoc($language_result)) != null) {
droy0b08d292008-05-28 15:18:11 +0000134 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000135 $language_iso = $language_row['iso_code'];
kitlo58d8a5a2008-09-24 20:08:44 +0000136 $language_id = $language_row['language_id'];
137 if (strcmp($language_iso, "en") == 0) {
kitlo58d8a5a2008-09-24 20:08:44 +0000138 $language_name = "Pseudo Translations";
kitloe3fea252010-01-25 02:13:49 +0000139 $language_iso = "en_AA";
kitlo58d8a5a2008-09-24 20:08:44 +0000140 }
kitlo9c7c62a2008-10-05 16:05:19 +0000141
kitlo58d8a5a2008-09-24 20:08:44 +0000142 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
143
gobrien1a8e02f2008-01-30 01:46:26 +0000144 /*
droy0b08d292008-05-28 15:18:11 +0000145 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000146 */
kitlo58d8a5a2008-09-24 20:08:44 +0000147 if (strcmp($language_iso, "en_AA") == 0) {
148 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
149 FROM files AS f
150 INNER JOIN strings AS s ON f.file_id = s.file_id
151 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
152 WHERE f.is_active
kitlo78f97432009-03-17 22:28:58 +0000153 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000154 } else {
155 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
156 FROM files AS f
157 INNER JOIN strings AS s ON f.file_id = s.file_id
158 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
159 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
160 WHERE t.language_id = " . $language_id . "
161 AND f.is_active
kitlo78f97432009-03-17 22:28:58 +0000162 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000163 }
164
droy0b08d292008-05-28 15:18:11 +0000165 $plugins = array();
kitlo9c7c62a2008-10-05 16:05:19 +0000166 $projects = array();
167 $project_versions = array();
168 $pseudo_translations_indexes = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000169 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
170 # save original filename
171 $file_row['origname'] = $file_row['name'];
172
droy02c430a2008-06-02 19:42:08 +0000173 # strip useless CVS structure before the plugin name (bug 221675 c14):
174 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
175 $replace = '${2}.${3}${4}.properties';
176 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000177
droy02c430a2008-06-02 19:42:08 +0000178 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
kitlo8d7c0532009-03-14 23:57:49 +0000179 /*
180 $pattern =
181 '/^
182 ([a-zA-Z0-9_-]+)\. # \1 org.
183 ([a-zA-Z0-9_-]+)\. # \2 eclipse.
184 ([a-zA-Z0-9\._-]+) # \3 datatools.connectivity
185 (.*)\/ # \4 \/plugins\/
186 (\1) # \5 org
187 ([\.\/]) # \6 .
188 (\2) # \7 eclipse
189 ([\.\/]) # \8 .
190 (.*) # \9 datatools.connectivity.ui\/plugin
191 \.properties # .properties
192 $/ix
193 ';
droy02c430a2008-06-02 19:42:08 +0000194 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
kitlo8d7c0532009-03-14 23:57:49 +0000195 */
196
197 # fix output folder (bug 261584)
198 $pattern =
199 '/^
200 (.*\/)? # \1 optional outer directories
201 ([a-z]+) # \2 org|com|etc
202 [.] # dot
203 ([^\/]+) # \3 plugin id except org.|com.
204 \/ # slash
205 (.*?\/)? # \4 optional src\/, src\/main\/ etc
206 # \5 resource path (pathname inside resulting jar)
207 # (a) within a org|com directory, or
208 # (b) in plugin root dir.
209 (\2\/.*[.]properties| # org|com\/anything.properties
210 [^\/]+[.]properties) # eg plugin.properties
211 $/ix';
212 $replace = '$2.$3/$5';
213
droy0b08d292008-05-28 15:18:11 +0000214 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000215
216 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000217 $file_row['subname'] = $matches[2];
218 $plugins[$matches[1]][] = $file_row;
219 } else {
220 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000221 }
droy0b08d292008-05-28 15:18:11 +0000222 }
kitlo58d8a5a2008-09-24 20:08:44 +0000223
droy0b08d292008-05-28 15:18:11 +0000224 /*
225 * Generate one plug-in fragment for each plug-in
226 */
kitlo58d8a5a2008-09-24 20:08:44 +0000227 foreach ($plugins as $plugin_name => $plugin_row) {
228 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000229 /*
droy0b08d292008-05-28 15:18:11 +0000230 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000231 */
kitlo58d8a5a2008-09-24 20:08:44 +0000232 if (file_exists($tmp_dir)) {
233 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000234 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000235 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000236 }
gobrien1a8e02f2008-01-30 01:46:26 +0000237 /*
droy0b08d292008-05-28 15:18:11 +0000238 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000239 */
droy0b08d292008-05-28 15:18:11 +0000240 foreach ($plugin_row as $properties_file) {
241 /*
242 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
243 */
244 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000245 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000246 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000247 }
kitlo58d8a5a2008-09-24 20:08:44 +0000248 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000249 /*
250 * Create any needed sub-directories
251 */
kitlo58d8a5a2008-09-24 20:08:44 +0000252 $fullpath = $tmp_dir . $filename;
253 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
254 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000255 /*
256 * Start writing to the file
257 */
kitlo58d8a5a2008-09-24 20:08:44 +0000258 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000259 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000260 if (strcmp($language_iso, "en_AA") == 0) {
261 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
262 " AND is_active AND non_translatable = 0";
263 $strings_result = mysql_query($sql);
264 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000265 /* Check for value starting with form tag (bug 270456) */
266 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
267 $pattern = "/^(<form>)(.*)/i";
268 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
269 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
270 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
271 } else {
272 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
273 ":" . $strings_row['value'];
274 }
275 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000276
277 $value = htmlspecialchars($strings_row['value']);
278 if (strlen($value) > 100) {
279 $value = substr($value, 0, 100) . " ...";
280 }
kitlo9c7c62a2008-10-05 16:05:19 +0000281 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
282 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
283 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
284 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000285 }
286 } else {
287 $sql = "SELECT
288 strings.name AS 'key',
289 strings.value AS orig,
290 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000291 FROM strings, translations
292 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000293 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000294 AND strings.is_active
295 AND strings.non_translatable = 0
296 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000297 AND translations.is_active";
298 $strings_result = mysql_query($sql);
299 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000300 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000301 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000302 if ($strings_row['trans']) {
303 # json_encode returns the string with quotes fore and aft. Need to strip them.
304 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
305 # $tr_string = str_replace('\\\\', '\\', $tr_string);
306 $tr_string = toescapedunicode($strings_row['trans']);
307 fwrite($outp, $tr_string);
308 # echo $strings_row['trans'];
309 } else {
310 fwrite($outp, $strings_row['orig']);
311 }
droy0b08d292008-05-28 15:18:11 +0000312 }
droy0b08d292008-05-28 15:18:11 +0000313 }
314 /*
315 * Finish the properties file
316 */
kitlo58d8a5a2008-09-24 20:08:44 +0000317 fclose($outp);
318 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000319 }
320 /*
droy0b08d292008-05-28 15:18:11 +0000321 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000322 */
kitlo9c7c62a2008-10-05 16:05:19 +0000323 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000324 /*
325 * Generate the META-INF/MANIFEST.MF file
326 */
327 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000328 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000329 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000330 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000331
droy0b08d292008-05-28 15:18:11 +0000332 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000333 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000334
335 exec("mkdir $tmp_dir/META-INF" );
336 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
337 fwrite($outp, "Manifest-Version: 1.0\n");
338 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
339 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000340 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
341 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000342 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
343 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000344 /*
345 * Jar up this directory as the fragment plug-in jar
346 */
kitlo58d8a5a2008-09-24 20:08:44 +0000347 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
348 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000349
kitlo9c7c62a2008-10-05 16:05:19 +0000350 $projects[$project_id][] = $fragment_id;
351 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000352 }
kitlo78f97432009-03-17 22:28:58 +0000353 if (sizeof($projects) > 0) {
354 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
355 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
356 $site_xml .= "\n\t</category-def>";
357
kitloe3fea252010-01-25 02:13:49 +0000358 fwrite($language_pack_links_file, "\n\t\t<a href='#$language_iso'>$language_name</a>");
359 if (strcmp($language_iso, "en_AA") != 0) {
360 fwrite($language_pack_links_file, ",");
361 }
362 $language_pack_links_file_buffer .= "\n\t\t<h4>Language: <a name='$language_iso'>$language_name</a></h4>";
363 $language_pack_links_file_buffer .= "\n\t\t<ul>";
kitlo78f97432009-03-17 22:28:58 +0000364 }
kitlo9c7c62a2008-10-05 16:05:19 +0000365 foreach ($projects as $project_id => $fragment_ids) {
366 /*
367 * Sort fragment names
368 */
369 asort($fragment_ids);
370 /*
371 * Create ${babel_language_packs_dir}tmp
372 */
373 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
374 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
375 /*
376 * Clean and create the temporary directory
377 */
378 if (file_exists($tmp_dir)) {
379 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
380 } else {
381 exec("mkdir $tmp_dir");
382 }
383 /*
384 * Create the feature.xml
385 *
386 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
387 *
388 * <url>
389 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
390 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
391 * </url>
392 */
kitlo5c9da712008-10-27 12:45:40 +0000393 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000394 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
395
396 $project_version = $project_versions[$project_id];
397 $sql = "SELECT pct_complete
398 FROM project_progress
399 WHERE project_id = \"$project_id\"
400 AND version = \"$project_version\"
401 AND language_id = $language_id";
402 $project_pct_complete_result = mysql_query($sql);
403 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
404 if (strcmp($language_iso, "en_AA") == 0) {
405 $project_pct_complete = 100;
406 }
407
408 $outp = fopen("$tmp_dir/feature.xml", "w");
409 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
410 "\n<feature" .
411 "\n\tid=\"$feature_id\"" .
412 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
413 "\n\timage=\"eclipse_update_120.jpg\"" .
414 "\n\tprovider-name=\"%providerName\"" .
415 "\n\tversion=\"$train_version_timestamp\">" .
416 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
417 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
418 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
419 foreach ($fragment_ids as $fragment_id) {
420 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
421 $size = filesize($jar_name);
422 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
423 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
424 /*
425 * Copy the plugin to ${babel_language_packs_dir}tmp
426 */
427 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
428 }
429 fwrite($outp, "\n</feature>");
430 fclose($outp);
431 /*
432 * Copy in the various legal files
433 */
434 exec("cp ${source_files_dir}about.html $tmp_dir");
435 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
436 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
437 exec("cp ${source_files_dir}feature.properties $tmp_dir");
438 exec("cp ${source_files_dir}license.html $tmp_dir");
439 /*
440 * Copy in the Babel Pseudo Translations Index file
441 */
442 if (strcmp($language_iso, "en_AA") == 0) {
443 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
444 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
445 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
446 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
447 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
448 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
449 foreach ($pseudo_translations_indexes[$project_id] as $index) {
450 fwrite($pseudo_translations_index_file, $index);
451 }
droy03d5c462008-11-10 21:07:01 +0000452 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000453 fclose($pseudo_translations_index_file);
454 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
455 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
456 }
457 /*
458 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
459 */
kitloc42941d2008-11-20 15:33:00 +0000460 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
461 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000462 /*
463 * Zip up language pack
464 */
465 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
466 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
467 /*
468 * Clean up ${babel_language_packs_dir}tmp
469 */
470 exec("rm -rf ${babel_language_packs_dir}tmp");
471 /*
472 * Add project language pack link to language pack links file
473 */
kitloe3fea252010-01-25 02:13:49 +0000474 $language_pack_links_file_buffer .= "\n\t\t\t<li><a href=\"<?= \$language_pack_leader ?>/${language_pack_name}\">$language_pack_name ($project_pct_complete%)</a></li>";
kitlo9c7c62a2008-10-05 16:05:19 +0000475 /*
476 * Jar up this directory as the feature jar
477 */
478 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
479 /*
480 * Register this feature with the site.xml
481 */
kitloc42941d2008-11-20 15:33:00 +0000482 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000483 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
484 $site_xml .= "\n\t</feature>";
droy58951f72009-05-13 18:12:20 +0000485
kitlo78f97432009-03-17 22:28:58 +0000486
droy58951f72009-05-13 18:12:20 +0000487 } /* End: foreach project */
488 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitloe3fea252010-01-25 02:13:49 +0000489 if (sizeof($projects) > 0) {
490 $language_pack_links_file_buffer .= "\n\t\t</ul>";
491 }
gobrien1a8e02f2008-01-30 01:46:26 +0000492 }
gobrien1a8e02f2008-01-30 01:46:26 +0000493 /*
droy0b08d292008-05-28 15:18:11 +0000494 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000495 */
kitlo58d8a5a2008-09-24 20:08:44 +0000496 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000497 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
498 "\n<site>" .
499 "\n\t<description url=\"http://babel.eclipse.org/\">" .
500 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
501 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
502 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
503 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000504 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000505 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000506 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000507
kitloe3fea252010-01-25 02:13:49 +0000508 fwrite($language_pack_links_file, "\n\t</p>");
509 fwrite($language_pack_links_file, $language_pack_links_file_buffer);
atoulmedbda4272009-01-20 06:04:22 +0000510
droy3081da02009-05-11 15:54:56 +0000511 fwrite($language_pack_links_file, "\n</body>\n</html>");
512 fclose($language_pack_links_file);
513
514
515 $dbh = $dbc->disconnect();
516
atoulmedbda4272009-01-20 06:04:22 +0000517 // now generate the metadata and add the non-greedy tags
atoulme09ce4642009-01-21 07:46:06 +0000518
droye77ad172009-05-04 17:35:56 +0000519 /*
520 * Leaving this out of generate1 to avoid p2 breakage
521 *
atoulme12882d52009-01-26 18:39:17 +0000522 system("sh " . dirname(__FILE__) . "/runMetadata.sh ".
atoulme09ce4642009-01-21 07:46:06 +0000523 METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
atoulmec86be152009-01-21 22:36:31 +0000524 system("xsltproc -o ${output_dir_for_train}content.xml ".
atoulmeb0f0e502009-01-21 17:27:25 +0000525 dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
atoulmec8efccd2009-02-13 08:51:59 +0000526 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml ; rm site.xml");
droye77ad172009-05-04 17:35:56 +0000527 */
gobrien1a8e02f2008-01-30 01:46:26 +0000528}
gobrien1a8e02f2008-01-30 01:46:26 +0000529echo "Completed generating update site\n";
530
kitlo9c7c62a2008-10-05 16:05:19 +0000531
gobrien1a8e02f2008-01-30 01:46:26 +0000532/*
kitlo58d8a5a2008-09-24 20:08:44 +0000533 2. what happens if the translation feature includes plug-in fragments for
534 plug-ins that are not in the current image?
535 does it load correctly and ignore those fragments? if so, good
536 A: warnings appear in the run-time error log
537 does it fail to load? if so, then we need to generate different features, perhaps
538 one feature for each plug or else we need to know more about the project
539 distro structure to know which plug-ins to put in each feature
540 what happens if those plug-ins are later added - does it load the strings now?
541 A: probably not
542 3. need to handle different versions of each feature/plugin/platform; generate different
543 language packs for each
544 */
gobrien1a8e02f2008-01-30 01:46:26 +0000545
kitlo58d8a5a2008-09-24 20:08:44 +0000546$alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w");
547fwrite($alloutput,ob_get_contents());
droyc6eb7ac2009-05-12 17:25:46 +0000548
549function usage() {
550 echo "\n";
551 echo "generate1.php -b <build_id> [-t <train_id>]\n";
552 echo " -b <build_id>: The Build ID for this build.\n";
kitloe3fea252010-01-25 02:13:49 +0000553 echo " -t <train_id>: Optional: train to build (helios, galileo, ganymede, europa).";
droyc6eb7ac2009-05-12 17:25:46 +0000554 echo "\n";
555}
556
kitloe3fea252010-01-25 02:13:49 +0000557?>