blob: 9e5fa52462d7ff7f3ce027130f7162ad38f1a1d4 [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
atoulme3e5e9342009-01-23 17:34:30 +000028global $dbh;
droy3bb0c962008-01-17 20:45:01 +000029
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
atoulme84cb3742008-12-05 11:01:39 +000055 $tmpdir = "/tmp/tmp-babel/" . str_replace(" ", "_", $myrow_maps['project_id']);
droyd9a61af2008-02-26 16:20:29 +000056 if(is_dir($tmpdir)) {
57 # zap the directory to make sure CVS versions don't overlap
58 exec("rm -rf " . $tmpdir);
droy3bb0c962008-01-17 20:45:01 +000059 }
droyd9a61af2008-02-26 16:20:29 +000060 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000061 chdir($tmpdir) || die("Cannot write to $tmpdir !");
62
droyd9a61af2008-02-26 16:20:29 +000063 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000064 $file_contents = stream_get_contents($h);
65 fclose($h);
66 $aLines = split("\n", $file_contents);
67
68
69 foreach ($aLines as $line) {
70 $line = trim($line);
71
droy87d1b182008-03-04 21:55:24 +000072 # 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 +000073 if(preg_match("/^(plugin|fragment)/", $line)) {
droyb9c2cb12008-10-08 13:58:14 +000074 echo $html_spacer . "Processing line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000075 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000076 $aElements = split("@", $aParts[0]);
droyb9c2cb12008-10-08 13:58:14 +000077 $plugin_id = $aElements[1];
droy3bb0c962008-01-17 20:45:01 +000078 if($aElements[0] == "plugin") {
droyb9c2cb12008-10-08 13:58:14 +000079 echo $html_spacer . $html_spacer . "Processing plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000080 $aStuff = parseLocation($aParts[1]);
81
82 $tagstring = "";
83 if(isset($aStuff['tag'])) {
84 $tagstring = "-r " . $aStuff['tag'] . " ";
85 }
droy87d1b182008-03-04 21:55:24 +000086 if(isset($aStuff['plugin'])) {
87 if($aStuff['plugin'] != "") {
88 $aElements[1] = $aStuff['plugin'];
89 }
90 }
droyd9a61af2008-02-26 16:20:29 +000091
droyf3b43282008-05-09 18:45:12 +000092 $command = "";
93 # determine CVS or SVN
94 if(isset($aStuff['cvsroot'])) {
95 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
96 }
97 elseif( isset($aStuff['svnroot'])) {
98 $command = "/usr/local/bin/svn co " . $aStuff['svnroot'] . " --config-dir /tmp";
99 }
droy87d1b182008-03-04 21:55:24 +0000100 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +0000101
102 $out = "";
103 if($command != "") {
104 $out = shell_exec($command);
105 }
droy3bb0c962008-01-17 20:45:01 +0000106
107 # process the output lines for .properties
108 $aOutLines = split("\n", $out);
109 foreach ($aOutLines as $out_line) {
110 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +0000111 # remove SVN's multiple spaces
112 $out_line = preg_replace("/\s+/", " ", $out_line);
113
droy87d1b182008-03-04 21:55:24 +0000114 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000115 # CVS:
droyec50f102008-02-01 19:33:10 +0000116 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000117 # SVN:
118 # 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 +0000119 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000120 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000121 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000122 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000123
atoulmebe3eae82008-12-05 16:38:20 +0000124 $file_id = File::getFileID($file_name, $myrow_maps['project_id'], $myrow_maps['version']);
atoulmee9ec6d82008-11-19 14:41:30 +0000125
126 if ($files[$file_id] != null) {
127 $File = $files[$file_id];
128 $File->isActive = 1;
129 unset($files[$file_id]);
130 } else {
131 $File = new File();
132 $File->project_id = $myrow_maps['project_id'];
133 $File->version = $myrow_maps['version'];
134 $File->name = $file_name;
135 $File->plugin_id = $plugin_id;
136 $File->isActive = 1;
137 }
droy3bb0c962008-01-17 20:45:01 +0000138 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000139 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000140 }
141 else {
142 # Start importing the strings!
143 $fh = fopen($file_name, 'r');
144 $size = filesize($file_name);
145
146 $content = fread($fh, $size);
147 fclose($fh);
148
149 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000150 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000151 }
152
153 }
154 }
155 }
156 }
157 }
158}
atoulmee9ec6d82008-11-19 14:41:30 +0000159echo "Marking the remaining files as inactive\n";
160
161foreach ($files as $file) {
162 $file->isActive = 0;
163 if(!$file->save()) {
164 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file->name . "\n";
165 }
166}
167
droy1df37fc2008-02-28 21:29:46 +0000168echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000169
droy58210512008-02-05 16:05:48 +0000170if($headless) {
171 $User = null;
172}
173
droy3bb0c962008-01-17 20:45:01 +0000174function parseLocation($in_string) {
175 # in_string looks something like this:
176 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000177 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000178 # 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 +0000179 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
180 # svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
droy87d1b182008-03-04 21:55:24 +0000181
droyd9a61af2008-02-26 16:20:29 +0000182 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000183
184 $aLocation = split(",", $in_string);
185 foreach($aLocation as $location_part) {
186 # TAG
droyd9a61af2008-02-26 16:20:29 +0000187 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
188 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000189 }
190 # CVSROOT
191 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000192 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000193 }
droyf3b43282008-05-09 18:45:12 +0000194 # SVNROOT
195 # SVN,trunk,http://dev.eclipse.org/svnroot/stp,,org.eclipse.stp.bpmn/trunk/org.eclipse.stp.bpmn
196 # maps to: svn://dev.eclipse.org/svnroot/stp/org.eclipse.stp.bpmn/trunk/
197 if(preg_match("/^(http|svn):\/\//", $location_part)) {
198 $location_part = str_replace("http", "svn", $location_part);
199 $aTheseElements['svnroot'] = $location_part . "/" . $aLocation[4];
200 }
droy3bb0c962008-01-17 20:45:01 +0000201 }
202
droy87d1b182008-03-04 21:55:24 +0000203 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
204
droyd9a61af2008-02-26 16:20:29 +0000205 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000206}
207
droyb9c2cb12008-10-08 13:58:14 +0000208?>