blob: 45d9ca9c392b868972a1c7c6e6ee3e04d8f9bf2a [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
kitlo58d8a5a2008-09-24 20:08:44 +000021 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000022
23/*
kitlo58d8a5a2008-09-24 20:08:44 +000024 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000025 */
atoulme3fa5f5c2009-01-20 21:26:16 +000026define("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 +000027
droyaa172502009-05-06 20:50:07 +000028ini_set("memory_limit", "512M");
atoulme3ac52612009-02-02 13:14:39 +000029require(dirname(__FILE__) . "/../system/backend_functions.php");
atoulme12882d52009-01-26 18:39:17 +000030require(dirname(__FILE__) . "/../system/dbconnection.class.php");
droy3081da02009-05-11 15:54:56 +000031
32# There is no easy way to sort "galileo", "ganymede", and "europa" in the correct order we want without
33# modifying the release_train_projects table.
34#
35# Here is a temporary fix to display train versions in most recent release order until we have a permanent solution.
36$train_result = array("galileo" => "3.5.0", "ganymede" => "3.4.0", "europa" => "3.3.0");
37
38# Command-line parameter for the release train
39# bug 272958
40$argv_train = "";
41if(isset($argv[1])) {
42 $argv_train = $argv[1];
43 if(array_key_exists($argv_train, $train_result)) {
44 # Picked a valid train .. remove all others
45 foreach ($train_result as $train_id => $train_version) {
46 if($train_id != $argv_train) {
47 unset($train_result[$train_id]);
48 }
49 }
50 }
51}
52
53
kitlo399df202008-09-30 15:32:25 +000054$dbc = new DBConnection();
droyb6e25c72008-07-18 13:01:13 +000055
atoulme3ac52612009-02-02 13:14:39 +000056$work_dir = $addon->callHook('babel_working');
atoulme12882d52009-01-26 18:39:17 +000057
atoulme3ac52612009-02-02 13:14:39 +000058global $addon;
59$context = $addon->callHook('context');
gobrienb854dcb2008-01-30 18:50:45 +000060
kitlo9c7c62a2008-10-05 16:05:19 +000061$work_context_dir = $work_dir . $context . "/";
62$tmp_dir = $work_context_dir . "tmp/";
63$babel_language_packs_dir = $work_context_dir . "babel_language_packs/";
64$output_dir = $work_context_dir . "output/";
atoulme3ac52612009-02-02 13:14:39 +000065$source_files_dir = dirname(__FILE__) . "/source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000066
gobrien1a8e02f2008-01-30 01:46:26 +000067$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000068$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000069
droyd157aac2008-10-07 21:14:33 +000070$rm_command = "rm -rf $work_dir" . "*";
71exec($rm_command);
droy082976e2008-10-07 21:02:23 +000072exec("mkdir -p $output_dir");
73
droy0b08d292008-05-28 15:18:11 +000074
droy3081da02009-05-11 15:54:56 +000075echo "Requested builds: ";
kitlo78f97432009-03-17 22:28:58 +000076foreach ($train_result as $train_id => $train_version) {
droy3081da02009-05-11 15:54:56 +000077 echo $train_id . " ";
78}
79echo "\n";
kitlo78f97432009-03-17 22:28:58 +000080
droy3081da02009-05-11 15:54:56 +000081# Loop through the trains
82foreach ($train_result as $train_id => $train_version) {
83
kitlo78f97432009-03-17 22:28:58 +000084#$train_result = mysql_query("SELECT DISTINCT train_id FROM release_train_projects ORDER BY train_id DESC");
85#while (($train_row = mysql_fetch_assoc($train_result)) != null) {
86# $train_id = $train_row['train_id'];
87# $train_version = "3.5.0";
88# if (strcmp($train_id, "ganymede") == 0) {
89# $train_version = "3.4.0";
90# }
91# if (strcmp($train_id, "europa") == 0) {
92# $train_version = "3.3.0";
93# }
94
droy3081da02009-05-11 15:54:56 +000095 echo "Generating update site for: $train_id\n";
96 $dbh = $dbc->connect();
97
98 /*
99 * Create language pack links file
100 */
101 exec("mkdir -p $babel_language_packs_dir");
102 $language_pack_links_file = fopen("${babel_language_packs_dir}${train_id}.php", "w");
103 fwrite($language_pack_links_file, "<?php\n\$pageTitle = \"Babel Language Packs for ${train_id}\";");
104 fwrite($language_pack_links_file, "\ninclude \$_SERVER['DOCUMENT_ROOT'] . '/eclipse.org-common/themes/Phoenix/header.php';");
105 fwrite($language_pack_links_file, "\n\$language_pack_leader = \"\";");
106 fwrite($language_pack_links_file, "\n?>");
107 fwrite($language_pack_links_file, "\n\t<div id='maincontent'>");
108 fwrite($language_pack_links_file, "\n\t<div id='midcolumn'>");
109 fwrite($language_pack_links_file, "\n\t<style>");
110 fwrite($language_pack_links_file, "\n\t\th3 {");
111 fwrite($language_pack_links_file, "\n\t\t\tbackground-color: SteelBlue;");
112 fwrite($language_pack_links_file, "\n\t\t\tcolor: white;");
113 fwrite($language_pack_links_file, "\n\t\t}");
114 fwrite($language_pack_links_file, "\n");
115 fwrite($language_pack_links_file, "\n\t\th4 {");
116 fwrite($language_pack_links_file, "\n\t\t\tbackground-color: LightSteelBlue;");
117 fwrite($language_pack_links_file, "\n\t\t}");
118 fwrite($language_pack_links_file, "\n\t</style>");
119 fwrite($language_pack_links_file, "\n\t<h1>Babel Language Packs for ${train_id}</h1>" .
120 "\n\t<h2>Build ID: $timestamp</h2>" .
121 "\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." .
122 "\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>");
123
124
kitlo9c7c62a2008-10-05 16:05:19 +0000125 $train_version_timestamp = "$train_version.v$timestamp";
126 $site_xml = "";
kitlo58d8a5a2008-09-24 20:08:44 +0000127
kitlo78f97432009-03-17 22:28:58 +0000128 $output_dir_for_train = $output_dir . $train_id . "/";
kitlo58d8a5a2008-09-24 20:08:44 +0000129 exec("mkdir $output_dir_for_train");
130 exec("mkdir ${output_dir_for_train}features/");
131 exec("mkdir ${output_dir_for_train}plugins/");
132
kitlo9c7c62a2008-10-05 16:05:19 +0000133 fwrite($language_pack_links_file, "\n\t<h3>Release Train: $train_id</h3>\n\t<ul>");
droy68864612009-04-14 15:44:05 +0000134
135 $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";
136 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000137 if($language_result === FALSE) {
138 # we may have lost the database connection.with our shell-outs
139 # bug 271685
140 $dbh = $dbc->connect();
droy68864612009-04-14 15:44:05 +0000141 $language_result = mysql_query($sql);
droyb3ff2742009-04-08 19:28:32 +0000142 }
kitlo9c7c62a2008-10-05 16:05:19 +0000143 while (($language_row = mysql_fetch_assoc($language_result)) != null) {
droy0b08d292008-05-28 15:18:11 +0000144 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +0000145 $language_iso = $language_row['iso_code'];
kitlo58d8a5a2008-09-24 20:08:44 +0000146 $language_id = $language_row['language_id'];
147 if (strcmp($language_iso, "en") == 0) {
148 $language_iso = "en_AA";
149 $language_name = "Pseudo Translations";
150 }
kitlo9c7c62a2008-10-05 16:05:19 +0000151
kitlo58d8a5a2008-09-24 20:08:44 +0000152 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
153
gobrien1a8e02f2008-01-30 01:46:26 +0000154 /*
droy0b08d292008-05-28 15:18:11 +0000155 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000156 */
kitlo58d8a5a2008-09-24 20:08:44 +0000157 if (strcmp($language_iso, "en_AA") == 0) {
158 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
159 FROM files AS f
160 INNER JOIN strings AS s ON f.file_id = s.file_id
161 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
162 WHERE f.is_active
kitlo78f97432009-03-17 22:28:58 +0000163 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000164 } else {
165 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
166 FROM files AS f
167 INNER JOIN strings AS s ON f.file_id = s.file_id
168 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
169 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
170 WHERE t.language_id = " . $language_id . "
171 AND f.is_active
kitlo78f97432009-03-17 22:28:58 +0000172 AND v.train_id = '" . $train_id . "'");
kitlo58d8a5a2008-09-24 20:08:44 +0000173 }
174
droy0b08d292008-05-28 15:18:11 +0000175 $plugins = array();
kitlo9c7c62a2008-10-05 16:05:19 +0000176 $projects = array();
177 $project_versions = array();
178 $pseudo_translations_indexes = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000179 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
180 # save original filename
181 $file_row['origname'] = $file_row['name'];
182
droy02c430a2008-06-02 19:42:08 +0000183 # strip useless CVS structure before the plugin name (bug 221675 c14):
184 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
185 $replace = '${2}.${3}${4}.properties';
186 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000187
droy02c430a2008-06-02 19:42:08 +0000188 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
kitlo8d7c0532009-03-14 23:57:49 +0000189 /*
190 $pattern =
191 '/^
192 ([a-zA-Z0-9_-]+)\. # \1 org.
193 ([a-zA-Z0-9_-]+)\. # \2 eclipse.
194 ([a-zA-Z0-9\._-]+) # \3 datatools.connectivity
195 (.*)\/ # \4 \/plugins\/
196 (\1) # \5 org
197 ([\.\/]) # \6 .
198 (\2) # \7 eclipse
199 ([\.\/]) # \8 .
200 (.*) # \9 datatools.connectivity.ui\/plugin
201 \.properties # .properties
202 $/ix
203 ';
droy02c430a2008-06-02 19:42:08 +0000204 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
kitlo8d7c0532009-03-14 23:57:49 +0000205 */
206
207 # fix output folder (bug 261584)
208 $pattern =
209 '/^
210 (.*\/)? # \1 optional outer directories
211 ([a-z]+) # \2 org|com|etc
212 [.] # dot
213 ([^\/]+) # \3 plugin id except org.|com.
214 \/ # slash
215 (.*?\/)? # \4 optional src\/, src\/main\/ etc
216 # \5 resource path (pathname inside resulting jar)
217 # (a) within a org|com directory, or
218 # (b) in plugin root dir.
219 (\2\/.*[.]properties| # org|com\/anything.properties
220 [^\/]+[.]properties) # eg plugin.properties
221 $/ix';
222 $replace = '$2.$3/$5';
223
droy0b08d292008-05-28 15:18:11 +0000224 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000225
226 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000227 $file_row['subname'] = $matches[2];
228 $plugins[$matches[1]][] = $file_row;
229 } else {
230 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000231 }
droy0b08d292008-05-28 15:18:11 +0000232 }
kitlo58d8a5a2008-09-24 20:08:44 +0000233
droy0b08d292008-05-28 15:18:11 +0000234 /*
235 * Generate one plug-in fragment for each plug-in
236 */
kitlo58d8a5a2008-09-24 20:08:44 +0000237 foreach ($plugins as $plugin_name => $plugin_row) {
238 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000239 /*
droy0b08d292008-05-28 15:18:11 +0000240 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000241 */
kitlo58d8a5a2008-09-24 20:08:44 +0000242 if (file_exists($tmp_dir)) {
243 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000244 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000245 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000246 }
gobrien1a8e02f2008-01-30 01:46:26 +0000247 /*
droy0b08d292008-05-28 15:18:11 +0000248 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000249 */
droy0b08d292008-05-28 15:18:11 +0000250 foreach ($plugin_row as $properties_file) {
251 /*
252 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
253 */
254 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000255 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000256 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000257 }
kitlo58d8a5a2008-09-24 20:08:44 +0000258 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000259 /*
260 * Create any needed sub-directories
261 */
kitlo58d8a5a2008-09-24 20:08:44 +0000262 $fullpath = $tmp_dir . $filename;
263 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
264 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000265 /*
266 * Start writing to the file
267 */
kitlo58d8a5a2008-09-24 20:08:44 +0000268 $outp = fopen($fullpath, "w");
kitloc42941d2008-11-20 15:33:00 +0000269 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/");
kitlo58d8a5a2008-09-24 20:08:44 +0000270 if (strcmp($language_iso, "en_AA") == 0) {
271 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
272 " AND is_active AND non_translatable = 0";
273 $strings_result = mysql_query($sql);
274 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlocc405032009-04-04 01:10:30 +0000275 /* Check for value starting with form tag (bug 270456) */
276 if (preg_match("/^(<form>)(.*)/i", $strings_row['value'], $matches)) {
277 $pattern = "/^(<form>)(.*)/i";
278 $replace = "$1" . "<p>" . $properties_file['project_id'] . $strings_row['string_id'] . ":" . "</p>" . "$2";
279 $strings_row['value'] = preg_replace($pattern, $replace, $strings_row['value']);
280 $outp_line = "\n" . $strings_row['name'] . "=" . $strings_row['value'];
281 } else {
282 $outp_line = "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] .
283 ":" . $strings_row['value'];
284 }
285 fwrite($outp, $outp_line);
kitlo58d8a5a2008-09-24 20:08:44 +0000286
287 $value = htmlspecialchars($strings_row['value']);
288 if (strlen($value) > 100) {
289 $value = substr($value, 0, 100) . " ...";
290 }
kitlo9c7c62a2008-10-05 16:05:19 +0000291 $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" .
292 $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" .
293 $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" .
294 $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>";
kitlo58d8a5a2008-09-24 20:08:44 +0000295 }
296 } else {
297 $sql = "SELECT
298 strings.name AS 'key',
299 strings.value AS orig,
300 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000301 FROM strings, translations
302 WHERE strings.string_id = translations.string_id
droy0b08d292008-05-28 15:18:11 +0000303 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo1173dbd2008-10-21 15:58:36 +0000304 AND strings.is_active
305 AND strings.non_translatable = 0
306 AND translations.language_id = " . $language_id . "
kitlo58d8a5a2008-09-24 20:08:44 +0000307 AND translations.is_active";
308 $strings_result = mysql_query($sql);
309 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
kitlo7f522672008-10-21 14:15:54 +0000310 fwrite($outp, "\n" . $strings_row['key'] . "=");
kitlo9c7c62a2008-10-05 16:05:19 +0000311 # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
kitlo58d8a5a2008-09-24 20:08:44 +0000312 if ($strings_row['trans']) {
313 # json_encode returns the string with quotes fore and aft. Need to strip them.
314 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
315 # $tr_string = str_replace('\\\\', '\\', $tr_string);
316 $tr_string = toescapedunicode($strings_row['trans']);
317 fwrite($outp, $tr_string);
318 # echo $strings_row['trans'];
319 } else {
320 fwrite($outp, $strings_row['orig']);
321 }
droy0b08d292008-05-28 15:18:11 +0000322 }
droy0b08d292008-05-28 15:18:11 +0000323 }
324 /*
325 * Finish the properties file
326 */
kitlo58d8a5a2008-09-24 20:08:44 +0000327 fclose($outp);
328 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000329 }
330 /*
droy0b08d292008-05-28 15:18:11 +0000331 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000332 */
kitlo9c7c62a2008-10-05 16:05:19 +0000333 exec("cp ${source_files_dir}about.html $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000334 /*
335 * Generate the META-INF/MANIFEST.MF file
336 */
337 $parent_plugin_id = $plugin_name;
kitlo9c7c62a2008-10-05 16:05:19 +0000338 $project_id = $properties_file['project_id'];
kitlo5c9da712008-10-27 12:45:40 +0000339 $fragment_id = "$parent_plugin_id.nl_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000340 $fragment_filename = "${fragment_id}_$train_version_timestamp.jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000341
droy0b08d292008-05-28 15:18:11 +0000342 $plugins[$plugin_name]['id'] = $fragment_id;
kitlo9c7c62a2008-10-05 16:05:19 +0000343 $plugins[$plugin_name]['version'] = $train_version_timestamp;
kitlo58d8a5a2008-09-24 20:08:44 +0000344
345 exec("mkdir $tmp_dir/META-INF" );
346 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
347 fwrite($outp, "Manifest-Version: 1.0\n");
348 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
349 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
kitlo9c7c62a2008-10-05 16:05:19 +0000350 fwrite($outp, "Bundle-Version: $train_version_timestamp\n");
351 fwrite($outp, "Bundle-Vendor: Eclipse.org\n");
kitlo58d8a5a2008-09-24 20:08:44 +0000352 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
353 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000354 /*
355 * Jar up this directory as the fragment plug-in jar
356 */
kitlo58d8a5a2008-09-24 20:08:44 +0000357 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
358 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
kitlo58d8a5a2008-09-24 20:08:44 +0000359
kitlo9c7c62a2008-10-05 16:05:19 +0000360 $projects[$project_id][] = $fragment_id;
361 $project_versions[$project_id] = $properties_file['version'];
droy0b08d292008-05-28 15:18:11 +0000362 }
kitlo78f97432009-03-17 22:28:58 +0000363 if (sizeof($projects) > 0) {
364 $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">";
365 $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>";
366 $site_xml .= "\n\t</category-def>";
367
368 fwrite($language_pack_links_file, "\n\t\t<h4>Language: $language_name</h4>");
369 }
kitlo9c7c62a2008-10-05 16:05:19 +0000370 foreach ($projects as $project_id => $fragment_ids) {
kitlo78f97432009-03-17 22:28:58 +0000371 fwrite($language_pack_links_file, "\n\t\t<ul>");
kitlo9c7c62a2008-10-05 16:05:19 +0000372 /*
373 * Sort fragment names
374 */
375 asort($fragment_ids);
376 /*
377 * Create ${babel_language_packs_dir}tmp
378 */
379 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features");
380 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins");
381 /*
382 * Clean and create the temporary directory
383 */
384 if (file_exists($tmp_dir)) {
385 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
386 } else {
387 exec("mkdir $tmp_dir");
388 }
389 /*
390 * Create the feature.xml
391 *
392 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
393 *
394 * <url>
395 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
396 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
397 * </url>
398 */
kitlo5c9da712008-10-27 12:45:40 +0000399 $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso";
kitlo9c7c62a2008-10-05 16:05:19 +0000400 $feature_filename = "${feature_id}_$train_version_timestamp.jar";
401
402 $project_version = $project_versions[$project_id];
403 $sql = "SELECT pct_complete
404 FROM project_progress
405 WHERE project_id = \"$project_id\"
406 AND version = \"$project_version\"
407 AND language_id = $language_id";
408 $project_pct_complete_result = mysql_query($sql);
409 $project_pct_complete = mysql_result($project_pct_complete_result, 0);
410 if (strcmp($language_iso, "en_AA") == 0) {
411 $project_pct_complete = 100;
412 }
413
414 $outp = fopen("$tmp_dir/feature.xml", "w");
415 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" .
416 "\n<feature" .
417 "\n\tid=\"$feature_id\"" .
418 "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" .
419 "\n\timage=\"eclipse_update_120.jpg\"" .
420 "\n\tprovider-name=\"%providerName\"" .
421 "\n\tversion=\"$train_version_timestamp\">" .
422 "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" .
423 "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" .
424 "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" );
425 foreach ($fragment_ids as $fragment_id) {
426 $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar";
427 $size = filesize($jar_name);
428 fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " .
429 "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />");
430 /*
431 * Copy the plugin to ${babel_language_packs_dir}tmp
432 */
433 exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins");
434 }
435 fwrite($outp, "\n</feature>");
436 fclose($outp);
437 /*
438 * Copy in the various legal files
439 */
440 exec("cp ${source_files_dir}about.html $tmp_dir");
441 exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir");
442 exec("cp ${source_files_dir}epl-v10.html $tmp_dir");
443 exec("cp ${source_files_dir}feature.properties $tmp_dir");
444 exec("cp ${source_files_dir}license.html $tmp_dir");
445 /*
446 * Copy in the Babel Pseudo Translations Index file
447 */
448 if (strcmp($language_iso, "en_AA") == 0) {
449 $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w");
450 fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" .
451 "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" .
452 "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" .
453 "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" .
454 "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>");
455 foreach ($pseudo_translations_indexes[$project_id] as $index) {
456 fwrite($pseudo_translations_index_file, $index);
457 }
droy03d5c462008-11-10 21:07:01 +0000458 fwrite($pseudo_translations_index_file, "\n\t</ul>\n</div></div></body>\n</html>");
kitlo9c7c62a2008-10-05 16:05:19 +0000459 fclose($pseudo_translations_index_file);
460 exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir");
461 exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html");
462 }
463 /*
464 * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up
465 */
kitloc42941d2008-11-20 15:33:00 +0000466 exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
467 exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${feature_id}_$train_version_timestamp");
kitlo9c7c62a2008-10-05 16:05:19 +0000468 /*
469 * Zip up language pack
470 */
471 $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip";
472 exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse");
473 /*
474 * Clean up ${babel_language_packs_dir}tmp
475 */
476 exec("rm -rf ${babel_language_packs_dir}tmp");
477 /*
478 * Add project language pack link to language pack links file
479 */
droy3081da02009-05-11 15:54:56 +0000480 fwrite($language_pack_links_file, "\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 +0000481 /*
482 * Jar up this directory as the feature jar
483 */
484 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
485 /*
486 * Register this feature with the site.xml
487 */
kitloc42941d2008-11-20 15:33:00 +0000488 $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$train_version_timestamp\">";
kitlo9c7c62a2008-10-05 16:05:19 +0000489 $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>";
490 $site_xml .= "\n\t</feature>";
491 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
kitlo78f97432009-03-17 22:28:58 +0000492
493 fwrite($language_pack_links_file, "\n\t\t</ul>");
kitlo58d8a5a2008-09-24 20:08:44 +0000494 }
gobrien1a8e02f2008-01-30 01:46:26 +0000495 }
gobrien1a8e02f2008-01-30 01:46:26 +0000496 /*
droy0b08d292008-05-28 15:18:11 +0000497 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000498 */
kitlo58d8a5a2008-09-24 20:08:44 +0000499 $outp = fopen("${output_dir_for_train}site.xml", "w");
kitlo9c7c62a2008-10-05 16:05:19 +0000500 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
501 "\n<site>" .
502 "\n\t<description url=\"http://babel.eclipse.org/\">" .
503 "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." .
504 "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" .
505 "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." .
506 "\n\t</description>");
kitlo58d8a5a2008-09-24 20:08:44 +0000507 fwrite($outp, $site_xml);
kitlo9c7c62a2008-10-05 16:05:19 +0000508 fwrite($outp, "\n</site>");
kitlo58d8a5a2008-09-24 20:08:44 +0000509 fclose($outp);
kitlo9c7c62a2008-10-05 16:05:19 +0000510
511 fwrite($language_pack_links_file, "\n\t</ul>");
atoulmedbda4272009-01-20 06:04:22 +0000512
droy3081da02009-05-11 15:54:56 +0000513 fwrite($language_pack_links_file, "\n</body>\n</html>");
514 fclose($language_pack_links_file);
515
516
517 $dbh = $dbc->disconnect();
518
atoulmedbda4272009-01-20 06:04:22 +0000519 // now generate the metadata and add the non-greedy tags
atoulme09ce4642009-01-21 07:46:06 +0000520
droye77ad172009-05-04 17:35:56 +0000521 /*
522 * Leaving this out of generate1 to avoid p2 breakage
523 *
atoulme12882d52009-01-26 18:39:17 +0000524 system("sh " . dirname(__FILE__) . "/runMetadata.sh ".
atoulme09ce4642009-01-21 07:46:06 +0000525 METADATA_GENERATOR_LOCATION . " ${output_dir_for_train} ");
atoulmec86be152009-01-21 22:36:31 +0000526 system("xsltproc -o ${output_dir_for_train}content.xml ".
atoulmeb0f0e502009-01-21 17:27:25 +0000527 dirname(__FILE__) . "/content.xsl ${output_dir_for_train}content.xml");
atoulmec8efccd2009-02-13 08:51:59 +0000528 system("cd ${output_dir_for_train} ; jar -fc content.jar content.xml ; jar -fc artifacts.jar artifacts.xml ; rm site.xml");
droye77ad172009-05-04 17:35:56 +0000529 */
gobrien1a8e02f2008-01-30 01:46:26 +0000530}
gobrien1a8e02f2008-01-30 01:46:26 +0000531echo "Completed generating update site\n";
532
kitlo9c7c62a2008-10-05 16:05:19 +0000533
gobrien1a8e02f2008-01-30 01:46:26 +0000534/*
kitlo58d8a5a2008-09-24 20:08:44 +0000535 2. what happens if the translation feature includes plug-in fragments for
536 plug-ins that are not in the current image?
537 does it load correctly and ignore those fragments? if so, good
538 A: warnings appear in the run-time error log
539 does it fail to load? if so, then we need to generate different features, perhaps
540 one feature for each plug or else we need to know more about the project
541 distro structure to know which plug-ins to put in each feature
542 what happens if those plug-ins are later added - does it load the strings now?
543 A: probably not
544 3. need to handle different versions of each feature/plugin/platform; generate different
545 language packs for each
546 */
gobrien1a8e02f2008-01-30 01:46:26 +0000547
kitlo58d8a5a2008-09-24 20:08:44 +0000548$alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w");
549fwrite($alloutput,ob_get_contents());
kitlo399df202008-09-30 15:32:25 +0000550?>