blob: e1a04b0dde99b681c116680d090746ab2d5e11a4 [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
droy3bb0c962008-01-17 20:45:01 +000012*******************************************************************************/
droy87d1b182008-03-04 21:55:24 +000013header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000014include("global.php");
15InitPage("");
16
droy58210512008-02-05 16:05:48 +000017$headless = 0;
18if(!isset($User)) {
19 echo "User not defined -- running headless.";
atoulme9118d612008-11-12 18:21:38 +000020 $User = getGenieUser();
droy58210512008-02-05 16:05:48 +000021 $headless = 1;
22}
23
droy3bb0c962008-01-17 20:45:01 +000024
25require(BABEL_BASE_DIR . "classes/file/file.class.php");
droy87d1b182008-03-04 21:55:24 +000026$html_spacer = " ";
droy3bb0c962008-01-17 20:45:01 +000027
28global $App, $dbh;
29
30if(!is_dir("/tmp/tmp-babel")) {
31 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
32}
33chdir("/tmp/tmp-babel") || die("Cannot use working directory");
34
35
atoulmee9ec6d82008-11-19 14:41:30 +000036$files = array();
37$sql = "SELECT * from files";
38$rs_files = mysql_query($sql, $dbh);
39while($myrow_file = mysql_fetch_assoc($rs_files)) {
40 $File = new File();
41 $File->project_id = $myrow_file['project_id'];
42 $File->version = $myrow_file['version'];
43 $File->name = $myrow_file['name'];
44 $File->plugin_id = $myrow_file['plugin_id'];
45 $File->file_id = $myrow_file['file_id'];
46 $files[$File->file_id] = $File;
47}
droy3bb0c962008-01-17 20:45:01 +000048
49
droyabf32a12008-05-09 18:46:20 +000050$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000051$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000052while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000053 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000054
atoulmee9ec6d82008-11-19 14:41:30 +000055
droyd9a61af2008-02-26 16:20:29 +000056 $tmpdir = "/tmp/tmp-babel/" . $myrow_maps['project_id'];
57 if(is_dir($tmpdir)) {
58 # zap the directory to make sure CVS versions don't overlap
59 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000060 }
droyd9a61af2008-02-26 16:20:29 +000061 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000062 chdir($tmpdir) || die("Cannot write to $tmpdir !");
63
droyd9a61af2008-02-26 16:20:29 +000064 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000065 $file_contents = stream_get_contents($h);
66 fclose($h);
67 $aLines = split("\n", $file_contents);
68
69
70 foreach ($aLines as $line) {
71 $line = trim($line);
72
droy87d1b182008-03-04 21:55:24 +000073 # 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
droy3bb0c962008-01-17 20:45:01 +000074 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000075 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000076 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000077 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000078 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000079 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000080 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000081 $aStuff = parseLocation($aParts[1]);
82
83 $tagstring = "";
84 if(isset($aStuff['tag'])) {
85 $tagstring = "-r " . $aStuff['tag'] . " ";
86 }
droy87d1b182008-03-04 21:55:24 +000087 if(isset($aStuff['plugin'])) {
88 if($aStuff['plugin'] != "") {
89 $aElements[1] = $aStuff['plugin'];
90 }
91 }
droyd9a61af2008-02-26 16:20:29 +000092
droyf3b43282008-05-09 18:45:12 +000093 $command = "";
94 # determine CVS or SVN
95 if(isset($aStuff['cvsroot'])) {
96 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
97 }
98 elseif( isset($aStuff['svnroot'])) {
99 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
100 }
droy87d1b182008-03-04 21:55:24 +0000101 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +0000102
103 $out = "";
104 if($command != "") {
105 $out = shell_exec($command);
106 }
droy3bb0c962008-01-17 20:45:01 +0000107
108 # process the output lines for .properties
109 $aOutLines = split("\n", $out);
110 foreach ($aOutLines as $out_line) {
111 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000112 # remove SVN's multiple spaces
113 $out_line = preg_replace("/\s+/", " ", $out_line);
114
droy87d1b182008-03-04 21:55:24 +0000115 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000116 # CVS:
droyec50f102008-02-01 19:33:10 +0000117 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000118 # SVN:
119 # 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 +0000120 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000121 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000122 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000123 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000124
atoulmee9ec6d82008-11-19 14:41:30 +0000125 $file_id = File->getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
126
127 if ($files[$file_id] != null) {
128 $File = $files[$file_id];
129 $File->isActive = 1;
130 unset($files[$file_id]);
131 } else {
132 $File = new File();
133 $File->project_id = $myrow_maps['project_id'];
134 $File->version = $myrow_maps['version'];
135 $File->name = $file_name;
136 $File->plugin_id = $plugin_id;
137 $File->isActive = 1;
138 }
droy3bb0c962008-01-17 20:45:01 +0000139 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000140 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000141 }
142 else {
143 # Start importing the strings!
144 $fh = fopen($file_name, 'r');
145 $size = filesize($file_name);
146
147 $content = fread($fh, $size);
148 fclose($fh);
149
150 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000151 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000152 }
153
154 }
155 }
156 }
157 }
158 }
159}
atoulmee9ec6d82008-11-19 14:41:30 +0000160echo "Marking the remaining files as inactive\n";
161
162foreach ($files as $file) {
163 $file->isActive = 0;
164 if(!$file->save()) {
165 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
166 }
167}
168
droy1df37fc2008-02-28 21:29:46 +0000169echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000170
droy58210512008-02-05 16:05:48 +0000171if($headless) {
172 $User = null;
173}
174
droy3bb0c962008-01-17 20:45:01 +0000175function parseLocation($in_string) {
176 # in_string looks something like this:
177 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000178 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000179 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
droyf3b43282008-05-09 18:45:12 +0000180 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
181 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000182
droyd9a61af2008-02-26 16:20:29 +0000183 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000184
185 $aLocation = split(",", $in_string);
186 foreach($aLocation as $location_part) {
187 # TAG
droyd9a61af2008-02-26 16:20:29 +0000188 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
189 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000190 }
191 # CVSROOT
192 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000193 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000194 }
droyf3b43282008-05-09 18:45:12 +0000195 # SVNROOT
196 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
197 # maps to: svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
198 if(preg_match("/^(http|svn):\/\//", $location_part)) {
199 $location_part = str_replace("http", "svn", $location_part);
200 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[4];
201 }
droy3bb0c962008-01-17 20:45:01 +0000202 }
203
droy87d1b182008-03-04 21:55:24 +0000204 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
205
droyd9a61af2008-02-26 16:20:29 +0000206 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000207}
208
droyb9c2cb12008-10-08 13:58:14 +0000209?>