1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.kernel.xml.Document;
20  import com.liferay.portal.kernel.xml.Element;
21  import com.liferay.portal.util.FileImpl;
22  import com.liferay.portal.xml.DocumentImpl;
23  import com.liferay.portal.xml.ElementImpl;
24  import com.liferay.util.xml.DocUtil;
25  
26  import java.util.Arrays;
27  
28  import org.apache.tools.ant.DirectoryScanner;
29  
30  import org.dom4j.DocumentHelper;
31  
32  /**
33   * <a href="ExtInfoBuilder.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class ExtInfoBuilder {
38  
39      public static void main(String[] args) throws Exception {
40          if (args.length == 3) {
41              new ExtInfoBuilder(args[0], args[1], args[2]);
42          }
43          else {
44              throw new IllegalArgumentException();
45          }
46      }
47  
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                  ".svn/**", "**/.svn/**", "ext-impl/ext-impl.jar",
58                  "ext-impl/src/**", "ext-service/ext-service.jar",
59                  "ext-service/src/**", "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 = new ElementImpl(
75              DocumentHelper.createElement("ext-info"));
76  
77          Document document = new DocumentImpl(DocumentHelper.createDocument());
78  
79          document.setRootElement(rootElement);
80  
81          DocUtil.add(rootElement, "servlet-context-name", servletContextName);
82  
83          Element filesElement = rootElement.addElement("files");
84  
85          for (String file : files) {
86              DocUtil.add(
87                  filesElement, "file",
88                  StringUtil.replace(
89                      file, StringPool.BACK_SLASH, StringPool.SLASH));
90          }
91  
92          _fileUtil.write(
93              outputDir + "/ext-" + servletContextName + ".xml",
94              document.formattedString());
95      }
96  
97      private static FileImpl _fileUtil = FileImpl.getInstance();
98  
99  }