001
014
015 package com.liferay.portal.tools.jspc.resin;
016
017 import com.liferay.portal.kernel.util.MethodHandler;
018 import com.liferay.portal.kernel.util.MethodKey;
019 import com.liferay.portal.kernel.util.StackTraceUtil;
020 import com.liferay.portal.util.FileImpl;
021
022 import java.util.ArrayList;
023 import java.util.Arrays;
024 import java.util.List;
025
026 import org.apache.tools.ant.DirectoryScanner;
027
028
031 public class BatchJspCompiler {
032
033 public static void main(String[] args) {
034 if (args.length == 2) {
035 new BatchJspCompiler(args[0], args[1]);
036 }
037 else {
038 throw new IllegalArgumentException();
039 }
040 }
041
042 public BatchJspCompiler(String appDir, String classDir) {
043 try {
044 _appDir = appDir;
045 _classDir = classDir;
046
047 DirectoryScanner ds = new DirectoryScanner();
048
049 ds.setBasedir(appDir);
050 ds.setIncludes(new String[] {"**\\*.jsp"});
051
052 ds.scan();
053
054 String[] fileNames = ds.getIncludedFiles();
055
056 Arrays.sort(fileNames);
057
058 _compile(fileNames);
059 }
060 catch (Exception e) {
061 e.printStackTrace();
062 }
063 }
064
065 private void _compile(String[] fileNames) throws Exception {
066 if (fileNames.length == 0) {
067 return;
068 }
069
070 List<String> arguments = new ArrayList<String>();
071
072 arguments.add("-app-dir");
073 arguments.add(_appDir);
074 arguments.add("-class-dir");
075 arguments.add(_classDir);
076 arguments.addAll(Arrays.asList(fileNames));
077
078 MethodKey methodKey = new MethodKey(
079 "com.caucho.jsp.JspCompiler", "main", String[].class);
080
081 MethodHandler methodHandler = new MethodHandler(
082 methodKey, (Object)arguments.toArray(new String[arguments.size()]));
083
084 try {
085 methodHandler.invoke(false);
086 }
087 catch (Exception e) {
088 _fileUtil.write(
089 _appDir + "/../jspc_error", StackTraceUtil.getStackTrace(e));
090 }
091 }
092
093 private static FileImpl _fileUtil = FileImpl.getInstance();
094
095 private String _appDir;
096 private String _classDir;
097
098 }