blob: cc3fb3bfa68f27fb6b9bd456335ef0796a81c403 [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
kitlo58d8a5a2008-09-24 20:08:44 +000023 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000024
25/*
kitlo58d8a5a2008-09-24 20:08:44 +000026 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000027 */
atoulme3fa5f5c2009-01-20 21:26:16 +000028define("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 +000029
droyaa172502009-05-06 20:50:07 +000030ini_set("memory_limit", "512M");
atoulme3ac52612009-02-02 13:14:39 +000031require(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme12882d52009-01-26 18:39:17 +000032require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy3081da02009-05-11 15:54:56 +000033
kitlo22479022010-01-25 03:22:33 +000034# Get all release trains
kitloe3fea252010-01-25 02:13:49 +000035$dbc = new DBConnection();
36$dbh = $dbc->connect();
37$result = mysql_query("SELECT * FROM release_trains ORDER BY train_version DESC");
38$train_result = array();
39while ($train_row = mysql_fetch_assoc($result)) {
40 $train_result[$train_row['train_id']] = $train_row['train_version'];
41}
droy3081da02009-05-11 15:54:56 +000042
43# Command-line parameter for the release train
44# bug 272958
droyc6eb7ac2009-05-12 17:25:46 +000045# b: build id
46# t: (optional: train id)
47
48$options = getopt("b:t:");
droy3081da02009-05-11 15:54:56 +000049$argv_train = "";
droyc6eb7ac2009-05-12 17:25:46 +000050if(isset($options['t'])) {
51 $argv_train = $options['t'];
droy3081da02009-05-11 15:54:56 +000052 if(array_key_exists($argv_train, $train_result)) {
53 # Picked a valid train .. remove all others
54 foreach ($train_result as $train_id => $train_version) {
55 if($train_id != $argv_train) {
56 unset($train_result[$train_id]);
57 }
58 }
59 }
60}
61
droyc6eb7ac2009-05-12 17:25:46 +000062$buildid = "";
63if(!isset($options['b'])) {
64 usage();
65 exit();
66}
67else {
68 $buildid = $options['b'];
69}
70
atoulme3ac52612009-02-02 13:14:39 +000071$work_dir = $addon->callHook('babel_working');
atoulme12882d52009-01-26 18:39:17 +000072
atoulme3ac52612009-02-02 13:14:39 +000073global $addon;
74$context = $addon->callHook('context');
gobrienb854dcb2008-01-30 18:50:45 +000075
kitlo9c7c62a2008-10-05 16:05:19 +000076$work_context_dir = $work_dir . $context . "/";
77$tmp_dir = $work_context_dir . "tmp/";
78$babel_language_packs_dir = $work_context_dir . "babel_language_packs/";
79$output_dir = $work_context_dir . "output/";
atoulme3ac52612009-02-02 13:14:39 +000080$source_files_dir = dirname(__FILE__) . "/source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000081
gobrien1a8e02f2008-01-30 01:46:26 +000082$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000083$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000084
kitlo82c999e2010-01-25 14:55:33 +000085$rm_command = "rm -rf $work_context_dir" . "*";
droyd157aac2008-10-07 21:14:33 +000086exec($rm_command);
droy082976e2008-10-07 21:02:23 +000087exec("mkdir -p $output_dir");
88
droy3081da02009-05-11 15:54:56 +000089echo "Requested builds: ";
kitlo78f97432009-03-17 22:28:58 +000090foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000091 echo $train_id . " ";
92}
93echo "\n";
kitlo78f97432009-03-17 22:28:58 +000094
droy3081da02009-05-11 15:54:56 +000095# Loop through the trains
96foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000097 echo "Generating update site for: $train_id\n";
droy3081da02009-05-11 15:54:56 +000098
99 /*
100 * Create language pack links file
101 */
102 exec("mkdir -p $babel_language_packs_dir");
103 $language_pack_links_file = fopen("${babel_language_packs_dir}${train_id}.php", "w");
droyc6eb7ac2009-05-12 17:25:46 +0000104 fwrite($language_pack_links_file, "<?php\n");
droy260639a2009-05-28 20:02:21 +0000105 # Uncomment if each train is in its own directory: fwrite($language_pack_links_file, "\$language_pack_leader = \"${train_id}\";\n");
106 fwrite($language_pack_links_file, "\$language_pack_leader = \".\";\n");
droy58951f72009-05-13 18:12:20 +0000107 fwrite($language_pack_links_file, "?>\n");
droyc6eb7ac2009-05-12 17:25:46 +0000108 # copy page_header.html here
109 $header = file_get_contents("${source_files_dir}page_header.html");
110 fwrite($language_pack_links_file, $header);
kitloe3fea252010-01-25 02:13:49 +0000111 fwrite($language_pack_links_file, "\n\t<h1>Babel Language Packs for " . ucfirst($train_id) . "</h1>" .
droyc6eb7ac2009-05-12 17:25:46 +0000112 "\n\t<h2>Build ID: $buildid</h2>" .
droy3081da02009-05-11 15:54:56 +0000113 "\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 +0000114 "\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>" .
115 "\n\t<p>Go to: ");
116
kitlo9c7c62a2008-10-05 16:05:19 +0000117 $train_version_timestamp = "$train_version.v$timestamp";
kitloe3fea252010-01-25 02:13:49 +0000118 $language_pack_links_file_buffer = "";
kitlo9c7c62a2008-10-05 16:05:19 +0000119 $site_xml = "";
kitlo58d8a5a2008-09-24 20:08:44 +0000120
kitlo78f97432009-03-17 22:28:58 +0000121 $output_dir_for_train = $output_dir . $train_id . "/";
kitlo58d8a5a2008-09-24 20:08:44 +0000122 exec("mkdir $output_dir_for_train");
123 exec("mkdir ${output_dir_for_train}features/");
124 exec("mkdir ${output_dir_for_train}plugins/");
125
droy68864612009-04-14 15:44:05 +0000126 $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";
127 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000128 if($language_result === FALSE) {
kitloe3fea252010-01-25 02:13:49 +0000129 # we may have lost the database connection with our shell-outs
droyb3ff2742009-04-08 19:28:32 +0000130 # bug 271685
131 $dbh = $dbc->connect();
droy68864612009-04-14 15:44:05 +0000132 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000133 }
kitlo9c7c62a2008-10-05 16:05:19 +0000134 while (($language_row = mysql_fetch_assoc($language_result)) != null) {
droy0b08d292008-05-28 15:18:11 +0000135 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000136 $language_iso = $language_row['iso_code'];
kitlo58d8a5a2008-09-24 20:08:44 +0000137 $language_id = $language_row['language_id'];
138 if (strcmp($language_iso, "en") == 0) {
kitlo58d8a5a2008-09-24 20:08:44 +0000139 $language_name = "Pseudo Translations";
kitloe3fea252010-01-25 02:13:49 +0000140 $language_iso = "en_AA";
kitlo58d8a5a2008-09-24 20:08:44 +0000141 }
kitlo9c7c62a2008-10-05 16:05:19 +0000142
kitlo58d8a5a2008-09-24 20:08:44 +0000143 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
144
gobrien1a8e02f2008-01-30 01:46:26 +0000145 /*
droy0b08d292008-05-28 15:18:11 +0000146 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000147 */
kitlo58d8a5a2008-09-24 20:08:44 +0000148 if (strcmp($language_iso, "en_AA") == 0) {
149 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
150 FROM files AS f
151 INNER JOIN strings AS s ON f.file_id = s.file_id
152 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
153 WHERE f.is_active
kitlo78f97432009-03-17 22:28:58 +0000154 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000155 } else {
156 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
157 FROM files AS f
158 INNER JOIN strings AS s ON f.file_id = s.file_id
159 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
160 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
161 WHERE t.language_id = " . $language_id . "
162 AND f.is_active
kitlo78f97432009-03-17 22:28:58 +0000163 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000164 }
165
droy0b08d292008-05-28 15:18:11 +0000166 $plugins = array();
kitlo9c7c62a2008-10-05 16:05:19 +0000167 $projects = array();
168 $project_versions = array();
169 $pseudo_translations_indexes = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000170 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
171 # save original filename
172 $file_row['origname'] = $file_row['name'];
173
droy02c430a2008-06-02 19:42:08 +0000174 # strip useless CVS structure before the plugin name (bug 221675 c14):
175 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
176 $replace = '${2}.${3}${4}.properties';
177 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000178
droy02c430a2008-06-02 19:42:08 +0000179 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
kitlo8d7c0532009-03-14 23:57:49 +0000180 /*
181 $pattern =
182 '/^
183 ([a-zA-Z0-9_-]+)\. # \1 org.
184 ([a-zA-Z0-9_-]+)\. # \2 eclipse.
185 ([a-zA-Z0-9\._-]+) # \3 datatools.connectivity
186 (.*)\/ # \4 \/plugins\/
187 (\1) # \5 org
188 ([\.\/]) # \6 .
189 (\2) # \7 eclipse
190 ([\.\/]) # \8 .
191 (.*) # \9 datatools.connectivity.ui\/plugin
192 \.properties # .properties
193 $/ix
194 ';
droy02c430a2008-06-02 19:42:08 +0000195 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
kitlo8d7c0532009-03-14 23:57:49 +0000196 */
197
198 # fix output folder (bug 261584)
199 $pattern =
200 '/^
201 (.*\/)? # \1 optional outer directories
202 ([a-z]+) # \2 org|com|etc
203 [.] # dot
204 ([^\/]+) # \3 plugin id except org.|com.
205 \/ # slash
206 (.*?\/)? # \4 optional src\/, src\/main\/ etc
207 # \5 resource path (pathname inside resulting jar)
208 # (a) within a org|com directory, or
209 # (b) in plugin root dir.
210 (\2\/.*[.]properties| # org|com\/anything.properties
211 [^\/]+[.]properties) # eg plugin.properties
212 $/ix';
213 $replace = '$2.$3/$5';
214
droy0b08d292008-05-28 15:18:11 +0000215 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000216
217 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000218 $file_row['subname'] = $matches[2];
219 $plugins[$matches[1]][] = $file_row;
220 } else {
221 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000222 }
droy0b08d292008-05-28 15:18:11 +0000223 }
kitlo58d8a5a2008-09-24 20:08:44 +0000224
droy0b08d292008-05-28 15:18:11 +0000225 /*
226 * Generate one plug-in fragment for each plug-in
227 */
kitlo58d8a5a2008-09-24 20:08:44 +0000228 foreach ($plugins as $plugin_name => $plugin_row) {
229 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000230 /*
droy0b08d292008-05-28 15:18:11 +0000231 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000232 */
kitlo58d8a5a2008-09-24 20:08:44 +0000233 if (file_exists($tmp_dir)) {
234 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000235 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000236 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000237 }
gobrien1a8e02f2008-01-30 01:46:26 +0000238 /*
droy0b08d292008-05-28 15:18:11 +0000239 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000240 */
droy0b08d292008-05-28 15:18:11 +0000241 foreach ($plugin_row as $properties_file) {
242 /*
243 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
244 */
245 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000246 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000247 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000248 }
kitlo58d8a5a2008-09-24 20:08:44 +0000249 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000250 /*
251 * Create any needed sub-directories
252 */
kitlo58d8a5a2008-09-24 20:08:44 +0000253 $fullpath = $tmp_dir . $filename;
254 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
255 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000256 /*
257 * Start writing to the file
258 */
kitlo58d8a5a2008-09-24 20:08:44 +0000259 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000260 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000261 if (strcmp($language_iso, "en_AA") == 0) {
262 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
263 " AND is_active AND non_translatable = 0";
264 $strings_result = mysql_query($sql);
265 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000266 /* Check for value starting with form tag (bug 270456) */
267 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
268 $pattern = "/^(<form>)(.*)/i";
269 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
270 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
271 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
272 } else {
273 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
274 ":" . $strings_row['value'];
275 }
276 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000277
278 $value = htmlspecialchars($strings_row['value']);
279 if (strlen($value) > 100) {
280 $value = substr($value, 0, 100) . " ...";
281 }
kitlo9c7c62a2008-10-05 16:05:19 +0000282 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
283 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
284 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
285 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000286 }
287 } else {
288 $sql = "SELECT
289 strings.name AS 'key',
290 strings.value AS orig,
291 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000292 FROM strings, translations
293 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000294 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000295 AND strings.is_active
296 AND strings.non_translatable = 0
297 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000298 AND translations.is_active";
299 $strings_result = mysql_query($sql);
300 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000301 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000302 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000303 if ($strings_row['trans']) {
304 # json_encode returns the string with quotes fore and aft. Need to strip them.
305 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
306 # $tr_string = str_replace('\\\\', '\\', $tr_string);
307 $tr_string = toescapedunicode($strings_row['trans']);
308 fwrite($outp, $tr_string);
309 # echo $strings_row['trans'];
310 } else {
311 fwrite($outp, $strings_row['orig']);
312 }
droy0b08d292008-05-28 15:18:11 +0000313 }
droy0b08d292008-05-28 15:18:11 +0000314 }
315 /*
316 * Finish the properties file
317 */
kitlo58d8a5a2008-09-24 20:08:44 +0000318 fclose($outp);
319 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000320 }
321 /*
droy0b08d292008-05-28 15:18:11 +0000322 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000323 */
kitlo9c7c62a2008-10-05 16:05:19 +0000324 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000325 /*
326 * Generate the META-INF/MANIFEST.MF file
327 */
328 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000329 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000330 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000331 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000332
droy0b08d292008-05-28 15:18:11 +0000333 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000334 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000335
336 exec("mkdir $tmp_dir/META-INF" );
337 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
338 fwrite($outp, "Manifest-Version: 1.0\n");
339 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
340 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000341 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
342 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000343 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
344 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000345 /*
346 * Jar up this directory as the fragment plug-in jar
347 */
kitlo58d8a5a2008-09-24 20:08:44 +0000348 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
349 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000350
kitlo9c7c62a2008-10-05 16:05:19 +0000351 $projects[$project_id][] = $fragment_id;
352 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000353 }
kitlo78f97432009-03-17 22:28:58 +0000354 if (sizeof($projects) > 0) {
355 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
356 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
357 $site_xml .= "\n\t</category-def>";
358
kitloe3fea252010-01-25 02:13:49 +0000359 fwrite($language_pack_links_file, "\n\t\t<a href='#$language_iso'>$language_name</a>");
360 if (strcmp($language_iso, "en_AA") != 0) {
361 fwrite($language_pack_links_file, ",");
362 }
363 $language_pack_links_file_buffer .= "\n\t\t<h4>Language: <a name='$language_iso'>$language_name</a></h4>";
364 $language_pack_links_file_buffer .= "\n\t\t<ul>";
kitlo78f97432009-03-17 22:28:58 +0000365 }
kitlo9c7c62a2008-10-05 16:05:19 +0000366 foreach ($projects as $project_id => $fragment_ids) {
367 /*
368 * Sort fragment names
369 */
370 asort($fragment_ids);
371 /*
372 * Create ${babel_language_packs_dir}tmp
373 */
374 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
375 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
376 /*
377 * Clean and create the temporary directory
378 */
379 if (file_exists($tmp_dir)) {
380 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
381 } else {
382 exec("mkdir $tmp_dir");
383 }
384 /*
385 * Create the feature.xml
386 *
387 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
388 *
389 * <url>
390 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
391 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
392 * </url>
393 */
kitlo5c9da712008-10-27 12:45:40 +0000394 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000395 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
396
397 $project_version = $project_versions[$project_id];
398 $sql = "SELECT pct_complete
399 FROM project_progress
400 WHERE project_id = \"$project_id\"
401 AND version = \"$project_version\"
402 AND language_id = $language_id";
403 $project_pct_complete_result = mysql_query($sql);
404 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
405 if (strcmp($language_iso, "en_AA") == 0) {
406 $project_pct_complete = 100;
407 }
408
409 $outp = fopen("$tmp_dir/feature.xml", "w");
410 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
411 "\n<feature" .
412 "\n\tid=\"$feature_id\"" .
413 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
414 "\n\timage=\"eclipse_update_120.jpg\"" .
415 "\n\tprovider-name=\"%providerName\"" .
416 "\n\tversion=\"$train_version_timestamp\">" .
417 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
418 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
419 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
420 foreach ($fragment_ids as $fragment_id) {
421 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
422 $size = filesize($jar_name);
423 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
424 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
425 /*
426 * Copy the plugin to ${babel_language_packs_dir}tmp
427 */
428 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
429 }
430 fwrite($outp, "\n</feature>");
431 fclose($outp);
432 /*
433 * Copy in the various legal files
434 */
435 exec("cp ${source_files_dir}about.html $tmp_dir");
436 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
437 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
438 exec("cp ${source_files_dir}feature.properties $tmp_dir");
439 exec("cp ${source_files_dir}license.html $tmp_dir");
440 /*
441 * Copy in the Babel Pseudo Translations Index file
442 */
443 if (strcmp($language_iso, "en_AA") == 0) {
444 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
445 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
446 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
447 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
448 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
449 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
450 foreach ($pseudo_translations_indexes[$project_id] as $index) {
451 fwrite($pseudo_translations_index_file, $index);
452 }
droy03d5c462008-11-10 21:07:01 +0000453 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000454 fclose($pseudo_translations_index_file);
455 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
456 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
457 }
458 /*
459 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
460 */
kitloc42941d2008-11-20 15:33:00 +0000461 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
462 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000463 /*
464 * Zip up language pack
465 */
466 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
467 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
468 /*
469 * Clean up ${babel_language_packs_dir}tmp
470 */
471 exec("rm -rf ${babel_language_packs_dir}tmp");
472 /*
473 * Add project language pack link to language pack links file
474 */
kitloe3fea252010-01-25 02:13:49 +0000475 $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 +0000476 /*
477 * Jar up this directory as the feature jar
478 */
479 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
480 /*
481 * Register this feature with the site.xml
482 */
kitloc42941d2008-11-20 15:33:00 +0000483 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000484 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
485 $site_xml .= "\n\t</feature>";
droy58951f72009-05-13 18:12:20 +0000486
kitlo78f97432009-03-17 22:28:58 +0000487
droy58951f72009-05-13 18:12:20 +0000488 } /* End: foreach project */
489 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitloe3fea252010-01-25 02:13:49 +0000490 if (sizeof($projects) > 0) {
491 $language_pack_links_file_buffer .= "\n\t\t</ul>";
492 }
gobrien1a8e02f2008-01-30 01:46:26 +0000493 }
gobrien1a8e02f2008-01-30 01:46:26 +0000494 /*
droy0b08d292008-05-28 15:18:11 +0000495 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000496 */
kitlo58d8a5a2008-09-24 20:08:44 +0000497 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000498 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
499 "\n<site>" .
500 "\n\t<description url=\"http://babel.eclipse.org/\">" .
501 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
502 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
503 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
504 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000505 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000506 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000507 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000508
kitloe3fea252010-01-25 02:13:49 +0000509 fwrite($language_pack_links_file, "\n\t</p>");
510 fwrite($language_pack_links_file, $language_pack_links_file_buffer);
atoulmedbda4272009-01-20 06:04:22 +0000511
droy3081da02009-05-11 15:54:56 +0000512 fwrite($language_pack_links_file, "\n</body>\n</html>");
513 fclose($language_pack_links_file);
514
515
516 $dbh = $dbc->disconnect();
kitlob2ca7c02010-02-10 19:05:41 +0000517
droye77ad172009-05-04 17:35:56 +0000518 /*
kitlob2ca7c02010-02-10 19:05:41 +0000519 * Generate the metadata and add the non-greedy tags
520 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
521 */
kitloe9468742010-02-10 20:08:49 +0000522 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlob2ca7c02010-02-10 19:05:41 +0000523 system("sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
524 system("xsltproc -o ${output_dir_for_train}content.xml ". dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
525 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml ; rm *.xml");
526 }
gobrien1a8e02f2008-01-30 01:46:26 +0000527}
gobrien1a8e02f2008-01-30 01:46:26 +0000528echo "Completed generating update site\n";
529
kitlo9c7c62a2008-10-05 16:05:19 +0000530
gobrien1a8e02f2008-01-30 01:46:26 +0000531/*
kitlo58d8a5a2008-09-24 20:08:44 +0000532 2. what happens if the translation feature includes plug-in fragments for
533 plug-ins that are not in the current image?
534 does it load correctly and ignore those fragments? if so, good
535 A: warnings appear in the run-time error log
536 does it fail to load? if so, then we need to generate different features, perhaps
537 one feature for each plug or else we need to know more about the project
538 distro structure to know which plug-ins to put in each feature
539 what happens if those plug-ins are later added - does it load the strings now?
540 A: probably not
541 3. need to handle different versions of each feature/plugin/platform; generate different
542 language packs for each
543 */
gobrien1a8e02f2008-01-30 01:46:26 +0000544
kitlo58d8a5a2008-09-24 20:08:44 +0000545$alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w");
546fwrite($alloutput,ob_get_contents());
droyc6eb7ac2009-05-12 17:25:46 +0000547
548function usage() {
549 echo "\n";
550 echo "generate1.php -b <build_id> [-t <train_id>]\n";
551 echo " -b <build_id>: The Build ID for this build.\n";
kitloe3fea252010-01-25 02:13:49 +0000552 echo " -t <train_id>: Optional: train to build (helios, galileo, ganymede, europa).";
droyc6eb7ac2009-05-12 17:25:46 +0000553 echo "\n";
554}
555
kitloe3fea252010-01-25 02:13:49 +0000556?>