Browse Source

Various cleanups

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272820 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 23 years ago
parent
commit
f19f07d6e4
13 changed files with 164 additions and 147 deletions
  1. +2
    -0
      proposal/mutant/build/ant1compat.xml
  2. +6
    -6
      proposal/mutant/build/docs.xml
  3. +1
    -0
      proposal/mutant/docs/desc.html
  4. +24
    -4
      proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java
  5. +47
    -45
      proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java
  6. +1
    -1
      proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java
  7. +10
    -8
      proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java
  8. +2
    -2
      proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java
  9. +24
    -66
      proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorAspect.java
  10. +32
    -14
      proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorRecord.java
  11. +9
    -0
      proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java
  12. +4
    -0
      proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java
  13. +2
    -1
      proposal/mutant/src/java/common/org/apache/ant/common/logger/DefaultLogger.java

+ 2
- 0
proposal/mutant/build/ant1compat.xml View File

@@ -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}">


+ 6
- 6
proposal/mutant/build/docs.xml View File

@@ -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"/>
@@ -15,8 +15,8 @@
</fileset>
</path>

<target name="prepare">
<available classname="org.apache.velocity.anakia.AnakiaTask"
<target name="prepare">
<available classname="org.apache.velocity.anakia.AnakiaTask"
property="AnakiaTask.present">
<classpath refid="anakia.classpath"/>
</available>
@@ -24,7 +24,7 @@

<target depends="prepare" name="prepare-error" unless="AnakiaTask.present">
<echo>
AnakiaTask is not present! Please check to make sure that
AnakiaTask is not present! Please check to make sure that
velocity.jar is in your classpath.
</echo>
</target>
@@ -33,7 +33,7 @@
<taskdef name="anakia" classname="org.apache.velocity.anakia.AnakiaTask">
<classpath refid="anakia.classpath"/>
</taskdef>
<anakia basedir="${docs.src}" destdir="${docs.dest}/"
extension=".html" style="./site.vsl"
projectFile="${project.file}"
@@ -44,6 +44,6 @@
velocityPropertiesFile="${velocity.props}">
</anakia>
</target>
<target name="all" depends="docs"/>
</project>

+ 1
- 0
proposal/mutant/docs/desc.html View File

@@ -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>


+ 24
- 4
proposal/mutant/src/java/antcore/org/apache/ant/antcore/antlib/AntLibManager.java View File

@@ -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 class AntLibManager {
*/
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 @@ public class AntLibManager {
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);
if (antLibrary != null) {
antLibrary.addLibraryURL(libPath);
for (Iterator i = newPaths.iterator(); i.hasNext();) {
URL newPath = (URL) i.next();
libPaths.add(newPath);
if (antLibrary != null) {
antLibrary.addLibraryURL(newPath);
}
}
}



+ 47
- 45
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java View File

@@ -435,37 +435,18 @@ public class ComponentManager implements ComponentService {
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);
}
ImportInfo importInfo = getImport(componentName);
if (importInfo == null) {
throw new ExecutionException("There is no definition of the <"
+ componentName + "> component");
}
String className = importInfo.getClassName();

if (component == null) {
ImportInfo importInfo = getImport(componentName);
if (importInfo == null) {
throw new ExecutionException("There is no definition of the <"
+ componentName + "> component");
}
String className = importInfo.getClassName();

ComponentLibrary componentLibrary
ComponentLibrary componentLibrary
= importInfo.getComponentLibrary();

component = 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;
return createComponentFromDef(componentName, componentLibrary,
importInfo.getDefinition(), model);
}

/**
@@ -486,22 +467,36 @@ public class ComponentManager implements ComponentService {
throws AntException {

Location location = Location.UNKNOWN_LOCATION;
if (model != null) {
location = model.getLocation();
}

boolean isTask
= libDefinition.getDefinitionType() == AntLibrary.TASKDEF;
String localName = libDefinition.getDefinitionName();
String className = libDefinition.getClassName();
String className = null;
try {
ClassLoader componentLoader = componentLibrary.getClassLoader();
Class componentClass
= Class.forName(className, true, componentLoader);
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);
}
}

AntLibFactory libFactory = getLibFactory(componentLibrary);
// create the component using the factory
Object component
= libFactory.createComponent(componentClass, localName);
ClassLoader componentLoader = null;
if (component == null) {
String localName = libDefinition.getDefinitionName();
className = libDefinition.getClassName();
componentLoader = componentLibrary.getClassLoader();
Class componentClass
= Class.forName(className, true, componentLoader);
// create the component using the factory
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,10 +517,13 @@ public class ComponentManager implements ComponentService {
// if the component is an execution component create a context and
// initialise the component with it.
if (execComponent != null) {
ExecutionContext context
= new ExecutionContext(frame, execComponent, model);
context.setClassLoader(componentLoader);
execComponent.init(context, componentName);
// 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
@@ -537,6 +535,10 @@ public class ComponentManager implements ComponentService {
if (execComponent != null) {
execComponent.validateComponent();
}
for (Iterator i = aspects.iterator(); i.hasNext();) {
Aspect aspect = (Aspect) i.next();
component = aspect.postCreateComponent(component, model);
}
}

// reset the loader


+ 1
- 1
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionContext.java View File

@@ -175,7 +175,7 @@ public class ExecutionContext implements AntContext {
*
* @return the build model or null if there is no build model.
*/
protected BuildElement getModel() {
public BuildElement getModel() {
return model;
}
}


+ 10
- 8
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java View File

@@ -973,14 +973,15 @@ public class Frame implements DemuxOutputReceiver {
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 @@ public class Frame implements DemuxOutputReceiver {
// 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 @@ public class Frame implements DemuxOutputReceiver {
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;


+ 2
- 2
proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Ant1Factory.java View File

@@ -57,7 +57,7 @@ import org.apache.ant.common.antlib.StandardLibFactory;
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 @@ public class Ant1Factory extends StandardLibFactory {
((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;


+ 24
- 66
proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorAspect.java View File

@@ -55,6 +55,7 @@ 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.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 @@ import java.io.IOException;
* @author Conor MacNeill
*/
public class MonitorAspect extends AbstractAspect {
/** The log into which monitoring info is written */
private static PrintStream monitorLog;
private static long lastMessageTime;
public MonitorAspect() {
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.
* Create a monitoring aspect instance. There will be one instance per
* active frame but they all share the same log output.
*/
public Object postCreateComponent(Object component, BuildElement model)
throws AntException {
monitor("Created component "
+ component.getClass().getName()
+ " from <" + model.getType() + ">");
return component;
public MonitorAspect() {
synchronized (MonitorAspect.class) {
if (monitorLog == null) {
try {
monitorLog
= new PrintStream(new FileOutputStream("monitor.log"));
monitorLog.println("Logging started at " + new Date());
} catch (IOException e) {
log("Unable to open monitor log", MessageLevel.MSG_WARN);
}
}
}
}

/**
@@ -152,9 +108,12 @@ public class MonitorAspect extends AbstractAspect {
*/
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());
}

/**
@@ -167,10 +126,9 @@ public class MonitorAspect extends AbstractAspect {
* @return a new failure reason or null if the task is not to fail.
*/
public Throwable postExecuteTask(Object context, Throwable failureCause) {
MonitorRecord record = (MonitorRecord)context;
record.print(monitorLog);
MonitorRecord record = (MonitorRecord) context;
System.gc();
record.print(monitorLog);
return failureCause;
}

}

+ 32
- 14
proposal/mutant/src/java/antlibs/monitor/org/apache/ant/antlib/monitor/MonitorRecord.java View File

@@ -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 @@ import java.io.IOException;
* @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);
}
}

+ 9
- 0
proposal/mutant/src/java/common/org/apache/ant/common/antlib/AntContext.java View File

@@ -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 @@ public interface AntContext {
* @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();
}


+ 4
- 0
proposal/mutant/src/java/common/org/apache/ant/common/event/BuildEvent.java View File

@@ -80,6 +80,10 @@ public class BuildEvent extends EventObject {
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;


+ 2
- 1
proposal/mutant/src/java/common/org/apache/ant/common/logger/DefaultLogger.java View File

@@ -57,6 +57,7 @@ import java.io.PrintStream;
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 @@ import org.apache.ant.common.util.Location;
* @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");


Loading…
Cancel
Save