KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > thirdparty > ant > JavaC


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 JavaDoc;
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.net.URL JavaDoc;
31
32
33 // ant imports
34
import org.apache.tools.ant.Project;
35 import org.apache.tools.ant.Target;
36 import org.apache.tools.ant.taskdefs.Javac;
37 import org.apache.tools.ant.types.Path;
38
39 // coadunation import
40
import com.rift.coad.BaseClassLoader;
41
42 /**
43  * This object is responsible for the creation of java classes from a source
44  * directory.
45  *
46  * @author Brett Chaldecott
47  */

48 public class JavaC extends Javac {
49     
50     /** Creates a new instance of JavaC */
51     public JavaC(File JavaDoc[] classPath, File JavaDoc source, File JavaDoc dest) {
52         project = new Project();
53         
54         project.init();
55         taskType = "JavaC";
56         taskName = "JavaC";
57         Path path = new Path(project);
58         for (int index = 0; index < classPath.length; index++) {
59             path.add(new Path(project,classPath[index].getAbsolutePath()));
60         }
61         if (this.getClass().getClassLoader() instanceof BaseClassLoader) {
62             BaseClassLoader baseClassLoader =
63                     (BaseClassLoader)this.getClass().getClassLoader();
64             URL JavaDoc 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 JavaDoc ex) {
87             throw new AntException("Failed to compile :" + ex.getMessage()
88                 + " [" + listener.getMessage() + "]",ex);
89         }
90     }
91 }
92
Popular Tags