blob: 9bab1aac8916b78590e9ad0e51f09091b7b09c80 [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
31if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
32 errorLog("Failed to find/read database conf file - aborting.");
33 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
34}
35
36$context = $ini['context'];
37if($context == "") {
38 $context = "staging";
39}
40global $context;
41
42
43$base_out_dir = "/home/babel-working/";
44
45if(!file_exists($base_out_dir)){
46 $base_out_dir = "";
47}
48
49if($context == "live"){
50 $base_out_dir .= "live/";
51}else{
52 $base_out_dir .= "staging/";
53}
54if( !file_exists( $base_out_dir ) ) {
55 exec( "mkdir $base_out_dir" );
56}
57
58$temporary_dir = $base_out_dir."tmp_generated/";
59$staging_update_site = $base_out_dir."staging/";
gobriene2bb07b2008-01-30 19:00:42 +000060$source_files_for_generate = "source_files_for_generate/";
gobrien1a8e02f2008-01-30 01:46:26 +000061
62$leader1 = "";
63$leader1S= "";
64$leader = ". . ";
65$leaderS= ". . ";
66$generated_timestamp = date("Ymdhis");
67
68/*
69 * Clear the staging site
70 */
71if( file_exists( $staging_update_site ) ) {
72 exec( "rm -rf $staging_update_site*" );
73} else {
74 exec( "mkdir $staging_update_site" );
75}
76if( file_exists( "${staging_update_site}plugins/" ) ) {
77 exec( "rm -rf ${staging_update_site}plugins/*" );
78} else {
79 exec( "mkdir ${staging_update_site}plugins/" );
80}
81if( file_exists( "${staging_update_site}features/" ) ) {
82 exec( "rm -rf ${staging_update_site}features/*" );
83} else {
84 exec( "mkdir ${staging_update_site}features/" );
85}
86/*
87 * Get the data (plugins, files, translations) from the live database
88 */
gobrien08a4e4e2008-01-30 18:18:29 +000089
gobrien08a4e4e2008-01-30 18:18:29 +000090$dbc = new DBConnection();
91global $dbh;
92$dbh = $dbc->connect();
93
gobrien1a8e02f2008-01-30 01:46:26 +000094
95/*
96 * Generate one language pack per language
97 */
98$site_xml = '';
99$language_result = mysql_query( 'SELECT * FROM languages WHERE languages.is_active' );
100while( ($language_row = mysql_fetch_assoc($language_result)) != null ) {
101 $language_name = $language_row['name'];
102 $language_iso = $language_row['iso_code'];
103 echo "${leader1}Generating language pack for $language_name ($language_iso)(" . $language_row['language_id'] . ")\n";
104
105 /*
106 * Determine which plug-ins need to be in this language pack.
107 */
108 $file_result = mysql_query( "SELECT DISTINCT files.file_id, files.name
109 FROM files, strings, translations
110 WHERE files.file_id = strings.file_id
111 AND strings.string_id = translations.string_id
112 AND translations.language_id = ". $language_row['language_id'] . "
113 AND translations.is_active
114 AND files.is_active ");
115 $plugins = array();
116 while( ($file_row = mysql_fetch_assoc($file_result)) != null ) {
117 if( preg_match( "/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches ) ) {
118 $file_row['subname'] = $matches[2];
119 $plugins[$matches[1]][] = $file_row;
120 } else {
121 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
122 }
123 }
124 /*
125 * Generate one plug-in fragment for each plug-in
126 */
127 foreach ($plugins as $plugin_name => $plugin_row ) {
128 echo "${leader1}${leader}Generating plug-in fragment $plugin_name \n";
129 /*
130 * Clean and create the temporary directory
131 */
132 if ( file_exists( $temporary_dir ) ) {
133 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
134 } else {
135 exec( "mkdir $temporary_dir" );
136 }
137
138 /*
139 * Generate each *.properties file
140 */
141 foreach ($plugin_row as $properties_file) {
142 /*
143 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
144 */
145 $filename = $properties_file['subname'];
146 if( preg_match( "/^(.*)\.properties$/", $filename, $matches ) ) {
147 $filename = $matches[1] . '_' . $language_iso . '.properties';
148 }
149 echo "${leader1}${leader}${leader}Generating properties file $filename (" . $properties_file['file_id'] . ")\n";
150 /*
151 * Create any needed sub-directories
152 */
153 $fullpath = $temporary_dir . $filename;
154 preg_match( "/^((.*)\/)?(.+?)$/", $fullpath, $matches );
155 $dirs1 = split( "\/", $matches[1] );
156 $dirs2 = array();
157 $d = '';
158 foreach ( $dirs1 as $each ) {
159 if( $each ) {
160 $d .= $each . '/';
161 $dirs2[] = $d;
162 }
163 }
164 foreach( $dirs2 as $each ) {
165 if( !file_exists( $each) ) {
166 exec( "mkdir " . $each );
167 }
168 }
169 /*
170 * Start writing to the file
171 */
172 $outp = fopen( $fullpath, "w" );
173 fwrite( $outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n" );
174 //TODO correct copyrights from all contributors
175 /*
176 * For each string that is translated in this file, write it out
177 * Note that if a string is not translated, then it will not be
178 * included and thus Eclipse will pick up the default string for
179 * that key from the default *.properities file. Thus we only
180 * include the strings that are translated.
181 */
182 $sql = "
183 SELECT
184 strings.name AS `key`,
185 strings.value AS orig,
186 translations.value AS trans
187 FROM strings, translations
188 WHERE strings.string_id = translations.string_id
189 AND translations.language_id = " . $language_row['language_id'] . "
190 AND strings.file_id = " . $properties_file['file_id'] . "
191 AND translations.is_active
192 ";
193 $strings_result = mysql_query( $sql );
194 while( ($strings_row = mysql_fetch_assoc($strings_result)) != null ) {
195 fwrite( $outp, $strings_row['key'] . "=" );
196 echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
197 if( $strings_row['trans'] ) {
198 fwrite( $outp, $strings_row['trans'] );
199 echo $strings_row['trans'];
200 } else {
201 fwrite( $outp, $strings_row['orig'] );
202 }
203 fwrite( $outp, "\n" );
204 echo "\n";
205 }
206 /*
207 * Finish the properties file
208 */
209 fclose( $outp );
210 echo "${leader1}${leader}${leader}completed properties file $filename\n";
211 }
212 /*
213 * Copy in the various legal files
214 */
215 exec( "cp ${source_files_for_generate}about.html ${temporary_dir}" );
216 exec( "cp ${source_files_for_generate}license.html ${temporary_dir}" );
217 exec( "cp ${source_files_for_generate}epl-v10.html ${temporary_dir}" );
218 exec( "cp ${source_files_for_generate}eclipse_update_120.jpg ${temporary_dir}" );
219 /*
220 * Generate the META-INF/MANIFEST.MF file
221 */
222 $parent_plugin_id = $plugin_name;
223 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
224 $fragment_major_version = "0.2.0"; //TODO what version number should these plugins be?
225 $fragment_version = $fragment_major_version . ".v" . $generated_timestamp;
226 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
227 $parent_min_version = "0.0.0"; //TODO specify a min version (when versions are supported)
228 $parent_max_version = "9.9.9"; //TODO specify a max version (when versions are supported)
229
230 $plugins[$plugin_name]['id'] = $fragment_id;
231 $plugins[$plugin_name]['version'] = $fragment_version;
232
233 exec( "mkdir $temporary_dir/META-INF" );
234 $outp = fopen( "$temporary_dir/META-INF/MANIFEST.MF", "w" );
235 fwrite( $outp, "Manifest-Version: 1.0\n");
236 fwrite( $outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
237 fwrite( $outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
238 fwrite( $outp, "Bundle-Version: $fragment_version\n");
239 fwrite( $outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
240 fwrite( $outp, "Fragment-Host: $parent_plugin_id;bundle-version=\"[$parent_min_version,$parent_max_version)\"\n");
241 fclose( $outp );
242 /*
243 * Jar up this directory as the fragment plug-in jar
244 */
gobrien7bc2aa12008-01-30 19:08:06 +0000245 system( "cd $temporary_dir; jar cfM ${staging_update_site}plugins/$fragment_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000246 echo "${leader1}${leader}completed plug-in fragment $plugin_name\n";
247 }
248 /*
249 * Clean and create the temporary directory
250 */
251 if ( file_exists( $temporary_dir ) ) {
252 exec( "rm -rf $temporary_dir; mkdir $temporary_dir" );
253 } else {
254 exec( "mkdir $temporary_dir" );
255 }
256 /*
257 * Create the feature.xml
258 *
259 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
260 *
261 * <url>
262 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
263 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
264 * </url>
265 */
266 $feature_id = "org.eclipse.nls.$language_iso";
267 $feature_major_version = "0.2.0"; //TODO what version number should this feature be?
268 $feature_version = $feature_major_version . ".v" . $generated_timestamp;
269 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
270
271 $outp = fopen( "$temporary_dir/feature.xml", "w" );
272 fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
273<feature
274 id=\"$feature_id\"
275 label=\"Eclipse Language Pack for $language_name\"
276 image=\"eclipse_update_120.jpg\"
277 provider-name=\"Eclipse Foundation Inc.\"
278 version=\"$feature_version\">
279<license url=\"license.html\">"
280 . htmlspecialchars( file_get_contents( "${source_files_for_generate}license.txt" ) ) . "</license>
281<description>Translations in $language_name for all Eclipse Projects</description>
282" );
283 foreach ($plugins as $plugin_name => $plugin_row ) {
284 fwrite( $outp, '<pluging fragment="true" id="'
285 . $plugin_row['id'] . '" unpack="false" version="'
286 . $plugin_row['version'] . '"/>
287' );
288 }
289 fwrite( $outp, '</feature>
290' );
291 fclose( $outp );
292 /*
293 * Jar up this directory as the feature jar
294 */
gobrien7bc2aa12008-01-30 19:08:06 +0000295 system( "cd $temporary_dir; jar cfM ${staging_update_site}features/$feature_filename ." );
gobrien1a8e02f2008-01-30 01:46:26 +0000296 /*
297 * Register this feature with the site.xml
298 */
299 $site_xml .= "<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
300 <category name=\"Language Packs\"/></feature>
301";
302 echo "${leader1}completed language pack for $language_name ($language_iso)\n";
303}
304/*
305 * TODO <site mirrorsURL=... is not yet implemented
306 */
307$outp = fopen( "${staging_update_site}site.xml", "w" );
308fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
309<site>
310 <description url=\"http://babel.eclipse.org/\">This update site contains
311user-contributed translations of the strings in all Eclipse projects. Please
312see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use
313explanation of these translations as well as how you can contribute to
314the translations of this and future versions of Eclipse.</description>
315 <category-def name=\"Language Packs\" label=\"Language Packs\">
316 <description>Language packs for all Eclipse projects</description>
317 </category-def>
318" );
319fwrite( $outp, $site_xml );
320fwrite( $outp, "</site>
321" );
322fclose( $outp );
323
324echo "Completed generating update site\n";
325
326/*
3272. what happens if the translation feature includes plug-in fragments for
328 plug-ins that are not in the current image?
329 does it load correctly and ignore those fragments? if so, good
330 A: warnings appear in the run-time error log
331 does it fail to load? if so, then we need to generate different features, perhaps
332 one feature for each plug or else we need to know more about the project
333 distro structure to know which plug-ins to put in each feature
334 what happens if those plug-ins are later added - does it load the strings now?
335 A: probably not
3363. need to handle different versions of each feature/plugin/platform; generate different
337 language packs for each
338*/
339
gobrienb854dcb2008-01-30 18:50:45 +0000340$alloutput = fopen($base_out_dir."langpack_output_".date("m_d_Y"), "w" );
341fwrite( $alloutput,ob_get_contents());
342?>