1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.tools;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  import com.liferay.portal.kernel.util.StringUtil;
19  import com.liferay.portal.util.FileImpl;
20  import com.liferay.util.xml.DocUtil;
21  import com.liferay.util.xml.XMLFormatter;
22  
23  import java.util.Arrays;
24  
25  import org.apache.tools.ant.DirectoryScanner;
26  
27  import org.dom4j.Document;
28  import org.dom4j.DocumentHelper;
29  import org.dom4j.Element;
30  
31  /**
32   * <a href="ExtInfoBuilder.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class ExtInfoBuilder {
37  
38      public static void main(String[] args) throws Exception {
39          if (args.length == 3) {
40              new ExtInfoBuilder(args[0], args[1], args[2]);
41          }
42          else {
43              throw new IllegalArgumentException();
44          }
45      }
46  
47      @SuppressWarnings("deprecation")
48      public ExtInfoBuilder(
49              String basedir, String outputDir, String servletContextName)
50          throws Exception {
51  
52          DirectoryScanner ds = new DirectoryScanner();
53  
54          ds.setBasedir(basedir);
55          ds.setExcludes(
56              new String[] {
57                  "ext-impl/ext-impl.jar", "ext-impl/src/**",
58                  "ext-service/ext-service.jar", "ext-service/src/**",
59                  "ext-util-bridges/ext-util-bridges.jar",
60                  "ext-util-bridges/src/**",
61                  "ext-util-java/ext-util-java.jar",
62                  "ext-util-java/src/**",
63                  "ext-util-taglib/ext-util-taglib.jar",
64                  "ext-util-taglib/src/**",
65                  "liferay-plugin-package.properties"
66              });
67  
68          ds.scan();
69  
70          String[] files = ds.getIncludedFiles();
71  
72          Arrays.sort(files);
73  
74          Element rootElement = DocumentHelper.createElement("ext-info");
75  
76          Document document = DocumentHelper.createDocument(rootElement);
77  
78          DocUtil.add(rootElement, "servlet-context-name", servletContextName);
79  
80          Element filesElement = rootElement.addElement("files");
81  
82          for (String file : files) {
83              DocUtil.add(
84                  filesElement, "file",
85                  StringUtil.replace(
86                      file, StringPool.BACK_SLASH, StringPool.SLASH));
87          }
88  
89          _fileUtil.write(
90              outputDir + "/ext-" + servletContextName + ".xml",
91              XMLFormatter.toString(document));
92      }
93  
94      private static FileImpl _fileUtil = FileImpl.getInstance();
95  
96  }