001: /*
002: * GCJcompiler.java
003: *
004: *
005: * Copyright (c) 2003 Rimfaxe ApS (www.rimfaxe.com).
006: * All rights reserved.
007: *
008: * This package is written by Lars Andersen <lars@rimfaxe.com>
009: * and licensed by Rimfaxe ApS.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions
013: * are met:
014: *
015: * 1. Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * 2. Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in
020: * the documentation and/or other materials provided with the
021: * distribution.
022: *
023: * 3. The end-user documentation included with the redistribution, if
024: * any, must include the following acknowlegement:
025: * "This product includes software developed by Rimfaxe ApS
026: (www.rimfaxe.com)"
027: * Alternately, this acknowlegement may appear in the software itself,
028: * if and wherever such third-party acknowlegements normally appear.
029: *
030: * 4. The names "Rimfaxe", "Rimfaxe Software", "Lars Andersen" and
031: * "Rimfaxe WebServer" must not be used to endorse or promote products
032: * derived from this software without prior written permission. For written
033: * permission, please contact info@rimfaxe.com
034: *
035: * 5. Products derived from this software may not be called "Rimfaxe"
036: * nor may "Rimfaxe" appear in their names without prior written
037: * permission of the Rimfaxe ApS.
038: *
039: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
040: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
041: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
042: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
043: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
044: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
045: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
046: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
047: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
048: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
049: * SUCH DAMAGE.
050: *
051: */
052:
053: package com.rimfaxe.webserver.compiler;
054:
055: import java.util.*;
056: import com.rimfaxe.webserver.VirtualHost;
057: import com.rimfaxe.webserver.WebContext;
058:
059: /**
060: *
061: * @author Lars Andersen
062: */
063: public class GCJcompiler {
064: com.rimfaxe.webserver.Configuration configuration = com.rimfaxe.webserver.ObjectStore
065: .getConfiguration();
066:
067: /** Creates a new instance of GCJcompiler */
068: public GCJcompiler() {
069: }
070:
071: public void checkDirs(String workdir) {
072:
073: java.io.File dir = new java.io.File(workdir);
074: if (!dir.exists())
075: dir.mkdir();
076:
077: dir = new java.io.File(workdir + "/jars");
078: if (!dir.exists())
079: dir.mkdir();
080:
081: dir = new java.io.File(workdir + "/jsp");
082: if (!dir.exists())
083: dir.mkdir();
084:
085: dir = new java.io.File(workdir + "/jsplib");
086: if (!dir.exists())
087: dir.mkdir();
088:
089: dir = new java.io.File(workdir + "/lib");
090: if (!dir.exists())
091: dir.mkdir();
092:
093: }
094:
095: public void compileWebApp(VirtualHost vh, WebContext webcontext) {
096: boolean hasEXT = false;
097:
098: // compile extension lib
099:
100: String webroot = webcontext.getRoot();
101:
102: System.out.print("Compile libservlets.so in web context ["
103: + webcontext.getName() + "] ");
104:
105: Library libservlets = new Library();
106: libservlets.setOutputFile("libservlets.so");
107: libservlets.setOutputDir(webroot + "/WEB-INF/rws/lib");
108:
109: checkDirs(webroot + "/WEB-INF/rws/");
110:
111: Vector inputfiles = new Vector();
112: Vector resourcefiles = new Vector();
113:
114: if (configuration.getWebappMode().equalsIgnoreCase("classic")) {
115:
116: libservlets.addCompileOption("-I" + webroot
117: + "/WEB-INF/classes");
118: libservlets.setInputDir(webroot + "/WEB-INF/classes");
119: libservlets.setSource(libservlets.CLASS_SOURCE);
120:
121: findFiles(webroot + "/WEB-INF/classes", "class", inputfiles);
122: libservlets.setInputFiles(inputfiles);
123:
124: findResources(webroot + "/WEB-INF/classes", resourcefiles);
125: libservlets.setResourceFiles(resourcefiles);
126: } else {
127: libservlets.addCompileOption("-I" + webroot
128: + "/WEB-INF/rws/src");
129: libservlets.setInputDir(webroot + "/WEB-INF/rws/src");
130: libservlets.setSource(libservlets.JAVA_SOURCE);
131:
132: findFiles(webroot + "/WEB-INF/rws/src", "java", inputfiles);
133: libservlets.setInputFiles(inputfiles);
134:
135: findResources(webroot + "/WEB-INF/rws/src", resourcefiles);
136: libservlets.setResourceFiles(resourcefiles);
137: }
138:
139: if (hasEXT) {
140: libservlets.addLinkOption("-lext -L" + webroot
141: + "/WEB-INF/rws/lib");
142: }
143:
144: if (inputfiles.size() > 0) {
145: try {
146:
147: libservlets.compile();
148: } catch (Exception e) {
149: System.out.println("" + e);
150: }
151: }
152: System.out.println("");
153: System.out.println("Compilation done");
154:
155: }
156:
157: public void findFiles(String rootdir, String ext, Vector vec) {
158:
159: java.io.File root = null;
160:
161: try {
162: root = new java.io.File(rootdir);
163: } catch (Exception e) {
164: }
165:
166: if (root == null)
167: return;
168:
169: String[] dirlist = root.list();
170:
171: if (dirlist == null)
172: return;
173:
174: for (int i = 0; i < dirlist.length; i++) {
175: String f = dirlist[i];
176: String name = f.toLowerCase();
177:
178: java.io.File temp = new java.io.File(rootdir + "/" + f);
179: if (temp.isDirectory()) {
180: findFiles(rootdir + "/" + f, ext, vec);
181: } else {
182: if (name.endsWith("." + ext)) {
183:
184: vec.addElement(rootdir + "/" + f);
185: }
186: }
187: }
188: }
189:
190: public void findResources(String rootdir, Vector vec) {
191:
192: java.io.File root = null;
193:
194: try {
195: root = new java.io.File(rootdir);
196: } catch (Exception e) {
197: }
198:
199: if (root == null)
200: return;
201:
202: String[] dirlist = root.list();
203:
204: if (dirlist == null)
205: return;
206:
207: for (int i = 0; i < dirlist.length; i++) {
208: String f = dirlist[i];
209: String name = f.toLowerCase();
210:
211: java.io.File temp = new java.io.File(rootdir + "/" + f);
212: if (temp.isDirectory()) {
213: findResources(rootdir + "/" + f, vec);
214: } else {
215: if ((!name.endsWith(".java"))
216: && (!name.endsWith(".class"))
217: && (!name.endsWith(".o"))
218: && (!name.endsWith("~"))) {
219: vec.addElement(rootdir + "/" + f);
220: }
221: }
222: }
223: }
224: }
|