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.kernel.xml.Document;
020    import com.liferay.portal.kernel.xml.Element;
021    import com.liferay.portal.util.FileImpl;
022    import com.liferay.portal.xml.DocumentImpl;
023    import com.liferay.portal.xml.ElementImpl;
024    import com.liferay.util.xml.DocUtil;
025    
026    import java.util.Arrays;
027    
028    import org.apache.tools.ant.DirectoryScanner;
029    
030    import org.dom4j.DocumentHelper;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class ExtInfoBuilder {
036    
037            public static void main(String[] args) throws Exception {
038                    if (args.length == 3) {
039                            new ExtInfoBuilder(args[0], args[1], args[2]);
040                    }
041                    else {
042                            throw new IllegalArgumentException();
043                    }
044            }
045    
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 = new ElementImpl(
073                            DocumentHelper.createElement("ext-info"));
074    
075                    Document document = new DocumentImpl(DocumentHelper.createDocument());
076    
077                    document.setRootElement(rootElement);
078    
079                    DocUtil.add(rootElement, "servlet-context-name", servletContextName);
080    
081                    Element filesElement = rootElement.addElement("files");
082    
083                    for (String file : files) {
084                            DocUtil.add(
085                                    filesElement, "file",
086                                    StringUtil.replace(
087                                            file, StringPool.BACK_SLASH, StringPool.SLASH));
088                    }
089    
090                    _fileUtil.write(
091                            outputDir + "/ext-" + servletContextName + ".xml",
092                            document.formattedString());
093            }
094    
095            private static FileImpl _fileUtil = FileImpl.getInstance();
096    
097    }