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