001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Benoit Pelletier
022: * --------------------------------------------------------------------------
023: * $Id: JOnASAntTool.java 7884 2006-01-11 08:30:02Z pelletib $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ant;
026:
027: import java.io.File;
028:
029: import org.apache.tools.ant.Project;
030: import org.apache.tools.ant.Task;
031: import org.apache.tools.ant.types.FileSet;
032: import org.apache.tools.ant.types.PatternSet.NameEntry;
033:
034: import org.objectweb.jonas.ant.jonasbase.Apps;
035: import org.objectweb.jonas.ant.jonasbase.Archives;
036: import org.objectweb.jonas.ant.jonasbase.Ejbjars;
037: import org.objectweb.jonas.ant.jonasbase.Rars;
038: import org.objectweb.jonas.ant.jonasbase.Wars;
039:
040: /**
041: * Common constants or methods used by several classes of the package
042: * @author Benoit Pelletier
043: */
044: public class JOnASAntTool {
045:
046: /**
047: * Name of JOnAS configuration file
048: */
049: public static final String JONAS_CONF_FILE = "jonas.properties";
050:
051: /**
052: * Name of Joram configuration file
053: */
054: public static final String JORAM_CONF_FILE = "a3servers.xml";
055:
056: /**
057: * Name of Joram admin configuration file (resource adaptor)
058: */
059: public static final String JORAM_ADMIN_CONF_FILE = "joramAdmin.xml";
060:
061: /**
062: * Name of Carol configuration file
063: */
064: public static final String CAROL_CONF_FILE = "carol.properties";
065:
066: /**
067: * Name of Tomcat configuration file
068: */
069: public static final String TOMCAT_CONF_FILE = "server.xml";
070:
071: /**
072: * Name of Tomcat configuration file
073: */
074: public static final String JETTY_CONF_FILE = "jetty5.xml";
075:
076: /**
077: * Name of P6Spy configuration file
078: */
079: public static final String P6SPY_CONF_FILE = "spy.properties";
080:
081: /**
082: * List of Wars to copy for each JONAS_BASE
083: */
084: public static final String[] WARS_LIST = new String[] {
085: "juddi.war", "autoload/jonasAdmin.war" };
086:
087: /**
088: * List of Rars to copy for each JONAS_BASE
089: */
090: public static final String[] RARS_LIST = new String[] {
091: "autoload/JOnAS_jdbcCP.rar", "autoload/JOnAS_jdbcDM.rar",
092: "autoload/JOnAS_jdbcDS.rar", "autoload/JOnAS_jdbcXA.rar" };
093:
094: /**
095: * List of EjbJars to copy for each JONAS_BASE
096: */
097: public static final String[] EJBJARS_LIST = new String[] { "" };
098:
099: /**
100: * List of Apps to copy for each JONAS_BASE
101: */
102: public static final String[] APPS_LIST = new String[] { "autoload/mejb.ear" };
103:
104: /**
105: * Private constructor for tool class
106: */
107: private JOnASAntTool() {
108:
109: }
110:
111: /**
112: * Update the JONAS_BASE directory with ejbjars, webapps, rars, etc.
113: * @param antTask target task
114: * @param jonasRoot JONAS_ROOT
115: * @param destDir destination directory
116: **/
117: public static void updateJonasBase(Task antTask, File jonasRoot,
118: File destDir) {
119: Archives wars = new Wars();
120: updateJonasBaseForArchives(antTask, jonasRoot, destDir, wars,
121: "webapps", WARS_LIST);
122:
123: Archives ejbjars = new Ejbjars();
124: updateJonasBaseForArchives(antTask, jonasRoot, destDir,
125: ejbjars, "ejbjars", EJBJARS_LIST);
126:
127: Archives rars = new Rars();
128: updateJonasBaseForArchives(antTask, jonasRoot, destDir, rars,
129: "rars", RARS_LIST);
130:
131: Archives apps = new Apps();
132: updateJonasBaseForArchives(antTask, jonasRoot, destDir, apps,
133: "apps", APPS_LIST);
134:
135: }
136:
137: /**
138: * Update JONAS_BASE with given archives with lists of includes
139: * @param antTask target task
140: * @param jonasRoot JONAS_ROOT
141: * @param destDir destination directory
142: * @param archives tasks (webapps, rars, ejbjars)
143: * @param folderName where to put files
144: * @param listOfIncludes files to include
145: */
146: public static void updateJonasBaseForArchives(Task antTask,
147: File jonasRoot, File destDir, Archives archives,
148: String folderName, String[] listOfIncludes) {
149: configure(antTask, archives);
150: archives.setDestDir(destDir);
151: FileSet fileSet = new FileSet();
152: fileSet.setDir(new File(jonasRoot, folderName));
153: for (int f = 0; f < listOfIncludes.length; f++) {
154: NameEntry ne = fileSet.createInclude();
155: ne.setName(listOfIncludes[f]);
156: }
157: archives.addFileset(fileSet);
158: archives.setOverwrite(true);
159: String info = archives.getLogInfo();
160: if (info != null) {
161: antTask.log(info, Project.MSG_INFO);
162: }
163: archives.execute();
164: }
165:
166: /**
167: * Configure the given task by setting name, project root, etc
168: * @param srcTask source task
169: * @param dstTask destination task
170: */
171: public static void configure(Task srcTask, Task dstTask) {
172: dstTask.setTaskName(srcTask.getTaskName());
173: dstTask.setProject(srcTask.getProject());
174: }
175:
176: /**
177: * Delete a file. If the file is a directory, delete recursivly all the
178: * files inside.
179: * @param aFile file to delete.
180: */
181: public static void deleteAllFiles(File aFile) {
182: if (aFile.isDirectory()) {
183: File someFiles[] = aFile.listFiles();
184: for (int i = 0; i < someFiles.length; i++) {
185: deleteAllFiles(someFiles[i]);
186: }
187: }
188: aFile.delete();
189: }
190:
191: }
|