blob: 0b799ae986a3c769ed47ee1342992d2e9be547ce [file] [log] [blame]
kitlo2e780dc2010-01-12 17:58:32 +00001<?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 */
kitlo2e780dc2010-01-12 17:58:32 +000016$temp_dir = "/tmp/tmp-babel/";
kitlo3efbb262010-01-13 15:18:57 +000017$files = array();
kitlo41083bd2010-02-16 17:17:10 +000018$files_collected = array(array());
kitlo2e780dc2010-01-12 17:58:32 +000019
20header("Content-type: text/plain");
21include("global.php");
22InitPage("");
23
24$headless = 0;
25if (!isset($User)) {
26 echo "User not defined - running headless\n";
27 $User = getGenieUser();
28 $headless = 1;
29}
30
31require(dirname(__FILE__) . "/../classes/file/file.class.php");
32global $dbh;
33
kitlo0da4aca2010-01-13 05:08:26 +000034$temp_unzips_dir = $temp_dir . "unzips/";
35if (is_dir($temp_unzips_dir)) {
36 exec("rm -rf $temp_unzips_dir");
kitlo2e780dc2010-01-12 17:58:32 +000037}
kitlo0da4aca2010-01-13 05:08:26 +000038mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
39
40global $addon;
41$context = $addon->callHook('context');
42if ($context == "live") {
43 $rsync_host = "download.eclipse.org::eclipseMirror/";
44} else {
45 $rsync_host = "rsync.osuosl.org::eclipse/";
46}
kitlo2e780dc2010-01-12 17:58:32 +000047
kitlod66aa992010-01-22 17:18:19 +000048# 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);
51while($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'];
kitlo0da4aca2010-01-13 05:08:26 +000055 # 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 . "/";
kitlo2e780dc2010-01-12 17:58:32 +000065
kitlo41083bd2010-02-16 17:17:10 +000066 # Collect all files for this project version
67 if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) {
68 $files_collected[$project_id][$version] = 1;
69 $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\"";
70 $rs_files = mysql_query($sql, $dbh);
71 while ($myrow_files = mysql_fetch_assoc($rs_files)) {
72 $file = new File();
73 $file->project_id = $myrow_files['project_id'];
74 $file->version = $myrow_files['version'];
75 $file->name = $myrow_files['name'];
76 $file->plugin_id = $myrow_files['plugin_id'];
77 $file->file_id = $myrow_files['file_id'];
78 $file->is_active = $myrow_files['is_active'];
79 $files[$file->file_id] = $file;
80 }
kitlo3efbb262010-01-13 15:18:57 +000081 }
82
kitlo41083bd2010-02-16 17:17:10 +000083 # Collect all plugin exclude patterns for this project version
kitlo3e175f42010-01-23 02:26:31 +000084 $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\"";
85 $rs_patterns = mysql_query($sql, $dbh);
86 $patterns = Array();
87 while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) {
88 $patterns[] = $myrow_patterns['pattern'];
89 }
90
kitlo0da4aca2010-01-13 05:08:26 +000091 # Rsync update site
92 exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir");
93
94 # Make unzip dir
95 mkdir($temp_unzip_dir, 0777, TRUE);
96
97 # Unzip properties files in each jar
98 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +000099 foreach (glob("*.jar") as $jar_name) {
100 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
101 #
102 # Remove plugin version from jar name:
103 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
104 $temp_str = $jar_name;
105 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
106 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
107 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
108 $plugin_id = $temp_str;
109
kitlo20071c52010-01-13 14:10:52 +0000110 if (!is_dir($temp_unzip_dir . $plugin_id)) {
111 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
112 }
kitlo0da4aca2010-01-13 05:08:26 +0000113 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000114 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000115 }
116
kitlo0da4aca2010-01-13 05:08:26 +0000117 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000118 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000119 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000120 exec("find . -name *.properties", $properties_file_names);
121 sort($properties_file_names);
122
kitlo0da4aca2010-01-13 05:08:26 +0000123 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000124 echo "Start processing properties files in project $project_id version $version...\n";
kitlo4331c752010-02-15 01:45:35 +0000125 echo " Update site location: $site_url\n";
kitlo2e780dc2010-01-12 17:58:32 +0000126 foreach ($properties_file_names as $properties_file_name) {
kitlo3e175f42010-01-23 02:26:31 +0000127 # Remove "./" from beginning of properties file name
kitlo2e780dc2010-01-12 17:58:32 +0000128 $properties_file_name = substr($properties_file_name, 2);
129 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
130 $file_id = File::getFileID($properties_file_name, $project_id, $version);
kitlo3e175f42010-01-23 02:26:31 +0000131
132 # Match plugin exclude list
133 $match = false;
134 foreach ($patterns as $pattern) {
135 if (preg_match($pattern, $properties_file_name)) {
136 $match = true;
137 break;
kitlo2e780dc2010-01-12 17:58:32 +0000138 }
139 }
kitlo3e175f42010-01-23 02:26:31 +0000140
141 if (!$match) {
kitlob746da42010-02-12 02:40:41 +0000142 if ($file_id > 0 && $files[$file_id] != null) {
kitlo3e175f42010-01-23 02:26:31 +0000143 # Existing file
144 $file = $files[$file_id];
145 $file->is_active = 1;
146 unset($files[$file_id]);
147 } else {
148 # New file
149 $file = new File();
150 $file->project_id = $project_id;
151 $file->version = $version;
152 $file->name = $properties_file_name;
153 $file->plugin_id = $plugin_id;
154 $file->is_active = 1;
155 }
156 if (!$file->save()) {
157 echo "***ERROR: Cannot save file $file->name\n";
158 } else {
159 $file_name = $temp_unzip_dir . $properties_file_name;
160 $file->parseProperties(file_get_contents($file_name));
kitlod12b06b2010-02-12 18:14:40 +0000161 echo " $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000162 }
163 } else {
kitlod12b06b2010-02-12 18:14:40 +0000164 echo " !!! Excluding $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000165 }
166 }
kitlo2e780dc2010-01-12 17:58:32 +0000167 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
168}
169
170# Deactivate the rest of the files
kitlod66aa992010-01-22 17:18:19 +0000171echo "Start deactivating inactive properties files in all projects above...\n";
kitlo2e780dc2010-01-12 17:58:32 +0000172foreach ($files as $file) {
kitlo4331c752010-02-15 01:45:35 +0000173 if ($file->is_active == 1) {
174 $file->is_active = 0;
175 if (!$file->save()) {
176 echo "***ERROR: Cannot deactivate file $file->name\n";
177 }
kitlo2e780dc2010-01-12 17:58:32 +0000178 echo " " . $file->name . "\n";
kitlo4331c752010-02-15 01:45:35 +0000179 } else {
180 unset($files[$file->file_id]);
181 }
kitlo2e780dc2010-01-12 17:58:32 +0000182}
kitlod66aa992010-01-22 17:18:19 +0000183echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
kitlo2e780dc2010-01-12 17:58:32 +0000184
kitlo59274fb2010-02-12 03:31:34 +0000185if (is_dir($temp_unzips_dir)) {
186 exec("rm -rf $temp_unzips_dir");
187}
188
kitlo2e780dc2010-01-12 17:58:32 +0000189if ($headless) {
190 $User = null;
191}
192
193echo "Done\n";
194?>