blob: a3b205233d7a8d4f208358cc51096a1e9d50ad9e [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
kitlo93a31a22012-06-17 18:38:24 +000011 * Kit Lo (IBM) - [299402] Extract properties files from Eclipse project update sites for translation
12 * Kit Lo (IBM) - [382800] CSSUIPluginResources.properties is missing on translator tool
kitlo2e780dc2010-01-12 17:58:32 +000013*******************************************************************************/
14/*
15 * Extract properties files from update sites
16 */
kitlo2e780dc2010-01-12 17:58:32 +000017$temp_dir = "/tmp/tmp-babel/";
kitlo3efbb262010-01-13 15:18:57 +000018$files = array();
kitlo41083bd2010-02-16 17:17:10 +000019$files_collected = array(array());
kitlo2e780dc2010-01-12 17:58:32 +000020
21header("Content-type: text/plain");
22include("global.php");
23InitPage("");
24
25$headless = 0;
26if (!isset($User)) {
27 echo "User not defined - running headless\n";
28 $User = getGenieUser();
29 $headless = 1;
30}
31
32require(dirname(__FILE__) . "/../classes/file/file.class.php");
33global $dbh;
34
kitlo0da4aca2010-01-13 05:08:26 +000035$temp_unzips_dir = $temp_dir . "unzips/";
36if (is_dir($temp_unzips_dir)) {
37 exec("rm -rf $temp_unzips_dir");
kitlo2e780dc2010-01-12 17:58:32 +000038}
kitlo0da4aca2010-01-13 05:08:26 +000039mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
40
41global $addon;
42$context = $addon->callHook('context');
kitloa3a2ae92011-06-14 22:35:43 +000043if ($context == "live") {
44 $rsync_host = "download.eclipse.org::eclipseFullMirror/";
45} else {
46 $rsync_host = "rsync.osuosl.org::eclipse/";
47}
kitlo2e780dc2010-01-12 17:58:32 +000048
kitlod66aa992010-01-22 17:18:19 +000049# Get all active update sites
droy1cdb7092010-04-19 20:38:19 +000050$sql = "SELECT * FROM map_files AS m
51INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version
52INNER JOIN release_trains AS t on t.train_id = r.train_id
53WHERE m.is_active = 1 AND m.is_map_file = 0 AND t.is_active = 1";
kitlo2c8d8a92018-04-19 13:25:09 -040054$rs_maps = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040055while($update_site = mysqli_fetch_assoc($rs_maps)) {
kitlod66aa992010-01-22 17:18:19 +000056 $site_url = $update_site['location'];
57 $project_id = $update_site['project_id'];
58 $version = $update_site['version'];
kitlo0da4aca2010-01-13 05:08:26 +000059 # Sample dirs:
60 # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301
61 # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/
62 # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/
63 # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/
64 # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/
kitloa3a2ae92011-06-14 22:35:43 +000065 $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1);
66 if (strcmp(substr($site_dir, -1), "/") != 0) {
67 $site_dir = $site_dir . "/";
68 }
69 $site_plugins_dir = $site_dir . "plugins/";
kitlo0da4aca2010-01-13 05:08:26 +000070 $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/";
71 $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
kitlo2e780dc2010-01-12 17:58:32 +000072
kitlo41083bd2010-02-16 17:17:10 +000073 # Collect all files for this project version
74 if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) {
75 $files_collected[$project_id][$version] = 1;
76 $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\"";
kitlo2c8d8a92018-04-19 13:25:09 -040077 $rs_files = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040078 while ($myrow_files = mysqli_fetch_assoc($rs_files)) {
kitlo41083bd2010-02-16 17:17:10 +000079 $file = new File();
80 $file->project_id = $myrow_files['project_id'];
81 $file->version = $myrow_files['version'];
82 $file->name = $myrow_files['name'];
83 $file->plugin_id = $myrow_files['plugin_id'];
84 $file->file_id = $myrow_files['file_id'];
85 $file->is_active = $myrow_files['is_active'];
86 $files[$file->file_id] = $file;
87 }
kitlo3efbb262010-01-13 15:18:57 +000088 }
89
kitlo41083bd2010-02-16 17:17:10 +000090 # Collect all plugin exclude patterns for this project version
kitlo3e175f42010-01-23 02:26:31 +000091 $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\"";
kitlo2c8d8a92018-04-19 13:25:09 -040092 $rs_patterns = mysqli_query($dbh, $sql);
kitlo3e175f42010-01-23 02:26:31 +000093 $patterns = Array();
kitloff89eb22011-06-29 20:52:24 +000094 # Add default exclude patterns
kitlo17b663e2011-06-30 03:33:01 +000095 $patterns[] = "/^.*\/feature.properties$/";
96 $patterns[] = "/^.*\/build.properties$/";
97 $patterns[] = "/^.*\/pom.properties$/";
kitloff89eb22011-06-29 20:52:24 +000098 $patterns[] = "/^.*\.source\/.*$/";
99 $patterns[] = "/^.*\.test\/.*$/";
100 $patterns[] = "/^.*\.tests\/.*$/";
kitlo17b663e2011-06-30 03:33:01 +0000101 $patterns[] = "/^.*\.testing\/.*$/";
kitlo1d027092018-04-19 17:44:07 -0400102 while ($myrow_patterns = mysqli_fetch_assoc($rs_patterns)) {
kitlo3e175f42010-01-23 02:26:31 +0000103 $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.*");
kitlo37757562011-12-28 01:00:10 +0000117 exec("rm org.eclipse.update.ui_*");
kitlo9a507cb2011-12-26 21:17:52 +0000118 }
119
kitlo0da4aca2010-01-13 05:08:26 +0000120 # Unzip properties files in each jar
121 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000122 foreach (glob("*.jar") as $jar_name) {
123 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
124 #
125 # Remove plugin version from jar name:
126 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
127 $temp_str = $jar_name;
128 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
129 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
130 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
131 $plugin_id = $temp_str;
132
kitlo20071c52010-01-13 14:10:52 +0000133 if (!is_dir($temp_unzip_dir . $plugin_id)) {
134 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
135 }
kitlo0da4aca2010-01-13 05:08:26 +0000136 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000137 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000138 }
139
kitlo0da4aca2010-01-13 05:08:26 +0000140 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000141 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000142 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000143 exec("find . -name *.properties", $properties_file_names);
144 sort($properties_file_names);
145
kitlo0da4aca2010-01-13 05:08:26 +0000146 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000147 echo "Start processing properties files in project $project_id version $version...\n";
kitlo4331c752010-02-15 01:45:35 +0000148 echo " Update site location: $site_url\n";
kitlo2e780dc2010-01-12 17:58:32 +0000149 foreach ($properties_file_names as $properties_file_name) {
kitlo3e175f42010-01-23 02:26:31 +0000150 # Remove "./" from beginning of properties file name
kitlo2e780dc2010-01-12 17:58:32 +0000151 $properties_file_name = substr($properties_file_name, 2);
152 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
153 $file_id = File::getFileID($properties_file_name, $project_id, $version);
kitlo3e175f42010-01-23 02:26:31 +0000154
155 # Match plugin exclude list
156 $match = false;
157 foreach ($patterns as $pattern) {
158 if (preg_match($pattern, $properties_file_name)) {
159 $match = true;
160 break;
kitlo2e780dc2010-01-12 17:58:32 +0000161 }
162 }
kitlo3e175f42010-01-23 02:26:31 +0000163
164 if (!$match) {
kitlob746da42010-02-12 02:40:41 +0000165 if ($file_id > 0 && $files[$file_id] != null) {
kitlo3e175f42010-01-23 02:26:31 +0000166 # Existing file
167 $file = $files[$file_id];
168 $file->is_active = 1;
169 unset($files[$file_id]);
170 } else {
171 # New file
172 $file = new File();
173 $file->project_id = $project_id;
174 $file->version = $version;
175 $file->name = $properties_file_name;
176 $file->plugin_id = $plugin_id;
177 $file->is_active = 1;
178 }
179 if (!$file->save()) {
180 echo "***ERROR: Cannot save file $file->name\n";
181 } else {
182 $file_name = $temp_unzip_dir . $properties_file_name;
kitlo37757562011-12-28 01:00:10 +0000183 $file_contents = ereg_replace("\r\n?", "\n", file_get_contents($file_name));
184 $file->parseProperties($file_contents);
kitlod12b06b2010-02-12 18:14:40 +0000185 echo " $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000186 }
187 } else {
kitlod12b06b2010-02-12 18:14:40 +0000188 echo " !!! Excluding $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000189 }
190 }
kitlo2e780dc2010-01-12 17:58:32 +0000191 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
192}
193
194# Deactivate the rest of the files
kitlod66aa992010-01-22 17:18:19 +0000195echo "Start deactivating inactive properties files in all projects above...\n";
kitlo2e780dc2010-01-12 17:58:32 +0000196foreach ($files as $file) {
kitlo4331c752010-02-15 01:45:35 +0000197 if ($file->is_active == 1) {
198 $file->is_active = 0;
199 if (!$file->save()) {
200 echo "***ERROR: Cannot deactivate file $file->name\n";
201 }
kitlo2e780dc2010-01-12 17:58:32 +0000202 echo " " . $file->name . "\n";
kitlo4331c752010-02-15 01:45:35 +0000203 } else {
204 unset($files[$file->file_id]);
205 }
kitlo2e780dc2010-01-12 17:58:32 +0000206}
kitlod66aa992010-01-22 17:18:19 +0000207echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
kitlo2e780dc2010-01-12 17:58:32 +0000208
kitlo59274fb2010-02-12 03:31:34 +0000209if (is_dir($temp_unzips_dir)) {
210 exec("rm -rf $temp_unzips_dir");
211}
212
kitlo2e780dc2010-01-12 17:58:32 +0000213if ($headless) {
214 $User = null;
215}
216
217echo "Done\n";
218?>