blob: a74ec82a1dd68b2338fb7c97ece404ce1717e613 [file] [log] [blame]
kitlo2e780dc2010-01-12 17:58:32 +00001<?php
2/*******************************************************************************
droy587ad062019-09-26 14:23:30 -04003 * Copyright (c) 2010-2019 Eclipse Foundation and others.
kitlo2e780dc2010-01-12 17:58:32 +00004 * 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
droy587ad062019-09-26 14:23:30 -040013 * Denis Roy (Eclipse Foundation) - Bug 550544 - Babel server is not ready for PHP 7
kitlo2e780dc2010-01-12 17:58:32 +000014*******************************************************************************/
15/*
16 * Extract properties files from update sites
17 */
kitlo2e780dc2010-01-12 17:58:32 +000018$temp_dir = "/tmp/tmp-babel/";
kitlo3efbb262010-01-13 15:18:57 +000019$files = array();
kitlo41083bd2010-02-16 17:17:10 +000020$files_collected = array(array());
kitlo2e780dc2010-01-12 17:58:32 +000021
22header("Content-type: text/plain");
23include("global.php");
24InitPage("");
25
26$headless = 0;
27if (!isset($User)) {
28 echo "User not defined - running headless\n";
29 $User = getGenieUser();
30 $headless = 1;
31}
32
33require(dirname(__FILE__) . "/../classes/file/file.class.php");
34global $dbh;
35
kitlo0da4aca2010-01-13 05:08:26 +000036$temp_unzips_dir = $temp_dir . "unzips/";
37if (is_dir($temp_unzips_dir)) {
38 exec("rm -rf $temp_unzips_dir");
kitlo2e780dc2010-01-12 17:58:32 +000039}
kitlo0da4aca2010-01-13 05:08:26 +000040mkdir($temp_unzips_dir, 0777, TRUE) || die("***ERROR: Cannot create working directory: $temp_unzips_dir\n");
41
42global $addon;
43$context = $addon->callHook('context');
kitloa3a2ae92011-06-14 22:35:43 +000044if ($context == "live") {
45 $rsync_host = "download.eclipse.org::eclipseFullMirror/";
46} else {
47 $rsync_host = "rsync.osuosl.org::eclipse/";
48}
kitlo2e780dc2010-01-12 17:58:32 +000049
kitlod66aa992010-01-22 17:18:19 +000050# Get all active update sites
droy1cdb7092010-04-19 20:38:19 +000051$sql = "SELECT * FROM map_files AS m
52INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version
53INNER JOIN release_trains AS t on t.train_id = r.train_id
54WHERE m.is_active = 1 AND m.is_map_file = 0 AND t.is_active = 1";
kitlo2c8d8a92018-04-19 13:25:09 -040055$rs_maps = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040056while($update_site = mysqli_fetch_assoc($rs_maps)) {
kitlod66aa992010-01-22 17:18:19 +000057 $site_url = $update_site['location'];
58 $project_id = $update_site['project_id'];
59 $version = $update_site['version'];
kitlo0da4aca2010-01-13 05:08:26 +000060 # Sample dirs:
61 # $site_url http://download.eclipse.org/eclipse/updates/3.6milestones/S-3.6M4-200912101301
62 # $site_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/
63 # $site_plugins_dir eclipse/updates/3.6milestones/S-3.6M4-200912101301/plugins/
64 # $temp_site_dir /tmp/tmp-babel/update_sites/eclipse/3.6/
65 # $temp_unzip_dir /tmp/tmp-babel/unzips/eclipse/3.6/
kitloa3a2ae92011-06-14 22:35:43 +000066 $site_dir = substr($site_url, strpos($site_url, "/", 7) + 1);
67 if (strcmp(substr($site_dir, -1), "/") != 0) {
68 $site_dir = $site_dir . "/";
69 }
70 $site_plugins_dir = $site_dir . "plugins/";
kitlo0da4aca2010-01-13 05:08:26 +000071 $temp_site_dir = $temp_dir . "update_sites/" . $project_id . "/" . $version . "/";
72 $temp_unzip_dir = $temp_dir . "unzips/" . $project_id . "/" . $version . "/";
kitlo2e780dc2010-01-12 17:58:32 +000073
kitlo41083bd2010-02-16 17:17:10 +000074 # Collect all files for this project version
75 if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) {
76 $files_collected[$project_id][$version] = 1;
77 $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\"";
kitlo2c8d8a92018-04-19 13:25:09 -040078 $rs_files = mysqli_query($dbh, $sql);
kitlo1d027092018-04-19 17:44:07 -040079 while ($myrow_files = mysqli_fetch_assoc($rs_files)) {
kitlo41083bd2010-02-16 17:17:10 +000080 $file = new File();
81 $file->project_id = $myrow_files['project_id'];
82 $file->version = $myrow_files['version'];
83 $file->name = $myrow_files['name'];
84 $file->plugin_id = $myrow_files['plugin_id'];
85 $file->file_id = $myrow_files['file_id'];
86 $file->is_active = $myrow_files['is_active'];
87 $files[$file->file_id] = $file;
88 }
kitlo3efbb262010-01-13 15:18:57 +000089 }
90
kitlo41083bd2010-02-16 17:17:10 +000091 # Collect all plugin exclude patterns for this project version
kitlo3e175f42010-01-23 02:26:31 +000092 $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\"";
kitlo2c8d8a92018-04-19 13:25:09 -040093 $rs_patterns = mysqli_query($dbh, $sql);
kitlo3e175f42010-01-23 02:26:31 +000094 $patterns = Array();
kitloff89eb22011-06-29 20:52:24 +000095 # Add default exclude patterns
kitlo17b663e2011-06-30 03:33:01 +000096 $patterns[] = "/^.*\/feature.properties$/";
97 $patterns[] = "/^.*\/build.properties$/";
98 $patterns[] = "/^.*\/pom.properties$/";
kitloff89eb22011-06-29 20:52:24 +000099 $patterns[] = "/^.*\.source\/.*$/";
100 $patterns[] = "/^.*\.test\/.*$/";
101 $patterns[] = "/^.*\.tests\/.*$/";
kitlo17b663e2011-06-30 03:33:01 +0000102 $patterns[] = "/^.*\.testing\/.*$/";
kitlo1d027092018-04-19 17:44:07 -0400103 while ($myrow_patterns = mysqli_fetch_assoc($rs_patterns)) {
kitlo3e175f42010-01-23 02:26:31 +0000104 $patterns[] = $myrow_patterns['pattern'];
105 }
106
kitlo0da4aca2010-01-13 05:08:26 +0000107 # Rsync update site
kitloa3a2ae92011-06-14 22:35:43 +0000108 echo "rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir\n";
kitlo0da4aca2010-01-13 05:08:26 +0000109 exec("mkdir -p $temp_site_dir; rsync -av --delete $rsync_host$site_plugins_dir $temp_site_dir");
110
111 # Make unzip dir
112 mkdir($temp_unzip_dir, 0777, TRUE);
113
kitlo9a507cb2011-12-26 21:17:52 +0000114 # Temporary workaround to remove Eclipse 3.8 plugins in 4.2 update site
115 chdir($temp_site_dir);
116 if ($project_id == "eclipse" && $version == "4.2") {
117 exec("rm org.eclipse.ui.workbench_3.8.*");
kitlo37757562011-12-28 01:00:10 +0000118 exec("rm org.eclipse.update.ui_*");
kitlo9a507cb2011-12-26 21:17:52 +0000119 }
120
kitlo0da4aca2010-01-13 05:08:26 +0000121 # Unzip properties files in each jar
122 chdir($temp_site_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000123 foreach (glob("*.jar") as $jar_name) {
124 # Sample jar name: org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar
125 #
126 # Remove plugin version from jar name:
127 # org.eclipse.ui.workbench_3.6.0.I20100105-1530.jar => org.eclipse.ui.workbench
128 $temp_str = $jar_name;
129 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
130 $temp_str = substr($temp_str, 0, strrpos($temp_str, "."));
131 $temp_str = substr($temp_str, 0, strrpos($temp_str, "_"));
132 $plugin_id = $temp_str;
133
kitlo20071c52010-01-13 14:10:52 +0000134 if (!is_dir($temp_unzip_dir . $plugin_id)) {
135 mkdir($temp_unzip_dir . $plugin_id, 0777, TRUE);
136 }
kitlo0da4aca2010-01-13 05:08:26 +0000137 chdir($temp_unzip_dir . $plugin_id);
kitlo281a6412010-01-13 13:34:57 +0000138 exec("unzip -o -q $temp_site_dir$jar_name");
kitlo2e780dc2010-01-12 17:58:32 +0000139 }
140
kitlo0da4aca2010-01-13 05:08:26 +0000141 # Collect properties file names
kitlo2e780dc2010-01-12 17:58:32 +0000142 $properties_file_names = array();
kitlo0da4aca2010-01-13 05:08:26 +0000143 chdir($temp_unzip_dir);
kitlo2e780dc2010-01-12 17:58:32 +0000144 exec("find . -name *.properties", $properties_file_names);
145 sort($properties_file_names);
146
kitlo0da4aca2010-01-13 05:08:26 +0000147 # Parse each properties file
kitlo2e780dc2010-01-12 17:58:32 +0000148 echo "Start processing properties files in project $project_id version $version...\n";
kitlo4331c752010-02-15 01:45:35 +0000149 echo " Update site location: $site_url\n";
kitlo2e780dc2010-01-12 17:58:32 +0000150 foreach ($properties_file_names as $properties_file_name) {
kitlo3e175f42010-01-23 02:26:31 +0000151 # Remove "./" from beginning of properties file name
kitlo2e780dc2010-01-12 17:58:32 +0000152 $properties_file_name = substr($properties_file_name, 2);
153 $plugin_id = substr($properties_file_name, 0, strpos($properties_file_name, "/"));
154 $file_id = File::getFileID($properties_file_name, $project_id, $version);
kitlo3e175f42010-01-23 02:26:31 +0000155
156 # Match plugin exclude list
157 $match = false;
158 foreach ($patterns as $pattern) {
159 if (preg_match($pattern, $properties_file_name)) {
160 $match = true;
161 break;
kitlo2e780dc2010-01-12 17:58:32 +0000162 }
163 }
kitlo3e175f42010-01-23 02:26:31 +0000164
165 if (!$match) {
kitlob746da42010-02-12 02:40:41 +0000166 if ($file_id > 0 && $files[$file_id] != null) {
kitlo3e175f42010-01-23 02:26:31 +0000167 # Existing file
168 $file = $files[$file_id];
169 $file->is_active = 1;
170 unset($files[$file_id]);
171 } else {
172 # New file
173 $file = new File();
174 $file->project_id = $project_id;
175 $file->version = $version;
176 $file->name = $properties_file_name;
177 $file->plugin_id = $plugin_id;
178 $file->is_active = 1;
179 }
180 if (!$file->save()) {
181 echo "***ERROR: Cannot save file $file->name\n";
182 } else {
183 $file_name = $temp_unzip_dir . $properties_file_name;
droy587ad062019-09-26 14:23:30 -0400184 $file_contents = preg_replace("/\r\n?/", "\n", file_get_contents($file_name));
kitlo37757562011-12-28 01:00:10 +0000185 $file->parseProperties($file_contents);
kitlod12b06b2010-02-12 18:14:40 +0000186 echo " $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000187 }
188 } else {
kitlod12b06b2010-02-12 18:14:40 +0000189 echo " !!! Excluding $properties_file_name\n";
kitlo3e175f42010-01-23 02:26:31 +0000190 }
191 }
kitlo2e780dc2010-01-12 17:58:32 +0000192 echo "Done processing " . sizeof($properties_file_names) . " properties files in project $project_id version $version\n\n";
193}
194
195# Deactivate the rest of the files
kitlod66aa992010-01-22 17:18:19 +0000196echo "Start deactivating inactive properties files in all projects above...\n";
kitlo2e780dc2010-01-12 17:58:32 +0000197foreach ($files as $file) {
kitlo4331c752010-02-15 01:45:35 +0000198 if ($file->is_active == 1) {
199 $file->is_active = 0;
200 if (!$file->save()) {
201 echo "***ERROR: Cannot deactivate file $file->name\n";
202 }
kitlo2e780dc2010-01-12 17:58:32 +0000203 echo " " . $file->name . "\n";
kitlo4331c752010-02-15 01:45:35 +0000204 } else {
205 unset($files[$file->file_id]);
206 }
kitlo2e780dc2010-01-12 17:58:32 +0000207}
kitlod66aa992010-01-22 17:18:19 +0000208echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
kitlo2e780dc2010-01-12 17:58:32 +0000209
kitlo59274fb2010-02-12 03:31:34 +0000210if (is_dir($temp_unzips_dir)) {
211 exec("rm -rf $temp_unzips_dir");
212}
213
kitlo2e780dc2010-01-12 17:58:32 +0000214if ($headless) {
215 $User = null;
216}
217
218echo "Done\n";
219?>