incubator-zeta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jero...@apache.org
Subject [zeta-commits] svn commit: r1095595 - /incubator/zetacomponents/website/Pakefile
Date Thu, 21 Apr 2011 04:51:57 GMT
Author: jeromer
Date: Thu Apr 21 04:51:56 2011
New Revision: 1095595

URL: http://svn.apache.org/viewvc?rev=1095595&view=rev
Log:
- Added revertempty task

Modified:
    incubator/zetacomponents/website/Pakefile

Modified: incubator/zetacomponents/website/Pakefile
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/website/Pakefile?rev=1095595&r1=1095594&r2=1095595&view=diff
==============================================================================
--- incubator/zetacomponents/website/Pakefile (original)
+++ incubator/zetacomponents/website/Pakefile Thu Apr 21 04:51:56 2011
@@ -376,6 +376,85 @@ function run_website( $task, $args )
     $options = pakeYaml::loadFile( CONFIG_FILE );
     pake_sh( $options['php.path'] . ' scripts/updateCache.php' );
     pake_sh( $options['php.path'] . ' var/scripts/highlight_source.php' );
+    run_revertempty( $task, $args );
+}
+
+pake_desc( 'Reverts all files without real changes' );
+pake_task( 'revertempty' );
+pake_alias( 'revert-empty', 'revertempty' );
+
+/**
+ * Reverts all files without real changes
+ *
+ * @param pakeTask $task
+ * @param mixed $args
+ * @access public
+ * @return void
+ */
+function run_revertempty( $task, $args )
+{
+    $options = pakeYaml::loadFile( CONFIG_FILE );
+
+    $modifiedFiles = array();
+
+    $xmlReader = new XMLReader();
+    $xmlReader->XML(
+        pake_sh( $options['svn.path'] . ' st --xml htdocs' )
+    );
+
+    while( $xmlReader->read() )
+    {
+        if( $xmlReader->nodeType == XMLReader::ELEMENT &&
+            $xmlReader->name == "entry" )
+        {
+            $xmlReader->moveToNextAttribute();
+            $modifiedFiles[] = $xmlReader->value;
+        }
+    }
+
+    foreach( $modifiedFiles as $modifiedFile )
+    {
+        $diff = explode(
+            "\n",
+            pake_sh(
+                $options['svn.path'] . " diff --diff-cmd '" .
+                $options['diff.path']. "' -x -U0 ${modifiedFile}"
+            )
+        );
+
+        // removes diff header
+        if( count( $diff ) > 4 )
+        {
+            $diff = array_slice( $diff, 4 );
+        }
+
+        $patterns = array(
+            "^@@.*@@$",
+            "<meta",
+            "<pubDate>",
+            "<lastBuildDate>",
+            "<author>",
+            "^[+-][\s]+by[\s]",
+            "^[+-][\s]+on[\s]"
+        );
+
+        foreach( $diff as $lineNumber => $diffLine )
+        {
+            // kind of equivalent of "grep -v"
+            foreach( $patterns as $pattern )
+            {
+                if( preg_match( "#${pattern}#", $diffLine, $matches ) )
+                {
+                    unset( $diff[$lineNumber] );
+                }
+            }
+        }
+
+        if( count( $diff ) == 0 )
+        {
+            pake_sh( $options['svn.path'] . " ${modifiedFile}" );
+        }
+    }
 }
 
 /* ------ "Private" functions ----------- */



Mime
View raw message