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