1 19 20 package org.netbeans.nbbuild; 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.io.StringReader ; 24 import java.util.ArrayList ; 25 import java.util.regex.Matcher ; 26 import java.util.regex.Pattern ; 27 import javax.xml.parsers.*; 28 29 import org.netbeans.junit.*; 30 import org.w3c.dom.Document ; 31 import org.xml.sax.EntityResolver ; 32 import org.xml.sax.InputSource ; 33 import org.xml.sax.SAXException ; 34 35 36 40 public class ArchQuestionsTest extends NbTestCase implements EntityResolver { 41 42 private ArrayList msg = new ArrayList (); 43 44 public ArchQuestionsTest (String name) { 45 super (name); 46 } 47 48 public void testGeneratePreferencesArch() throws Exception { 49 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractResource("arch-preferences.xml"); 50 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 51 output.delete(); 52 53 54 55 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString( 56 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 57 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 58 "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 59 "<target name=\"all\" >" + 60 " <arch answers=\"" + answers + "\" output='" + output + "' />" + 61 "</target>" + 62 "</project>" 63 64 ); 65 PublicPackagesInProjectizedXMLTest.execute(f, new String [] { }); 66 67 assertTrue("File is generated", output.exists()); 68 69 String content = PublicPackagesInProjectizedXMLTest.readFile(output); 70 if (content.indexOf("resources-preferences") == -1) { 71 fail("resources-preferences shall be in output:\n" + content); 72 } 73 if (content.indexOf("answer-resources-preferences") == -1) { 74 fail("answer-resources-preferences shall be in output:\n" + content); 75 } 76 } 77 78 79 public void testGenerateArchFileWhenEmpty () throws Exception { 80 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString (""); 81 answers.delete (); 82 assertFalse ("Really deleted", answers.exists ()); 83 84 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 85 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 86 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 87 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 88 " <arch answers=\"" + answers + "\" output=\"x.html\" />" + 89 "<target name=\"all\" >" + 90 " " + 91 "</target>" + 92 "</project>" 93 94 ); 95 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { }); 96 97 assertTrue ("File is generated", answers.exists ()); 98 99 String content = PublicPackagesInProjectizedXMLTest.readFile(answers); 100 101 if (content.indexOf("module=") >= 0) { 102 fail("No mention of a module should be there anymore:\n" + content); 103 } 104 } 105 106 public void testGenerateArchFileWhenEmptyWithDefaultAnswerForNbDepsQuestion() throws Exception { 107 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString (""); 108 answers.delete (); 109 assertFalse ("Really deleted", answers.exists ()); 110 111 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 112 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 113 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 114 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 115 " <arch answers=\"" + answers + "\" output=\"x.html\" />" + 116 "<target name=\"all\" >" + 117 " " + 118 "</target>" + 119 "</project>" 120 121 ); 122 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { }); 123 124 assertTrue ("File is generated", answers.exists ()); 125 126 String res = PublicPackagesInProjectizedXMLTest.readFile(answers); 127 DocumentBuilderFactory fack = DocumentBuilderFactory.newInstance(); 128 fack.setValidating(false); 129 DocumentBuilder build = fack.newDocumentBuilder(); 130 build.setEntityResolver(this); 131 org.w3c.dom.Document dom; 132 try { 133 dom = build.parse(answers); 134 } catch (IOException ex) { 135 throw (IOException )new IOException (ex.getMessage() + "\n" + msg.toString()).initCause(ex); 136 } 137 138 org.w3c.dom.NodeList list = dom.getElementsByTagName("defaultanswer"); 139 assertTrue("There is at least one defaultanswer: " + res, list.getLength() > 0); 140 BIGLOOP: for (int i = 0; i < list.getLength(); i++) { 141 org.w3c.dom.Node n = list.item(i); 142 while (n != null) { 143 n = n.getParentNode(); 144 assertNotNull ("No parent node answer found: " + res, n); 145 146 if (n.getNodeName().equals ("answer")) { 147 String id = n.getAttributes().getNamedItem("id").getNodeValue(); 148 if (id.equals ("dep-nb")) { 149 return; 151 } 152 continue BIGLOOP; 153 } 154 } 155 } 156 157 fail ("dep-nb question should have a defaultanswer: " + res); 158 } 159 160 public void testDoNotCorruptTheFileWhenItExists() throws Exception { 161 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString ( 162 "<?xml version='1.0' encoding='UTF-8'?>\n" + 163 "<!--\n" + 164 "CDDL Notice\n" + 165 "-->\n" + 166 "\n" + 172 "<api-answers\n" + 173 "question-version='1.25'\n" + 174 "module='Input/Output System'\n" + 175 "author='jglick@netbeans.org'\n" + 176 ">\n" + 177 "\n" + 178 "<api-questions version='1.25'>\n" + 181 "<category id='arch' name='General Information'>\n" + 182 "<question id='arch-what' when='init' >\n" + 183 "What is this project good for?\n" + 184 "<hint>\n" + 185 "Please provide here a few lines describing the project, \n" + 186 "what problem it should solve, provide links to documentation, \n" + 187 "specifications, etc.\n" + 188 "</hint>\n" + 189 "</question>\n" + 190 "<question id='arch-overall' when='init'>\n" + 191 "Describe the overall architecture. \n" + 192 "<hint>\n" + 193 "What will be API for \n" + 194 "<a HREF='http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi'>\n" + 195 "clients and what support API</a>? \n" + 196 "What parts will be pluggable?\n" + 197 "How will plug-ins be registered? Please use <code><api type='export'/></code>\n" + 198 "to describe your general APIs.\n" + 199 "If possible please provide \n" + 200 "simple diagrams. \n" + 201 "</hint>\n" + 202 "</question>\n" + 203 "</category>\n" + 204 "</api-questions> \n" + 205 "\n" + 207 "\n" + 208 "<answer id='arch-what'>\n" + 209 "The Input/Output API is a small API module\n" + 210 "which contains <code>InputOutput</code> and related interfaces used in\n" + 211 "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n" + 212 "</answer>\n" + 213 "\n" + 214 "</api-answers> \n" 215 ); 216 217 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 218 219 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 220 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 221 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 222 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 223 " <arch answers=\"" + answers + "\" output='" + output + "' />" + 224 "<target name=\"all\" >" + 225 " " + 226 "</target>" + 227 "</project>" 228 229 ); 230 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { 231 "-Darch.generate=true", 232 "-Darch.private.disable.validation.for.test.purposes=true", 233 234 }); 235 236 assertTrue ("Answers still exists", answers.exists ()); 237 assertTrue ("Output file generated", output.exists ()); 238 239 String s1 = PublicPackagesInProjectizedXMLTest.readFile(answers); 240 if (s1.indexOf("answer id=\"arch-overall\"") == -1) { 241 fail ("There should be a answer template for arch-overall in answers: " + s1); 242 } 243 String s2 = PublicPackagesInProjectizedXMLTest.readFile(output); 244 if (s2.indexOf("question id=\"arch-overall\"") == -1) { 245 fail ("There should be a answer template for arch-overall in html output: " + s2); 246 } 247 } 248 249 250 public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified() throws Exception { 251 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString ( 252 "<?xml version='1.0' encoding='UTF-8'?>\n" + 253 "<!--\n" + 254 "CDDL Notice\n" + 255 "-->\n" + 256 "\n" + 262 "<api-answers\n" + 263 "question-version='1.25'\n" + 264 "module='Input/Output System'\n" + 265 "author='jglick@netbeans.org'\n" + 266 ">\n" + 267 "\n" + 268 "<api-questions version='1.25'>\n" + 271 "<category id='arch' name='General Information'>\n" + 272 "<question id='arch-what' when='init' >\n" + 273 "What is this project good for?\n" + 274 "<hint>\n" + 275 "Please provide here a few lines describing the project, \n" + 276 "what problem it should solve, provide links to documentation, \n" + 277 "specifications, etc.\n" + 278 "</hint>\n" + 279 "</question>\n" + 280 "<question id='arch-overall' when='init'>\n" + 281 "Describe the overall architecture. \n" + 282 "<hint>\n" + 283 "What will be API for \n" + 284 "<a HREF='http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi'>\n" + 285 "clients and what support API</a>? \n" + 286 "What parts will be pluggable?\n" + 287 "How will plug-ins be registered? Please use <code><api type='export'/></code>\n" + 288 "to describe your general APIs.\n" + 289 "If possible please provide \n" + 290 "simple diagrams. \n" + 291 "</hint>\n" + 292 "</question>\n" + 293 "</category>\n" + 294 "</api-questions> \n" + 295 "\n" + 297 "\n" + 298 "<answer id='arch-what'>\n" + 299 "The Input/Output API is a small API module\n" + 300 "which contains <code>InputOutput</code> and related interfaces used in\n" + 301 "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n" + 302 "</answer>\n" + 303 "\n" + 304 "</api-answers> \n" 305 ); 306 307 java.io.File apichanges = PublicPackagesInProjectizedXMLTest.extractString( 308 "<?xml version='1.0' encoding='UTF-8'?>\n" + 309 "<!--\n" + 310 "CDDL Notice\n" + 311 "-->\n" + 312 "<apichanges>\n" + 314 "<apidefs>\n" + 315 "<apidef name='nodes'>Nodes API</apidef>\n" + 316 "</apidefs>\n" + 317 "<changes>\n" + 318 "<change id='AbstractNode.setIconBaseWithExtension'>\n" + 319 "<api name='nodes'/>\n" + 320 "<summary>AbstractNode allows using different icon extensions</summary>\n" + 321 "<version major='6' minor='5'/>\n" + 322 "<date day='14' month='7' year='2005'/>\n" + 323 "<author login='pnejedly'/>\n" + 324 "<compatibility addition='yes' binary='compatible' source='compatible' semantic='compatible' deprecation='yes' deletion='no' modification='no'/>\n" + 325 "<description>\n" + 326 "Some description\n" + 327 "</description>\n" + 328 "<class package='org.openide.nodes' name='AbstractNode'/>\n" + 329 "<issue number='53461'/>\n" + 330 "</change> \n" + 331 "<change id='anotherChange'>\n" + 332 "<api name='nodes'/>\n" + 333 "<summary>Ble</summary>\n" + 334 "<version major='6' minor='3'/>\n" + 335 "<date day='14' month='3' year='2005'/>\n" + 336 "<author login='jtulach'/>\n" + 337 "<compatibility addition='yes' binary='compatible' source='compatible' semantic='compatible' deprecation='yes' deletion='no' modification='no'/>\n" + 338 "<description>\n" + 339 "Some description\n" + 340 "</description>\n" + 341 "<class package='org.openide.nodes' name='AbstractNode'/>\n" + 342 "<issue number='23461'/>\n" + 343 "</change> \n" + 344 "</changes>\n" + 345 "<htmlcontents>\n" + 346 "<head>\n" + 347 "<title>Change History for the Nodes API</title>\n" + 348 "<link rel='stylesheet' HREF='prose.css' type='text/css'/>\n" + 349 "</head>\n" + 350 "<body>\n" + 351 "<p class='overviewlink'>\n" + 352 "<a HREF='overview-summary.html'>Overview</a>\n" + 353 "</p>\n" + 354 "<h1>Introduction</h1>\n" + 355 "<h2>What do the Dates Mean?</h2>\n" + 356 "<p>The supplied dates indicate when the API change was made, on the CVS\n" + 357 "bug fix; this ought to be marked in this list.</p>\n" + 358 "<ul>\n" + 359 "<li>The <code>release41</code> branch was made on Apr 03 '05 for use in the NetBeans 4.1 release.\n" + 360 "Specification versions: 6.0 begins after this point.</li>\n" + 361 "<li>The <code>release40</code> branch was made on Nov 01 '04 for use in the NetBeans 4.0 release.\n" + 362 "Specification versions: 5.0 begins after this point.</li>\n" + 363 "</ul>\n" + 364 "<hr/>\n" + 365 "<standard-changelists module-code-name='org.openide.nodes'/>\n" + 366 "<hr/>\n" + 367 "<p>@FOOTER@</p>\n" + 368 "</body>\n" + 369 "</htmlcontents>\n" + 370 "</apichanges>\n" + 371 ""); 372 373 java.io.File xsl = PublicPackagesInProjectizedXMLTest.extractString( 374 "<?xml version='1.0' encoding='UTF-8' ?>\n" + 375 "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" + 376 "<xsl:output method='xml'/>\n" + 377 "<!-- Format random HTML elements as is: -->\n" + 378 "<xsl:template match='@*|node()'>\n" + 379 "<xsl:copy>\n" + 380 "<xsl:apply-templates select='@*|node()'/>\n" + 381 "</xsl:copy>\n" + 382 "</xsl:template>\n" + 383 "</xsl:stylesheet> \n" 384 ); 385 386 387 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 388 389 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 390 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 391 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 392 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 393 " <arch answers=\"" + answers + "\" output='" + output + "'" + 394 " apichanges='" + apichanges + "' xsl='" + xsl + "'\n" + 395 " />\n" + 396 "<target name=\"all\" >" + 397 " " + 398 "</target>" + 399 "</project>" 400 401 ); 402 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { 403 "-Darch.generate=true", 404 "-Darch.private.disable.validation.for.test.purposes=true", 405 406 }); 407 408 assertTrue ("Answers still exists", answers.exists ()); 409 assertTrue ("Output file generated", output.exists ()); 410 411 String txt = PublicPackagesInProjectizedXMLTest.readFile(output); 412 413 org.w3c.dom.Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(output); 414 415 org.w3c.dom.NodeList list; 416 list = dom.getElementsByTagName("apidef"); 417 assertEquals ("One apidef element:\n" + txt, 1, list.getLength()); 418 419 list = dom.getElementsByTagName("change"); 420 assertEquals("Two change elements:\n" + txt, 2, list.getLength()); 421 422 } 423 424 425 public void testReadNbDepsFromProjectXML() throws Exception { 426 String [] txt = new String [1]; 427 Document dom = doReadNbDepsFromProjectXML("", txt); 428 429 430 org.w3c.dom.NodeList list; 431 list = dom.getElementsByTagName("api"); 432 assertTrue("There is more than one api tag: " + txt[0], list.getLength() > 0); 433 434 for (int i = 0; i < list.getLength(); i++) { 435 org.w3c.dom.Node n = list.item(i); 436 437 assertEquals ("group is java", "java", n.getAttributes().getNamedItem("group").getNodeValue()); 438 assertEquals ("type is import", "import", n.getAttributes().getNamedItem("type").getNodeValue()); 439 } 440 } 441 442 443 public void testReadNbDepsFromProjectXMLWhenDefaultAnswerRequested() throws Exception { 444 String [] txt = new String [1]; 445 Document dom = doReadNbDepsFromProjectXML(" <defaultanswer generate='here'/>", txt); 446 447 448 org.w3c.dom.NodeList list; 449 list = dom.getElementsByTagName("api"); 450 assertTrue("There is more than one api tag: " + txt[0], list.getLength() > 0); 451 452 for (int i = 0; i < list.getLength(); i++) { 453 org.w3c.dom.Node n = list.item(i); 454 455 assertEquals ("group is java", "java", n.getAttributes().getNamedItem("group").getNodeValue()); 456 assertEquals ("type is import", "import", n.getAttributes().getNamedItem("type").getNodeValue()); 457 } 458 459 assertEquals("Warnings are not included if defaultanswer is present: " + txt[0], -1, txt[0].indexOf("Default answer to this question")); 460 461 462 Matcher m = Pattern.compile("<!--[^-\"']*<api *type..import. *group..java. *" 466 + "category=.private. *" 467 + "name=.org.openide.util.*url=..org-openide-util./overview-summary.*>" 468 + "[^-]*</api>" 469 ).matcher(txt[0]); 470 if (!m.find()) { 471 fail("<api/> should be in comment\n" + txt[0]); 472 } 473 } 474 475 public void testReadNbDepsFromProjectXMLWhenDefaultAnswerProhibited () throws Exception { 476 String [] txt = new String [1]; 477 Document dom = doReadNbDepsFromProjectXML(" <defaultanswer generate='none'/>", txt); 478 479 480 org.w3c.dom.NodeList list; 481 list = dom.getElementsByTagName("api"); 482 483 assertEquals("There is no api tag", 0, list.getLength()); 484 } 485 486 public void testReadNbDepsFromProjectXMLWithPropertiesSetToNameAnd() throws Exception { 487 String [] txt = new String [3]; 488 txt[1] = "-Darch.org.openide.util.name=UtilitiesAPI"; 490 txt[2] = "-Darch.org.openide.util.category=official"; 491 Document dom = doReadNbDepsFromProjectXML(" <defaultanswer generate='here'/>", txt); 492 493 494 org.w3c.dom.NodeList list; 495 list = dom.getElementsByTagName("api"); 496 assertTrue("There is more than one api tag: " + txt[0], list.getLength() > 0); 497 498 for (int i = 0; i < list.getLength(); i++) { 499 org.w3c.dom.Node n = list.item(i); 500 501 assertEquals ("group is java", "java", n.getAttributes().getNamedItem("group").getNodeValue()); 502 assertEquals ("type is import", "import", n.getAttributes().getNamedItem("type").getNodeValue()); 503 504 if ("UtilitiesAPI".equals(n.getAttributes().getNamedItem("name").getNodeValue())) { 505 assertEquals("Category is official", "official", n.getAttributes().getNamedItem("category").getNodeValue()); 506 return; 507 } 508 } 509 510 fail ("There should be the name='UtilitiesAPI' used " + txt[0]); 511 } 512 513 private Document doReadNbDepsFromProjectXML(String inlinedCode, String [] txt) throws Exception { 514 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString ( 515 "<?xml version='1.0' encoding='UTF-8'?>\n" + 516 "<!--\n" + 517 "CDDL Notice\n" + 518 "-->\n" + 519 "\n" + 525 "<api-answers\n" + 526 "question-version='1.25'\n" + 527 "module='Input/Output System'\n" + 528 "author='jglick@netbeans.org'\n" + 529 ">\n" + 530 "\n" + 531 "<api-questions version='1.25'>\n" + 534 "<category id='dep' name='Dependencies'>\n" + 535 "<question id='dep-nb' when='init' >\n" + 536 "What other nb project this one depends on?\n" + 537 "<hint>\n" + 538 "Please provide here a few lines describing the project, \n" + 539 "what problem it should solve, provide links to documentation, \n" + 540 "specifications, etc.\n" + 541 "</hint>\n" + 542 "</question>\n" + 543 "</category>\n" + 544 "</api-questions> \n" + 545 "\n" + 547 "\n" + 548 "<answer id='dep-nb'>\n" + 549 "The Input/Output API is a small API module\n" + 550 "which contains <code>InputOutput</code> and related interfaces used in\n" + 551 "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n" + 552 inlinedCode + "\n" + 553 "</answer>\n" + 554 "\n" + 555 "</api-answers> \n" 556 ); 557 558 java.io.File project = PublicPackagesInProjectizedXMLTest.extractString( 559 "<?xml version='1.0' encoding='UTF-8'?>\n" + 560 "<!--\n" + 561 "CDDL Notice\n" + 562 "-->\n" + 563 "<project xmlns='http://www.netbeans.org/ns/project/1'>\n" + 564 "<type>org.netbeans.modules.apisupport.project</type>\n" + 565 "<configuration>\n" + 566 "<data xmlns='http://www.netbeans.org/ns/nb-module-project/2'>\n" + 567 "<code-name-base>org.openide.loaders</code-name-base>\n" + 568 "<module-dependencies>\n" + 569 "<dependency>\n" + 570 "<code-name-base>org.openide.util</code-name-base>\n" + 571 "<build-prerequisite/>\n" + 572 "<compile-dependency/>\n" + 573 "<run-dependency>\n" + 574 "<specification-version>6.2</specification-version>\n" + 575 "</run-dependency>\n" + 576 "</dependency>\n" + 577 "<dependency>\n" + 578 "<code-name-base>org.openide.filesystems</code-name-base>\n" + 579 "<build-prerequisite/>\n" + 580 "<compile-dependency/>\n" + 581 "<run-dependency>\n" + 582 "<specification-version>6.2</specification-version>\n" + 583 "</run-dependency>\n" + 584 "</dependency>\n" + 585 "<dependency>\n" + 586 "<code-name-base>org.openide.nodes</code-name-base>\n" + 587 "<build-prerequisite/>\n" + 588 "<compile-dependency/>\n" + 589 "<run-dependency>\n" + 590 "<specification-version>6.2</specification-version>\n" + 591 "</run-dependency>\n" + 592 "</dependency>\n" + 593 "<dependency>\n" + 594 "<code-name-base>org.openide.dialogs</code-name-base>\n" + 595 "<build-prerequisite/>\n" + 596 "<compile-dependency/>\n" + 597 "<run-dependency>\n" + 598 "<specification-version>6.2</specification-version>\n" + 599 "</run-dependency>\n" + 600 "</dependency>\n" + 601 "<dependency>\n" + 602 "<code-name-base>org.openide.modules</code-name-base>\n" + 603 "<build-prerequisite/>\n" + 604 "<compile-dependency/>\n" + 605 "<run-dependency>\n" + 606 "<specification-version>6.2</specification-version>\n" + 607 "</run-dependency>\n" + 608 "</dependency>\n" + 609 "<dependency>\n" + 610 "<code-name-base>org.openide.awt</code-name-base>\n" + 611 "<build-prerequisite/>\n" + 612 "<compile-dependency/>\n" + 613 "<run-dependency>\n" + 614 "<specification-version>6.2</specification-version>\n" + 615 "</run-dependency>\n" + 616 "</dependency>\n" + 617 "<dependency>\n" + 618 "<code-name-base>org.openide.explorer</code-name-base>\n" + 619 "<build-prerequisite/>\n" + 620 "<compile-dependency/>\n" + 621 "<run-dependency>\n" + 622 "<specification-version>6.2</specification-version>\n" + 623 "</run-dependency>\n" + 624 "</dependency>\n" + 625 "<dependency>\n" + 626 "<code-name-base>org.openide.actions</code-name-base>\n" + 627 "<build-prerequisite/>\n" + 628 "<compile-dependency/>\n" + 629 "<run-dependency>\n" + 630 "<specification-version>6.2</specification-version>\n" + 631 "</run-dependency>\n" + 632 "</dependency>\n" + 633 "<dependency>\n" + 634 "<code-name-base>org.openide.text</code-name-base>\n" + 635 "<build-prerequisite/>\n" + 636 "<compile-dependency/>\n" + 637 "<run-dependency>\n" + 638 "<specification-version>6.2</specification-version>\n" + 639 "</run-dependency>\n" + 640 "</dependency>\n" + 641 "<dependency>\n" + 642 "<code-name-base>org.openide.windows</code-name-base>\n" + 643 "<build-prerequisite/>\n" + 644 "<compile-dependency/>\n" + 645 "<run-dependency>\n" + 646 "<specification-version>6.2</specification-version>\n" + 647 "</run-dependency>\n" + 648 "</dependency>\n" + 649 "</module-dependencies>\n" + 650 "<public-packages>\n" + 651 "<package>org.openide.awt</package>\n" + 652 "<package>org.openide.actions</package>\n" + 653 "<package>org.openide.loaders</package>\n" + 654 "<package>org.openide.text</package>\n" + 655 "</public-packages>\n" + 656 "</data>\n" + 657 "</configuration>\n" + 658 "</project>\n" + 659 ""); 660 661 662 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 663 assertTrue("File can be deleted: " + output, output.delete()); 664 665 java.io.File xsl = PublicPackagesInProjectizedXMLTest.extractString( 666 "<?xml version='1.0' encoding='UTF-8' ?>\n" + 667 "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" + 668 "<xsl:output method='xml'/>\n" + 669 "<!-- Format random HTML elements as is: -->\n" + 670 "<xsl:template match='@*|node()'>\n" + 671 "<xsl:copy>\n" + 672 "<xsl:apply-templates select='@*|node()'/>\n" + 673 "</xsl:copy>\n" + 674 "</xsl:template>\n" + 675 "</xsl:stylesheet> \n" 676 ); 677 678 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 679 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 680 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 681 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 682 " <arch answers=\"" + answers + "\" output='" + output + "'" + 683 " project='" + project + "' \n" + 684 " xsl='" + xsl + "' \n" + 685 " />\n" + 686 "<target name=\"all\" >" + 687 " " + 688 "</target>" + 689 "</project>" 690 691 ); 692 txt[0] = "-Darch.private.disable.validation.for.test.purposes=true"; 694 PublicPackagesInProjectizedXMLTest.execute (f, txt); 695 696 assertTrue ("Answers still exists", answers.exists ()); 697 assertTrue ("Output file generated", output.exists ()); 698 699 txt[0] = PublicPackagesInProjectizedXMLTest.readFile(output); 701 702 org.w3c.dom.Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(output); 703 return dom; 704 } 705 706 707 public void testReadNbDepsFromProjectXMLGeneratesCVSLocation () throws Exception { 708 String [] txt = new String [1]; 709 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString ( 710 "<?xml version='1.0' encoding='UTF-8'?>\n" + 711 "<!--\n" + 712 "CDDL Notice\n" + 713 "-->\n" + 714 "\n" + 720 "<api-answers\n" + 721 "question-version='1.25'\n" + 722 "module='Input/Output System'\n" + 723 "author='jglick@netbeans.org'\n" + 724 ">\n" + 725 "\n" + 726 "<api-questions version='1.25'>\n" + 729 "<category id='arch' name='Architecture'>\n" + 730 "<question id='arch-where' when='init' >\n" + 731 "What other nb project this one depends on?\n" + 732 "<hint>\n" + 733 "Please provide here a few lines describing the project, \n" + 734 "what problem it should solve, provide links to documentation, \n" + 735 "specifications, etc.\n" + 736 "</hint>\n" + 737 "</question>\n" + 738 "</category>\n" + 739 "</api-questions> \n" + 740 "\n" + 742 "\n" + 743 "<answer id='arch-where'>\n" + 744 "<defaultanswer generate='here' /> \n" + 745 "</answer>\n" + 746 "\n" + 747 "</api-answers> \n" 748 ); 749 750 java.io.File project = PublicPackagesInProjectizedXMLTest.extractString( 751 "<?xml version='1.0' encoding='UTF-8'?>\n" + 752 "<!--\n" + 753 "CDDL Notice\n" + 754 "-->\n" + 755 "<project xmlns='http://www.netbeans.org/ns/project/1'>\n" + 756 "<type>org.netbeans.modules.apisupport.project</type>\n" + 757 "<configuration>\n" + 758 "<data xmlns='http://www.netbeans.org/ns/nb-module-project/2'>\n" + 759 "<code-name-base>org.openide.loaders</code-name-base>\n" + 760 "<module-dependencies>\n" + 761 "</module-dependencies>\n" + 762 "<public-packages>\n" + 763 "<package>org.openide.awt</package>\n" + 764 "</public-packages>\n" + 765 "</data>\n" + 766 "</configuration>\n" + 767 "</project>\n" + 768 ""); 769 770 771 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 772 assertTrue("File can be deleted: " + output, output.delete()); 773 774 java.io.File xsl = PublicPackagesInProjectizedXMLTest.extractString( 775 "<?xml version='1.0' encoding='UTF-8' ?>\n" + 776 "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" + 777 "<xsl:output method='xml'/>\n" + 778 "<!-- Format random HTML elements as is: -->\n" + 779 "<xsl:template match='@*|node()'>\n" + 780 "<xsl:copy>\n" + 781 "<xsl:apply-templates select='@*|node()'/>\n" + 782 "</xsl:copy>\n" + 783 "</xsl:template>\n" + 784 "</xsl:stylesheet> \n" 785 ); 786 787 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 788 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 789 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 790 " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 791 " <arch answers=\"" + answers + "\" output='" + output + "'" + 792 " project='" + project + "' \n" + 793 " xsl='" + xsl + "' \n" + 794 " />\n" + 795 "<target name=\"all\" >" + 796 " " + 797 "</target>" + 798 "</project>" 799 800 ); 801 txt[0] = "-Darch.private.disable.validation.for.test.purposes=true"; 803 PublicPackagesInProjectizedXMLTest.execute (f, txt); 804 805 assertTrue ("Answers still exists", answers.exists ()); 806 assertTrue ("Output file generated", output.exists ()); 807 808 txt[0] = PublicPackagesInProjectizedXMLTest.readFile(output); 810 811 org.w3c.dom.Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(output); 812 813 814 if (txt[0].indexOf("http://www.netbeans.org/source/browse/") == -1) { 815 fail ("reference to CVS location should be in output: " + txt[0]); 816 } 817 } 818 819 public void testGenerateArchInExternalDir () throws Exception { 820 java.io.File answers = java.io.File.createTempFile("arch", ".xml", new java.io.File (System.getProperty("user.home"))); 821 answers.delete(); 822 assertFalse("Does not exists", answers.exists()); 823 824 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 825 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 826 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 827 "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 828 "<target name=\"all\" >" + 829 " <arch answers=\"" + answers + "\" output='" + "x.html" + "' />" + 830 "</target>" + 831 "</project>" 832 833 ); 834 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { "-Darch.generate=true" }); 835 836 answers.deleteOnExit(); 837 assertTrue ("File is generated", answers.exists ()); 838 } 839 840 public void testGenerateArchWithLogging () throws Exception { 841 File dtd = PublicPackagesInProjectizedXMLTest.extractResource("Arch.dtd"); 842 File quest = PublicPackagesInProjectizedXMLTest.extractResource("Arch-api-questions.xml"); 843 844 845 846 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractString( 847 "<?xml version='1.0' encoding='UTF-8'?>\n" + 848 "<!--\n" + 849 "CDDL Notice\n" + 850 "-->\n" + 851 "<!DOCTYPE api-answers PUBLIC '-//NetBeans//DTD Arch Answers//EN' '" + dtd + "' [\n" + 852 "<!ENTITY api-questions SYSTEM '" + quest + "'>\n" + 853 "]>\n" + 854 "\n" + 855 "<api-answers\n" + 856 "question-version='1.25'\n" + 857 "module='Input/Output System'\n" + 858 "author='jglick@netbeans.org'\n" + 859 ">\n" + 860 "\n" + 861 "&api-questions;\n" + 862 "\n" + 863 "\n" + 864 "<answer id='dep-nb'>\n" + 865 "<api name='some-logging' group='logger' type='export' category='stable'>MyLogger</api>\n" + 866 "</answer>\n" + 867 "\n" + 868 "</api-answers> \n" 869 ); 870 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 871 output.delete(); 872 873 874 875 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 876 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 877 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 878 "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 879 "<target name=\"all\" >" + 880 " <arch answers=\"" + answers + "\" output='" + output + "' />" + 881 "</target>" + 882 "</project>" 883 884 ); 885 String [] txt = new String [1]; 886 txt[0] = "-verbose"; 888 PublicPackagesInProjectizedXMLTest.execute (f, txt); 889 890 assertTrue ("File is generated", output.exists ()); 891 892 String content = PublicPackagesInProjectizedXMLTest.readFile(output); 893 894 if (content.indexOf("MyLogger") == -1) { 895 fail(content); 896 } 897 if (content.indexOf("logger interface") == -1) { 898 fail(content); 899 } 900 } 901 902 public void testGenerateProfilerArch () throws Exception { 903 java.io.File answers = PublicPackagesInProjectizedXMLTest.extractResource("arch-profiler.xml"); 904 java.io.File output = PublicPackagesInProjectizedXMLTest.extractString(""); 905 output.delete(); 906 907 908 909 java.io.File f = PublicPackagesInProjectizedXMLTest.extractString ( 910 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 911 "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >" + 912 "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>" + 913 "<target name=\"all\" >" + 914 " <property name='javadoc.title' value='My Lovely Profiler'/>" + 915 " <arch answers=\"" + answers + "\" output='" + output + "' />" + 916 "</target>" + 917 "</project>" 918 919 ); 920 PublicPackagesInProjectizedXMLTest.execute (f, new String [] { }); 921 922 assertTrue ("File is generated", output.exists ()); 923 924 String content = PublicPackagesInProjectizedXMLTest.readFile(output); 925 926 if (content.indexOf("My Lovely Profiler - NetBeans Architecture Questions") == -1) { 927 fail(content); 928 } 929 } 930 931 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 932 msg.add("publicId: " + publicId + " systemId: " + systemId); 933 String x = ""; 934 return new InputSource (new StringReader (x)); 935 } 936 937 938 } 939 | Popular Tags |