blob: fb028dea360cbd8ba0b14c05b0c56d1573778aab [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*******************************************************************************/
12include("global.php");
13InitPage("");
14
droy58210512008-02-05 16:05:48 +000015$headless = 0;
16if(!isset($User)) {
17 echo "User not defined -- running headless.";
18 $User = new User();
19 $User->loadFromID(40623); // genie
20 $headless = 1;
21}
22
droy3bb0c962008-01-17 20:45:01 +000023
24require(BABEL_BASE_DIR . "classes/file/file.class.php");
25$html_spacer = "&#160;&#160;&#160;&#160;";
26
27global $App, $dbh;
28
29if(!is_dir("/tmp/tmp-babel")) {
30 mkdir("/tmp/tmp-babel") || die("Cannot create a working directory");
31}
32chdir("/tmp/tmp-babel") || die("Cannot use working directory");
33
34
35
36
37$sql = "SELECT * FROM map_files WHERE is_active = 1";
38$rs_maps = mysql_query($sql, $dbh);
39while($myrow = mysql_fetch_assoc($rs_maps)) {
40 echo "Processing map file: " . $myrow['filename'] . " in location: " . $myrow['location'] . "<br />";
41
42 $tmpdir = "/tmp/tmp-babel/" . $myrow['project_id'];
43 if(!is_dir($tmpdir)) {
44 mkdir($tmpdir) || die("Cannot create working directory $tmpdir !");
45 }
46 chdir($tmpdir) || die("Cannot write to $tmpdir !");
47
48 $h = fopen($myrow['location'], "rb");
49 $file_contents = stream_get_contents($h);
50 fclose($h);
51 $aLines = split("\n", $file_contents);
52
53
54 foreach ($aLines as $line) {
55 $line = trim($line);
56
57 if(preg_match("/^(plugin|fragment)/", $line)) {
58 echo $html_spacer . "Processling line: " . $line . "<br />";
59 $aParts = split("=", $line);
60 $aElements = split("@", $aParts[0]);
61 if($aElements[0] == "plugin") {
62 echo $html_spacer . $html_spacer . "Processling plugin: " . $aParts[1] . "<br />";
63 $aStuff = parseLocation($aParts[1]);
64
65 $tagstring = "";
66 if(isset($aStuff['tag'])) {
67 $tagstring = "-r " . $aStuff['tag'] . " ";
68 }
69
70 $command = "cvs -d " . $aStuff['cvsroot'] . " co " . $tagstring . $aElements[1];
71 echo $html_spacer . $html_spacer ."<font color=blue>" . $command . "</font><br />";
72 $out = shell_exec($command);
73
74 # process the output lines for .properties
75 $aOutLines = split("\n", $out);
76 foreach ($aOutLines as $out_line) {
77 $out_line = trim($out_line);
droyec50f102008-02-01 19:33:10 +000078 echo $html_spacer . $html_spacer . "CVS out line: " . $out_line . "<br />";
79 # U org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/dtd/util/AntDTDUtilMessages.properties
droye19e49b2008-01-31 14:05:50 +000080 if(preg_match("/\.properties$/", $out_line) && !preg_match("/build\.properties$/", $out_line)) {
droy3bb0c962008-01-17 20:45:01 +000081 # this is a .properties file!
droyec50f102008-02-01 19:33:10 +000082 $file_name = trim(substr($out_line, 2));
droy3bb0c962008-01-17 20:45:01 +000083 echo $html_spacer . $html_spacer . $html_spacer . "<font color=green>Processing .properties file: " . $file_name . "</font><br />";
84
85 $File = new File();
86 $File->project_id = $myrow['project_id'];
87 $File->version = $myrow['version'];
88 $File->name = $file_name;
89 if(!$File->save()) {
90 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "<font color=red>Error saving file: " . $file_name . "</font><br />";
91 }
92 else {
93 # Start importing the strings!
94 $fh = fopen($file_name, 'r');
95 $size = filesize($file_name);
96
97 $content = fread($fh, $size);
98 fclose($fh);
99
100 $strings = $File->parseProperties($content);
droyec50f102008-02-01 19:33:10 +0000101 echo $html_spacer . $html_spacer . $html_spacer . $html_spacer . "Strings processed: $strings<br /><br />";
droy3bb0c962008-01-17 20:45:01 +0000102 }
103
104 }
105 }
106 }
107 }
108 }
109}
110
droy58210512008-02-05 16:05:48 +0000111if($headless) {
112 $User = null;
113}
114
droy3bb0c962008-01-17 20:45:01 +0000115function parseLocation($in_string) {
116 # in_string looks something like this:
117 # v_832,:pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse,
118 $aElements = array();
119
120 $aLocation = split(",", $in_string);
121 foreach($aLocation as $location_part) {
122 # TAG
123 if(preg_match("/^[0-9a-zA-Z_]+$/", $location_part) && !isset($aElements['cvsroot'])) {
124 $aElements['tag'] = $location_part;
125 }
126 # CVSROOT
127 if(preg_match("/^:.*:.*@.*:\//", $location_part)) {
128 $aElements['cvsroot'] = $location_part;
129 }
130 }
131
132 return $aElements;
133}
134
135?>