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 | 41083bd | 2010-02-16 17:17:10 +0000 | [diff] [blame] | 18 | $files_collected = array(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'); |
kitlo | a3a2ae9 | 2011-06-14 22:35:43 +0000 | [diff] [blame] | 42 | if ($context == "live") { |
| 43 | $rsync_host = "download.eclipse.org::eclipseFullMirror/"; |
| 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 |
droy | 1cdb709 | 2010-04-19 20:38:19 +0000 | [diff] [blame] | 49 | $sql = "SELECT * FROM map_files AS m |
| 50 | INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version |
| 51 | INNER JOIN release_trains AS t on t.train_id = r.train_id |
| 52 | WHERE m.is_active = 1 AND m.is_map_file = 0 AND t.is_active = 1"; |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 53 | $rs_maps = mysql_query($sql, $dbh); |
| 54 | while($update_site = mysql_fetch_assoc($rs_maps)) { |
| 55 | $site_url = $update_site['location']; |
| 56 | $project_id = $update_site['project_id']; |
| 57 | $version = $update_site['version']; |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 58 | # Sample dirs: |
| 59 | # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301 |
| 60 | # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/ |
| 61 | # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/ |
| 62 | # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/ |
| 63 | # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/ |
kitlo | a3a2ae9 | 2011-06-14 22:35:43 +0000 | [diff] [blame] | 64 | $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1); |
| 65 | if (strcmp(substr($site_dir, -1), "/") != 0) { |
| 66 | $site_dir = $site_dir . "/"; |
| 67 | } |
| 68 | $site_plugins_dir = $site_dir . "plugins/"; |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 69 | $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/"; |
| 70 | $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 71 | |
kitlo | 41083bd | 2010-02-16 17:17:10 +0000 | [diff] [blame] | 72 | # Collect all files for this project version |
| 73 | if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) { |
| 74 | $files_collected[$project_id][$version] = 1; |
| 75 | $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\""; |
| 76 | $rs_files = mysql_query($sql, $dbh); |
| 77 | while ($myrow_files = mysql_fetch_assoc($rs_files)) { |
| 78 | $file = new File(); |
| 79 | $file->project_id = $myrow_files['project_id']; |
| 80 | $file->version = $myrow_files['version']; |
| 81 | $file->name = $myrow_files['name']; |
| 82 | $file->plugin_id = $myrow_files['plugin_id']; |
| 83 | $file->file_id = $myrow_files['file_id']; |
| 84 | $file->is_active = $myrow_files['is_active']; |
| 85 | $files[$file->file_id] = $file; |
| 86 | } |
kitlo | 3efbb26 | 2010-01-13 15:18:57 +0000 | [diff] [blame] | 87 | } |
| 88 | |
kitlo | 41083bd | 2010-02-16 17:17:10 +0000 | [diff] [blame] | 89 | # Collect all plugin exclude patterns for this project version |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 90 | $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\""; |
| 91 | $rs_patterns = mysql_query($sql, $dbh); |
| 92 | $patterns = Array(); |
kitlo | ff89eb2 | 2011-06-29 20:52:24 +0000 | [diff] [blame] | 93 | # Add default exclude patterns |
kitlo | 17b663e | 2011-06-30 03:33:01 +0000 | [diff] [blame] | 94 | $patterns[] = "/^.*\/feature.properties$/"; |
| 95 | $patterns[] = "/^.*\/build.properties$/"; |
| 96 | $patterns[] = "/^.*\/pom.properties$/"; |
| 97 | $patterns[] = "/^.*\/css\/.*$/"; |
kitlo | ff89eb2 | 2011-06-29 20:52:24 +0000 | [diff] [blame] | 98 | $patterns[] = "/^.*\.source\/.*$/"; |
| 99 | $patterns[] = "/^.*\.test\/.*$/"; |
| 100 | $patterns[] = "/^.*\.tests\/.*$/"; |
kitlo | 17b663e | 2011-06-30 03:33:01 +0000 | [diff] [blame] | 101 | $patterns[] = "/^.*\.testing\/.*$/"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 102 | while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) { |
| 103 | $patterns[] = $myrow_patterns['pattern']; |
| 104 | } |
| 105 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 106 | # Rsync update site |
kitlo | a3a2ae9 | 2011-06-14 22:35:43 +0000 | [diff] [blame] | 107 | echo "rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir\n"; |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 108 | exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir"); |
| 109 | |
| 110 | # Make unzip dir |
| 111 | mkdir($temp_unzip_dir, 0777, TRUE); |
| 112 | |
kitlo | 9a507cb | 2011-12-26 21:17:52 +0000 | [diff] [blame^] | 113 | # Temporary workaround to remove Eclipse 3.8 plugins in 4.2 update site |
| 114 | chdir($temp_site_dir); |
| 115 | if ($project_id == "eclipse" && $version == "4.2") { |
| 116 | exec("rm org.eclipse.ui.workbench_3.8.*"); |
| 117 | } |
| 118 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 119 | # Unzip properties files in each jar |
| 120 | chdir($temp_site_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 121 | foreach (glob("*.jar") as $jar_name) { |
| 122 | # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar |
| 123 | # |
| 124 | # Remove plugin version from jar name: |
| 125 | # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench |
| 126 | $temp_str = $jar_name; |
| 127 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 128 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 129 | $temp_str = substr($temp_str, 0, strrpos($temp_str, "_")); |
| 130 | $plugin_id = $temp_str; |
| 131 | |
kitlo | 20071c5 | 2010-01-13 14:10:52 +0000 | [diff] [blame] | 132 | if (!is_dir($temp_unzip_dir . $plugin_id)) { |
| 133 | mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE); |
| 134 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 135 | chdir($temp_unzip_dir . $plugin_id); |
kitlo | 281a641 | 2010-01-13 13:34:57 +0000 | [diff] [blame] | 136 | exec("unzip -o -q $temp_site_dir$jar_name"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 137 | } |
| 138 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 139 | # Collect properties file names |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 140 | $properties_file_names = array(); |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 141 | chdir($temp_unzip_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 142 | exec("find . -name *.properties", $properties_file_names); |
| 143 | sort($properties_file_names); |
| 144 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 145 | # Parse each properties file |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 146 | echo "Start processing properties files in project $project_id version $version...\n"; |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 147 | echo " Update site location: $site_url\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 148 | foreach ($properties_file_names as $properties_file_name) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 149 | # Remove "./" from beginning of properties file name |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 150 | $properties_file_name = substr($properties_file_name, 2); |
| 151 | $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/")); |
| 152 | $file_id = File::getFileID($properties_file_name, $project_id, $version); |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 153 | |
| 154 | # Match plugin exclude list |
| 155 | $match = false; |
| 156 | foreach ($patterns as $pattern) { |
| 157 | if (preg_match($pattern, $properties_file_name)) { |
| 158 | $match = true; |
| 159 | break; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 162 | |
| 163 | if (!$match) { |
kitlo | b746da4 | 2010-02-12 02:40:41 +0000 | [diff] [blame] | 164 | if ($file_id > 0 && $files[$file_id] != null) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 165 | # Existing file |
| 166 | $file = $files[$file_id]; |
| 167 | $file->is_active = 1; |
| 168 | unset($files[$file_id]); |
| 169 | } else { |
| 170 | # New file |
| 171 | $file = new File(); |
| 172 | $file->project_id = $project_id; |
| 173 | $file->version = $version; |
| 174 | $file->name = $properties_file_name; |
| 175 | $file->plugin_id = $plugin_id; |
| 176 | $file->is_active = 1; |
| 177 | } |
| 178 | if (!$file->save()) { |
| 179 | echo "***ERROR: Cannot save file $file->name\n"; |
| 180 | } else { |
| 181 | $file_name = $temp_unzip_dir . $properties_file_name; |
| 182 | $file->parseProperties(file_get_contents($file_name)); |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame] | 183 | echo " $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 184 | } |
| 185 | } else { |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame] | 186 | echo " !!! Excluding $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 189 | echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n"; |
| 190 | } |
| 191 | |
| 192 | # Deactivate the rest of the files |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 193 | echo "Start deactivating inactive properties files in all projects above...\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 194 | foreach ($files as $file) { |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 195 | if ($file->is_active == 1) { |
| 196 | $file->is_active = 0; |
| 197 | if (!$file->save()) { |
| 198 | echo "***ERROR: Cannot deactivate file $file->name\n"; |
| 199 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 200 | echo " " . $file->name . "\n"; |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 201 | } else { |
| 202 | unset($files[$file->file_id]); |
| 203 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 204 | } |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 205 | 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] | 206 | |
kitlo | 59274fb | 2010-02-12 03:31:34 +0000 | [diff] [blame] | 207 | if (is_dir($temp_unzips_dir)) { |
| 208 | exec("rm -rf $temp_unzips_dir"); |
| 209 | } |
| 210 | |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 211 | if ($headless) { |
| 212 | $User = null; |
| 213 | } |
| 214 | |
| 215 | echo "Done\n"; |
| 216 | ?> |