conor 02/04/16 07:07:47
Modified: proposal/mutant bootstrap.bat bootstrap.sh build.bat
build.sh build.xml
proposal/mutant/build bootstrap.xsl
proposal/mutant/src/java/bootstrap/org/apache/ant/builder
Ant1CompatBuilder.java BuildHelper.java
Builder.java MutantBuilder.java
Added: proposal/mutant/src/java/frontend/org/apache/ant/cli
BuildLogger.java Commandline.java
DefaultLogger.java
proposal/mutant/src/java/frontend/org/apache/ant/frontend
FrontendUtils.java
Removed: proposal/mutant/src/java/cli/org/apache/ant/cli
BuildLogger.java Commandline.java
DefaultLogger.java
Log:
Reorg of mutant frontend classes
Revision Changes Path
1.3 +2 -2 jakarta-ant/proposal/mutant/bootstrap.bat
Index: bootstrap.bat
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/bootstrap.bat,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- bootstrap.bat 4 Mar 2002 15:17:31 -0000 1.2
+++ bootstrap.bat 16 Apr 2002 14:07:46 -0000 1.3
@@ -23,10 +23,10 @@
java -classpath bin\init;bin\bootstrap org.apache.ant.bootstrap.Bootstrap
REM run full build using bootstrapped version
-java -classpath bootstrap\lib\start.jar;bootstrap\lib\init.jar
org.apache.ant.start.Main %*
+java -jar bootstrap\lib\start.jar %*
REM Use the full build as the build used by the build script
xcopy /s dist bootstrap
REM clean up after bootstrap
-java -classpath bootstrap\lib\start.jar:bootstrap\lib\init.jar
org.apache.ant.start.Main clean
+java -jar bootstrap\lib\start.jar clean
1.5 +2 -2 jakarta-ant/proposal/mutant/bootstrap.sh
Index: bootstrap.sh
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/bootstrap.sh,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- bootstrap.sh 2 Mar 2002 14:14:49 -0000 1.4
+++ bootstrap.sh 16 Apr 2002 14:07:46 -0000 1.5
@@ -22,10 +22,10 @@
java -classpath bin/init:bin/bootstrap org.apache.ant.bootstrap.Bootstrap
# run full build using bootstrapped version
-java -classpath bootstrap/lib/start.jar:bootstrap/lib/init.jar
org.apache.ant.start.Main $*
+java -jar bootstrap/lib/start.jar $*
# Use the full build as the build used by the build script
cp -r dist/lib bootstrap
#clean up after bootstrap
-java -classpath bootstrap/lib/start.jar:bootstrap/lib/init.jar
org.apache.ant.start.Main clean
+java -jar bootstrap/lib/start.jar clean
1.2 +2 -2 jakarta-ant/proposal/mutant/build.bat
Index: build.bat
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build.bat,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- build.bat 19 Feb 2002 02:12:21 -0000 1.1
+++ build.bat 16 Apr 2002 14:07:46 -0000 1.2
@@ -1,5 +1,5 @@
@echo off
-REM Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+REM Copyright (c) 2002 The Apache Software Foundation. All rights
REM reserved.
-java -classpath bootstrap\lib\start.jar;bootstrap\lib\init.jar
org.apache.ant.start.Main %*
+java -jar bootstrap\lib\start.jar %*
1.3 +2 -2 jakarta-ant/proposal/mutant/build.sh
Index: build.sh
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build.sh,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- build.sh 20 Feb 2002 13:43:14 -0000 1.2
+++ build.sh 16 Apr 2002 14:07:46 -0000 1.3
@@ -1,6 +1,6 @@
#!/bin/sh -x
-# Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+# Copyright (c) 2002 The Apache Software Foundation. All rights
# reserved.
-java -classpath bootstrap/lib/start.jar:bootstrap/lib/init.jar
org.apache.ant.start.Main $@
+java -jar bootstrap/lib/start.jar $@
1.22 +15 -10 jakarta-ant/proposal/mutant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -w -u -r1.21 -r1.22
--- build.xml 12 Apr 2002 14:59:56 -0000 1.21
+++ build.xml 16 Apr 2002 14:07:46 -0000 1.22
@@ -25,7 +25,7 @@
<path refid="classpath.parser"/>
</path>
- <path id="classpath.cli">
+ <path id="classpath.frontend">
<path refid="classpath.antcore"/>
<pathelement location="${distlib.dir}/antcore/antcore.jar"/>
</path>
@@ -75,18 +75,23 @@
<jar basedir="${bin.dir}/antcore"
jarfile="${distlib.dir}/antcore/antcore.jar"/>
</target>
- <target name="cli" depends="antcore, start">
- <mkdir dir="${bin.dir}/cli"/>
+ <target name="frontend" depends="antcore, start">
+ <mkdir dir="${bin.dir}/frontend"/>
<mkdir dir="${distlib.dir}/frontend"/>
- <depend destdir="${bin.dir}/cli" srcdir="${java.dir}/cli">
- <classpath refid="classpath.cli"/>
+ <depend destdir="${bin.dir}/frontend" srcdir="${java.dir}/frontend">
+ <classpath refid="classpath.frontend"/>
</depend>
- <javac destdir="${bin.dir}/cli" srcdir="${java.dir}/cli"
debug="${debug}">
- <classpath refid="classpath.cli"/>
+ <javac destdir="${bin.dir}/frontend" srcdir="${java.dir}/frontend"
debug="${debug}">
+ <classpath refid="classpath.frontend"/>
</javac>
- <jar basedir="${bin.dir}/cli" jarfile="${distlib.dir}/frontend/cli.jar">
+ <jar basedir="${bin.dir}/frontend"
jarfile="${distlib.dir}/frontend/frontend.jar">
+ <include name="**/frontend/*.class"/>
+ </jar>
+ <jar basedir="${bin.dir}/frontend"
jarfile="${distlib.dir}/frontend/cli.jar">
+ <include name="**/cli/*.class"/>
<manifest>
<attribute name="Main-Class" value="org.apache.ant.cli.Commandline"/>
+ <attribute name="Class-Path" value="frontend.jar"/>
</manifest>
</jar>
</target>
@@ -165,7 +170,7 @@
</jar>
</target>
- <target name="main" depends="cli, antlibs, ant1compat, remote,
checkstyle"/>
+ <target name="main" depends="frontend, antlibs, ant1compat, remote,
checkstyle"/>
<target name="checkstyle" if="checkstyle.available">
<taskdef name="checkstyle"
@@ -197,7 +202,7 @@
<mkdir dir="${javadocs.dir}"/>
<javadoc packagenames="org.apache.*"
useexternalfile="yes"
-
sourcepath="${java.dir}/antcore:${java.dir}/init:${java.dir}/common:${java.dir}/cli:${java.dir}/start"
+
sourcepath="${java.dir}/antcore:${java.dir}/init:${java.dir}/common:${java.dir}/frontend:${java.dir}/start"
destdir="${javadocs.dir}"
author="true"
private ="true"
1.2 +25 -3 jakarta-ant/proposal/mutant/build/bootstrap.xsl
Index: bootstrap.xsl
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/build/bootstrap.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -u -r1.1 -r1.2
--- bootstrap.xsl 18 Feb 2002 12:36:03 -0000 1.1
+++ bootstrap.xsl 16 Apr 2002 14:07:46 -0000 1.2
@@ -23,11 +23,15 @@
<xsl:text>"); </xsl:text>
</xsl:template>
+ <xsl:template match="echo">
+ </xsl:template>
+
<xsl:template match="path">
<xsl:text> helper.createPath("</xsl:text>
<xsl:variable name="pathName" select="attribute::id"/>
<xsl:value-of select="$pathName"/>
<xsl:text>"); </xsl:text>
+
<xsl:for-each select="fileset">
<xsl:text> </xsl:text>
<xsl:text>helper.addFileSetToPath("</xsl:text>
@@ -48,6 +52,7 @@
</xsl:choose>
<xsl:text>); </xsl:text>
</xsl:for-each>
+
<xsl:for-each select="pathelement">
<xsl:text> </xsl:text>
<xsl:text>helper.addPathElementToPath("</xsl:text>
@@ -56,6 +61,7 @@
<xsl:value-of select="attribute::location"/>
<xsl:text>"); </xsl:text>
</xsl:for-each>
+
<xsl:for-each select="path">
<xsl:text> </xsl:text>
<xsl:text>helper.addPathToPath("</xsl:text>
@@ -114,16 +120,32 @@
<xsl:when test="metainf/attribute::includes">
<xsl:text>"</xsl:text>
<xsl:value-of select="metainf/attribute::includes"/>
- <xsl:text>"</xsl:text>
+ <xsl:text>", </xsl:text>
</xsl:when>
<xsl:otherwise>
- <xsl:text>null</xsl:text>
+ <xsl:text>null, </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
- <xsl:text>null, null</xsl:text>
+ <xsl:text>null, null, </xsl:text>
</xsl:otherwise>
+ </xsl:choose>
+ <xsl:choose>
+ <xsl:when test="manifest/attribute[attribute::name='Class-Path']">
+ <xsl:text>"</xsl:text>
+ <xsl:value-of
select="manifest/attribute[attribute::name='Class-Path']/attribute::value"/>
+ <xsl:text>", </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>null, </xsl:otherwise>
+ </xsl:choose>
+ <xsl:choose>
+ <xsl:when test="manifest/attribute[attribute::name='Main-Class']">
+ <xsl:text>"</xsl:text>
+ <xsl:value-of
select="manifest/attribute[attribute::name='Main-Class']/attribute::value"/>
+ <xsl:text>"</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>null</xsl:otherwise>
</xsl:choose>
<xsl:text>); </xsl:text>
</xsl:template>
1.5 +1 -1
jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Ant1CompatBuilder.java
Index: Ant1CompatBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Ant1CompatBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- Ant1CompatBuilder.java 28 Mar 2002 14:49:27 -0000 1.4
+++ Ant1CompatBuilder.java 16 Apr 2002 14:07:46 -0000 1.5
@@ -37,7 +37,7 @@
helper.copyFileset("${bin.dir}/ant1src_copy",
"${bin.dir}/ant1compat");
helper.copyFileset("${ant1etc.dir}",
"${bin.dir}/ant1compat/${optional.package}/junit/xsl");
helper.jar("${bin.dir}/ant1compat",
"${distlib.dir}/antlibs/ant1compat.jar",
- "${java.dir}/antlibs/ant1compat", "antlib.xml");
+ "${java.dir}/antlibs/ant1compat", "antlib.xml", null,
null);
}
protected void clean(BuildHelper helper) {
}
1.5 +79 -9
jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/BuildHelper.java
Index: BuildHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/BuildHelper.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- BuildHelper.java 7 Apr 2002 14:38:07 -0000 1.4
+++ BuildHelper.java 16 Apr 2002 14:07:46 -0000 1.5
@@ -64,7 +64,9 @@
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
/**
@@ -90,6 +92,7 @@
}
+
/** The properties which have been defined in the build */
private Map properties = new HashMap();
@@ -99,6 +102,7 @@
/** Filesets created in the build */
private Map filesets = new HashMap();
+
/**
* Set a property for the build
*
@@ -108,30 +112,49 @@
protected void setProperty(String propertyName, String propertyValue) {
if (!properties.containsKey(propertyName)) {
String value = resolve(propertyValue);
+
properties.put(propertyName, value);
}
}
+
/**
* Create a Jar
*
* @param basedir the base directpory from which files are added to the
* jar
* @param metaInfDir the directory containing the META-INF for the jar
- * @param metaInfIncludes the files to be included in the META-INF area
- * of the jar
+ * @param metaInfIncludes the files to be included in the META-INF area
of
+ * the jar
* @param jarFile the file in which the Jar is created
+ * @param classpath Class-Path attribute in manifest
+ * @param mainClass Main-Class attribute in manifest
*/
protected void jar(String basedir, String jarFile, String metaInfDir,
- String metaInfIncludes) {
+ String metaInfIncludes,
+ String classpath, String mainClass) {
try {
File base = new File(resolve(basedir));
File jar = new File(resolve(jarFile));
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ attributes.putValue("Manifest-Version", "1.0");
+ attributes.putValue("Created-By", "Mutant Bootstrap");
+
+ if (classpath != null) {
+ attributes.putValue("Class-Path", classpath);
+ }
+ if (mainClass != null) {
+ attributes.putValue("Main-Class", mainClass);
+ }
+
JarOutputStream jos
- = new JarOutputStream(new FileOutputStream(jar));
+ = new JarOutputStream(new FileOutputStream(jar), manifest);
+
addToJar(jos, base, null);
if (metaInfDir != null) {
File[] metaFileSet = buildFileSet(metaInfDir,
metaInfIncludes);
+
addFilesToJar(jos, new File(resolve(metaInfDir)),
metaFileSet, "META-INF");
}
@@ -142,34 +165,40 @@
}
}
+
/**
* Compile a set of files
*
* @param srcDir the source directory
* @param destDir where the compiled classes will go
- * @param classpathRef the id of a path object with the classpath for
- * the build
+ * @param classpathRef the id of a path object with the classpath for the
+ * build
*/
protected void javac(String srcDir, String destDir, String classpathRef)
{
List javaFiles = new ArrayList();
String src = resolve(srcDir);
StringTokenizer tokenizer = new StringTokenizer(src, ":");
+
while (tokenizer.hasMoreTokens()) {
File srcLocation = new File(tokenizer.nextToken());
+
getJavaFiles(srcLocation, javaFiles);
}
File dest = new File(resolve(destDir));
int numArgs = javaFiles.size() + 2;
+
if (classpathRef != null) {
numArgs += 2;
}
String[] args = new String[numArgs];
int index = 0;
+
args[index++] = "-d";
args[index++] = dest.getPath();
if (classpathRef != null) {
String path = (String) paths.get(resolve(classpathRef));
+
args[index++] = "-classpath";
args[index++] = path;
}
@@ -182,6 +211,7 @@
Object compiler = c.newInstance();
Method compile = c.getMethod("compile",
new Class[]{(new String[]{}).getClass()});
+
compile.invoke(compiler, new Object[]{args});
} catch (Exception e) {
e.printStackTrace();
@@ -189,6 +219,7 @@
}
}
+
/**
* Copy a directory
*
@@ -198,9 +229,11 @@
protected void copyFileset(String fromDir, String toDir) {
File from = new File(resolve(fromDir));
File to = new File(resolve(toDir));
+
copyDir(from, to);
}
+
/**
* Add a fileset to this build helper
*
@@ -210,11 +243,13 @@
*/
protected void addFileSet(String name, File root, File[] files) {
FileSetInfo info = new FileSetInfo();
+
info.root = root;
info.files = files;
filesets.put(name, info);
}
+
/**
* Copy a fileset given a reference to the source fileset
*
@@ -223,12 +258,15 @@
*/
protected void copyFilesetRef(String fileSetRef, String toDir) {
FileSetInfo fileset = (FileSetInfo)
filesets.get(resolve(fileSetRef));
+
if (fileset != null) {
File to = new File(resolve(toDir));
+
copyFileList(fileset.root, fileset.files, to);
}
}
+
/**
* Make a directory
*
@@ -236,9 +274,11 @@
*/
protected void mkdir(String dirName) {
File dir = new File(resolve(dirName));
+
dir.mkdirs();
}
+
/**
* Create a path object
*
@@ -246,9 +286,11 @@
*/
protected void createPath(String pathName) {
String path = "";
+
paths.put(pathName, path);
}
+
/**
* Add a fileset to a path
*
@@ -260,6 +302,7 @@
String filesetIncludes) {
File[] files = buildFileSet(filesetDir, filesetIncludes);
String currentPath = (String) paths.get(pathName);
+
for (int i = 0; i < files.length; ++i) {
if (currentPath == null || currentPath.length() == 0) {
currentPath = files[i].getPath();
@@ -271,6 +314,7 @@
paths.put(pathName, currentPath);
}
+
/**
* Add a new element to a path
*
@@ -280,6 +324,7 @@
protected void addPathElementToPath(String pathName, String location) {
String pathElement = resolve(location).replace('/',
File.separatorChar);
String currentPath = (String) paths.get(pathName);
+
if (currentPath == null || currentPath.length() == 0) {
currentPath = pathElement;
} else {
@@ -288,6 +333,7 @@
paths.put(pathName, currentPath);
}
+
/**
* Add an existing path to another path
*
@@ -296,11 +342,13 @@
*/
protected void addPathToPath(String pathName, String pathNameToAdd) {
String pathToAdd = (String) paths.get(pathNameToAdd);
+
if (pathToAdd == null || pathToAdd.length() == 0) {
return;
}
String currentPath = (String) paths.get(pathName);
+
if (currentPath == null || currentPath.length() == 0) {
currentPath = pathToAdd;
} else {
@@ -309,6 +357,7 @@
paths.put(pathName, currentPath);
}
+
/**
* Get the set of Java files to be compiled
*
@@ -317,6 +366,7 @@
*/
private void getJavaFiles(File srcDir, List javaFiles) {
File[] files = srcDir.listFiles();
+
for (int i = 0; i < files.length; ++i) {
if (files[i].isDirectory()) {
getJavaFiles(files[i], javaFiles);
@@ -326,6 +376,7 @@
}
}
+
/**
* Copy a file
*
@@ -340,6 +391,7 @@
FileOutputStream out = new FileOutputStream(dest);
byte[] buf = new byte[1024 * 16];
int count = 0;
+
count = in.read(buf, 0, buf.length);
while (count != -1) {
out.write(buf, 0, count);
@@ -355,6 +407,7 @@
}
}
+
/**
* Copy a list of files from one directory to another, preserving the
* relative paths
@@ -371,6 +424,7 @@
String name
= files[i].getPath().substring(root.getPath().length() + 1);
File dest = new File(to, name);
+
if (files[i].isDirectory()) {
copyDir(files[i], dest);
} else {
@@ -379,6 +433,7 @@
}
}
+
/**
* Copy a directory
*
@@ -387,10 +442,13 @@
*/
private void copyDir(File from, File to) {
to.mkdirs();
+
File[] files = from.listFiles();
+
copyFileList(from, files, to);
}
+
/**
* Add a directory to a Jar
*
@@ -403,9 +461,11 @@
private void addToJar(JarOutputStream jos, File dir, String prefix)
throws IOException {
File[] files = dir.listFiles();
+
addFilesToJar(jos, dir, files, prefix);
}
+
/**
* Add a set of files to a jar
*
@@ -420,11 +480,13 @@
File[] files, String prefix) throws
IOException {
for (int i = 0; i < files.length; i++) {
String name = files[i].getPath().replace('\\', '/');
+
name = name.substring(dir.getPath().length() + 1);
if (prefix != null) {
name = prefix + "/" + name;
}
ZipEntry ze = new ZipEntry(name);
+
jos.putNextEntry(ze);
if (files[i].isDirectory()) {
addToJar(jos, files[i], name);
@@ -432,6 +494,7 @@
FileInputStream fis = new FileInputStream(files[i]);
int count = 0;
byte[] buf = new byte[8 * 1024];
+
count = fis.read(buf, 0, buf.length);
while (count != -1) {
jos.write(buf, 0, count);
@@ -442,9 +505,10 @@
}
}
+
/**
- * Build a simple fileset. Only simple inclusion filtering is supported
- * - no complicated patterns.
+ * Build a simple fileset. Only simple inclusion filtering is supported -
+ * no complicated patterns.
*
* @param filesetDir the base directory of the fileset
* @param filesetIncludes the simple includes spec for the fileset
@@ -455,11 +519,13 @@
return new File[0];
}
final String includes = resolve(filesetIncludes);
+
if (includes.indexOf("**") != -1) {
throw new RuntimeException("Simple fileset cannot handle ** "
+ "style includes");
}
int index = 0;
+
if (includes.charAt(0) == '*') {
index = 1;
}
@@ -469,6 +535,7 @@
}
File base = new File(resolve(filesetDir));
+
return base.listFiles(
new FilenameFilter() {
public boolean accept(File dir, String name) {
@@ -481,6 +548,7 @@
});
}
+
/**
* Resolve the property references in a string
*
@@ -490,11 +558,13 @@
*/
private String resolve(String propertyValue) {
String newValue = propertyValue;
+
while (newValue.indexOf("${") != -1) {
int index = newValue.indexOf("${");
int endIndex = newValue.indexOf("}", index);
String propertyName = newValue.substring(index + 2, endIndex);
String repValue = (String) properties.get(propertyName);
+
newValue = newValue.substring(0, index) +
repValue + newValue.substring(endIndex + 1);
}
1.15 +3 -2
jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java
Index: Builder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/Builder.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -w -u -r1.14 -r1.15
--- Builder.java 11 Apr 2002 16:20:13 -0000 1.14
+++ Builder.java 16 Apr 2002 14:07:46 -0000 1.15
@@ -141,6 +141,7 @@
addJavaFiles(files, UTIL_ROOT);
addJavaFiles(files, new File(UTIL_ROOT, "depend"));
addJavaFiles(files, ZIP_ROOT);
+ addJavaFiles(files, new File(UTIL_ROOT, "facade"));
files.add(new File(PACKAGE_ROOT, "BuildException.java"));
files.add(new File(PACKAGE_ROOT, "Location.java"));
@@ -163,7 +164,7 @@
files.add(new File(UTIL_ROOT, "regexp/RegexpMatcherFactory.java"));
files.add(new File(FILTERS_ROOT, "util/ChainReaderHelper.java"));
- // these shouyld not be included
+ // these should not be included
files.remove(new File(TYPES_ROOT, "DataType.java"));
files.remove(new File(TASKDEFS_ROOT, "Ant.java"));
files.remove(new File(TASKDEFS_ROOT, "CallTarget.java"));
@@ -200,7 +201,7 @@
mutantBuilder.common(mainBuild);
mutantBuilder.antcore(mainBuild);
mutantBuilder.start(mainBuild);
- mutantBuilder.cli(mainBuild);
+ mutantBuilder.frontend(mainBuild);
BuildHelper systemBuild = new BuildHelper();
systemBuild.setProperty("libset", "system");
1.5 +17 -15
jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/MutantBuilder.java
Index: MutantBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/bootstrap/org/apache/ant/builder/MutantBuilder.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- MutantBuilder.java 3 Apr 2002 15:02:47 -0000 1.4
+++ MutantBuilder.java 16 Apr 2002 14:07:46 -0000 1.5
@@ -18,9 +18,9 @@
helper.addPathElementToPath("classpath.antcore",
"${distlib.dir}/common/common.jar");
helper.addPathToPath("classpath.antcore", "classpath.common");
helper.addPathToPath("classpath.antcore", "classpath.parser");
- helper.createPath("classpath.cli");
- helper.addPathElementToPath("classpath.cli",
"${distlib.dir}/antcore/antcore.jar");
- helper.addPathToPath("classpath.cli", "classpath.antcore");
+ helper.createPath("classpath.frontend");
+ helper.addPathElementToPath("classpath.frontend",
"${distlib.dir}/antcore/antcore.jar");
+ helper.addPathToPath("classpath.frontend", "classpath.antcore");
helper.createPath("classpath.start");
helper.addPathElementToPath("classpath.start",
"${distlib.dir}/init.jar");
}
@@ -33,36 +33,38 @@
helper.mkdir("${bin.dir}/init");
helper.javac("${java.dir}/init", "${bin.dir}/init", null);
helper.jar("${bin.dir}/init", "${distlib.dir}/init.jar",
- null, null);
+ null, null, null, null);
}
protected void common(BuildHelper helper) {
helper.mkdir("${bin.dir}/common");
helper.mkdir("${distlib.dir}/common");
helper.javac("${java.dir}/common", "${bin.dir}/common",
"classpath.common");
helper.jar("${bin.dir}/common", "${distlib.dir}/common/common.jar",
- null, null);
+ null, null, null, null);
}
protected void antcore(BuildHelper helper) {
helper.mkdir("${bin.dir}/antcore");
helper.mkdir("${distlib.dir}/antcore");
helper.javac("${java.dir}/antcore", "${bin.dir}/antcore",
"classpath.antcore");
helper.jar("${bin.dir}/antcore",
"${distlib.dir}/antcore/antcore.jar",
- null, null);
+ null, null, null, null);
}
- protected void cli(BuildHelper helper) {
- helper.mkdir("${bin.dir}/cli");
+ protected void frontend(BuildHelper helper) {
+ helper.mkdir("${bin.dir}/frontend");
helper.mkdir("${distlib.dir}/frontend");
- helper.javac("${java.dir}/cli", "${bin.dir}/cli", "classpath.cli");
- helper.jar("${bin.dir}/cli", "${distlib.dir}/frontend/cli.jar",
- null, null);
+ helper.javac("${java.dir}/frontend", "${bin.dir}/frontend",
"classpath.frontend");
+ helper.jar("${bin.dir}/frontend",
"${distlib.dir}/frontend/frontend.jar",
+ null, null, null, null);
+ helper.jar("${bin.dir}/frontend", "${distlib.dir}/frontend/cli.jar",
+ null, null, "frontend.jar",
"org.apache.ant.cli.Commandline");
}
protected void start(BuildHelper helper) {
helper.mkdir("${bin.dir}/start");
helper.javac("${java.dir}/start", "${bin.dir}/start",
"classpath.start");
helper.jar("${bin.dir}/start", "${distlib.dir}/start.jar",
- null, null);
+ null, null, "init.jar", "org.apache.ant.start.Main");
helper.jar("${bin.dir}/start", "${distlib.dir}/ant.jar",
- null, null);
+ null, null, "start.jar", "org.apache.tools.ant.Main");
}
protected void ant1compat(BuildHelper helper) {
}
@@ -70,7 +72,7 @@
helper.mkdir("${bin.dir}/remote");
helper.javac("${java.dir}/remote", "${bin.dir}/remote",
"classpath.start");
helper.jar("${bin.dir}/remote", "${distlib.dir}/remote.jar",
- null, null);
+ null, null, null, "org.apache.ant.remote.RemoteMain");
}
protected void clean(BuildHelper helper) {
}
@@ -84,7 +86,7 @@
helper.addPathToPath("classpath.antlibs", "classpath.common");
helper.javac("${java.dir}/antlibs/${libset}",
"${bin.dir}/antlibs/${libset}", "classpath.antlibs");
helper.jar("${bin.dir}/antlibs/${libset}",
"${distlib.dir}/antlibs/${libset}.jar",
- "${java.dir}/antlibs/${libset}", "antlib.xml");
+ "${java.dir}/antlibs/${libset}", "antlib.xml", null,
null);
}
protected void main(BuildHelper helper) {
}
1.1
jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/cli/BuildLogger.java
Index: BuildLogger.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.ant.cli;
import java.io.PrintStream;
import org.apache.ant.common.event.BuildListener;
/**
* Interface used by Ant to log the build output. A build logger is a build
* listener which has the 'right' to send output to the ant log, which is
* usually System.out unles redirected by the -logfile option.
*
* @author Conor MacNeill
* @created 15 January 2002
*/
public interface BuildLogger extends BuildListener {
/**
* Set the msgOutputLevel this logger is to respond to. Only messages
* with a message level lower than or equal to the given level are
* output to the log.
*
* @param level the logging level for the logger.
*/
public void setMessageOutputLevel(int level);
/**
* Set the output stream to which this logger is to send its output.
*
* @param output the output stream for the logger.
*/
public void setOutputPrintStream(PrintStream output);
/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
public void setErrorPrintStream(PrintStream err);
}
1.1
jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/cli/Commandline.java
Index: Commandline.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.ant.cli;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.ant.antcore.config.AntConfig;
import org.apache.ant.antcore.config.AntConfigHandler;
import org.apache.ant.antcore.execution.ExecutionManager;
import org.apache.ant.antcore.modelparser.XMLProjectParser;
import org.apache.ant.antcore.xml.ParseContext;
import org.apache.ant.antcore.xml.XMLParseException;
import org.apache.ant.common.event.BuildEvent;
import org.apache.ant.common.event.BuildListener;
import org.apache.ant.common.event.MessageLevel;
import org.apache.ant.common.model.Project;
import org.apache.ant.common.util.ConfigException;
import org.apache.ant.common.util.DemuxOutputStream;
import org.apache.ant.init.InitConfig;
import org.apache.ant.init.InitUtils;
import org.apache.ant.frontend.FrontendUtils;
/**
* This is the command line front end. It drives the core.
*
* @author Conor MacNeill
* @created 9 January 2002
*/
public class Commandline {
/** The initialisation configuration for Ant */
private InitConfig initConfig;
/** Stream that we are using for logging */
private PrintStream out = System.out;
/** Stream that we are using for logging error messages */
private PrintStream err = System.err;
/** Names of classes to add as listeners to project */
private List listeners = new ArrayList(2);
/** The list of targets to be evaluated in this invocation */
private List targets = new ArrayList(4);
/** The command line properties */
private Map definedProperties = new HashMap();
/** The Config files to use in this run */
private List configFiles = new ArrayList();
/**
* This is the build file to run. By default it is a file: type URL but
* other URL protocols can be used.
*/
private URL buildFileURL;
/**
* The Ant logger class. There may be only one logger. It will have the
* right to use the 'out' PrintStream. The class must implements the
* BuildLogger interface
*/
private String loggerClassname = null;
/** Our current message output status. Follows MessageLevel values */
private int messageOutputLevel = MessageLevel.MSG_INFO;
/** The logger that will be used for the build */
private BuildLogger logger = null;
/**
* Start the command line front end for mutant.
*
* @param args the commandline arguments
* @param config the initialisation configuration
*/
public static void start(String[] args, InitConfig config) {
// create a command line and use it to run ant
Commandline commandline = new Commandline();
commandline.process(args, config);
}
/**
* Adds a feature to the BuildListeners attribute of the Commandline
* object
*
* @param execManager The feature to be added to the BuildListeners
* attribute
* @exception ConfigException if the necessary listener instances could
* not be created
*/
protected void addBuildListeners(ExecutionManager execManager)
throws ConfigException {
// Add the default listener
execManager.addBuildListener(logger);
for (Iterator i = listeners.iterator(); i.hasNext();) {
String className = (String) i.next();
try {
BuildListener listener =
(BuildListener) Class.forName(className).newInstance();
execManager.addBuildListener(listener);
} catch (ClassCastException e) {
System.err.println("The specified listener class "
+ className +
" does not implement the Listener interface");
throw new ConfigException("Unable to instantiate listener "
+ className, e);
} catch (Exception e) {
System.err.println("Unable to instantiate specified listener "
+ "class " + className + " : "
+ e.getClass().getName());
throw new ConfigException("Unable to instantiate listener "
+ className, e);
}
}
}
/**
* Get an option value
*
* @param args the full list of command line arguments
* @param position the position in the args array where the value shoudl
* be
* @param argType the option type
* @return the value of the option
* @exception ConfigException if the option cannot be read
*/
private String getOption(String[] args, int position, String argType)
throws ConfigException {
String value = null;
try {
value = args[position];
} catch (IndexOutOfBoundsException e) {
throw new ConfigException("You must specify a value for the "
+ argType + " argument");
}
return value;
}
/**
* Start the command line front end for mutant.
*
* @param args the commandline arguments
* @param initConfig Ant's initialization configuration
*/
private void process(String[] args, InitConfig initConfig) {
this.initConfig = initConfig;
ExecutionManager executionManager = null;
Project project = null;
try {
parseArguments(args);
createLogger();
determineBuildFile();
AntConfig config = new AntConfig();
AntConfig userConfig =
FrontendUtils.getAntConfig(initConfig.getUserConfigArea());
AntConfig systemConfig
=
FrontendUtils.getAntConfig(initConfig.getSystemConfigArea());
if (systemConfig != null) {
config.merge(systemConfig);
}
if (userConfig != null) {
config.merge(userConfig);
}
for (Iterator i = configFiles.iterator(); i.hasNext();) {
File configFile = (File) i.next();
AntConfig runConfig
= FrontendUtils.getAntConfigFile(configFile);
config.merge(runConfig);
}
if (!buildFileURL.getProtocol().equals("file")
&& !config.isRemoteProjectAllowed()) {
throw new ConfigException("Remote Projects are not allowed: "
+ buildFileURL);
}
project = parseProject();
// create the execution manager to execute the build
executionManager = new ExecutionManager(initConfig, config);
OutputStream demuxOut
= new DemuxOutputStream(executionManager, false);
OutputStream demuxErr
= new DemuxOutputStream(executionManager, true);
System.setOut(new PrintStream(demuxOut));
System.setErr(new PrintStream(demuxErr));
addBuildListeners(executionManager);
} catch (Throwable e) {
if (logger != null) {
BuildEvent finishedEvent
= new BuildEvent(this, BuildEvent.BUILD_FINISHED, e);
logger.buildFinished(finishedEvent);
} else {
e.printStackTrace();
}
System.exit(1);
}
try {
executionManager.runBuild(project, targets, definedProperties);
System.exit(0);
} catch (Throwable t) {
System.exit(1);
}
}
/**
* Use the XML parser to parse the build file into a project model
*
* @return a project model representation of the project file
* @exception XMLParseException if the project cannot be parsed
*/
private Project parseProject()
throws XMLParseException {
XMLProjectParser parser = new XMLProjectParser();
Project project = parser.parseBuildFile(buildFileURL);
return project;
}
/**
* Handle build file argument
*
* @param url the build file's URL
* @exception ConfigException if the build file location is not valid
*/
private void argBuildFile(String url) throws ConfigException {
try {
if (url.indexOf(":") == -1) {
// We convert any hash characters to their URL escape.
buildFileURL = InitUtils.getFileURL(new File(url));
} else {
buildFileURL = new URL(url);
}
} catch (MalformedURLException e) {
throw new ConfigException("Build file is not valid", e);
}
}
/**
* Handle the log file option
*
* @param arg the value of the log file option
* @exception ConfigException if the log file is not writeable
*/
private void argLogFile(String arg) throws ConfigException {
try {
File logFile = new File(arg);
out = new PrintStream(new FileOutputStream(logFile));
err = out;
} catch (IOException ioe) {
throw new ConfigException("Cannot write on the specified log " +
"file. Make sure the path exists and " +
"you have write permissions.", ioe);
}
}
/**
* Handle the logger attribute
*
* @param arg the logger classname
* @exception ConfigException if a logger has already been defined
*/
private void argLogger(String arg) throws ConfigException {
if (loggerClassname != null) {
throw new ConfigException("Only one logger class may be " +
"specified.");
}
loggerClassname = arg;
}
/**
* Determine the build file to use
*
* @exception ConfigException if the build file cannot be found
*/
private void determineBuildFile() throws ConfigException {
if (buildFileURL == null) {
File defaultBuildFile
= new File(FrontendUtils.DEFAULT_BUILD_FILENAME);
if (!defaultBuildFile.exists()) {
File ant1BuildFile
= new File(FrontendUtils.DEFAULT_ANT1_FILENAME);
if (ant1BuildFile.exists()) {
defaultBuildFile = ant1BuildFile;
}
}
try {
buildFileURL = InitUtils.getFileURL(defaultBuildFile);
} catch (MalformedURLException e) {
throw new ConfigException("Build file is not valid", e);
}
}
}
/**
* Parse the command line arguments.
*
* @param args the command line arguments
* @exception ConfigException thrown when the command line contains some
* sort of error.
*/
private void parseArguments(String[] args)
throws ConfigException {
int i = 0;
while (i < args.length) {
String arg = args[i++];
if (arg.equals("-buildfile") || arg.equals("-file")
|| arg.equals("-f")) {
argBuildFile(getOption(args, i++, arg));
} else if (arg.equals("-logfile") || arg.equals("-l")) {
argLogFile(getOption(args, i++, arg));
} else if (arg.equals("-quiet") || arg.equals("-q")) {
messageOutputLevel = MessageLevel.MSG_WARN;
} else if (arg.equals("-verbose") || arg.equals("-v")) {
// printVersion();
messageOutputLevel = MessageLevel.MSG_VERBOSE;
} else if (arg.equals("-debug")) {
// printVersion();
messageOutputLevel = MessageLevel.MSG_DEBUG;
} else if (arg.equals("-config") || arg.equals("-c")) {
configFiles.add(new File(getOption(args, i++, arg)));
} else if (arg.equals("-listener")) {
listeners.add(getOption(args, i++, arg));
} else if (arg.equals("-logger")) {
argLogger(getOption(args, i++, arg));
} else if (arg.startsWith("-D")) {
String name = arg.substring(2, arg.length());
String value = null;
int posEq = name.indexOf("=");
if (posEq > 0) {
value = name.substring(posEq + 1);
name = name.substring(0, posEq);
} else {
value = getOption(args, i++, arg);
}
definedProperties.put(name, value);
} else if (arg.startsWith("-")) {
// we don't have any more args to recognize!
System.out.println("Unknown option: " + arg);
return;
} else {
// if it's no other arg, it must be a target
targets.add(arg);
}
}
}
/**
* Creates the default build logger for sending build events to the ant
* log.
*
* @exception ConfigException if the logger cannot be instantiatd
*/
private void createLogger() throws ConfigException {
if (loggerClassname != null) {
try {
Class loggerClass = Class.forName(loggerClassname);
logger = (BuildLogger) loggerClass.newInstance();
} catch (ClassCastException e) {
System.err.println("The specified logger class "
+ loggerClassname +
" does not implement the BuildLogger interface");
throw new ConfigException("Unable to instantiate logger "
+ loggerClassname, e);
} catch (Exception e) {
System.err.println("Unable to instantiate specified logger "
+ "class " + loggerClassname + " : "
+ e.getClass().getName());
throw new ConfigException("Unable to instantiate logger "
+ loggerClassname, e);
}
} else {
logger = new DefaultLogger();
}
logger.setMessageOutputLevel(messageOutputLevel);
logger.setOutputPrintStream(out);
logger.setErrorPrintStream(err);
}
}
1.1
jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/cli/DefaultLogger.java
Index: DefaultLogger.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.ant.cli;
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.MessageLevel;
import org.apache.ant.common.model.Target;
import org.apache.ant.common.util.AntException;
import org.apache.ant.common.util.Location;
/**
* Writes build event to a PrintStream. Currently, it only writes which
* targets are being executed, and any messages that get logged.
*
* @author Conor MacNeill
* @created 15 January 2002
*/
public class DefaultLogger implements BuildLogger {
/** Standard field separator */
private static String lSep = System.getProperty("line.separator");
/** spacing to allow for task tags */
private static final int LEFT_COLUMN_SIZE = 12;
/** The stream where output should be written */
private PrintStream out;
/** The stream to where errors should be written */
private PrintStream err;
/** The level of messages which should be let through */
private int messageOutputLevel = MessageLevel.MSG_ERR;
/** Controls whether adornments are added */
private boolean emacsMode = false;
/** The time at which the build started */
private long startTime = System.currentTimeMillis();
/**
* Format the time into something readable
*
* @param millis Java millis value
* @return the formatted time
*/
protected static String formatTime(long millis) {
long seconds = millis / 1000;
long minutes = seconds / 60;
if (minutes > 0) {
return Long.toString(minutes) + " minute"
+ (minutes == 1 ? " " : "s ")
+ Long.toString(seconds % 60) + " second"
+ (seconds % 60 == 1 ? "" : "s");
} else {
return Long.toString(seconds) + " second"
+ (seconds % 60 == 1 ? "" : "s");
}
}
/**
* Set the messageOutputLevel this logger is to respond to. Only
* messages with a message level lower than or equal to the given level
* are output to the log. <P>
*
* Constants for the message levels are in Project.java. The order of
* the levels, from least to most verbose, is MSG_ERR, MSG_WARN,
* MSG_INFO, MSG_VERBOSE, MSG_DEBUG. The default message level for
* DefaultLogger is Project.MSG_ERR.
*
* @param level the logging level for the logger.
*/
public void setMessageOutputLevel(int level) {
this.messageOutputLevel = level;
}
/**
* Set the output stream to which this logger is to send its output.
*
* @param output the output stream for the logger.
*/
public void setOutputPrintStream(PrintStream output) {
this.out = output;
}
/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
public void setErrorPrintStream(PrintStream err) {
this.err = err;
}
/**
* Set this logger to produce emacs (and other editor) friendly output.
*
* @param emacsMode true if output is to be unadorned so that emacs and
* other editors can parse files names, etc.
*/
public void setEmacsMode(boolean emacsMode) {
this.emacsMode = emacsMode;
}
/**
* Report an exception
*
* @param t The exception to be reported.
*/
public void reportException(Throwable t) {
if (t instanceof AntException) {
AntException e = (AntException) t;
Location location = e.getLocation();
Throwable cause = e.getCause();
if (location != null && location != Location.UNKNOWN_LOCATION) {
out.print(location);
}
out.println(e.getMessage());
if (messageOutputLevel >= MessageLevel.MSG_VERBOSE) {
t.printStackTrace(out);
}
if (!cause.getMessage().equals(t.getMessage())) {
out.println("Root cause: " + cause.toString());
}
} else {
t.printStackTrace(err);
}
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void buildStarted(BuildEvent event) {
startTime = System.currentTimeMillis();
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void buildFinished(BuildEvent event) {
Throwable cause = event.getCause();
if (cause == null) {
out.println(lSep + "BUILD SUCCESSFUL");
} else {
err.println(lSep + "BUILD FAILED" + lSep);
reportException(cause);
}
out.println(lSep + "Total time: "
+ formatTime(System.currentTimeMillis() - startTime));
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void targetStarted(BuildEvent event) {
if (MessageLevel.MSG_INFO <= messageOutputLevel) {
Target target = (Target) event.getSource();
out.println(lSep + target.getName() + ":");
}
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void targetFinished(BuildEvent event) {
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void taskStarted(BuildEvent event) {
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void taskFinished(BuildEvent event) {
}
/**
* Description of the Method
*
* @param event Description of Parameter
*/
public void messageLogged(BuildEvent event) {
PrintStream logTo
= event.getPriority() == MessageLevel.MSG_ERR ? err : out;
// Filter out messages based on priority
if (event.getPriority() <= messageOutputLevel) {
String name = null;
Object source = event.getSource();
if (source instanceof Task) {
name = ((Task) source).getTaskName();
}
if (name == null && source instanceof ExecutionComponent) {
name = ((ExecutionComponent) source).getComponentType();
}
if (name != null) {
// Print out the name of the task if we're in one
if (!emacsMode) {
String tag = "[" + name + "] ";
int indentSize = LEFT_COLUMN_SIZE - tag.length();
for (int i = 0; i < indentSize; i++) {
logTo.print(" ");
}
logTo.print(tag);
}
}
// Print the message
logTo.println(event.getMessage());
}
}
}
1.1
jakarta-ant/proposal/mutant/src/java/frontend/org/apache/ant/frontend/FrontendUtils.java
Index: FrontendUtils.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.ant.frontend;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.ant.antcore.config.AntConfig;
import org.apache.ant.antcore.config.AntConfigHandler;
import org.apache.ant.antcore.xml.ParseContext;
import org.apache.ant.antcore.xml.XMLParseException;
import org.apache.ant.common.util.ConfigException;
import org.apache.ant.init.InitUtils;
/**
* Frontend Utilities methods and constants.
*
* @author Conor MacNeill
* @created 16 April 2002
*/
public class FrontendUtils {
/** The default build file name */
public static final String DEFAULT_BUILD_FILENAME = "build.ant";
/** The default build file name */
public static final String DEFAULT_ANT1_FILENAME = "build.xml";
/**
* Get the AntConfig from the given config area if it is available
*
* @param configArea the config area from which the config may be read
* @return the AntConfig instance representing the config info read in
* from the config area. May be null if the AntConfig is not present
* @exception ConfigException if the URL for the config file cannotbe
* formed.
*/
public static AntConfig getAntConfig(File configArea)
throws ConfigException {
File configFile = new File(configArea, "antconfig.xml");
try {
return getAntConfigFile(configFile);
} catch (FileNotFoundException e) {
// ignore if files are not present
return null;
}
}
/**
* Read in a config file
*
* @param configFile the file containing the XML config
* @return the parsed config object
* @exception ConfigException if the config cannot be parsed
* @exception FileNotFoundException if the file cannot be found.
*/
public static AntConfig getAntConfigFile(File configFile)
throws ConfigException, FileNotFoundException {
try {
URL configFileURL = InitUtils.getFileURL(configFile);
ParseContext context = new ParseContext();
AntConfigHandler configHandler = new AntConfigHandler();
context.parse(configFileURL, "antconfig", configHandler);
return configHandler.getAntConfig();
} catch (MalformedURLException e) {
throw new ConfigException("Unable to form URL to read config from
"
+ configFile, e);
} catch (XMLParseException e) {
if (e.getCause() instanceof FileNotFoundException) {
throw (FileNotFoundException) e.getCause();
}
throw new ConfigException("Unable to parse config file from "
+ configFile, e);
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>