blob: 0abf2a5a6d1c7b1405da5adc562b24d27a736438 [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
kitlo17b663e2011-06-30 03:33:01 +000094 $patterns[] = "/^.*\/feature.properties$/";
95 $patterns[] = "/^.*\/build.properties$/";
96 $patterns[] = "/^.*\/pom.properties$/";
97 $patterns[] = "/^.*\/css\/.*$/";
kitloff89eb22011-06-29 20:52:24 +000098 $patterns[] = "/^.*\.source\/.*$/";
99 $patterns[] = "/^.*\.test\/.*$/";
100 $patterns[] = "/^.*\.tests\/.*$/";
kitlo17b663e2011-06-30 03:33:01 +0000101 $patterns[] = "/^.*\.testing\/.*$/";
kitlo3e175f42010-01-23 02:26:31 +0000102 while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) {
103 $patterns[] = $myrow_patterns['pattern'];
104 }
105
kitlo0da4aca2010-01-13 05:08:26 +0000106 # Rsync update site
kitloa3a2ae92011-06-14 22:35:43 +0000107 echo "rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir\n";
kitlo0da4aca2010-01-13 05:08:26 +0000108 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
kitlo9a507cb2011-12-26 21:17:52 +0000113 # 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.*");
117 }
118
kitlo0da4aca2010-01-13 05:08:26 +0000119 # Unzip properties files in each jar
120 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000121 foreach (glob("*.jar") as $jar_name) {
122 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
123 #
124 # Remove plugin version from jar name:
125 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
126 $temp_str = $jar_name;
127 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
128 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
129 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
130 $plugin_id = $temp_str;
131
kitlo20071c52010-01-13 14:10:52 +0000132 if (!is_dir($temp_unzip_dir . $plugin_id)) {
133 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
134 }
kitlo0da4aca2010-01-13 05:08:26 +0000135 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000136 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000137 }
138
kitlo0da4aca2010-01-13 05:08:26 +0000139 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000140 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000141 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000142 exec("find . -name *.properties", $properties_file_names);
143 sort($properties_file_names);
144
kitlo0da4aca2010-01-13 05:08:26 +0000145 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000146 echo "Start processing properties files in project $project_id version $version...\n";
kitlo4331c752010-02-15 01:45:35 +0000147 echo " Update site location: $site_url\n";
kitlo2e780dc2010-01-12 17:58:32 +0000148 foreach ($properties_file_names as $properties_file_name) {
kitlo3e175f42010-01-23 02:26:31 +0000149 # Remove "./" from beginning of properties file name
kitlo2e780dc2010-01-12 17:58:32 +0000150 $properties_file_name = substr($properties_file_name, 2);
151 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
152 $file_id = File::getFileID($properties_file_name, $project_id, $version);
kitlo3e175f42010-01-23 02:26:31 +0000153
154 # Match plugin exclude list
155 $match = false;
156 foreach ($patterns as $pattern) {
157 if (preg_match($pattern, $properties_file_name)) {
158 $match = true;
159 break;
kitlo2e780dc2010-01-12 17:58:32 +0000160 }
161 }
kitlo3e175f42010-01-23 02:26:31 +0000162
163 if (!$match) {
kitlob746da42010-02-12 02:40:41 +0000164 if ($file_id > 0 && $files[$file_id] != null) {
kitlo3e175f42010-01-23 02:26:31 +0000165 # Existing file
166 $file = $files[$file_id];
167 $file->is_active = 1;
168 unset($files[$file_id]);
169 } else {
170 # New file
171 $file = new File();
172 $file->project_id = $project_id;
173 $file->version = $version;
174 $file->name = $properties_file_name;
175 $file->plugin_id = $plugin_id;
176 $file->is_active = 1;
177 }
178 if (!$file->save()) {
179 echo "***ERROR: Cannot save file $file->name\n";
180 } else {
181 $file_name = $temp_unzip_dir . $properties_file_name;
182 $file->parseProperties(file_get_contents($file_name));
kitlod12b06b2010-02-12 18:14:40 +0000183 echo " $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000184 }
185 } else {
kitlod12b06b2010-02-12 18:14:40 +0000186 echo " !!! Excluding $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000187 }
188 }
kitlo2e780dc2010-01-12 17:58:32 +0000189 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
190}
191
192# Deactivate the rest of the files
kitlod66aa992010-01-22 17:18:19 +0000193echo "Start deactivating inactive properties files in all projects above...\n";
kitlo2e780dc2010-01-12 17:58:32 +0000194foreach ($files as $file) {
kitlo4331c752010-02-15 01:45:35 +0000195 if ($file->is_active == 1) {
196 $file->is_active = 0;
197 if (!$file->save()) {
198 echo "***ERROR: Cannot deactivate file $file->name\n";
199 }
kitlo2e780dc2010-01-12 17:58:32 +0000200 echo " " . $file->name . "\n";
kitlo4331c752010-02-15 01:45:35 +0000201 } else {
202 unset($files[$file->file_id]);
203 }
kitlo2e780dc2010-01-12 17:58:32 +0000204}
kitlod66aa992010-01-22 17:18:19 +0000205echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
kitlo2e780dc2010-01-12 17:58:32 +0000206
kitlo59274fb2010-02-12 03:31:34 +0000207if (is_dir($temp_unzips_dir)) {
208 exec("rm -rf $temp_unzips_dir");
209}
210
kitlo2e780dc2010-01-12 17:58:32 +0000211if ($headless) {
212 $User = null;
213}
214
215echo "Done\n";
216?>