blob: 6a8b64afb0a37b51e9793ea0ebd5050f5a562ad6 [file] [log] [blame]
droy3bb0c962008-01-17 20:45:01 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2008 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 * Eclipse Foundation - Initial API and implementation
droyb9c2cb12008-10-08 13:58:14 +000011 * Antoine Toulmé - Bug 248917
atoulmea8c21012009-01-27 14:06:40 +000012 * Motorola - Change SVN map file format to follow SVN PDE
13 * Gustavo de Paula - Bug 261252
kitlofe25fa92009-04-15 04:17:04 +000014 * Kit Lo (IBM) - Bug 266250, Map file processor not running properly on live server
15 * Kit Lo (IBM) - Bug 272176, Support "bundle" element type in map file
kitlob8dd4b32010-01-12 17:57:34 +000016 * Kit Lo (IBM) - Bug 257332, NLS warnings appear unnecessarily in runtime log
kitlo3d59f972010-02-15 01:47:29 +000017 * Kit Lo (IBM) - Bug 302834, Add plugin filtering supports to map files process
kitlo7e46a452012-06-18 12:48:24 +000018 * Kit Lo (IBM) - [382800] CSSUIPluginResources.properties is missing on translator tool
droy3bb0c962008-01-17 20:45:01 +000019*******************************************************************************/
kitlo9d573732010-02-15 20:15:16 +000020$temp_dir = "/tmp/tmp-babel/";
21$files = array();
kitlo41083bd2010-02-16 17:17:10 +000022$files_collected = array(array());
kitlo9d573732010-02-15 20:15:16 +000023
droy87d1b182008-03-04 21:55:24 +000024header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000025include("global.php");
26InitPage("");
27
droy58210512008-02-05 16:05:48 +000028$headless = 0;
kitlo3d59f972010-02-15 01:47:29 +000029if (!isset($User)) {
30 echo "User not defined - running headless\n";
kitlo9d573732010-02-15 20:15:16 +000031 $User = getGenieUser();
32 $headless = 1;
droy58210512008-02-05 16:05:48 +000033}
34
atoulme12882d52009-01-26 18:39:17 +000035require(dirname(__FILE__) . "/../classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000036$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000037
atoulme3e5e9342009-01-23 17:34:30 +000038global $dbh;
droy3bb0c962008-01-17 20:45:01 +000039
kitlo9d573732010-02-15 20:15:16 +000040$temp_downloads_dir = $temp_dir . "downloads/";
41if (!is_dir($temp_downloads_dir)) {
42 mkdir($temp_downloads_dir) || die("Cannot create a working directory");
droy3bb0c962008-01-17 20:45:01 +000043}
kitlo9d573732010-02-15 20:15:16 +000044chdir($temp_downloads_dir) || die("Cannot use working directory");
droy3bb0c962008-01-17 20:45:01 +000045
droy1cdb7092010-04-19 20:38:19 +000046$sql = "SELECT * FROM map_files AS m
47INNER JOIN release_train_projects AS r ON r.project_id = m.project_id AND r.version = m.version
48INNER JOIN release_trains AS t on t.train_id = r.train_id
49WHERE m.is_active = 1 AND m.is_map_file = 1 AND t.is_active = 1";
droy3bb0c962008-01-17 20:45:01 +000050$rs_maps = mysql_query($sql, $dbh);
kitlo3d59f972010-02-15 01:47:29 +000051while ($myrow_maps = mysql_fetch_assoc($rs_maps)) {
52 $location = $myrow_maps['location'];
53 $project_id = $myrow_maps['project_id'];
54 $version = $myrow_maps['version'];
55 $properties_file_count = 0;
droy3bb0c962008-01-17 20:45:01 +000056
kitlo3d59f972010-02-15 01:47:29 +000057 # Parse each properties file for this project version
58 echo "Start processing properties files in project $project_id version $version...\n";
59 echo " Map file location: $location\n";
60
kitlo41083bd2010-02-16 17:17:10 +000061 # Collect all files for this project version
62 if (!(isset($files_collected[$project_id]) && isset($files_collected[$project_id][$version]))) {
63 $files_collected[$project_id][$version] = 1;
64 $sql = "SELECT * FROM files WHERE project_id = \"$project_id\" AND version = \"$version\"";
65 $rs_files = mysql_query($sql, $dbh);
66 while($myrow_files = mysql_fetch_assoc($rs_files)) {
67 $file = new File();
68 $file->project_id = $myrow_files['project_id'];
69 $file->version = $myrow_files['version'];
70 $file->name = $myrow_files['name'];
71 $file->plugin_id = $myrow_files['plugin_id'];
72 $file->file_id = $myrow_files['file_id'];
73 $file->is_active = $myrow_files['is_active'];
74 $files[$file->file_id] = $file;
75 }
kitlo3d59f972010-02-15 01:47:29 +000076 }
77
kitlo41083bd2010-02-16 17:17:10 +000078 # Collect all plugin exclude patterns for this project version
kitlo3d59f972010-02-15 01:47:29 +000079 $sql = "SELECT pattern FROM plugin_exclude_patterns WHERE project_id = \"$project_id\" AND version = \"$version\"";
80 $rs_patterns = mysql_query($sql, $dbh);
81 $patterns = Array();
kitloff89eb22011-06-29 20:52:24 +000082 # Add default exclude patterns
kitlo17b663e2011-06-30 03:33:01 +000083 $patterns[] = "/^.*\/feature.properties$/";
84 $patterns[] = "/^.*\/build.properties$/";
85 $patterns[] = "/^.*\/pom.properties$/";
kitloff89eb22011-06-29 20:52:24 +000086 $patterns[] = "/^.*\.source\/.*$/";
87 $patterns[] = "/^.*\.test\/.*$/";
88 $patterns[] = "/^.*\.tests\/.*$/";
kitlo17b663e2011-06-30 03:33:01 +000089 $patterns[] = "/^.*\.testing\/.*$/";
kitlo3d59f972010-02-15 01:47:29 +000090 while ($myrow_patterns = mysql_fetch_assoc($rs_patterns)) {
91 $patterns[] = $myrow_patterns['pattern'];
92 }
93
94 # echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
95
kitlo9d573732010-02-15 20:15:16 +000096 $tmpdir = $temp_downloads_dir . str_replace(" ", "_", $myrow_maps['project_id']);
kitlo3d59f972010-02-15 01:47:29 +000097 if (is_dir($tmpdir)) {
98 # zap the directory to make sure CVS versions don't overlap
99 exec("rm -rf " . $tmpdir);
100 }
101 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
102 chdir($tmpdir) || die("Cannot write to $tmpdir !");
103
104 $h = fopen($myrow_maps['location'], "rb");
105 $file_contents = stream_get_contents($h);
106 fclose($h);
107 $file_contents = ereg_replace("\r\n?", "\n", $file_contents);
108 $aLines = split("\n", $file_contents);
109
110 foreach ($aLines as $line) {
111 $line = trim($line);
112
113 # $line looks something like this:
114 # See http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tasks/pde_fetch_phase.htm for more info
115 # plugin@org.eclipse.emf.query=v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
116 # plugin@org.eclipse.equinox.frameworkadmin=CVS,tag=R34x_v20080910,cvsRoot=:pserver:anonymous@dev.eclipse.org:/cvsroot/rt,path=org.eclipse.equinox/p2/bundles/org.eclipse.equinox.frameworkadmin
117 # bundle@org.eclipse.wst.xml.xpath.ui=v200902122100,:pserver:anonymous@dev.eclipse.org:/cvsroot/webtools,,sourceediting/plugins/org.eclipse.wst.xml.xpath.ui
118
119 # Bug 272176 - Support "bundle" element type in map file
120 if (preg_match("/^(plugin|bundle)/", $line)) {
121 # echo $html_spacer . "Processing line: " . $line . "\n";
122 $aParts = split("=", $line);
123 $aElements = split("@", $aParts[0]);
124 $plugin_id = $aElements[1];
125 # Bug 272176 - Support "bundle" element type in map file
126 if ($aElements[0] == "plugin" || $aElements[0] == "bundle") {
127 $plugin = $aParts[1];
128 if ($aParts[1] == "CVS,tag") {
129 $tagPart = split(",", $aParts[2]);
130 $cvsRootPart = split(",", $aParts[3]);
131 $plugin = $tagPart[0] . "," . $cvsRootPart[0] . "," . $aParts[4];
kitlo86e005d2011-08-14 03:25:27 +0000132 } elseif ($aParts[1] == "SVN,url") {
133 # Support STEM project SVN syntax
134 # plugin@org.eclipse.stem.core=SVN,url=http://dev.eclipse.org/svnroot/technology/org.eclipse.stem,tag=trunk,path=core/org.eclipse.stem.core
135 #
136 # maps $plugin to:
137 # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath>
138 $svnRootPart = split(",", $aParts[2]);
139 $svnTagPart = split(",", $aParts[3]);
140 $plugin = "SVN," . $svnTagPart[0] . "," . $svnRootPart[0] . ",," . $aParts[4];
kitlo3d59f972010-02-15 01:47:29 +0000141 }
142 $aStuff = parseLocation($plugin);
143
144 $tagstring = "";
145 if (isset($aStuff['tag'])) {
146 $tagstring = "-r " . $aStuff['tag'] . " ";
147 }
148 if (isset($aStuff['plugin'])) {
149 if ($aStuff['plugin'] != "") {
150 $aElements[1] = $aStuff['plugin'];
151 }
152 }
153
154 $command = "";
155 # determine CVS or SVN
156 if (isset($aStuff['cvsroot'])) {
157 $command = "cvs -q -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
158 } elseif (isset($aStuff['svnroot'])) {
159 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
160 }
161 # echo $html_spacer . $html_spacer ."--> " . $command . "\n";
162
163 $out = "";
164 if ($command != "") {
165 $out = shell_exec($command);
166 }
167
168 # process the output lines for .properties
169 $aOutLines = split("\n", $out);
170 foreach ($aOutLines as $out_line) {
171 $out_line = trim($out_line);
172 # remove SVN's multiple spaces
173 $out_line = preg_replace("/\s+/", " ", $out_line);
174
175 # echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
176 # CVS:
177 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
178 # SVN:
179 # A org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn/org.eclipse.stp.eid/trunk/org.eclipse.stp.eid.generator.test/build.properties
kitlo8d6aa4e2011-06-30 04:47:38 +0000180 if (preg_match("/\.properties$/", $out_line)) {
kitlo3d59f972010-02-15 01:47:29 +0000181 # this is a .properties file!
kitlo9430efa2011-06-29 22:50:58 +0000182 $repository_file_name = trim(substr($out_line, 2));
183 $file_name = $repository_file_name;
184
185 # remove optional outer dirs, e.g. 'pde/ui/'
186 $pos = strripos($file_name, 'org.');
187 if ($pos !== false) {
188 $file_name = substr($file_name, $pos);
189 }
190 $pos = strripos($file_name, 'com.');
191 if ($pos !== false) {
192 $file_name = substr($file_name, $pos);
193 }
194
195 $pattern =
196 '/^
197 (.*?)? # $1 plugin name
198 \/ # slash
199 (.*?\/)? # $2 dir name
200 ([^\/]+[.]properties) # $3 file name
201 $/ix';
202 $plugin_name_string = preg_replace($pattern, '$1', $file_name);
203 $dir_name_string = preg_replace($pattern, '$2', $file_name);
204 $file_name_string = preg_replace($pattern, '$3', $file_name);
205
206 # remove optional source dir, e.g. 'src' or 'src_ant'
207 $pos = stripos($dir_name_string, 'org/');
208 if ($pos !== false) {
209 $dir_name_string = substr($dir_name_string, $pos);
210 }
211 $pos = strripos($dir_name_string, 'com/');
212 if ($pos !== false) {
213 $dir_name_string = substr($dir_name_string, $pos);
214 }
215
216 $file_name = $plugin_name_string . "/" . $dir_name_string . $file_name_string;
217
kitlo3d59f972010-02-15 01:47:29 +0000218 $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
219 $properties_file_count = $properties_file_count + 1;
220
221 # Match plugin exclude list
222 $match = false;
223 foreach ($patterns as $pattern) {
224 if (preg_match($pattern, $file_name)) {
225 $match = true;
226 break;
227 }
228 }
229
230 if (!$match) {
231 if ($file_id > 0 && $files[$file_id] != null) {
kitlo41083bd2010-02-16 17:17:10 +0000232 # Existing file
kitlo3d59f972010-02-15 01:47:29 +0000233 $file = $files[$file_id];
234 $file->is_active = 1;
235 unset($files[$file_id]);
236 } else {
kitlo41083bd2010-02-16 17:17:10 +0000237 # New file
kitlo3d59f972010-02-15 01:47:29 +0000238 $file = new File();
239 $file->project_id = $myrow_maps['project_id'];
240 $file->version = $myrow_maps['version'];
241 $file->name = $file_name;
242 $file->plugin_id = $plugin_id;
243 $file->is_active = 1;
244 }
245 if (!$file->save()) {
246 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
247 } else {
kitlo9430efa2011-06-29 22:50:58 +0000248 $file->parseProperties(file_get_contents($repository_file_name));
kitlo3d59f972010-02-15 01:47:29 +0000249 echo " $file_name\n";
250 }
251 } else {
252 echo " !!! Excluding $file_name\n";
253 }
254 }
255 }
256 }
257 }
258 }
259 echo "Done processing " . $properties_file_count . " properties files in project $project_id version $version\n\n";
droy3bb0c962008-01-17 20:45:01 +0000260}
atoulmee9ec6d82008-11-19 14:41:30 +0000261
kitlo3d59f972010-02-15 01:47:29 +0000262# Deactivate the rest of the files
263echo "Start deactivating inactive properties files in all projects above...\n";
atoulmee9ec6d82008-11-19 14:41:30 +0000264foreach ($files as $file) {
kitlo3d59f972010-02-15 01:47:29 +0000265 if ($file->is_active == 1) {
266 $file->is_active = 0;
267 if (!$file->save()) {
268 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
269 }
270 echo " " . $file->name . "\n";
271 } else {
272 unset($files[$file->file_id]);
273 }
274}
275echo "Done deactivating " . sizeof($files) . " inactive properties files in all projects above\n\n";
276
kitlo9d573732010-02-15 20:15:16 +0000277if (is_dir($temp_downloads_dir)) {
278 exec("rm -rf $temp_downloads_dir");
279}
280
kitlo3d59f972010-02-15 01:47:29 +0000281if ($headless) {
282 $User = null;
atoulmee9ec6d82008-11-19 14:41:30 +0000283}
284
kitlo3d59f972010-02-15 01:47:29 +0000285echo "Done\n";
droy58210512008-02-05 16:05:48 +0000286
droy3bb0c962008-01-17 20:45:01 +0000287function parseLocation($in_string) {
kitlo3d59f972010-02-15 01:47:29 +0000288 # in_string looks something like this:
289 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
290 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
291 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
292 # SVN,tags/1.0M5,http://dev.eclipse.org/svnroot/dsdp/org.eclipse.mtj,,features/org.eclipse.mtj
293 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy3bb0c962008-01-17 20:45:01 +0000294
kitlo3d59f972010-02-15 01:47:29 +0000295 $aTheseElements = array();
296
297 $aLocation = split(",", $in_string);
298 foreach($aLocation as $location_part) {
299 # TAG
300 # Bug 257332, NLS warnings appear unnecessarily in runtime log
301 if (preg_match("/^[0-9a-zA-Z_]+/", $location_part) && !isset($aTheseElements['cvsroot'])) {
302 $aTheseElements['tag'] = $location_part;
303 }
304 # CVSROOT
305 if (preg_match("/^:.*:.*@.*:\//", $location_part)) {
306 $aTheseElements['cvsroot'] = $location_part;
307 }
308 # SVNROOT
309 # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath>
310 # maps to: svn://<svnRepositoryURL>/<preTagPath>/<tagPath>/<postTagPath>
311 if (preg_match("/^(http|svn):\/\//", $location_part)) {
312 $location_part = str_replace("http", "svn", $location_part);
313 if ($aLocation[3] == ' ' || $aLocation[3] == '') {
314 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[1] . "/" . $aLocation[4];
315 } else {
316 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[3] . "/" . $aLocation[1] . "/" . $aLocation[4];
317 }
318 }
319 }
320
321 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
322
323 return $aTheseElements;
324}
droyb9c2cb12008-10-08 13:58:14 +0000325?>