You are viewing a plain text version of this content. The canonical link for it is here.
Posted to zeta-commits@incubator.apache.org by je...@apache.org on 2011/04/13 15:27:29 UTC

[zeta-commits] svn commit: r1091818 - in /incubator/zetacomponents/website: Pakefile pake/ pake/config.yaml

Author: jeromer
Date: Wed Apr 13 15:27:29 2011
New Revision: 1091818

URL: http://svn.apache.org/viewvc?rev=1091818&view=rev
Log:
- Added first bits of the Pakefile
# let's see if Pake is what we need

Added:
    incubator/zetacomponents/website/Pakefile
    incubator/zetacomponents/website/pake/
    incubator/zetacomponents/website/pake/config.yaml

Added: incubator/zetacomponents/website/Pakefile
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/website/Pakefile?rev=1091818&view=auto
==============================================================================
--- incubator/zetacomponents/website/Pakefile (added)
+++ incubator/zetacomponents/website/Pakefile Wed Apr 13 15:27:29 2011
@@ -0,0 +1,309 @@
+<?php
+
+setup_zeta_components();
+
+define_config_file();
+
+/* ---------- task definitions ------------ */
+
+pake_desc( 'Cleans the build directory if non empty.' );
+pake_task( 'builddir' );
+
+/**
+ * Cleans the build directory if non empty.
+ *
+ * It is not created since it is under revision control
+ * so running svn up build should be enough.
+ *
+ * @param pakeTask $task
+ * @param array $args
+ * @access public
+ * @return void
+ */
+function run_builddir($task, $args)
+{
+    $options = pakeYaml::loadFile( CONFIG_FILE );
+    $buildDir = $options['build.dir'];
+
+    if( is_dir( $buildDir ) )
+    {
+        pake_echo( "Removing ${buildDir}/*" );
+        $rule = pakeFinder::type('any')->name('*')
+                                       ->ignore_version_control();
+        pake_remove( $rule, $buildDir );
+    }
+}
+
+pake_desc(
+    'Checks out the required external bits required to re-build the website.'
+);
+pake_task( 'checkout_wcv' );
+
+/**
+ * run_checkout_wcv
+ *
+ * @param pakeTask $task
+ * @param array $args
+ * @access public
+ * @return void
+ */
+function run_checkout_wcv( $task, $args )
+{
+    $options = pakeYaml::loadFile( CONFIG_FILE );
+    foreach( $options['wcv.paths'] as $wcvPath )
+    {
+        if( !is_dir( $wcvPath ) )
+        {
+            /* --ignore-externals is not supported */
+            pakeSubversion::checkout(
+                $options['wcv.svn.repository'] . "/${wcvPath}",
+                $wcvPath
+            );
+        }
+        else
+        {
+            /* --ignore-externals is not supported */
+            pakeSubversion::update( $wcvPath );
+        }
+    }
+
+    /**
+     * since --ignore-externals is not supported in pakeSubversion
+     * that means classes/ezc/* have been updated as well
+     * wo we do not need to update them once again
+     */
+}
+
+pake_desc( 'Creates the API documentation.' );
+pake_task( 'phpdoc' );
+
+/**
+ * Creates the API documentation.
+ *
+ * @param pakeTask $task
+ * @param array $args
+ * @access public
+ * @return void
+ */
+function run_phpdoc( $task, $args )
+{
+    $options = pakeYaml::loadFile( CONFIG_FILE );
+
+    pake_echo( 'Building PHPDoc for ' . $options['build.name'] );
+
+    $command = $options['php.path'] . ' -d "memory_limit=2500M" -d "xdebug.default_enable=0" '
+             . $options['phpdoc.path'] . ' '
+             . '--directory ' . $options['zeta.base'] . ' '
+             . '--templatebase "phpdoc/" '
+             . '--target "' . $options['build.dir'] . '/phpdoc/' . $options['build.name'] . '/phpdoc" '
+             . '--ignore "autoload/,*autoload.php,tests/,docs/,design/" '
+             . '--hidden false '
+             . '--undocumentedelements off '
+             . '--title "Apache Zeta Components Manual" '
+             . '--parseprivate off '
+             . '--defaultpackagename "NoPackageName" '
+             . '--defaultcategoryname "NoCategoryName" '
+             . '--output "HTML:Arbit:arbit" '
+             . '--sourcecode off '
+             . '--javadocdesc off '
+             . '--quiet '
+             . '--pear off';
+
+    passthru( $command, $return );
+
+    if( $return !== 0 )
+    {
+        throw new pakeException( 'Building PHPDoc failed' );
+    }
+
+    $PHPDocRoot = $options['build.dir'] . '/phpdoc/' . $options['build.name'];
+
+    move_html_files( "${PHPDocRoot}/phpdoc" );
+
+    // ezcArchiveGnuTar can not write files
+    // and other Tar algorithsm doe not support filenames
+    // longer than 100 chars.
+    shorten_long_filenames( "${PHPDocRoot}/phpdoc" );
+
+    $tarball = "${PHPDocRoot}.tar.bz2";
+
+    create_bz2_archive( $tarball, $PHPDocRoot );
+
+    $targetDir = 'content/documentation/' . $options['build.name'];
+
+    if( !is_dir( $targetDir ) )
+    {
+        mkdir( $targetDir, 0755 );
+    }
+
+    pake_echo( 'Copying tarball' );
+    copy( $tarball, $targetDir . '/' . $options['build.name'] . '.tar.bz2' );
+
+    pake_echo( 'Removing tarball' );
+    ezcBaseFile::removeRecursive( $options['build.dir'] . '/phpdoc/' );
+}
+
+/* ------ "Private" functions ----------- */
+
+/**
+ * Defines the path to the config file
+ *
+ * @access public
+ * @return void
+ */
+function define_config_file()
+{
+    $yamlFile = './pake/config.yaml';
+
+    if( getenv( 'ZETA_PAKE_FILE' ) and file_exists( getenv( 'ZETA_PAKE_FILE' ) ) )
+    {
+        $yamlFile = getenv( 'ZETA_PAKE_FILE' );
+        pake_echo( "Using custom config file ${yamlFile}" );
+    }
+
+    define( 'CONFIG_FILE', $yamlFile );
+}
+
+/**
+ * Activates zeta components
+ *
+ * @access public
+ * @return void
+ */
+function setup_zeta_components()
+{
+    set_include_path(
+        realpath( '../trunk' ) . PATH_SEPARATOR . get_include_path()
+    );
+
+    require_once 'Base/src/ezc_bootstrap.php';
+
+    spl_autoload_register( 'ezcBase::autoload' );
+}
+
+/**
+ * Move PHP doc files to their correct location
+ *
+ * @param string $baseDir
+ * @access public
+ * @return void
+ */
+function move_html_files( $baseDir )
+{
+    $pattern = '/(classtrees|elementindex)_([a-z]+).html/i';
+
+    /* There is way too much magic in the Pake file finder ... */
+    $HTMLFiles = ezcBaseFile::findRecursive( $baseDir, array( $pattern ) );
+
+    foreach( $HTMLFiles as $HTMLFile )
+    {
+        /* it will obviously match */
+        if( preg_match( $pattern, $HTMLFile , $matches ) )
+        {
+            list( $unused, $newFile, $component ) = $matches;
+            $destination = "${baseDir}/${component}/${newFile}.html";
+
+            pake_echo( "Moving ${HTMLFile} to ${destination}" );
+            rename( $HTMLFile, $destination );
+        }
+    }
+}
+
+/**
+ * Shortens PHP doc filenames that are longer than 100 chars
+ *
+ * @param string $baseDir
+ * @access public
+ * @return void
+ */
+function shorten_long_filenames( $baseDir )
+{
+    $HTMLFiles = ezcBaseFile::findRecursive( $baseDir, array( '/(.*).html/') );
+
+    $replacementList = array();
+
+    $token = 'fsource_';
+
+    // finding long file names
+    foreach( $HTMLFiles as $HTMLFile )
+    {
+        $baseName = basename( $HTMLFile );
+
+        // max length supported by the Ustar algorithm
+        if( strlen( $baseName ) < 100 )
+        {
+            continue;
+        }
+
+        // removing "fsource_" should be enough to get an
+        // acceptable length. That way we still keep
+        // a "meaningful" URL for SEO.
+        $newHTMLFile = str_replace( $token, '', $baseName );
+
+        pake_echo( "Renaming ${baseName} to\n         ${newHTMLFile}" );
+
+        rename( $HTMLFile,  dirname( $HTMLFile ) . '/' . $newHTMLFile );
+
+        if( preg_match( "#^([a-zA-Z]+)_#", $newHTMLFile, $matches ) )
+        {
+            $component = $matches[1];
+
+            $replacementList[$component]['old'][] = $baseName;
+            $replacementList[$component]['new'][] = $newHTMLFile;
+        }
+    }
+
+    // replacing links
+    foreach( $replacementList as $component => $fileNamesToReplace )
+    {
+        $componentFiles = ezcBaseFile::findRecursive(
+            $baseDir,
+            array( "/${component}/" )
+        );
+
+        foreach( $componentFiles as $sourceFile )
+        {
+            file_put_contents(
+                $sourceFile,
+                str_replace(
+                    $fileNamesToReplace['old'],
+                    $fileNamesToReplace['new'],
+                    file_get_contents( $sourceFile ),
+                    $count
+                )
+            );
+        }
+    }
+}
+
+/**
+ * Creates an .tar.bz2 archive
+ *
+ * @param string $archiveName
+ * @param string $directory
+ * @access public
+ * @return void
+ */
+function create_bz2_archive( $archiveName, $directory )
+{
+    if( file_exists( $archiveName ) )
+    {
+        unlink( $archiveName );
+    }
+
+    $PHPDocFiles = ezcBaseFile::findRecursive( $directory, array( "/(.*)/" ) );
+    pake_echo( "Creating ${archiveName}" );
+
+    $tarball = ezcArchive::open(
+        "compress.bzip2://${archiveName}",
+        ezcArchive::TAR_USTAR
+    );
+
+    foreach( $PHPDocFiles as $PHPDocFile )
+    {
+        $tarball->append( $PHPDocFile, $directory );
+    }
+
+    $tarball->close();
+}
+?>
\ No newline at end of file

Added: incubator/zetacomponents/website/pake/config.yaml
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/website/pake/config.yaml?rev=1091818&view=auto
==============================================================================
--- incubator/zetacomponents/website/pake/config.yaml (added)
+++ incubator/zetacomponents/website/pake/config.yaml Wed Apr 13 15:27:29 2011
@@ -0,0 +1,9 @@
+build.dir: ./build
+build.name: trunk
+
+wcv.paths: [classes, scripts, templates]
+wcv.svn.repository: svn://web-content-viewer.org/wcv/trunk
+
+zeta.base: ../trunk
+phpdoc.path: /usr/bin/phpdoc
+php.path: /usr/bin/php
\ No newline at end of file