blob: 91ce6a43e51aba93a7eda48c551cd4b4380b8904 [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
gobrien1a8e02f2008-01-30 01:46:26 +000012*******************************************************************************/
13
14/*
15 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
16 */
17//TODO handle versions, however that works; files.version is like "3.4" for Eclipse 3.4
18
19/*
20 * Globals
21 */
gobrienb854dcb2008-01-30 18:50:45 +000022
droyb6e25c72008-07-18 13:01:13 +000023ob_start();
gobrienb854dcb2008-01-30 18:50:45 +000024
droyb6e25c72008-07-18 13:01:13 +000025# Set this according to your local setup
26$base_out_dir = "/home/babel-working/";
27
28if(!defined('BABEL_BASE_DIR')){
gobrienb854dcb2008-01-30 18:50:45 +000029 define('BABEL_BASE_DIR', "../../");
droy86f26212008-03-04 19:54:23 +000030}
droyb6e25c72008-07-18 13:01:13 +000031define('USE_PHOENIX', false);
32require(BABEL_BASE_DIR . "html/global.php");
33InitPage("");
34
droy86f26212008-03-04 19:54:23 +000035
gobrienb854dcb2008-01-30 18:50:45 +000036if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
37 errorLog("Failed to find/read database conf file - aborting.");
38 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
39}
40
41$context = $ini['context'];
42if($context == "") {
43 $context = "staging";
44}
droyb6e25c72008-07-18 13:01:13 +000045global $dbh;
gobrienb854dcb2008-01-30 18:50:45 +000046
47
gobrienb854dcb2008-01-30 18:50:45 +000048if(!file_exists($base_out_dir)){
49 $base_out_dir = "";
50}
51
52if($context == "live"){
53 $base_out_dir .= "live/";
54}else{
55 $base_out_dir .= "staging/";
56}
57if( !file_exists( $base_out_dir ) ) {
58 exec( "mkdir $base_out_dir" );
59}
60
61$temporary_dir = $base_out_dir."tmp_generated/";
gobrien431ca4f2008-01-30 19:54:00 +000062$staging_update_site = $base_out_dir."output/";
gobriene2bb07b2008-01-30 19:00:42 +000063$source_files_for_generate = "source_files_for_generate/";
gobrien1a8e02f2008-01-30 01:46:26 +000064
65$leader1 = "";
66$leader1S= "";
67$leader = ". . ";
68$leaderS= ". . ";
69$generated_timestamp = date("Ymdhis");
70
droy0b08d292008-05-28 15:18:11 +000071
gobrien1a8e02f2008-01-30 01:46:26 +000072/*
73 * Get the data (plugins, files, translations) from the live database
74 */
gobrien08a4e4e2008-01-30 18:18:29 +000075
gobrien1a8e02f2008-01-30 01:46:26 +000076
77/*
droy0b08d292008-05-28 15:18:11 +000078 * Generate one update site pack per train
gobrien1a8e02f2008-01-30 01:46:26 +000079 */
80$site_xml = '';
droyb6e25c72008-07-18 13:01:13 +000081$train_result = mysql_query( 'SELECT DISTINCT train_id FROM release_train_projects');
droy0b08d292008-05-28 15:18:11 +000082while( ($train_row = mysql_fetch_assoc($train_result)) != null ) {
83 $train_id = $train_row['train_id'];
droy0b08d292008-05-28 15:18:11 +000084
gobrien1a8e02f2008-01-30 01:46:26 +000085 /*
droy0b08d292008-05-28 15:18:11 +000086 * Clear the staging site
gobrien1a8e02f2008-01-30 01:46:26 +000087 */
droy0b08d292008-05-28 15:18:11 +000088
89 # output/europa/plugins
90 # output/ganymede/plugins
91 # etc...
droy4c8bd832008-05-28 19:49:40 +000092 $staging_update_site = $base_out_dir . "output/" . $train_row['train_id'] . "/";
droy0b08d292008-05-28 15:18:11 +000093
94 if( file_exists( $staging_update_site ) ) {
95 exec( "rm -rf $staging_update_site*" );
96 } else {
97 exec( "mkdir $staging_update_site" );
98 }
99 if( file_exists( "${staging_update_site}plugins/" ) ) {
100 exec( "rm -rf ${staging_update_site}plugins/*" );
101 } else {
102 exec( "mkdir ${staging_update_site}plugins/" );
103 }
104 if( file_exists( "${staging_update_site}features/" ) ) {
105 exec( "rm -rf ${staging_update_site}features/*" );
106 } else {
107 exec( "mkdir ${staging_update_site}features/" );
108 }
109
110 /*
111 * Generate one language pack per language
112 */
droy64eca802008-03-10 19:49:21 +0000113
droy0b08d292008-05-28 15:18:11 +0000114 $language_result = mysql_query( 'SELECT * FROM languages WHERE languages.is_active' );
115 while( ($language_row = mysql_fetch_assoc($language_result)) != null ) {
116 $language_name = $language_row['name'];
117 $language_iso = $language_row['iso_code'];
118 $language_locale = $language_row['locale'];
119 if ( $language_locale != null ) {
120 $language_name = $language_locale . " " . $language_name;
gobrien1a8e02f2008-01-30 01:46:26 +0000121 }
droy0b08d292008-05-28 15:18:11 +0000122 echo "${leader1}Generating language pack for $train_id - $language_name ($language_iso)(" . $language_row['language_id'] . ")\n";
123
gobrien1a8e02f2008-01-30 01:46:26 +0000124 /*
droy0b08d292008-05-28 15:18:11 +0000125 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +0000126 */
droy0b08d292008-05-28 15:18:11 +0000127 $file_result = mysql_query( "SELECT DISTINCT
128 f.file_id, f.name
129FROM files AS f
130 INNER JOIN strings AS s ON f.file_id = s.file_id
droy94fda352008-05-28 15:26:36 +0000131 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
132 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
droy0b08d292008-05-28 15:18:11 +0000133WHERE
134 t.language_id = " . $language_row['language_id'] . "
135 AND f.is_active
droy3725f7c2008-05-28 15:21:48 +0000136 AND v.train_id = '" . $train_row['train_id'] . "'");
droy0b08d292008-05-28 15:18:11 +0000137 $plugins = array();
138 while( ($file_row = mysql_fetch_assoc($file_result)) != null ) {
droy02c430a2008-06-02 19:42:08 +0000139 # strip useless CVS structure before the plugin name (bug 221675 c14):
140 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
141 $replace = '${2}.${3}${4}.properties';
142 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
143
144 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
145 $pattern = '/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9\._-]+)(.*)\/(\1)([\.\/])(\2)([\.\/])(.*)\.properties$/i';
146 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
droy0b08d292008-05-28 15:18:11 +0000147 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
148
149 if( preg_match( "/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches ) ) {
150 $file_row['subname'] = $matches[2];
151 $plugins[$matches[1]][] = $file_row;
152 } else {
153 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000154 }
droy0b08d292008-05-28 15:18:11 +0000155 }
156 /*
157 * Generate one plug-in fragment for each plug-in
158 */
159 foreach ($plugins as $plugin_name => $plugin_row ) {
160 echo "${leader1}${leader}Generating plug-in fragment $plugin_name \n";
gobrien1a8e02f2008-01-30 01:46:26 +0000161 /*
droy0b08d292008-05-28 15:18:11 +0000162 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000163 */
droy0b08d292008-05-28 15:18:11 +0000164 if ( file_exists( $temporary_dir ) ) {
165 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
166 } else {
167 exec( "mkdir $temporary_dir" );
168 }
169
gobrien1a8e02f2008-01-30 01:46:26 +0000170 /*
droy0b08d292008-05-28 15:18:11 +0000171 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000172 */
droy0b08d292008-05-28 15:18:11 +0000173 foreach ($plugin_row as $properties_file) {
174 /*
175 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
176 */
177 $filename = $properties_file['subname'];
178 if( preg_match( "/^(.*)\.properties$/", $filename, $matches ) ) {
179 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000180 }
droy0b08d292008-05-28 15:18:11 +0000181 echo "${leader1}${leader}${leader}Generating properties file $filename (" . $properties_file['file_id'] . ")\n";
182 /*
183 * Create any needed sub-directories
184 */
185 $fullpath = $temporary_dir . $filename;
186 preg_match( "/^((.*)\/)?(.+?)$/", $fullpath, $matches );
187 exec( "mkdir -p \"" . $matches[1] . "\"");
188 /*
189 * Start writing to the file
190 */
191 $outp = fopen( $fullpath, "w" );
192 fwrite( $outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n" );
193 //TODO correct copyrights from all contributors
194 /*
195 * For each string that is translated in this file, write it out
196 * Note that if a string is not translated, then it will not be
197 * included and thus Eclipse will pick up the default string for
198 * that key from the default *.properities file. Thus we only
199 * include the strings that are translated.
200 */
201 $sql = "
202 SELECT
203 strings.name AS `key`,
204 strings.value AS orig,
205 translations.value AS trans
206 FROM strings, translations
207 WHERE strings.string_id = translations.string_id
208 AND translations.language_id = " . $language_row['language_id'] . "
209 AND strings.file_id = " . $properties_file['file_id'] . "
210 AND translations.is_active
211 ";
212 $strings_result = mysql_query( $sql );
213 while( ($strings_row = mysql_fetch_assoc($strings_result)) != null ) {
214 fwrite( $outp, $strings_row['key'] . "=" );
215 #echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
216 if( $strings_row['trans'] ) {
217 # json_encode returns the string with quotes fore and aft. Need to strip them.
droy433871e2008-06-02 14:42:30 +0000218 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
219 # $tr_string = str_replace('\\\\', '\\', $tr_string);
220 $tr_string = toescapedunicode($strings_row['trans']);
droy0b08d292008-05-28 15:18:11 +0000221 fwrite( $outp, $tr_string );
222 # echo $strings_row['trans'];
223 } else {
224 fwrite( $outp, $strings_row['orig'] );
225 }
226 fwrite( $outp, "\n" );
227 # echo "\n";
228 }
229 /*
230 * Finish the properties file
231 */
232 fclose( $outp );
233 echo "${leader1}${leader}${leader}completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000234 }
235 /*
droy0b08d292008-05-28 15:18:11 +0000236 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000237 */
droy0b08d292008-05-28 15:18:11 +0000238 exec( "cp ${source_files_for_generate}about.html ${temporary_dir}" );
239 exec( "cp ${source_files_for_generate}license.html ${temporary_dir}" );
240 exec( "cp ${source_files_for_generate}epl-v10.html ${temporary_dir}" );
241 exec( "cp ${source_files_for_generate}eclipse_update_120.jpg ${temporary_dir}" );
242 /*
243 * Generate the META-INF/MANIFEST.MF file
244 */
245 $parent_plugin_id = $plugin_name;
246 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
247 $fragment_major_version = "0.2.0"; //TODO what version number should these plugins be?
248 $fragment_version = $fragment_major_version . ".v" . $generated_timestamp;
249 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
250 $parent_min_version = "0.0.0"; //TODO specify a min version (when versions are supported)
251 $parent_max_version = "9.9.9"; //TODO specify a max version (when versions are supported)
252
253 $plugins[$plugin_name]['id'] = $fragment_id;
254 $plugins[$plugin_name]['version'] = $fragment_version;
255
256 exec( "mkdir $temporary_dir/META-INF" );
257 $outp = fopen( "$temporary_dir/META-INF/MANIFEST.MF", "w" );
258 fwrite( $outp, "Manifest-Version: 1.0\n");
259 fwrite( $outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
260 fwrite( $outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
261 fwrite( $outp, "Bundle-Version: $fragment_version\n");
262 fwrite( $outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
263 fwrite( $outp, "Fragment-Host: $parent_plugin_id;bundle-version=\"[$parent_min_version,$parent_max_version)\"\n");
gobrien1a8e02f2008-01-30 01:46:26 +0000264 fclose( $outp );
droy0b08d292008-05-28 15:18:11 +0000265 /*
266 * Jar up this directory as the fragment plug-in jar
267 */
268 system( "cd $temporary_dir; jar cfM ${staging_update_site}plugins/$fragment_filename ." );
269 echo "${leader1}${leader}completed plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000270 }
droy0b08d292008-05-28 15:18:11 +0000271 /*
272 * Clean and create the temporary directory
273 */
274 if ( file_exists( $temporary_dir ) ) {
275 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
276 } else {
277 exec( "mkdir $temporary_dir" );
278 }
gobrien1a8e02f2008-01-30 01:46:26 +0000279 /*
droy0b08d292008-05-28 15:18:11 +0000280 * Create the feature.xml
281 *
282 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
283 *
284 * <url>
285 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
286 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
287 * </url>
gobrien1a8e02f2008-01-30 01:46:26 +0000288 */
droy0b08d292008-05-28 15:18:11 +0000289 $feature_id = "org.eclipse.nls.$language_iso";
290 $feature_major_version = "0.2.0"; //TODO what version number should this feature be?
291 $feature_version = $feature_major_version . ".v" . $generated_timestamp;
292 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
293
294 $outp = fopen( "$temporary_dir/feature.xml", "w" );
295 fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
296 <feature
297 id=\"$feature_id\"
298 label=\"Eclipse Language Pack for $language_name\"
299 image=\"eclipse_update_120.jpg\"
300 provider-name=\"Eclipse Foundation Inc.\"
301 version=\"$feature_version\">
302 <license url=\"license.html\">"
303 . htmlspecialchars( file_get_contents( "${source_files_for_generate}license.txt" ) ) . "</license>
304 <description>Translations in $language_name for all Eclipse Projects</description>
305 " );
306 foreach ($plugins as $plugin_name => $plugin_row ) {
307 fwrite( $outp, '<plugin fragment="true" id="'
308 . $plugin_row['id'] . '" unpack="false" version="'
309 . $plugin_row['version'] . '"/>
310 ' );
311 }
312 fwrite( $outp, '</feature>
313 ' );
gobrien1a8e02f2008-01-30 01:46:26 +0000314 fclose( $outp );
droy0b08d292008-05-28 15:18:11 +0000315 /*
316 * Jar up this directory as the feature jar
317 */
318 system( "cd $temporary_dir; jar cfM ${staging_update_site}features/$feature_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000319 /*
droy0b08d292008-05-28 15:18:11 +0000320 * Register this feature with the site.xml
gobrien1a8e02f2008-01-30 01:46:26 +0000321 */
droy0b08d292008-05-28 15:18:11 +0000322 $site_xml .= "<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
323 <category name=\"Language Packs\"/></feature>
324 ";
325 echo "${leader1}completed language pack for $language_name ($language_iso)\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000326 }
gobrien1a8e02f2008-01-30 01:46:26 +0000327 /*
droy0b08d292008-05-28 15:18:11 +0000328 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000329 */
droy0b08d292008-05-28 15:18:11 +0000330 $outp = fopen( "${staging_update_site}site.xml", "w" );
331 fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
332 <site>
333 <description url=\"http://babel.eclipse.org/\">This update site contains
334 user-contributed translations of the strings in all Eclipse projects. Please
335 see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use
336 explanation of these translations as well as how you can contribute to
337 the translations of this and future versions of Eclipse.</description>
338 <category-def name=\"Language Packs\" label=\"Language Packs\">
339 <description>Language packs for all Eclipse projects</description>
340 </category-def>
341 " );
342 fwrite( $outp, $site_xml );
343 fwrite( $outp, "</site>
344 " );
gobrien1a8e02f2008-01-30 01:46:26 +0000345 fclose( $outp );
gobrien1a8e02f2008-01-30 01:46:26 +0000346}
gobrien1a8e02f2008-01-30 01:46:26 +0000347echo "Completed generating update site\n";
348
349/*
3502. what happens if the translation feature includes plug-in fragments for
351 plug-ins that are not in the current image?
352 does it load correctly and ignore those fragments? if so, good
353 A: warnings appear in the run-time error log
354 does it fail to load? if so, then we need to generate different features, perhaps
355 one feature for each plug or else we need to know more about the project
356 distro structure to know which plug-ins to put in each feature
357 what happens if those plug-ins are later added - does it load the strings now?
358 A: probably not
3593. need to handle different versions of each feature/plugin/platform; generate different
360 language packs for each
361*/
362
gobrienb854dcb2008-01-30 18:50:45 +0000363$alloutput = fopen($base_out_dir."langpack_output_".date("m_d_Y"), "w" );
364fwrite( $alloutput,ob_get_contents());
365?>