001 /** 002 * Copyright (c) 2000-2013 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/**", "ext-util-java/ext-util-java.jar", 059 "ext-util-java/src/**", "ext-util-taglib/ext-util-taglib.jar", 060 "ext-util-taglib/src/**", "liferay-plugin-package.properties" 061 }); 062 063 ds.scan(); 064 065 String[] files = ds.getIncludedFiles(); 066 067 Arrays.sort(files); 068 069 Element rootElement = new ElementImpl( 070 DocumentHelper.createElement("ext-info")); 071 072 Document document = new DocumentImpl(DocumentHelper.createDocument()); 073 074 document.setRootElement(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 document.formattedString()); 090 } 091 092 private static FileImpl _fileUtil = FileImpl.getInstance(); 093 094 }