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 | */ |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 16 | $temp_dir = "/tmp/tmp-babel/"; |
kitlo | 3efbb26 | 2010-01-13 15:18:57 +0000 | [diff] [blame] | 17 | $files = array(); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 18 | |
| 19 | header("Content-type: text/plain"); |
| 20 | include("global.php"); |
| 21 | InitPage(""); |
| 22 | |
| 23 | $headless = 0; |
| 24 | if (!isset($User)) { |
| 25 | echo "User not defined - running headless\n"; |
| 26 | $User = getGenieUser(); |
| 27 | $headless = 1; |
| 28 | } |
| 29 | |
| 30 | require(dirname(__FILE__) . "/../classes/file/file.class.php"); |
| 31 | global $dbh; |
| 32 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 33 | $temp_unzips_dir = $temp_dir . "unzips/"; |
| 34 | if (is_dir($temp_unzips_dir)) { |
| 35 | exec("rm -rf $temp_unzips_dir"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 36 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 37 | mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n"); |
| 38 | |
| 39 | global $addon; |
| 40 | $context = $addon->callHook('context'); |
| 41 | if ($context == "live") { |
| 42 | $rsync_host = "download.eclipse.org::eclipseMirror/"; |
| 43 | } else { |
| 44 | $rsync_host = "rsync.osuosl.org::eclipse/"; |
| 45 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 46 | |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 47 | # Get all active update sites |
| 48 | $sql = "SELECT * FROM map_files WHERE is_active = 1 AND is_map_file = 0"; |
| 49 | $rs_maps = mysql_query($sql, $dbh); |
| 50 | while($update_site = mysql_fetch_assoc($rs_maps)) { |
| 51 | $site_url = $update_site['location']; |
| 52 | $project_id = $update_site['project_id']; |
| 53 | $version = $update_site['version']; |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 54 | # Sample dirs: |
| 55 | # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301 |
| 56 | # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/ |
| 57 | # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/ |
| 58 | # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/ |
| 59 | # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/ |
| 60 | $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1) . "/"; |
| 61 | $site_plugins_dir = $site_dir . "/plugins/"; |
| 62 | $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/"; |
| 63 | $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 64 | |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 65 | # Get all current active files for this project version |
kitlo | 3efbb26 | 2010-01-13 15:18:57 +0000 | [diff] [blame] | 66 | $sql = "SELECT * FROM files WHERE is_active = 1 AND project_id = \"$project_id\" AND version = \"$version\""; |
| 67 | $rs_files = mysql_query($sql, $dbh); |
| 68 | while ($myrow_files = mysql_fetch_assoc($rs_files)) { |
| 69 | $file = new File(); |
| 70 | $file->project_id = $myrow_files['project_id']; |
| 71 | $file->version = $myrow_files['version']; |
| 72 | $file->name = $myrow_files['name']; |
| 73 | $file->plugin_id = $myrow_files['plugin_id']; |
| 74 | $file->file_id = $myrow_files['file_id']; |
| 75 | $files[$file->file_id] = $file; |
| 76 | } |
| 77 | |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 78 | # Get all plugin exclude patterns for this project version |
| 79 | $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\""; |
| 80 | $rs_patterns = mysql_query($sql, $dbh); |
| 81 | $patterns = Array(); |
| 82 | while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) { |
| 83 | $patterns[] = $myrow_patterns['pattern']; |
| 84 | } |
| 85 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 86 | # Rsync update site |
| 87 | exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir"); |
| 88 | |
| 89 | # Make unzip dir |
| 90 | mkdir($temp_unzip_dir, 0777, TRUE); |
| 91 | |
| 92 | # Unzip properties files in each jar |
| 93 | chdir($temp_site_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 94 | foreach (glob("*.jar") as $jar_name) { |
| 95 | # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar |
| 96 | # |
| 97 | # Remove plugin version from jar name: |
| 98 | # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench |
| 99 | $temp_str = $jar_name; |
| 100 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 101 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 102 | $temp_str = substr($temp_str, 0, strrpos($temp_str, "_")); |
| 103 | $plugin_id = $temp_str; |
| 104 | |
kitlo | 20071c5 | 2010-01-13 14:10:52 +0000 | [diff] [blame] | 105 | if (!is_dir($temp_unzip_dir . $plugin_id)) { |
| 106 | mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE); |
| 107 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 108 | chdir($temp_unzip_dir . $plugin_id); |
kitlo | 281a641 | 2010-01-13 13:34:57 +0000 | [diff] [blame] | 109 | exec("unzip -o -q $temp_site_dir$jar_name"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 110 | } |
| 111 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 112 | # Collect properties file names |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 113 | $properties_file_names = array(); |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 114 | chdir($temp_unzip_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 115 | exec("find . -name *.properties", $properties_file_names); |
| 116 | sort($properties_file_names); |
| 117 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 118 | # Parse each properties file |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 119 | echo "Start processing properties files in project $project_id version $version...\n"; |
| 120 | foreach ($properties_file_names as $properties_file_name) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 121 | # Remove "./" from beginning of properties file name |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 122 | $properties_file_name = substr($properties_file_name, 2); |
| 123 | $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/")); |
| 124 | $file_id = File::getFileID($properties_file_name, $project_id, $version); |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 125 | |
| 126 | # Match plugin exclude list |
| 127 | $match = false; |
| 128 | foreach ($patterns as $pattern) { |
| 129 | if (preg_match($pattern, $properties_file_name)) { |
| 130 | $match = true; |
| 131 | break; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 134 | |
| 135 | if (!$match) { |
kitlo | b746da4 | 2010-02-12 02:40:41 +0000 | [diff] [blame] | 136 | if ($file_id > 0 && $files[$file_id] != null) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 137 | # Existing file |
| 138 | $file = $files[$file_id]; |
| 139 | $file->is_active = 1; |
| 140 | unset($files[$file_id]); |
| 141 | } else { |
| 142 | # New file |
| 143 | $file = new File(); |
| 144 | $file->project_id = $project_id; |
| 145 | $file->version = $version; |
| 146 | $file->name = $properties_file_name; |
| 147 | $file->plugin_id = $plugin_id; |
| 148 | $file->is_active = 1; |
| 149 | } |
| 150 | if (!$file->save()) { |
| 151 | echo "***ERROR: Cannot save file $file->name\n"; |
| 152 | } else { |
| 153 | $file_name = $temp_unzip_dir . $properties_file_name; |
| 154 | $file->parseProperties(file_get_contents($file_name)); |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame^] | 155 | echo " $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 156 | } |
| 157 | } else { |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame^] | 158 | echo " !!! Excluding $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 161 | echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n"; |
| 162 | } |
| 163 | |
| 164 | # Deactivate the rest of the files |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 165 | echo "Start deactivating inactive properties files in all projects above...\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 166 | foreach ($files as $file) { |
| 167 | $file->is_active = 0; |
| 168 | if (!$file->save()) { |
| 169 | echo "***ERROR: Cannot deactivate file $file->name\n"; |
| 170 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 171 | echo " " . $file->name . "\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 172 | } |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 173 | echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 174 | |
kitlo | 59274fb | 2010-02-12 03:31:34 +0000 | [diff] [blame] | 175 | if (is_dir($temp_unzips_dir)) { |
| 176 | exec("rm -rf $temp_unzips_dir"); |
| 177 | } |
| 178 | |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 179 | if ($headless) { |
| 180 | $User = null; |
| 181 | } |
| 182 | |
| 183 | echo "Done\n"; |
| 184 | ?> |