You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2002/05/31 17:15:47 UTC
cvs commit: jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/logger DefaultLogger.java
conor 2002/05/31 08:15:47
Modified: proposal/mutant/build ant1compat.xml docs.xml
proposal/mutant/docs desc.html
proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib
AntLibManager.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
ComponentManager.java ExecutionContext.java
Frame.java
proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant
Ant1Factory.java
proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor
MonitorAspect.java MonitorRecord.java
proposal/mutant/src/java/common/org/apache/ant/common/antlib
AntContext.java
proposal/mutant/src/java/common/org/apache/ant/common/event
BuildEvent.java
proposal/mutant/src/java/common/org/apache/ant/common/logger
DefaultLogger.java
Log:
Various cleanups
Revision Changes Path
1.21 +2 -0 jakarta-ant/proposal/mutant/build/ant1compat.xml
Index: ant1compat.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build/ant1compat.xml,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -w -u -r1.20 -r1.21
--- ant1compat.xml 27 May 2002 15:52:20 -0000 1.20
+++ ant1compat.xml 31 May 2002 15:15:46 -0000 1.21
@@ -96,6 +96,8 @@
<exclude name="org/apache/tools/ant/taskdefs/JavaTest.java"/>
<exclude name="org/apache/tools/ant/taskdefs/JavacTest.java"/>
<exclude name="org/apache/tools/ant/taskdefs/TStampTest.java"/>
+ <exclude name="org/apache/tools/ant/taskdefs/TaskdefTest.java"/>
+ <exclude name="org/apache/tools/ant/taskdefs/TypedefTest.java"/>
</patternset>
<fileset id="ant1src_tocopy" dir="${ant1java.dir}">
1.2 +6 -6 jakarta-ant/proposal/mutant/build/docs.xml
Index: docs.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build/docs.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- docs.xml 18 Feb 2002 12:36:03 -0000 1.1
+++ docs.xml 31 May 2002 15:15:46 -0000 1.2
@@ -1,4 +1,4 @@
-<project name="build-site" default="docs" basedir=".">
+<project name="build-site" default="docs" basedir="..">
<!-- Initialization properties -->
<property name="project.name" value="mutant"/>
1.3 +1 -0 jakarta-ant/proposal/mutant/docs/desc.html
Index: desc.html
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/docs/desc.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- desc.html 18 Mar 2002 02:44:24 -0000 1.2
+++ desc.html 31 May 2002 15:15:46 -0000 1.3
@@ -9,6 +9,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="author" value="Conor MacNeill">
+ <meta name="email" value="">
<title>The Jakarta Site - Mutant Design Notes</title>
</head>
1.13 +24 -4 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java
Index: AntLibManager.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -u -r1.12 -r1.13
--- AntLibManager.java 27 May 2002 15:52:21 -0000 1.12
+++ AntLibManager.java 31 May 2002 15:15:46 -0000 1.13
@@ -53,6 +53,7 @@
*/
package org.apache.ant.antcore.antlib;
import java.io.FileNotFoundException;
+import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -248,7 +249,6 @@
*/
public void addLibPath(String libraryId, URL libPath)
throws AntLibException {
- System.out.println("Adding path " + libPath + " for " + libraryId);
if (!libPath.getProtocol().equals("file")
&& !remoteAllowed) {
throw new AntLibException("Remote libpaths are not"
@@ -260,11 +260,31 @@
libPaths = new ArrayList();
libPathsMap.put(libraryId, libPaths);
}
- libPaths.add(libPath);
+
+ List newPaths = new ArrayList();
+ newPaths.add(libPath);
+ if (libPath.getProtocol().equals("file")) {
+ File dir = new File(libPath.getFile());
+ if (dir.isDirectory()) {
+ try {
+ URL[] pathURLs = LoaderUtils.getLocationURLs(libPath,
+ null, ANTLIB_EXTENSIONS);
+ for (int i = 0; i < pathURLs.length; ++i) {
+ newPaths.add(pathURLs[i]);
+ }
+ } catch (MalformedURLException e) {
+ // ignore and just use what we were given
+ }
+ }
+ }
AntLibrary antLibrary = getLibrary(libraryId);
+ for (Iterator i = newPaths.iterator(); i.hasNext();) {
+ URL newPath = (URL) i.next();
+ libPaths.add(newPath);
if (antLibrary != null) {
- antLibrary.addLibraryURL(libPath);
+ antLibrary.addLibraryURL(newPath);
+ }
}
}
1.20 +47 -45 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java
Index: ComponentManager.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -w -u -r1.19 -r1.20
--- ComponentManager.java 27 May 2002 15:52:21 -0000 1.19
+++ ComponentManager.java 31 May 2002 15:15:46 -0000 1.20
@@ -435,15 +435,6 @@
private Object createComponent(String componentName, BuildElement model)
throws AntException {
- Object component = null;
- if (model != null) {
- for (Iterator i = aspects.iterator(); i.hasNext();) {
- Aspect aspect = (Aspect) i.next();
- component = aspect.preCreateComponent(component, model);
- }
- }
-
- if (component == null) {
ImportInfo importInfo = getImport(componentName);
if (importInfo == null) {
throw new ExecutionException("There is no definition of the <"
@@ -454,20 +445,10 @@
ComponentLibrary componentLibrary
= importInfo.getComponentLibrary();
- component = createComponentFromDef(componentName, componentLibrary,
+ return createComponentFromDef(componentName, componentLibrary,
importInfo.getDefinition(), model);
}
- if (model != null) {
- for (Iterator i = aspects.iterator(); i.hasNext();) {
- Aspect aspect = (Aspect) i.next();
- component = aspect.postCreateComponent(component, model);
- }
- }
-
- return component;
- }
-
/**
* Create a component from its library definition.
*
@@ -486,22 +467,36 @@
throws AntException {
Location location = Location.UNKNOWN_LOCATION;
+ String className = null;
+ try {
+ boolean isTask
+ = libDefinition.getDefinitionType() == AntLibrary.TASKDEF;
+
+
+ Object component = null;
if (model != null) {
location = model.getLocation();
+ for (Iterator i = aspects.iterator(); i.hasNext();) {
+ Aspect aspect = (Aspect) i.next();
+ component = aspect.preCreateComponent(component, model);
+ }
}
- boolean isTask
- = libDefinition.getDefinitionType() == AntLibrary.TASKDEF;
+ AntLibFactory libFactory = getLibFactory(componentLibrary);
+ ClassLoader componentLoader = null;
+ if (component == null) {
String localName = libDefinition.getDefinitionName();
- String className = libDefinition.getClassName();
- try {
- ClassLoader componentLoader = componentLibrary.getClassLoader();
+ className = libDefinition.getClassName();
+ componentLoader = componentLibrary.getClassLoader();
Class componentClass
= Class.forName(className, true, componentLoader);
- AntLibFactory libFactory = getLibFactory(componentLibrary);
// create the component using the factory
- Object component
+ component
= libFactory.createComponent(componentClass, localName);
+ } else {
+ className = component.getClass().getName();
+ componentLoader = component.getClass().getClassLoader();
+ }
// wrap the component in an adapter if required.
ExecutionComponent execComponent = null;
@@ -522,11 +517,14 @@
// if the component is an execution component create a context and
// initialise the component with it.
if (execComponent != null) {
+ // give it a context unless it already has one
+ if (execComponent.getAntContext() == null) {
ExecutionContext context
= new ExecutionContext(frame, execComponent, model);
context.setClassLoader(componentLoader);
execComponent.init(context, componentName);
}
+ }
// if we have a model, use it to configure the component. Otherwise
// the caller is expected to configure thre object
@@ -536,6 +534,10 @@
// model, validate it
if (execComponent != null) {
execComponent.validateComponent();
+ }
+ for (Iterator i = aspects.iterator(); i.hasNext();) {
+ Aspect aspect = (Aspect) i.next();
+ component = aspect.postCreateComponent(component, model);
}
}
1.15 +1 -1 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java
Index: ExecutionContext.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -u -r1.14 -r1.15
--- ExecutionContext.java 27 May 2002 15:52:21 -0000 1.14
+++ ExecutionContext.java 31 May 2002 15:15:47 -0000 1.15
@@ -175,7 +175,7 @@
*
* @return the build model or null if there is no build model.
*/
- protected BuildElement getModel() {
+ public BuildElement getModel() {
return model;
}
}
1.28 +10 -8 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java
Index: Frame.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -w -u -r1.27 -r1.28
--- Frame.java 27 May 2002 15:52:21 -0000 1.27
+++ Frame.java 31 May 2002 15:15:47 -0000 1.28
@@ -973,14 +973,15 @@
failureCause
= aspect.postExecuteTask(aspectContext, failureCause);
}
+
eventSupport.fireTaskFinished(task, failureCause);
if (aspectContexts.size() != 0) {
aspectContextsMap.remove(task);
}
if (failureCause != null) {
- if (failureCause instanceof ExecutionException) {
- throw (ExecutionException) failureCause;
+ if (failureCause instanceof AntException) {
+ throw (AntException) failureCause;
}
throw new ExecutionException(failureCause);
}
@@ -1156,7 +1157,8 @@
// load system ant lib
URL systemLibs
= new URL(initConfig.getLibraryURL(), "syslibs/");
- componentManager.loadLib(systemLibs, true);
+ componentManager.loadLib(systemLibs, false);
+ importStandardComponents();
executeTasks(config.getGlobalTasks());
@@ -1164,12 +1166,12 @@
URL antLibs = new URL(initConfig.getLibraryURL(), "antlibs/");
componentManager.loadLib(antLibs, false);
- } catch (MalformedURLException e) {
- throw new ExecutionException("Unable to initialize antlibs", e);
- }
-
- try {
runBuild(targets);
+ } catch (MalformedURLException e) {
+ ExecutionException ee =
+ new ExecutionException("Unable to initialize antlibs", e);
+ buildFailureCause = ee;
+ throw ee;
} catch (RuntimeException e) {
buildFailureCause = e;
throw e;
1.13 +2 -2 jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java
Index: Ant1Factory.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -u -r1.12 -r1.13
--- Ant1Factory.java 27 May 2002 15:52:22 -0000 1.12
+++ Ant1Factory.java 31 May 2002 15:15:47 -0000 1.13
@@ -57,7 +57,7 @@
import org.apache.ant.common.service.EventService;
import org.apache.ant.common.util.AntException;
import org.apache.ant.init.LoaderUtils;
-
+import java.lang.reflect.InvocationTargetException;
/**
* The factory object for the Ant1 compatability Ant library
*
@@ -132,7 +132,7 @@
((ProjectComponent) component).setProject(project);
}
return component;
- } catch (java.lang.reflect.InvocationTargetException ite) {
+ } catch (InvocationTargetException ite) {
Throwable t = ite.getTargetException();
String msg = "Could not create component of type: "
+ componentClass.getName() + " due to " + t;
1.2 +24 -66 jakarta-ant/proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorAspect.java
Index: MonitorAspect.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorAspect.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- MonitorAspect.java 27 May 2002 15:52:24 -0000 1.1
+++ MonitorAspect.java 31 May 2002 15:15:47 -0000 1.2
@@ -55,6 +55,7 @@
import org.apache.ant.common.antlib.AbstractAspect;
import org.apache.ant.common.antlib.Task;
+import org.apache.ant.common.antlib.AntContext;
import org.apache.ant.common.model.BuildElement;
import org.apache.ant.common.model.AspectValueCollection;
import org.apache.ant.common.util.AntException;
@@ -71,70 +72,25 @@
* @author Conor MacNeill
*/
public class MonitorAspect extends AbstractAspect {
+ /** The log into which monitoring info is written */
private static PrintStream monitorLog;
- private static long lastMessageTime;
+
+ /**
+ * Create a monitoring aspect instance. There will be one instance per
+ * active frame but they all share the same log output.
+ */
public MonitorAspect() {
+ synchronized (MonitorAspect.class) {
if (monitorLog == null) {
try {
monitorLog
= new PrintStream(new FileOutputStream("monitor.log"));
monitorLog.println("Logging started at " + new Date());
- lastMessageTime = System.currentTimeMillis();
} catch (IOException e) {
log("Unable to open monitor log", MessageLevel.MSG_WARN);
}
}
}
-
- private void monitor(String message) {
- Runtime rt = Runtime.getRuntime();
- synchronized (monitorLog) {
- long now = System.currentTimeMillis();
- long diff = now - lastMessageTime;
- lastMessageTime = now;
- long freeMem = rt.freeMemory();
- long usedMem = rt.totalMemory() - freeMem;
- monitorLog.println("+" + diff + " (" + usedMem + "/"
- + freeMem + "): " + message);
- }
- }
-
- /**
- * This join point is activated before a component is to be created.
- * The aspect can return an object to be used rather than the core creating
- * the object.
- *
- * @param component the component that has been created. This will be null
- * unless another aspect has created the component
- * @param model the Build model that applies to the component
- *
- * @return a component to use.
- * @exception AntException if the aspect cannot process the component.
- */
- public Object preCreateComponent(Object component, BuildElement model)
- throws AntException {
- monitor("Creating component " + "from <" + model.getType() + ">");
- return component;
- }
-
- /**
- * This join point is activated after a component has been created and
- * configured. If the aspect wishes, an object can be returned in place
- * of the one created by Ant.
- *
- * @param component the component that has been created.
- * @param model the Build model used to create the component.
- *
- * @return a replacement for the component if desired. If null is returned
- * the current component is used.
- * @exception AntException if the aspect cannot process the component.
- */
- public Object postCreateComponent(Object component, BuildElement model)
- throws AntException {
- monitor("Created component "
- + component.getClass().getName()
- + " from <" + model.getType() + ">");
- return component;
}
/**
@@ -152,9 +108,12 @@
*/
public Object preExecuteTask(Task task, AspectValueCollection aspectValues)
throws AntException {
- String taskName = task.getClass().getName();
- MonitorRecord record = new MonitorRecord(taskName);
- return record;
+ System.gc();
+ AntContext taskContext = task.getAntContext();
+ BuildElement model = taskContext.getModel();
+ String name = (model == null) ? task.getClass().getName()
+ : model.getType();
+ return new MonitorRecord(name, taskContext.getLocation());
}
/**
@@ -168,9 +127,8 @@
*/
public Throwable postExecuteTask(Object context, Throwable failureCause) {
MonitorRecord record = (MonitorRecord)context;
- record.print(monitorLog);
System.gc();
+ record.print(monitorLog);
return failureCause;
}
-
}
1.2 +32 -14 jakarta-ant/proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorRecord.java
Index: MonitorRecord.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorRecord.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- MonitorRecord.java 27 May 2002 15:52:24 -0000 1.1
+++ MonitorRecord.java 31 May 2002 15:15:47 -0000 1.2
@@ -53,16 +53,8 @@
*/
package org.apache.ant.antlib.monitor;
-import org.apache.ant.common.antlib.AbstractAspect;
-import org.apache.ant.common.antlib.Task;
-import org.apache.ant.common.model.BuildElement;
-import org.apache.ant.common.model.AspectValueCollection;
-import org.apache.ant.common.util.AntException;
-import org.apache.ant.common.event.MessageLevel;
-import java.util.Date;
+import org.apache.ant.common.util.Location;
import java.io.PrintStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
/**
* A record of some performance values at a particular time
@@ -70,25 +62,51 @@
* @author Conor MacNeill
*/
public class MonitorRecord {
- private String recordName;
+ /** The element name being monitored */
+ private String elementName;
+
+ /** The location in the build file */
+ private Location location;
+
+ /** System clock when task started */
private long startMillis;
+
+ /** Starting memory when task started */
private long startMemory;
+ /**
+ * Get the current used memory from the runtime
+ *
+ * @return the amount of memory in use.
+ */
private long getMemoryUsage() {
Runtime rt = Runtime.getRuntime();
return rt.totalMemory() - rt.freeMemory();
}
- public MonitorRecord(String recordName) {
- this.recordName = recordName;
+ /**
+ * Create a monitoring record.
+ *
+ * @param elementName the name of the element.
+ * @param location the build file location of the element.
+ */
+ public MonitorRecord(String elementName, Location location) {
+ this.elementName = elementName;
+ this.location = location;
startMillis = System.currentTimeMillis();
startMemory = getMemoryUsage();
}
+ /**
+ * Print a summary of the monitor
+ *
+ * @param stream the stream onto which the summary is printed.
+ */
public void print(PrintStream stream) {
long timeDiff = System.currentTimeMillis() - startMillis;
long memDiff = getMemoryUsage() - startMemory;
- stream.println(recordName + " took " + timeDiff
- + " milliseconds and memory used changed by " + memDiff);
+ stream.println(location + elementName + " took " + timeDiff
+ + " milliseconds, memory used at start " + startMemory
+ + " which changed by " + memDiff);
}
}
1.10 +9 -0 jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java
Index: AntContext.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -u -r1.9 -r1.10
--- AntContext.java 27 May 2002 15:52:25 -0000 1.9
+++ AntContext.java 31 May 2002 15:15:47 -0000 1.10
@@ -54,6 +54,7 @@
package org.apache.ant.common.antlib;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.Location;
+import org.apache.ant.common.model.BuildElement;
/**
* The AntContext is the interface through which the Ant container and the
@@ -91,5 +92,13 @@
* @return the location which may be the unknown location
*/
Location getLocation();
+
+ /**
+ * Get the build model associated with this context if any
+ *
+ * @return the build model which may be null if there is no associated
+ * model
+ */
+ BuildElement getModel();
}
1.8 +4 -0 jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java
Index: BuildEvent.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -u -r1.7 -r1.8
--- BuildEvent.java 18 Mar 2002 02:44:27 -0000 1.7
+++ BuildEvent.java 31 May 2002 15:15:47 -0000 1.8
@@ -80,6 +80,10 @@
public static final int TASK_FINISHED = 6;
/** message event type */
public static final int MESSAGE = 7;
+ /** Project started event type */
+ public static final int PROJECT_STARTED = 8;
+ /** Project finished event type */
+ public static final int PROJECT_FINISHED = 9;
/** The type of this event */
private int eventType;
1.2 +2 -1 jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/logger/DefaultLogger.java
Index: DefaultLogger.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/logger/DefaultLogger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- DefaultLogger.java 27 May 2002 15:52:26 -0000 1.1
+++ DefaultLogger.java 31 May 2002 15:15:47 -0000 1.2
@@ -57,6 +57,7 @@
import org.apache.ant.common.antlib.ExecutionComponent;
import org.apache.ant.common.antlib.Task;
import org.apache.ant.common.event.BuildEvent;
+import org.apache.ant.common.event.BuildListenerAdapter;
import org.apache.ant.common.event.MessageLevel;
import org.apache.ant.common.model.Target;
import org.apache.ant.common.util.AntException;
@@ -69,7 +70,7 @@
* @author Conor MacNeill
* @created 15 January 2002
*/
-public class DefaultLogger implements BuildLogger {
+public class DefaultLogger extends BuildListenerAdapter implements BuildLogger {
/** Standard field separator */
private static String lSep = System.getProperty("line.separator");
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>