1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.tools;
24  
25  import com.liferay.portal.kernel.util.CharPool;
26  import com.liferay.portal.kernel.util.ClassUtil;
27  import com.liferay.portal.kernel.util.ListUtil;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.kernel.util.StringUtil;
30  import com.liferay.portal.util.ContentUtil;
31  import com.liferay.portal.util.FileImpl;
32  
33  import java.io.BufferedReader;
34  import java.io.File;
35  import java.io.InputStream;
36  import java.io.IOException;
37  import java.io.StringReader;
38  import java.net.URL;
39  import java.util.ArrayList;
40  import java.util.HashSet;
41  import java.util.List;
42  import java.util.Properties;
43  import java.util.Set;
44  import java.util.regex.Matcher;
45  import java.util.regex.Pattern;
46  
47  import org.apache.tools.ant.DirectoryScanner;
48  
49  /**
50   * <a href="SourceFormatter.java.html"><b><i>View Source</i></b></a>
51   *
52   * @author Brian Wing Shun Chan
53   *
54   */
55  public class SourceFormatter {
56  
57      public static void main(String[] args) {
58          try {
59              _readExclusions();
60  
61              _checkPersistenceTestSuite();
62              _checkWebXML();
63              _formatJava();
64              _formatJSP();
65          }
66          catch (Exception e) {
67              e.printStackTrace();
68          }
69      }
70  
71      public static String stripImports(
72              String content, String packageDir, String className)
73          throws IOException {
74  
75          int x = content.indexOf("import ");
76  
77          if (x == -1) {
78              return content;
79          }
80  
81          int y = content.indexOf("{", x);
82  
83          y = content.substring(0, y).lastIndexOf(";") + 1;
84  
85          String imports = _formatImports(content.substring(x, y));
86  
87          content =
88              content.substring(0, x) + imports +
89                  content.substring(y + 1, content.length());
90  
91          Set<String> classes = ClassUtil.getClasses(
92              new StringReader(content), className);
93  
94          classes.add("_getMarkup");
95          classes.add("_performBlockingInteraction");
96  
97          x = content.indexOf("import ");
98  
99          y = content.indexOf("{", x);
100 
101         y = content.substring(0, y).lastIndexOf(";") + 1;
102 
103         imports = content.substring(x, y);
104 
105         StringBuilder sb = new StringBuilder();
106 
107         BufferedReader br = new BufferedReader(new StringReader(imports));
108 
109         String line = null;
110 
111         while ((line = br.readLine()) != null) {
112             if (line.indexOf("import ") != -1) {
113                 int importX = line.indexOf(" ");
114                 int importY = line.lastIndexOf(".");
115 
116                 String importPackage = line.substring(importX + 1, importY);
117                 String importClass = line.substring(
118                     importY + 1, line.length() - 1);
119 
120                 if (!packageDir.equals(importPackage)) {
121                     if (!importClass.equals("*")) {
122                         if (classes.contains(importClass)) {
123                             sb.append(line);
124                             sb.append("\n");
125                         }
126                     }
127                     else {
128                         sb.append(line);
129                         sb.append("\n");
130                     }
131                 }
132             }
133         }
134 
135         imports = _formatImports(sb.toString());
136 
137         content =
138             content.substring(0, x) + imports +
139                 content.substring(y + 1, content.length());
140 
141         return content;
142     }
143 
144     public static void _checkPersistenceTestSuite() throws IOException {
145         String basedir = "./portal-impl/test";
146 
147         if (!_fileUtil.exists(basedir)) {
148             return;
149         }
150 
151         DirectoryScanner ds = new DirectoryScanner();
152 
153         ds.setBasedir(basedir);
154         ds.setIncludes(new String[] {"**\\*PersistenceTest.java"});
155 
156         ds.scan();
157 
158         String[] files = ds.getIncludedFiles();
159 
160         Set<String> persistenceTests = new HashSet<String>();
161 
162         for (String file : files) {
163             String persistenceTest = file.substring(0, file.length() - 5);
164 
165             persistenceTest = persistenceTest.substring(
166                 persistenceTest.lastIndexOf(File.separator) + 1,
167                 persistenceTest.length());
168 
169             persistenceTests.add(persistenceTest);
170         }
171 
172         String persistenceTestSuite = _fileUtil.read(
173             basedir + "/com/liferay/portal/service/persistence/" +
174                 "PersistenceTestSuite.java");
175 
176         for (String persistenceTest : persistenceTests) {
177             if (persistenceTestSuite.indexOf(persistenceTest) == -1) {
178                 System.out.println("PersistenceTestSuite: " + persistenceTest);
179             }
180         }
181     }
182 
183     private static void _checkWebXML() throws IOException {
184         String basedir = "./";
185 
186         if (_fileUtil.exists(basedir + "portal-impl")) {
187             return;
188         }
189 
190         String webXML = ContentUtil.get(
191             "com/liferay/portal/deploy/dependencies/web.xml");
192 
193         DirectoryScanner ds = new DirectoryScanner();
194 
195         ds.setBasedir(basedir);
196         ds.setIncludes(new String[] {"**\\web.xml"});
197 
198         ds.scan();
199 
200         String[] files = ds.getIncludedFiles();
201 
202         for (String file : files) {
203             String content = _fileUtil.read(basedir + file);
204 
205             if (content.equals(webXML)) {
206                 System.out.println(file);
207             }
208         }
209     }
210 
211     private static void _checkXSS(String fileName, String jspContent) {
212         Matcher matcher = _xssPattern.matcher(jspContent);
213 
214         while (matcher.find()) {
215             boolean xssVulnerable = false;
216 
217             String jspVariable = matcher.group(1);
218 
219             String inputVulnerability =
220                 " type=\"hidden\" value=\"<%= " + jspVariable + " %>";
221 
222             if (jspContent.indexOf(inputVulnerability) != -1) {
223                 xssVulnerable = true;
224             }
225 
226             String anchorVulnerability = " href=\"<%= " + jspVariable + " %>";
227 
228             if (jspContent.indexOf(anchorVulnerability) != -1) {
229                 xssVulnerable = true;
230             }
231 
232             String inlineStringVulnerability1 = "'<%= " + jspVariable + " %>";
233 
234             if (jspContent.indexOf(inlineStringVulnerability1) != -1) {
235                 xssVulnerable = true;
236             }
237 
238             String inlineStringVulnerability2 = "(\"<%= " + jspVariable + " %>";
239 
240             if (jspContent.indexOf(inlineStringVulnerability2) != -1) {
241                 xssVulnerable = true;
242             }
243 
244             String inlineStringVulnerability3 = " \"<%= " + jspVariable + " %>";
245 
246             if (jspContent.indexOf(inlineStringVulnerability3) != -1) {
247                 xssVulnerable = true;
248             }
249 
250             String documentIdVulnerability = ".<%= " + jspVariable + " %>";
251 
252             if (jspContent.indexOf(documentIdVulnerability) != -1) {
253                 xssVulnerable = true;
254             }
255 
256             if (xssVulnerable) {
257                 System.out.println(
258                     "(xss): " + fileName + " (" + jspVariable + ")");
259             }
260         }
261     }
262 
263     public static String _formatImports(String imports) throws IOException {
264         if ((imports.indexOf("/*") != -1) ||
265             (imports.indexOf("*/") != -1) ||
266             (imports.indexOf("//") != -1)) {
267 
268             return imports + "\n";
269         }
270 
271         List<String> importsList = new ArrayList<String>();
272 
273         BufferedReader br = new BufferedReader(new StringReader(imports));
274 
275         String line = null;
276 
277         while ((line = br.readLine()) != null) {
278             if (line.indexOf("import ") != -1) {
279                 if (!importsList.contains(line)) {
280                     importsList.add(line);
281                 }
282             }
283         }
284 
285         importsList = ListUtil.sort(importsList);
286 
287         StringBuilder sb = new StringBuilder();
288 
289         String temp = null;
290 
291         for (int i = 0; i < importsList.size(); i++) {
292             String s = importsList.get(i);
293 
294             int pos = s.indexOf(".");
295 
296             pos = s.indexOf(".", pos + 1);
297 
298             if (pos == -1) {
299                 pos = s.indexOf(".");
300             }
301 
302             String packageLevel = s.substring(7, pos);
303 
304             if ((i != 0) && (!packageLevel.equals(temp))) {
305                 sb.append("\n");
306             }
307 
308             temp = packageLevel;
309 
310             sb.append(s);
311             sb.append("\n");
312         }
313 
314         return sb.toString();
315     }
316 
317     private static void _formatJava() throws IOException {
318         String basedir = "./";
319 
320         String copyright = _getCopyright();
321 
322         String[] files = null;
323 
324         if (_fileUtil.exists(basedir + "portal-impl")) {
325             files = _getPortalJavaFiles();
326         }
327         else {
328             files = _getPluginJavaFiles();
329         }
330 
331         for (int i = 0; i < files.length; i++) {
332             File file = new File(basedir + files[i]);
333 
334             String content = _fileUtil.read(file);
335 
336             String className = file.getName();
337 
338             className = className.substring(0, className.length() - 5);
339 
340             String packagePath = files[i];
341 
342             int packagePathX = packagePath.indexOf(
343                 File.separator + "src" + File.separator);
344             int packagePathY = packagePath.lastIndexOf(File.separator);
345 
346             if ((packagePathX + 5) >= packagePathY) {
347                 packagePath = StringPool.BLANK;
348             }
349             else {
350                 packagePath = packagePath.substring(
351                     packagePathX + 5, packagePathY);
352             }
353 
354             packagePath = StringUtil.replace(
355                 packagePath, File.separator, StringPool.PERIOD);
356 
357             if (packagePath.endsWith(".model")) {
358                 if (content.indexOf(
359                         "extends " + className + "Model {") != -1) {
360 
361                     continue;
362                 }
363             }
364 
365             String newContent = _formatJavaContent(files[i], content);
366 
367             if (newContent.indexOf("$\n */") != -1) {
368                 System.out.println("*: " + files[i]);
369 
370                 newContent = StringUtil.replace(
371                     newContent, "$\n */", "$\n *\n */");
372             }
373 
374             if (newContent.indexOf(copyright) == -1) {
375                 System.out.println("(c): " + files[i]);
376             }
377 
378             if (newContent.indexOf(className + ".java.html") == -1) {
379                 System.out.println("Java2HTML: " + files[i]);
380             }
381 
382             newContent = stripImports(newContent, packagePath, className);
383 
384             newContent = StringUtil.replace(
385                 newContent, "@author Raymond Aug?", "@author Raymond Augé");
386 
387             if (newContent.indexOf(";\n/**") != -1) {
388                 newContent = StringUtil.replace(
389                     newContent,
390                     ";\n/**",
391                     ";\n\n/**");
392             }
393 
394             if (newContent.indexOf("\t/*\n\t *") != -1) {
395                 newContent = StringUtil.replace(
396                     newContent,
397                     "\t/*\n\t *",
398                     "\t/**\n\t *");
399             }
400 
401             if (newContent.indexOf("if(") != -1) {
402                 newContent = StringUtil.replace(
403                     newContent,
404                     "if(",
405                     "if (");
406             }
407 
408             if (newContent.indexOf("while(") != -1) {
409                 newContent = StringUtil.replace(
410                     newContent,
411                     "while(",
412                     "while (");
413             }
414 
415             if (newContent.indexOf("\n\n\n") != -1) {
416                 newContent = StringUtil.replace(
417                     newContent,
418                     "\n\n\n",
419                     "\n\n");
420             }
421 
422             if (newContent.indexOf("*/\npackage ") != -1) {
423                 System.out.println("package: " + files[i]);
424             }
425 
426             if (newContent.indexOf("    ") != -1) {
427                 if (!files[i].endsWith("StringPool.java")) {
428                     System.out.println("tab: " + files[i]);
429                 }
430             }
431 
432             if (newContent.indexOf("  {") != -1) {
433                 System.out.println("{:" + files[i]);
434             }
435 
436             if (!newContent.endsWith("\n\n}") &&
437                 !newContent.endsWith("{\n}")) {
438 
439                 System.out.println("}: " + files[i]);
440             }
441 
442             if ((newContent != null) && !content.equals(newContent)) {
443                 _fileUtil.write(file, newContent);
444 
445                 System.out.println(file);
446             }
447         }
448     }
449 
450     private static String _formatJavaContent(String fileName, String content)
451         throws IOException {
452 
453         boolean longLogFactoryUtil = false;
454 
455         StringBuilder sb = new StringBuilder();
456 
457         BufferedReader br = new BufferedReader(new StringReader(content));
458 
459         int lineCount = 0;
460 
461         String line = null;
462 
463         while ((line = br.readLine()) != null) {
464             lineCount++;
465 
466             if (line.trim().length() == 0) {
467                 line = StringPool.BLANK;
468             }
469 
470             line = StringUtil.trimTrailing(line);
471 
472             line = StringUtil.replace(
473                 line,
474                 new String[] {
475                     "* Copyright (c) 2000-2008 Liferay, Inc.",
476                     "* Copyright 2008 Sun Microsystems Inc."
477                 },
478                 new String[] {
479                     "* Copyright (c) 2000-2009 Liferay, Inc.",
480                     "* Copyright 2009 Sun Microsystems Inc."
481                 });
482 
483             sb.append(line);
484             sb.append("\n");
485 
486             line = StringUtil.replace(line, "\t", "    ");
487 
488             String excluded = _exclusions.getProperty(
489                 StringUtil.replace(fileName, "\\", "/") + StringPool.AT +
490                     lineCount);
491 
492             if (excluded == null) {
493                 excluded = _exclusions.getProperty(
494                     StringUtil.replace(fileName, "\\", "/"));
495             }
496 
497             if ((excluded == null) && ((line.length() - 1) > 79) &&
498                 (!line.startsWith("import "))) {
499 
500                 if (line.contains(
501                         "private static Log _log = LogFactoryUtil.getLog(")) {
502 
503                     longLogFactoryUtil = true;
504                 }
505 
506                 System.out.println("> 80: " + fileName + " " + lineCount);
507             }
508         }
509 
510         br.close();
511 
512         String newContent = sb.toString();
513 
514         if (newContent.endsWith("\n")) {
515             newContent = newContent.substring(0, newContent.length() -1);
516         }
517 
518         if (longLogFactoryUtil) {
519             newContent = StringUtil.replace(
520                 newContent, "private static Log _log =",
521                 "private static Log _log =\n\t\t");
522         }
523 
524         return newContent;
525     }
526 
527     private static void _formatJSP() throws IOException {
528         String basedir = "./";
529 
530         List<File> list = new ArrayList<File>();
531 
532         DirectoryScanner ds = new DirectoryScanner();
533 
534         ds.setBasedir(basedir);
535         ds.setExcludes(new String[] {"**\\null.jsp", "**\\tmp\\**"});
536         ds.setIncludes(new String[] {"**\\*.jsp", "**\\*.jspf", "**\\*.vm"});
537 
538         ds.scan();
539 
540         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
541 
542         String copyright = _getCopyright();
543 
544         String[] files = list.toArray(new String[list.size()]);
545 
546         for (int i = 0; i < files.length; i++) {
547             File file = new File(basedir + files[i]);
548 
549             String content = _fileUtil.read(file);
550             String newContent = _formatJSPContent(files[i], content);
551 
552             newContent = StringUtil.replace(
553                 newContent,
554                 new String[] {
555                     "<br/>", "\"/>", "\" >", "@page import", "\"%>", ")%>"
556                 },
557                 new String[] {
558                     "<br />", "\" />", "\">", "@ page import", "\" %>", ") %>"
559                 });
560 
561             newContent = StringUtil.replace(
562                 newContent,
563                 new String[] {
564                     "* Copyright (c) 2000-2008 Liferay, Inc.",
565                     "* Copyright 2008 Sun Microsystems Inc."
566                 },
567                 new String[] {
568                     "* Copyright (c) 2000-2009 Liferay, Inc.",
569                     "* Copyright 2009 Sun Microsystems Inc."
570                 });
571 
572             if (files[i].endsWith(".jsp")) {
573                 if (newContent.indexOf(copyright) == -1) {
574                     System.out.println("(c): " + files[i]);
575                 }
576             }
577 
578             if (newContent.indexOf("alert('<%= LanguageUtil.") != -1) {
579                 newContent = StringUtil.replace(newContent,
580                     "alert('<%= LanguageUtil.",
581                     "alert('<%= UnicodeLanguageUtil.");
582             }
583 
584             if (newContent.indexOf("alert(\"<%= LanguageUtil.") != -1) {
585                 newContent = StringUtil.replace(newContent,
586                     "alert(\"<%= LanguageUtil.",
587                     "alert(\"<%= UnicodeLanguageUtil.");
588             }
589 
590             if (newContent.indexOf("confirm('<%= LanguageUtil.") != -1) {
591                 newContent = StringUtil.replace(newContent,
592                     "confirm('<%= LanguageUtil.",
593                     "confirm('<%= UnicodeLanguageUtil.");
594             }
595 
596             if (newContent.indexOf("confirm(\"<%= LanguageUtil.") != -1) {
597                 newContent = StringUtil.replace(newContent,
598                     "confirm(\"<%= LanguageUtil.",
599                     "confirm(\"<%= UnicodeLanguageUtil.");
600             }
601 
602             if (newContent.indexOf("    ") != -1) {
603                 if (!files[i].endsWith("template.vm")) {
604                     System.out.println("tab: " + files[i]);
605                 }
606             }
607 
608             _checkXSS(files[i], content);
609 
610             if ((newContent != null) && !content.equals(newContent)) {
611                 _fileUtil.write(file, newContent);
612 
613                 System.out.println(file);
614             }
615         }
616     }
617 
618     private static String _formatJSPContent(String fileName, String content)
619         throws IOException {
620 
621         StringBuilder sb = new StringBuilder();
622 
623         BufferedReader br = new BufferedReader(new StringReader(content));
624 
625         String line = null;
626 
627         while ((line = br.readLine()) != null) {
628             if (line.trim().length() == 0) {
629                 line = StringPool.BLANK;
630             }
631 
632             line = StringUtil.trimTrailing(line);
633 
634             sb.append(line);
635             sb.append("\n");
636         }
637 
638         br.close();
639 
640         content = sb.toString();
641 
642         if (content.endsWith("\n")) {
643             content = content.substring(0, content.length() -1);
644         }
645 
646         content = _formatTaglibQuotes(fileName, content, StringPool.QUOTE);
647         content = _formatTaglibQuotes(fileName, content, StringPool.APOSTROPHE);
648 
649         return content;
650     }
651 
652     private static String _formatTaglibQuotes(
653         String fileName, String content, String quoteType) {
654 
655         String quoteFix = StringPool.APOSTROPHE;
656 
657         if (quoteFix.equals(quoteType)) {
658             quoteFix = StringPool.QUOTE;
659         }
660 
661         Pattern pattern = Pattern.compile(_getTaglibRegex(quoteType));
662 
663         Matcher matcher = pattern.matcher(content);
664 
665         while (matcher.find()) {
666             int x = content.indexOf(quoteType + "<%=", matcher.start());
667             int y = content.indexOf("%>" + quoteType, x);
668 
669             while ((x != -1) && (y != -1)) {
670                 String result = content.substring(x + 1, y + 2);
671 
672                 if (result.indexOf(quoteType) != -1) {
673                     int lineCount = 1;
674 
675                     char contentCharArray[] = content.toCharArray();
676 
677                     for (int i = 0; i < x; i++) {
678                         if (contentCharArray[i] == CharPool.NEW_LINE) {
679                             lineCount++;
680                         }
681                     }
682 
683                     if (result.indexOf(quoteFix) == -1) {
684                         StringBuilder sb = new StringBuilder();
685 
686                         sb.append(content.substring(0, x));
687                         sb.append(quoteFix);
688                         sb.append(result);
689                         sb.append(quoteFix);
690                         sb.append(content.substring(y + 3, content.length()));
691 
692                         content = sb.toString();
693                     }
694                     else {
695                         System.out.println(
696                             "taglib: " + fileName + " " + lineCount);
697                     }
698                 }
699 
700                 x = content.indexOf(quoteType + "<%=", y);
701 
702                 if (x > matcher.end()) {
703                     break;
704                 }
705 
706                 y = content.indexOf("%>" + quoteType, x);
707             }
708         }
709 
710         return content;
711     }
712 
713     private static String _getCopyright() throws IOException {
714         try {
715             return _fileUtil.read("copyright.txt");
716         }
717         catch (Exception e1) {
718             try {
719                 return _fileUtil.read("../copyright.txt");
720             }
721             catch (Exception e2) {
722                 return _fileUtil.read("../../copyright.txt");
723             }
724         }
725     }
726 
727     private static String[] _getPluginJavaFiles() {
728         String basedir = "./";
729 
730         List<File> list = new ArrayList<File>();
731 
732         DirectoryScanner ds = new DirectoryScanner();
733 
734         ds.setBasedir(basedir);
735         ds.setExcludes(
736             new String[] {
737                 "**\\model\\*Clp.java", "**\\model\\*Model.java",
738                 "**\\model\\*Soap.java", "**\\model\\impl\\*ModelImpl.java",
739                 "**\\service\\*Service.java", "**\\service\\*ServiceClp.java",
740                 "**\\service\\*ServiceFactory.java",
741                 "**\\service\\*ServiceUtil.java",
742                 "**\\service\\ClpSerializer.java",
743                 "**\\service\\base\\*ServiceBaseImpl.java",
744                 "**\\service\\http\\*JSONSerializer.java",
745                 "**\\service\\http\\*ServiceHttp.java",
746                 "**\\service\\http\\*ServiceJSON.java",
747                 "**\\service\\http\\*ServiceSoap.java",
748                 "**\\service\\persistence\\*Finder.java",
749                 "**\\service\\persistence\\*Persistence.java",
750                 "**\\service\\persistence\\*PersistenceImpl.java",
751                 "**\\service\\persistence\\*Util.java"
752             });
753         ds.setIncludes(new String[] {"**\\*.java"});
754 
755         ds.scan();
756 
757         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
758 
759         return list.toArray(new String[list.size()]);
760     }
761 
762     private static String[] _getPortalJavaFiles() {
763         String basedir = "./";
764 
765         List<File> list = new ArrayList<File>();
766 
767         DirectoryScanner ds = new DirectoryScanner();
768 
769         ds.setBasedir(basedir);
770         ds.setExcludes(
771             new String[] {
772                 "**\\classes\\*", "**\\jsp\\*", "**\\tmp\\**",
773                 "**\\EARXMLBuilder.java", "**\\EJBXMLBuilder.java",
774                 "**\\PropsKeys.java", "**\\InstanceWrapperBuilder.java",
775                 "**\\ServiceBuilder.java", "**\\SourceFormatter.java",
776                 "**\\UserAttributes.java", "**\\WebKeys.java",
777                 "**\\*_IW.java", "**\\XHTMLComplianceFormatter.java",
778                 "**\\portal-service\\**\\model\\*Model.java",
779                 "**\\portal-service\\**\\model\\*Soap.java",
780                 "**\\model\\impl\\*ModelImpl.java",
781                 "**\\portal\\service\\**", "**\\portal-client\\**",
782                 "**\\portal-web\\classes\\**\\*.java",
783                 "**\\portal-web\\test\\**\\*Test.java",
784                 "**\\portlet\\**\\service\\**", "**\\tools\\ext_tmpl\\**",
785                 "**\\wsrp\\service\\**"
786             });
787         ds.setIncludes(new String[] {"**\\*.java"});
788 
789         ds.scan();
790 
791         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
792 
793         ds = new DirectoryScanner();
794 
795         ds.setBasedir(basedir);
796         ds.setExcludes(
797             new String[] {
798                 "**\\tools\\ext_tmpl\\**", "**\\*_IW.java",
799                 "**\\test\\**\\*PersistenceTest.java"
800             });
801         ds.setIncludes(
802             new String[] {
803                 "**\\com\\liferay\\portal\\service\\ServiceContext*.java",
804                 "**\\model\\BaseModel.java",
805                 "**\\model\\impl\\BaseModelImpl.java",
806                 "**\\service\\base\\PrincipalBean.java",
807                 "**\\service\\http\\*HttpTest.java",
808                 "**\\service\\http\\*SoapTest.java",
809                 "**\\service\\http\\TunnelUtil.java",
810                 "**\\service\\impl\\*.java", "**\\service\\jms\\*.java",
811                 "**\\service\\permission\\*.java",
812                 "**\\service\\persistence\\BasePersistence.java",
813                 "**\\service\\persistence\\BatchSession*.java",
814                 "**\\service\\persistence\\*FinderImpl.java",
815                 "**\\service\\persistence\\impl\\BasePersistenceImpl.java",
816                 "**\\portal-impl\\test\\**\\*.java",
817                 "**\\portal-service\\**\\liferay\\counter\\**.java",
818                 "**\\portal-service\\**\\liferay\\documentlibrary\\**.java",
819                 "**\\portal-service\\**\\liferay\\lock\\**.java",
820                 "**\\portal-service\\**\\liferay\\mail\\**.java",
821                 "**\\util-bridges\\**\\*.java"
822             });
823 
824         ds.scan();
825 
826         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
827 
828         return list.toArray(new String[list.size()]);
829     }
830 
831     private static String _getTaglibRegex(String quoteType) {
832         StringBuilder sb = new StringBuilder();
833 
834         sb.append("<(");
835 
836         for (int i = 0; i < _TAG_LIBRARIES.length; i++) {
837             sb.append(_TAG_LIBRARIES[i]);
838             sb.append(StringPool.PIPE);
839         }
840 
841         sb.deleteCharAt(sb.length() - 1);
842         sb.append("):([^>]|%>)*");
843         sb.append(quoteType);
844         sb.append("<%=[^>]*");
845         sb.append(quoteType);
846         sb.append("[^>]*%>");
847         sb.append(quoteType);
848         sb.append("([^>]|%>)*>");
849 
850         return sb.toString();
851     }
852 
853     private static void _readExclusions() throws IOException {
854         _exclusions = new Properties();
855 
856         ClassLoader classLoader = SourceFormatter.class.getClassLoader();
857 
858         URL url = classLoader.getResource(
859             "com/liferay/portal/tools/dependencies/" +
860                 "source_formatter_exclusions.properties");
861 
862         if (url == null) {
863             return;
864         }
865 
866         InputStream is = url.openStream();
867 
868         _exclusions.load(is);
869 
870         is.close();
871     }
872 
873     private static final String[] _TAG_LIBRARIES = new String[] {
874         "c", "html", "jsp", "liferay-portlet", "liferay-security",
875         "liferay-theme", "liferay-ui", "liferay-util", "portlet", "struts",
876         "tiles"
877     };
878 
879     private static FileImpl _fileUtil = FileImpl.getInstance();
880     private static Properties _exclusions;
881     private static Pattern _xssPattern = Pattern.compile(
882         "String\\s+([^\\s]+)\\s*=\\s*ParamUtil\\.getString\\(");
883 }
884