incubator-groovy git commit: Documentation: add FileTreeBuilder documentation

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

incubator-groovy git commit: Documentation: add FileTreeBuilder documentation

pascalschumacher
Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X b3ca8026f -> 5aee7c966


Documentation: add FileTreeBuilder documentation


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/5aee7c96
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/5aee7c96
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/5aee7c96

Branch: refs/heads/GROOVY_2_4_X
Commit: 5aee7c9662fbd7813e0c476710c178db6a11dcc6
Parents: b3ca802
Author: pascalschumacher <[hidden email]>
Authored: Sun Apr 19 17:44:54 2015 +0200
Committer: pascalschumacher <[hidden email]>
Committed: Sun Apr 19 17:47:04 2015 +0200

----------------------------------------------------------------------
 .../doc/core-domain-specific-languages.adoc     | 40 ++++++++++-
 .../test/builder/FileTreeBuilderTest.groovy     | 75 ++++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5aee7c96/src/spec/doc/core-domain-specific-languages.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-domain-specific-languages.adoc b/src/spec/doc/core-domain-specific-languages.adoc
index d35fa82..4870623 100644
--- a/src/spec/doc/core-domain-specific-languages.adoc
+++ b/src/spec/doc/core-domain-specific-languages.adoc
@@ -1148,4 +1148,42 @@ See <<jmx_jmxbuilder,Working with JMX - JmxBuilder>> for details.
 
 ==== FileTreeBuilder
 
-(TBD)
\ No newline at end of file
+gapi:groovy.util.FileTreeBuilder[FileTreeBuilder] is a builder for generating a file directory structure from a specification. For example, to create the following tree:
+
+---------
+ src/
+  |--- main
+  |     |--- groovy
+  |            |--- Foo.groovy
+  |--- test
+        |--- groovy
+               |--- FooTest.groovy
+---------
+
+You can use a `FileTreeBuilder` like this:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/FileTreeBuilderTest.groovy[tags=example,indent=0]
+----
+
+To check that everything worked as expected we use the following `assert`s:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/FileTreeBuilderTest.groovy[tags=example_assert,indent=0]
+----
+
+`FileTreeBuilder` also supports a shorthand syntax:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/FileTreeBuilderTest.groovy[tags=shorthand_syntax,indent=0]
+----
+
+This produces the same directory structure as above, as shown by these `assert`s:
+
+[source,groovy]
+----
+include::{projectdir}/src/spec/test/builder/FileTreeBuilderTest.groovy[tags=shorthand_syntax_assert,indent=0]
+----
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5aee7c96/src/spec/test/builder/FileTreeBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/builder/FileTreeBuilderTest.groovy b/src/spec/test/builder/FileTreeBuilderTest.groovy
new file mode 100644
index 0000000..3a3c699
--- /dev/null
+++ b/src/spec/test/builder/FileTreeBuilderTest.groovy
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package builder
+
+class FileTreeBuilderTest extends GroovyTestCase {
+    File tmpDir
+
+    void tearDown() {
+        tmpDir.deleteDir()
+    }
+
+    void testFileTreeBuilder() {
+        // tag::example[]
+        tmpDir = File.createTempDir()
+        def fileTreeBuilder = new FileTreeBuilder(tmpDir)
+        fileTreeBuilder.dir('src') {
+            dir('main') {
+               dir('groovy') {
+                  file('Foo.groovy', 'println "Hello"')
+               }
+            }
+            dir('test') {
+               dir('groovy') {
+                  file('FooTest.groovy', 'class FooTest extends GroovyTestCase {}')
+               }
+            }
+         }
+         // end::example[]
+        
+         // tag::example_assert[]
+         assert new File(tmpDir, '/src/main/groovy/Foo.groovy').text == 'println "Hello"'
+         assert new File(tmpDir, '/src/test/groovy/FooTest.groovy').text == 'class FooTest extends GroovyTestCase {}'
+         // end::example_assert[]
+    }
+    
+    void testFileTreeBuilderShortHandSyntax() {
+        // tag::shorthand_syntax[]
+        tmpDir = File.createTempDir()
+        def fileTreeBuilder = new FileTreeBuilder(tmpDir)
+        fileTreeBuilder.src {
+            main {
+               groovy {
+                  'Foo.groovy'('println "Hello"')
+               }
+            }
+            test {
+               groovy {
+                  'FooTest.groovy'('class FooTest extends GroovyTestCase {}')
+               }
+            }
+         }
+         // end::shorthand_syntax[]
+        
+         // tag::shorthand_syntax_assert[]
+         assert new File(tmpDir, '/src/main/groovy/Foo.groovy').text == 'println "Hello"'
+         assert new File(tmpDir, '/src/test/groovy/FooTest.groovy').text == 'class FooTest extends GroovyTestCase {}'
+         // end::shorthand_syntax_assert[]
+    }    
+ }