blob: 2e404ce58345bc3007d90087e634811004c5b79c [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
11*******************************************************************************/
droy87d1b182008-03-04 21:55:24 +000012header("Content-type: text/plain");
droy3bb0c962008-01-17 20:45:01 +000013include("global.php");
14InitPage("");
15
droy58210512008-02-05 16:05:48 +000016$headless = 0;
17if(!isset($User)) {
18 echo "User not defined -- running headless.";
19 $User = new User();
20 $User->loadFromID(40623); // genie
21 $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
36
37
droyabf32a12008-05-09 18:46:20 +000038$sql = "SELECT * FROM map_files WHERE is_active = 1 ORDER BY RAND()";
droy3bb0c962008-01-17 20:45:01 +000039$rs_maps = mysql_query($sql, $dbh);
droyd9a61af2008-02-26 16:20:29 +000040while($myrow_maps = mysql_fetch_assoc($rs_maps)) {
droy87d1b182008-03-04 21:55:24 +000041 echo "Processing map file: " . $myrow_maps['filename'] . " in location: " . $myrow_maps['location'] . "\n";
droy3bb0c962008-01-17 20:45:01 +000042
droyd9a61af2008-02-26 16:20:29 +000043 $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);
droy3bb0c962008-01-17 20:45:01 +000047 }
droyd9a61af2008-02-26 16:20:29 +000048 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
droy3bb0c962008-01-17 20:45:01 +000049 chdir($tmpdir) || die("Cannot write to $tmpdir !");
50
droyd9a61af2008-02-26 16:20:29 +000051 $h = fopen($myrow_maps['location'], "rb");
droy3bb0c962008-01-17 20:45:01 +000052 $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
droy87d1b182008-03-04 21:55:24 +000060 # 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 +000061 if(preg_match("/^(plugin|fragment)/", $line)) {
droy87d1b182008-03-04 21:55:24 +000062 echo $html_spacer . "Processling line: " . $line . "\n";
droy3bb0c962008-01-17 20:45:01 +000063 $aParts = split("=", $line);
droy87d1b182008-03-04 21:55:24 +000064 $aElements = split("@", $aParts[0]);
65
droy3bb0c962008-01-17 20:45:01 +000066 if($aElements[0] == "plugin") {
droy87d1b182008-03-04 21:55:24 +000067 echo $html_spacer . $html_spacer . "Processling plugin: " . $aParts[1] . "\n";
droy3bb0c962008-01-17 20:45:01 +000068 $aStuff = parseLocation($aParts[1]);
69
70 $tagstring = "";
71 if(isset($aStuff['tag'])) {
72 $tagstring = "-r " . $aStuff['tag'] . " ";
73 }
droy87d1b182008-03-04 21:55:24 +000074 if(isset($aStuff['plugin'])) {
75 if($aStuff['plugin'] != "") {
76 $aElements[1] = $aStuff['plugin'];
77 }
78 }
droyd9a61af2008-02-26 16:20:29 +000079
droyf3b43282008-05-09 18:45:12 +000080 $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 }
droy87d1b182008-03-04 21:55:24 +000088 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droyf3b43282008-05-09 18:45:12 +000089
90 $out = "";
91 if($command != "") {
92 $out = shell_exec($command);
93 }
droy3bb0c962008-01-17 20:45:01 +000094
95 # process the output lines for .properties
96 $aOutLines = split("\n", $out);
97 foreach ($aOutLines as $out_line) {
98 $out_line = trim($out_line);
droyf3b43282008-05-09 18:45:12 +000099 # remove SVN's multiple spaces
100 $out_line = preg_replace("/\s+/", " ", $out_line);
101
droy87d1b182008-03-04 21:55:24 +0000102 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyf3b43282008-05-09 18:45:12 +0000103 # CVS:
droyec50f102008-02-01 19:33:10 +0000104 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droyf3b43282008-05-09 18:45:12 +0000105 # 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
droye19e49b2008-01-31 14:05:50 +0000107 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +0000108 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +0000109 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +0000110 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000111
112 $File = new File();
droyd9a61af2008-02-26 16:20:29 +0000113 $File->project_id = $myrow_maps['project_id'];
114 $File->version = $myrow_maps['version'];
droy3bb0c962008-01-17 20:45:01 +0000115 $File->name = $file_name;
116 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000117 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000118 }
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);
droy87d1b182008-03-04 21:55:24 +0000128 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000129 }
130
131 }
132 }
133 }
134 }
135 }
136}
droy1df37fc2008-02-28 21:29:46 +0000137echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000138
droy58210512008-02-05 16:05:48 +0000139if($headless) {
140 $User = null;
141}
142
droy3bb0c962008-01-17 20:45:01 +0000143function parseLocation($in_string) {
144 # in_string looks something like this:
145 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000146 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000147 # 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 +0000148 # 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/
droy87d1b182008-03-04 21:55:24 +0000150
droyd9a61af2008-02-26 16:20:29 +0000151 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000152
153 $aLocation = split(",", $in_string);
154 foreach($aLocation as $location_part) {
155 # TAG
droyd9a61af2008-02-26 16:20:29 +0000156 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
157 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000158 }
159 # CVSROOT
160 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000161 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000162 }
droyf3b43282008-05-09 18:45:12 +0000163 # 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 }
droy3bb0c962008-01-17 20:45:01 +0000170 }
171
droy87d1b182008-03-04 21:55:24 +0000172 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
173
droyd9a61af2008-02-26 16:20:29 +0000174 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000175}
176
177?>