gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 1 | <?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 | */ |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 21 | ob_start(); |
| 22 | |
| 23 | |
| 24 | if(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 | |
| 31 | if (!($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']; |
| 37 | if($context == "") { |
| 38 | $context = "staging"; |
| 39 | } |
| 40 | global $context; |
| 41 | |
| 42 | |
| 43 | $base_out_dir = "/home/babel-working/"; |
| 44 | |
| 45 | if(!file_exists($base_out_dir)){ |
| 46 | $base_out_dir = ""; |
| 47 | } |
| 48 | |
| 49 | if($context == "live"){ |
| 50 | $base_out_dir .= "live/"; |
| 51 | }else{ |
| 52 | $base_out_dir .= "staging/"; |
| 53 | } |
| 54 | if( !file_exists( $base_out_dir ) ) { |
| 55 | exec( "mkdir $base_out_dir" ); |
| 56 | } |
| 57 | |
| 58 | $temporary_dir = $base_out_dir."tmp_generated/"; |
gobrien | 431ca4f | 2008-01-30 19:54:00 +0000 | [diff] [blame] | 59 | $staging_update_site = $base_out_dir."output/"; |
gobrien | e2bb07b | 2008-01-30 19:00:42 +0000 | [diff] [blame] | 60 | $source_files_for_generate = "source_files_for_generate/"; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 61 | |
| 62 | $leader1 = ""; |
| 63 | $leader1S= ""; |
| 64 | $leader = ". . "; |
| 65 | $leaderS= ". . "; |
| 66 | $generated_timestamp = date("Ymdhis"); |
| 67 | |
| 68 | /* |
| 69 | * Clear the staging site |
| 70 | */ |
| 71 | if( file_exists( $staging_update_site ) ) { |
| 72 | exec( "rm -rf $staging_update_site*" ); |
| 73 | } else { |
| 74 | exec( "mkdir $staging_update_site" ); |
| 75 | } |
| 76 | if( file_exists( "${staging_update_site}plugins/" ) ) { |
| 77 | exec( "rm -rf ${staging_update_site}plugins/*" ); |
| 78 | } else { |
| 79 | exec( "mkdir ${staging_update_site}plugins/" ); |
| 80 | } |
| 81 | if( 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 | */ |
gobrien | 08a4e4e | 2008-01-30 18:18:29 +0000 | [diff] [blame] | 89 | |
gobrien | 08a4e4e | 2008-01-30 18:18:29 +0000 | [diff] [blame] | 90 | $dbc = new DBConnection(); |
| 91 | global $dbh; |
| 92 | $dbh = $dbc->connect(); |
| 93 | |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Generate one language pack per language |
| 97 | */ |
| 98 | $site_xml = ''; |
| 99 | $language_result = mysql_query( 'SELECT * FROM languages WHERE languages.is_active' ); |
| 100 | while( ($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 ); |
droy | d841b3c | 2008-02-13 16:39:24 +0000 | [diff] [blame^] | 155 | exec( "mkdir -p \"" . $matches[1] . "\""); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 156 | /* |
| 157 | * Start writing to the file |
| 158 | */ |
| 159 | $outp = fopen( $fullpath, "w" ); |
| 160 | fwrite( $outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n" ); |
| 161 | //TODO correct copyrights from all contributors |
| 162 | /* |
| 163 | * For each string that is translated in this file, write it out |
| 164 | * Note that if a string is not translated, then it will not be |
| 165 | * included and thus Eclipse will pick up the default string for |
| 166 | * that key from the default *.properities file. Thus we only |
| 167 | * include the strings that are translated. |
| 168 | */ |
| 169 | $sql = " |
| 170 | SELECT |
| 171 | strings.name AS `key`, |
| 172 | strings.value AS orig, |
| 173 | translations.value AS trans |
| 174 | FROM strings, translations |
| 175 | WHERE strings.string_id = translations.string_id |
| 176 | AND translations.language_id = " . $language_row['language_id'] . " |
| 177 | AND strings.file_id = " . $properties_file['file_id'] . " |
| 178 | AND translations.is_active |
| 179 | "; |
| 180 | $strings_result = mysql_query( $sql ); |
| 181 | while( ($strings_row = mysql_fetch_assoc($strings_result)) != null ) { |
| 182 | fwrite( $outp, $strings_row['key'] . "=" ); |
| 183 | echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "="; |
| 184 | if( $strings_row['trans'] ) { |
| 185 | fwrite( $outp, $strings_row['trans'] ); |
| 186 | echo $strings_row['trans']; |
| 187 | } else { |
| 188 | fwrite( $outp, $strings_row['orig'] ); |
| 189 | } |
| 190 | fwrite( $outp, "\n" ); |
| 191 | echo "\n"; |
| 192 | } |
| 193 | /* |
| 194 | * Finish the properties file |
| 195 | */ |
| 196 | fclose( $outp ); |
| 197 | echo "${leader1}${leader}${leader}completed properties file $filename\n"; |
| 198 | } |
| 199 | /* |
| 200 | * Copy in the various legal files |
| 201 | */ |
| 202 | exec( "cp ${source_files_for_generate}about.html ${temporary_dir}" ); |
| 203 | exec( "cp ${source_files_for_generate}license.html ${temporary_dir}" ); |
| 204 | exec( "cp ${source_files_for_generate}epl-v10.html ${temporary_dir}" ); |
| 205 | exec( "cp ${source_files_for_generate}eclipse_update_120.jpg ${temporary_dir}" ); |
| 206 | /* |
| 207 | * Generate the META-INF/MANIFEST.MF file |
| 208 | */ |
| 209 | $parent_plugin_id = $plugin_name; |
| 210 | $fragment_id = "${parent_plugin_id}.nl_$language_iso"; |
| 211 | $fragment_major_version = "0.2.0"; //TODO what version number should these plugins be? |
| 212 | $fragment_version = $fragment_major_version . ".v" . $generated_timestamp; |
| 213 | $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar"; |
| 214 | $parent_min_version = "0.0.0"; //TODO specify a min version (when versions are supported) |
| 215 | $parent_max_version = "9.9.9"; //TODO specify a max version (when versions are supported) |
| 216 | |
| 217 | $plugins[$plugin_name]['id'] = $fragment_id; |
| 218 | $plugins[$plugin_name]['version'] = $fragment_version; |
| 219 | |
| 220 | exec( "mkdir $temporary_dir/META-INF" ); |
| 221 | $outp = fopen( "$temporary_dir/META-INF/MANIFEST.MF", "w" ); |
| 222 | fwrite( $outp, "Manifest-Version: 1.0\n"); |
| 223 | fwrite( $outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n"); |
| 224 | fwrite( $outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n"); |
| 225 | fwrite( $outp, "Bundle-Version: $fragment_version\n"); |
| 226 | fwrite( $outp, "Bundle-Vendor: Eclipse Foundation Inc.\n"); |
| 227 | fwrite( $outp, "Fragment-Host: $parent_plugin_id;bundle-version=\"[$parent_min_version,$parent_max_version)\"\n"); |
| 228 | fclose( $outp ); |
| 229 | /* |
| 230 | * Jar up this directory as the fragment plug-in jar |
| 231 | */ |
gobrien | 7bc2aa1 | 2008-01-30 19:08:06 +0000 | [diff] [blame] | 232 | system( "cd $temporary_dir; jar cfM ${staging_update_site}plugins/$fragment_filename ." ); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 233 | echo "${leader1}${leader}completed plug-in fragment $plugin_name\n"; |
| 234 | } |
| 235 | /* |
| 236 | * Clean and create the temporary directory |
| 237 | */ |
| 238 | if ( file_exists( $temporary_dir ) ) { |
| 239 | exec( "rm -rf $temporary_dir; mkdir $temporary_dir" ); |
| 240 | } else { |
| 241 | exec( "mkdir $temporary_dir" ); |
| 242 | } |
| 243 | /* |
| 244 | * Create the feature.xml |
| 245 | * |
| 246 | * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented |
| 247 | * |
| 248 | * <url> |
| 249 | * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" /> |
| 250 | * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" /> |
| 251 | * </url> |
| 252 | */ |
| 253 | $feature_id = "org.eclipse.nls.$language_iso"; |
| 254 | $feature_major_version = "0.2.0"; //TODO what version number should this feature be? |
| 255 | $feature_version = $feature_major_version . ".v" . $generated_timestamp; |
| 256 | $feature_filename = $feature_id . "_" . $feature_version . ".jar"; |
| 257 | |
| 258 | $outp = fopen( "$temporary_dir/feature.xml", "w" ); |
| 259 | fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> |
| 260 | <feature |
| 261 | id=\"$feature_id\" |
| 262 | label=\"Eclipse Language Pack for $language_name\" |
| 263 | image=\"eclipse_update_120.jpg\" |
| 264 | provider-name=\"Eclipse Foundation Inc.\" |
| 265 | version=\"$feature_version\"> |
| 266 | <license url=\"license.html\">" |
| 267 | . htmlspecialchars( file_get_contents( "${source_files_for_generate}license.txt" ) ) . "</license> |
| 268 | <description>Translations in $language_name for all Eclipse Projects</description> |
| 269 | " ); |
| 270 | foreach ($plugins as $plugin_name => $plugin_row ) { |
| 271 | fwrite( $outp, '<pluging fragment="true" id="' |
| 272 | . $plugin_row['id'] . '" unpack="false" version="' |
| 273 | . $plugin_row['version'] . '"/> |
| 274 | ' ); |
| 275 | } |
| 276 | fwrite( $outp, '</feature> |
| 277 | ' ); |
| 278 | fclose( $outp ); |
| 279 | /* |
| 280 | * Jar up this directory as the feature jar |
| 281 | */ |
gobrien | 7bc2aa1 | 2008-01-30 19:08:06 +0000 | [diff] [blame] | 282 | system( "cd $temporary_dir; jar cfM ${staging_update_site}features/$feature_filename ." ); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 283 | /* |
| 284 | * Register this feature with the site.xml |
| 285 | */ |
| 286 | $site_xml .= "<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\"> |
| 287 | <category name=\"Language Packs\"/></feature> |
| 288 | "; |
| 289 | echo "${leader1}completed language pack for $language_name ($language_iso)\n"; |
| 290 | } |
| 291 | /* |
| 292 | * TODO <site mirrorsURL=... is not yet implemented |
| 293 | */ |
| 294 | $outp = fopen( "${staging_update_site}site.xml", "w" ); |
| 295 | fwrite( $outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
| 296 | <site> |
| 297 | <description url=\"http://babel.eclipse.org/\">This update site contains |
| 298 | user-contributed translations of the strings in all Eclipse projects. Please |
| 299 | see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use |
| 300 | explanation of these translations as well as how you can contribute to |
| 301 | the translations of this and future versions of Eclipse.</description> |
| 302 | <category-def name=\"Language Packs\" label=\"Language Packs\"> |
| 303 | <description>Language packs for all Eclipse projects</description> |
| 304 | </category-def> |
| 305 | " ); |
| 306 | fwrite( $outp, $site_xml ); |
| 307 | fwrite( $outp, "</site> |
| 308 | " ); |
| 309 | fclose( $outp ); |
| 310 | |
| 311 | echo "Completed generating update site\n"; |
| 312 | |
| 313 | /* |
| 314 | 2. what happens if the translation feature includes plug-in fragments for |
| 315 | plug-ins that are not in the current image? |
| 316 | does it load correctly and ignore those fragments? if so, good |
| 317 | A: warnings appear in the run-time error log |
| 318 | does it fail to load? if so, then we need to generate different features, perhaps |
| 319 | one feature for each plug or else we need to know more about the project |
| 320 | distro structure to know which plug-ins to put in each feature |
| 321 | what happens if those plug-ins are later added - does it load the strings now? |
| 322 | A: probably not |
| 323 | 3. need to handle different versions of each feature/plugin/platform; generate different |
| 324 | language packs for each |
| 325 | */ |
| 326 | |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 327 | $alloutput = fopen($base_out_dir."langpack_output_".date("m_d_Y"), "w" ); |
| 328 | fwrite( $alloutput,ob_get_contents()); |
| 329 | ?> |