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