blob: 6b6870d399fda372b774adc0c7a8f54fee4ea141 [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
droy3bb0c962008-01-17 20:45:01 +000017*******************************************************************************/
droy87d1b182008-03-04 21:55:24 +000018header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000019include("global.php");
20InitPage("");
21
droy58210512008-02-05 16:05:48 +000022$headless = 0;
23if(!isset($User)) {
24 echo "User not defined -- running headless.";
atoulme9118d612008-11-12 18:21:38 +000025 $User = getGenieUser();
droy58210512008-02-05 16:05:48 +000026 $headless = 1;
27}
28
droy3bb0c962008-01-17 20:45:01 +000029
atoulme12882d52009-01-26 18:39:17 +000030require(dirname(__FILE__) . "/../classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000031$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000032
atoulme3e5e9342009-01-23 17:34:30 +000033global $dbh;
droy3bb0c962008-01-17 20:45:01 +000034
35if(!is_dir("/tmp/tmp-babel")) {
36 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
37}
38chdir("/tmp/tmp-babel") || die("Cannot use working directory");
39
40
atoulmee9ec6d82008-11-19 14:41:30 +000041$files = array();
42$sql = "SELECT * from files";
43$rs_files = mysql_query($sql, $dbh);
44while($myrow_file = mysql_fetch_assoc($rs_files)) {
45 $File = new File();
46 $File->project_id = $myrow_file['project_id'];
47 $File->version = $myrow_file['version'];
48 $File->name = $myrow_file['name'];
49 $File->plugin_id = $myrow_file['plugin_id'];
50 $File->file_id = $myrow_file['file_id'];
51 $files[$File->file_id] = $File;
52}
droy3bb0c962008-01-17 20:45:01 +000053
54
droyabf32a12008-05-09 18:46:20 +000055$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000056$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000057while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000058 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000059
atoulme84cb3742008-12-05 11:01:39 +000060 $tmpdir = "/tmp/tmp-babel/" . str_replace(" ", "_", $myrow_maps['project_id']);
droyd9a61af2008-02-26 16:20:29 +000061 if(is_dir($tmpdir)) {
62 # zap the directory to make sure CVS versions don't overlap
63 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000064 }
droyd9a61af2008-02-26 16:20:29 +000065 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000066 chdir($tmpdir) || die("Cannot write to $tmpdir !");
67
droyd9a61af2008-02-26 16:20:29 +000068 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000069 $file_contents = stream_get_contents($h);
70 fclose($h);
atoulmedfab0852009-02-16 11:47:31 +000071 $file_contents = ereg_replace("\r\n?", "\n", $file_contents);
droy3bb0c962008-01-17 20:45:01 +000072 $aLines = split("\n", $file_contents);
73
74
75 foreach ($aLines as $line) {
76 $line = trim($line);
77
kitlo2f6982f2009-03-12 14:06:38 +000078 # $line looks something like this:
kitlofe25fa92009-04-15 04:17:04 +000079 # See http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tasks/pde_fetch_phase.htm for more info
droy87d1b182008-03-04 21:55:24 +000080 # 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
kitlo2f6982f2009-03-12 14:06:38 +000081 # 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
kitlofe25fa92009-04-15 04:17:04 +000082 # bundle@org.eclipse.wst.xml.xpath.ui=v200902122100,:pserver:anonymous@dev.eclipse.org:/cvsroot/webtools,,sourceediting/plugins/org.eclipse.wst.xml.xpath.ui
83
84 # Bug 272176 - Support "bundle" element type in map file
85 if(preg_match("/^(plugin|bundle)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000086 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000087 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000088 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000089 $plugin_id = $aElements[1];
kitlofe25fa92009-04-15 04:17:04 +000090 # Bug 272176 - Support "bundle" element type in map file
91 if($aElements[0] == "plugin" || $aElements[0] == "bundle") {
kitlo2f6982f2009-03-12 14:06:38 +000092 $plugin = $aParts[1];
93 if($aParts[1] == "CVS,tag") {
94 $tagPart = split(",", $aParts[2]);
95 $cvsRootPart = split(",", $aParts[3]);
96 $plugin = $tagPart[0] . "," . $cvsRootPart[0] . "," . $aParts[4];
97 }
98 echo $html_spacer . $html_spacer . "Processing plugin: " . $plugin . "\n";
99 $aStuff = parseLocation($plugin);
droy3bb0c962008-01-17 20:45:01 +0000100
101 $tagstring = "";
102 if(isset($aStuff['tag'])) {
103 $tagstring = "-r " . $aStuff['tag'] . " ";
104 }
droy87d1b182008-03-04 21:55:24 +0000105 if(isset($aStuff['plugin'])) {
106 if($aStuff['plugin'] != "") {
107 $aElements[1] = $aStuff['plugin'];
108 }
109 }
droyd9a61af2008-02-26 16:20:29 +0000110
droyf3b43282008-05-09 18:45:12 +0000111 $command = "";
112 # determine CVS or SVN
113 if(isset($aStuff['cvsroot'])) {
114 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
115 }
116 elseif( isset($aStuff['svnroot'])) {
117 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
118 }
droy87d1b182008-03-04 21:55:24 +0000119 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +0000120
121 $out = "";
122 if($command != "") {
123 $out = shell_exec($command);
124 }
droy3bb0c962008-01-17 20:45:01 +0000125
126 # process the output lines for .properties
127 $aOutLines = split("\n", $out);
128 foreach ($aOutLines as $out_line) {
129 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000130 # remove SVN's multiple spaces
131 $out_line = preg_replace("/\s+/", " ", $out_line);
132
droy87d1b182008-03-04 21:55:24 +0000133 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000134 # CVS:
droyec50f102008-02-01 19:33:10 +0000135 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000136 # SVN:
137 # A org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn/org.eclipse.stp.eid/trunk/org.eclipse.stp.eid.generator.test/build.properties
droye19e49b2008-01-31 14:05:50 +0000138 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000139 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000140 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000141 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000142
atoulmebe3eae82008-12-05 16:38:20 +0000143 $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
atoulmee9ec6d82008-11-19 14:41:30 +0000144
145 if ($files[$file_id] != null) {
146 $File = $files[$file_id];
atoulmea80e8272009-03-01 11:28:05 +0000147 $File->is_active = 1;
atoulmee9ec6d82008-11-19 14:41:30 +0000148 unset($files[$file_id]);
149 } else {
150 $File = new File();
151 $File->project_id = $myrow_maps['project_id'];
152 $File->version = $myrow_maps['version'];
153 $File->name = $file_name;
154 $File->plugin_id = $plugin_id;
atoulmea80e8272009-03-01 11:28:05 +0000155 $File->is_active = 1;
atoulmee9ec6d82008-11-19 14:41:30 +0000156 }
droy3bb0c962008-01-17 20:45:01 +0000157 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000158 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000159 }
160 else {
161 # Start importing the strings!
162 $fh = fopen($file_name, 'r');
163 $size = filesize($file_name);
164
165 $content = fread($fh, $size);
166 fclose($fh);
167
168 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000169 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000170 }
171
172 }
173 }
174 }
175 }
176 }
177}
atoulmee9ec6d82008-11-19 14:41:30 +0000178echo "Marking the remaining files as inactive\n";
179
180foreach ($files as $file) {
atoulmea80e8272009-03-01 11:28:05 +0000181 $file->is_active = 0;
atoulmee9ec6d82008-11-19 14:41:30 +0000182 if(!$file->save()) {
183 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
184 }
185}
186
droy1df37fc2008-02-28 21:29:46 +0000187echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000188
droy58210512008-02-05 16:05:48 +0000189if($headless) {
190 $User = null;
191}
192
droy3bb0c962008-01-17 20:45:01 +0000193function parseLocation($in_string) {
194 # in_string looks something like this:
195 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000196 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000197 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
atoulmea8c21012009-01-27 14:06:40 +0000198 # SVN,tags/1.0M5,http://dev.eclipse.org/svnroot/dsdp/org.eclipse.mtj,,features/org.eclipse.mtj
droyf3b43282008-05-09 18:45:12 +0000199 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000200
droyd9a61af2008-02-26 16:20:29 +0000201 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000202
203 $aLocation = split(",", $in_string);
204 foreach($aLocation as $location_part) {
205 # TAG
kitlob8dd4b32010-01-12 17:57:34 +0000206 # Bug 257332, NLS warnings appear unnecessarily in runtime log
207 if(preg_match("/^[0-9a-zA-Z_]+/", $location_part) && !isset($aTheseElements['cvsroot'])) {
droyd9a61af2008-02-26 16:20:29 +0000208 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000209 }
210 # CVSROOT
211 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000212 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000213 }
droyf3b43282008-05-09 18:45:12 +0000214 # SVNROOT
atoulmea8c21012009-01-27 14:06:40 +0000215 # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath>
216 # maps to: svn://<svnRepositoryURL>/<preTagPath>/<tagPath>/<postTagPath>
droyf3b43282008-05-09 18:45:12 +0000217 if(preg_match("/^(http|svn):\/\//", $location_part)) {
218 $location_part = str_replace("http", "svn", $location_part);
atoulmea8c21012009-01-27 14:06:40 +0000219 if ($aLocation[3] == ' ' || $aLocation[3] == '') {
220 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[1] . "/" . $aLocation[4];
221 } else {
222 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[3] . "/" . $aLocation[1] . "/" . $aLocation[4];
223 }
droyf3b43282008-05-09 18:45:12 +0000224 }
droy3bb0c962008-01-17 20:45:01 +0000225 }
226
droy87d1b182008-03-04 21:55:24 +0000227 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
228
droyd9a61af2008-02-26 16:20:29 +0000229 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000230}
231
droyb9c2cb12008-10-08 13:58:14 +0000232?>