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 |
| 11 | *******************************************************************************/ |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 12 | header("Content-type: text/plain"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 13 | include("global.php"); |
| 14 | InitPage(""); |
| 15 | |
droy | 5821051 | 2008-02-05 16:05:48 +0000 | [diff] [blame] | 16 | $headless = 0; |
| 17 | if(!isset($User)) { |
| 18 | echo "User not defined -- running headless."; |
| 19 | $User = new User(); |
| 20 | $User->loadFromID(40623); // genie |
| 21 | $headless = 1; |
| 22 | } |
| 23 | |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 24 | |
| 25 | require(BABEL_BASE_DIR . "classes/file/file.class.php"); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 26 | $html_spacer = " "; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 27 | |
| 28 | global $App, $dbh; |
| 29 | |
| 30 | if(!is_dir("/tmp/tmp-babel")) { |
| 31 | mkdir("/tmp/tmp-babel") || die("Cannot create a working directory"); |
| 32 | } |
| 33 | chdir("/tmp/tmp-babel") || die("Cannot use working directory"); |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
droy | abf32a1 | 2008-05-09 18:46:20 +0000 | [diff] [blame] | 38 | $sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 39 | $rs_maps = mysql_query($sql, $dbh); |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 40 | while($myrow_maps = mysql_fetch_assoc($rs_maps)) { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 41 | echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 42 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 43 | $tmpdir = "/tmp/tmp-babel/" . $myrow_maps['project_id']; |
| 44 | if(is_dir($tmpdir)) { |
| 45 | # zap the directory to make sure CVS versions don't overlap |
| 46 | exec("rm -rf " . $tmpdir); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 47 | } |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 48 | mkdir($tmpdir) || die("Cannot create working directory $tmpdir !"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 49 | chdir($tmpdir) || die("Cannot write to $tmpdir !"); |
| 50 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 51 | $h = fopen($myrow_maps['location'], "rb"); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 52 | $file_contents = stream_get_contents($h); |
| 53 | fclose($h); |
| 54 | $aLines = split("\n", $file_contents); |
| 55 | |
| 56 | |
| 57 | foreach ($aLines as $line) { |
| 58 | $line = trim($line); |
| 59 | |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 60 | # 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 |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 61 | if(preg_match("/^(plugin|fragment)/", $line)) { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 62 | echo $html_spacer . "Processling line: " . $line . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 63 | $aParts = split("=", $line); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 64 | $aElements = split("@", $aParts[0]); |
| 65 | |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 66 | if($aElements[0] == "plugin") { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 67 | echo $html_spacer . $html_spacer . "Processling plugin: " . $aParts[1] . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 68 | $aStuff = parseLocation($aParts[1]); |
| 69 | |
| 70 | $tagstring = ""; |
| 71 | if(isset($aStuff['tag'])) { |
| 72 | $tagstring = "-r " . $aStuff['tag'] . " "; |
| 73 | } |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 74 | if(isset($aStuff['plugin'])) { |
| 75 | if($aStuff['plugin'] != "") { |
| 76 | $aElements[1] = $aStuff['plugin']; |
| 77 | } |
| 78 | } |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 79 | |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 80 | $command = ""; |
| 81 | # determine CVS or SVN |
| 82 | if(isset($aStuff['cvsroot'])) { |
| 83 | $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1]; |
| 84 | } |
| 85 | elseif( isset($aStuff['svnroot'])) { |
| 86 | $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp"; |
| 87 | } |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 88 | echo $html_spacer . $html_spacer ."--> " . $command . "\n"; |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 89 | |
| 90 | $out = ""; |
| 91 | if($command != "") { |
| 92 | $out = shell_exec($command); |
| 93 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 94 | |
| 95 | # process the output lines for .properties |
| 96 | $aOutLines = split("\n", $out); |
| 97 | foreach ($aOutLines as $out_line) { |
| 98 | $out_line = trim($out_line); |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 99 | # remove SVN's multiple spaces |
| 100 | $out_line = preg_replace("/\s+/", " ", $out_line); |
| 101 | |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 102 | echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n"; |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 103 | # CVS: |
droy | ec50f10 | 2008-02-01 19:33:10 +0000 | [diff] [blame] | 104 | # 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] | 105 | # SVN: |
| 106 | # 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] | 107 | if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) { |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 108 | # this is a .properties file! |
droy | ec50f10 | 2008-02-01 19:33:10 +0000 | [diff] [blame] | 109 | $file_name = trim(substr($out_line, 2)); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 110 | echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n"; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 111 | |
| 112 | $File = new File(); |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 113 | $File->project_id = $myrow_maps['project_id']; |
| 114 | $File->version = $myrow_maps['version']; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 115 | $File->name = $file_name; |
| 116 | if(!$File->save()) { |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 117 | 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] | 118 | } |
| 119 | else { |
| 120 | # Start importing the strings! |
| 121 | $fh = fopen($file_name, 'r'); |
| 122 | $size = filesize($file_name); |
| 123 | |
| 124 | $content = fread($fh, $size); |
| 125 | fclose($fh); |
| 126 | |
| 127 | $strings = $File->parseProperties($content); |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 128 | 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] | 129 | } |
| 130 | |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
droy | 1df37fc | 2008-02-28 21:29:46 +0000 | [diff] [blame] | 137 | echo "Done."; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 138 | |
droy | 5821051 | 2008-02-05 16:05:48 +0000 | [diff] [blame] | 139 | if($headless) { |
| 140 | $User = null; |
| 141 | } |
| 142 | |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 143 | function parseLocation($in_string) { |
| 144 | # in_string looks something like this: |
| 145 | # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse, |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 146 | # 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] | 147 | # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 148 | # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn |
| 149 | # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/ |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 150 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 151 | $aTheseElements = array(); |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 152 | |
| 153 | $aLocation = split(",", $in_string); |
| 154 | foreach($aLocation as $location_part) { |
| 155 | # TAG |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 156 | if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) { |
| 157 | $aTheseElements['tag'] = $location_part; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 158 | } |
| 159 | # CVSROOT |
| 160 | if(preg_match("/^:.*:.*@.*:\//", $location_part)) { |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 161 | $aTheseElements['cvsroot'] = $location_part; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 162 | } |
droy | f3b4328 | 2008-05-09 18:45:12 +0000 | [diff] [blame] | 163 | # SVNROOT |
| 164 | # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn |
| 165 | # maps to: svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/ |
| 166 | if(preg_match("/^(http|svn):\/\//", $location_part)) { |
| 167 | $location_part = str_replace("http", "svn", $location_part); |
| 168 | $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[4]; |
| 169 | } |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 170 | } |
| 171 | |
droy | 87d1b18 | 2008-03-04 21:55:24 +0000 | [diff] [blame] | 172 | $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1); |
| 173 | |
droy | d9a61af | 2008-02-26 16:20:29 +0000 | [diff] [blame] | 174 | return $aTheseElements; |
droy | 3bb0c96 | 2008-01-17 20:45:01 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | ?> |