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