001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.resin;
022:
023: import com.liferay.portal.kernel.util.MethodInvoker;
024: import com.liferay.portal.kernel.util.MethodWrapper;
025: import com.liferay.portal.kernel.util.StackTraceUtil;
026: import com.liferay.util.FileUtil;
027:
028: import java.io.File;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: /**
034: * <a href="BatchJspCompiler.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class BatchJspCompiler {
040:
041: public static void main(String[] args) {
042: if (args.length == 2) {
043: new BatchJspCompiler(args[0], args[1]);
044: } else {
045: throw new IllegalArgumentException();
046: }
047: }
048:
049: public BatchJspCompiler(String appDir, String classDir) {
050: try {
051: _appDir = appDir;
052: _classDir = classDir;
053:
054: _compile(new File(appDir));
055: } catch (Exception e) {
056: e.printStackTrace();
057: }
058: }
059:
060: private void _compile(File directory) throws Exception {
061: if (directory.exists() && directory.isDirectory()) {
062: List fileList = new ArrayList();
063:
064: File[] fileArray = FileUtil
065: .sortFiles(directory.listFiles());
066:
067: for (int i = 0; i < fileArray.length; i++) {
068: File file = fileArray[i];
069:
070: if (file.isDirectory()) {
071: _compile(fileArray[i]);
072: } else if (file.getName().endsWith(".jsp")) {
073: fileList.add(file);
074: }
075: }
076:
077: _compile(directory.getPath(), fileList);
078: }
079: }
080:
081: private void _compile(String sourcePath, List files)
082: throws Exception {
083: if (files.size() == 0) {
084: return;
085: }
086:
087: System.out.println(sourcePath);
088:
089: for (int i = 0; i < files.size(); i++) {
090: File file = (File) files.get(i);
091:
092: String fileName = file.toString();
093:
094: String[] args = new String[] { "-app-dir", _appDir,
095: "-class-dir", _classDir, fileName };
096:
097: MethodWrapper methodWrapper = new MethodWrapper(
098: "com.caucho.jsp.JspCompiler", "main",
099: new Object[] { args });
100:
101: try {
102: MethodInvoker.invoke(methodWrapper);
103: } catch (Exception e) {
104: FileUtil.write(fileName + ".jspc_error", StackTraceUtil
105: .getStackTrace(e));
106: }
107: }
108: }
109:
110: private String _appDir;
111: private String _classDir;
112:
113: }
|