1
19
20 package com.liferay.portal.tools.jspc.resin;
21
22 import com.liferay.portal.kernel.util.MethodInvoker;
23 import com.liferay.portal.kernel.util.MethodWrapper;
24 import com.liferay.portal.kernel.util.StackTraceUtil;
25 import com.liferay.portal.util.FileImpl;
26
27 import java.io.File;
28
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.List;
32
33 import org.apache.tools.ant.DirectoryScanner;
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 DirectoryScanner ds = new DirectoryScanner();
58
59 ds.setBasedir(appDir);
60 ds.setIncludes(new String[] {"**\\*.jsp"});
61
62 ds.scan();
63
64 String[] files = ds.getIncludedFiles();
65
66 Arrays.sort(files);
67
68 List<String> fileNames = new ArrayList<String>();
69
70 for (int i = 0; i < files.length; i++) {
71 File file = new File(appDir + "/" + files[i]);
72
73 fileNames.add(file.toString());
74
75 if (((i > 0) && ((i % 200) == 0)) ||
76 ((i + 1) == files.length)) {
77
78 _compile(fileNames);
79
80 fileNames.clear();
81 }
82 }
83 }
84 catch (Exception e) {
85 e.printStackTrace();
86 }
87 }
88
89 private void _compile(List<String> fileNames) throws Exception {
90 if (fileNames.size() == 0) {
91 return;
92 }
93
94 List<String> args = new ArrayList<String>();
95
96 args.add("-app-dir");
97 args.add(_appDir);
98 args.add("-class-dir");
99 args.add(_classDir);
100 args.addAll(fileNames);
101
102 MethodWrapper methodWrapper = new MethodWrapper(
103 "com.caucho.jsp.JspCompiler", "main",
104 new Object[] {args.toArray(new String[args.size()])});
105
106 try {
107 MethodInvoker.invoke(methodWrapper);
108 }
109 catch (Exception e) {
110 _fileUtil.write(
111 _appDir + "/../jspc_error", StackTraceUtil.getStackTrace(e));
112 }
113 }
114
115 private static FileImpl _fileUtil = FileImpl.getInstance();
116
117 private String _appDir;
118 private String _classDir;
119
120 }