Author: jhm
Date: Fri Nov  7 07:19:36 2008
New Revision: 712158

URL: http://svn.apache.org/viewvc?rev=712158&view=rev
Log:
Use JavaFront for running tasks from the command line.

Added:
    ant/sandbox/javafront/src/main/org/apache/ant/javafront/TaskExec.java
    ant/sandbox/javafront/taskexec.bat

Added: ant/sandbox/javafront/src/main/org/apache/ant/javafront/TaskExec.java
URL: 
http://svn.apache.org/viewvc/ant/sandbox/javafront/src/main/org/apache/ant/javafront/TaskExec.java?rev=712158&view=auto
==============================================================================
--- ant/sandbox/javafront/src/main/org/apache/ant/javafront/TaskExec.java 
(added)
+++ ant/sandbox/javafront/src/main/org/apache/ant/javafront/TaskExec.java Fri 
Nov  7 07:19:36 2008
@@ -0,0 +1,71 @@
+/*
+ *  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;
+
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Map;
+
+import org.apache.tools.ant.launch.*;
+import org.apache.tools.ant.*;
+
+import org.apache.ant.javafront.builder.TagBuilder;
+import org.apache.ant.javafront.builder.Tag;
+
+
+public class TaskExec implements AntMain {
+
+    public void startAnt(String[] args, Properties additionalUserProperties, 
ClassLoader coreLoader) {
+        Map<String, String> attributes = new Hashtable<String, String>();
+
+        // Analyzing the command line arguments
+        String taskname = args[0];
+        for(int i=1; i<args.length; ) {
+            String attrName  = args[i++];
+            String attrValue = args[i++];
+            attributes.put(attrName, attrValue);
+        }
+
+        // Initializing
+        Project    project = initProject();
+        TagBuilder builder = TagBuilder.forProject(project);
+
+        // Initializing the Task
+        Tag tag = builder.tag(taskname);
+        for (String key : attributes.keySet()) {
+            tag.withAttribute(key, attributes.get(key));
+        }
+
+        // Run the task
+        tag.execute();
+    }
+
+    private Project initProject() {
+        DefaultLogger logger = new DefaultLogger();
+        logger.setOutputPrintStream(System.out);
+        logger.setErrorPrintStream(System.err);
+        logger.setMessageOutputLevel(Project.MSG_INFO);
+
+        Project rv = new Project();
+        rv.addBuildListener(logger);
+        rv.init();
+
+        return rv;
+    }
+
+}
\ No newline at end of file

Added: ant/sandbox/javafront/taskexec.bat
URL: 
http://svn.apache.org/viewvc/ant/sandbox/javafront/taskexec.bat?rev=712158&view=auto
==============================================================================
--- ant/sandbox/javafront/taskexec.bat (added)
+++ ant/sandbox/javafront/taskexec.bat Fri Nov  7 07:19:36 2008
@@ -0,0 +1,23 @@
[EMAIL PROTECTED] off
+cls
+set START=call ant -lib build\classes -main org.apache.ant.javafront.TaskExec
+
+echo ----- Build the library -----
+call ant
+
+echo ----- First Run: using ^<echo^> as Hello World
+%START% echo message "Hello World"
+
+echo ----- Second Run: using ^<echoproperties^> for printing all Ant related 
properties -----
+%START% echoproperties prefix ant.
+
+echo ----- Third Run: using ^<copy^> for copying one file -----
+%START% copy file build.xml tofile build.xml.bak
+
+echo ----- A 'build.xml.bak' should exist -----
+dir bu*.*
+
+echo ----- Delete that file again -----
+%START% delete file build.xml.bak
+dir bu*.*
+


Reply via email to