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 | |
| 113 | # Unzip properties files in each jar |
| 114 | chdir($temp_site_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 115 | foreach (glob("*.jar") as $jar_name) { |
| 116 | # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar |
| 117 | # |
| 118 | # Remove plugin version from jar name: |
| 119 | # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench |
| 120 | $temp_str = $jar_name; |
| 121 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 122 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 123 | $temp_str = substr($temp_str, 0, strrpos($temp_str, "_")); |
| 124 | $plugin_id = $temp_str; |
| 125 | |
kitlo | 20071c5 | 2010-01-13 14:10:52 +0000 | [diff] [blame] | 126 | if (!is_dir($temp_unzip_dir . $plugin_id)) { |
| 127 | mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE); |
| 128 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 129 | chdir($temp_unzip_dir . $plugin_id); |
kitlo | 281a641 | 2010-01-13 13:34:57 +0000 | [diff] [blame] | 130 | exec("unzip -o -q $temp_site_dir$jar_name"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 131 | } |
| 132 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 133 | # Collect properties file names |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 134 | $properties_file_names = array(); |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 135 | chdir($temp_unzip_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 136 | exec("find . -name *.properties", $properties_file_names); |
| 137 | sort($properties_file_names); |
| 138 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 139 | # Parse each properties file |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 140 | echo "Start processing properties files in project $project_id version $version...\n"; |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 141 | echo " Update site location: $site_url\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 142 | foreach ($properties_file_names as $properties_file_name) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 143 | # Remove "./" from beginning of properties file name |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 144 | $properties_file_name = substr($properties_file_name, 2); |
| 145 | $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/")); |
| 146 | $file_id = File::getFileID($properties_file_name, $project_id, $version); |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 147 | |
| 148 | # Match plugin exclude list |
| 149 | $match = false; |
| 150 | foreach ($patterns as $pattern) { |
| 151 | if (preg_match($pattern, $properties_file_name)) { |
| 152 | $match = true; |
| 153 | break; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 156 | |
| 157 | if (!$match) { |
kitlo | b746da4 | 2010-02-12 02:40:41 +0000 | [diff] [blame] | 158 | if ($file_id > 0 && $files[$file_id] != null) { |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 159 | # Existing file |
| 160 | $file = $files[$file_id]; |
| 161 | $file->is_active = 1; |
| 162 | unset($files[$file_id]); |
| 163 | } else { |
| 164 | # New file |
| 165 | $file = new File(); |
| 166 | $file->project_id = $project_id; |
| 167 | $file->version = $version; |
| 168 | $file->name = $properties_file_name; |
| 169 | $file->plugin_id = $plugin_id; |
| 170 | $file->is_active = 1; |
| 171 | } |
| 172 | if (!$file->save()) { |
| 173 | echo "***ERROR: Cannot save file $file->name\n"; |
| 174 | } else { |
| 175 | $file_name = $temp_unzip_dir . $properties_file_name; |
| 176 | $file->parseProperties(file_get_contents($file_name)); |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame] | 177 | echo " $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 178 | } |
| 179 | } else { |
kitlo | d12b06b | 2010-02-12 18:14:40 +0000 | [diff] [blame] | 180 | echo " !!! Excluding $properties_file_name\n"; |
kitlo | 3e175f4 | 2010-01-23 02:26:31 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 183 | echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n"; |
| 184 | } |
| 185 | |
| 186 | # Deactivate the rest of the files |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 187 | echo "Start deactivating inactive properties files in all projects above...\n"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 188 | foreach ($files as $file) { |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 189 | if ($file->is_active == 1) { |
| 190 | $file->is_active = 0; |
| 191 | if (!$file->save()) { |
| 192 | echo "***ERROR: Cannot deactivate file $file->name\n"; |
| 193 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 194 | echo " " . $file->name . "\n"; |
kitlo | 4331c75 | 2010-02-15 01:45:35 +0000 | [diff] [blame] | 195 | } else { |
| 196 | unset($files[$file->file_id]); |
| 197 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 198 | } |
kitlo | d66aa99 | 2010-01-22 17:18:19 +0000 | [diff] [blame] | 199 | 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] | 200 | |
kitlo | 59274fb | 2010-02-12 03:31:34 +0000 | [diff] [blame] | 201 | if (is_dir($temp_unzips_dir)) { |
| 202 | exec("rm -rf $temp_unzips_dir"); |
| 203 | } |
| 204 | |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 205 | if ($headless) { |
| 206 | $User = null; |
| 207 | } |
| 208 | |
| 209 | echo "Done\n"; |
| 210 | ?> |