001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.tools;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.util.FileImpl;
020    import com.liferay.util.xml.DocUtil;
021    import com.liferay.util.xml.XMLFormatter;
022    
023    import java.util.Arrays;
024    
025    import org.apache.tools.ant.DirectoryScanner;
026    
027    import org.dom4j.Document;
028    import org.dom4j.DocumentHelper;
029    import org.dom4j.Element;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class ExtInfoBuilder {
035    
036            public static void main(String[] args) throws Exception {
037                    if (args.length == 3) {
038                            new ExtInfoBuilder(args[0], args[1], args[2]);
039                    }
040                    else {
041                            throw new IllegalArgumentException();
042                    }
043            }
044    
045            @SuppressWarnings("deprecation")
046            public ExtInfoBuilder(
047                            String basedir, String outputDir, String servletContextName)
048                    throws Exception {
049    
050                    DirectoryScanner ds = new DirectoryScanner();
051    
052                    ds.setBasedir(basedir);
053                    ds.setExcludes(
054                            new String[] {
055                                    ".svn/**", "**/.svn/**", "ext-impl/ext-impl.jar",
056                                    "ext-impl/src/**", "ext-service/ext-service.jar",
057                                    "ext-service/src/**", "ext-util-bridges/ext-util-bridges.jar",
058                                    "ext-util-bridges/src/**",
059                                    "ext-util-java/ext-util-java.jar",
060                                    "ext-util-java/src/**",
061                                    "ext-util-taglib/ext-util-taglib.jar",
062                                    "ext-util-taglib/src/**",
063                                    "liferay-plugin-package.properties"
064                            });
065    
066                    ds.scan();
067    
068                    String[] files = ds.getIncludedFiles();
069    
070                    Arrays.sort(files);
071    
072                    Element rootElement = DocumentHelper.createElement("ext-info");
073    
074                    Document document = DocumentHelper.createDocument(rootElement);
075    
076                    DocUtil.add(rootElement, "servlet-context-name", servletContextName);
077    
078                    Element filesElement = rootElement.addElement("files");
079    
080                    for (String file : files) {
081                            DocUtil.add(
082                                    filesElement, "file",
083                                    StringUtil.replace(
084                                            file, StringPool.BACK_SLASH, StringPool.SLASH));
085                    }
086    
087                    _fileUtil.write(
088                            outputDir + "/ext-" + servletContextName + ".xml",
089                            XMLFormatter.toString(document));
090            }
091    
092            private static FileImpl _fileUtil = FileImpl.getInstance();
093    
094    }