1 37 package net.sourceforge.cruisecontrol.builders; 38 39 import java.util.ArrayList ; 40 import java.util.Hashtable ; 41 import java.util.List ; 42 43 import junit.framework.TestCase; 44 import net.sourceforge.cruisecontrol.CruiseControlException; 45 import net.sourceforge.cruisecontrol.testutil.TestUtil; 46 47 public class AntScriptTest extends TestCase { 48 private AntScript script; 49 private AntBuilder unixBuilder; 50 private AntBuilder windowsBuilder; 51 private Hashtable properties; 52 private static final boolean USE_LOGGER = true; 53 private static final boolean USE_SCRIPT = true; 54 private static final boolean IS_WINDOWS = true; 55 private static final String UNIX_PATH = "/usr/java/jdk1.5.0/lib/tools.jar:" 56 + "/home/joris/java/cruisecontrol-2.2/main/dist/cruisecontrol.jar:" 57 + "/home/joris/java/cruisecontrol-2.2/main/lib/log4j.jar:" 58 + "/home/joris/java/cruisecontrol-2.2/main/lib/jdom.jar:" 59 + "/home/joris/java/cruisecontrol-2.2/main/lib/ant:" 60 + "/home/joris/java/cruisecontrol-2.2/main/lib/ant/ant.jar:" 61 + "/home/joris/java/cruisecontrol-2.2/main/lib/ant/ant-launcher.jar:" 62 + "/home/joris/java/cruisecontrol-2.2/main/lib/xerces.jar:" 63 + "/home/joris/java/cruisecontrol-2.2/main/lib/xalan.jar:" 64 + "/home/joris/java/cruisecontrol-2.2/main/lib/jakarta-oro-2.0.3.jar:" 65 + "/home/joris/java/cruisecontrol-2.2/main/lib/mail.jar:" 66 + "/home/joris/java/cruisecontrol-2.2/main/lib/junit.jar:" 67 + "/home/joris/java/cruisecontrol-2.2/main/lib/activation.jar:" 68 + "/home/joris/java/cruisecontrol-2.2/main/lib/commons-net-1.1.0.jar:" 69 + "/home/joris/java/cruisecontrol-2.2/main/lib/starteam-sdk.jar:" 70 + "/home/joris/java/cruisecontrol-2.2/main/lib/mx4j.jar:" 71 + "/home/joris/java/cruisecontrol-2.2/main/lib/mx4j-tools.jar:" 72 + "/home/joris/java/cruisecontrol-2.2/main/lib/mx4j-remote.jar:" 73 + "/home/joris/java/cruisecontrol-2.2/main/lib/smack.jar:."; 74 private static final String WINDOWS_PATH = "C:\\Progra~1\\IBM\\WSAD\\tools.jar;" 75 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\dist\\cruisecontrol.jar;" 76 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\log4j.jar;" 77 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\jdom.jar;" 78 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\ant;" 79 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\ant\\ant.jar;" 80 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\ant\\ant-launcher.jar;" 81 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\xerces.jar;" 82 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\xalan.jar;" 83 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\jakarta-oro-2.0.3.jar;" 84 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\mail.jar;" 85 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\junit.jar;" 86 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\activation.jar;" 87 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\commons-net-1.1.0.jar;" 88 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\starteam-sdk.jar;" 89 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\mx4j.jar;" 90 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\mx4j-tools.jar;" 91 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\mx4j-remote.jar;" 92 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\smack.jar;" 93 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\comm.jar;" 94 + "C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\x10.jar;."; 95 96 protected void setUp() throws Exception { 97 script = new AntScript(); 98 99 100 properties = new Hashtable (); 101 properties.put("label", "200.1.23"); 102 103 script.setBuildProperties(properties); 105 script.setArgs(new ArrayList ()); 106 script.setProperties(new ArrayList ()); 107 script.setBuildFile("buildfile"); 108 script.setTarget("target"); 109 110 unixBuilder = new AntBuilder() { 111 protected String getSystemClassPath() { 112 return UNIX_PATH; 113 } 114 }; 115 unixBuilder.setTarget("target"); 116 unixBuilder.setBuildFile("buildfile"); 117 118 windowsBuilder = new AntBuilder() { 119 protected String getSystemClassPath() { 120 return WINDOWS_PATH; 121 } 122 }; 123 windowsBuilder.setTarget("target"); 124 windowsBuilder.setBuildFile("buildfile"); 125 } 126 127 public void testGetAntLauncherJarLocationForWindows() throws Exception { 128 assertEquals("C:\\Java\\cruisecontrol-2.2\\main\\bin\\\\..\\lib\\ant\\ant-launcher.jar", 129 script.getAntLauncherJarLocation(WINDOWS_PATH, IS_WINDOWS)); 130 } 131 132 public void testGetAntLauncherJarLocationForUnix() throws Exception { 133 assertEquals("/home/joris/java/cruisecontrol-2.2/main/lib/ant/ant-launcher.jar", 134 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS)); 135 } 136 137 public void testGetCommandLineArgs() throws CruiseControlException { 138 String [] resultInfo = 139 { 140 "java", 141 "-classpath", 142 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 143 "org.apache.tools.ant.launch.Launcher", 144 "-lib", 145 UNIX_PATH, 146 "-listener", 147 "org.apache.tools.ant.XmlLogger", 148 "-DXmlLogger.file=log.xml", 149 "-Dlabel=200.1.23", 150 "-buildfile", 151 "buildfile", 152 "target" }; 153 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 154 script.setBuildProperties(properties); 155 script.setUseLogger(!USE_LOGGER); 156 script.setWindows(!IS_WINDOWS); 157 script.setSystemClassPath(UNIX_PATH); 158 159 TestUtil.assertArray( 160 "Logger set to INFO", 161 resultInfo, 162 script.buildCommandline().getCommandline()); 163 164 165 String [] resultLogger = 166 { 167 "java", 168 "-classpath", 169 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 170 "org.apache.tools.ant.launch.Launcher", 171 "-lib", 172 UNIX_PATH, 173 "-logger", 174 "org.apache.tools.ant.XmlLogger", 175 "-logfile", 176 "log.xml", 177 "-Dlabel=200.1.23", 178 "-buildfile", 179 "buildfile", 180 "target" }; 181 script.setBuildProperties(properties); 182 script.setUseLogger(USE_LOGGER); 183 script.setWindows(!IS_WINDOWS); 184 script.setUseScript(!USE_SCRIPT); 185 TestUtil.assertArray( 186 "Using result Logger", 187 resultLogger, 188 script.buildCommandline().getCommandline()); 189 190 191 } 192 193 public void testGetCommandLineArgs_EmptyLogger() throws CruiseControlException { 194 String [] resultInfo = 195 { 196 "java.exe", 197 "-classpath", 198 script.getAntLauncherJarLocation(WINDOWS_PATH, IS_WINDOWS), 199 "org.apache.tools.ant.launch.Launcher", 200 "-lib", 201 WINDOWS_PATH, 202 "-listener", 203 "org.apache.tools.ant.XmlLogger", 204 "-DXmlLogger.file=log.xml", 205 "-buildfile", 206 "buildfile", 207 "target" }; 208 properties.put("label", ""); 209 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 210 script.setBuildProperties(properties); 211 script.setUseLogger(!USE_LOGGER); 212 script.setWindows(IS_WINDOWS); 213 script.setUseScript(!USE_SCRIPT); 214 script.setSystemClassPath(WINDOWS_PATH); 215 TestUtil.assertArray( 216 "resultInfo", 217 resultInfo, 218 script.buildCommandline().getCommandline()); 219 220 221 String [] resultLogger = 222 { 223 "java", 224 "-classpath", 225 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 226 "org.apache.tools.ant.launch.Launcher", 227 "-lib", 228 UNIX_PATH, 229 "-logger", 230 "org.apache.tools.ant.XmlLogger", 231 "-logfile", 232 "log.xml", 233 "-buildfile", 234 "buildfile", 235 "target" }; 236 script.setUseLogger(USE_LOGGER); 237 script.setUseScript(!USE_SCRIPT); 238 script.setWindows(!IS_WINDOWS); 239 script.setSystemClassPath(UNIX_PATH); 240 TestUtil.assertArray( 241 "resultLogger", 242 resultLogger, 243 script.buildCommandline().getCommandline()); 244 245 } 246 247 public void testGetCommandLineArgs_Debug() throws CruiseControlException { 248 String [] resultDebug = 249 { 250 "java", 251 "-classpath", 252 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 253 "org.apache.tools.ant.launch.Launcher", 254 "-lib", 255 UNIX_PATH, 256 "-logger", 257 "org.apache.tools.ant.XmlLogger", 258 "-logfile", 259 "log.xml", 260 "-debug", 261 "-Dlabel=200.1.23", 262 "-buildfile", 263 "buildfile", 264 "target" }; 265 266 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 267 script.setBuildProperties(properties); 268 script.setUseLogger(USE_LOGGER); 269 script.setWindows(!IS_WINDOWS); 270 script.setUseScript(!USE_SCRIPT); 271 script.setUseDebug(true); 272 script.setSystemClassPath(UNIX_PATH); 273 TestUtil.assertArray( 274 "resultDebug", 275 resultDebug, 276 script.buildCommandline().getCommandline()); 277 278 } 279 280 public void testGetCommandLineArgs_DebugWithListener() throws CruiseControlException { 281 String [] resultDebug = 282 { 283 "java", 284 "-classpath", 285 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 286 "org.apache.tools.ant.launch.Launcher", 287 "-lib", 288 UNIX_PATH, 289 "-listener", 290 "org.apache.tools.ant.XmlLogger", 291 "-DXmlLogger.file=log.xml", 292 "-debug", 293 "-Dlabel=200.1.23", 294 "-buildfile", 295 "buildfile", 296 "target" }; 297 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 298 script.setBuildProperties(properties); 299 script.setUseLogger(!USE_LOGGER); 300 script.setWindows(!IS_WINDOWS); 301 script.setUseScript(!USE_SCRIPT); 302 script.setSystemClassPath(UNIX_PATH); 303 script.setUseDebug(true); 304 TestUtil.assertArray( 305 "debug with listener", 306 resultDebug, 307 script.buildCommandline().getCommandline()); 308 } 309 310 public void testGetCommandLineArgs_Quiet() throws CruiseControlException { 311 String [] resultQuiet = 312 { 313 "java", 314 "-classpath", 315 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 316 "org.apache.tools.ant.launch.Launcher", 317 "-lib", 318 UNIX_PATH, 319 "-logger", 320 "org.apache.tools.ant.XmlLogger", 321 "-logfile", 322 "log.xml", 323 "-quiet", 324 "-Dlabel=200.1.23", 325 "-buildfile", 326 "buildfile", 327 "target" }; 328 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 329 script.setBuildProperties(properties); 330 script.setUseLogger(USE_LOGGER); 331 script.setWindows(!IS_WINDOWS); 332 script.setUseScript(!USE_SCRIPT); 333 script.setSystemClassPath(UNIX_PATH); 334 script.setUseQuiet(true); 335 TestUtil.assertArray( 336 "resultQuiet", 337 resultQuiet, 338 script.buildCommandline().getCommandline()); 339 340 } 341 342 public void testGetCommandLineArgs_MaxMemory() throws CruiseControlException { 343 String [] resultWithMaxMemory = 344 { 345 "java", 346 "-Xmx256m", 347 "-classpath", 348 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 349 "org.apache.tools.ant.launch.Launcher", 350 "-lib", 351 UNIX_PATH, 352 "-listener", 353 "org.apache.tools.ant.XmlLogger", 354 "-DXmlLogger.file=log.xml", 355 "-Dlabel=200.1.23", 356 "-buildfile", 357 "buildfile", 358 "target" }; 359 AntBuilder.JVMArg arg = (AntBuilder.JVMArg) unixBuilder.createJVMArg(); 360 arg.setArg("-Xmx256m"); 361 List args = new ArrayList (); 362 args.add(arg); 363 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 364 script.setBuildProperties(properties); 365 script.setUseLogger(!USE_LOGGER); 366 script.setWindows(!IS_WINDOWS); 367 script.setUseScript(!USE_SCRIPT); 368 script.setArgs(args); 369 script.setSystemClassPath(UNIX_PATH); 370 TestUtil.assertArray( 371 "resultWithMaxMemory", 372 resultWithMaxMemory, 373 script.buildCommandline().getCommandline()); 374 375 } 376 377 public void testGetCommandLineArgs_MaxMemoryAndProperty() throws CruiseControlException { 378 String [] resultWithMaxMemoryAndProperty = 379 { 380 "java", 381 "-Xmx256m", 382 "-classpath", 383 script.getAntLauncherJarLocation(UNIX_PATH, !IS_WINDOWS), 384 "org.apache.tools.ant.launch.Launcher", 385 "-lib", 386 UNIX_PATH, 387 "-listener", 388 "org.apache.tools.ant.XmlLogger", 389 "-DXmlLogger.file=log.xml", 390 "-Dlabel=200.1.23", 391 "-Dfoo=bar", 392 "-buildfile", 393 "buildfile", 394 "target" }; 395 AntBuilder.JVMArg arg = (AntBuilder.JVMArg) unixBuilder.createJVMArg(); 396 arg.setArg("-Xmx256m"); 397 Property prop = unixBuilder.createProperty(); 398 prop.setName("foo"); 399 prop.setValue("bar"); 400 401 List args = new ArrayList (); 402 args.add(arg); 403 List props = new ArrayList (); 404 props.add(prop); 405 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 406 script.setBuildProperties(properties); 407 script.setUseLogger(!USE_LOGGER); 408 script.setWindows(!IS_WINDOWS); 409 script.setUseScript(!USE_SCRIPT); 410 script.setArgs(args); 411 script.setProperties(props); 412 script.setSystemClassPath(UNIX_PATH); 413 TestUtil.assertArray( 414 "resultWithMaxMemoryAndProperty", 415 resultWithMaxMemoryAndProperty, 416 script.buildCommandline().getCommandline()); 417 } 418 419 public void testGetCommandLineArgs_BatchFile() throws CruiseControlException { 420 String [] resultBatchFile = 421 { 422 "ant.bat", 423 "-listener", 424 "org.apache.tools.ant.XmlLogger", 425 "-DXmlLogger.file=log.xml", 426 "-Dlabel=200.1.23", 427 "-buildfile", 428 "buildfile", 429 "target" }; 430 script.setAntScript("ant.bat"); 431 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 432 script.setBuildProperties(properties); 433 script.setUseLogger(!USE_LOGGER); 434 script.setWindows(IS_WINDOWS); 435 script.setUseScript(USE_SCRIPT); 436 TestUtil.assertArray( 437 "resultBatchFile", 438 resultBatchFile, 439 script.buildCommandline().getCommandline()); 440 441 } 442 443 public void testGetCommandLineArgs_ShellScript() throws CruiseControlException { 444 String [] resultShellScript = 445 { 446 "ant.sh", 447 "-listener", 448 "org.apache.tools.ant.XmlLogger", 449 "-DXmlLogger.file=log.xml", 450 "-Dlabel=200.1.23", 451 "-buildfile", 452 "buildfile", 453 "target" }; 454 script.setAntScript("ant.sh"); 455 script.setLoggerClassName(AntBuilder.DEFAULT_LOGGER); 456 script.setBuildProperties(properties); 457 script.setUseLogger(!USE_LOGGER); 458 script.setWindows(!IS_WINDOWS); 459 script.setUseScript(USE_SCRIPT); 460 TestUtil.assertArray( 461 "resultShellScript", 462 resultShellScript, 463 script.buildCommandline().getCommandline()); 464 465 } 466 467 public void testGetCommandLineArgs_AlternateLogger() throws CruiseControlException { 468 String [] args = 469 { 470 "java.exe", 471 "-classpath", 472 script.getAntLauncherJarLocation(WINDOWS_PATH, IS_WINDOWS), 473 "org.apache.tools.ant.launch.Launcher", 474 "-lib", 475 WINDOWS_PATH, 476 "-listener", 477 "com.canoo.Logger", 478 "-DXmlLogger.file=log.xml", 479 "-Dlabel=200.1.23", 480 "-buildfile", 481 "buildfile", 482 "target" }; 483 script.setLoggerClassName("com.canoo.Logger"); 484 script.setBuildProperties(properties); 485 script.setUseLogger(!USE_LOGGER); 486 script.setWindows(IS_WINDOWS); 487 script.setUseScript(!USE_SCRIPT); 488 script.setSystemClassPath(WINDOWS_PATH); 489 490 491 TestUtil.assertArray( 492 "args", 493 args, 494 script.buildCommandline().getCommandline()); 495 496 } 497 498 499 } 500 | Popular Tags |