blob: e00813d96609810848c35d31c51251af38e6c8a3 [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
droy02c430a2008-06-02 19:42:08 +0000179 # strip useless CVS structure before the plugin name (bug 221675 c14):
180 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
181 $replace = '${2}.${3}${4}.properties';
182 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000183
droy02c430a2008-06-02 19:42:08 +0000184 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
kitlo8d7c0532009-03-14 23:57:49 +0000185 /*
186 $pattern =
187 '/^
188 ([a-zA-Z0-9_-]+)\. # \1 org.
189 ([a-zA-Z0-9_-]+)\. # \2 eclipse.
190 ([a-zA-Z0-9\._-]+) # \3 datatools.connectivity
191 (.*)\/ # \4 \/plugins\/
192 (\1) # \5 org
193 ([\.\/]) # \6 .
194 (\2) # \7 eclipse
195 ([\.\/]) # \8 .
196 (.*) # \9 datatools.connectivity.ui\/plugin
197 \.properties # .properties
198 $/ix
199 ';
droy02c430a2008-06-02 19:42:08 +0000200 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
kitlo8d7c0532009-03-14 23:57:49 +0000201 */
202
203 # fix output folder (bug 261584)
kitloc2fbc882011-06-11 21:31:40 +0000204 /*
kitlo8d7c0532009-03-14 23:57:49 +0000205 $pattern =
206 '/^
207 (.*\/)? # \1 optional outer directories
208 ([a-z]+) # \2 org|com|etc
209 [.] # dot
210 ([^\/]+) # \3 plugin id except org.|com.
211 \/ # slash
212 (.*?\/)? # \4 optional src\/, src\/main\/ etc
213 # \5 resource path (pathname inside resulting jar)
214 # (a) within a org|com directory, or
215 # (b) in plugin root dir.
216 (\2\/.*[.]properties| # org|com\/anything.properties
217 [^\/]+[.]properties) # eg plugin.properties
218 $/ix';
219 $replace = '$2.$3/$5';
220
droy0b08d292008-05-28 15:18:11 +0000221 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000222
223 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000224 $file_row['subname'] = $matches[2];
225 $plugins[$matches[1]][] = $file_row;
226 } else {
227 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000228 }
kitloc2fbc882011-06-11 21:31:40 +0000229 */
230
231 # remove optional outer dirs, e.g. 'pde/ui/'
232 $pos = strripos($file_row['name'], 'org.');
233 if ($pos !== false) {
234 $file_row['name'] = substr($file_row['name'], $pos);
235 }
236 $pos = strripos($file_row['name'], 'com.');
237 if ($pos !== false) {
238 $file_row['name'] = substr($file_row['name'], $pos);
239 }
240
241 $pattern =
242 '/^
243 (.*?)? # $1 plugin name
244 \/ # slash
245 (.*?\/)? # $2 dir name
246 ([^\/]+[.]properties) # $3 file name
247 $/ix';
248 $plugin_name_string = preg_replace($pattern, '$1', $file_row['name']);
249 $dir_name_string = preg_replace($pattern, '$2', $file_row['name']);
250 $file_name_string = preg_replace($pattern, '$3', $file_row['name']);
251
252 # remove optional source dir, e.g. 'src' or 'src_ant'
253 $pos = stripos($dir_name_string, 'org/');
254 if ($pos !== false) {
255 $dir_string = substr($dir_name_string, $pos);
256 }
257 $pos = strripos($dir_name_string, 'com/');
258 if ($pos !== false) {
259 $dir_name_string = substr($dir_name_string, $pos);
260 }
261
262 $file_row['plugin_name'] = $plugin_name_string;
263 $file_row['dir_name'] = $dir_name_string;
264 $file_row['file_name'] = $file_name_string;
265
266 $plugins[$plugin_name_string][] = $file_row;
droy0b08d292008-05-28 15:18:11 +0000267 }
kitlo58d8a5a2008-09-24 20:08:44 +0000268
droy0b08d292008-05-28 15:18:11 +0000269 /*
270 * Generate one plug-in fragment for each plug-in
271 */
kitlobd84b752010-05-14 13:29:01 +0000272 ksort($plugins);
kitlo58d8a5a2008-09-24 20:08:44 +0000273 foreach ($plugins as $plugin_name => $plugin_row) {
274 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000275 /*
droy0b08d292008-05-28 15:18:11 +0000276 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000277 */
kitlo58d8a5a2008-09-24 20:08:44 +0000278 if (file_exists($tmp_dir)) {
279 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000280 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000281 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000282 }
gobrien1a8e02f2008-01-30 01:46:26 +0000283 /*
droy0b08d292008-05-28 15:18:11 +0000284 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000285 */
droy0b08d292008-05-28 15:18:11 +0000286 foreach ($plugin_row as $properties_file) {
287 /*
288 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
289 */
kitloc2fbc882011-06-11 21:31:40 +0000290 $filename = $properties_file['file_name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000291 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000292 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000293 }
kitlo58d8a5a2008-09-24 20:08:44 +0000294 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000295 /*
296 * Create any needed sub-directories
297 */
kitloc2fbc882011-06-11 21:31:40 +0000298 exec("mkdir -p \"" . $tmp_dir . $properties_file['dir_name'] . "\"");
droy0b08d292008-05-28 15:18:11 +0000299 /*
300 * Start writing to the file
301 */
kitloc2fbc882011-06-11 21:31:40 +0000302 $fullpath = $tmp_dir . $properties_file['dir_name'] . $filename;
kitlo58d8a5a2008-09-24 20:08:44 +0000303 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000304 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000305 if (strcmp($language_iso, "en_AA") == 0) {
306 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
307 " AND is_active AND non_translatable = 0";
308 $strings_result = mysql_query($sql);
309 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000310 /* Check for value starting with form tag (bug 270456) */
311 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
312 $pattern = "/^(<form>)(.*)/i";
313 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
314 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
315 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
316 } else {
317 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
318 ":" . $strings_row['value'];
319 }
320 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000321
322 $value = htmlspecialchars($strings_row['value']);
323 if (strlen($value) > 100) {
324 $value = substr($value, 0, 100) . " ...";
325 }
kitlo9c7c62a2008-10-05 16:05:19 +0000326 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
327 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
328 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
329 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000330 }
331 } else {
332 $sql = "SELECT
333 strings.name AS 'key',
334 strings.value AS orig,
335 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000336 FROM strings, translations
337 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000338 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000339 AND strings.is_active
340 AND strings.non_translatable = 0
341 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000342 AND translations.is_active";
343 $strings_result = mysql_query($sql);
344 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000345 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000346 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000347 if ($strings_row['trans']) {
348 # json_encode returns the string with quotes fore and aft. Need to strip them.
349 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
350 # $tr_string = str_replace('\\\\', '\\', $tr_string);
351 $tr_string = toescapedunicode($strings_row['trans']);
352 fwrite($outp, $tr_string);
353 # echo $strings_row['trans'];
354 } else {
355 fwrite($outp, $strings_row['orig']);
356 }
droy0b08d292008-05-28 15:18:11 +0000357 }
droy0b08d292008-05-28 15:18:11 +0000358 }
359 /*
360 * Finish the properties file
361 */
kitlo58d8a5a2008-09-24 20:08:44 +0000362 fclose($outp);
363 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000364 }
365 /*
droy0b08d292008-05-28 15:18:11 +0000366 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000367 */
kitlo9c7c62a2008-10-05 16:05:19 +0000368 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000369 /*
370 * Generate the META-INF/MANIFEST.MF file
371 */
372 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000373 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000374 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000375 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000376
droy0b08d292008-05-28 15:18:11 +0000377 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000378 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000379
380 exec("mkdir $tmp_dir/META-INF" );
381 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
382 fwrite($outp, "Manifest-Version: 1.0\n");
383 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
384 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000385 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
386 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000387 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
388 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000389 /*
390 * Jar up this directory as the fragment plug-in jar
391 */
kitlo58d8a5a2008-09-24 20:08:44 +0000392 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
393 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000394
kitlo9c7c62a2008-10-05 16:05:19 +0000395 $projects[$project_id][] = $fragment_id;
396 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000397 }
kitlo78f97432009-03-17 22:28:58 +0000398 if (sizeof($projects) > 0) {
399 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
400 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
401 $site_xml .= "\n\t</category-def>";
402
kitloe3fea252010-01-25 02:13:49 +0000403 fwrite($language_pack_links_file, "\n\t\t<a href='#$language_iso'>$language_name</a>");
404 if (strcmp($language_iso, "en_AA") != 0) {
405 fwrite($language_pack_links_file, ",");
406 }
kitlob1920882010-05-12 23:33:18 +0000407 $language_pack_links_file_buffer .= "\n\t<h4>Language: <a name='$language_iso'>$language_name</a></h4>";
408 $language_pack_links_file_buffer .= "\n\t<ul>";
kitlo78f97432009-03-17 22:28:58 +0000409 }
kitlobd84b752010-05-14 13:29:01 +0000410 ksort($projects);
kitlo9c7c62a2008-10-05 16:05:19 +0000411 foreach ($projects as $project_id => $fragment_ids) {
412 /*
413 * Sort fragment names
414 */
415 asort($fragment_ids);
416 /*
417 * Create ${babel_language_packs_dir}tmp
418 */
419 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
420 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
421 /*
422 * Clean and create the temporary directory
423 */
424 if (file_exists($tmp_dir)) {
425 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
426 } else {
427 exec("mkdir $tmp_dir");
428 }
429 /*
430 * Create the feature.xml
431 *
432 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
433 *
434 * <url>
435 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
436 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
437 * </url>
438 */
kitlo5c9da712008-10-27 12:45:40 +0000439 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000440 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
441
kitlo9c7c62a2008-10-05 16:05:19 +0000442 if (strcmp($language_iso, "en_AA") == 0) {
443 $project_pct_complete = 100;
kitlo95107b72010-07-29 05:18:34 +0000444 } else {
445 $project_version = $project_versions[$project_id];
446 $sql = "SELECT pct_complete
447 FROM project_progress
448 WHERE project_id = \"$project_id\"
449 AND version = \"$project_version\"
450 AND language_id = $language_id";
451 $project_pct_complete_result = mysql_query($sql);
452 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
kitlo9c7c62a2008-10-05 16:05:19 +0000453 }
454
455 $outp = fopen("$tmp_dir/feature.xml", "w");
456 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
457 "\n<feature" .
458 "\n\tid=\"$feature_id\"" .
459 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
460 "\n\timage=\"eclipse_update_120.jpg\"" .
461 "\n\tprovider-name=\"%providerName\"" .
462 "\n\tversion=\"$train_version_timestamp\">" .
463 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
464 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
465 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
466 foreach ($fragment_ids as $fragment_id) {
467 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
468 $size = filesize($jar_name);
469 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
470 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
471 /*
472 * Copy the plugin to ${babel_language_packs_dir}tmp
473 */
474 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
475 }
476 fwrite($outp, "\n</feature>");
477 fclose($outp);
478 /*
479 * Copy in the various legal files
480 */
481 exec("cp ${source_files_dir}about.html $tmp_dir");
482 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
483 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
484 exec("cp ${source_files_dir}feature.properties $tmp_dir");
485 exec("cp ${source_files_dir}license.html $tmp_dir");
486 /*
487 * Copy in the Babel Pseudo Translations Index file
488 */
489 if (strcmp($language_iso, "en_AA") == 0) {
490 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
491 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
492 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
493 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
494 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
495 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
496 foreach ($pseudo_translations_indexes[$project_id] as $index) {
497 fwrite($pseudo_translations_index_file, $index);
498 }
droy03d5c462008-11-10 21:07:01 +0000499 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000500 fclose($pseudo_translations_index_file);
501 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
502 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
503 }
504 /*
505 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
506 */
kitloc42941d2008-11-20 15:33:00 +0000507 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
508 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000509 /*
510 * Zip up language pack
511 */
512 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
513 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
514 /*
515 * Clean up ${babel_language_packs_dir}tmp
516 */
517 exec("rm -rf ${babel_language_packs_dir}tmp");
518 /*
519 * Add project language pack link to language pack links file
520 */
kitlob1920882010-05-12 23:33:18 +0000521 $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 +0000522 /*
523 * Jar up this directory as the feature jar
524 */
525 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
526 /*
527 * Register this feature with the site.xml
528 */
kitloc42941d2008-11-20 15:33:00 +0000529 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000530 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
531 $site_xml .= "\n\t</feature>";
droy58951f72009-05-13 18:12:20 +0000532
kitlo78f97432009-03-17 22:28:58 +0000533
droy58951f72009-05-13 18:12:20 +0000534 } /* End: foreach project */
535 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitloe3fea252010-01-25 02:13:49 +0000536 if (sizeof($projects) > 0) {
kitlob1920882010-05-12 23:33:18 +0000537 $language_pack_links_file_buffer .= "\n\t</ul>";
kitloe3fea252010-01-25 02:13:49 +0000538 }
gobrien1a8e02f2008-01-30 01:46:26 +0000539 }
kitlob1920882010-05-12 23:33:18 +0000540
541 fwrite($language_pack_links_file, "\n\t</p>");
542 fwrite($language_pack_links_file, $language_pack_links_file_buffer);
543
544 fwrite($language_pack_links_file, "\n\t<br />\n</body>\n</html>");
545 fclose($language_pack_links_file);
546
547 $dbh = $dbc->disconnect();
548
gobrien1a8e02f2008-01-30 01:46:26 +0000549 /*
kitlob1920882010-05-12 23:33:18 +0000550 * Generate and save site.xml/content.jar/artifacts.jar with mirrorsURL
551 */
552 $outp = fopen("${output_dir_for_train}site.xml", "w");
553 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
554 "\n<site pack200=\"true\" digestURL=\"http://download.eclipse.org/technology/babel/update-site/R$release_id/$train_id\"" .
555 "\n\tmirrorsURL=\"http://www.eclipse.org/downloads/download.php?file=/technology/babel/update-site/R$release_id/$train_id/site.xml&amp;format=xml\">" .
556 "\n\t<description url=\"http://babel.eclipse.org/\">" .
557 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
558 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
559 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
560 "\n\t</description>");
561 fwrite($outp, $site_xml);
562 fwrite($outp, "\n</site>");
563 fclose($outp);
564
565 /*
566 * Generate the metadata and add the non-greedy tags
567 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
568 */
569 exec("mkdir ${output_dir_for_train}mirrors/");
570 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000571 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
572 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
573 echo "Processing XML\n";
kitlob1920882010-05-12 23:33:18 +0000574 system("xsltproc -o ${output_dir_for_train}content.xml ". dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
575 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
576 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
577 system("cd ${output_dir_for_train} ; mv content.jar mirrors/content.mirrors ; mv artifacts.jar mirrors/artifacts.mirrors");
578 }
579 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.mirrors");
580
581 /*
582 * Generate normal site.xml/content.jar/artifacts.jar without mirrorsURL
gobrien1a8e02f2008-01-30 01:46:26 +0000583 */
kitlo58d8a5a2008-09-24 20:08:44 +0000584 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000585 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
586 "\n<site>" .
587 "\n\t<description url=\"http://babel.eclipse.org/\">" .
588 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
589 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
590 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
591 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000592 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000593 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000594 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000595
droye77ad172009-05-04 17:35:56 +0000596 /*
kitlob2ca7c02010-02-10 19:05:41 +0000597 * Generate the metadata and add the non-greedy tags
598 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
599 */
kitloe9468742010-02-10 20:08:49 +0000600 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000601 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
602 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
603 echo "Processing XML\n";
kitlob2ca7c02010-02-10 19:05:41 +0000604 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 +0000605 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
606 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
607 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.txt");
608 } else {
609 system("cd ${output_dir_for_train} ; cp site.xml mirrors/site.txt");
kitlob2ca7c02010-02-10 19:05:41 +0000610 }
gobrien1a8e02f2008-01-30 01:46:26 +0000611}
gobrien1a8e02f2008-01-30 01:46:26 +0000612echo "Completed generating update site\n";
613
kitlo9c7c62a2008-10-05 16:05:19 +0000614
gobrien1a8e02f2008-01-30 01:46:26 +0000615/*
kitlo58d8a5a2008-09-24 20:08:44 +0000616 2. what happens if the translation feature includes plug-in fragments for
617 plug-ins that are not in the current image?
618 does it load correctly and ignore those fragments? if so, good
619 A: warnings appear in the run-time error log
620 does it fail to load? if so, then we need to generate different features, perhaps
621 one feature for each plug or else we need to know more about the project
622 distro structure to know which plug-ins to put in each feature
623 what happens if those plug-ins are later added - does it load the strings now?
624 A: probably not
625 3. need to handle different versions of each feature/plugin/platform; generate different
626 language packs for each
627 */
gobrien1a8e02f2008-01-30 01:46:26 +0000628
droyc6eb7ac2009-05-12 17:25:46 +0000629function usage() {
630 echo "\n";
631 echo "generate1.php -b <build_id> [-t <train_id>]\n";
632 echo " -b <build_id>: The Build ID for this build.\n";
kitloe3fea252010-01-25 02:13:49 +0000633 echo " -t <train_id>: Optional: train to build (helios, galileo, ganymede, europa).";
droyc6eb7ac2009-05-12 17:25:46 +0000634 echo "\n";
635}
636
kitloe3fea252010-01-25 02:13:49 +0000637?>