01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * JavaC.java
20: *
21: * This object is responsible for the creation of java classes from a source
22: * directory.
23: */
24:
25: package com.rift.coad.lib.thirdparty.ant;
26:
27: // java imports
28: import java.io.File;
29: import java.io.ByteArrayOutputStream;
30: import java.net.URL;
31:
32: // ant imports
33: import org.apache.tools.ant.Project;
34: import org.apache.tools.ant.Target;
35: import org.apache.tools.ant.taskdefs.Javac;
36: import org.apache.tools.ant.types.Path;
37:
38: // coadunation import
39: import com.rift.coad.BaseClassLoader;
40:
41: /**
42: * This object is responsible for the creation of java classes from a source
43: * directory.
44: *
45: * @author Brett Chaldecott
46: */
47: public class JavaC extends Javac {
48:
49: /** Creates a new instance of JavaC */
50: public JavaC(File[] classPath, File source, File dest) {
51: project = new Project();
52:
53: project.init();
54: taskType = "JavaC";
55: taskName = "JavaC";
56: Path path = new Path(project);
57: for (int index = 0; index < classPath.length; index++) {
58: path.add(new Path(project, classPath[index]
59: .getAbsolutePath()));
60: }
61: if (this .getClass().getClassLoader() instanceof BaseClassLoader) {
62: BaseClassLoader baseClassLoader = (BaseClassLoader) this
63: .getClass().getClassLoader();
64: URL urls[] = baseClassLoader.getURLs();
65: for (int index = 0; index < urls.length; index++) {
66: path.add(new Path(project, urls[index].getFile()));
67: }
68: }
69:
70: this .setProject(project);
71: this .setClasspath(path);
72: this .setSrcdir(new Path(project, source.getAbsolutePath()));
73: this .setDestdir(dest);
74: }
75:
76: /**
77: * Compile the classes.
78: *
79: * @exception AntException
80: */
81: public void compileClasses() throws AntException {
82: AntListener listener = new AntListener();
83: project.addBuildListener(listener);
84: try {
85: super .execute();
86: } catch (Exception ex) {
87: throw new AntException("Failed to compile :"
88: + ex.getMessage() + " [" + listener.getMessage()
89: + "]", ex);
90: }
91: }
92: }
|