This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-site.git


The following commit(s) were added to refs/heads/master by this push:
     new 03c78d0  Add OncePerBuild mechanism
03c78d0 is described below

commit 03c78d06fa881ac6c143cee56ba7d2de5274d170
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Thu Nov 23 14:24:56 2017 +0100

    Add OncePerBuild mechanism
---
 src/main/jbake/templates/includes/U.groovy         |  7 ++++++
 src/main/jbake/templates/page.tpl                  |  2 +-
 .../jbake/templates/runonce/OncePerBuild.groovy    | 27 ++++++++++++++++++++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/main/jbake/templates/includes/U.groovy 
b/src/main/jbake/templates/includes/U.groovy
index 943891b..a05d920 100644
--- a/src/main/jbake/templates/includes/U.groovy
+++ b/src/main/jbake/templates/includes/U.groovy
@@ -2,6 +2,13 @@
 package includes
 
 class U {
+
+    U(jbakeConfig) {
+        // As this class is used in each build,
+        // use it to trigger the OncePerBuild stuff
+        def once = new runonce.OncePerBuild(jbakeConfig)
+    }
+
     def processBody(content, config) {
        def str = content.body
 
diff --git a/src/main/jbake/templates/page.tpl 
b/src/main/jbake/templates/page.tpl
index be33887..eb41386 100644
--- a/src/main/jbake/templates/page.tpl
+++ b/src/main/jbake/templates/page.tpl
@@ -1,5 +1,5 @@
 // Include common utilities
-U = new includes.U()
+U = new includes.U(config)
 
 layout 'layout/main.tpl', true,
         projects: projects,
diff --git a/src/main/jbake/templates/runonce/OncePerBuild.groovy 
b/src/main/jbake/templates/runonce/OncePerBuild.groovy
new file mode 100644
index 0000000..46ea0a2
--- /dev/null
+++ b/src/main/jbake/templates/runonce/OncePerBuild.groovy
@@ -0,0 +1,27 @@
+package runonce
+
+/** Stuff that runs once for each build
+ ** like generating the list of Sling Git modules etc.
+ **/
+class OncePerBuild {
+    static boolean hasRun
+    
+    def OncePerBuild(jbakeConfig) {
+        synchronized(this.class) {
+            if(!hasRun) {
+                hasRun = true
+                execute(jbakeConfig)
+            }
+        }
+    }
+    
+    /** Call things that need to run once during the website build here */
+    def execute(jbakeConfig) {
+        // I used this to test the mechanism, feel
+        // free to remove this code once this method
+        // starts doing something useful
+        // new File("/tmp/sling-site-once.txt").append("The build ran at " 
+        //    + new java.util.Date() 
+        //    + " with config " + jbakeConfig + "\n")
+    }
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to