001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.nbbuild;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.io.StringReader;
047: import java.util.ArrayList;
048: import java.util.regex.Matcher;
049: import java.util.regex.Pattern;
050: import javax.xml.parsers.*;
051:
052: import org.netbeans.junit.*;
053: import org.w3c.dom.Document;
054: import org.xml.sax.EntityResolver;
055: import org.xml.sax.InputSource;
056: import org.xml.sax.SAXException;
057:
058: /** Check the behaviour Arch task.
059: *
060: * @author Jaroslav Tulach
061: */
062: public class ArchQuestionsTest extends NbTestCase implements
063: EntityResolver {
064: /** debug messages to show if necessary */
065: private ArrayList/*<String>*/msg = new ArrayList();
066:
067: public ArchQuestionsTest(String name) {
068: super (name);
069: }
070:
071: public void testGeneratePreferencesArch() throws Exception {
072: java.io.File answers = PublicPackagesInProjectizedXMLTest
073: .extractResource("arch-preferences.xml");
074: java.io.File output = PublicPackagesInProjectizedXMLTest
075: .extractString("");
076: output.delete();
077:
078: java.io.File f = PublicPackagesInProjectizedXMLTest
079: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
080: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
081: + "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
082: + "<target name=\"all\" >"
083: + " <arch answers=\""
084: + answers
085: + "\" output='"
086: + output
087: + "' />"
088: + "</target>"
089: + "</project>"
090:
091: );
092: PublicPackagesInProjectizedXMLTest.execute(f, new String[] {});
093:
094: assertTrue("File is generated", output.exists());
095:
096: String content = PublicPackagesInProjectizedXMLTest
097: .readFile(output);
098: if (content.indexOf("resources-preferences") == -1) {
099: fail("resources-preferences shall be in output:\n"
100: + content);
101: }
102: if (content.indexOf("answer-resources-preferences") == -1) {
103: fail("answer-resources-preferences shall be in output:\n"
104: + content);
105: }
106: }
107:
108: public void testGenerateArchFileWhenEmpty() throws Exception {
109: java.io.File answers = PublicPackagesInProjectizedXMLTest
110: .extractString("");
111: answers.delete();
112: assertFalse("Really deleted", answers.exists());
113:
114: java.io.File f = PublicPackagesInProjectizedXMLTest
115: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
116: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
117: + " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
118: + " <arch answers=\""
119: + answers
120: + "\" output=\"x.html\" />"
121: + "<target name=\"all\" >"
122: + " "
123: + "</target>"
124: + "</project>"
125:
126: );
127: PublicPackagesInProjectizedXMLTest.execute(f, new String[] {});
128:
129: assertTrue("File is generated", answers.exists());
130:
131: String content = PublicPackagesInProjectizedXMLTest
132: .readFile(answers);
133:
134: if (content.indexOf("module=") >= 0) {
135: fail("No mention of a module should be there anymore:\n"
136: + content);
137: }
138: }
139:
140: public void testGenerateArchFileWhenEmptyWithDefaultAnswerForNbDepsQuestion()
141: throws Exception {
142: java.io.File answers = PublicPackagesInProjectizedXMLTest
143: .extractString("");
144: answers.delete();
145: assertFalse("Really deleted", answers.exists());
146:
147: java.io.File f = PublicPackagesInProjectizedXMLTest
148: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
149: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
150: + " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
151: + " <arch answers=\""
152: + answers
153: + "\" output=\"x.html\" />"
154: + "<target name=\"all\" >"
155: + " "
156: + "</target>"
157: + "</project>"
158:
159: );
160: PublicPackagesInProjectizedXMLTest.execute(f, new String[] {});
161:
162: assertTrue("File is generated", answers.exists());
163:
164: String res = PublicPackagesInProjectizedXMLTest
165: .readFile(answers);
166: DocumentBuilderFactory fack = DocumentBuilderFactory
167: .newInstance();
168: fack.setValidating(false);
169: DocumentBuilder build = fack.newDocumentBuilder();
170: build.setEntityResolver(this );
171: org.w3c.dom.Document dom;
172: try {
173: dom = build.parse(answers);
174: } catch (IOException ex) {
175: throw (IOException) new IOException(ex.getMessage() + "\n"
176: + msg.toString()).initCause(ex);
177: }
178:
179: org.w3c.dom.NodeList list = dom
180: .getElementsByTagName("defaultanswer");
181: assertTrue("There is at least one defaultanswer: " + res, list
182: .getLength() > 0);
183: BIGLOOP: for (int i = 0; i < list.getLength(); i++) {
184: org.w3c.dom.Node n = list.item(i);
185: while (n != null) {
186: n = n.getParentNode();
187: assertNotNull("No parent node answer found: " + res, n);
188:
189: if (n.getNodeName().equals("answer")) {
190: String id = n.getAttributes().getNamedItem("id")
191: .getNodeValue();
192: if (id.equals("dep-nb")) {
193: // ok, we were searching for answer to dep-nb question
194: return;
195: }
196: continue BIGLOOP;
197: }
198: }
199: }
200:
201: fail("dep-nb question should have a defaultanswer: " + res);
202: }
203:
204: public void testDoNotCorruptTheFileWhenItExists() throws Exception {
205: java.io.File answers = PublicPackagesInProjectizedXMLTest
206: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
207: + "<!--\n"
208: + "CDDL Notice\n"
209: + "-->\n"
210: +
211: // "<!DOCTYPE api-answers PUBLIC '-//NetBeans//DTD Arch Answers//EN' '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd' [\n" +
212: // The following lines needs to be commented out as we do not have the right relative locations!
213: // instead there is a part of Arch-api-questions directly inserted into the document bellow
214: // "<!ENTITY api-questions SYSTEM '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml'>\n" +
215: //"]>\n" +
216: "\n"
217: + "<api-answers\n"
218: + "question-version='1.25'\n"
219: + "module='Input/Output System'\n"
220: + "author='jglick@netbeans.org'\n"
221: + ">\n"
222: + "\n"
223: +
224: // "&api-questions;\n" +
225: // replaced by part of api-questions entity
226: "<api-questions version='1.25'>\n"
227: + "<category id='arch' name='General Information'>\n"
228: + "<question id='arch-what' when='init' >\n"
229: + "What is this project good for?\n"
230: + "<hint>\n"
231: + "Please provide here a few lines describing the project, \n"
232: + "what problem it should solve, provide links to documentation, \n"
233: + "specifications, etc.\n"
234: + "</hint>\n"
235: + "</question>\n"
236: + "<question id='arch-overall' when='init'>\n"
237: + "Describe the overall architecture. \n"
238: + "<hint>\n"
239: + "What will be API for \n"
240: + "<a href='http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi'>\n"
241: + "clients and what support API</a>? \n"
242: + "What parts will be pluggable?\n"
243: + "How will plug-ins be registered? Please use <code><api type='export'/></code>\n"
244: + "to describe your general APIs.\n"
245: + "If possible please provide \n"
246: + "simple diagrams. \n"
247: + "</hint>\n"
248: + "</question>\n"
249: + "</category>\n"
250: + "</api-questions> \n"
251: +
252: // end of Arch-api-questionx.xmls
253: "\n"
254: + "\n"
255: + "<answer id='arch-what'>\n"
256: + "The Input/Output API is a small API module\n"
257: + "which contains <code>InputOutput</code> and related interfaces used in\n"
258: + "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n"
259: + "</answer>\n" + "\n" + "</api-answers> \n");
260:
261: java.io.File output = PublicPackagesInProjectizedXMLTest
262: .extractString("");
263:
264: java.io.File f = PublicPackagesInProjectizedXMLTest
265: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
266: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
267: + " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
268: + " <arch answers=\""
269: + answers
270: + "\" output='"
271: + output
272: + "' />"
273: + "<target name=\"all\" >"
274: + " "
275: + "</target>"
276: + "</project>"
277:
278: );
279: PublicPackagesInProjectizedXMLTest
280: .execute(
281: f,
282: new String[] {
283: "-Darch.generate=true",
284: "-Darch.private.disable.validation.for.test.purposes=true",
285:
286: });
287:
288: assertTrue("Answers still exists", answers.exists());
289: assertTrue("Output file generated", output.exists());
290:
291: String s1 = PublicPackagesInProjectizedXMLTest
292: .readFile(answers);
293: if (s1.indexOf("answer id=\"arch-overall\"") == -1) {
294: fail("There should be a answer template for arch-overall in answers: "
295: + s1);
296: }
297: String s2 = PublicPackagesInProjectizedXMLTest.readFile(output);
298: if (s2.indexOf("question id=\"arch-overall\"") == -1) {
299: fail("There should be a answer template for arch-overall in html output: "
300: + s2);
301: }
302: }
303:
304: public void testIncludeAPIChangesDocumentIntoSetOfAnswersIfSpecified()
305: throws Exception {
306: java.io.File answers = PublicPackagesInProjectizedXMLTest
307: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
308: + "<!--\n"
309: + "CDDL Notice\n"
310: + "-->\n"
311: +
312: // "<!DOCTYPE api-answers PUBLIC '-//NetBeans//DTD Arch Answers//EN' '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd' [\n" +
313: // The following lines needs to be commented out as we do not have the right relative locations!
314: // instead there is a part of Arch-api-questions directly inserted into the document bellow
315: // "<!ENTITY api-questions SYSTEM '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml'>\n" +
316: //"]>\n" +
317: "\n"
318: + "<api-answers\n"
319: + "question-version='1.25'\n"
320: + "module='Input/Output System'\n"
321: + "author='jglick@netbeans.org'\n"
322: + ">\n"
323: + "\n"
324: +
325: // "&api-questions;\n" +
326: // replaced by part of api-questions entity
327: "<api-questions version='1.25'>\n"
328: + "<category id='arch' name='General Information'>\n"
329: + "<question id='arch-what' when='init' >\n"
330: + "What is this project good for?\n"
331: + "<hint>\n"
332: + "Please provide here a few lines describing the project, \n"
333: + "what problem it should solve, provide links to documentation, \n"
334: + "specifications, etc.\n"
335: + "</hint>\n"
336: + "</question>\n"
337: + "<question id='arch-overall' when='init'>\n"
338: + "Describe the overall architecture. \n"
339: + "<hint>\n"
340: + "What will be API for \n"
341: + "<a href='http://openide.netbeans.org/tutorial/api-design.html#design.apiandspi'>\n"
342: + "clients and what support API</a>? \n"
343: + "What parts will be pluggable?\n"
344: + "How will plug-ins be registered? Please use <code><api type='export'/></code>\n"
345: + "to describe your general APIs.\n"
346: + "If possible please provide \n"
347: + "simple diagrams. \n"
348: + "</hint>\n"
349: + "</question>\n"
350: + "</category>\n"
351: + "</api-questions> \n"
352: +
353: // end of Arch-api-questionx.xmls
354: "\n"
355: + "\n"
356: + "<answer id='arch-what'>\n"
357: + "The Input/Output API is a small API module\n"
358: + "which contains <code>InputOutput</code> and related interfaces used in\n"
359: + "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n"
360: + "</answer>\n" + "\n" + "</api-answers> \n");
361:
362: java.io.File apichanges = PublicPackagesInProjectizedXMLTest
363: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
364: + "<!--\n"
365: + "CDDL Notice\n"
366: + "-->\n"
367: +
368: //"<!DOCTYPE apichanges PUBLIC '-//NetBeans//DTD API changes list 1.0//EN' '../../nbbuild/javadoctools/apichanges.dtd'>\n" +
369: "<apichanges>\n"
370: + "<apidefs>\n"
371: + "<apidef name='nodes'>Nodes API</apidef>\n"
372: + "</apidefs>\n"
373: + "<changes>\n"
374: + "<change id='AbstractNode.setIconBaseWithExtension'>\n"
375: + "<api name='nodes'/>\n"
376: + "<summary>AbstractNode allows using different icon extensions</summary>\n"
377: + "<version major='6' minor='5'/>\n"
378: + "<date day='14' month='7' year='2005'/>\n"
379: + "<author login='pnejedly'/>\n"
380: + "<compatibility addition='yes' binary='compatible' source='compatible' semantic='compatible' deprecation='yes' deletion='no' modification='no'/>\n"
381: + "<description>\n"
382: + "Some description\n"
383: + "</description>\n"
384: + "<class package='org.openide.nodes' name='AbstractNode'/>\n"
385: + "<issue number='53461'/>\n"
386: + "</change> \n"
387: + "<change id='anotherChange'>\n"
388: + "<api name='nodes'/>\n"
389: + "<summary>Ble</summary>\n"
390: + "<version major='6' minor='3'/>\n"
391: + "<date day='14' month='3' year='2005'/>\n"
392: + "<author login='jtulach'/>\n"
393: + "<compatibility addition='yes' binary='compatible' source='compatible' semantic='compatible' deprecation='yes' deletion='no' modification='no'/>\n"
394: + "<description>\n"
395: + "Some description\n"
396: + "</description>\n"
397: + "<class package='org.openide.nodes' name='AbstractNode'/>\n"
398: + "<issue number='23461'/>\n"
399: + "</change> \n"
400: + "</changes>\n"
401: + "<htmlcontents>\n"
402: + "<head>\n"
403: + "<title>Change History for the Nodes API</title>\n"
404: + "<link rel='stylesheet' href='prose.css' type='text/css'/>\n"
405: + "</head>\n"
406: + "<body>\n"
407: + "<p class='overviewlink'>\n"
408: + "<a href='overview-summary.html'>Overview</a>\n"
409: + "</p>\n"
410: + "<h1>Introduction</h1>\n"
411: + "<h2>What do the Dates Mean?</h2>\n"
412: + "<p>The supplied dates indicate when the API change was made, on the\n"
413: + "bug fix in version control; this ought to be marked in this list.</p>\n"
414: + "<ul>\n"
415: + "<li>The <code>release41</code> branch was made on Apr 03 '05 for use in the NetBeans 4.1 release.\n"
416: + "Specification versions: 6.0 begins after this point.</li>\n"
417: + "<li>The <code>release40</code> branch was made on Nov 01 '04 for use in the NetBeans 4.0 release.\n"
418: + "Specification versions: 5.0 begins after this point.</li>\n"
419: + "</ul>\n"
420: + "<hr/>\n"
421: + "<standard-changelists module-code-name='org.openide.nodes'/>\n"
422: + "<hr/>\n"
423: + "<p>@FOOTER@</p>\n"
424: + "</body>\n"
425: + "</htmlcontents>\n" + "</apichanges>\n" + "");
426:
427: java.io.File xsl = PublicPackagesInProjectizedXMLTest
428: .extractString("<?xml version='1.0' encoding='UTF-8' ?>\n"
429: + "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n"
430: + "<xsl:output method='xml'/>\n"
431: + "<!-- Format random HTML elements as is: -->\n"
432: + "<xsl:template match='@*|node()'>\n"
433: + "<xsl:copy>\n"
434: + "<xsl:apply-templates select='@*|node()'/>\n"
435: + "</xsl:copy>\n"
436: + "</xsl:template>\n"
437: + "</xsl:stylesheet> \n");
438:
439: java.io.File output = PublicPackagesInProjectizedXMLTest
440: .extractString("");
441:
442: java.io.File f = PublicPackagesInProjectizedXMLTest
443: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
444: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
445: + " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
446: + " <arch answers=\""
447: + answers
448: + "\" output='"
449: + output
450: + "'"
451: + " apichanges='"
452: + apichanges
453: + "' xsl='"
454: + xsl
455: + "'\n"
456: + " />\n"
457: + "<target name=\"all\" >"
458: + " "
459: + "</target>"
460: + "</project>"
461:
462: );
463: PublicPackagesInProjectizedXMLTest
464: .execute(
465: f,
466: new String[] {
467: "-Darch.generate=true",
468: "-Darch.private.disable.validation.for.test.purposes=true",
469:
470: });
471:
472: assertTrue("Answers still exists", answers.exists());
473: assertTrue("Output file generated", output.exists());
474:
475: String txt = PublicPackagesInProjectizedXMLTest
476: .readFile(output);
477:
478: org.w3c.dom.Document dom = DocumentBuilderFactory.newInstance()
479: .newDocumentBuilder().parse(output);
480:
481: org.w3c.dom.NodeList list;
482: list = dom.getElementsByTagName("apidef");
483: assertEquals("One apidef element:\n" + txt, 1, list.getLength());
484:
485: list = dom.getElementsByTagName("change");
486: assertEquals("Two change elements:\n" + txt, 2, list
487: .getLength());
488:
489: }
490:
491: public void testReadNbDepsFromProjectXML() throws Exception {
492: String[] txt = new String[1];
493: Document dom = doReadNbDepsFromProjectXML("", txt);
494:
495: org.w3c.dom.NodeList list;
496: list = dom.getElementsByTagName("api");
497: assertTrue("There is more than one api tag: " + txt[0], list
498: .getLength() > 0);
499:
500: for (int i = 0; i < list.getLength(); i++) {
501: org.w3c.dom.Node n = list.item(i);
502:
503: assertEquals("group is java", "java", n.getAttributes()
504: .getNamedItem("group").getNodeValue());
505: assertEquals("type is import", "import", n.getAttributes()
506: .getNamedItem("type").getNodeValue());
507: }
508: }
509:
510: public void testReadNbDepsFromProjectXMLWhenDefaultAnswerRequested()
511: throws Exception {
512: String[] txt = new String[1];
513: Document dom = doReadNbDepsFromProjectXML(
514: " <defaultanswer generate='here'/>", txt);
515:
516: org.w3c.dom.NodeList list;
517: list = dom.getElementsByTagName("api");
518: assertTrue("There is more than one api tag: " + txt[0], list
519: .getLength() > 0);
520:
521: for (int i = 0; i < list.getLength(); i++) {
522: org.w3c.dom.Node n = list.item(i);
523:
524: assertEquals("group is java", "java", n.getAttributes()
525: .getNamedItem("group").getNodeValue());
526: assertEquals("type is import", "import", n.getAttributes()
527: .getNamedItem("type").getNodeValue());
528: }
529:
530: assertEquals(
531: "Warnings are not included if defaultanswer is present: "
532: + txt[0], -1, txt[0]
533: .indexOf("Default answer to this question"));
534:
535: // the api tags are also included in comment
536: // like this one:
537: // <api type='import' group='java' category='private' name='org.openide.util' url='@org-openide-util@/overview-summary.html'></api>
538: Matcher m = Pattern
539: .compile(
540: "<!--[^-\"']*<api *type..import. *group..java. *"
541: + "category=.private. *"
542: + "name=.org.openide.util.*url=..org-openide-util./overview-summary.*>"
543: + "[^-]*</api>").matcher(txt[0]);
544: if (!m.find()) {
545: fail("<api/> should be in comment\n" + txt[0]);
546: }
547: }
548:
549: public void testReadNbDepsFromProjectXMLWhenDefaultAnswerProhibited()
550: throws Exception {
551: String[] txt = new String[1];
552: Document dom = doReadNbDepsFromProjectXML(
553: " <defaultanswer generate='none'/>", txt);
554:
555: org.w3c.dom.NodeList list;
556: list = dom.getElementsByTagName("api");
557:
558: assertEquals("There is no api tag", 0, list.getLength());
559: }
560:
561: public void testReadNbDepsFromProjectXMLWithPropertiesSetToNameAnd()
562: throws Exception {
563: String[] txt = new String[3];
564: // txt[0] = is reserved for the doReadNbDepsFromProjectXML method and will contain a result
565: txt[1] = "-Darch.org.openide.util.name=UtilitiesAPI";
566: txt[2] = "-Darch.org.openide.util.category=official";
567: Document dom = doReadNbDepsFromProjectXML(
568: " <defaultanswer generate='here'/>", txt);
569:
570: org.w3c.dom.NodeList list;
571: list = dom.getElementsByTagName("api");
572: assertTrue("There is more than one api tag: " + txt[0], list
573: .getLength() > 0);
574:
575: for (int i = 0; i < list.getLength(); i++) {
576: org.w3c.dom.Node n = list.item(i);
577:
578: assertEquals("group is java", "java", n.getAttributes()
579: .getNamedItem("group").getNodeValue());
580: assertEquals("type is import", "import", n.getAttributes()
581: .getNamedItem("type").getNodeValue());
582:
583: if ("UtilitiesAPI".equals(n.getAttributes().getNamedItem(
584: "name").getNodeValue())) {
585: assertEquals("Category is official", "official", n
586: .getAttributes().getNamedItem("category")
587: .getNodeValue());
588: return;
589: }
590: }
591:
592: fail("There should be the name='UtilitiesAPI' used " + txt[0]);
593: }
594:
595: private Document doReadNbDepsFromProjectXML(String inlinedCode,
596: String[] txt) throws Exception {
597: java.io.File answers = PublicPackagesInProjectizedXMLTest
598: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
599: + "<!--\n"
600: + "CDDL Notice\n"
601: + "-->\n"
602: +
603: // "<!DOCTYPE api-answers PUBLIC '-//NetBeans//DTD Arch Answers//EN' '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd' [\n" +
604: // The following lines needs to be commented out as we do not have the right relative locations!
605: // instead there is a part of Arch-api-questions directly inserted into the document bellow
606: // "<!ENTITY api-questions SYSTEM '../../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml'>\n" +
607: //"]>\n" +
608: "\n"
609: + "<api-answers\n"
610: + "question-version='1.25'\n"
611: + "module='Input/Output System'\n"
612: + "author='jglick@netbeans.org'\n"
613: + ">\n"
614: + "\n"
615: +
616: // "&api-questions;\n" +
617: // replaced by part of api-questions entity
618: "<api-questions version='1.25'>\n"
619: + "<category id='dep' name='Dependencies'>\n"
620: + "<question id='dep-nb' when='init' >\n"
621: + "What other nb project this one depends on?\n"
622: + "<hint>\n"
623: + "Please provide here a few lines describing the project, \n"
624: + "what problem it should solve, provide links to documentation, \n"
625: + "specifications, etc.\n"
626: + "</hint>\n"
627: + "</question>\n"
628: + "</category>\n"
629: + "</api-questions> \n"
630: +
631: // end of Arch-api-questionx.xmls
632: "\n"
633: + "\n"
634: + "<answer id='dep-nb'>\n"
635: + "The Input/Output API is a small API module\n"
636: + "which contains <code>InputOutput</code> and related interfaces used in\n"
637: + "driving the Output Window. The normal implementation is <code>org.netbeans.core.output2</code>.\n"
638: + inlinedCode
639: + "\n"
640: + "</answer>\n"
641: + "\n"
642: + "</api-answers> \n");
643:
644: java.io.File project = PublicPackagesInProjectizedXMLTest
645: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
646: + "<!--\n"
647: + "CDDL Notice\n"
648: + "-->\n"
649: + "<project xmlns='http://www.netbeans.org/ns/project/1'>\n"
650: + "<type>org.netbeans.modules.apisupport.project</type>\n"
651: + "<configuration>\n"
652: + "<data xmlns='http://www.netbeans.org/ns/nb-module-project/2'>\n"
653: + "<code-name-base>org.openide.loaders</code-name-base>\n"
654: + "<module-dependencies>\n"
655: + "<dependency>\n"
656: + "<code-name-base>org.openide.util</code-name-base>\n"
657: + "<build-prerequisite/>\n"
658: + "<compile-dependency/>\n"
659: + "<run-dependency>\n"
660: + "<specification-version>6.2</specification-version>\n"
661: + "</run-dependency>\n"
662: + "</dependency>\n"
663: + "<dependency>\n"
664: + "<code-name-base>org.openide.filesystems</code-name-base>\n"
665: + "<build-prerequisite/>\n"
666: + "<compile-dependency/>\n"
667: + "<run-dependency>\n"
668: + "<specification-version>6.2</specification-version>\n"
669: + "</run-dependency>\n"
670: + "</dependency>\n"
671: + "<dependency>\n"
672: + "<code-name-base>org.openide.nodes</code-name-base>\n"
673: + "<build-prerequisite/>\n"
674: + "<compile-dependency/>\n"
675: + "<run-dependency>\n"
676: + "<specification-version>6.2</specification-version>\n"
677: + "</run-dependency>\n"
678: + "</dependency>\n"
679: + "<dependency>\n"
680: + "<code-name-base>org.openide.dialogs</code-name-base>\n"
681: + "<build-prerequisite/>\n"
682: + "<compile-dependency/>\n"
683: + "<run-dependency>\n"
684: + "<specification-version>6.2</specification-version>\n"
685: + "</run-dependency>\n"
686: + "</dependency>\n"
687: + "<dependency>\n"
688: + "<code-name-base>org.openide.modules</code-name-base>\n"
689: + "<build-prerequisite/>\n"
690: + "<compile-dependency/>\n"
691: + "<run-dependency>\n"
692: + "<specification-version>6.2</specification-version>\n"
693: + "</run-dependency>\n"
694: + "</dependency>\n"
695: + "<dependency>\n"
696: + "<code-name-base>org.openide.awt</code-name-base>\n"
697: + "<build-prerequisite/>\n"
698: + "<compile-dependency/>\n"
699: + "<run-dependency>\n"
700: + "<specification-version>6.2</specification-version>\n"
701: + "</run-dependency>\n"
702: + "</dependency>\n"
703: + "<dependency>\n"
704: + "<code-name-base>org.openide.explorer</code-name-base>\n"
705: + "<build-prerequisite/>\n"
706: + "<compile-dependency/>\n"
707: + "<run-dependency>\n"
708: + "<specification-version>6.2</specification-version>\n"
709: + "</run-dependency>\n"
710: + "</dependency>\n"
711: + "<dependency>\n"
712: + "<code-name-base>org.openide.actions</code-name-base>\n"
713: + "<build-prerequisite/>\n"
714: + "<compile-dependency/>\n"
715: + "<run-dependency>\n"
716: + "<specification-version>6.2</specification-version>\n"
717: + "</run-dependency>\n"
718: + "</dependency>\n"
719: + "<dependency>\n"
720: + "<code-name-base>org.openide.text</code-name-base>\n"
721: + "<build-prerequisite/>\n"
722: + "<compile-dependency/>\n"
723: + "<run-dependency>\n"
724: + "<specification-version>6.2</specification-version>\n"
725: + "</run-dependency>\n"
726: + "</dependency>\n"
727: + "<dependency>\n"
728: + "<code-name-base>org.openide.windows</code-name-base>\n"
729: + "<build-prerequisite/>\n"
730: + "<compile-dependency/>\n"
731: + "<run-dependency>\n"
732: + "<specification-version>6.2</specification-version>\n"
733: + "</run-dependency>\n"
734: + "</dependency>\n"
735: + "</module-dependencies>\n"
736: + "<public-packages>\n"
737: + "<package>org.openide.awt</package>\n"
738: + "<package>org.openide.actions</package>\n"
739: + "<package>org.openide.loaders</package>\n"
740: + "<package>org.openide.text</package>\n"
741: + "</public-packages>\n"
742: + "</data>\n"
743: + "</configuration>\n" + "</project>\n" + "");
744:
745: java.io.File output = PublicPackagesInProjectizedXMLTest
746: .extractString("");
747: assertTrue("File can be deleted: " + output, output.delete());
748:
749: java.io.File xsl = PublicPackagesInProjectizedXMLTest
750: .extractString("<?xml version='1.0' encoding='UTF-8' ?>\n"
751: + "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n"
752: + "<xsl:output method='xml'/>\n"
753: + "<!-- Format random HTML elements as is: -->\n"
754: + "<xsl:template match='@*|node()'>\n"
755: + "<xsl:copy>\n"
756: + "<xsl:apply-templates select='@*|node()'/>\n"
757: + "</xsl:copy>\n"
758: + "</xsl:template>\n"
759: + "</xsl:stylesheet> \n");
760:
761: java.io.File f = PublicPackagesInProjectizedXMLTest
762: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
763: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
764: + " <taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
765: + " <arch answers=\""
766: + answers
767: + "\" output='"
768: + output
769: + "'"
770: + " project='"
771: + project
772: + "' \n"
773: + " xsl='"
774: + xsl
775: + "' \n"
776: + " />\n"
777: + "<target name=\"all\" >"
778: + " "
779: + "</target>"
780: + "</project>"
781:
782: );
783: // happy hacking first of the txt argument is used to pass args to the execution script
784: txt[0] = "-Darch.private.disable.validation.for.test.purposes=true";
785: PublicPackagesInProjectizedXMLTest.execute(f, txt);
786:
787: assertTrue("Answers still exists", answers.exists());
788: assertTrue("Output file generated", output.exists());
789:
790: // happy hacking2: and now it is used to return back the result of the execution ;-)
791: txt[0] = PublicPackagesInProjectizedXMLTest.readFile(output);
792:
793: org.w3c.dom.Document dom = DocumentBuilderFactory.newInstance()
794: .newDocumentBuilder().parse(output);
795: return dom;
796: }
797:
798: public void testGenerateArchInExternalDir() throws Exception {
799: java.io.File answers = java.io.File.createTempFile("arch",
800: ".xml", new java.io.File(System
801: .getProperty("user.home")));
802: answers.delete();
803: assertFalse("Does not exists", answers.exists());
804:
805: java.io.File f = PublicPackagesInProjectizedXMLTest
806: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
807: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
808: + "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
809: + "<target name=\"all\" >"
810: + " <arch answers=\""
811: + answers
812: + "\" output='"
813: + "x.html"
814: + "' />"
815: + "</target>" + "</project>"
816:
817: );
818: PublicPackagesInProjectizedXMLTest.execute(f,
819: new String[] { "-Darch.generate=true" });
820:
821: answers.deleteOnExit();
822: assertTrue("File is generated", answers.exists());
823: }
824:
825: public void testGenerateArchWithLogging() throws Exception {
826: File dtd = PublicPackagesInProjectizedXMLTest
827: .extractResource("Arch.dtd");
828: File quest = PublicPackagesInProjectizedXMLTest
829: .extractResource("Arch-api-questions.xml");
830:
831: java.io.File answers = PublicPackagesInProjectizedXMLTest
832: .extractString("<?xml version='1.0' encoding='UTF-8'?>\n"
833: + "<!--\n"
834: + "CDDL Notice\n"
835: + "-->\n"
836: + "<!DOCTYPE api-answers PUBLIC '-//NetBeans//DTD Arch Answers//EN' '"
837: + dtd
838: + "' [\n"
839: + "<!ENTITY api-questions SYSTEM '"
840: + quest
841: + "'>\n"
842: + "]>\n"
843: + "\n"
844: + "<api-answers\n"
845: + "question-version='1.25'\n"
846: + "module='Input/Output System'\n"
847: + "author='jglick@netbeans.org'\n"
848: + ">\n"
849: + "\n"
850: + "&api-questions;\n"
851: + "\n"
852: + "\n"
853: + "<answer id='dep-nb'>\n"
854: + "<api name='some-logging' group='logger' type='export' category='stable'>MyLogger</api>\n"
855: + "</answer>\n" + "\n" + "</api-answers> \n");
856: java.io.File output = PublicPackagesInProjectizedXMLTest
857: .extractString("");
858: output.delete();
859:
860: java.io.File f = PublicPackagesInProjectizedXMLTest
861: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
862: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
863: + "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
864: + "<target name=\"all\" >"
865: + " <arch answers=\""
866: + answers
867: + "\" output='"
868: + output
869: + "' />"
870: + "</target>"
871: + "</project>"
872:
873: );
874: String[] txt = new String[1];
875: // txt[0] = "-Darch.private.disable.validation.for.test.purposes=true";
876: txt[0] = "-verbose";
877: PublicPackagesInProjectizedXMLTest.execute(f, txt);
878:
879: assertTrue("File is generated", output.exists());
880:
881: String content = PublicPackagesInProjectizedXMLTest
882: .readFile(output);
883:
884: if (content.indexOf("MyLogger") == -1) {
885: fail(content);
886: }
887: if (content.indexOf("logger interface") == -1) {
888: fail(content);
889: }
890: }
891:
892: public void testGenerateProfilerArch() throws Exception {
893: java.io.File answers = PublicPackagesInProjectizedXMLTest
894: .extractResource("arch-profiler.xml");
895: java.io.File output = PublicPackagesInProjectizedXMLTest
896: .extractString("");
897: output.delete();
898:
899: java.io.File f = PublicPackagesInProjectizedXMLTest
900: .extractString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
901: + "<project name=\"Test Arch\" basedir=\".\" default=\"all\" >"
902: + "<taskdef name=\"arch\" classname=\"org.netbeans.nbbuild.Arch\" classpath=\"${nb_all}/nbbuild/nbantext.jar\"/>"
903: + "<target name=\"all\" >"
904: + " <property name='javadoc.title' value='My Lovely Profiler'/>"
905: + " <arch answers=\""
906: + answers
907: + "\" output='"
908: + output
909: + "' />"
910: + "</target>"
911: + "</project>"
912:
913: );
914: PublicPackagesInProjectizedXMLTest.execute(f, new String[] {});
915:
916: assertTrue("File is generated", output.exists());
917:
918: String content = PublicPackagesInProjectizedXMLTest
919: .readFile(output);
920:
921: if (content
922: .indexOf("My Lovely Profiler - NetBeans Architecture Questions") == -1) {
923: fail(content);
924: }
925: }
926:
927: public InputSource resolveEntity(String publicId, String systemId)
928: throws SAXException, IOException {
929: msg.add("publicId: " + publicId + " systemId: " + systemId);
930: String x = "";
931: return new InputSource(new StringReader(x));
932: }
933:
934: }
|