You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@locus.apache.org on 2000/01/24 01:15:08 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Ant.java
stefano 00/01/23 16:15:08
Modified: src/main/org/apache/tools/ant Main.java Project.java
src/main/org/apache/tools/ant/taskdefs Ant.java
Log:
Added the ability to dump everything to a file.
Revision Changes Path
1.3 +26 -3 jakarta-ant/src/main/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Main.java 2000/01/23 11:38:22 1.2
+++ Main.java 2000/01/24 00:15:07 1.3
@@ -78,6 +78,9 @@
/** File that we are using for configuration */
private static File buildFile = new File("build.xml");
+ /** Stream that we are using for logging */
+ private static PrintStream out = System.out;
+
/** The build targets */
private static Vector targets = new Vector(5);
@@ -106,7 +109,25 @@
msgOutputLevel = Project.MSG_WARN;
} else if (arg.equals("-verbose") || arg.equals("-v") || arg.equals("v")) {
msgOutputLevel = Project.MSG_VERBOSE;
- } else if (arg.equals("-buildfile") || arg.equals("-file") || arg.equals("-f")) {
+ } else if (arg.equals("-logfile") || arg.equals("-l") || arg.equals("l")) {
+ try {
+ File logFile = new File(args[i+1]);
+ i++;
+ out = new PrintStream(new FileOutputStream(logFile));
+ System.setOut(out);
+ System.setErr(out);
+ } catch (IOException ioe) {
+ String msg = "Cannot write on the specified log file. " +
+ "Make sure the path exists and you have write permissions.";
+ System.out.println(msg);
+ return;
+ } catch (ArrayIndexOutOfBoundsException aioobe) {
+ String msg = "You must specify a log file when " +
+ "using the -log argument";
+ System.out.println(msg);
+ return;
+ }
+ } else if (arg.equals("-buildfile") || arg.equals("-file") || arg.equals("-f") || arg.equals("f")) {
try {
buildFile = new File(args[i+1]);
i++;
@@ -157,6 +178,8 @@
// ok, so if we've made it here, let's run the damn build allready
runBuild();
+
+ return;
}
/**
@@ -172,8 +195,7 @@
System.out.println("Buildfile: " + buildFile);
}
- Project project = new Project();
- project.setOutputLevel(msgOutputLevel);
+ Project project = new Project(out, msgOutputLevel);
// set user-define properties
Enumeration e = definedProps.keys();
@@ -234,6 +256,7 @@
msg.append(" -help print this message" + lSep);
msg.append(" -quiet be extra quiet" + lSep);
msg.append(" -verbose be extra verbose" + lSep);
+ msg.append(" -logfile <file> use given file for log" + lSep);
msg.append(" -buildfile <file> use given buildfile" + lSep);
msg.append(" -D<property>=<value> use value for given property" + lSep);
System.out.println(msg.toString());
1.3 +26 -22 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Project.java 2000/01/23 11:38:22 1.2
+++ Project.java 2000/01/24 00:15:08 1.3
@@ -83,14 +83,14 @@
private static final String VISITED = "VISITED";
private static String javaVersion;
-
+
public static final String JAVA_1_0 = "1.0";
public static final String JAVA_1_1 = "1.1";
public static final String JAVA_1_2 = "1.2";
public static final String JAVA_1_3 = "1.3";
private String name;
- private PrintStream out = System.out;
+ private PrintStream out;
private int msgOutputLevel = MSG_INFO;
private Hashtable properties = new Hashtable();
@@ -99,10 +99,16 @@
private Hashtable taskClassDefinitions = new Hashtable();
private Hashtable targets = new Hashtable();
private File baseDir;
+
+ public Project(PrintStream out, int msgOutputLevel) {
- public Project() {
+ this.out = out;
+ this.msgOutputLevel = msgOutputLevel;
+
detectJavaVersion();
+
String defs = "/org/apache/tools/ant/taskdefs/defaults.properties";
+
try {
Properties props = new Properties();
InputStream in = this.getClass().getResourceAsStream(defs);
@@ -120,11 +126,11 @@
}
}
- Properties systemP=System.getProperties();
+ Properties systemP = System.getProperties();
Enumeration e=systemP.keys();
- while( e.hasMoreElements() ) {
+ while (e.hasMoreElements()) {
String n=(String) e.nextElement();
- properties.put( n, systemP.get(n));
+ properties.put(n, systemP.get(n));
}
} catch (IOException ioe) {
String msg = "Can't load default task list";
@@ -133,18 +139,14 @@
}
}
- public void setOutput(PrintStream out) {
- this.out = out;
+ public PrintStream getOutput() {
+ return this.out;
}
-
- public void setOutputLevel(int msgOutputLevel) {
- this.msgOutputLevel = msgOutputLevel;
- }
public int getOutputLevel() {
return this.msgOutputLevel;
}
-
+
public void log(String msg) {
log(msg, MSG_INFO);
}
@@ -157,13 +159,13 @@
public void log(String msg, String tag, int msgLevel) {
if (msgLevel <= msgOutputLevel) {
- out.println("[" + tag + "]" + msg);
+ out.println("[" + tag + "] " + msg);
}
}
public void setProperty(String name, String value) {
// command line properties take precedence
- if( null!= userProperties.get(name))
+ if (null != userProperties.get(name))
return;
log("Setting project property: " + name + " to " +
value, MSG_VERBOSE);
@@ -178,7 +180,7 @@
}
public String getProperty(String name) {
- String property = (String)properties.get(name);
+ String property = (String) properties.get(name);
return property;
}
@@ -209,9 +211,9 @@
}
// match basedir attribute in xml
- public void setBasedir( String baseD ) throws BuildException {
+ public void setBasedir(String baseD) throws BuildException {
try {
- setBaseDir(new File( new File(baseD).getCanonicalPath()));
+ setBaseDir(new File(new File(baseD).getCanonicalPath()));
} catch (IOException ioe) {
String msg = "Can't set basedir " + baseDir + " due to " +
ioe.getMessage();
@@ -226,10 +228,12 @@
}
public File getBaseDir() {
- if(baseDir==null) {
+ if (baseDir == null) {
try {
setBasedir(".");
- } catch(BuildException ex) {ex.printStackTrace();}
+ } catch (BuildException ex) {
+ ex.printStackTrace();
+ }
}
return baseDir;
}
@@ -259,12 +263,12 @@
// swallow as we've hit the max class version that
// we have
}
-
+
// sanity check
if (javaVersion == JAVA_1_0) {
throw new BuildException("Ant cannot work on Java 1.0");
}
-
+
log("Detected Java Version: " + javaVersion);
}
1.2 +24 -28 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
Index: Ant.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Ant.java 2000/01/13 10:41:41 1.1
+++ Ant.java 2000/01/24 00:15:08 1.2
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * 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
@@ -17,15 +17,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * 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", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,7 +59,7 @@
import java.util.*;
/**
- * Call Ant in a sub-project
+ * Call Ant in a sub-project
*
* @author costin@dnt.ro
*/
@@ -68,36 +68,34 @@
private String dir = null;
private String antFile = null;
private String target = null;
-
+
/**
* Do the execution.
*/
public void execute() throws BuildException {
- Project p1=new Project();
- p1.setOutputLevel( project.getOutputLevel() );
-
- // set user-define properties
- Hashtable prop1=project.getProperties();
+ Project p1 = new Project(project.getOutput(), project.getOutputLevel());
+
+ // set user-define properties
+ Hashtable prop1 = project.getProperties();
Enumeration e = prop1.keys();
while (e.hasMoreElements()) {
- String arg = (String)e.nextElement();
- String value = (String)prop1.get(arg);
+ String arg = (String) e.nextElement();
+ String value = (String) prop1.get(arg);
p1.setUserProperty(arg, value);
+ }
+
+ p1.setBasedir(dir);
+ p1.setUserProperty("basedir" , dir);
+ if (antFile == null) antFile = dir + "/build.xml";
+ ProjectHelper.configureProject(p1, new File(antFile));
+
+ if (target == null) {
+ target = p1.getDefaultTarget();
}
-
- p1.setBasedir( dir );
- p1.setUserProperty( "basedir" , dir);
- if(antFile==null) antFile= dir + "/build.xml";
- ProjectHelper.configureProject(p1, new File(antFile));
-
- if (target == null) {
- target = p1.getDefaultTarget();
- }
- p1.executeTarget( target );
-
+ p1.executeTarget(target);
}
-
+
public void setDir(String d) {
this.dir = d;
}
@@ -109,6 +107,4 @@
public void setTarget(String s) {
this.target = s;
}
-
-
}