Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
4
// | PHP version 5                                                        |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 2004-2007, Clay Loveless                               |
7
// | All rights reserved.                                                 |
8
// +----------------------------------------------------------------------+
9
// | This LICENSE is in the BSD license style.                            |
10
// | http://www.opensource.org/licenses/bsd-license.php                   |
11
// |                                                                      |
12
// | Redistribution and use in source and binary forms, with or without   |
13
// | modification, are permitted provided that the following conditions   |
14
// | are met:                                                             |
15
// |                                                                      |
16
// |  * Redistributions of source code must retain the above copyright    |
17
// |    notice, this list of conditions and the following disclaimer.     |
18
// |                                                                      |
19
// |  * Redistributions in binary form must reproduce the above           |
20
// |    copyright notice, this list of conditions and the following       |
21
// |    disclaimer in the documentation and/or other materials provided   |
22
// |    with the distribution.                                            |
23
// |                                                                      |
24
// |  * Neither the name of Clay Loveless nor the names of contributors   |
25
// |    may be used to endorse or promote products derived from this      |
26
// |    software without specific prior written permission.               |
27
// |                                                                      |
28
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
32
// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35
// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36
// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38
// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39
// | POSSIBILITY OF SUCH DAMAGE.                                          |
40
// +----------------------------------------------------------------------+
41
// | Author: Clay Loveless <clay@killersoft.com>                          |
42
// +----------------------------------------------------------------------+
43
//
44
// $Id: Export.php 286753 2009-08-03 19:37:03Z mrook $
45
//
46
 
47
/**
48
 * @package     VersionControl_SVN
49
 * @category    VersionControl
50
 * @author      Clay Loveless <clay@killersoft.com>
51
 */
52
 
53
/**
54
 * Subversion Export command manager class
55
 *
56
 * Create an unversioned copy of a tree.
57
 *
58
 * From 'svn export --help':
59
 *
60
 * usage: 1. export [-r REV] URL [PATH]
61
 *        2. export [-r REV] PATH1 [PATH2]
62
 *
63
 *   1. Exports a clean directory tree from the repository specified by
64
 *      URL, at revision REV if it is given, otherwise at HEAD, into
65
 *      PATH. If PATH is omitted, the last component of the URL is used
66
 *      for the local directory name.
67
 *
68
 *   2. Exports a clean directory tree from the working copy specified by
69
 *      PATH1, at revision REV if it is given, otherwise at WORKING, into
70
 *      PATH2.  If PATH2 is omitted, the last component of the PATH1 is used
71
 *      for the local directory name. If REV is not specified, all local
72
 *      changes will be preserved, but files not under version control will
73
 *      not be copied.
74
 *
75
 * Conversion of the above usage examples to VersionControl_SVN_Export:
76
 *
77
 * Example 1:
78
 * <code>
79
 * <?php
80
 * require_once 'VersionControl/SVN.php';
81
 *
82
 * // Setup error handling -- always a good idea!
83
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
84
 *
85
 * // Set up runtime options. Will be passed to all
86
 * // subclasses.
87
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
88
 *
89
 * $switches = array('r' => 'HEAD');
90
 * $args = array('svn://svn.example.com/repos/TestProj/trunk',
91
 *               '/my/export/path/Test-Project-1.0');
92
 *
93
 * $svn = VersionControl_SVN::factory(array('export'), $options);
94
 * $svn->export->run($args,$switches));
95
 *     if (count($errs = $svnstack->getErrors())) {
96
 *         foreach ($errs as $err) {
97
 *             echo '<br />'.$err['message']."<br />\n";
98
 *             echo "Command used: " . $err['params']['cmd'];
99
 *         }
100
 *     }
101
 *
102
 * ?>
103
 * </code>
104
 *
105
 * Example 2:
106
 * <code>
107
 * <?php
108
 * require_once 'VersionControl/SVN.php';
109
 *
110
 * // Setup error handling -- always a good idea!
111
 * $svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');
112
 *
113
 * // Set up runtime options. Will be passed to all
114
 * // subclasses.
115
 * $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW);
116
 *
117
 * $args = array('/repos/TestProj/trunk',
118
 *               '/my/export/path/Test-Project-1.0');
119
 *
120
 * $svn = VersionControl_SVN::factory(array('export'), $options);
121
 * $svn->export->run($args);
122
 *     if (count($errs = $svnstack->getErrors())) {
123
 *         foreach ($errs as $err) {
124
 *             echo '<br />'.$err['message']."<br />\n";
125
 *             echo "Command used: " . $err['params']['cmd'];
126
 *         }
127
 *     }
128
 *
129
 * ?>
130
 * </code>
131
 *
132
 *
133
 * $switches is an array containing one or more command line options
134
 * defined by the following associative keys:
135
 *
136
 * <code>
137
 *
138
 * $switches = array(
139
 *  'r [revision]'  =>  'ARG (some commands also take ARG1:ARG2 range)
140
 *                        A revision argument can be one of:
141
 *                           NUMBER       revision number
142
 *                           "{" DATE "}" revision at start of the date
143
 *                           "HEAD"       latest in repository
144
 *                           "BASE"       base rev of item's working copy
145
 *                           "COMMITTED"  last commit at or before BASE
146
 *                           "PREV"       revision just before COMMITTED',
147
 *                      // either 'r' or 'revision' may be used
148
 *  'q [quiet]'     =>  true|false,
149
 *                      // prints as little as possible
150
 *  'force'         =>  true|false,
151
 *                      // force operation to run
152
 *  'username'      =>  'Subversion repository login',
153
 *  'password'      =>  'Subversion repository password',
154
 *  'no-auth-cache' =>  true|false,
155
 *                      // Do not cache authentication tokens
156
 *  'config-dir'    =>  'Path to a Subversion configuration directory'
157
 * );
158
 *
159
 * </code>
160
 *
161
 * Note: Subversion does not offer an XML output option for this subcommand
162
 *
163
 * The non-interactive option available on the command-line
164
 * svn client may also be set (true|false), but it is set to true by default.
165
 *
166
 * @package  VersionControl_SVN
167
 * @version  0.3.4
168
 * @category SCM
169
 * @author   Clay Loveless <clay@killersoft.com>
170
 */
171
class VersionControl_SVN_Export extends VersionControl_SVN
172
{
173
    /**
174
     * Valid switches for svn diff
175
     *
176
     * @var     array
177
     * @access  public
178
     */
179
    var $valid_switches = array('r',
180
                                'revision',
181
                                'q',
182
                                'quiet',
183
                                'force',
184
                                'username',
185
                                'password',
186
                                'no-auth-cache',
187
                                'no_auth_cache',
188
                                'non-interactive',
189
                                'non_interactive',
190
                                'config-dir',
191
                                'config_dir'
192
                                );
193
 
194
 
195
    /**
196
     * Command-line arguments that should be passed
197
     * <b>outside</b> of those specified in {@link switches}.
198
     *
199
     * @var     array
200
     * @access  public
201
     */
202
    var $args = array();
203
 
204
    /**
205
     * Minimum number of args required by this subcommand.
206
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
207
     * Subversion Complete Reference for details on arguments for this subcommand.
208
     * @var     int
209
     * @access  public
210
     */
211
    var $min_args = 1;
212
 
213
    /**
214
     * Switches required by this subcommand.
215
     * See {@link http://svnbook.red-bean.com/svnbook/ Version Control with Subversion},
216
     * Subversion Complete Reference for details on arguments for this subcommand.
217
     * @var     array
218
     * @access  public
219
     */
220
    var $required_switches = array();
221
 
222
    /**
223
     * Use exec or passthru to get results from command.
224
     * @var     bool
225
     * @access  public
226
     */
227
    var $passthru = false;
228
 
229
    /**
230
     * Prepare the svn subcommand switches.
231
     *
232
     * Defaults to non-interactive mode, and will auto-set the
233
     * --xml switch (if available) if $fetchmode is set to VERSIONCONTROL_SVN_FETCHMODE_XML,
234
     * VERSIONCONTROL_SVN_FETCHMODE_ASSOC or VERSIONCONTROL_SVN_FETCHMODE_OBJECT
235
     *
236
     * @param   void
237
     * @return  int    true on success, false on failure. Check PEAR_ErrorStack
238
     *                 for error details, if any.
239
     */
240
    function prepare()
241
    {
242
        $meets_requirements = $this->checkCommandRequirements();
243
        if (!$meets_requirements) {
244
            return false;
245
        }
246
 
247
        $valid_switches     = $this->valid_switches;
248
        $switches           = $this->switches;
249
        $args               = $this->args;
250
        $fetchmode          = $this->fetchmode;
251
        $invalid_switches   = array();
252
        $_switches          = '';
253
 
254
        foreach ($switches as $switch => $val) {
255
            if (in_array($switch, $valid_switches)) {
256
                $switch = str_replace('_', '-', $switch);
257
                switch ($switch) {
258
                    case 'revision':
259
                    case 'username':
260
                    case 'password':
261
                    case 'config-dir':
262
                        $_switches .= "--$switch $val ";
263
                        break;
264
                    case 'r':
265
                        $_switches .= "-$switch $val ";
266
                        break;
267
                    case 'q':
268
                        if ($val === true) {
269
                            $_switches .= "-$switch ";
270
                        }
271
                        break;
272
                    case 'quiet':
273
                    case 'force':
274
                    case 'non-interactive':
275
                    case 'no-auth-cache':
276
                        if ($val === true) {
277
                            $_switches .= "--$switch ";
278
                        }
279
                        break;
280
                    default:
281
                        // that's all, folks!
282
                        break;
283
                }
284
            } else {
285
                $invalid_switches[] = $switch;
286
            }
287
        }
288
        // We don't want interactive mode
289
        if (strpos($_switches, 'non-interactive') === false) {
290
            $_switches .= '--non-interactive ';
291
        }
292
        $_switches = trim($_switches);
293
        $this->_switches = $_switches;
294
 
295
        $cmd = "$this->svn_path $this->_svn_cmd $_switches";
296
        if (!empty($args)) {
297
            $cmd .= ' '. join(' ', $args);
298
        }
299
 
300
        $this->_prepped_cmd = $cmd;
301
        $this->prepared = true;
302
 
303
        $invalid = count($invalid_switches);
304
        if ($invalid > 0) {
305
            $params['was'] = 'was';
306
            $params['is_invalid_switch'] = 'is an invalid switch';
307
            if ($invalid > 1) {
308
                $params['was'] = 'were';
309
                $params['is_invalid_switch'] = 'are invalid switches';
310
            }
311
            $params['list'] = $invalid_switches;
312
            $params['switches'] = $switches;
313
            $params['_svn_cmd'] = ucfirst($this->_svn_cmd);
314
            $this->_stack->push(VERSIONCONTROL_SVN_NOTICE_INVALID_SWITCH, 'notice', $params);
315
        }
316
        return true;
317
    }
318
 
319
    // }}}
320
    // {{{ parseOutput()
321
 
322
    /**
323
     * Handles output parsing of standard and verbose output of command.
324
     *
325
     * @param   array   $out    Array of output captured by exec command in {@link run}.
326
     * @return  mixed   Returns output requested by fetchmode (if available), or raw output
327
     *                  if desired fetchmode is not available.
328
     * @access  public
329
     */
330
    function parseOutput($out)
331
    {
332
        $fetchmode = $this->fetchmode;
333
        switch($fetchmode) {
334
            case VERSIONCONTROL_SVN_FETCHMODE_RAW:
335
                return join("\n", $out);
336
                break;
337
            case VERSIONCONTROL_SVN_FETCHMODE_ASSOC:
338
                // Temporary, see parseOutputArray below
339
                return join("\n", $out);
340
                break;
341
            case VERSIONCONTROL_SVN_FETCHMODE_OBJECT:
342
                // Temporary, will return object-ified array from
343
                // parseOutputArray
344
                return join("\n", $out);
345
                break;
346
            case VERSIONCONTROL_SVN_FETCHMODE_XML:
347
                // Temporary, will eventually build an XML string
348
                // with XML_Util or XML_Tree
349
                return join("\n", $out);
350
                break;
351
            default:
352
                // What you get with VERSIONCONTROL_SVN_FETCHMODE_DEFAULT
353
                return join("\n", $out);
354
                break;
355
        }
356
    }
357
 
358
    /**
359
     * Helper method for parseOutput that parses output into an associative array
360
     *
361
     * @todo Finish this method! : )
362
     */
363
    function parseOutputArray($out)
364
    {
365
        $parsed = array();
366
    }
367
}
368
 
369
// }}}
370
?>