1 26 27 package org.objectweb.jonas.ant; 28 29 import java.io.File ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 import org.apache.tools.ant.BuildException; 35 import org.apache.tools.ant.Project; 36 import org.apache.tools.ant.Task; 37 import org.apache.tools.ant.taskdefs.Copy; 38 import org.apache.tools.ant.types.FileSet; 39 40 import org.objectweb.jonas.ant.cluster.Common; 41 import org.objectweb.jonas.ant.cluster.ClusterTasks; 42 import org.objectweb.jonas.ant.cluster.EjbLevel; 43 import org.objectweb.jonas.ant.cluster.WebLevel; 44 45 import org.objectweb.jonas.ant.jonasbase.BaseTaskItf; 46 import org.objectweb.jonas.ant.jonasbase.Tasks; 47 48 52 public class JOnASClusterConfigTask extends Task { 53 54 57 private static final String ARCH_BOTH_WEB_EJB = "bothWebEjb"; 58 59 62 private static final String ARCH_DIFF_WEB_EJB = "diffWebEjb"; 63 64 67 private File jonasRoot = null; 68 69 72 private String destDirPrefix = null; 73 74 77 private String arch = null; 78 79 82 private int webInstNb = -1; 83 84 87 private int ejbInstNb = -1; 88 89 92 private boolean onlyUpdate = false; 93 94 97 private List tasks = null; 98 99 100 103 public JOnASClusterConfigTask() { 104 tasks = new ArrayList (); 105 } 106 107 111 public void execute() { 112 if (jonasRoot == null) { 113 throw new BuildException("jonasRoot element is not set"); 114 } 115 116 if (destDirPrefix == null) { 117 throw new BuildException("destDirPrefix element is not set"); 118 } 119 120 if (jonasRoot.getPath().equals(destDirPrefix)) { 121 throw new BuildException("jonasRoot and destDirPrefix is the same path !"); 122 } 123 124 for (int i = 1; i <= webInstNb + ejbInstNb; i++) { 126 127 String destDir = ClusterTasks.getDestDir(destDirPrefix, i); 128 File destDirFile = new File (destDir); 129 File jprops = new File (destDir + File.separator + "conf" + File.separator + "jonas.properties"); 130 131 if (onlyUpdate) { 132 if (jprops.exists()) { 133 log("Only updating JONAS_BASE in the directory '" + destDir + "' from source directory '" + jonasRoot + "'", 134 Project.MSG_INFO); 135 JOnASAntTool.updateJonasBase(this, jonasRoot, destDirFile); 136 137 return; 138 } else { 139 throw new BuildException("JOnAS base directory '" + destDir + "' doesn't exists. Cannot update."); 140 } 141 } 142 143 log("Creating JONAS_BASE in the directory '" + destDir + "' from source directory '" + jonasRoot + "'", 144 Project.MSG_INFO); 145 Copy copy = new Copy(); 146 JOnASAntTool.configure(this, copy); 147 copy.setTodir(destDirFile); 148 FileSet fileSet = new FileSet(); 149 fileSet.setDir(new File (new File (jonasRoot, "templates"), "conf")); 150 copy.addFileset(fileSet); 151 copy.setOverwrite(true); 152 copy.execute(); 153 } 154 155 for (Iterator it = tasks.iterator(); it.hasNext();) { 157 BaseTaskItf task = (BaseTaskItf) it.next(); 158 task.setJonasRoot(jonasRoot); 159 JOnASAntTool.configure(this, (Task) task); 160 String info = task.getLogInfo(); 161 if (info != null) { 162 log(info, Project.MSG_INFO); 163 } 164 165 task.execute(); 166 } 167 168 for (int i = 1; i <= webInstNb + ejbInstNb; i++) { 170 String destDir = ClusterTasks.getDestDir(destDirPrefix, i); 171 File destDirFile = new File (destDir); 172 JOnASAntTool.updateJonasBase(this, jonasRoot, destDirFile); 173 } 174 } 175 176 177 181 public void addTasks(Tasks subTasks) { 182 if (subTasks != null) { 183 for (Iterator it = subTasks.getTasks().iterator(); it.hasNext();) { 184 tasks.add(it.next()); 185 } 186 } 187 } 188 189 193 public void setDestDirPrefix(String destDirPrefix) { 194 this.destDirPrefix = destDirPrefix; 195 } 196 197 201 public void setJonasRoot(File jonasRoot) { 202 this.jonasRoot = jonasRoot; 203 } 204 205 209 public void setArch(String arch) { 210 this.arch = arch; 211 } 212 213 217 public void setWebInstNb(int webInstNb) { 218 this.webInstNb = webInstNb; 219 } 220 221 225 public void setEjbInstNb(int ejbInstNb) { 226 this.ejbInstNb = ejbInstNb; 227 } 228 229 233 public void addConfiguredCommon(Common common) { 234 common.setRootTask(this); 235 common.setDestDirPrefix(destDirPrefix); 236 common.setDestDirSuffixIndFirst(1); 237 common.setDestDirSuffixIndLast(webInstNb + ejbInstNb); 238 common.setArch(arch); 239 common.generatesTasks(); 240 addTasks(common); 241 } 242 243 249 public void addConfiguredWebLevel(WebLevel webLevel) { 250 webLevel.setRootTask(this); 251 webLevel.setDestDirPrefix(destDirPrefix); 252 webLevel.setArch(arch); 253 254 if (arch.compareTo(ARCH_BOTH_WEB_EJB) == 0) { 255 webLevel.setDestDirSuffixIndFirst(1); 256 webLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb); 257 } else { 258 webLevel.setDestDirSuffixIndFirst(1); 259 webLevel.setDestDirSuffixIndLast(webInstNb); 260 } 261 webLevel.generatesTasks(); 262 addTasks(webLevel); 263 } 264 265 271 public void addConfiguredEjbLevel(EjbLevel ejbLevel) { 272 ejbLevel.setRootTask(this); 273 ejbLevel.setDestDirPrefix(destDirPrefix); 274 ejbLevel.setArch(arch); 275 276 if (arch.compareTo(ARCH_BOTH_WEB_EJB) == 0) { 277 ejbLevel.setDestDirSuffixIndFirst(1); 278 ejbLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb); 279 } else { 280 ejbLevel.setDestDirSuffixIndFirst(webInstNb + 1); 281 ejbLevel.setDestDirSuffixIndLast(webInstNb + ejbInstNb); 282 } 283 ejbLevel.generatesTasks(); 284 addTasks(ejbLevel); 285 } 286 287 291 public void setUpdate(boolean onlyUpdate) { 292 this.onlyUpdate = onlyUpdate; 293 } 294 295 } | Popular Tags |