blob: 648e619610fe919600a22dfb3accb3ee6ccde151 [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
droy1df37fc2008-02-28 21:29:46 +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
droy3bb0c962008-01-17 20:45:01 +000080 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
droy87d1b182008-03-04 21:55:24 +000081 echo $html_spacer . $html_spacer ."--> " . $command . "\n";
droy3bb0c962008-01-17 20:45:01 +000082 $out = shell_exec($command);
83
84 # process the output lines for .properties
85 $aOutLines = split("\n", $out);
86 foreach ($aOutLines as $out_line) {
87 $out_line = trim($out_line);
droy87d1b182008-03-04 21:55:24 +000088 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "\n";
droyec50f102008-02-01 19:33:10 +000089 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droye19e49b2008-01-31 14:05:50 +000090 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +000091 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +000092 $file_name = trim(substr($out_line, 2));
droy87d1b182008-03-04 21:55:24 +000093 echo $html_spacer . $html_spacer . $html_spacer . "Processing .properties file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +000094
95 $File = new File();
droyd9a61af2008-02-26 16:20:29 +000096 $File->project_id = $myrow_maps['project_id'];
97 $File->version = $myrow_maps['version'];
droy3bb0c962008-01-17 20:45:01 +000098 $File->name = $file_name;
99 if(!$File->save()) {
droy87d1b182008-03-04 21:55:24 +0000100 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "***ERROR saving file: " . $file_name . "\n";
droy3bb0c962008-01-17 20:45:01 +0000101 }
102 else {
103 # Start importing the strings!
104 $fh = fopen($file_name, 'r');
105 $size = filesize($file_name);
106
107 $content = fread($fh, $size);
108 fclose($fh);
109
110 $strings = $File->parseProperties($content);
droy87d1b182008-03-04 21:55:24 +0000111 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings\n\n";
droy3bb0c962008-01-17 20:45:01 +0000112 }
113
114 }
115 }
116 }
117 }
118 }
119}
droy1df37fc2008-02-28 21:29:46 +0000120echo "Done.";
droy3bb0c962008-01-17 20:45:01 +0000121
droy58210512008-02-05 16:05:48 +0000122if($headless) {
123 $User = null;
124}
125
droy3bb0c962008-01-17 20:45:01 +0000126function parseLocation($in_string) {
127 # in_string looks something like this:
128 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
droyd9a61af2008-02-26 16:20:29 +0000129 # v20080204,:pserver:anonymous@dev.eclipse.org:/cvsroot/birt,,source/org.eclipse.birt.report.designer.core
droy87d1b182008-03-04 21:55:24 +0000130 # v200802262150,:pserver:anonymous@dev.eclipse.org:/cvsroot/modeling,,org.eclipse.emf/org.eclipse.emf.query/plugins/org.eclipse.emf.query
131
droyd9a61af2008-02-26 16:20:29 +0000132 $aTheseElements = array();
droy3bb0c962008-01-17 20:45:01 +0000133
134 $aLocation = split(",", $in_string);
135 foreach($aLocation as $location_part) {
136 # TAG
droyd9a61af2008-02-26 16:20:29 +0000137 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aTheseElements['cvsroot'])) {
138 $aTheseElements['tag'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000139 }
140 # CVSROOT
141 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
droyd9a61af2008-02-26 16:20:29 +0000142 $aTheseElements['cvsroot'] = $location_part;
droy3bb0c962008-01-17 20:45:01 +0000143 }
144 }
145
droy87d1b182008-03-04 21:55:24 +0000146 $aTheseElements['plugin'] = substr($in_string, strrpos($in_string, ",") + 1);
147
droyd9a61af2008-02-26 16:20:29 +0000148 return $aTheseElements;
droy3bb0c962008-01-17 20:45:01 +0000149}
150
151?>