kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame^] | 1 | <?php |
| 2 | /******************************************************************************* |
| 3 | * Copyright (c) 2010 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 | * Kit Lo (IBM) - Initial API and implementation |
| 11 | * Kit Lo (IBM) - Bug 299402, Extract properties files from Eclipse project update sites for translation |
| 12 | *******************************************************************************/ |
| 13 | /* |
| 14 | * Extract properties files from update sites |
| 15 | */ |
| 16 | # To-do: hard-coding the Eclipse, BIRT, & Webtools update sites for now; need to create an UI for project committers to enter their update sites |
| 17 | $eclipse = array("/home/data/httpd/download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301", "eclipse", "3.6"); |
| 18 | $birt = array("/home/data/httpd/download.eclipse.org/birt/update-site/2.6-interim", "birt", "2.6.0"); |
| 19 | $webtools = array("/home/data/httpd/download.eclipse.org/webtools/updates", "webtools", "3.2"); |
| 20 | |
| 21 | # BIRT 2.6.0 & Webtools 3.2 are not defined yet, cannot test on staging server |
| 22 | #$update_sites = array($eclipse, $birt, $webtools); |
| 23 | $update_sites = array($eclipse); |
| 24 | |
| 25 | $temp_dir = "/tmp/tmp-babel/"; |
| 26 | $debug = TRUE; |
| 27 | |
| 28 | header("Content-type: text/plain"); |
| 29 | include("global.php"); |
| 30 | InitPage(""); |
| 31 | |
| 32 | $headless = 0; |
| 33 | if (!isset($User)) { |
| 34 | echo "User not defined - running headless\n"; |
| 35 | $User = getGenieUser(); |
| 36 | $headless = 1; |
| 37 | } |
| 38 | |
| 39 | require(dirname(__FILE__) . "/../classes/file/file.class.php"); |
| 40 | global $dbh; |
| 41 | |
| 42 | if (is_dir($temp_dir)) { |
| 43 | exec("rm -rf $temp_dir"); |
| 44 | } |
| 45 | mkdir($temp_dir) || die("***ERROR: Cannot create working directory $temp_dir\n"); |
| 46 | |
| 47 | $files = array(); |
| 48 | $sql = "SELECT * FROM files WHERE is_active = 1"; |
| 49 | $rs_files = mysql_query($sql, $dbh); |
| 50 | while ($myrow_files = mysql_fetch_assoc($rs_files)) { |
| 51 | $file = new File(); |
| 52 | $file->project_id = $myrow_files['project_id']; |
| 53 | $file->version = $myrow_files['version']; |
| 54 | $file->name = $myrow_files['name']; |
| 55 | $file->plugin_id = $myrow_files['plugin_id']; |
| 56 | $file->file_id = $myrow_files['file_id']; |
| 57 | $files[$file->file_id] = $file; |
| 58 | } |
| 59 | |
| 60 | foreach ($update_sites as $update_site) { |
| 61 | $plugins_dir = $update_site[0] . "/plugins/"; |
| 62 | $project_id = $update_site[1]; |
| 63 | $version = $update_site[2]; |
| 64 | |
| 65 | chdir($plugins_dir); |
| 66 | foreach (glob("*.jar") as $jar_name) { |
| 67 | # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar |
| 68 | # |
| 69 | # Remove plugin version from jar name: |
| 70 | # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench |
| 71 | $temp_str = $jar_name; |
| 72 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 73 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 74 | $temp_str = substr($temp_str, 0, strrpos($temp_str, "_")); |
| 75 | $plugin_id = $temp_str; |
| 76 | |
| 77 | mkdir($temp_dir . $project_id); |
| 78 | mkdir($temp_dir . $project_id . "/" . $version); |
| 79 | mkdir($temp_dir . $project_id . "/" . $version . "/" . $plugin_id); |
| 80 | chdir($temp_dir . $project_id . "/" . $version . "/" . $plugin_id); |
| 81 | exec("unzip -o -q " . $plugins_dir . $jar_name . " *.properties"); |
| 82 | } |
| 83 | |
| 84 | $properties_file_names = array(); |
| 85 | chdir($temp_dir . $project_id . "/" . $version); |
| 86 | exec("find . -name *.properties", $properties_file_names); |
| 87 | sort($properties_file_names); |
| 88 | |
| 89 | echo "Start processing properties files in project $project_id version $version...\n"; |
| 90 | foreach ($properties_file_names as $properties_file_name) { |
| 91 | $properties_file_name = substr($properties_file_name, 2); |
| 92 | $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/")); |
| 93 | $file_id = File::getFileID($properties_file_name, $project_id, $version); |
| 94 | |
| 95 | if ($files[$file_id] != null) { |
| 96 | $file = $files[$file_id]; |
| 97 | $file->is_active = 1; |
| 98 | unset($files[$file_id]); |
| 99 | } else { |
| 100 | $file = new File(); |
| 101 | $file->project_id = $project_id; |
| 102 | $file->version = $version; |
| 103 | $file->name = $properties_file_name; |
| 104 | $file->plugin_id = $plugin_id; |
| 105 | $file->is_active = 1; |
| 106 | } |
| 107 | if (!$file->save()) { |
| 108 | echo "***ERROR: Cannot save file $file->name\n"; |
| 109 | } else { |
| 110 | $file_name = $temp_dir . $project_id . "/" . $version . "/" . $properties_file_name; |
| 111 | $file->parseProperties(file_get_contents($file_name)); |
| 112 | if ($debug) { |
| 113 | echo " " . $file->name . "\n"; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n"; |
| 118 | } |
| 119 | |
| 120 | # Deactivate the rest of the files |
| 121 | foreach ($files as $file) { |
| 122 | $file->is_active = 0; |
| 123 | if (!$file->save()) { |
| 124 | echo "***ERROR: Cannot deactivate file $file->name\n"; |
| 125 | } |
| 126 | if ($debug) { |
| 127 | echo " " . $file->name . "\n"; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if ($headless) { |
| 132 | $User = null; |
| 133 | } |
| 134 | |
| 135 | echo "Done\n"; |
| 136 | ?> |