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         boolean portalJavaFiles = true;
323 
324         String[] files = null;
325 
326         if (_fileUtil.exists(basedir + "portal-impl")) {
327             files = _getPortalJavaFiles();
328         }
329         else {
330             portalJavaFiles = false;
331 
332             files = _getPluginJavaFiles();
333         }
334 
335         for (int i = 0; i < files.length; i++) {
336             File file = new File(basedir + files[i]);
337 
338             String content = _fileUtil.read(file);
339 
340             String className = file.getName();
341 
342             className = className.substring(0, className.length() - 5);
343 
344             String packagePath = files[i];
345 
346             int packagePathX = packagePath.indexOf(
347                 File.separator + "src" + File.separator);
348             int packagePathY = packagePath.lastIndexOf(File.separator);
349 
350             if ((packagePathX + 5) >= packagePathY) {
351                 packagePath = StringPool.BLANK;
352             }
353             else {
354                 packagePath = packagePath.substring(
355                     packagePathX + 5, packagePathY);
356             }
357 
358             packagePath = StringUtil.replace(
359                 packagePath, File.separator, StringPool.PERIOD);
360 
361             if (packagePath.endsWith(".model")) {
362                 if (content.indexOf(
363                         "extends " + className + "Model {") != -1) {
364 
365                     continue;
366                 }
367             }
368 
369             String newContent = _formatJavaContent(files[i], content);
370 
371             if (newContent.indexOf("$\n */") != -1) {
372                 System.out.println("*: " + files[i]);
373 
374                 newContent = StringUtil.replace(
375                     newContent, "$\n */", "$\n *\n */");
376             }
377 
378             if (newContent.indexOf(copyright) == -1) {
379                 System.out.println("(c): " + files[i]);
380             }
381 
382             if (newContent.indexOf(className + ".java.html") == -1) {
383                 System.out.println("Java2HTML: " + files[i]);
384             }
385 
386             newContent = stripImports(newContent, packagePath, className);
387 
388             newContent = StringUtil.replace(
389                 newContent, "@author Raymond Aug?", "@author Raymond Augé");
390 
391             if (newContent.indexOf(";\n/**") != -1) {
392                 newContent = StringUtil.replace(
393                     newContent,
394                     ";\n/**",
395                     ";\n\n/**");
396             }
397 
398             if (newContent.indexOf("\t/*\n\t *") != -1) {
399                 newContent = StringUtil.replace(
400                     newContent,
401                     "\t/*\n\t *",
402                     "\t/**\n\t *");
403             }
404 
405             if (newContent.indexOf("if(") != -1) {
406                 newContent = StringUtil.replace(
407                     newContent,
408                     "if(",
409                     "if (");
410             }
411 
412             if (newContent.indexOf("while(") != -1) {
413                 newContent = StringUtil.replace(
414                     newContent,
415                     "while(",
416                     "while (");
417             }
418 
419             if (newContent.indexOf("\n\n\n") != -1) {
420                 newContent = StringUtil.replace(
421                     newContent,
422                     "\n\n\n",
423                     "\n\n");
424             }
425 
426             if (newContent.indexOf("*/\npackage ") != -1) {
427                 System.out.println("package: " + files[i]);
428             }
429 
430             if (newContent.indexOf("    ") != -1) {
431                 if (!files[i].endsWith("StringPool.java")) {
432                     System.out.println("tab: " + files[i]);
433                 }
434             }
435 
436             if (newContent.indexOf("  {") != -1) {
437                 System.out.println("{:" + files[i]);
438             }
439 
440             if (!newContent.endsWith("\n\n}") &&
441                 !newContent.endsWith("{\n}")) {
442 
443                 System.out.println("}: " + files[i]);
444             }
445 
446             if (portalJavaFiles && className.endsWith("ServiceImpl") &&
447                 (newContent.indexOf("ServiceUtil.") != -1)) {
448 
449                 System.out.println("ServiceUtil: " + files[i]);
450             }
451 
452             if ((newContent != null) && !content.equals(newContent)) {
453                 _fileUtil.write(file, newContent);
454 
455                 System.out.println(file);
456             }
457         }
458     }
459 
460     private static String _formatJavaContent(String fileName, String content)
461         throws IOException {
462 
463         boolean longLogFactoryUtil = false;
464 
465         StringBuilder sb = new StringBuilder();
466 
467         BufferedReader br = new BufferedReader(new StringReader(content));
468 
469         int lineCount = 0;
470 
471         String line = null;
472 
473         while ((line = br.readLine()) != null) {
474             lineCount++;
475 
476             if (line.trim().length() == 0) {
477                 line = StringPool.BLANK;
478             }
479 
480             line = StringUtil.trimTrailing(line);
481 
482             line = StringUtil.replace(
483                 line,
484                 new String[] {
485                     "* Copyright (c) 2000-2008 Liferay, Inc.",
486                     "* Copyright 2008 Sun Microsystems Inc."
487                 },
488                 new String[] {
489                     "* Copyright (c) 2000-2009 Liferay, Inc.",
490                     "* Copyright 2009 Sun Microsystems Inc."
491                 });
492 
493             sb.append(line);
494             sb.append("\n");
495 
496             line = StringUtil.replace(line, "\t", "    ");
497 
498             String excluded = _exclusions.getProperty(
499                 StringUtil.replace(fileName, "\\", "/") + StringPool.AT +
500                     lineCount);
501 
502             if (excluded == null) {
503                 excluded = _exclusions.getProperty(
504                     StringUtil.replace(fileName, "\\", "/"));
505             }
506 
507             if ((excluded == null) && ((line.length() - 1) > 79) &&
508                 (!line.startsWith("import "))) {
509 
510                 if (line.contains(
511                         "private static Log _log = LogFactoryUtil.getLog(")) {
512 
513                     longLogFactoryUtil = true;
514                 }
515 
516                 System.out.println("> 80: " + fileName + " " + lineCount);
517             }
518         }
519 
520         br.close();
521 
522         String newContent = sb.toString();
523 
524         if (newContent.endsWith("\n")) {
525             newContent = newContent.substring(0, newContent.length() -1);
526         }
527 
528         if (longLogFactoryUtil) {
529             newContent = StringUtil.replace(
530                 newContent, "private static Log _log =",
531                 "private static Log _log =\n\t\t");
532         }
533 
534         return newContent;
535     }
536 
537     private static void _formatJSP() throws IOException {
538         String basedir = "./";
539 
540         List<File> list = new ArrayList<File>();
541 
542         DirectoryScanner ds = new DirectoryScanner();
543 
544         ds.setBasedir(basedir);
545         ds.setExcludes(new String[] {"**\\null.jsp", "**\\tmp\\**"});
546         ds.setIncludes(new String[] {"**\\*.jsp", "**\\*.jspf", "**\\*.vm"});
547 
548         ds.scan();
549 
550         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
551 
552         String copyright = _getCopyright();
553 
554         String[] files = list.toArray(new String[list.size()]);
555 
556         for (int i = 0; i < files.length; i++) {
557             File file = new File(basedir + files[i]);
558 
559             String content = _fileUtil.read(file);
560             String newContent = _formatJSPContent(files[i], content);
561 
562             newContent = StringUtil.replace(
563                 newContent,
564                 new String[] {
565                     "<br/>", "\"/>", "\" >", "@page import", "\"%>", ")%>"
566                 },
567                 new String[] {
568                     "<br />", "\" />", "\">", "@ page import", "\" %>", ") %>"
569                 });
570 
571             newContent = StringUtil.replace(
572                 newContent,
573                 new String[] {
574                     "* Copyright (c) 2000-2008 Liferay, Inc.",
575                     "* Copyright 2008 Sun Microsystems Inc."
576                 },
577                 new String[] {
578                     "* Copyright (c) 2000-2009 Liferay, Inc.",
579                     "* Copyright 2009 Sun Microsystems Inc."
580                 });
581 
582             if (files[i].endsWith(".jsp")) {
583                 if (newContent.indexOf(copyright) == -1) {
584                     System.out.println("(c): " + files[i]);
585                 }
586             }
587 
588             if (newContent.indexOf("alert('<%= LanguageUtil.") != -1) {
589                 newContent = StringUtil.replace(newContent,
590                     "alert('<%= LanguageUtil.",
591                     "alert('<%= UnicodeLanguageUtil.");
592             }
593 
594             if (newContent.indexOf("alert(\"<%= LanguageUtil.") != -1) {
595                 newContent = StringUtil.replace(newContent,
596                     "alert(\"<%= LanguageUtil.",
597                     "alert(\"<%= UnicodeLanguageUtil.");
598             }
599 
600             if (newContent.indexOf("confirm('<%= LanguageUtil.") != -1) {
601                 newContent = StringUtil.replace(newContent,
602                     "confirm('<%= LanguageUtil.",
603                     "confirm('<%= UnicodeLanguageUtil.");
604             }
605 
606             if (newContent.indexOf("confirm(\"<%= LanguageUtil.") != -1) {
607                 newContent = StringUtil.replace(newContent,
608                     "confirm(\"<%= LanguageUtil.",
609                     "confirm(\"<%= UnicodeLanguageUtil.");
610             }
611 
612             if (newContent.indexOf("    ") != -1) {
613                 if (!files[i].endsWith("template.vm")) {
614                     System.out.println("tab: " + files[i]);
615                 }
616             }
617 
618             _checkXSS(files[i], content);
619 
620             if ((newContent != null) && !content.equals(newContent)) {
621                 _fileUtil.write(file, newContent);
622 
623                 System.out.println(file);
624             }
625         }
626     }
627 
628     private static String _formatJSPContent(String fileName, String content)
629         throws IOException {
630 
631         StringBuilder sb = new StringBuilder();
632 
633         BufferedReader br = new BufferedReader(new StringReader(content));
634 
635         String line = null;
636 
637         while ((line = br.readLine()) != null) {
638             if (line.trim().length() == 0) {
639                 line = StringPool.BLANK;
640             }
641 
642             line = StringUtil.trimTrailing(line);
643 
644             sb.append(line);
645             sb.append("\n");
646         }
647 
648         br.close();
649 
650         content = sb.toString();
651 
652         if (content.endsWith("\n")) {
653             content = content.substring(0, content.length() -1);
654         }
655 
656         content = _formatTaglibQuotes(fileName, content, StringPool.QUOTE);
657         content = _formatTaglibQuotes(fileName, content, StringPool.APOSTROPHE);
658 
659         return content;
660     }
661 
662     private static String _formatTaglibQuotes(
663         String fileName, String content, String quoteType) {
664 
665         String quoteFix = StringPool.APOSTROPHE;
666 
667         if (quoteFix.equals(quoteType)) {
668             quoteFix = StringPool.QUOTE;
669         }
670 
671         Pattern pattern = Pattern.compile(_getTaglibRegex(quoteType));
672 
673         Matcher matcher = pattern.matcher(content);
674 
675         while (matcher.find()) {
676             int x = content.indexOf(quoteType + "<%=", matcher.start());
677             int y = content.indexOf("%>" + quoteType, x);
678 
679             while ((x != -1) && (y != -1)) {
680                 String result = content.substring(x + 1, y + 2);
681 
682                 if (result.indexOf(quoteType) != -1) {
683                     int lineCount = 1;
684 
685                     char contentCharArray[] = content.toCharArray();
686 
687                     for (int i = 0; i < x; i++) {
688                         if (contentCharArray[i] == CharPool.NEW_LINE) {
689                             lineCount++;
690                         }
691                     }
692 
693                     if (result.indexOf(quoteFix) == -1) {
694                         StringBuilder sb = new StringBuilder();
695 
696                         sb.append(content.substring(0, x));
697                         sb.append(quoteFix);
698                         sb.append(result);
699                         sb.append(quoteFix);
700                         sb.append(content.substring(y + 3, content.length()));
701 
702                         content = sb.toString();
703                     }
704                     else {
705                         System.out.println(
706                             "taglib: " + fileName + " " + lineCount);
707                     }
708                 }
709 
710                 x = content.indexOf(quoteType + "<%=", y);
711 
712                 if (x > matcher.end()) {
713                     break;
714                 }
715 
716                 y = content.indexOf("%>" + quoteType, x);
717             }
718         }
719 
720         return content;
721     }
722 
723     private static String _getCopyright() throws IOException {
724         try {
725             return _fileUtil.read("copyright.txt");
726         }
727         catch (Exception e1) {
728             try {
729                 return _fileUtil.read("../copyright.txt");
730             }
731             catch (Exception e2) {
732                 return _fileUtil.read("../../copyright.txt");
733             }
734         }
735     }
736 
737     private static String[] _getPluginJavaFiles() {
738         String basedir = "./";
739 
740         List<File> list = new ArrayList<File>();
741 
742         DirectoryScanner ds = new DirectoryScanner();
743 
744         ds.setBasedir(basedir);
745         ds.setExcludes(
746             new String[] {
747                 "**\\model\\*Clp.java", "**\\model\\*Model.java",
748                 "**\\model\\*Soap.java", "**\\model\\impl\\*ModelImpl.java",
749                 "**\\service\\*Service.java", "**\\service\\*ServiceClp.java",
750                 "**\\service\\*ServiceFactory.java",
751                 "**\\service\\*ServiceUtil.java",
752                 "**\\service\\ClpSerializer.java",
753                 "**\\service\\base\\*ServiceBaseImpl.java",
754                 "**\\service\\http\\*JSONSerializer.java",
755                 "**\\service\\http\\*ServiceHttp.java",
756                 "**\\service\\http\\*ServiceJSON.java",
757                 "**\\service\\http\\*ServiceSoap.java",
758                 "**\\service\\messaging\\*ClpMessageListener.java",
759                 "**\\service\\persistence\\*Finder.java",
760                 "**\\service\\persistence\\*Persistence.java",
761                 "**\\service\\persistence\\*PersistenceImpl.java",
762                 "**\\service\\persistence\\*Util.java", "**\\tmp\\**"
763             });
764         ds.setIncludes(new String[] {"**\\*.java"});
765 
766         ds.scan();
767 
768         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
769 
770         return list.toArray(new String[list.size()]);
771     }
772 
773     private static String[] _getPortalJavaFiles() {
774         String basedir = "./";
775 
776         List<File> list = new ArrayList<File>();
777 
778         DirectoryScanner ds = new DirectoryScanner();
779 
780         ds.setBasedir(basedir);
781         ds.setExcludes(
782             new String[] {
783                 "**\\classes\\*", "**\\jsp\\*", "**\\tmp\\**",
784                 "**\\EARXMLBuilder.java", "**\\EJBXMLBuilder.java",
785                 "**\\PropsKeys.java", "**\\InstanceWrapperBuilder.java",
786                 "**\\ServiceBuilder.java", "**\\SourceFormatter.java",
787                 "**\\UserAttributes.java", "**\\WebKeys.java",
788                 "**\\*_IW.java", "**\\XHTMLComplianceFormatter.java",
789                 "**\\portal-service\\**\\model\\*Model.java",
790                 "**\\portal-service\\**\\model\\*Soap.java",
791                 "**\\model\\impl\\*ModelImpl.java",
792                 "**\\portal\\service\\**", "**\\portal-client\\**",
793                 "**\\portal-web\\classes\\**\\*.java",
794                 "**\\portal-web\\test\\**\\*Test.java",
795                 "**\\portlet\\**\\service\\**", "**\\tools\\ext_tmpl\\**",
796                 "**\\util-wsrp\\**", "**\\wsrp\\**"
797             });
798         ds.setIncludes(new String[] {"**\\*.java"});
799 
800         ds.scan();
801 
802         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
803 
804         ds = new DirectoryScanner();
805 
806         ds.setBasedir(basedir);
807         ds.setExcludes(
808             new String[] {
809                 "**\\tools\\ext_tmpl\\**", "**\\*_IW.java",
810                 "**\\test\\**\\*PersistenceTest.java"
811             });
812         ds.setIncludes(
813             new String[] {
814                 "**\\model\\BaseModel.java",
815                 "**\\model\\impl\\BaseModelImpl.java",
816                 "**\\service\\base\\PrincipalBean.java",
817                 "**\\service\\http\\*HttpTest.java",
818                 "**\\service\\http\\*SoapTest.java",
819                 "**\\service\\http\\TunnelUtil.java",
820                 "**\\service\\impl\\*.java", "**\\service\\jms\\*.java",
821                 "**\\service\\permission\\*.java",
822                 "**\\service\\persistence\\BasePersistence.java",
823                 "**\\service\\persistence\\BatchSession*.java",
824                 "**\\service\\persistence\\*FinderImpl.java",
825                 "**\\service\\persistence\\impl\\BasePersistenceImpl.java",
826                 "**\\portal-impl\\test\\**\\*.java",
827                 "**\\portal-service\\**\\liferay\\counter\\**.java",
828                 "**\\portal-service\\**\\liferay\\documentlibrary\\**.java",
829                 "**\\portal-service\\**\\liferay\\lock\\**.java",
830                 "**\\portal-service\\**\\liferay\\mail\\**.java",
831                 "**\\util-bridges\\**\\*.java"
832             });
833 
834         ds.scan();
835 
836         list.addAll(ListUtil.fromArray(ds.getIncludedFiles()));
837 
838         return list.toArray(new String[list.size()]);
839     }
840 
841     private static String _getTaglibRegex(String quoteType) {
842         StringBuilder sb = new StringBuilder();
843 
844         sb.append("<(");
845 
846         for (int i = 0; i < _TAG_LIBRARIES.length; i++) {
847             sb.append(_TAG_LIBRARIES[i]);
848             sb.append(StringPool.PIPE);
849         }
850 
851         sb.deleteCharAt(sb.length() - 1);
852         sb.append("):([^>]|%>)*");
853         sb.append(quoteType);
854         sb.append("<%=[^>]*");
855         sb.append(quoteType);
856         sb.append("[^>]*%>");
857         sb.append(quoteType);
858         sb.append("([^>]|%>)*>");
859 
860         return sb.toString();
861     }
862 
863     private static void _readExclusions() throws IOException {
864         _exclusions = new Properties();
865 
866         ClassLoader classLoader = SourceFormatter.class.getClassLoader();
867 
868         String sourceFormatterExclusions = System.getProperty(
869             "source-formatter-exclusions",
870             "com/liferay/portal/tools/dependencies/" +
871                 "source_formatter_exclusions.properties");
872 
873         URL url = classLoader.getResource(sourceFormatterExclusions);
874 
875         if (url == null) {
876             return;
877         }
878 
879         InputStream is = url.openStream();
880 
881         _exclusions.load(is);
882 
883         is.close();
884     }
885 
886     private static final String[] _TAG_LIBRARIES = new String[] {
887         "c", "html", "jsp", "liferay-portlet", "liferay-security",
888         "liferay-theme", "liferay-ui", "liferay-util", "portlet", "struts",
889         "tiles"
890     };
891 
892     private static FileImpl _fileUtil = FileImpl.getInstance();
893     private static Properties _exclusions;
894     private static Pattern _xssPattern = Pattern.compile(
895         "String\\s+([^\\s]+)\\s*=\\s*ParamUtil\\.getString\\(");
896 
897 }
898