ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r709202 - in /ant/sandbox/javafront/src: etc/examples/Simple3.java main/org/apache/ant/javafront/builder/ main/org/apache/ant/javafront/builder/Tag.java main/org/apache/ant/javafront/builder/TagBuilder.java
Date Thu, 30 Oct 2008 16:42:52 GMT
Author: bodewig
Date: Thu Oct 30 09:42:51 2008
New Revision: 709202

URL: http://svn.apache.org/viewvc?rev=709202&view=rev
Log:
some initial builder stuff

Added:
    ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/
    ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java   (with props)
    ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java   (with
props)
Modified:
    ant/sandbox/javafront/src/etc/examples/Simple3.java

Modified: ant/sandbox/javafront/src/etc/examples/Simple3.java
URL: http://svn.apache.org/viewvc/ant/sandbox/javafront/src/etc/examples/Simple3.java?rev=709202&r1=709201&r2=709202&view=diff
==============================================================================
--- ant/sandbox/javafront/src/etc/examples/Simple3.java (original)
+++ ant/sandbox/javafront/src/etc/examples/Simple3.java Thu Oct 30 09:42:51 2008
@@ -18,7 +18,9 @@
 package org.example;
 
 import org.apache.ant.javafront.annotations.AntProject;
+import org.apache.ant.javafront.annotations.AntTarget;
 import org.apache.tools.ant.Project;
+import org.apache.ant.javafront.builder.TagBuilder;
 
 @AntProject(Name="simple3", BaseDir="..")
 public class Simple3 {
@@ -27,4 +29,12 @@
     public void setProject(Project p) {
         this.p = p;
     }
+
+    @AntTarget
+    public void hello() {
+        TagBuilder.forProject(p)
+            .newTag("echo")
+            .withAttribute("message", "Hello, world!")
+            .execute();
+    }
 }

Added: ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java
URL: http://svn.apache.org/viewvc/ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java?rev=709202&view=auto
==============================================================================
--- ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java (added)
+++ ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java Thu Oct 30 09:42:51
2008
@@ -0,0 +1,65 @@
+/*
+ *  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 org.apache.ant.javafront.builder;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.RuntimeConfigurable;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.UnknownElement;
+
+public class Tag<T extends Tag<T>> {
+
+    private final UnknownElement ue;
+    private final RuntimeConfigurable rc;
+
+    protected Tag(Project p, String name) {
+        ue = new UnknownElement(name);
+        ue.setProject(p);
+        ue.setTaskType(name);
+        ue.setTaskName(name);
+        rc = new RuntimeConfigurable(ue, name);
+    }
+
+    public Tag<T> withAttribute(String name, String value) {
+        rc.setAttribute(name, value);
+        return this;
+    }
+
+    public Tag<T> withChild(Tag<?> child) {
+        ue.addChild(child.ue);
+        rc.addChild(child.rc);
+        return this;
+    }
+
+    public Tag<T> withNestedText(String text) {
+        rc.addText(text);
+        return this;
+    }
+
+    public Object build() {
+        ue.maybeConfigure();
+        return ue.getRealThing();
+    }
+
+    public void execute() {
+        Object o = build();
+        if (o instanceof Task) {
+            ((Task) o).perform();
+        }
+    }
+}
\ No newline at end of file

Propchange: ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/Tag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java
URL: http://svn.apache.org/viewvc/ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java?rev=709202&view=auto
==============================================================================
--- ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java (added)
+++ ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java Thu Oct
30 09:42:51 2008
@@ -0,0 +1,44 @@
+/*
+ *  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 org.apache.ant.javafront.builder;
+
+import org.apache.tools.ant.Project;
+
+public final class TagBuilder {
+
+    private final Project project;
+
+    private TagBuilder(Project project) {
+        this.project = project;
+    }
+
+    /**
+     * A TagBuilder for a given project.
+     */
+    public static TagBuilder forProject(Project p) {
+        return new TagBuilder(p);
+    }
+
+    /**
+     * Collects information for a giben task/type.
+     */
+    public Tag newTag(String name) {
+        return new Tag(project, name);
+    }
+
+}
\ No newline at end of file

Propchange: ant/sandbox/javafront/src/main/org/apache/ant/javafront/builder/TagBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message