git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267559 13f79535-47bb-0310-9956-ffa450edef68master
@@ -78,6 +78,9 @@ public class Main { | |||||
/** File that we are using for configuration */ | /** File that we are using for configuration */ | ||||
private static File buildFile = new File("build.xml"); | private static File buildFile = new File("build.xml"); | ||||
/** Stream that we are using for logging */ | |||||
private static PrintStream out = System.out; | |||||
/** The build targets */ | /** The build targets */ | ||||
private static Vector targets = new Vector(5); | private static Vector targets = new Vector(5); | ||||
@@ -106,7 +109,25 @@ public class Main { | |||||
msgOutputLevel = Project.MSG_WARN; | msgOutputLevel = Project.MSG_WARN; | ||||
} else if (arg.equals("-verbose") || arg.equals("-v") || arg.equals("v")) { | } else if (arg.equals("-verbose") || arg.equals("-v") || arg.equals("v")) { | ||||
msgOutputLevel = Project.MSG_VERBOSE; | 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 { | try { | ||||
buildFile = new File(args[i+1]); | buildFile = new File(args[i+1]); | ||||
i++; | i++; | ||||
@@ -157,6 +178,8 @@ public class Main { | |||||
// ok, so if we've made it here, let's run the damn build allready | // ok, so if we've made it here, let's run the damn build allready | ||||
runBuild(); | runBuild(); | ||||
return; | |||||
} | } | ||||
/** | /** | ||||
@@ -172,8 +195,7 @@ public class Main { | |||||
System.out.println("Buildfile: " + buildFile); | System.out.println("Buildfile: " + buildFile); | ||||
} | } | ||||
Project project = new Project(); | |||||
project.setOutputLevel(msgOutputLevel); | |||||
Project project = new Project(out, msgOutputLevel); | |||||
// set user-define properties | // set user-define properties | ||||
Enumeration e = definedProps.keys(); | Enumeration e = definedProps.keys(); | ||||
@@ -234,6 +256,7 @@ public class Main { | |||||
msg.append(" -help print this message" + lSep); | msg.append(" -help print this message" + lSep); | ||||
msg.append(" -quiet be extra quiet" + lSep); | msg.append(" -quiet be extra quiet" + lSep); | ||||
msg.append(" -verbose be extra verbose" + 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(" -buildfile <file> use given buildfile" + lSep); | ||||
msg.append(" -D<property>=<value> use value for given property" + lSep); | msg.append(" -D<property>=<value> use value for given property" + lSep); | ||||
System.out.println(msg.toString()); | System.out.println(msg.toString()); | ||||
@@ -83,14 +83,14 @@ public class Project { | |||||
private static final String VISITED = "VISITED"; | private static final String VISITED = "VISITED"; | ||||
private static String javaVersion; | private static String javaVersion; | ||||
public static final String JAVA_1_0 = "1.0"; | public static final String JAVA_1_0 = "1.0"; | ||||
public static final String JAVA_1_1 = "1.1"; | public static final String JAVA_1_1 = "1.1"; | ||||
public static final String JAVA_1_2 = "1.2"; | public static final String JAVA_1_2 = "1.2"; | ||||
public static final String JAVA_1_3 = "1.3"; | public static final String JAVA_1_3 = "1.3"; | ||||
private String name; | private String name; | ||||
private PrintStream out = System.out; | |||||
private PrintStream out; | |||||
private int msgOutputLevel = MSG_INFO; | private int msgOutputLevel = MSG_INFO; | ||||
private Hashtable properties = new Hashtable(); | private Hashtable properties = new Hashtable(); | ||||
@@ -100,9 +100,15 @@ public class Project { | |||||
private Hashtable targets = new Hashtable(); | private Hashtable targets = new Hashtable(); | ||||
private File baseDir; | private File baseDir; | ||||
public Project() { | |||||
public Project(PrintStream out, int msgOutputLevel) { | |||||
this.out = out; | |||||
this.msgOutputLevel = msgOutputLevel; | |||||
detectJavaVersion(); | detectJavaVersion(); | ||||
String defs = "/org/apache/tools/ant/taskdefs/defaults.properties"; | String defs = "/org/apache/tools/ant/taskdefs/defaults.properties"; | ||||
try { | try { | ||||
Properties props = new Properties(); | Properties props = new Properties(); | ||||
InputStream in = this.getClass().getResourceAsStream(defs); | InputStream in = this.getClass().getResourceAsStream(defs); | ||||
@@ -120,11 +126,11 @@ public class Project { | |||||
} | } | ||||
} | } | ||||
Properties systemP=System.getProperties(); | |||||
Properties systemP = System.getProperties(); | |||||
Enumeration e=systemP.keys(); | Enumeration e=systemP.keys(); | ||||
while( e.hasMoreElements() ) { | |||||
while (e.hasMoreElements()) { | |||||
String n=(String) e.nextElement(); | String n=(String) e.nextElement(); | ||||
properties.put( n, systemP.get(n)); | |||||
properties.put(n, systemP.get(n)); | |||||
} | } | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
String msg = "Can't load default task list"; | String msg = "Can't load default task list"; | ||||
@@ -133,18 +139,14 @@ public class Project { | |||||
} | } | ||||
} | } | ||||
public void setOutput(PrintStream out) { | |||||
this.out = out; | |||||
} | |||||
public void setOutputLevel(int msgOutputLevel) { | |||||
this.msgOutputLevel = msgOutputLevel; | |||||
public PrintStream getOutput() { | |||||
return this.out; | |||||
} | } | ||||
public int getOutputLevel() { | public int getOutputLevel() { | ||||
return this.msgOutputLevel; | return this.msgOutputLevel; | ||||
} | } | ||||
public void log(String msg) { | public void log(String msg) { | ||||
log(msg, MSG_INFO); | log(msg, MSG_INFO); | ||||
} | } | ||||
@@ -157,13 +159,13 @@ public class Project { | |||||
public void log(String msg, String tag, int msgLevel) { | public void log(String msg, String tag, int msgLevel) { | ||||
if (msgLevel <= msgOutputLevel) { | if (msgLevel <= msgOutputLevel) { | ||||
out.println("[" + tag + "]" + msg); | |||||
out.println("[" + tag + "] " + msg); | |||||
} | } | ||||
} | } | ||||
public void setProperty(String name, String value) { | public void setProperty(String name, String value) { | ||||
// command line properties take precedence | // command line properties take precedence | ||||
if( null!= userProperties.get(name)) | |||||
if (null != userProperties.get(name)) | |||||
return; | return; | ||||
log("Setting project property: " + name + " to " + | log("Setting project property: " + name + " to " + | ||||
value, MSG_VERBOSE); | value, MSG_VERBOSE); | ||||
@@ -178,7 +180,7 @@ public class Project { | |||||
} | } | ||||
public String getProperty(String name) { | public String getProperty(String name) { | ||||
String property = (String)properties.get(name); | |||||
String property = (String) properties.get(name); | |||||
return property; | return property; | ||||
} | } | ||||
@@ -209,9 +211,9 @@ public class Project { | |||||
} | } | ||||
// match basedir attribute in xml | // match basedir attribute in xml | ||||
public void setBasedir( String baseD ) throws BuildException { | |||||
public void setBasedir(String baseD) throws BuildException { | |||||
try { | try { | ||||
setBaseDir(new File( new File(baseD).getCanonicalPath())); | |||||
setBaseDir(new File(new File(baseD).getCanonicalPath())); | |||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
String msg = "Can't set basedir " + baseDir + " due to " + | String msg = "Can't set basedir " + baseDir + " due to " + | ||||
ioe.getMessage(); | ioe.getMessage(); | ||||
@@ -226,10 +228,12 @@ public class Project { | |||||
} | } | ||||
public File getBaseDir() { | public File getBaseDir() { | ||||
if(baseDir==null) { | |||||
if (baseDir == null) { | |||||
try { | try { | ||||
setBasedir("."); | setBasedir("."); | ||||
} catch(BuildException ex) {ex.printStackTrace();} | |||||
} catch (BuildException ex) { | |||||
ex.printStackTrace(); | |||||
} | |||||
} | } | ||||
return baseDir; | return baseDir; | ||||
} | } | ||||
@@ -259,12 +263,12 @@ public class Project { | |||||
// swallow as we've hit the max class version that | // swallow as we've hit the max class version that | ||||
// we have | // we have | ||||
} | } | ||||
// sanity check | // sanity check | ||||
if (javaVersion == JAVA_1_0) { | if (javaVersion == JAVA_1_0) { | ||||
throw new BuildException("Ant cannot work on Java 1.0"); | throw new BuildException("Ant cannot work on Java 1.0"); | ||||
} | } | ||||
log("Detected Java Version: " + javaVersion); | log("Detected Java Version: " + javaVersion); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -9,7 +9,7 @@ | |||||
* are met: | * are met: | ||||
* | * | ||||
* 1. Redistributions of source code must retain the above copyright | * 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 | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in | * notice, this list of conditions and the following disclaimer in | ||||
@@ -17,15 +17,15 @@ | |||||
* distribution. | * distribution. | ||||
* | * | ||||
* 3. The end-user documentation included with the redistribution, if | * 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/)." | * Apache Software Foundation (http://www.apache.org/)." | ||||
* Alternately, this acknowlegement may appear in the software itself, | * Alternately, this acknowlegement may appear in the software itself, | ||||
* if and wherever such third-party acknowlegements normally appear. | * if and wherever such third-party acknowlegements normally appear. | ||||
* | * | ||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | ||||
* Foundation" must not be used to endorse or promote products derived | * 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. | * permission, please contact apache@apache.org. | ||||
* | * | ||||
* 5. Products derived from this software may not be called "Apache" | * 5. Products derived from this software may not be called "Apache" | ||||
@@ -59,7 +59,7 @@ import java.io.*; | |||||
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
* Call Ant in a sub-project | |||||
* Call Ant in a sub-project | |||||
* | * | ||||
* @author costin@dnt.ro | * @author costin@dnt.ro | ||||
*/ | */ | ||||
@@ -68,36 +68,34 @@ public class Ant extends Task { | |||||
private String dir = null; | private String dir = null; | ||||
private String antFile = null; | private String antFile = null; | ||||
private String target = null; | private String target = null; | ||||
/** | /** | ||||
* Do the execution. | * Do the execution. | ||||
*/ | */ | ||||
public void execute() throws BuildException { | 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(); | Enumeration e = prop1.keys(); | ||||
while (e.hasMoreElements()) { | 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.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) { | public void setDir(String d) { | ||||
this.dir = d; | this.dir = d; | ||||
} | } | ||||
@@ -109,6 +107,4 @@ public class Ant extends Task { | |||||
public void setTarget(String s) { | public void setTarget(String s) { | ||||
this.target = s; | this.target = s; | ||||
} | } | ||||
} | } |