You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by du...@locus.apache.org on 2000/12/11 11:32:09 UTC
cvs commit: jakarta-ant/proposal/anteater/source/main/org/apache/ant/cli CLIFrontEnd.java
duncan 00/12/11 02:32:08
Modified: proposal/anteater/bootstrap Bootstrap.java Bootstrap2.java
proposal/anteater/source main.ant
proposal/anteater/source/coretasks/echo/org/apache/ant/echo
EchoTask.java
proposal/anteater/source/main/org/apache/ant Project.java
ProjectBuilder.java TaskManager.java
proposal/anteater/source/main/org/apache/ant/cli
CLIFrontEnd.java
Log:
Removed last legacy of Ant.java and have settled a bit on how front
ends use core... In order for a front end to run a build, it first
creates a ProjectBuilder, loads a Project from it, then can run a
build on that Project. What still needs a bit of looking after is
creating a project from scratch (such as a GUI might do) and then
executing it. Later.
Revision Changes Path
1.5 +0 -6 jakarta-ant/proposal/anteater/bootstrap/Bootstrap.java
Index: Bootstrap.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/bootstrap/Bootstrap.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Bootstrap.java 2000/12/08 18:06:51 1.4
+++ Bootstrap.java 2000/12/11 10:31:56 1.5
@@ -70,12 +70,6 @@
*/
static void runCommand(String[] command) throws IOException {
- System.out.print("Exec'ing: ");
- for (int i = 0; i < command.length; i++) {
- System.out.print(command[i] + " ");
- }
- System.out.println();
-
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
1.4 +10 -6 jakarta-ant/proposal/anteater/bootstrap/Bootstrap2.java
Index: Bootstrap2.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/bootstrap/Bootstrap2.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Bootstrap2.java 2000/12/08 18:06:51 1.3
+++ Bootstrap2.java 2000/12/11 10:31:56 1.4
@@ -42,11 +42,14 @@
}
// ------------------------------------------------------------
- // build crimson
+ // build crimson, but only if it hasn't been built yet since
+ // 127 class files takes more seconds than I like to wait.
// ------------------------------------------------------------
- Vector v1 = getSources(base + crimsonSources);
- doCompile(base + "bootstrap/temp/crimson", v1);
+ if (!(new File(base + "bootstrap/temp/crimson/javax").exists())) {
+ Vector v1 = getSources(base + crimsonSources);
+ doCompile(base + "bootstrap/temp/crimson", v1);
+ }
// ------------------------------------------------------------
// build the main thing
@@ -75,7 +78,7 @@
System.out.println("-------------------------------------------");
System.out.println();
- String[] cmdarray = new String[9];
+ String[] cmdarray = new String[10];
cmdarray[0] = "java";
cmdarray[1] = "-cp";
cmdarray[2] = base + "bootstrap/temp/main" + File.pathSeparator +
@@ -84,8 +87,9 @@
cmdarray[4] = "-taskpath";
cmdarray[5] = base + "bootstrap/temp/taskjars";
cmdarray[6] = "-buildfile";
- cmdarray[7] = base + "source/main.ant";
- cmdarray[8] = "default";
+ cmdarray[7] = base + "source/main.ant";
+ cmdarray[8] = "-target";
+ cmdarray[9] = "default";
Bootstrap.runCommand(cmdarray, args);
1.2 +13 -5 jakarta-ant/proposal/anteater/source/main.ant
Index: main.ant
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/main.ant,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- main.ant 2000/12/06 08:08:33 1.1
+++ main.ant 2000/12/11 10:31:59 1.2
@@ -1,13 +1,21 @@
<?xml version="1.0"?>
-<project name="Ant">
+<!-- Comment outside of project -->
- <target name="default">
- <echo data="Echo In Default"/>
+<project name="Ant" default="default">
+
+ <!-- Comment inside of project -->
+
+ <description>Primary buildfile for building Ant itself</description>
+
+ <property name="foo" value="bar"/>
+
+ <target name="default" depends="main">
+ <echo text="Default Target is Executing"/>
</target>
<target name="main">
- <echo data="Echo In Main"/>
+ <echo text="Main Target is Executing"/>
</target>
-</project>
+</project>
\ No newline at end of file
1.2 +10 -12 jakarta-ant/proposal/anteater/source/coretasks/echo/org/apache/ant/echo/EchoTask.java
Index: EchoTask.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/coretasks/echo/org/apache/ant/echo/EchoTask.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EchoTask.java 2000/12/06 08:08:34 1.1
+++ EchoTask.java 2000/12/11 10:32:01 1.2
@@ -1,12 +1,12 @@
package org.apache.ant.echo;
-import java.io.*;
-import java.util.*;
-
import org.apache.ant.*;
/**
- * Basic echo task that just spits out whatever it is supposed to...
+ * A very simple task that takes a bit of text and echos it back out
+ * when it is executed. This is useful for troubleshooting properties
+ * in buildfiles, letting the user know that something is going to happen
+ * and as a very simple example that can be copied to create other tasks.
*
* @author James Duncan Davidson (duncan@apache.org)
*/
@@ -19,26 +19,24 @@
/**
* Data to echo
*/
- private String data;
+ private String text;
// -----------------------------------------------------------------
// PUBLIC METHODS
// -----------------------------------------------------------------
/**
- *
+ * Executes this task.
*/
public boolean execute() throws AntException {
-
- PrintStream out = project.getOutput();
- out.println("ECHOING: " + data);
+ project.getFrontEnd().writeMessage(text);
return true;
}
/**
- *
+ * Sets the text that this task will echo.
*/
- public void setData(String data) {
- this.data = data;
+ public void setText(String text) {
+ this.text = text;
}
}
1.3 +13 -2 jakarta-ant/proposal/anteater/source/main/org/apache/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/main/org/apache/ant/Project.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Project.java 2000/12/11 09:36:19 1.2
+++ Project.java 2000/12/11 10:32:02 1.3
@@ -71,9 +71,21 @@
/**
* TaskManager for this project.
*/
- private TaskManager taskManager = new TaskManager(this);
+ private TaskManager taskManager;
// -----------------------------------------------------------------
+ // CONSTRUCTORS
+ // -----------------------------------------------------------------
+
+ /**
+ * Creates a new Project object with the given FrontEnd and TaskManager
+ */
+ public Project(FrontEnd frontEnd, TaskManager taskManager) {
+ this.frontEnd = frontEnd;
+ this.taskManager = taskManager;
+ }
+
+ // -----------------------------------------------------------------
// PUBLIC METHODS
// -----------------------------------------------------------------
@@ -225,7 +237,6 @@
frontEnd.notifyProjectStart(this);
Target target = getTarget(targetName);
- //TaskManager taskManager = ant.getTaskManager();
frontEnd.notifyTargetStart(target);
1.3 +22 -5 jakarta-ant/proposal/anteater/source/main/org/apache/ant/ProjectBuilder.java
Index: ProjectBuilder.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/main/org/apache/ant/ProjectBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProjectBuilder.java 2000/12/11 09:36:19 1.2
+++ ProjectBuilder.java 2000/12/11 10:32:03 1.3
@@ -26,17 +26,17 @@
/**
*
*/
- //private Ant ant;
+ private FrontEnd frontEnd;
/**
*
*/
- private FrontEnd frontEnd;
+ private SAXParserFactory parserFactory;
/**
*
*/
- private SAXParserFactory parserFactory;
+ private TaskManager taskManager;
// -----------------------------------------------------------------
// CONSTRUCTORS
@@ -49,10 +49,15 @@
*/
public ProjectBuilder(FrontEnd frontEnd) {
this.frontEnd = frontEnd;
+ taskManager = new TaskManager(frontEnd);
parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
}
-
+
+ // -----------------------------------------------------------------
+ // PUBLIC METHODS
+ // -----------------------------------------------------------------
+
/**
* Builds a project from the given file.
*/
@@ -80,6 +85,18 @@
}
/**
+ * Returns the TaskManager associated with this ProjectBuilder and
+ * the projects that it builds
+ */
+ public TaskManager getTaskManager() {
+ return taskManager;
+ }
+
+ // -----------------------------------------------------------------
+ // INNER CLASSES
+ // -----------------------------------------------------------------
+
+ /**
* Inner class that implements the needed SAX methods to get all the
* data needed out of a build file.
*/
@@ -100,7 +117,7 @@
private Target currentTarget;
private Task currentTask;
- Project project = new Project();
+ Project project = new Project(frontEnd, taskManager);
Project getProject() {
return project;
1.3 +69 -16 jakarta-ant/proposal/anteater/source/main/org/apache/ant/TaskManager.java
Index: TaskManager.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/main/org/apache/ant/TaskManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TaskManager.java 2000/12/11 09:36:20 1.2
+++ TaskManager.java 2000/12/11 10:32:04 1.3
@@ -17,23 +17,18 @@
*
* @author James Duncan Davidson (duncan@apache.org)
*/
-class TaskManager {
+public class TaskManager {
// -----------------------------------------------------------------
// PRIVATE DATA MEMBERS
// -----------------------------------------------------------------
/**
- * Reference to Ant that holds this TaskManager
+ * FrontEnd that this TaskManager can communicate through.
*/
- //private Ant ant;
+ private FrontEnd frontEnd;
/**
- * Project to which this task manger belongs.
- */
- private Project project;
-
- /**
* Data structure where all the Class definition for all known tasks are
* held.
*/
@@ -51,21 +46,26 @@
/**
* Creates a new TaskManager.
*/
- TaskManager(Project project) {
- this.project = project;
+ TaskManager(FrontEnd frontEnd) {
+ System.out.println("CREATING TM");
+ this.frontEnd = frontEnd;
}
// -----------------------------------------------------------------
- // PACKAGE METHODS
+ // PUBLIC METHODS
// -----------------------------------------------------------------
/**
* Adds a node to the task path
*/
- void addTaskPathNode(File file) {
+ public void addTaskPathNode(File file) {
taskPathNodes.addElement(file);
processTaskPathNode(file);
}
+
+ // -----------------------------------------------------------------
+ // PACKAGE METHODS
+ // -----------------------------------------------------------------
/**
*
@@ -104,7 +104,7 @@
* Processes a directory to get class defintions from it
*/
private void processDir(File dir) {
- project.getFrontEnd().writeMessage("Scanning " + dir + " for tasks",
+ frontEnd.writeMessage("Scanning " + dir + " for tasks",
FrontEnd.MSG_LEVEL_LOW);
File file = new File(dir, "taskdef.properties");
if (file.exists()) {
@@ -121,7 +121,7 @@
URLClassLoader loader = new URLClassLoader(new URL[] {dir.toURL()});
try {
Class clazz = loader.loadClass(taskClass);
- project.getFrontEnd().writeMessage("Got Task: " + taskName +
+ frontEnd.writeMessage("Got Task: " + taskName +
clazz, FrontEnd.MSG_LEVEL_LOW);
taskClasses.put(taskName, clazz);
} catch (ClassNotFoundException cnfe) {
@@ -142,7 +142,7 @@
* Processes a jar file to get class definitions from it
*/
private void processJar(File file) {
- project.getFrontEnd().writeMessage("Scanning " + file + " for tasks",
+ frontEnd.writeMessage("Scanning " + file + " for tasks",
FrontEnd.MSG_LEVEL_LOW);
try {
ZipFile zipFile = new ZipFile(file);
@@ -160,7 +160,7 @@
URLClassLoader loader = new URLClassLoader(new URL[] {file.toURL()});
try {
Class clazz = loader.loadClass(taskClass);
- project.getFrontEnd().writeMessage("Got Task: " + taskName +
+ frontEnd.writeMessage("Got Task: " + taskName +
clazz, FrontEnd.MSG_LEVEL_LOW);
taskClasses.put(taskName, clazz);
} catch (ClassNotFoundException cnfe) {
@@ -207,4 +207,57 @@
processJar(file);
}
}
+
+ /**
+ * Sets up the taskpath based on the currently running operating
+ * system. In general, the ordering of the taskpath is: user directory,
+ * system directory, and then installation. This allows users or
+ * system admins to override or add tasks.
+ */
+ private void setUpTaskPath() {
+
+ // 1st, add user's home dir.
+
+ File f;
+
+ String userHome = System.getProperty("user.home");
+
+ // generic unix
+ f = new File(userHome + ".ant", "tasks");
+ if (f.exists() && f.isDirectory()) {
+ addTaskPathNode(f);
+ }
+
+ // macos x
+ f = new File(userHome + "/Library/Ant", "Tasks");
+ if (f.exists() && f.isDirectory()) {
+ addTaskPathNode(f);
+ }
+
+ // windows -- todo
+
+ // 2nd, add system local dir.
+
+ // generic unix
+ f = new File("/usr/local/ant/tasks");
+ if (f.exists() && f.isDirectory()) {
+ addTaskPathNode(f);
+ }
+
+ // macos x
+ f = new File("/Library/Ant/Tasks");
+ if (f.exists() && f.isDirectory()) {
+ addTaskPathNode(f);
+ }
+
+ // windows -- todo
+
+ // 3rd, add installation local dir.
+
+ //System.out.println("BASE: " + this.getClass().getResource("/"));
+
+ // XXX ---- not really sure how the best way of getting this info is...
+ // hafta think about it.
+ }
+
}
1.3 +23 -11 jakarta-ant/proposal/anteater/source/main/org/apache/ant/cli/CLIFrontEnd.java
Index: CLIFrontEnd.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/anteater/source/main/org/apache/ant/cli/CLIFrontEnd.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CLIFrontEnd.java 2000/12/11 09:36:22 1.2
+++ CLIFrontEnd.java 2000/12/11 10:32:08 1.3
@@ -23,18 +23,23 @@
/**
*
*/
- //private Ant ant;
+ private String[] args;
/**
- *
+ * ProjectBuilder that is associated with this frontEnd.
*/
- private String[] args;
+ private ProjectBuilder projectBuilder;
/**
*
*/
private int msgLevelFilter = MSG_LEVEL_MED;
+ /**
+ * TaskManager instance that we can set taskpaths and such on.
+ */
+ private TaskManager taskManager;
+
// -----------------------------------------------------------------
// CONSTRUCTORS
// -----------------------------------------------------------------
@@ -44,7 +49,8 @@
* Line.
*/
public CLIFrontEnd() {
- //ant = new Ant(this);
+ projectBuilder = new ProjectBuilder(this);
+ taskManager = projectBuilder.getTaskManager();
}
// -----------------------------------------------------------------
@@ -135,7 +141,7 @@
return;
} else {
// XXX need to separate on path seps so that real paths can be taken
- // ant.addTaskPathNode(new File(argTaskpath));
+ taskManager.addTaskPathNode(new File(argTaskpath));
}
}
@@ -164,16 +170,15 @@
// like get the default...
try {
- ProjectBuilder projectBuilder = new ProjectBuilder(this);
Project project = projectBuilder.buildFromFile(buildFile);
- //Project project = ant.getProject();
-
- // XXX
- // get taskmanager from project and set taskpath nodes on it!
project.setFrontEnd(this);
project.startBuild(target);
- } catch (AntException ae) {
+ } catch (AntException ae) {
+
+ //XXX this whole write a string at a time message handling
+ // sucks and needs to be improved...
+
writeMessage("Build Stopped");
writeMessage(" Project: " + ae.getProject().getName());
writeMessage(" Target: " + ae.getTarget().getName());
@@ -182,6 +187,13 @@
writeMessage("");
writeMessage(ae.getMessage());
ae.printStackTrace(System.out);
+ Throwable t = ae.getCause();
+ if (t != null) {
+ writeMessage("");
+ writeMessage("Cause Exception: " + t.toString());
+ writeMessage(t.getMessage());
+ t.printStackTrace(System.out);
+ }
}
}