blob: 4242a14e7ffbc0f209c79015a3008840ceb87500 [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
kitlo58d8a5a2008-09-24 20:08:44 +000025 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000026
27/*
kitlo58d8a5a2008-09-24 20:08:44 +000028 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000029 */
atoulme3fa5f5c2009-01-20 21:26:16 +000030define("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 +000031
droyaa172502009-05-06 20:50:07 +000032ini_set("memory_limit", "512M");
atoulme3ac52612009-02-02 13:14:39 +000033require(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme12882d52009-01-26 18:39:17 +000034require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy3081da02009-05-11 15:54:56 +000035
kitlo22479022010-01-25 03:22:33 +000036# Get all release trains
kitloe3fea252010-01-25 02:13:49 +000037$dbc = new DBConnection();
38$dbh = $dbc->connect();
39$result = mysql_query("SELECT * FROM release_trains ORDER BY train_version DESC");
40$train_result = array();
41while ($train_row = mysql_fetch_assoc($result)) {
42 $train_result[$train_row['train_id']] = $train_row['train_version'];
43}
droy3081da02009-05-11 15:54:56 +000044
45# Command-line parameter for the release train
46# bug 272958
droyc6eb7ac2009-05-12 17:25:46 +000047# b: build id
48# t: (optional: train id)
49
50$options = getopt("b:t:");
droy3081da02009-05-11 15:54:56 +000051$argv_train = "";
droyc6eb7ac2009-05-12 17:25:46 +000052if(isset($options['t'])) {
53 $argv_train = $options['t'];
droy3081da02009-05-11 15:54:56 +000054 if(array_key_exists($argv_train, $train_result)) {
55 # Picked a valid train .. remove all others
56 foreach ($train_result as $train_id => $train_version) {
57 if($train_id != $argv_train) {
58 unset($train_result[$train_id]);
59 }
60 }
61 }
62}
63
kitlob1920882010-05-12 23:33:18 +000064$build_id = "";
droyc6eb7ac2009-05-12 17:25:46 +000065if(!isset($options['b'])) {
66 usage();
67 exit();
68}
69else {
kitlob1920882010-05-12 23:33:18 +000070 $build_id = $options['b'];
droyc6eb7ac2009-05-12 17:25:46 +000071}
72
kitlob1920882010-05-12 23:33:18 +000073$release_id = "0.8.0";
74
atoulme3ac52612009-02-02 13:14:39 +000075$work_dir = $addon->callHook('babel_working');
atoulme12882d52009-01-26 18:39:17 +000076
atoulme3ac52612009-02-02 13:14:39 +000077global $addon;
78$context = $addon->callHook('context');
gobrienb854dcb2008-01-30 18:50:45 +000079
kitlo9c7c62a2008-10-05 16:05:19 +000080$work_context_dir = $work_dir . $context . "/";
81$tmp_dir = $work_context_dir . "tmp/";
82$babel_language_packs_dir = $work_context_dir . "babel_language_packs/";
83$output_dir = $work_context_dir . "output/";
atoulme3ac52612009-02-02 13:14:39 +000084$source_files_dir = dirname(__FILE__) . "/source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000085
gobrien1a8e02f2008-01-30 01:46:26 +000086$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000087$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000088
kitlo95107b72010-07-29 05:18:34 +000089$rm_command = "rm -rf $tmp_dir; rm -rf $babel_language_packs_dir; rm -rf $output_dir";
droyd157aac2008-10-07 21:14:33 +000090exec($rm_command);
droy082976e2008-10-07 21:02:23 +000091exec("mkdir -p $output_dir");
92
droy3081da02009-05-11 15:54:56 +000093echo "Requested builds: ";
kitlo78f97432009-03-17 22:28:58 +000094foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000095 echo $train_id . " ";
96}
97echo "\n";
kitlo78f97432009-03-17 22:28:58 +000098
droy3081da02009-05-11 15:54:56 +000099# Loop through the trains
100foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +0000101 echo "Generating update site for: $train_id\n";
droy3081da02009-05-11 15:54:56 +0000102
103 /*
104 * Create language pack links file
105 */
106 exec("mkdir -p $babel_language_packs_dir");
107 $language_pack_links_file = fopen("${babel_language_packs_dir}${train_id}.php", "w");
droyc6eb7ac2009-05-12 17:25:46 +0000108 fwrite($language_pack_links_file, "<?php\n");
droy260639a2009-05-28 20:02:21 +0000109 # Uncomment if each train is in its own directory: fwrite($language_pack_links_file, "\$language_pack_leader = \"${train_id}\";\n");
110 fwrite($language_pack_links_file, "\$language_pack_leader = \".\";\n");
droy58951f72009-05-13 18:12:20 +0000111 fwrite($language_pack_links_file, "?>\n");
droyc6eb7ac2009-05-12 17:25:46 +0000112 # copy page_header.html here
113 $header = file_get_contents("${source_files_dir}page_header.html");
114 fwrite($language_pack_links_file, $header);
kitloe3fea252010-01-25 02:13:49 +0000115 fwrite($language_pack_links_file, "\n\t<h1>Babel Language Packs for " . ucfirst($train_id) . "</h1>" .
kitlob1920882010-05-12 23:33:18 +0000116 "\n\t<h2>Build ID: $build_id</h2>" .
droy3081da02009-05-11 15:54:56 +0000117 "\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 +0000118 "\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>" .
119 "\n\t<p>Go to: ");
120
kitlo9c7c62a2008-10-05 16:05:19 +0000121 $train_version_timestamp = "$train_version.v$timestamp";
kitloe3fea252010-01-25 02:13:49 +0000122 $language_pack_links_file_buffer = "";
kitlo9c7c62a2008-10-05 16:05:19 +0000123 $site_xml = "";
kitlo58d8a5a2008-09-24 20:08:44 +0000124
kitlo78f97432009-03-17 22:28:58 +0000125 $output_dir_for_train = $output_dir . $train_id . "/";
kitlo58d8a5a2008-09-24 20:08:44 +0000126 exec("mkdir $output_dir_for_train");
127 exec("mkdir ${output_dir_for_train}features/");
128 exec("mkdir ${output_dir_for_train}plugins/");
129
droy68864612009-04-14 15:44:05 +0000130 $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";
131 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000132 if($language_result === FALSE) {
kitloe3fea252010-01-25 02:13:49 +0000133 # we may have lost the database connection with our shell-outs
droyb3ff2742009-04-08 19:28:32 +0000134 # bug 271685
135 $dbh = $dbc->connect();
droy68864612009-04-14 15:44:05 +0000136 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000137 }
kitlo9c7c62a2008-10-05 16:05:19 +0000138 while (($language_row = mysql_fetch_assoc($language_result)) != null) {
droy0b08d292008-05-28 15:18:11 +0000139 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000140 $language_iso = $language_row['iso_code'];
kitlo58d8a5a2008-09-24 20:08:44 +0000141 $language_id = $language_row['language_id'];
142 if (strcmp($language_iso, "en") == 0) {
kitlo58d8a5a2008-09-24 20:08:44 +0000143 $language_name = "Pseudo Translations";
kitloe3fea252010-01-25 02:13:49 +0000144 $language_iso = "en_AA";
kitlo58d8a5a2008-09-24 20:08:44 +0000145 }
kitlo9c7c62a2008-10-05 16:05:19 +0000146
kitlo58d8a5a2008-09-24 20:08:44 +0000147 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
148
gobrien1a8e02f2008-01-30 01:46:26 +0000149 /*
droy0b08d292008-05-28 15:18:11 +0000150 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000151 */
kitlo58d8a5a2008-09-24 20:08:44 +0000152 if (strcmp($language_iso, "en_AA") == 0) {
153 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
154 FROM files AS f
155 INNER JOIN strings AS s ON f.file_id = s.file_id
156 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
157 WHERE f.is_active
kitlo78f97432009-03-17 22:28:58 +0000158 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000159 } else {
160 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
161 FROM files AS f
162 INNER JOIN strings AS s ON f.file_id = s.file_id
163 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
164 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
165 WHERE t.language_id = " . $language_id . "
166 AND f.is_active
kitlo78f97432009-03-17 22:28:58 +0000167 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000168 }
169
droy0b08d292008-05-28 15:18:11 +0000170 $plugins = array();
kitlo9c7c62a2008-10-05 16:05:19 +0000171 $projects = array();
172 $project_versions = array();
173 $pseudo_translations_indexes = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000174 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
175 # save original filename
176 $file_row['origname'] = $file_row['name'];
177
droy02c430a2008-06-02 19:42:08 +0000178 # strip useless CVS structure before the plugin name (bug 221675 c14):
179 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
180 $replace = '${2}.${3}${4}.properties';
181 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000182
droy02c430a2008-06-02 19:42:08 +0000183 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
kitlo8d7c0532009-03-14 23:57:49 +0000184 /*
185 $pattern =
186 '/^
187 ([a-zA-Z0-9_-]+)\. # \1 org.
188 ([a-zA-Z0-9_-]+)\. # \2 eclipse.
189 ([a-zA-Z0-9\._-]+) # \3 datatools.connectivity
190 (.*)\/ # \4 \/plugins\/
191 (\1) # \5 org
192 ([\.\/]) # \6 .
193 (\2) # \7 eclipse
194 ([\.\/]) # \8 .
195 (.*) # \9 datatools.connectivity.ui\/plugin
196 \.properties # .properties
197 $/ix
198 ';
droy02c430a2008-06-02 19:42:08 +0000199 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
kitlo8d7c0532009-03-14 23:57:49 +0000200 */
201
202 # fix output folder (bug 261584)
203 $pattern =
204 '/^
205 (.*\/)? # \1 optional outer directories
206 ([a-z]+) # \2 org|com|etc
207 [.] # dot
208 ([^\/]+) # \3 plugin id except org.|com.
209 \/ # slash
210 (.*?\/)? # \4 optional src\/, src\/main\/ etc
211 # \5 resource path (pathname inside resulting jar)
212 # (a) within a org|com directory, or
213 # (b) in plugin root dir.
214 (\2\/.*[.]properties| # org|com\/anything.properties
215 [^\/]+[.]properties) # eg plugin.properties
216 $/ix';
217 $replace = '$2.$3/$5';
218
droy0b08d292008-05-28 15:18:11 +0000219 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000220
221 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000222 $file_row['subname'] = $matches[2];
223 $plugins[$matches[1]][] = $file_row;
224 } else {
225 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000226 }
droy0b08d292008-05-28 15:18:11 +0000227 }
kitlo58d8a5a2008-09-24 20:08:44 +0000228
droy0b08d292008-05-28 15:18:11 +0000229 /*
230 * Generate one plug-in fragment for each plug-in
231 */
kitlobd84b752010-05-14 13:29:01 +0000232 ksort($plugins);
kitlo58d8a5a2008-09-24 20:08:44 +0000233 foreach ($plugins as $plugin_name => $plugin_row) {
234 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000235 /*
droy0b08d292008-05-28 15:18:11 +0000236 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000237 */
kitlo58d8a5a2008-09-24 20:08:44 +0000238 if (file_exists($tmp_dir)) {
239 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000240 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000241 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000242 }
gobrien1a8e02f2008-01-30 01:46:26 +0000243 /*
droy0b08d292008-05-28 15:18:11 +0000244 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000245 */
droy0b08d292008-05-28 15:18:11 +0000246 foreach ($plugin_row as $properties_file) {
247 /*
248 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
249 */
250 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000251 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000252 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000253 }
kitlo58d8a5a2008-09-24 20:08:44 +0000254 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000255 /*
256 * Create any needed sub-directories
257 */
kitlo58d8a5a2008-09-24 20:08:44 +0000258 $fullpath = $tmp_dir . $filename;
259 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
260 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000261 /*
262 * Start writing to the file
263 */
kitlo58d8a5a2008-09-24 20:08:44 +0000264 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000265 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000266 if (strcmp($language_iso, "en_AA") == 0) {
267 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
268 " AND is_active AND non_translatable = 0";
269 $strings_result = mysql_query($sql);
270 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000271 /* Check for value starting with form tag (bug 270456) */
272 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
273 $pattern = "/^(<form>)(.*)/i";
274 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
275 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
276 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
277 } else {
278 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
279 ":" . $strings_row['value'];
280 }
281 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000282
283 $value = htmlspecialchars($strings_row['value']);
284 if (strlen($value) > 100) {
285 $value = substr($value, 0, 100) . " ...";
286 }
kitlo9c7c62a2008-10-05 16:05:19 +0000287 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
288 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
289 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
290 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000291 }
292 } else {
293 $sql = "SELECT
294 strings.name AS 'key',
295 strings.value AS orig,
296 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000297 FROM strings, translations
298 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000299 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000300 AND strings.is_active
301 AND strings.non_translatable = 0
302 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000303 AND translations.is_active";
304 $strings_result = mysql_query($sql);
305 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000306 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000307 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000308 if ($strings_row['trans']) {
309 # json_encode returns the string with quotes fore and aft. Need to strip them.
310 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
311 # $tr_string = str_replace('\\\\', '\\', $tr_string);
312 $tr_string = toescapedunicode($strings_row['trans']);
313 fwrite($outp, $tr_string);
314 # echo $strings_row['trans'];
315 } else {
316 fwrite($outp, $strings_row['orig']);
317 }
droy0b08d292008-05-28 15:18:11 +0000318 }
droy0b08d292008-05-28 15:18:11 +0000319 }
320 /*
321 * Finish the properties file
322 */
kitlo58d8a5a2008-09-24 20:08:44 +0000323 fclose($outp);
324 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000325 }
326 /*
droy0b08d292008-05-28 15:18:11 +0000327 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000328 */
kitlo9c7c62a2008-10-05 16:05:19 +0000329 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000330 /*
331 * Generate the META-INF/MANIFEST.MF file
332 */
333 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000334 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000335 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000336 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000337
droy0b08d292008-05-28 15:18:11 +0000338 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000339 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000340
341 exec("mkdir $tmp_dir/META-INF" );
342 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
343 fwrite($outp, "Manifest-Version: 1.0\n");
344 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
345 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000346 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
347 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000348 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
349 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000350 /*
351 * Jar up this directory as the fragment plug-in jar
352 */
kitlo58d8a5a2008-09-24 20:08:44 +0000353 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
354 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000355
kitlo9c7c62a2008-10-05 16:05:19 +0000356 $projects[$project_id][] = $fragment_id;
357 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000358 }
kitlo78f97432009-03-17 22:28:58 +0000359 if (sizeof($projects) > 0) {
360 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
361 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
362 $site_xml .= "\n\t</category-def>";
363
kitloe3fea252010-01-25 02:13:49 +0000364 fwrite($language_pack_links_file, "\n\t\t<a href='#$language_iso'>$language_name</a>");
365 if (strcmp($language_iso, "en_AA") != 0) {
366 fwrite($language_pack_links_file, ",");
367 }
kitlob1920882010-05-12 23:33:18 +0000368 $language_pack_links_file_buffer .= "\n\t<h4>Language: <a name='$language_iso'>$language_name</a></h4>";
369 $language_pack_links_file_buffer .= "\n\t<ul>";
kitlo78f97432009-03-17 22:28:58 +0000370 }
kitlobd84b752010-05-14 13:29:01 +0000371 ksort($projects);
kitlo9c7c62a2008-10-05 16:05:19 +0000372 foreach ($projects as $project_id => $fragment_ids) {
373 /*
374 * Sort fragment names
375 */
376 asort($fragment_ids);
377 /*
378 * Create ${babel_language_packs_dir}tmp
379 */
380 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
381 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
382 /*
383 * Clean and create the temporary directory
384 */
385 if (file_exists($tmp_dir)) {
386 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
387 } else {
388 exec("mkdir $tmp_dir");
389 }
390 /*
391 * Create the feature.xml
392 *
393 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
394 *
395 * <url>
396 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
397 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
398 * </url>
399 */
kitlo5c9da712008-10-27 12:45:40 +0000400 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000401 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
402
kitlo9c7c62a2008-10-05 16:05:19 +0000403 if (strcmp($language_iso, "en_AA") == 0) {
404 $project_pct_complete = 100;
kitlo95107b72010-07-29 05:18:34 +0000405 } else {
406 $project_version = $project_versions[$project_id];
407 $sql = "SELECT pct_complete
408 FROM project_progress
409 WHERE project_id = \"$project_id\"
410 AND version = \"$project_version\"
411 AND language_id = $language_id";
412 $project_pct_complete_result = mysql_query($sql);
413 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
kitlo9c7c62a2008-10-05 16:05:19 +0000414 }
415
416 $outp = fopen("$tmp_dir/feature.xml", "w");
417 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
418 "\n<feature" .
419 "\n\tid=\"$feature_id\"" .
420 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
421 "\n\timage=\"eclipse_update_120.jpg\"" .
422 "\n\tprovider-name=\"%providerName\"" .
423 "\n\tversion=\"$train_version_timestamp\">" .
424 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
425 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
426 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
427 foreach ($fragment_ids as $fragment_id) {
428 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
429 $size = filesize($jar_name);
430 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
431 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
432 /*
433 * Copy the plugin to ${babel_language_packs_dir}tmp
434 */
435 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
436 }
437 fwrite($outp, "\n</feature>");
438 fclose($outp);
439 /*
440 * Copy in the various legal files
441 */
442 exec("cp ${source_files_dir}about.html $tmp_dir");
443 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
444 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
445 exec("cp ${source_files_dir}feature.properties $tmp_dir");
446 exec("cp ${source_files_dir}license.html $tmp_dir");
447 /*
448 * Copy in the Babel Pseudo Translations Index file
449 */
450 if (strcmp($language_iso, "en_AA") == 0) {
451 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
452 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
453 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
454 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
455 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
456 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
457 foreach ($pseudo_translations_indexes[$project_id] as $index) {
458 fwrite($pseudo_translations_index_file, $index);
459 }
droy03d5c462008-11-10 21:07:01 +0000460 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000461 fclose($pseudo_translations_index_file);
462 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
463 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
464 }
465 /*
466 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
467 */
kitloc42941d2008-11-20 15:33:00 +0000468 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
469 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000470 /*
471 * Zip up language pack
472 */
473 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
474 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
475 /*
476 * Clean up ${babel_language_packs_dir}tmp
477 */
478 exec("rm -rf ${babel_language_packs_dir}tmp");
479 /*
480 * Add project language pack link to language pack links file
481 */
kitlob1920882010-05-12 23:33:18 +0000482 $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 +0000483 /*
484 * Jar up this directory as the feature jar
485 */
486 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
487 /*
488 * Register this feature with the site.xml
489 */
kitloc42941d2008-11-20 15:33:00 +0000490 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000491 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
492 $site_xml .= "\n\t</feature>";
droy58951f72009-05-13 18:12:20 +0000493
kitlo78f97432009-03-17 22:28:58 +0000494
droy58951f72009-05-13 18:12:20 +0000495 } /* End: foreach project */
496 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitloe3fea252010-01-25 02:13:49 +0000497 if (sizeof($projects) > 0) {
kitlob1920882010-05-12 23:33:18 +0000498 $language_pack_links_file_buffer .= "\n\t</ul>";
kitloe3fea252010-01-25 02:13:49 +0000499 }
gobrien1a8e02f2008-01-30 01:46:26 +0000500 }
kitlob1920882010-05-12 23:33:18 +0000501
502 fwrite($language_pack_links_file, "\n\t</p>");
503 fwrite($language_pack_links_file, $language_pack_links_file_buffer);
504
505 fwrite($language_pack_links_file, "\n\t<br />\n</body>\n</html>");
506 fclose($language_pack_links_file);
507
508 $dbh = $dbc->disconnect();
509
gobrien1a8e02f2008-01-30 01:46:26 +0000510 /*
kitlob1920882010-05-12 23:33:18 +0000511 * Generate and save site.xml/content.jar/artifacts.jar with mirrorsURL
512 */
513 $outp = fopen("${output_dir_for_train}site.xml", "w");
514 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
515 "\n<site pack200=\"true\" digestURL=\"http://download.eclipse.org/technology/babel/update-site/R$release_id/$train_id\"" .
516 "\n\tmirrorsURL=\"http://www.eclipse.org/downloads/download.php?file=/technology/babel/update-site/R$release_id/$train_id/site.xml&amp;format=xml\">" .
517 "\n\t<description url=\"http://babel.eclipse.org/\">" .
518 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
519 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
520 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
521 "\n\t</description>");
522 fwrite($outp, $site_xml);
523 fwrite($outp, "\n</site>");
524 fclose($outp);
525
526 /*
527 * Generate the metadata and add the non-greedy tags
528 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
529 */
530 exec("mkdir ${output_dir_for_train}mirrors/");
531 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000532 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
533 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
534 echo "Processing XML\n";
kitlob1920882010-05-12 23:33:18 +0000535 system("xsltproc -o ${output_dir_for_train}content.xml ". dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
536 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
537 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
538 system("cd ${output_dir_for_train} ; mv content.jar mirrors/content.mirrors ; mv artifacts.jar mirrors/artifacts.mirrors");
539 }
540 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.mirrors");
541
542 /*
543 * Generate normal site.xml/content.jar/artifacts.jar without mirrorsURL
gobrien1a8e02f2008-01-30 01:46:26 +0000544 */
kitlo58d8a5a2008-09-24 20:08:44 +0000545 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000546 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
547 "\n<site>" .
548 "\n\t<description url=\"http://babel.eclipse.org/\">" .
549 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
550 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
551 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
552 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000553 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000554 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000555 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000556
droye77ad172009-05-04 17:35:56 +0000557 /*
kitlob2ca7c02010-02-10 19:05:41 +0000558 * Generate the metadata and add the non-greedy tags
559 * Note: Not needed for Europa and Ganymede because p2 repository was not supported
560 */
kitloe9468742010-02-10 20:08:49 +0000561 if (file_exists(METADATA_GENERATOR_LOCATION) && strcmp($train_id, "europa") != 0 && strcmp($train_id, "ganymede") != 0) {
kitlo95107b72010-07-29 05:18:34 +0000562 echo "Running the Meta at " . dirname(__FILE__) . "/runMetadata.sh\n";
563 system("/bin/sh " . dirname(__FILE__) . "/runMetadata.sh ". METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
564 echo "Processing XML\n";
kitlob2ca7c02010-02-10 19:05:41 +0000565 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 +0000566 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml");
567 system("cd ${output_dir_for_train} ; rm content.xml ; rm artifacts.xml");
568 system("cd ${output_dir_for_train} ; mv site.xml mirrors/site.txt");
569 } else {
570 system("cd ${output_dir_for_train} ; cp site.xml mirrors/site.txt");
kitlob2ca7c02010-02-10 19:05:41 +0000571 }
gobrien1a8e02f2008-01-30 01:46:26 +0000572}
gobrien1a8e02f2008-01-30 01:46:26 +0000573echo "Completed generating update site\n";
574
kitlo9c7c62a2008-10-05 16:05:19 +0000575
gobrien1a8e02f2008-01-30 01:46:26 +0000576/*
kitlo58d8a5a2008-09-24 20:08:44 +0000577 2. what happens if the translation feature includes plug-in fragments for
578 plug-ins that are not in the current image?
579 does it load correctly and ignore those fragments? if so, good
580 A: warnings appear in the run-time error log
581 does it fail to load? if so, then we need to generate different features, perhaps
582 one feature for each plug or else we need to know more about the project
583 distro structure to know which plug-ins to put in each feature
584 what happens if those plug-ins are later added - does it load the strings now?
585 A: probably not
586 3. need to handle different versions of each feature/plugin/platform; generate different
587 language packs for each
588 */
gobrien1a8e02f2008-01-30 01:46:26 +0000589
droyc6eb7ac2009-05-12 17:25:46 +0000590function usage() {
591 echo "\n";
592 echo "generate1.php -b <build_id> [-t <train_id>]\n";
593 echo " -b <build_id>: The Build ID for this build.\n";
kitloe3fea252010-01-25 02:13:49 +0000594 echo " -t <train_id>: Optional: train to build (helios, galileo, ganymede, europa).";
droyc6eb7ac2009-05-12 17:25:46 +0000595 echo "\n";
596}
597
kitloe3fea252010-01-25 02:13:49 +0000598?>