2 /** FusionForge Bazaar plugin
4 * Copyright 2009, Roland Mas
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 class BzrPlugin extends SCMPlugin {
25 function BzrPlugin () {
28 $this->name = 'scmbzr';
29 $this->text = 'Bazaar';
30 $this->hooks[] = 'scm_generate_snapshots' ;
32 require_once $gfconfig.'plugins/scmbzr/config.php' ;
34 $this->default_bzr_server = $default_bzr_server ;
35 $this->enabled_by_default = $enabled_by_default ;
36 $this->bzr_root = $bzr_root;
38 $this->main_branch_names = array () ;
39 $this->main_branch_names[] = 'trunk' ;
40 $this->main_branch_names[] = 'master' ;
41 $this->main_branch_names[] = 'main' ;
42 $this->main_branch_names[] = 'head' ;
43 $this->main_branch_names[] = 'HEAD' ;
48 function getDefaultServer() {
49 return $this->default_bzr_server ;
52 function getBlurb () {
53 return _('<p>Documentation for Bazaar (sometimes referred to as "bzr") is available <a href="http://bazaar-vcs.org/Documentation">here</a>.</p>') ;
56 function getInstructionsForAnon ($project) {
57 $b = _('<p><b>Anonymous Bazaar Access</b></p><p>This project\'s Bazaar repository can be checked out through anonymous access with the following command(s).</p>');
59 $b .= '<tt>bzr checkout http://'.$project->getSCMBox().$this->bzr_root.'/'.$project->getUnixName().'/'._('branchname').'</tt><br />';
64 function getInstructionsForRW ($project) {
66 $b .= _('<p><b>Developer Bazaar Access via SSH</b></p><p>Only project developers can access the Bazaar branches via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
67 $b .= '<p><tt>bzr checkout bzr+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . $this->bzr_root .'/'. $project->getUnixName().'/'._('branchname').'</tt></p>' ;
72 function getSnapshotPara ($project) {
76 function getBrowserLinkBlock ($project) {
80 function getStatsBlock ($project) {
84 function createOrUpdateRepo ($params) {
85 $project = $this->checkParams ($params) ;
90 if (! $project->usesPlugin ($this->name)) {
94 $repo = $this->bzr_root . '/' . $project->getUnixName() ;
95 $unix_group = 'scm_' . $project->getUnixName() ;
97 $repo_exists = false ;
99 $pipe = popen ("bzr info $repo 2>/dev/null", "r") ;
100 $line = fgets ($pipe) ;
103 if (preg_match ("/^Shared repository/", $line) != 0) {
104 $repo_exists = true ;
109 system ("mkdir -p $repo") ;
110 system ("bzr init-repo --no-trees $repo >/dev/null") ;
113 system ("chgrp -R $unix_group $repo") ;
114 if ($project->enableAnonSCM()) {
115 system ("chmod -R g+wXs,o+rX-w $repo") ;
117 system ("chmod -R g+wXs,o-rwx $repo") ;
121 function generateSnapshots ($params) {
122 global $sys_scm_snapshots_path ;
123 global $sys_scm_tarballs_path ;
125 $project = $this->checkParams ($params) ;
130 $group_name = $project->getUnixName() ;
132 $snapshot = $sys_scm_snapshots_path.'/'.$group_name.'-scm-latest.tar.gz';
133 $tarball = $sys_scm_tarballs_path.'/'.$group_name.'-scmroot.tar.gz';
135 if (! $project->usesPlugin ($this->name)
136 || ! $project->enableAnonSCM()) {
142 $toprepo = $this->bzr_root ;
143 $repo = $toprepo . '/' . $project->getUnixName() ;
145 if (!is_dir ($repo) || !is_file ("$repo/format")) {
151 $tmp = trim (`mktemp -d`) ;
155 $today = date ('Y-m-d') ;
156 $dir = $project->getUnixName ()."-$today" ;
157 system ("mkdir -p $tmp") ;
161 foreach ($this->main_branch_names as $bname) {
162 system ("bzr ls file://$repo/$bname > /dev/null 2>&1", $code) ;
169 system ("cd $tmp ; bzr export $tmp/snapshot.tar.gz $repo/$bname") ;
170 chmod ("$tmp/snapshot.tar.gz", 0644) ;
171 copy ("$tmp/snapshot.tar.gz", $snapshot) ;
172 unlink ("$tmp/snapshot.tar.gz") ;
173 system ("rm -rf $tmp/$dir") ;
178 system ("tar czCf $toprepo $tmp/tarball.tar.gz " . $project->getUnixName()) ;
179 chmod ("$tmp/tarball.tar.gz", 0644) ;
180 copy ("$tmp/tarball.tar.gz", $tarball) ;
181 unlink ("$tmp/tarball.tar.gz") ;
182 system ("rm -rf $tmp") ;
188 // c-file-style: "bsd"