classes/BuildTasks.php
static function run_init( $task=null, $args=array(), $cliopts=array() )
    {
        $skip_init = @$cliopts['skip-init'];
        $skip_init_fetch = @$cliopts['skip-init-fetch'] || $skip_init;
        $skip_init_clean = @$cliopts['skip-init-clean'] || $skip_init;

        if ( ! $skip_init )
        {
            $opts = self::getOpts( @$args[0], @$args[1], $cliopts );
            pake_mkdirs( self::getBuildDir( $opts ) );

            $destdir = self::getBuildDir( $opts ) . '/' . $opts['extension']['name'];

            if ( !SharedLock::acquire( $opts['extension']['name'], LOCK_EX, $opts ) )
                throw new PakeException( "Source code locked by another process" );
        }

        if ( ! $skip_init_fetch )
        {
            if ( @$opts['svn']['url'] != '' )
            {
                pake_echo( "Fetching code from SVN repository {$opts['svn']['url']}" );
                pakeSubversion::checkout( $opts['svn']['url'], $destdir );
                /// @todo test that we got at least one file
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
                {
                    sleep( 3 );
                }
            }
            else if ( @$opts['git']['url'] != '' )
            {
                pake_echo( "Fetching code from GIT repository {$opts['git']['url']}" );
                pakeGit::clone_repository( $opts['git']['url'], $destdir );
                if ( @$opts['git']['branch'] != '' )
                {
                    /// @todo test checking out a specific branch
                    pakeGit::checkout_repo( $destdir, $opts['git']['branch'] );
                    /// @todo test that we got at least one file
                }
                if ( strtoupper( substr( PHP_OS, 0, 3) ) === 'WIN' )
                {
                    sleep( 3 );
                }
            }
            else if ( @$opts['file']['url'] != '' )
            {
                pake_echo( "Fetching code from local repository {$opts['file']['url']}" );
                /// @todo (!important) exclude stuff we know we're going to delete immediately afterwards
                $files = pakeFinder::type( 'any' )->relative()->in( $opts['file']['url'] );
                if ( count( $files ) == 0 )
                {
                    SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
                    throw new pakeException( "Empty source repo option: no files found in {$opts['file']['url']}" );
                }

                pake_mirror( $files, $opts['file']['url'], $destdir );
            }
            else
            {
                SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
                throw new pakeException( "Missing source repo option: either svn:url, git:url or file:url" );
            }
        }


        // remove files
        if ( ! $skip_init_clean )
        {
            // known files/dirs not to be packed / md5'ed
            /// @todo !important shall we make this configurable?
            /// @bug 'build' & 'dist' we should probably take from options
            $files = array( 'ant/', 'build.xml', '**/.svn', '.git/', 'build/', 'dist/', 'composer.phar', 'composer.lock', '.idea/', 'vendor/' );
            // hack! when packing ourself, we need to keep this stuff
            if ( $opts['extension']['name'] != 'ezextensionbuilder' )
            {
                $files = array_merge( $files, array( 'pake/', 'pakefile.php', '**/.gitignore' ) );
            }
            // files from user configuration
            $files = array_merge( $files, $opts['files']['to_exclude'] );

            /// we figured a way to allow user to specify both:
            ///       files in a specific subdir
            ///       files to be removed globally (ie. from any subdir)
            //pakeFinder::type( 'any' )->name( $files )->in( $destdir );
            $files = self::pake_antpattern( $files, $destdir );
            foreach( $files as $key => $file )
            {
                if ( is_dir( $file ) )
                {
                    pake_remove_dir( $file );
                    unset( $files[$key] );
                }
            }
            pake_remove( $files, '' );
        }

        if ( ! $skip_init )
        {
            // move package file where it has to be
            $file = pakeFinder::type( 'file' )->name( 'package.xml' )->maxdepth( 0 )->in( $destdir );
            if ( count( $file ) )
            {
                if ( $opts['create']['tarball'] || $opts['create']['zip'] )
                {
                    pake_rename( $destdir . '/package.xml', $destdir . '/../../package.xml' );
                }
                else
                {
                    pake_remove( $file, '' );
                }
            }

            SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
        }
    }
static function run_init( $task=null, $args=array(), $cliopts=array() )
    {
        $skip_init = @$cliopts['skip-init'];
        $skip_init_fetch = @$cliopts['skip-init-fetch'] || $skip_init;
        $skip_init_clean = @$cliopts['skip-init-clean'] || $skip_init;

        if ( ! $skip_init )
        {
            $opts = self::getOpts( @$args[0], @$args[1], $cliopts );
            pake_mkdirs( self::getBuildDir( $opts ) );

            $destdir = self::getBuildDir( $opts ) . '/' . $opts['extension']['name'];

            if ( !SharedLock::acquire( $opts['extension']['name'], LOCK_EX, $opts ) )
                throw new PakeException( "Source code locked by another process" );
        }

        if ( ! $skip_init_fetch )
        {
            if ( @$opts['svn']['url'] != '' )
            {
                pake_echo( "Fetching code from SVN repository {$opts['svn']['url']}" );
                pakeSubversion::checkout( $opts['svn']['url'], $destdir );
                /// @todo test that we got at least one file
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
                {
                    sleep( 3 );
                }
            }
            else if ( @$opts['git']['url'] != '' )
            {
                pake_echo( "Fetching code from GIT repository {$opts['git']['url']}" );
                pakeGit::clone_repository( $opts['git']['url'], $destdir );
                if ( @$opts['git']['branch'] != '' )
                {
                    /// @todo test checking out a specific branch
                    pakeGit::checkout_repo( $destdir, $opts['git']['branch'] );
                    /// @todo test that we got at least one file
                }
                if ( strtoupper( substr( PHP_OS, 0, 3) ) === 'WIN' )
                {
                    sleep( 3 );
                }
            }
            else if ( @$opts['file']['url'] != '' )
            {
                pake_echo( "Fetching code from local repository {$opts['file']['url']}" );
                /// @todo (!important) exclude stuff we know we're going to delete immediately afterwards
                $files = pakeFinder::type( 'any' )->relative()->in( $opts['file']['url'] );
                if ( count( $files ) == 0 )
                {
                    SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
                    throw new pakeException( "Empty source repo option: no files found in {$opts['file']['url']}" );
                }

                pake_mirror( $files, $opts['file']['url'], $destdir );
            }
            else
            {
                SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
                throw new pakeException( "Missing source repo option: either svn:url, git:url or file:url" );
            }
        }


        // remove files
        if ( ! $skip_init_clean )
        {
            // known files/dirs not to be packed / md5'ed
            /// @todo !important shall we make this configurable?
            /// @bug 'build' & 'dist' we should probably take from options
            $files = array( 'ant/', 'build.xml', '**/.svn', '.git/', 'build/', 'dist/', 'composer.phar', 'composer.lock', '.idea/', 'vendor/' );
            // hack! when packing ourself, we need to keep this stuff
            if ( $opts['extension']['name'] != 'ezextensionbuilder' )
            {
                $files = array_merge( $files, array( 'pake/', 'pakefile.php', '**/.gitignore' ) );
            }
            // files from user configuration
            $files = array_merge( $files, $opts['files']['to_exclude'] );

            /// we figured a way to allow user to specify both:
            ///       files in a specific subdir
            ///       files to be removed globally (ie. from any subdir)
            //pakeFinder::type( 'any' )->name( $files )->in( $destdir );
            $files = self::pake_antpattern( $files, $destdir );
            foreach( $files as $key => $file )
            {
                if ( is_dir( $file ) )
                {
                    pake_remove_dir( $file );
                    unset( $files[$key] );
                }
            }
            pake_remove( $files, '' );
        }

        if ( ! $skip_init )
        {
            // move package file where it has to be
            $file = pakeFinder::type( 'file' )->name( 'package.xml' )->maxdepth( 0 )->in( $destdir );
            if ( count( $file ) )
            {
                if ( $opts['create']['tarball'] || $opts['create']['zip'] )
                {
                    pake_rename( $destdir . '/package.xml', $destdir . '/../../package.xml' );
                }
                else
                {
                    pake_remove( $file, '' );
                }
            }

            SharedLock::release( $opts['extension']['name'], LOCK_EX, $opts );
        }
    }
Downloads the extension from its source repository, removes files not to be built
(the list of files to be removed is in part hardcoded and in part specified in
the configuration file).
Options: skip-init, skip-init-fetch, skip-init-clean

@todo add a dependency on a check-updates task that updates script itself?
@todo split this in two tasks and avoid this unsightly mess of options?