blob: 03463a1bca2f244a92ab853e1702ebd46e928f45 [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'];
112 if ( $language_locale != null ) ) {
113 $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 ) {
129 if( preg_match( "/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches ) ) {
130 $file_row['subname'] = $matches[2];
131 $plugins[$matches[1]][] = $file_row;
132 } else {
133 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
134 }
135 }
136 /*
137 * Generate one plug-in fragment for each plug-in
138 */
139 foreach ($plugins as $plugin_name => $plugin_row ) {
140 echo "${leader1}${leader}Generating plug-in fragment $plugin_name \n";
141 /*
142 * Clean and create the temporary directory
143 */
144 if ( file_exists( $temporary_dir ) ) {
145 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
146 } else {
147 exec( "mkdir $temporary_dir" );
148 }
149
150 /*
151 * Generate each *.properties file
152 */
153 foreach ($plugin_row as $properties_file) {
154 /*
155 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
156 */
157 $filename = $properties_file['subname'];
158 if( preg_match( "/^(.*)\.properties$/", $filename, $matches ) ) {
159 $filename = $matches[1] . '_' . $language_iso . '.properties';
160 }
161 echo "${leader1}${leader}${leader}Generating properties file $filename (" . $properties_file['file_id'] . ")\n";
162 /*
163 * Create any needed sub-directories
164 */
165 $fullpath = $temporary_dir . $filename;
166 preg_match( "/^((.*)\/)?(.+?)$/", $fullpath, $matches );
droyd841b3c2008-02-13 16:39:24 +0000167 exec( "mkdir -p \"" . $matches[1] . "\"");
gobrien1a8e02f2008-01-30 01:46:26 +0000168 /*
169 * Start writing to the file
170 */
171 $outp = fopen( $fullpath, "w" );
172 fwrite( $outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n" );
173 //TODO correct copyrights from all contributors
174 /*
175 * For each string that is translated in this file, write it out
176 * Note that if a string is not translated, then it will not be
177 * included and thus Eclipse will pick up the default string for
178 * that key from the default *.properities file. Thus we only
179 * include the strings that are translated.
180 */
181 $sql = "
182 SELECT
183 strings.name AS `key`,
184 strings.value AS orig,
185 translations.value AS trans
186 FROM strings, translations
187 WHERE strings.string_id = translations.string_id
188 AND translations.language_id = " . $language_row['language_id'] . "
189 AND strings.file_id = " . $properties_file['file_id'] . "
190 AND translations.is_active
191 ";
192 $strings_result = mysql_query( $sql );
193 while( ($strings_row = mysql_fetch_assoc($strings_result)) != null ) {
194 fwrite( $outp, $strings_row['key'] . "=" );
droy16712fe2008-03-04 14:23:53 +0000195 #echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
gobrien1a8e02f2008-01-30 01:46:26 +0000196 if( $strings_row['trans'] ) {
droy86f26212008-03-04 19:54:23 +0000197 # json_encode returns the string with quotes fore and aft. Need to strip them.
198 $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
199 fwrite( $outp, $tr_string );
droy16712fe2008-03-04 14:23:53 +0000200 # echo $strings_row['trans'];
gobrien1a8e02f2008-01-30 01:46:26 +0000201 } else {
202 fwrite( $outp, $strings_row['orig'] );
203 }
204 fwrite( $outp, "\n" );
droy16712fe2008-03-04 14:23:53 +0000205 # echo "\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000206 }
207 /*
208 * Finish the properties file
209 */
210 fclose( $outp );
211 echo "${leader1}${leader}${leader}completed properties file $filename\n";
212 }
213 /*
214 * Copy in the various legal files
215 */
216 exec( "cp ${source_files_for_generate}about.html ${temporary_dir}" );
217 exec( "cp ${source_files_for_generate}license.html ${temporary_dir}" );
218 exec( "cp ${source_files_for_generate}epl-v10.html ${temporary_dir}" );
219 exec( "cp ${source_files_for_generate}eclipse_update_120.jpg ${temporary_dir}" );
220 /*
221 * Generate the META-INF/MANIFEST.MF file
222 */
223 $parent_plugin_id = $plugin_name;
224 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
225 $fragment_major_version = "0.2.0"; //TODO what version number should these plugins be?
226 $fragment_version = $fragment_major_version . ".v" . $generated_timestamp;
227 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
228 $parent_min_version = "0.0.0"; //TODO specify a min version (when versions are supported)
229 $parent_max_version = "9.9.9"; //TODO specify a max version (when versions are supported)
230
231 $plugins[$plugin_name]['id'] = $fragment_id;
232 $plugins[$plugin_name]['version'] = $fragment_version;
233
234 exec( "mkdir $temporary_dir/META-INF" );
235 $outp = fopen( "$temporary_dir/META-INF/MANIFEST.MF", "w" );
236 fwrite( $outp, "Manifest-Version: 1.0\n");
237 fwrite( $outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
238 fwrite( $outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
239 fwrite( $outp, "Bundle-Version: $fragment_version\n");
240 fwrite( $outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
241 fwrite( $outp, "Fragment-Host: $parent_plugin_id;bundle-version=\"[$parent_min_version,$parent_max_version)\"\n");
242 fclose( $outp );
243 /*
244 * Jar up this directory as the fragment plug-in jar
245 */
gobrien7bc2aa12008-01-30 19:08:06 +0000246 system( "cd $temporary_dir; jar cfM ${staging_update_site}plugins/$fragment_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000247 echo "${leader1}${leader}completed plug-in fragment $plugin_name\n";
248 }
249 /*
250 * Clean and create the temporary directory
251 */
252 if ( file_exists( $temporary_dir ) ) {
253 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
254 } else {
255 exec( "mkdir $temporary_dir" );
256 }
257 /*
258 * Create the feature.xml
259 *
260 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
261 *
262 * <url>
263 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
264 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
265 * </url>
266 */
267 $feature_id = "org.eclipse.nls.$language_iso";
268 $feature_major_version = "0.2.0"; //TODO what version number should this feature be?
269 $feature_version = $feature_major_version . ".v" . $generated_timestamp;
270 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
271
272 $outp = fopen( "$temporary_dir/feature.xml", "w" );
273 fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
274<feature
275 id=\"$feature_id\"
276 label=\"Eclipse Language Pack for $language_name\"
277 image=\"eclipse_update_120.jpg\"
278 provider-name=\"Eclipse Foundation Inc.\"
279 version=\"$feature_version\">
280<license url=\"license.html\">"
281 . htmlspecialchars( file_get_contents( "${source_files_for_generate}license.txt" ) ) . "</license>
282<description>Translations in $language_name for all Eclipse Projects</description>
283" );
284 foreach ($plugins as $plugin_name => $plugin_row ) {
droy01776c12008-03-04 15:16:41 +0000285 fwrite( $outp, '<plugin fragment="true" id="'
gobrien1a8e02f2008-01-30 01:46:26 +0000286 . $plugin_row['id'] . '" unpack="false" version="'
287 . $plugin_row['version'] . '"/>
288' );
289 }
290 fwrite( $outp, '</feature>
291' );
292 fclose( $outp );
293 /*
294 * Jar up this directory as the feature jar
295 */
gobrien7bc2aa12008-01-30 19:08:06 +0000296 system( "cd $temporary_dir; jar cfM ${staging_update_site}features/$feature_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000297 /*
298 * Register this feature with the site.xml
299 */
300 $site_xml .= "<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
301 <category name=\"Language Packs\"/></feature>
302";
droyd5f24422008-03-05 21:48:42 +0000303 echo "${leader1}completed language pack for $language_name ($language_iso)\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000304}
305/*
306 * TODO <site mirrorsURL=... is not yet implemented
307 */
308$outp = fopen( "${staging_update_site}site.xml", "w" );
309fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
310<site>
311 <description url=\"http://babel.eclipse.org/\">This update site contains
312user-contributed translations of the strings in all Eclipse projects. Please
313see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use
314explanation of these translations as well as how you can contribute to
315the translations of this and future versions of Eclipse.</description>
316 <category-def name=\"Language Packs\" label=\"Language Packs\">
317 <description>Language packs for all Eclipse projects</description>
318 </category-def>
319" );
320fwrite( $outp, $site_xml );
321fwrite( $outp, "</site>
322" );
323fclose( $outp );
324
325echo "Completed generating update site\n";
326
327/*
3282. what happens if the translation feature includes plug-in fragments for
329 plug-ins that are not in the current image?
330 does it load correctly and ignore those fragments? if so, good
331 A: warnings appear in the run-time error log
332 does it fail to load? if so, then we need to generate different features, perhaps
333 one feature for each plug or else we need to know more about the project
334 distro structure to know which plug-ins to put in each feature
335 what happens if those plug-ins are later added - does it load the strings now?
336 A: probably not
3373. need to handle different versions of each feature/plugin/platform; generate different
338 language packs for each
339*/
340
gobrienb854dcb2008-01-30 18:50:45 +0000341$alloutput = fopen($base_out_dir."langpack_output_".date("m_d_Y"), "w" );
342fwrite( $alloutput,ob_get_contents());
343?>