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