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