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