Hi Stephen,
first of all: thanks for your answer and help!
I know that is some kind against the philosophy of ant. The thing in my
application is that nearly all properties have to be generated
on-the-fly and if something fails the stream has to be parsed and the
properties re-adjusted before the next run. So I felt it was unnecessary
to create a build.xml and tried the API... and this is why my question
raised ;-)
I also checked out the source code and I am going to take a look at it
at the weekend.
- Didi
Stephen McConnell wrote:
-----Original Message-----
From: Mark Russell [mailto:[EMAIL PROTECTED]
Sent: Wednesday, 4 January 2006 3:42 AM
To: Ant Users List
Subject: Re: calling ant API from java instead of using
build.xml from console
I would be interested in looking at that code
You can checkout sources from:
svn checkout svn://svn.berlios.de/dpml/trunk/main
The packages you should be looking at include:
* main/depot/tools/builder - this is a plugin that creates an Ant project
and parameterizes the project with a template. During build
initialization
an independent library is consulted concerning project production info
from
build listeners are added (based on the types of resources the project
declares)
* main/depot/library/common - this is the project library definition that
holds info about projects, their build, runtime and tests dependencies,
and project specific properties
* main/depot/library/console - a command line handler that launches a
a build system implementation (the default is the Ant-based builder
plugin)
Additional information is available at:
http://www.dpml.net/depot/concepts/index.html
/Steve.
Stephen McConnell wrote:
The approach your taking is kind of out of sync with the Ant object
model. A much easier approach is to construct your project, then
parameterize the project and finally trigger project execution. The
parameterization of the project could include:
a) assign a project basedir
b) assigning a template build file - for example you could
declare a
build file
that declares a bunch of build phases (e.g. init,
prepare, build,
package,
test, install) - note: these target don't necessarily
need to do
anything
c) add build listeners - you could create any number of build
listeners that
listener for build events declared in your template and
these listeners
could be doing the bulk of the work needed to build your project
In the build listeners you could do the sorts of things your
describing
in your code:
MyTask task = new MyTask();
task.setProject();
task.init();
task.setXxxx( whatever );
Yyy yyy = task.createYyy();
yyy.setSomething( true );
task.execute();
This approach kind of ties into the overall assumptions made by ant
which in turn makes things a lot easier. If your interested
I can point
you to code that does the above.
Cheers, Steve.
-----Original Message-----
From: Dieter Frej [mailto:[EMAIL PROTECTED]
Sent: Monday, 2 January 2006 6:45 PM
To: user@ant.apache.org
Subject: calling ant API from java instead of using build.xml from
console
Hi,
I would like to call ant (1.6.5) from java (1.5.0_04-b05),
but I am a
little puzzled with all createXYZ, addXYZ, init, and
execute methods
and in which order they should be called.
I wrote it the following way:
Project project = new Project();
XmlLogger xlog = new XmlLogger();
project.addBuildListener(xlog);
project.init();
Target target = new Target();
target.setLocation(new Location("somewhere"));
target.setName("blubb");
Mkdir mkdir = new Mkdir();
mkdir.setProject(project);
mkdir.setTaskName("init");
mkdir.init();
String destDir = "build/classes";
mkdir.setDir(new File(destDir));
target.addTask(mkdir);
Javac javac = new Javac();
javac.setProject(project);
javac.setTaskName("compile");
javac.init();
String srcDir = "src";
javac.setDestdir(new File(destDir));
javac.setSrcdir(new Path(project, srcDir));
javac.setDebug(true);
javac.setDeprecation(false);
javac.setOptimize(false);
Path classPath = new Path(project);
String classesDir = destDir;
Path classesPath = classPath.createPath();
classesPath.setPath(classesDir); classPath.add(classesPath);
ArrayList<String> libs = new ArrayList<String>();
libs.add("junit3.8.1/junit.jar");
Iterator it = libs.iterator();
while(it.hasNext()) {
String lib = (String) it.next();
FileSet libFile = new FileSet();
libFile.setFile(new File(lib));
classPath.addFileset(libFile);
}
javac.setClasspath(classPath);
//Javac.ImplementationSpecificArgument compilerArgs =
javac.createCompilerArg();
//compilerArgs.setLine("-Xlint:deprecation
-Xlint:unchecked");
target.addTask(javac);
project.addTarget("bla", target);
project.executeTarget("bla");
This more or less works fine, but I am not sure if it is correct,
because the XmlLogger gets a NullPointerException that is caused by
the fact that never buildStarted() is called...
I hope someone is able to help me. Thanks in advance!
-Didi
------------------------------------------------------------
---------
To unsubscribe, e-mail: [EMAIL PROTECTED] For
additional
commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED] For
additional
commands, e-mail: [EMAIL PROTECTED]
--
Mark Russell
Instantiations, Inc.
724-368-3331 (land line)
http://www.instantiations.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]