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<File> fileList = new ArrayList<File>();
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<File> files)
86 throws Exception {
87
88 if (files.size() == 0) {
89 return;
90 }
91
92 System.out.println(sourcePath);
93
94 for (int i = 0; i < files.size(); i++) {
95 File file = files.get(i);
96
97 String fileName = file.toString();
98
99 String[] args = new String[] {
100 "-app-dir", _appDir, "-class-dir", _classDir, fileName
101 };
102
103 MethodWrapper methodWrapper = new MethodWrapper(
104 "com.caucho.jsp.JspCompiler", "main", new Object[] {args});
105
106 try {
107 MethodInvoker.invoke(methodWrapper);
108 }
109 catch (Exception e) {
110 FileUtil.write(
111 fileName + ".jspc_error", StackTraceUtil.getStackTrace(e));
112 }
113 }
114 }
115
116 private String _appDir;
117 private String _classDir;
118
119 }