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