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 |
droy | 133e746 | 2008-05-13 17:37:24 +0000 | [diff] [blame] | 11 | * Motoki MORT mori-m@mxa.nes.nec.co.jp - patch, bug 227366 |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 12 | * Kit Lo (IBM) - patch, bug 217339, generate pseudo translations language packs |
| 13 | * Kit Lo (IBM) - patch, bug 234430, need language packs by means of other than update site |
kitlo | 7f52267 | 2008-10-21 14:15:54 +0000 | [diff] [blame] | 14 | * Kit Lo (IBM) - patch, bug 251536, newline char missing after copyright comment on first line |
kitlo | 1173dbd | 2008-10-21 15:58:36 +0000 | [diff] [blame] | 15 | * Kit Lo (IBM) - patch, bug 238580, language packs should not include strings that are marked "non-translatable" |
kitlo | 5c9da71 | 2008-10-27 12:45:40 +0000 | [diff] [blame^] | 16 | * Kit Lo (IBM) - patch, bug 252140, Illegal token characters in babel fragment names |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 17 | *******************************************************************************/ |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 18 | |
| 19 | /* |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 20 | * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 21 | */ |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 22 | |
droy | b6e25c7 | 2008-07-18 13:01:13 +0000 | [diff] [blame] | 23 | ob_start(); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 24 | ini_set("memory_limit", "64M"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 25 | define("BABEL_BASE_DIR", "../../"); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 26 | require(BABEL_BASE_DIR . "html/common_functions.php"); |
| 27 | require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php"); |
kitlo | 399df20 | 2008-09-30 15:32:25 +0000 | [diff] [blame] | 28 | $dbc = new DBConnection(); |
| 29 | $dbh = $dbc->connect(); |
droy | b6e25c7 | 2008-07-18 13:01:13 +0000 | [diff] [blame] | 30 | |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 31 | $work_dir = "/home/babel-working/"; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 32 | if (!($ini = @parse_ini_file(BABEL_BASE_DIR . "classes/base.conf"))) { |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 33 | errorLog("Failed to find/read database conf file - aborting."); |
| 34 | exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found"); |
| 35 | } |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 36 | $context = $ini['context']; |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 37 | |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 38 | $work_context_dir = $work_dir . $context . "/"; |
| 39 | $tmp_dir = $work_context_dir . "tmp/"; |
| 40 | $babel_language_packs_dir = $work_context_dir . "babel_language_packs/"; |
| 41 | $output_dir = $work_context_dir . "output/"; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 42 | $source_files_dir = "source_files_for_generate/"; |
gobrien | b854dcb | 2008-01-30 18:50:45 +0000 | [diff] [blame] | 43 | |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 44 | $leader = ". . "; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 45 | $timestamp = date("Ymdhis"); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 46 | |
droy | d157aac | 2008-10-07 21:14:33 +0000 | [diff] [blame] | 47 | $rm_command = "rm -rf $work_dir" . "*"; |
| 48 | exec($rm_command); |
droy | 082976e | 2008-10-07 21:02:23 +0000 | [diff] [blame] | 49 | exec("mkdir -p $output_dir"); |
| 50 | |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 51 | /* |
| 52 | * Create language pack links file |
| 53 | */ |
| 54 | exec("mkdir -p $babel_language_packs_dir"); |
| 55 | $language_pack_links_file = fopen("${babel_language_packs_dir}index.html", "w"); |
| 56 | fwrite($language_pack_links_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" . |
| 57 | "\n<html>\n<head>\n<title>Babel Language Packs</title>" . |
| 58 | "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" . |
| 59 | "\n<body>\n\t<h1>Babel Language Packs</h1>" . |
| 60 | "\n\t<h2>Build ID: $timestamp</h2>"); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 61 | |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 62 | echo "Generating update site\n"; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 63 | $train_result = mysql_query("SELECT DISTINCT train_id FROM release_train_projects"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 64 | while (($train_row = mysql_fetch_assoc($train_result)) != null) { |
| 65 | $train_id = $train_row['train_id']; |
| 66 | $train_version = "3.4.0"; |
| 67 | if (strcmp($train_id, "europa") == 0) { |
| 68 | $train_version = "3.3.0"; |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 69 | } |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 70 | $train_version_timestamp = "$train_version.v$timestamp"; |
| 71 | $site_xml = ""; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 72 | |
| 73 | $output_dir_for_train = $output_dir . $train_row['train_id'] . "/"; |
| 74 | exec("mkdir $output_dir_for_train"); |
| 75 | exec("mkdir ${output_dir_for_train}features/"); |
| 76 | exec("mkdir ${output_dir_for_train}plugins/"); |
| 77 | |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 78 | fwrite($language_pack_links_file, "\n\t<h3>Release Train: $train_id</h3>\n\t<ul>"); |
| 79 | |
| 80 | $language_result = mysql_query("SELECT * FROM languages WHERE languages.is_active"); |
| 81 | while (($language_row = mysql_fetch_assoc($language_result)) != null) { |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 82 | $language_name = $language_row['name']; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 83 | $language_iso = $language_row['iso_code']; |
| 84 | $language_locale = $language_row['locale']; |
| 85 | $language_id = $language_row['language_id']; |
| 86 | if (strcmp($language_iso, "en") == 0) { |
| 87 | $language_iso = "en_AA"; |
| 88 | $language_name = "Pseudo Translations"; |
| 89 | } |
| 90 | if ($language_locale != null) { |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 91 | $language_name = $language_locale . " " . $language_name; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 92 | } |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 93 | |
| 94 | $site_xml .= "\n\t<category-def name=\"Babel Language Packs in $language_name\" label=\"Babel Language Packs in $language_name\">"; |
| 95 | $site_xml .= "\n\t\t<description>Babel Language Packs in $language_name</description>"; |
| 96 | $site_xml .= "\n\t</category-def>"; |
| 97 | |
| 98 | fwrite($language_pack_links_file, "\n\t<h4>Language: $language_name</h4>\n\t<ul>"); |
| 99 | |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 100 | echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n"; |
| 101 | |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 102 | /* |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 103 | * Determine which plug-ins need to be in this language pack. |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 104 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 105 | if (strcmp($language_iso, "en_AA") == 0) { |
| 106 | $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name |
| 107 | FROM files AS f |
| 108 | INNER JOIN strings AS s ON f.file_id = s.file_id |
| 109 | INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version) |
| 110 | WHERE f.is_active |
| 111 | AND v.train_id = '" . $train_row['train_id'] . "'"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 112 | } else { |
| 113 | $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name |
| 114 | FROM files AS f |
| 115 | INNER JOIN strings AS s ON f.file_id = s.file_id |
| 116 | INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active) |
| 117 | INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version) |
| 118 | WHERE t.language_id = " . $language_id . " |
| 119 | AND f.is_active |
| 120 | AND v.train_id = '" . $train_row['train_id'] . "'"); |
| 121 | } |
| 122 | |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 123 | $plugins = array(); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 124 | $projects = array(); |
| 125 | $project_versions = array(); |
| 126 | $pseudo_translations_indexes = array(); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 127 | while (($file_row = mysql_fetch_assoc($file_result)) != null) { |
| 128 | # save original filename |
| 129 | $file_row['origname'] = $file_row['name']; |
| 130 | |
droy | 02c430a | 2008-06-02 19:42:08 +0000 | [diff] [blame] | 131 | # strip useless CVS structure before the plugin name (bug 221675 c14): |
| 132 | $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i'; |
| 133 | $replace = '${2}.${3}${4}.properties'; |
| 134 | $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 135 | |
droy | 02c430a | 2008-06-02 19:42:08 +0000 | [diff] [blame] | 136 | # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin) |
| 137 | $pattern = '/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9\._-]+)(.*)\/(\1)([\.\/])(\2)([\.\/])(.*)\.properties$/i'; |
| 138 | $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties'; |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 139 | $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 140 | |
| 141 | if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) { |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 142 | $file_row['subname'] = $matches[2]; |
| 143 | $plugins[$matches[1]][] = $file_row; |
| 144 | } else { |
| 145 | echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n"; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 146 | } |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 147 | } |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 148 | |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 149 | /* |
| 150 | * Generate one plug-in fragment for each plug-in |
| 151 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 152 | foreach ($plugins as $plugin_name => $plugin_row) { |
| 153 | echo "${leader}${leader}Generating plug-in fragment $plugin_name\n"; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 154 | /* |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 155 | * Clean and create the temporary directory |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 156 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 157 | if (file_exists($tmp_dir)) { |
| 158 | exec("rm -rf $tmp_dir; mkdir $tmp_dir"); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 159 | } else { |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 160 | exec("mkdir $tmp_dir"); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 161 | } |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 162 | /* |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 163 | * Generate each *.properties file |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 164 | */ |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 165 | foreach ($plugin_row as $properties_file) { |
| 166 | /* |
| 167 | * Convert the filename to *_lang.properties, e.g., foo_fr.properties |
| 168 | */ |
| 169 | $filename = $properties_file['subname']; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 170 | if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) { |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 171 | $filename = $matches[1] . '_' . $language_iso . '.properties'; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 172 | } |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 173 | echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n"; |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 174 | /* |
| 175 | * Create any needed sub-directories |
| 176 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 177 | $fullpath = $tmp_dir . $filename; |
| 178 | preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches); |
| 179 | exec("mkdir -p \"" . $matches[1] . "\""); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 180 | /* |
| 181 | * Start writing to the file |
| 182 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 183 | $outp = fopen($fullpath, "w"); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 184 | fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 185 | if (strcmp($language_iso, "en_AA") == 0) { |
| 186 | $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] . |
| 187 | " AND is_active AND non_translatable = 0"; |
| 188 | $strings_result = mysql_query($sql); |
| 189 | while (($strings_row = mysql_fetch_assoc($strings_result)) != null) { |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 190 | fwrite($outp, "\n" . $strings_row['name'] . "=" . $properties_file['project_id'] . $strings_row['string_id'] . |
| 191 | ":" . $strings_row['value']); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 192 | |
| 193 | $value = htmlspecialchars($strings_row['value']); |
| 194 | if (strlen($value) > 100) { |
| 195 | $value = substr($value, 0, 100) . " ..."; |
| 196 | } |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 197 | $pseudo_translations_indexes[$properties_file['project_id']][] = "\n\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" . |
| 198 | $properties_file['project_id'] . "&version=" . $properties_file['version'] . "&file=" . |
| 199 | $properties_file['origname'] . "&string=" . $strings_row['name'] . "\">" . |
| 200 | $properties_file['project_id'] . $strings_row['string_id'] . "</a> " . $value . "</li>"; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 201 | } |
| 202 | } else { |
| 203 | $sql = "SELECT |
| 204 | strings.name AS 'key', |
| 205 | strings.value AS orig, |
| 206 | translations.value AS trans |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 207 | FROM strings, translations |
| 208 | WHERE strings.string_id = translations.string_id |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 209 | AND strings.file_id = " . $properties_file['file_id'] . " |
kitlo | 1173dbd | 2008-10-21 15:58:36 +0000 | [diff] [blame] | 210 | AND strings.is_active |
| 211 | AND strings.non_translatable = 0 |
| 212 | AND translations.language_id = " . $language_id . " |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 213 | AND translations.is_active"; |
| 214 | $strings_result = mysql_query($sql); |
| 215 | while (($strings_row = mysql_fetch_assoc($strings_result)) != null) { |
kitlo | 7f52267 | 2008-10-21 14:15:54 +0000 | [diff] [blame] | 216 | fwrite($outp, "\n" . $strings_row['key'] . "="); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 217 | # echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "="; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 218 | if ($strings_row['trans']) { |
| 219 | # json_encode returns the string with quotes fore and aft. Need to strip them. |
| 220 | # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans'])); |
| 221 | # $tr_string = str_replace('\\\\', '\\', $tr_string); |
| 222 | $tr_string = toescapedunicode($strings_row['trans']); |
| 223 | fwrite($outp, $tr_string); |
| 224 | # echo $strings_row['trans']; |
| 225 | } else { |
| 226 | fwrite($outp, $strings_row['orig']); |
| 227 | } |
| 228 | fwrite($outp, "\n"); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 229 | } |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 230 | } |
| 231 | /* |
| 232 | * Finish the properties file |
| 233 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 234 | fclose($outp); |
| 235 | echo "${leader}${leader}${leader}Completed properties file $filename\n"; |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 236 | } |
| 237 | /* |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 238 | * Copy in the various legal files |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 239 | */ |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 240 | exec("cp ${source_files_dir}about.html $tmp_dir"); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 241 | /* |
| 242 | * Generate the META-INF/MANIFEST.MF file |
| 243 | */ |
| 244 | $parent_plugin_id = $plugin_name; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 245 | $project_id = $properties_file['project_id']; |
kitlo | 5c9da71 | 2008-10-27 12:45:40 +0000 | [diff] [blame^] | 246 | $fragment_id = "$parent_plugin_id.nl_$language_iso"; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 247 | $fragment_filename = "${fragment_id}_$train_version_timestamp.jar"; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 248 | |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 249 | $plugins[$plugin_name]['id'] = $fragment_id; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 250 | $plugins[$plugin_name]['version'] = $train_version_timestamp; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 251 | |
| 252 | exec("mkdir $tmp_dir/META-INF" ); |
| 253 | $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w"); |
| 254 | fwrite($outp, "Manifest-Version: 1.0\n"); |
| 255 | fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n"); |
| 256 | fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n"); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 257 | fwrite($outp, "Bundle-Version: $train_version_timestamp\n"); |
| 258 | fwrite($outp, "Bundle-Vendor: Eclipse.org\n"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 259 | fwrite($outp, "Fragment-Host: $parent_plugin_id\n"); |
| 260 | fclose($outp); |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 261 | /* |
| 262 | * Jar up this directory as the fragment plug-in jar |
| 263 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 264 | system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename ."); |
| 265 | echo "${leader}${leader}Completed plug-in fragment $plugin_name\n"; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 266 | |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 267 | $projects[$project_id][] = $fragment_id; |
| 268 | $project_versions[$project_id] = $properties_file['version']; |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 269 | } |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 270 | foreach ($projects as $project_id => $fragment_ids) { |
| 271 | /* |
| 272 | * Sort fragment names |
| 273 | */ |
| 274 | asort($fragment_ids); |
| 275 | /* |
| 276 | * Create ${babel_language_packs_dir}tmp |
| 277 | */ |
| 278 | exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features"); |
| 279 | exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/plugins"); |
| 280 | /* |
| 281 | * Clean and create the temporary directory |
| 282 | */ |
| 283 | if (file_exists($tmp_dir)) { |
| 284 | exec("rm -rf $tmp_dir; mkdir $tmp_dir"); |
| 285 | } else { |
| 286 | exec("mkdir $tmp_dir"); |
| 287 | } |
| 288 | /* |
| 289 | * Create the feature.xml |
| 290 | * |
| 291 | * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented |
| 292 | * |
| 293 | * <url> |
| 294 | * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" /> |
| 295 | * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" /> |
| 296 | * </url> |
| 297 | */ |
kitlo | 5c9da71 | 2008-10-27 12:45:40 +0000 | [diff] [blame^] | 298 | $feature_id = "org.eclipse.babel.nls_${project_id}_$language_iso"; |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 299 | $feature_version = "$train_version.v$timestamp"; |
| 300 | $feature_filename = "${feature_id}_$train_version_timestamp.jar"; |
| 301 | |
| 302 | $project_version = $project_versions[$project_id]; |
| 303 | $sql = "SELECT pct_complete |
| 304 | FROM project_progress |
| 305 | WHERE project_id = \"$project_id\" |
| 306 | AND version = \"$project_version\" |
| 307 | AND language_id = $language_id"; |
| 308 | $project_pct_complete_result = mysql_query($sql); |
| 309 | $project_pct_complete = mysql_result($project_pct_complete_result, 0); |
| 310 | if (strcmp($language_iso, "en_AA") == 0) { |
| 311 | $project_pct_complete = 100; |
| 312 | } |
| 313 | |
| 314 | $outp = fopen("$tmp_dir/feature.xml", "w"); |
| 315 | fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" . |
| 316 | "\n<feature" . |
| 317 | "\n\tid=\"$feature_id\"" . |
| 318 | "\n\tlabel=\"Babel Language Pack for $project_id in $language_name ($project_pct_complete%)\"" . |
| 319 | "\n\timage=\"eclipse_update_120.jpg\"" . |
| 320 | "\n\tprovider-name=\"%providerName\"" . |
| 321 | "\n\tversion=\"$train_version_timestamp\">" . |
| 322 | "\n\t<copyright>\n\t\t%copyright\n\t</copyright>" . |
| 323 | "\n\t<license url=\"%licenseURL\">\n\t\t%license\n\t</license>" . |
| 324 | "\n\t<description>Babel Language Pack for $project_id in $language_name</description>" ); |
| 325 | foreach ($fragment_ids as $fragment_id) { |
| 326 | $jar_name = "${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar"; |
| 327 | $size = filesize($jar_name); |
| 328 | fwrite($outp, "\n\t<plugin fragment=\"true\" id=\"$fragment_id\" unpack=\"false\" " . |
| 329 | "version=\"$train_version_timestamp\" download-size=\"$size\" install-size=\"$size\" />"); |
| 330 | /* |
| 331 | * Copy the plugin to ${babel_language_packs_dir}tmp |
| 332 | */ |
| 333 | exec("cp ${output_dir_for_train}plugins/${fragment_id}_$train_version_timestamp.jar ${babel_language_packs_dir}tmp/eclipse/plugins"); |
| 334 | } |
| 335 | fwrite($outp, "\n</feature>"); |
| 336 | fclose($outp); |
| 337 | /* |
| 338 | * Copy in the various legal files |
| 339 | */ |
| 340 | exec("cp ${source_files_dir}about.html $tmp_dir"); |
| 341 | exec("cp ${source_files_dir}eclipse_update_120.jpg $tmp_dir"); |
| 342 | exec("cp ${source_files_dir}epl-v10.html $tmp_dir"); |
| 343 | exec("cp ${source_files_dir}feature.properties $tmp_dir"); |
| 344 | exec("cp ${source_files_dir}license.html $tmp_dir"); |
| 345 | /* |
| 346 | * Copy in the Babel Pseudo Translations Index file |
| 347 | */ |
| 348 | if (strcmp($language_iso, "en_AA") == 0) { |
| 349 | $pseudo_translations_index_file = fopen("${output_dir}BabelPseudoTranslationsIndex-$project_id.html", "w"); |
| 350 | fwrite($pseudo_translations_index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">" . |
| 351 | "\n<html>\n<head>\n<title>Babel Pseudo Translations Index for $project_id</title>" . |
| 352 | "\n<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>" . |
| 353 | "\n<body>\n\t<h1>Babel Pseudo Translations Index for $project_id</h1>" . |
| 354 | "\n\t<h2>Version: $train_version_timestamp</h2>\n\t<ul>"); |
| 355 | foreach ($pseudo_translations_indexes[$project_id] as $index) { |
| 356 | fwrite($pseudo_translations_index_file, $index); |
| 357 | } |
| 358 | fwrite($pseudo_translations_index_file, "\n\t</ul>\n</body>\n</html>"); |
| 359 | fclose($pseudo_translations_index_file); |
| 360 | exec("cp ${output_dir}BabelPseudoTranslationsIndex-$project_id.html $tmp_dir"); |
| 361 | exec("rm ${output_dir}BabelPseudoTranslationsIndex-$project_id.html"); |
| 362 | } |
| 363 | /* |
| 364 | * Copy the feature to ${babel_language_packs_dir}tmp before jar'ing up |
| 365 | */ |
| 366 | exec("mkdir -p ${babel_language_packs_dir}tmp/eclipse/features/${fragment_id}_$train_version_timestamp"); |
| 367 | exec("cd $tmp_dir; cp * ${babel_language_packs_dir}tmp/eclipse/features/${fragment_id}_$train_version_timestamp"); |
| 368 | /* |
| 369 | * Zip up language pack |
| 370 | */ |
| 371 | $language_pack_name = "BabelLanguagePack-$project_id-${language_iso}_$train_version_timestamp.zip"; |
| 372 | exec("cd ${babel_language_packs_dir}tmp; zip -r $babel_language_packs_dir$language_pack_name eclipse"); |
| 373 | /* |
| 374 | * Clean up ${babel_language_packs_dir}tmp |
| 375 | */ |
| 376 | exec("rm -rf ${babel_language_packs_dir}tmp"); |
| 377 | /* |
| 378 | * Add project language pack link to language pack links file |
| 379 | */ |
| 380 | fwrite($language_pack_links_file, "\n\t<li><a href=\"$language_pack_name\">$language_pack_name</a></li>"); |
| 381 | /* |
| 382 | * Jar up this directory as the feature jar |
| 383 | */ |
| 384 | system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename ."); |
| 385 | /* |
| 386 | * Register this feature with the site.xml |
| 387 | */ |
| 388 | $site_xml .= "\n\t<feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">"; |
| 389 | $site_xml .= "\n\t\t<category name=\"Babel Language Packs in $language_name\"/>"; |
| 390 | $site_xml .= "\n\t</feature>"; |
| 391 | echo "${leader}Completed language pack for $language_name ($language_iso)\n"; |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 392 | } |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 393 | fwrite($language_pack_links_file, "\n\t</ul>"); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 394 | } |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 395 | /* |
droy | 0b08d29 | 2008-05-28 15:18:11 +0000 | [diff] [blame] | 396 | * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site> |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 397 | */ |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 398 | $outp = fopen("${output_dir_for_train}site.xml", "w"); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 399 | fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . |
| 400 | "\n<site>" . |
| 401 | "\n\t<description url=\"http://babel.eclipse.org/\">" . |
| 402 | "\n\t\tThis update site contains user-contributed translations of the strings in all Eclipse projects." . |
| 403 | "\n\t\tPlease see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of" . |
| 404 | "\n\t\tthese translations as well as how you can contribute to the translations of this and future versions of Eclipse." . |
| 405 | "\n\t</description>"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 406 | fwrite($outp, $site_xml); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 407 | fwrite($outp, "\n</site>"); |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 408 | fclose($outp); |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 409 | |
| 410 | fwrite($language_pack_links_file, "\n\t</ul>"); |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 411 | } |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 412 | echo "Completed generating update site\n"; |
| 413 | |
kitlo | 9c7c62a | 2008-10-05 16:05:19 +0000 | [diff] [blame] | 414 | fwrite($language_pack_links_file, "\n</body>\n</html>"); |
| 415 | fclose($language_pack_links_file); |
| 416 | |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 417 | /* |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 418 | 2. what happens if the translation feature includes plug-in fragments for |
| 419 | plug-ins that are not in the current image? |
| 420 | does it load correctly and ignore those fragments? if so, good |
| 421 | A: warnings appear in the run-time error log |
| 422 | does it fail to load? if so, then we need to generate different features, perhaps |
| 423 | one feature for each plug or else we need to know more about the project |
| 424 | distro structure to know which plug-ins to put in each feature |
| 425 | what happens if those plug-ins are later added - does it load the strings now? |
| 426 | A: probably not |
| 427 | 3. need to handle different versions of each feature/plugin/platform; generate different |
| 428 | language packs for each |
| 429 | */ |
gobrien | 1a8e02f | 2008-01-30 01:46:26 +0000 | [diff] [blame] | 430 | |
kitlo | 58d8a5a | 2008-09-24 20:08:44 +0000 | [diff] [blame] | 431 | $alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w"); |
| 432 | fwrite($alloutput,ob_get_contents()); |
kitlo | 399df20 | 2008-09-30 15:32:25 +0000 | [diff] [blame] | 433 | ?> |