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 | */ |
| 16 | # To-do: hard-coding the Eclipse, BIRT, & Webtools update sites for now; need to create an UI for project committers to enter their update sites |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 17 | $eclipse = array("http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301", "eclipse", "3.6"); |
| 18 | $birt = array("http://download.eclipse.org/birt/update-site/2.6-interim", "birt", "2.6.0"); |
| 19 | $webtools = array("http://download.eclipse.org/webtools/updates", "webtools", "3.2"); |
kitlo | 27e80be | 2010-01-13 13:03:55 +0000 | [diff] [blame] | 20 | |
| 21 | # BIRT 2.6.0 & Webtools 3.2 are not defined yet, cannot test on staging server |
| 22 | #$update_sites = array($eclipse, $birt, $webtools); |
| 23 | $update_sites = array($eclipse); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 24 | |
| 25 | $temp_dir = "/tmp/tmp-babel/"; |
| 26 | $debug = TRUE; |
| 27 | |
| 28 | header("Content-type: text/plain"); |
| 29 | include("global.php"); |
| 30 | InitPage(""); |
| 31 | |
| 32 | $headless = 0; |
| 33 | if (!isset($User)) { |
| 34 | echo "User not defined - running headless\n"; |
| 35 | $User = getGenieUser(); |
| 36 | $headless = 1; |
| 37 | } |
| 38 | |
| 39 | require(dirname(__FILE__) . "/../classes/file/file.class.php"); |
| 40 | global $dbh; |
| 41 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 42 | $temp_unzips_dir = $temp_dir . "unzips/"; |
| 43 | if (is_dir($temp_unzips_dir)) { |
| 44 | exec("rm -rf $temp_unzips_dir"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 45 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 46 | mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n"); |
| 47 | |
| 48 | global $addon; |
| 49 | $context = $addon->callHook('context'); |
| 50 | if ($context == "live") { |
| 51 | $rsync_host = "download.eclipse.org::eclipseMirror/"; |
| 52 | } else { |
| 53 | $rsync_host = "rsync.osuosl.org::eclipse/"; |
| 54 | } |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 55 | |
| 56 | $files = array(); |
| 57 | $sql = "SELECT * FROM files WHERE is_active = 1"; |
| 58 | $rs_files = mysql_query($sql, $dbh); |
| 59 | while ($myrow_files = mysql_fetch_assoc($rs_files)) { |
| 60 | $file = new File(); |
| 61 | $file->project_id = $myrow_files['project_id']; |
| 62 | $file->version = $myrow_files['version']; |
| 63 | $file->name = $myrow_files['name']; |
| 64 | $file->plugin_id = $myrow_files['plugin_id']; |
| 65 | $file->file_id = $myrow_files['file_id']; |
| 66 | $files[$file->file_id] = $file; |
| 67 | } |
| 68 | |
| 69 | foreach ($update_sites as $update_site) { |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 70 | $site_url = $update_site[0]; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 71 | $project_id = $update_site[1]; |
| 72 | $version = $update_site[2]; |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 73 | # Sample dirs: |
| 74 | # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301 |
| 75 | # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/ |
| 76 | # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/ |
| 77 | # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/ |
| 78 | # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/ |
| 79 | $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1) . "/"; |
| 80 | $site_plugins_dir = $site_dir . "/plugins/"; |
| 81 | $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/"; |
| 82 | $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/"; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 83 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 84 | # Rsync update site |
| 85 | exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir"); |
| 86 | |
| 87 | # Make unzip dir |
| 88 | mkdir($temp_unzip_dir, 0777, TRUE); |
| 89 | |
| 90 | # Unzip properties files in each jar |
| 91 | chdir($temp_site_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 92 | foreach (glob("*.jar") as $jar_name) { |
| 93 | # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar |
| 94 | # |
| 95 | # Remove plugin version from jar name: |
| 96 | # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench |
| 97 | $temp_str = $jar_name; |
| 98 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 99 | $temp_str = substr($temp_str, 0, strrpos($temp_str, ".")); |
| 100 | $temp_str = substr($temp_str, 0, strrpos($temp_str, "_")); |
| 101 | $plugin_id = $temp_str; |
| 102 | |
kitlo | 20071c5 | 2010-01-13 14:10:52 +0000 | [diff] [blame^] | 103 | if (!is_dir($temp_unzip_dir . $plugin_id)) { |
| 104 | mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE); |
| 105 | } |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 106 | chdir($temp_unzip_dir . $plugin_id); |
kitlo | 281a641 | 2010-01-13 13:34:57 +0000 | [diff] [blame] | 107 | exec("unzip -o -q $temp_site_dir$jar_name"); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 108 | } |
| 109 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 110 | # Collect properties file names |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 111 | $properties_file_names = array(); |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 112 | chdir($temp_unzip_dir); |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 113 | exec("find . -name *.properties", $properties_file_names); |
| 114 | sort($properties_file_names); |
| 115 | |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 116 | # Parse each properties file |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 117 | echo "Start processing properties files in project $project_id version $version...\n"; |
| 118 | foreach ($properties_file_names as $properties_file_name) { |
| 119 | $properties_file_name = substr($properties_file_name, 2); |
| 120 | $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/")); |
| 121 | $file_id = File::getFileID($properties_file_name, $project_id, $version); |
| 122 | |
| 123 | if ($files[$file_id] != null) { |
| 124 | $file = $files[$file_id]; |
| 125 | $file->is_active = 1; |
| 126 | unset($files[$file_id]); |
| 127 | } else { |
| 128 | $file = new File(); |
| 129 | $file->project_id = $project_id; |
| 130 | $file->version = $version; |
| 131 | $file->name = $properties_file_name; |
| 132 | $file->plugin_id = $plugin_id; |
| 133 | $file->is_active = 1; |
| 134 | } |
| 135 | if (!$file->save()) { |
| 136 | echo "***ERROR: Cannot save file $file->name\n"; |
| 137 | } else { |
kitlo | 0da4aca | 2010-01-13 05:08:26 +0000 | [diff] [blame] | 138 | $file_name = $temp_unzip_dir . $properties_file_name; |
kitlo | 2e780dc | 2010-01-12 17:58:32 +0000 | [diff] [blame] | 139 | $file->parseProperties(file_get_contents($file_name)); |
| 140 | if ($debug) { |
| 141 | echo " " . $file->name . "\n"; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n"; |
| 146 | } |
| 147 | |
| 148 | # Deactivate the rest of the files |
| 149 | foreach ($files as $file) { |
| 150 | $file->is_active = 0; |
| 151 | if (!$file->save()) { |
| 152 | echo "***ERROR: Cannot deactivate file $file->name\n"; |
| 153 | } |
| 154 | if ($debug) { |
| 155 | echo " " . $file->name . "\n"; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if ($headless) { |
| 160 | $User = null; |
| 161 | } |
| 162 | |
| 163 | echo "Done\n"; |
| 164 | ?> |