droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 1 | <?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 |
droy | b9c2cb1 | 2008-10-08 13:58:14 +0000 | [diff] [blame] | 11 | * Antoine Toulmé - Bug 248917 |
atoulme | a8c2101 | 2009-01-27 14:06:40 +0000 | [diff] [blame] | 12 | * Motorola - Change SVN map file format to follow SVN PDE |
| 13 | * Gustavo de Paula - Bug 261252 |
kitlo | fe25fa9 | 2009-04-15 04:17:04 +0000 | [diff] [blame] | 14 | * 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 |
kitlo | b8dd4b3 | 2010-01-12 17:57:34 +0000 | [diff] [blame] | 16 | * Kit Lo (IBM) - Bug 257332, NLS warnings appear unnecessarily in runtime log |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 17 | *******************************************************************************/ |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 18 | header("Content-type: text/plain"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 19 | include("global.php"); |
| 20 | InitPage(""); |
| 21 | |
droy | 5821051 | 2008-02-05 16:05:48 +0000 | [diff] [blame] | 22 | $headless = 0; |
| 23 | if(!isset($User)) { |
| 24 | echo "User not defined -- running headless."; |
atoulme | 9118d61 | 2008-11-12 18:21:38 +0000 | [diff] [blame] | 25 | $User = getGenieUser(); |
droy | 5821051 | 2008-02-05 16:05:48 +0000 | [diff] [blame] | 26 | $headless = 1; |
| 27 | } |
| 28 | |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 29 | |
atoulme | 12882d5 | 2009-01-26 18:39:17 +0000 | [diff] [blame] | 30 | require(dirname(__FILE__) . "/../classes/file/file.class.php"); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 31 | $html_spacer = " "; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 32 | |
atoulme | 3e5e934 | 2009-01-23 17:34:30 +0000 | [diff] [blame] | 33 | global $dbh; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 34 | |
| 35 | if(!is_dir("/tmp/tmp-babel")) { |
| 36 | mkdir("/tmp/tmp-babel") || die("Cannot create a working directory"); |
| 37 | } |
| 38 | chdir("/tmp/tmp-babel") || die("Cannot use working directory"); |
| 39 | |
| 40 | |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 41 | $files = array(); |
| 42 | $sql = "SELECT * from files"; |
| 43 | $rs_files = mysql_query($sql, $dbh); |
| 44 | while($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 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 53 | |
| 54 | |
droy | abf32a1 | 2008-05-09 18:46:20 +0000 | [diff] [blame] | 55 | $sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 56 | $rs_maps = mysql_query($sql, $dbh); |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 57 | while($myrow_maps = mysql_fetch_assoc($rs_maps)) { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 58 | echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 59 | |
atoulme | 84cb374 | 2008-12-05 11:01:39 +0000 | [diff] [blame] | 60 | $tmpdir = "/tmp/tmp-babel/" . str_replace(" ", "_", $myrow_maps['project_id']); |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 61 | if(is_dir($tmpdir)) { |
| 62 | # zap the directory to make sure CVS versions don't overlap |
| 63 | exec("rm -rf " . $tmpdir); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 64 | } |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 65 | mkdir($tmpdir) || die("Cannot create working directory $tmpdir !"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 66 | chdir($tmpdir) || die("Cannot write to $tmpdir !"); |
| 67 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 68 | $h = fopen($myrow_maps['location'], "rb"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 69 | $file_contents = stream_get_contents($h); |
| 70 | fclose($h); |
atoulme | dfab085 | 2009-02-16 11:47:31 +0000 | [diff] [blame] | 71 | $file_contents = ereg_replace("\r\n?", "\n", $file_contents); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 72 | $aLines = split("\n", $file_contents); |
| 73 | |
| 74 | |
| 75 | foreach ($aLines as $line) { |
| 76 | $line = trim($line); |
| 77 | |
kitlo | 2f6982f | 2009-03-12 14:06:38 +0000 | [diff] [blame] | 78 | # $line looks something like this: |
kitlo | fe25fa9 | 2009-04-15 04:17:04 +0000 | [diff] [blame] | 79 | # See http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tasks/pde_fetch_phase.htm for more info |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 80 | # 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 |
kitlo | 2f6982f | 2009-03-12 14:06:38 +0000 | [diff] [blame] | 81 | # 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 |
kitlo | fe25fa9 | 2009-04-15 04:17:04 +0000 | [diff] [blame] | 82 | # 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)) { |
droy | b9c2cb1 | 2008-10-08 13:58:14 +0000 | [diff] [blame] | 86 | echo $html_spacer . "Processing line: " . $line . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 87 | $aParts = split("=", $line); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 88 | $aElements = split("@", $aParts[0]); |
droy | b9c2cb1 | 2008-10-08 13:58:14 +0000 | [diff] [blame] | 89 | $plugin_id = $aElements[1]; |
kitlo | fe25fa9 | 2009-04-15 04:17:04 +0000 | [diff] [blame] | 90 | # Bug 272176 - Support "bundle" element type in map file |
| 91 | if($aElements[0] == "plugin" || $aElements[0] == "bundle") { |
kitlo | 2f6982f | 2009-03-12 14:06:38 +0000 | [diff] [blame] | 92 | $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); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 100 | |
| 101 | $tagstring = ""; |
| 102 | if(isset($aStuff['tag'])) { |
| 103 | $tagstring = "-r " . $aStuff['tag'] . " "; |
| 104 | } |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 105 | if(isset($aStuff['plugin'])) { |
| 106 | if($aStuff['plugin'] != "") { |
| 107 | $aElements[1] = $aStuff['plugin']; |
| 108 | } |
| 109 | } |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 110 | |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 111 | $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 | } |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 119 | echo $html_spacer . $html_spacer ."--> " . $command . "\n"; |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 120 | |
| 121 | $out = ""; |
| 122 | if($command != "") { |
| 123 | $out = shell_exec($command); |
| 124 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 125 | |
| 126 | # process the output lines for .properties |
| 127 | $aOutLines = split("\n", $out); |
| 128 | foreach ($aOutLines as $out_line) { |
| 129 | $out_line = trim($out_line); |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 130 | # remove SVN's multiple spaces |
| 131 | $out_line = preg_replace("/\s+/", " ", $out_line); |
| 132 | |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 133 | echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n"; |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 134 | # CVS: |
droy | ec50f10 | 2008-02-01 19:33:10 +0000 | [diff] [blame] | 135 | # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 136 | # 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 |
droy | e19e49b | 2008-01-31 14:05:50 +0000 | [diff] [blame] | 138 | if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) { |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 139 | # this is a .properties file! |
droy | ec50f10 | 2008-02-01 19:33:10 +0000 | [diff] [blame] | 140 | $file_name = trim(substr($out_line, 2)); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 141 | echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 142 | |
atoulme | be3eae8 | 2008-12-05 16:38:20 +0000 | [diff] [blame] | 143 | $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']); |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 144 | |
| 145 | if ($files[$file_id] != null) { |
| 146 | $File = $files[$file_id]; |
atoulme | a80e827 | 2009-03-01 11:28:05 +0000 | [diff] [blame] | 147 | $File->is_active = 1; |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 148 | 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; |
atoulme | a80e827 | 2009-03-01 11:28:05 +0000 | [diff] [blame] | 155 | $File->is_active = 1; |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 156 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 157 | if(!$File->save()) { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 158 | echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 159 | } |
| 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); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 169 | echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | } |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 178 | echo "Marking the remaining files as inactive\n"; |
| 179 | |
| 180 | foreach ($files as $file) { |
atoulme | a80e827 | 2009-03-01 11:28:05 +0000 | [diff] [blame] | 181 | $file->is_active = 0; |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 182 | if(!$file->save()) { |
| 183 | echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n"; |
| 184 | } |
| 185 | } |
| 186 | |
droy | 1df37fc | 2008-02-28 21:29:46 +0000 | [diff] [blame] | 187 | echo "Done."; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 188 | |
droy | 5821051 | 2008-02-05 16:05:48 +0000 | [diff] [blame] | 189 | if($headless) { |
| 190 | $User = null; |
| 191 | } |
| 192 | |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 193 | function parseLocation($in_string) { |
| 194 | # in_string looks something like this: |
| 195 | # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse, |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 196 | # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 197 | # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query |
atoulme | a8c2101 | 2009-01-27 14:06:40 +0000 | [diff] [blame] | 198 | # SVN,tags/1.0M5,http://dev.eclipse.org/svnroot/dsdp/org.eclipse.mtj,,features/org.eclipse.mtj |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 199 | # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/ |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 200 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 201 | $aTheseElements = array(); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 202 | |
| 203 | $aLocation = split(",", $in_string); |
| 204 | foreach($aLocation as $location_part) { |
| 205 | # TAG |
kitlo | b8dd4b3 | 2010-01-12 17:57:34 +0000 | [diff] [blame] | 206 | # Bug 257332, NLS warnings appear unnecessarily in runtime log |
| 207 | if(preg_match("/^[0-9a-zA-Z_]+/", $location_part) && !isset($aTheseElements['cvsroot'])) { |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 208 | $aTheseElements['tag'] = $location_part; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 209 | } |
| 210 | # CVSROOT |
| 211 | if(preg_match("/^:.*:.*@.*:\//", $location_part)) { |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 212 | $aTheseElements['cvsroot'] = $location_part; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 213 | } |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 214 | # SVNROOT |
atoulme | a8c2101 | 2009-01-27 14:06:40 +0000 | [diff] [blame] | 215 | # SVN,<tagPath>[:revision],<svnRepositoryURL>,<preTagPath>,<postTagPath> |
| 216 | # maps to: svn://<svnRepositoryURL>/<preTagPath>/<tagPath>/<postTagPath> |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 217 | if(preg_match("/^(http|svn):\/\//", $location_part)) { |
| 218 | $location_part = str_replace("http", "svn", $location_part); |
atoulme | a8c2101 | 2009-01-27 14:06:40 +0000 | [diff] [blame] | 219 | 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 | } |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 224 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 225 | } |
| 226 | |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 227 | $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1); |
| 228 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 229 | return $aTheseElements; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 230 | } |
| 231 | |
droy | b9c2cb1 | 2008-10-08 13:58:14 +0000 | [diff] [blame] | 232 | ?> |