blob: 39bb8bd39dede6bc47c1ee107925cb9c9e4b418f [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
11*******************************************************************************/
12
13/*
14 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
15 */
16//TODO handle versions, however that works; files.version is like "3.4" for Eclipse 3.4
17
18/*
19 * Globals
20 */
gobrienb854dcb2008-01-30 18:50:45 +000021ob_start();
22
23
24if(defined('BABEL_BASE_DIR')){
25 require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
26}else{
27 define('BABEL_BASE_DIR', "../../");
28 require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
29}
30
droy86f26212008-03-04 19:54:23 +000031if( !function_exists('json_encode') ){
32 require("/home/data/httpd/babel.eclipse.org/html/json_encode.php");
33 function json_encode($encode){
34 $jsons = new Services_JSON();
35 return $jsons->encode($encode);
36 }
37}
38
gobrienb854dcb2008-01-30 18:50:45 +000039if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
40 errorLog("Failed to find/read database conf file - aborting.");
41 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
42}
43
44$context = $ini['context'];
45if($context == "") {
46 $context = "staging";
47}
48global $context;
49
50
51$base_out_dir = "/home/babel-working/";
52
53if(!file_exists($base_out_dir)){
54 $base_out_dir = "";
55}
56
57if($context == "live"){
58 $base_out_dir .= "live/";
59}else{
60 $base_out_dir .= "staging/";
61}
62if( !file_exists( $base_out_dir ) ) {
63 exec( "mkdir $base_out_dir" );
64}
65
66$temporary_dir = $base_out_dir."tmp_generated/";
gobrien431ca4f2008-01-30 19:54:00 +000067$staging_update_site = $base_out_dir."output/";
gobriene2bb07b2008-01-30 19:00:42 +000068$source_files_for_generate = "source_files_for_generate/";
gobrien1a8e02f2008-01-30 01:46:26 +000069
70$leader1 = "";
71$leader1S= "";
72$leader = ". . ";
73$leaderS= ". . ";
74$generated_timestamp = date("Ymdhis");
75
76/*
77 * Clear the staging site
78 */
79if( file_exists( $staging_update_site ) ) {
80 exec( "rm -rf $staging_update_site*" );
81} else {
82 exec( "mkdir $staging_update_site" );
83}
84if( file_exists( "${staging_update_site}plugins/" ) ) {
85 exec( "rm -rf ${staging_update_site}plugins/*" );
86} else {
87 exec( "mkdir ${staging_update_site}plugins/" );
88}
89if( file_exists( "${staging_update_site}features/" ) ) {
90 exec( "rm -rf ${staging_update_site}features/*" );
91} else {
92 exec( "mkdir ${staging_update_site}features/" );
93}
94/*
95 * Get the data (plugins, files, translations) from the live database
96 */
gobrien08a4e4e2008-01-30 18:18:29 +000097
gobrien08a4e4e2008-01-30 18:18:29 +000098$dbc = new DBConnection();
99global $dbh;
100$dbh = $dbc->connect();
101
gobrien1a8e02f2008-01-30 01:46:26 +0000102
103/*
104 * Generate one language pack per language
105 */
106$site_xml = '';
107$language_result = mysql_query( 'SELECT * FROM languages WHERE languages.is_active' );
108while( ($language_row = mysql_fetch_assoc($language_result)) != null ) {
109 $language_name = $language_row['name'];
110 $language_iso = $language_row['iso_code'];
droyd5f24422008-03-05 21:48:42 +0000111 $language_locale = $language_row['locale'];
droyd01a5642008-03-05 22:05:20 +0000112 if ( $language_locale != null ) {
droyd5f24422008-03-05 21:48:42 +0000113 $language_name = $language_locale . " " . $language_name;
114 }
gobrien1a8e02f2008-01-30 01:46:26 +0000115 echo "${leader1}Generating language pack for $language_name ($language_iso)(" . $language_row['language_id'] . ")\n";
116
117 /*
118 * Determine which plug-ins need to be in this language pack.
119 */
120 $file_result = mysql_query( "SELECT DISTINCT files.file_id, files.name
121 FROM files, strings, translations
122 WHERE files.file_id = strings.file_id
123 AND strings.string_id = translations.string_id
124 AND translations.language_id = ". $language_row['language_id'] . "
125 AND translations.is_active
126 AND files.is_active ");
127 $plugins = array();
128 while( ($file_row = mysql_fetch_assoc($file_result)) != null ) {
droy64eca802008-03-10 19:49:21 +0000129 # strip source folder (bug 221675)
130 $pattern = '/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.(.*)\/(.*)\/(\1)\/(\2)\/(.*)\.properties$/i';
131 $replace = '${1}.${2}.${3}/${5}/${6}/${7}.properties';
132 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
133
gobrien1a8e02f2008-01-30 01:46:26 +0000134 if( preg_match( "/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches ) ) {
135 $file_row['subname'] = $matches[2];
136 $plugins[$matches[1]][] = $file_row;
137 } else {
138 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
139 }
140 }
141 /*
142 * Generate one plug-in fragment for each plug-in
143 */
144 foreach ($plugins as $plugin_name => $plugin_row ) {
145 echo "${leader1}${leader}Generating plug-in fragment $plugin_name \n";
146 /*
147 * Clean and create the temporary directory
148 */
149 if ( file_exists( $temporary_dir ) ) {
150 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
151 } else {
152 exec( "mkdir $temporary_dir" );
153 }
154
155 /*
156 * Generate each *.properties file
157 */
158 foreach ($plugin_row as $properties_file) {
159 /*
160 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
161 */
162 $filename = $properties_file['subname'];
163 if( preg_match( "/^(.*)\.properties$/", $filename, $matches ) ) {
164 $filename = $matches[1] . '_' . $language_iso . '.properties';
165 }
166 echo "${leader1}${leader}${leader}Generating properties file $filename (" . $properties_file['file_id'] . ")\n";
167 /*
168 * Create any needed sub-directories
169 */
170 $fullpath = $temporary_dir . $filename;
171 preg_match( "/^((.*)\/)?(.+?)$/", $fullpath, $matches );
droyd841b3c2008-02-13 16:39:24 +0000172 exec( "mkdir -p \"" . $matches[1] . "\"");
gobrien1a8e02f2008-01-30 01:46:26 +0000173 /*
174 * Start writing to the file
175 */
176 $outp = fopen( $fullpath, "w" );
177 fwrite( $outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n" );
178 //TODO correct copyrights from all contributors
179 /*
180 * For each string that is translated in this file, write it out
181 * Note that if a string is not translated, then it will not be
182 * included and thus Eclipse will pick up the default string for
183 * that key from the default *.properities file. Thus we only
184 * include the strings that are translated.
185 */
186 $sql = "
187 SELECT
188 strings.name AS `key`,
189 strings.value AS orig,
190 translations.value AS trans
191 FROM strings, translations
192 WHERE strings.string_id = translations.string_id
193 AND translations.language_id = " . $language_row['language_id'] . "
194 AND strings.file_id = " . $properties_file['file_id'] . "
195 AND translations.is_active
196 ";
197 $strings_result = mysql_query( $sql );
198 while( ($strings_row = mysql_fetch_assoc($strings_result)) != null ) {
199 fwrite( $outp, $strings_row['key'] . "=" );
droy16712fe2008-03-04 14:23:53 +0000200 #echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
gobrien1a8e02f2008-01-30 01:46:26 +0000201 if( $strings_row['trans'] ) {
droy86f26212008-03-04 19:54:23 +0000202 # json_encode returns the string with quotes fore and aft. Need to strip them.
203 $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
204 fwrite( $outp, $tr_string );
droy16712fe2008-03-04 14:23:53 +0000205 # echo $strings_row['trans'];
gobrien1a8e02f2008-01-30 01:46:26 +0000206 } else {
207 fwrite( $outp, $strings_row['orig'] );
208 }
209 fwrite( $outp, "\n" );
droy16712fe2008-03-04 14:23:53 +0000210 # echo "\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000211 }
212 /*
213 * Finish the properties file
214 */
215 fclose( $outp );
216 echo "${leader1}${leader}${leader}completed properties file $filename\n";
217 }
218 /*
219 * Copy in the various legal files
220 */
221 exec( "cp ${source_files_for_generate}about.html ${temporary_dir}" );
222 exec( "cp ${source_files_for_generate}license.html ${temporary_dir}" );
223 exec( "cp ${source_files_for_generate}epl-v10.html ${temporary_dir}" );
224 exec( "cp ${source_files_for_generate}eclipse_update_120.jpg ${temporary_dir}" );
225 /*
226 * Generate the META-INF/MANIFEST.MF file
227 */
228 $parent_plugin_id = $plugin_name;
229 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
230 $fragment_major_version = "0.2.0"; //TODO what version number should these plugins be?
231 $fragment_version = $fragment_major_version . ".v" . $generated_timestamp;
232 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
233 $parent_min_version = "0.0.0"; //TODO specify a min version (when versions are supported)
234 $parent_max_version = "9.9.9"; //TODO specify a max version (when versions are supported)
235
236 $plugins[$plugin_name]['id'] = $fragment_id;
237 $plugins[$plugin_name]['version'] = $fragment_version;
238
239 exec( "mkdir $temporary_dir/META-INF" );
240 $outp = fopen( "$temporary_dir/META-INF/MANIFEST.MF", "w" );
241 fwrite( $outp, "Manifest-Version: 1.0\n");
242 fwrite( $outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
243 fwrite( $outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
244 fwrite( $outp, "Bundle-Version: $fragment_version\n");
245 fwrite( $outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
246 fwrite( $outp, "Fragment-Host: $parent_plugin_id;bundle-version=\"[$parent_min_version,$parent_max_version)\"\n");
247 fclose( $outp );
248 /*
249 * Jar up this directory as the fragment plug-in jar
250 */
gobrien7bc2aa12008-01-30 19:08:06 +0000251 system( "cd $temporary_dir; jar cfM ${staging_update_site}plugins/$fragment_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000252 echo "${leader1}${leader}completed plug-in fragment $plugin_name\n";
253 }
254 /*
255 * Clean and create the temporary directory
256 */
257 if ( file_exists( $temporary_dir ) ) {
258 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
259 } else {
260 exec( "mkdir $temporary_dir" );
261 }
262 /*
263 * Create the feature.xml
264 *
265 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
266 *
267 * <url>
268 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
269 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
270 * </url>
271 */
272 $feature_id = "org.eclipse.nls.$language_iso";
273 $feature_major_version = "0.2.0"; //TODO what version number should this feature be?
274 $feature_version = $feature_major_version . ".v" . $generated_timestamp;
275 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
276
277 $outp = fopen( "$temporary_dir/feature.xml", "w" );
278 fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
279<feature
280 id=\"$feature_id\"
281 label=\"Eclipse Language Pack for $language_name\"
282 image=\"eclipse_update_120.jpg\"
283 provider-name=\"Eclipse Foundation Inc.\"
284 version=\"$feature_version\">
285<license url=\"license.html\">"
286 . htmlspecialchars( file_get_contents( "${source_files_for_generate}license.txt" ) ) . "</license>
287<description>Translations in $language_name for all Eclipse Projects</description>
288" );
289 foreach ($plugins as $plugin_name => $plugin_row ) {
droy01776c12008-03-04 15:16:41 +0000290 fwrite( $outp, '<plugin fragment="true" id="'
gobrien1a8e02f2008-01-30 01:46:26 +0000291 . $plugin_row['id'] . '" unpack="false" version="'
292 . $plugin_row['version'] . '"/>
293' );
294 }
295 fwrite( $outp, '</feature>
296' );
297 fclose( $outp );
298 /*
299 * Jar up this directory as the feature jar
300 */
gobrien7bc2aa12008-01-30 19:08:06 +0000301 system( "cd $temporary_dir; jar cfM ${staging_update_site}features/$feature_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000302 /*
303 * Register this feature with the site.xml
304 */
305 $site_xml .= "<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
306 <category name=\"Language Packs\"/></feature>
307";
droyd5f24422008-03-05 21:48:42 +0000308 echo "${leader1}completed language pack for $language_name ($language_iso)\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000309}
310/*
311 * TODO <site mirrorsURL=... is not yet implemented
312 */
313$outp = fopen( "${staging_update_site}site.xml", "w" );
314fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
315<site>
316 <description url=\"http://babel.eclipse.org/\">This update site contains
317user-contributed translations of the strings in all Eclipse projects. Please
318see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use
319explanation of these translations as well as how you can contribute to
320the translations of this and future versions of Eclipse.</description>
321 <category-def name=\"Language Packs\" label=\"Language Packs\">
322 <description>Language packs for all Eclipse projects</description>
323 </category-def>
324" );
325fwrite( $outp, $site_xml );
326fwrite( $outp, "</site>
327" );
328fclose( $outp );
329
330echo "Completed generating update site\n";
331
332/*
3332. what happens if the translation feature includes plug-in fragments for
334 plug-ins that are not in the current image?
335 does it load correctly and ignore those fragments? if so, good
336 A: warnings appear in the run-time error log
337 does it fail to load? if so, then we need to generate different features, perhaps
338 one feature for each plug or else we need to know more about the project
339 distro structure to know which plug-ins to put in each feature
340 what happens if those plug-ins are later added - does it load the strings now?
341 A: probably not
3423. need to handle different versions of each feature/plugin/platform; generate different
343 language packs for each
344*/
345
gobrienb854dcb2008-01-30 18:50:45 +0000346$alloutput = fopen($base_out_dir."langpack_output_".date("m_d_Y"), "w" );
347fwrite( $alloutput,ob_get_contents());
348?>