blob: 6d28ee8e3ab8cc0383a3cfd575c74f6b57da4793 [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
kitlob2ca7c02010-02-10 19:05:41 +000022 * Kit Lo (IBM) - Bug 276306, Re-enable p2 repository
kitlo844140c2010-04-28 16:16:05 +000023 * Kit Lo (IBM) - Bug 310135, Babel p2 update site not using mirrors
kitloaf749822010-07-29 05:19:44 +000024 * Kit Lo (IBM) - [289376] Need to start up a Helios build
kitloc2fbc882011-06-11 21:31:40 +000025 * Kit Lo (IBM) - [344764] Translation fragments discard the plug-in's directory structure
kitlo58d8a5a2008-09-24 20:08:44 +000026 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000027
28/*
kitlo58d8a5a2008-09-24 20:08:44 +000029 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000030 */
atoulme3fa5f5c2009-01-20 21:26:16 +000031define("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 +000032
droyaa172502009-05-06 20:50:07 +000033ini_set("memory_limit", "512M");
atoulme3ac52612009-02-02 13:14:39 +000034require(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme12882d52009-01-26 18:39:17 +000035require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy3081da02009-05-11 15:54:56 +000036
kitlo22479022010-01-25 03:22:33 +000037# Get all release trains
kitloe3fea252010-01-25 02:13:49 +000038$dbc = new DBConnection();
39$dbh = $dbc->connect();
40$result = mysql_query("SELECT * FROM release_trains ORDER BY train_version DESC");
41$train_result = array();
42while ($train_row = mysql_fetch_assoc($result)) {
43 $train_result[$train_row['train_id']] = $train_row['train_version'];
44}
droy3081da02009-05-11 15:54:56 +000045
46# Command-line parameter for the release train
47# bug 272958
droyc6eb7ac2009-05-12 17:25:46 +000048# b: build id
49# t: (optional: train id)
50
51$options = getopt("b:t:");
droy3081da02009-05-11 15:54:56 +000052$argv_train = "";
droyc6eb7ac2009-05-12 17:25:46 +000053if(isset($options['t'])) {
54 $argv_train = $options['t'];
droy3081da02009-05-11 15:54:56 +000055 if(array_key_exists($argv_train, $train_result)) {
56 # Picked a valid train .. remove all others
57 foreach ($train_result as $train_id => $train_version) {
58 if($train_id != $argv_train) {
59 unset($train_result[$train_id]);
60 }
61 }
62 }
63}
64
kitlob1920882010-05-12 23:33:18 +000065$build_id = "";
droyc6eb7ac2009-05-12 17:25:46 +000066if(!isset($options['b'])) {
67 usage();
68 exit();
69}
70else {
kitlob1920882010-05-12 23:33:18 +000071 $build_id = $options['b'];
droyc6eb7ac2009-05-12 17:25:46 +000072}
73
kitlob1920882010-05-12 23:33:18 +000074$release_id = "0.8.0";
75
atoulme3ac52612009-02-02 13:14:39 +000076$work_dir = $addon->callHook('babel_working');
atoulme12882d52009-01-26 18:39:17 +000077
atoulme3ac52612009-02-02 13:14:39 +000078global $addon;
79$context = $addon->callHook('context');
gobrienb854dcb2008-01-30 18:50:45 +000080
kitlo9c7c62a2008-10-05 16:05:19 +000081$work_context_dir = $work_dir . $context . "/";
82$tmp_dir = $work_context_dir . "tmp/";
83$babel_language_packs_dir = $work_context_dir . "babel_language_packs/";
84$output_dir = $work_context_dir . "output/";
atoulme3ac52612009-02-02 13:14:39 +000085$source_files_dir = dirname(__FILE__) . "/source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000086
gobrien1a8e02f2008-01-30 01:46:26 +000087$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000088$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000089
kitlo95107b72010-07-29 05:18:34 +000090$rm_command = "rm -rf $tmp_dir; rm -rf $babel_language_packs_dir; rm -rf $output_dir";
droyd157aac2008-10-07 21:14:33 +000091exec($rm_command);
droy082976e2008-10-07 21:02:23 +000092exec("mkdir -p $output_dir");
93
droy3081da02009-05-11 15:54:56 +000094echo "Requested builds: ";
kitlo78f97432009-03-17 22:28:58 +000095foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000096 echo $train_id . " ";
97}
98echo "\n";
kitlo78f97432009-03-17 22:28:58 +000099
droy3081da02009-05-11 15:54:56 +0000100# Loop through the trains
101foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +0000102 echo "Generating update site for: $train_id\n";
droy3081da02009-05-11 15:54:56 +0000103
104 /*
105 * Create language pack links file
106 */
107 exec("mkdir -p $babel_language_packs_dir");
108 $language_pack_links_file = fopen("${babel_language_packs_dir}${train_id}.php", "w");
droyc6eb7ac2009-05-12 17:25:46 +0000109 fwrite($language_pack_links_file, "<?php\n");
droy260639a2009-05-28 20:02:21 +0000110 # Uncomment if each train is in its own directory: fwrite($language_pack_links_file, "\$language_pack_leader = \"${train_id}\";\n");
111 fwrite($language_pack_links_file, "\$language_pack_leader = \".\";\n");
droy58951f72009-05-13 18:12:20 +0000112 fwrite($language_pack_links_file, "?>\n");
droyc6eb7ac2009-05-12 17:25:46 +0000113 # copy page_header.html here
114 $header = file_get_contents("${source_files_dir}page_header.html");
115 fwrite($language_pack_links_file, $header);
kitloe3fea252010-01-25 02:13:49 +0000116 fwrite($language_pack_links_file, "\n\t<h1>Babel Language Packs for " . ucfirst($train_id) . "</h1>" .
kitlob1920882010-05-12 23:33:18 +0000117 "\n\t<h2>Build ID: $build_id</h2>" .
droy3081da02009-05-11 15:54:56 +0000118 "\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 +0000119 "\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>" .
120 "\n\t<p>Go to: ");
121
kitlo9c7c62a2008-10-05 16:05:19 +0000122 $train_version_timestamp = "$train_version.v$timestamp";
kitloe3fea252010-01-25 02:13:49 +0000123 $language_pack_links_file_buffer = "";
kitlo9c7c62a2008-10-05 16:05:19 +0000124 $site_xml = "";
kitlo58d8a5a2008-09-24 20:08:44 +0000125
kitlo78f97432009-03-17 22:28:58 +0000126 $output_dir_for_train = $output_dir . $train_id . "/";
kitlo58d8a5a2008-09-24 20:08:44 +0000127 exec("mkdir $output_dir_for_train");
128 exec("mkdir ${output_dir_for_train}features/");
129 exec("mkdir ${output_dir_for_train}plugins/");
130
droy68864612009-04-14 15:44:05 +0000131 $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";
132 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000133 if($language_result === FALSE) {
kitloe3fea252010-01-25 02:13:49 +0000134 # we may have lost the database connection with our shell-outs
droyb3ff2742009-04-08 19:28:32 +0000135 # bug 271685
136 $dbh = $dbc->connect();
droy68864612009-04-14 15:44:05 +0000137 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000138 }
kitlo9c7c62a2008-10-05 16:05:19 +0000139 while (($language_row = mysql_fetch_assoc($language_result)) != null) {
droy0b08d292008-05-28 15:18:11 +0000140 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000141 $language_iso = $language_row['iso_code'];
kitlo58d8a5a2008-09-24 20:08:44 +0000142 $language_id = $language_row['language_id'];
143 if (strcmp($language_iso, "en") == 0) {
kitlo58d8a5a2008-09-24 20:08:44 +0000144 $language_name = "Pseudo Translations";
kitloe3fea252010-01-25 02:13:49 +0000145 $language_iso = "en_AA";
kitlo58d8a5a2008-09-24 20:08:44 +0000146 }
kitlo9c7c62a2008-10-05 16:05:19 +0000147
kitlo58d8a5a2008-09-24 20:08:44 +0000148 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
149
gobrien1a8e02f2008-01-30 01:46:26 +0000150 /*
droy0b08d292008-05-28 15:18:11 +0000151 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000152 */
kitlo58d8a5a2008-09-24 20:08:44 +0000153 if (strcmp($language_iso, "en_AA") == 0) {
154 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
155 FROM files AS f
156 INNER JOIN strings AS s ON f.file_id = s.file_id
157 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
158 WHERE f.is_active
kitlo78f97432009-03-17 22:28:58 +0000159 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000160 } else {
161 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
162 FROM files AS f
163 INNER JOIN strings AS s ON f.file_id = s.file_id
164 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
165 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
166 WHERE t.language_id = " . $language_id . "
167 AND f.is_active
kitlo78f97432009-03-17 22:28:58 +0000168 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000169 }
170
droy0b08d292008-05-28 15:18:11 +0000171 $plugins = array();
kitlo9c7c62a2008-10-05 16:05:19 +0000172 $projects = array();
173 $project_versions = array();
174 $pseudo_translations_indexes = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000175 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
176 # save original filename
177 $file_row['origname'] = $file_row['name'];
178
kitloc2fbc882011-06-11 21:31:40 +0000179 # remove optional outer dirs, e.g. 'pde/ui/'
180 $pos = strripos($file_row['name'], 'org.');
181 if ($pos !== false) {
182 $file_row['name'] = substr($file_row['name'], $pos);
183 }
184 $pos = strripos($file_row['name'], 'com.');
185 if ($pos !== false) {
186 $file_row['name'] = substr($file_row['name'], $pos);
187 }
188
189 $pattern =
190 '/^
191 (.*?)? # $1 plugin name
192 \/ # slash
193 (.*?\/)? # $2 dir name
194 ([^\/]+[.]properties) # $3 file name
195 $/ix';
196 $plugin_name_string = preg_replace($pattern, '$1', $file_row['name']);
197 $dir_name_string = preg_replace($pattern, '$2', $file_row['name']);
198 $file_name_string = preg_replace($pattern, '$3', $file_row['name']);
199
200 # remove optional source dir, e.g. 'src' or 'src_ant'
201 $pos = stripos($dir_name_string, 'org/');
202 if ($pos !== false) {
kitlo4e649d42011-06-12 12:50:35 +0000203 $dir_name_string = substr($dir_name_string, $pos);
kitloc2fbc882011-06-11 21:31:40 +0000204 }
205 $pos = strripos($dir_name_string, 'com/');
206 if ($pos !== false) {
207 $dir_name_string = substr($dir_name_string, $pos);
208 }
209
210 $file_row['plugin_name'] = $plugin_name_string;
211 $file_row['dir_name'] = $dir_name_string;
212 $file_row['file_name'] = $file_name_string;
213
214 $plugins[$plugin_name_string][] = $file_row;
droy0b08d292008-05-28 15:18:11 +0000215 }
kitlo58d8a5a2008-09-24 20:08:44 +0000216
droy0b08d292008-05-28 15:18:11 +0000217 /*
218 * Generate one plug-in fragment for each plug-in
219 */
kitlobd84b752010-05-14 13:29:01 +0000220 ksort($plugins);
kitlo58d8a5a2008-09-24 20:08:44 +0000221 foreach ($plugins as $plugin_name => $plugin_row) {
222 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000223 /*
droy0b08d292008-05-28 15:18:11 +0000224 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000225 */
kitlo58d8a5a2008-09-24 20:08:44 +0000226 if (file_exists($tmp_dir)) {
227 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000228 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000229 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000230 }
gobrien1a8e02f2008-01-30 01:46:26 +0000231 /*
droy0b08d292008-05-28 15:18:11 +0000232 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000233 */
droy0b08d292008-05-28 15:18:11 +0000234 foreach ($plugin_row as $properties_file) {
235 /*
236 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
237 */
kitloc2fbc882011-06-11 21:31:40 +0000238 $filename = $properties_file['file_name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000239 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000240 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000241 }
kitlo58d8a5a2008-09-24 20:08:44 +0000242 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000243 /*
244 * Create any needed sub-directories
245 */
kitloc2fbc882011-06-11 21:31:40 +0000246 exec("mkdir -p \"" . $tmp_dir . $properties_file['dir_name'] . "\"");
droy0b08d292008-05-28 15:18:11 +0000247 /*
248 * Start writing to the file
249 */
kitloc2fbc882011-06-11 21:31:40 +0000250 $fullpath = $tmp_dir . $properties_file['dir_name'] . $filename;
kitlo58d8a5a2008-09-24 20:08:44 +0000251 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000252 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000253 if (strcmp($language_iso, "en_AA") == 0) {
254 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
255 " AND is_active AND non_translatable = 0";
256 $strings_result = mysql_query($sql);
257 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000258 /* Check for value starting with form tag (bug 270456) */
259 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
260 $pattern = "/^(<form>)(.*)/i";
261 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
262 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
263 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
264 } else {
265 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
266 ":" . $strings_row['value'];
267 }
268 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000269
270 $value = htmlspecialchars($strings_row['value']);
271 if (strlen($value) > 100) {
272 $value = substr($value, 0, 100) . " ...";
273 }
kitlo9c7c62a2008-10-05 16:05:19 +0000274 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
275 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
276 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
277 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000278 }
279 } else {
280 $sql = "SELECT
281 strings.name AS 'key',
282 strings.value AS orig,
283 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000284 FROM strings, translations
285 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000286 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000287 AND strings.is_active
288 AND strings.non_translatable = 0
289 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000290 AND translations.is_active";
291 $strings_result = mysql_query($sql);
292 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000293 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000294 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000295 if ($strings_row['trans']) {
296 # json_encode returns the string with quotes fore and aft. Need to strip them.
297 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
298 # $tr_string = str_replace('\\\\', '\\', $tr_string);
299 $tr_string = toescapedunicode($strings_row['trans']);
300 fwrite($outp, $tr_string);
301 # echo $strings_row['trans'];
302 } else {
303 fwrite($outp, $strings_row['orig']);
304 }
droy0b08d292008-05-28 15:18:11 +0000305 }
droy0b08d292008-05-28 15:18:11 +0000306 }
307 /*
308 * Finish the properties file
309 */
kitlo58d8a5a2008-09-24 20:08:44 +0000310 fclose($outp);
311 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000312 }
313 /*
droy0b08d292008-05-28 15:18:11 +0000314 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000315 */
kitlo9c7c62a2008-10-05 16:05:19 +0000316 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000317 /*
318 * Generate the META-INF/MANIFEST.MF file
319 */
320 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000321 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000322 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000323 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000324
droy0b08d292008-05-28 15:18:11 +0000325 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000326 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000327
328 exec("mkdir $tmp_dir/META-INF" );
329 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
330 fwrite($outp, "Manifest-Version: 1.0\n");
331 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
332 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000333 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
334 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000335 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
336 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000337 /*
338 * Jar up this directory as the fragment plug-in jar
339 */
kitlo58d8a5a2008-09-24 20:08:44 +0000340 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
341 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000342
kitlo9c7c62a2008-10-05 16:05:19 +0000343 $projects[$project_id][] = $fragment_id;
344 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000345 }
kitlo78f97432009-03-17 22:28:58 +0000346 if (sizeof($projects) > 0) {
347 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
348 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
349 $site_xml .= "\n\t</category-def>";
350
kitloe3fea252010-01-25 02:13:49 +0000351 fwrite($language_pack_links_file, "\n\t\t<a href='#$language_iso'>$language_name</a>");
352 if (strcmp($language_iso, "en_AA") != 0) {
353 fwrite($language_pack_links_file, ",");
354 }
kitlob1920882010-05-12 23:33:18 +0000355 $language_pack_links_file_buffer .= "\n\t<h4>Language: <a name='$language_iso'>$language_name</a></h4>";
356 $language_pack_links_file_buffer .= "\n\t<ul>";
kitlo78f97432009-03-17 22:28:58 +0000357 }
kitlobd84b752010-05-14 13:29:01 +0000358 ksort($projects);
kitlo9c7c62a2008-10-05 16:05:19 +0000359 foreach ($projects as $project_id => $fragment_ids) {
360 /*
361 * Sort fragment names
362 */
363 asort($fragment_ids);
364 /*
365 * Create ${babel_language_packs_dir}tmp
366 */
367 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
368 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
369 /*
370 * Clean and create the temporary directory
371 */
372 if (file_exists($tmp_dir)) {
373 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
374 } else {
375 exec("mkdir $tmp_dir");
376 }
377 /*
378 * Create the feature.xml
379 *
380 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
381 *
382 * <url>
383 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
384 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
385 * </url>
386 */
kitlo5c9da712008-10-27 12:45:40 +0000387 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000388 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
389
kitlo9c7c62a2008-10-05 16:05:19 +0000390 if (strcmp($language_iso, "en_AA") == 0) {
391 $project_pct_complete = 100;
kitlo95107b72010-07-29 05:18:34 +0000392 } else {
393 $project_version = $project_versions[$project_id];
394 $sql = "SELECT pct_complete
395 FROM project_progress
396 WHERE project_id = \"$project_id\"
397 AND version = \"$project_version\"
398 AND language_id = $language_id";
399 $project_pct_complete_result = mysql_query($sql);
400 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
kitlo9c7c62a2008-10-05 16:05:19 +0000401 }
402
403 $outp = fopen("$tmp_dir/feature.xml", "w");
404 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
405 "\n<feature" .
406 "\n\tid=\"$feature_id\"" .
407 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
408 "\n\timage=\"eclipse_update_120.jpg\"" .
409 "\n\tprovider-name=\"%providerName\"" .
410 "\n\tversion=\"$train_version_timestamp\">" .
411 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
412 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
413 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
414 foreach ($fragment_ids as $fragment_id) {
415 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
416 $size = filesize($jar_name);
417 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
418 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
419 /*
420 * Copy the plugin to ${babel_language_packs_dir}tmp
421 */
422 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
423 }
424 fwrite($outp, "\n</feature>");
425 fclose($outp);
426 /*
427 * Copy in the various legal files
428 */
429 exec("cp ${source_files_dir}about.html $tmp_dir");
430 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
431 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
432 exec("cp ${source_files_dir}feature.properties $tmp_dir");
433 exec("cp ${source_files_dir}license.html $tmp_dir");
434 /*
435 * Copy in the Babel Pseudo Translations Index file
436 */
437 if (strcmp($language_iso, "en_AA") == 0) {
438 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
439 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
440 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
441 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
442 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
443 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
444 foreach ($pseudo_translations_indexes[$project_id] as $index) {
445 fwrite($pseudo_translations_index_file, $index);
446 }
droy03d5c462008-11-10 21:07:01 +0000447 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000448 fclose($pseudo_translations_index_file);
449 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
450 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
451 }
452 /*
453 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
454 */
kitloc42941d2008-11-20 15:33:00 +0000455 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
456 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000457 /*
458 * Zip up language pack
459 */
460 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
461 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
462 /*
463 * Clean up ${babel_language_packs_dir}tmp
464 */
465 exec("rm -rf ${babel_language_packs_dir}tmp");
466 /*
467 * Add project language pack link to language pack links file
468 */
kitlob1920882010-05-12 23:33:18 +0000469 $language_pack_links_file_buffer .= "\n\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 +0000470 /*
471 * Jar up this directory as the feature jar
472 */
473 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
474 /*
475 * Register this feature with the site.xml
476 */
kitloc42941d2008-11-20 15:33:00 +0000477 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000478 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
479 $site_xml .= "\n\t</feature>";
droy58951f72009-05-13 18:12:20 +0000480
kitlo78f97432009-03-17 22:28:58 +0000481
droy58951f72009-05-13 18:12:20 +0000482 } /* End: foreach project */
483 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitloe3fea252010-01-25 02:13:49 +0000484 if (sizeof($projects) > 0) {
kitlob1920882010-05-12 23:33:18 +0000485 $language_pack_links_file_buffer .= "\n\t</ul>";
kitloe3fea252010-01-25 02:13:49 +0000486 }
gobrien1a8e02f2008-01-30 01:46:26 +0000487 }
kitlob1920882010-05-12 23:33:18 +0000488
489 fwrite($language_pack_links_file, "\n\t</p>");
490 fwrite($language_pack_links_file, $language_pack_links_file_buffer);
491
492 fwrite($language_pack_links_file, "\n\t<br />\n</body>\n</html>");
493 fclose($language_pack_links_file);
494
495 $dbh = $dbc->disconnect();
496
gobrien1a8e02f2008-01-30 01:46:26 +0000497 /*
kitlob1920882010-05-12 23:33:18 +0000498 * Generate and save site.xml/content.jar/artifacts.jar with mirrorsURL
499 */
500 $outp = fopen("${output_dir_for_train}site.xml", "w");
501 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
502 "\n<site pack200=\"true\" digestURL=\"http://download.eclipse.org/technology/babel/update-site/R$release_id/$train_id\"" .
503 "\n\tmirrorsURL=\"http://www.eclipse.org/downloads/download.php?file=/technology/babel/update-site/R$release_id/$train_id/site.xml&amp;format=xml\">" .
504 "\n\t<description url=\"http://babel.eclipse.org/\">" .
505 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
506 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
507 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
508 "\n\t</description>");
509 fwrite($outp, $site_xml);
510 fwrite($outp, "\n</site>");
511 fclose($outp);
512
513 /*
514 * Generate the metadata and add the non-greedy tags
515 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
516 */
517 exec("mkdir ${output_dir_for_train}mirrors/");
518 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000519 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
520 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
521 echo "Processing XML\n";
kitlob1920882010-05-12 23:33:18 +0000522 system("xsltproc -o ${output_dir_for_train}content.xml ". dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
523 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
524 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
525 system("cd ${output_dir_for_train} ; mv content.jar mirrors/content.mirrors ; mv artifacts.jar mirrors/artifacts.mirrors");
526 }
527 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.mirrors");
528
529 /*
530 * Generate normal site.xml/content.jar/artifacts.jar without mirrorsURL
gobrien1a8e02f2008-01-30 01:46:26 +0000531 */
kitlo58d8a5a2008-09-24 20:08:44 +0000532 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000533 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
534 "\n<site>" .
535 "\n\t<description url=\"http://babel.eclipse.org/\">" .
536 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
537 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
538 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
539 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000540 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000541 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000542 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000543
droye77ad172009-05-04 17:35:56 +0000544 /*
kitlob2ca7c02010-02-10 19:05:41 +0000545 * Generate the metadata and add the non-greedy tags
546 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
547 */
kitloe9468742010-02-10 20:08:49 +0000548 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000549 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
550 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
551 echo "Processing XML\n";
kitlob2ca7c02010-02-10 19:05:41 +0000552 system("xsltproc -o ${output_dir_for_train}content.xml ". dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
kitlob1920882010-05-12 23:33:18 +0000553 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
554 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
555 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.txt");
556 } else {
557 system("cd ${output_dir_for_train} ; cp site.xml mirrors/site.txt");
kitlob2ca7c02010-02-10 19:05:41 +0000558 }
gobrien1a8e02f2008-01-30 01:46:26 +0000559}
gobrien1a8e02f2008-01-30 01:46:26 +0000560echo "Completed generating update site\n";
561
kitlo9c7c62a2008-10-05 16:05:19 +0000562
gobrien1a8e02f2008-01-30 01:46:26 +0000563/*
kitlo58d8a5a2008-09-24 20:08:44 +0000564 2. what happens if the translation feature includes plug-in fragments for
565 plug-ins that are not in the current image?
566 does it load correctly and ignore those fragments? if so, good
567 A: warnings appear in the run-time error log
568 does it fail to load? if so, then we need to generate different features, perhaps
569 one feature for each plug or else we need to know more about the project
570 distro structure to know which plug-ins to put in each feature
571 what happens if those plug-ins are later added - does it load the strings now?
572 A: probably not
573 3. need to handle different versions of each feature/plugin/platform; generate different
574 language packs for each
575 */
gobrien1a8e02f2008-01-30 01:46:26 +0000576
droyc6eb7ac2009-05-12 17:25:46 +0000577function usage() {
578 echo "\n";
579 echo "generate1.php -b <build_id> [-t <train_id>]\n";
580 echo " -b <build_id>: The Build ID for this build.\n";
kitloe3fea252010-01-25 02:13:49 +0000581 echo " -t <train_id>: Optional: train to build (helios, galileo, ganymede, europa).";
droyc6eb7ac2009-05-12 17:25:46 +0000582 echo "\n";
583}
584
kitloe3fea252010-01-25 02:13:49 +0000585?>