blob: 339ae5d6f5366dfefeb48128d8be931b6a2a03ea [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');
kitloa3a2ae92011-06-14 22:35:43 +000042if ($context == "live") {
43 $rsync_host = "download.eclipse.org::eclipseFullMirror/";
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
droy1cdb7092010-04-19 20:38:19 +000049$sql = "SELECT * FROM map_files AS m
50INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version
51INNER JOIN release_trains AS t on t.train_id = r.train_id
52WHERE m.is_active = 1 AND m.is_map_file = 0 AND t.is_active = 1";
kitlod66aa992010-01-22 17:18:19 +000053$rs_maps = mysql_query($sql, $dbh);
54while($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'];
kitlo0da4aca2010-01-13 05:08:26 +000058 # 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/
kitloa3a2ae92011-06-14 22:35:43 +000064 $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/";
kitlo0da4aca2010-01-13 05:08:26 +000069 $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/";
70 $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
kitlo2e780dc2010-01-12 17:58:32 +000071
kitlo41083bd2010-02-16 17:17:10 +000072 # 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 }
kitlo3efbb262010-01-13 15:18:57 +000087 }
88
kitlo41083bd2010-02-16 17:17:10 +000089 # Collect all plugin exclude patterns for this project version
kitlo3e175f42010-01-23 02:26:31 +000090 $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();
kitloff89eb22011-06-29 20:52:24 +000093 # Add default exclude patterns
94 $patterns[] = "/^.*\.source\/.*$/";
95 $patterns[] = "/^.*\.test\/.*$/";
96 $patterns[] = "/^.*\.tests\/.*$/";
kitlo3e175f42010-01-23 02:26:31 +000097 while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) {
98 $patterns[] = $myrow_patterns['pattern'];
99 }
100
kitlo0da4aca2010-01-13 05:08:26 +0000101 # Rsync update site
kitloa3a2ae92011-06-14 22:35:43 +0000102 echo "rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir\n";
kitlo0da4aca2010-01-13 05:08:26 +0000103 exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir");
104
105 # Make unzip dir
106 mkdir($temp_unzip_dir, 0777, TRUE);
107
108 # Unzip properties files in each jar
109 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000110 foreach (glob("*.jar") as $jar_name) {
111 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
112 #
113 # Remove plugin version from jar name:
114 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
115 $temp_str = $jar_name;
116 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
117 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
118 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
119 $plugin_id = $temp_str;
120
kitlo20071c52010-01-13 14:10:52 +0000121 if (!is_dir($temp_unzip_dir . $plugin_id)) {
122 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
123 }
kitlo0da4aca2010-01-13 05:08:26 +0000124 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000125 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000126 }
127
kitlo0da4aca2010-01-13 05:08:26 +0000128 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000129 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000130 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000131 exec("find . -name *.properties", $properties_file_names);
132 sort($properties_file_names);
133
kitlo0da4aca2010-01-13 05:08:26 +0000134 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000135 echo "Start processing properties files in project $project_id version $version...\n";
kitlo4331c752010-02-15 01:45:35 +0000136 echo " Update site location: $site_url\n";
kitlo2e780dc2010-01-12 17:58:32 +0000137 foreach ($properties_file_names as $properties_file_name) {
kitlo3e175f42010-01-23 02:26:31 +0000138 # Remove "./" from beginning of properties file name
kitlo2e780dc2010-01-12 17:58:32 +0000139 $properties_file_name = substr($properties_file_name, 2);
140 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
141 $file_id = File::getFileID($properties_file_name, $project_id, $version);
kitlo3e175f42010-01-23 02:26:31 +0000142
143 # Match plugin exclude list
144 $match = false;
145 foreach ($patterns as $pattern) {
146 if (preg_match($pattern, $properties_file_name)) {
147 $match = true;
148 break;
kitlo2e780dc2010-01-12 17:58:32 +0000149 }
150 }
kitlo3e175f42010-01-23 02:26:31 +0000151
152 if (!$match) {
kitlob746da42010-02-12 02:40:41 +0000153 if ($file_id > 0 && $files[$file_id] != null) {
kitlo3e175f42010-01-23 02:26:31 +0000154 # Existing file
155 $file = $files[$file_id];
156 $file->is_active = 1;
157 unset($files[$file_id]);
158 } else {
159 # New file
160 $file = new File();
161 $file->project_id = $project_id;
162 $file->version = $version;
163 $file->name = $properties_file_name;
164 $file->plugin_id = $plugin_id;
165 $file->is_active = 1;
166 }
167 if (!$file->save()) {
168 echo "***ERROR: Cannot save file $file->name\n";
169 } else {
170 $file_name = $temp_unzip_dir . $properties_file_name;
171 $file->parseProperties(file_get_contents($file_name));
kitlod12b06b2010-02-12 18:14:40 +0000172 echo " $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000173 }
174 } else {
kitlod12b06b2010-02-12 18:14:40 +0000175 echo " !!! Excluding $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000176 }
177 }
kitlo2e780dc2010-01-12 17:58:32 +0000178 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
179}
180
181# Deactivate the rest of the files
kitlod66aa992010-01-22 17:18:19 +0000182echo "Start deactivating inactive properties files in all projects above...\n";
kitlo2e780dc2010-01-12 17:58:32 +0000183foreach ($files as $file) {
kitlo4331c752010-02-15 01:45:35 +0000184 if ($file->is_active == 1) {
185 $file->is_active = 0;
186 if (!$file->save()) {
187 echo "***ERROR: Cannot deactivate file $file->name\n";
188 }
kitlo2e780dc2010-01-12 17:58:32 +0000189 echo " " . $file->name . "\n";
kitlo4331c752010-02-15 01:45:35 +0000190 } else {
191 unset($files[$file->file_id]);
192 }
kitlo2e780dc2010-01-12 17:58:32 +0000193}
kitlod66aa992010-01-22 17:18:19 +0000194echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
kitlo2e780dc2010-01-12 17:58:32 +0000195
kitlo59274fb2010-02-12 03:31:34 +0000196if (is_dir($temp_unzips_dir)) {
197 exec("rm -rf $temp_unzips_dir");
198}
199
kitlo2e780dc2010-01-12 17:58:32 +0000200if ($headless) {
201 $User = null;
202}
203
204echo "Done\n";
205?>