1
22
23 package com.liferay.util.resin;
24
25 import com.liferay.portal.kernel.util.MethodInvoker;
26 import com.liferay.portal.kernel.util.MethodWrapper;
27 import com.liferay.portal.kernel.util.StackTraceUtil;
28 import com.liferay.util.FileUtil;
29
30 import java.io.File;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
41 public class BatchJspCompiler {
42
43 public static void main(String[] args) {
44 if (args.length == 2) {
45 new BatchJspCompiler(args[0], args[1]);
46 }
47 else {
48 throw new IllegalArgumentException();
49 }
50 }
51
52 public BatchJspCompiler(String appDir, String classDir) {
53 try {
54 _appDir = appDir;
55 _classDir = classDir;
56
57 _compile(new File(appDir));
58 }
59 catch (Exception e) {
60 e.printStackTrace();
61 }
62 }
63
64 private void _compile(File directory) throws Exception {
65 if (directory.exists() && directory.isDirectory()) {
66 List fileList = new ArrayList();
67
68 File[] fileArray = FileUtil.sortFiles(directory.listFiles());
69
70 for (int i = 0; i < fileArray.length; i++) {
71 File file = fileArray[i];
72
73 if (file.isDirectory()) {
74 _compile(fileArray[i]);
75 }
76 else if (file.getName().endsWith(".jsp")) {
77 fileList.add(file);
78 }
79 }
80
81 _compile(directory.getPath(), fileList);
82 }
83 }
84
85 private void _compile(String sourcePath, List files) throws Exception {
86 if (files.size() == 0) {
87 return;
88 }
89
90 System.out.println(sourcePath);
91
92 for (int i = 0; i < files.size(); i++) {
93 File file = (File)files.get(i);
94
95 String fileName = file.toString();
96
97 String[] args = new String[] {
98 "-app-dir", _appDir, "-class-dir", _classDir, fileName
99 };
100
101 MethodWrapper methodWrapper = new MethodWrapper(
102 "com.caucho.jsp.JspCompiler", "main", new Object[] {args});
103
104 try {
105 MethodInvoker.invoke(methodWrapper);
106 }
107 catch (Exception e) {
108 FileUtil.write(
109 fileName + ".jspc_error", StackTraceUtil.getStackTrace(e));
110 }
111 }
112 }
113
114 private String _appDir;
115 private String _classDir;
116
117 }