This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 136595
Collapse All | Expand All

(-)a/project.ant/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingleton.java (-4 / +4 lines)
Lines 190-198 Link Here
190
        try {
190
        try {
191
            Document projectXml = loadProjectXml(projectDiskFile);
191
            Document projectXml = loadProjectXml(projectDiskFile);
192
            if (projectXml != null) {
192
            if (projectXml != null) {
193
                Element typeEl = Util.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
193
                Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
194
                if (typeEl != null) {
194
                if (typeEl != null) {
195
                    String type = Util.findText(typeEl);
195
                    String type = XMLUtil.findText(typeEl);
196
                    if (type != null) {
196
                    if (type != null) {
197
                        AntBasedProjectType provider = findAntBasedProjectType(type);
197
                        AntBasedProjectType provider = findAntBasedProjectType(type);
198
                        if (provider != null) {
198
                        if (provider != null) {
Lines 236-247 Link Here
236
            LOG.log(Level.FINE, "could not load {0}", projectDiskFile);
236
            LOG.log(Level.FINE, "could not load {0}", projectDiskFile);
237
            return null;
237
            return null;
238
        }
238
        }
239
        Element typeEl = Util.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
239
        Element typeEl = XMLUtil.findElement(projectXml.getDocumentElement(), "type", PROJECT_NS); // NOI18N
240
        if (typeEl == null) {
240
        if (typeEl == null) {
241
            LOG.log(Level.FINE, "no <type> in {0}", projectDiskFile);
241
            LOG.log(Level.FINE, "no <type> in {0}", projectDiskFile);
242
            return null;
242
            return null;
243
        }
243
        }
244
        String type = Util.findText(typeEl);
244
        String type = XMLUtil.findText(typeEl);
245
        if (type == null) {
245
        if (type == null) {
246
            LOG.log(Level.FINE, "no <type> text in {0}", projectDiskFile);
246
            LOG.log(Level.FINE, "no <type> text in {0}", projectDiskFile);
247
            return null;
247
            return null;
(-)a/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java (-3 / +3 lines)
Lines 414-422 Link Here
414
    public static String getLibrariesLocationText(AuxiliaryConfiguration aux) {
414
    public static String getLibrariesLocationText(AuxiliaryConfiguration aux) {
415
        Element libraries = aux.getConfigurationFragment(EL_LIBRARIES, NAMESPACE, true);
415
        Element libraries = aux.getConfigurationFragment(EL_LIBRARIES, NAMESPACE, true);
416
        if (libraries != null) {
416
        if (libraries != null) {
417
            for (Element definitions : Util.findSubElements(libraries)) {
417
            for (Element definitions : XMLUtil.findSubElements(libraries)) {
418
                assert definitions.getLocalName().equals(EL_DEFINITIONS) : definitions;
418
                assert definitions.getLocalName().equals(EL_DEFINITIONS) : definitions;
419
                String text = Util.findText(definitions);
419
                String text = XMLUtil.findText(definitions);
420
                assert text != null : aux;
420
                assert text != null : aux;
421
                return text;
421
                return text;
422
            }
422
            }
Lines 990-996 Link Here
990
        if (libraries == null) {
990
        if (libraries == null) {
991
            libraries = XMLUtil.createDocument("dummy", null, null, null).createElementNS(NAMESPACE, EL_LIBRARIES); // NOI18N
991
            libraries = XMLUtil.createDocument("dummy", null, null, null).createElementNS(NAMESPACE, EL_LIBRARIES); // NOI18N
992
        } else {
992
        } else {
993
            List<Element> elements = Util.findSubElements(libraries);
993
            List<Element> elements = XMLUtil.findSubElements(libraries);
994
            if (elements.size() == 1) {
994
            if (elements.size() == 1) {
995
                libraries.removeChild(elements.get(0));
995
                libraries.removeChild(elements.get(0));
996
            }
996
            }
(-)a/project.ant/src/org/netbeans/modules/project/ant/ProjectXMLCatalogReader.java (-24 / +1 lines)
Lines 68-74 Link Here
68
import org.openide.util.NbCollections;
68
import org.openide.util.NbCollections;
69
import org.openide.xml.XMLUtil;
69
import org.openide.xml.XMLUtil;
70
import org.w3c.dom.Element;
70
import org.w3c.dom.Element;
71
import org.w3c.dom.NamedNodeMap;
72
import org.w3c.dom.Node;
71
import org.w3c.dom.Node;
73
import org.w3c.dom.NodeList;
72
import org.w3c.dom.NodeList;
74
import org.xml.sax.SAXException;
73
import org.xml.sax.SAXException;
Lines 251-257 Link Here
251
                        try {
250
                        try {
252
                            String ns2 = ns.substring(0, slash + 1) + Integer.toString(Integer.parseInt(ns.substring(slash + 1)) + 1);
251
                            String ns2 = ns.substring(0, slash + 1) + Integer.toString(Integer.parseInt(ns.substring(slash + 1)) + 1);
253
                            if (_resolveURI(ns2) != null) {
252
                            if (_resolveURI(ns2) != null) {
254
                                Element data2 = translateXML(data, ns2);
253
                                Element data2 = XMLUtil.translateXML(data, ns2);
255
                                data.getParentNode().replaceChild(data2, data);
254
                                data.getParentNode().replaceChild(data2, data);
256
                                try {
255
                                try {
257
                                    validate(attempt);
256
                                    validate(attempt);
Lines 315-340 Link Here
315
        return null;
314
        return null;
316
    }
315
    }
317
316
318
    private static Element translateXML(Element from, String namespace) { // XXX use #136595
319
        Element to = from.getOwnerDocument().createElementNS(namespace, from.getLocalName());
320
        NodeList nl = from.getChildNodes();
321
        int length = nl.getLength();
322
        for (int i = 0; i < length; i++) {
323
            Node node = nl.item(i);
324
            Node newNode;
325
            if (node.getNodeType() == Node.ELEMENT_NODE) {
326
                newNode = translateXML((Element) node, namespace);
327
            } else {
328
                newNode = node.cloneNode(true);
329
            }
330
            to.appendChild(newNode);
331
        }
332
        NamedNodeMap m = from.getAttributes();
333
        for (int i = 0; i < m.getLength(); i++) {
334
            Node attr = m.item(i);
335
            to.setAttribute(attr.getNodeName(), attr.getNodeValue());
336
        }
337
        return to;
338
    }
339
340
}
317
}
(-)a/project.ant/src/org/netbeans/modules/project/ant/Util.java (-83 lines)
Lines 41-55 Link Here
41
41
42
package org.netbeans.modules.project.ant;
42
package org.netbeans.modules.project.ant;
43
43
44
import java.util.ArrayList;
45
import java.util.List;
46
import java.util.logging.Level;
44
import java.util.logging.Level;
47
import java.util.logging.Logger;
45
import java.util.logging.Logger;
48
import org.openide.util.Exceptions;
46
import org.openide.util.Exceptions;
49
import org.w3c.dom.Element;
50
import org.w3c.dom.Node;
51
import org.w3c.dom.NodeList;
52
import org.w3c.dom.Text;
53
import org.xml.sax.ErrorHandler;
47
import org.xml.sax.ErrorHandler;
54
import org.xml.sax.SAXException;
48
import org.xml.sax.SAXException;
55
import org.xml.sax.SAXParseException;
49
import org.xml.sax.SAXParseException;
Lines 63-145 Link Here
63
    private Util() {}
57
    private Util() {}
64
58
65
    /**
59
    /**
66
     * Search for an XML element in the direct children of a parent.
67
     * DOM provides a similar method but it does a recursive search
68
     * which we do not want. It also gives a node list and we want
69
     * only one result.
70
     * @param parent a parent element
71
     * @param name the intended local name
72
     * @param namespace the intended namespace
73
     * @return the one child element with that name, or null if none or more than one
74
     */
75
    public static Element findElement(Element parent, String name, String namespace) {
76
        Element result = null;
77
        NodeList l = parent.getChildNodes();
78
        int len = l.getLength();
79
        for (int i = 0; i < len; i++) {
80
            if (l.item(i).getNodeType() == Node.ELEMENT_NODE) {
81
                Element el = (Element)l.item(i);
82
                if (namespace.equals(el.getNamespaceURI()) && name.equals(el.getLocalName())) {
83
                    if (result == null) {
84
                        result = el;
85
                    } else {
86
                        return null;
87
                    }
88
                }
89
            }
90
        }
91
        return result;
92
    }
93
    
94
    /**
95
     * Extract nested text from an element.
96
     * Currently does not handle coalescing text nodes, CDATA sections, etc.
97
     * @param parent a parent element
98
     * @return the nested text, or null if none was found
99
     */
100
    public static String findText(Element parent) {
101
        NodeList l = parent.getChildNodes();
102
        for (int i = 0; i < l.getLength(); i++) {
103
            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
104
                Text text = (Text)l.item(i);
105
                return text.getNodeValue();
106
            }
107
        }
108
        return null;
109
    }
110
    
111
    /**
112
     * Find all direct child elements of an element.
113
     * More useful than {@link Element#getElementsByTagNameNS} because it does
114
     * not recurse into recursive child elements.
115
     * Children which are all-whitespace text nodes are ignored; others cause
116
     * an exception to be thrown.
117
     * @param parent a parent element in a DOM tree
118
     * @return a list of direct child elements (may be empty)
119
     * @throws IllegalArgumentException if there are non-element children besides whitespace
120
     */
121
    public static List<Element> findSubElements(Element parent) throws IllegalArgumentException {
122
        NodeList l = parent.getChildNodes();
123
        List<Element> elements = new ArrayList<Element>(l.getLength());
124
        for (int i = 0; i < l.getLength(); i++) {
125
            Node n = l.item(i);
126
            if (n.getNodeType() == Node.ELEMENT_NODE) {
127
                elements.add((Element)n);
128
            } else if (n.getNodeType() == Node.TEXT_NODE) {
129
                String text = ((Text)n).getNodeValue();
130
                if (text.trim().length() > 0) {
131
                    throw new IllegalArgumentException("non-ws text encountered in " + parent + ": " + text); // NOI18N
132
                }
133
            } else if (n.getNodeType() == Node.COMMENT_NODE) {
134
                // skip
135
            } else {
136
                throw new IllegalArgumentException("unexpected non-element child of " + parent + ": " + n); // NOI18N
137
            }
138
        }
139
        return elements;
140
    }
141
    
142
    /**
143
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
60
     * Create an XML error handler that rethrows errors and fatal errors and logs warnings.
144
     * @return a standard error handler
61
     * @return a standard error handler
145
     */
62
     */
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java (-4 / +4 lines)
Lines 416-422 Link Here
416
        Document doc = getConfigurationXml(shared);
416
        Document doc = getConfigurationXml(shared);
417
        if (shared) {
417
        if (shared) {
418
            Element project = doc.getDocumentElement();
418
            Element project = doc.getDocumentElement();
419
            Element config = Util.findElement(project, "configuration", PROJECT_NS); // NOI18N
419
            Element config = XMLUtil.findElement(project, "configuration", PROJECT_NS); // NOI18N
420
            assert config != null;
420
            assert config != null;
421
            return config;
421
            return config;
422
        } else {
422
        } else {
Lines 888-894 Link Here
888
            public Element run() {
888
            public Element run() {
889
                synchronized (modifiedMetadataPaths) {
889
                synchronized (modifiedMetadataPaths) {
890
                    Element root = getConfigurationDataRoot(shared);
890
                    Element root = getConfigurationDataRoot(shared);
891
                    Element data = Util.findElement(root, elementName, namespace);
891
                    Element data = XMLUtil.findElement(root, elementName, namespace);
892
                    if (data != null) {
892
                    if (data != null) {
893
                        return cloneSafely(data);
893
                        return cloneSafely(data);
894
                    } else {
894
                    } else {
Lines 926-932 Link Here
926
            public Void run() {
926
            public Void run() {
927
                synchronized (modifiedMetadataPaths) {
927
                synchronized (modifiedMetadataPaths) {
928
                    Element root = getConfigurationDataRoot(shared);
928
                    Element root = getConfigurationDataRoot(shared);
929
                    Element existing = Util.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
929
                    Element existing = XMLUtil.findElement(root, fragment.getLocalName(), fragment.getNamespaceURI());
930
                    // XXX first compare to existing and return if the same
930
                    // XXX first compare to existing and return if the same
931
                    if (existing != null) {
931
                    if (existing != null) {
932
                        root.removeChild(existing);
932
                        root.removeChild(existing);
Lines 968-974 Link Here
968
            public Boolean run() {
968
            public Boolean run() {
969
                synchronized (modifiedMetadataPaths) {
969
                synchronized (modifiedMetadataPaths) {
970
                    Element root = getConfigurationDataRoot(shared);
970
                    Element root = getConfigurationDataRoot(shared);
971
                    Element data = Util.findElement(root, elementName, namespace);
971
                    Element data = XMLUtil.findElement(root, elementName, namespace);
972
                    if (data != null) {
972
                    if (data != null) {
973
                        root.removeChild(data);
973
                        root.removeChild(data);
974
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
974
                        modifying(shared ? PROJECT_XML_PATH : PRIVATE_XML_PATH);
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java (-10 / +9 lines)
Lines 70-76 Link Here
70
import org.netbeans.api.queries.CollocationQuery;
70
import org.netbeans.api.queries.CollocationQuery;
71
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
71
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
72
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
72
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
73
import org.netbeans.modules.project.ant.Util;
74
import org.netbeans.spi.project.AuxiliaryConfiguration;
73
import org.netbeans.spi.project.AuxiliaryConfiguration;
75
import org.netbeans.spi.project.SubprojectProvider;
74
import org.netbeans.spi.project.SubprojectProvider;
76
import org.openide.ErrorManager;
75
import org.openide.ErrorManager;
Lines 569-575 Link Here
569
        // Linear search; always keeping references sorted first by foreign project
568
        // Linear search; always keeping references sorted first by foreign project
570
        // name, then by target name.
569
        // name, then by target name.
571
        Element nextRefEl = null;
570
        Element nextRefEl = null;
572
        Iterator<Element> it = Util.findSubElements(references).iterator();
571
        Iterator<Element> it = XMLUtil.findSubElements(references).iterator();
573
        while (it.hasNext()) {
572
        while (it.hasNext()) {
574
            Element testRefEl = it.next();
573
            Element testRefEl = it.next();
575
            RawReference testRef = RawReference.create(testRefEl);
574
            RawReference testRef = RawReference.create(testRefEl);
Lines 816-822 Link Here
816
    
815
    
817
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
816
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
818
        // As with addRawReference, do a linear search through.
817
        // As with addRawReference, do a linear search through.
819
        for (Element testRefEl : Util.findSubElements(references)) {
818
        for (Element testRefEl : XMLUtil.findSubElements(references)) {
820
            RawReference testRef = RawReference.create(testRefEl);
819
            RawReference testRef = RawReference.create(testRefEl);
821
            String refID = testRef.getID();
820
            String refID = testRef.getID();
822
            String refName = testRef.getForeignProjectName();
821
            String refName = testRef.getForeignProjectName();
Lines 869-875 Link Here
869
    }
868
    }
870
    
869
    
871
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
870
    private static RawReference[] getRawReferences(Element references) throws IllegalArgumentException {
872
        List<Element> subEls = Util.findSubElements(references);
871
        List<Element> subEls = XMLUtil.findSubElements(references);
873
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
872
        List<RawReference> refs = new ArrayList<RawReference>(subEls.size());
874
        for (Element subEl : subEls) {
873
        for (Element subEl : subEls) {
875
            refs.add(RawReference.create(subEl));
874
            refs.add(RawReference.create(subEl));
Lines 911-917 Link Here
911
    }
910
    }
912
    
911
    
913
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
912
    private static RawReference getRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
914
        for (Element subEl : Util.findSubElements(references)) {
913
        for (Element subEl : XMLUtil.findSubElements(references)) {
915
            RawReference ref = RawReference.create(subEl);
914
            RawReference ref = RawReference.create(subEl);
916
            String refID = ref.getID();
915
            String refID = ref.getID();
917
            String refName = ref.getForeignProjectName();
916
            String refName = ref.getForeignProjectName();
Lines 1693-1699 Link Here
1693
                if (idx == -1) {
1692
                if (idx == -1) {
1694
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1693
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1695
                }
1694
                }
1696
                String val = Util.findText(el);
1695
                String val = XMLUtil.findText(el);
1697
                if (val == null) {
1696
                if (val == null) {
1698
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1697
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1699
                }
1698
                }
Lines 1711-1717 Link Here
1711
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1710
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1712
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1711
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1713
            }
1712
            }
1714
            List nl = Util.findSubElements(xml);
1713
            List nl = XMLUtil.findSubElements(xml);
1715
            if (nl.size() < 6) {
1714
            if (nl.size() < 6) {
1716
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1715
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1717
            }
1716
            }
Lines 1726-1732 Link Here
1726
                if (idx == -1) {
1725
                if (idx == -1) {
1727
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1726
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1728
                }
1727
                }
1729
                String val = Util.findText(el);
1728
                String val = XMLUtil.findText(el);
1730
                if (val == null) {
1729
                if (val == null) {
1731
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1730
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1732
                }
1731
                }
Lines 1744-1752 Link Here
1744
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1743
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1745
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1744
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1746
                }
1745
                }
1747
                for (Element el2 : Util.findSubElements(el)) {
1746
                for (Element el2 : XMLUtil.findSubElements(el)) {
1748
                    String key = el2.getAttribute("name");
1747
                    String key = el2.getAttribute("name");
1749
                    String value = Util.findText(el2);
1748
                    String value = XMLUtil.findText(el2);
1750
                    // #53553: NPE
1749
                    // #53553: NPE
1751
                    if (value == null) {
1750
                    if (value == null) {
1752
                        value = ""; // NOI18N
1751
                        value = ""; // NOI18N
(-)a/project.ant/test/unit/src/org/netbeans/modules/project/ant/AntBasedProjectFactorySingletonTest.java (-1 / +2 lines)
Lines 58-63 Link Here
58
import org.openide.util.Lookup;
58
import org.openide.util.Lookup;
59
import org.openide.util.lookup.Lookups;
59
import org.openide.util.lookup.Lookups;
60
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
61
import org.openide.xml.XMLUtil;
61
import org.w3c.dom.Element;
62
import org.w3c.dom.Element;
62
63
63
public class AntBasedProjectFactorySingletonTest extends NbTestCase {
64
public class AntBasedProjectFactorySingletonTest extends NbTestCase {
Lines 238-244 Link Here
238
    }
239
    }
239
    private static String namesOfChildren(Element e) {
240
    private static String namesOfChildren(Element e) {
240
        StringBuilder b = new StringBuilder();
241
        StringBuilder b = new StringBuilder();
241
        for (Element kid : Util.findSubElements(e)) {
242
        for (Element kid : XMLUtil.findSubElements(e)) {
242
            if (b.length() > 0) {
243
            if (b.length() > 0) {
243
                b.append(' ');
244
                b.append(' ');
244
            }
245
            }
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntBasedTestUtil.java (-2 / +2 lines)
Lines 225-233 Link Here
225
            
225
            
226
            private String getText(String elementName) {
226
            private String getText(String elementName) {
227
                Element data = helper.getPrimaryConfigurationData(true);
227
                Element data = helper.getPrimaryConfigurationData(true);
228
                Element el = Util.findElement(data, elementName, "urn:test:shared");
228
                Element el = XMLUtil.findElement(data, elementName, "urn:test:shared");
229
                if (el != null) {
229
                if (el != null) {
230
                    String text = Util.findText(el);
230
                    String text = XMLUtil.findText(el);
231
                    if (text != null) {
231
                    if (text != null) {
232
                        return text;
232
                        return text;
233
                    }
233
                    }
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/AntProjectHelperTest.java (-37 / +36 lines)
Lines 54-60 Link Here
54
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.junit.NbTestCase;
55
import org.netbeans.junit.RandomlyFails;
55
import org.netbeans.junit.RandomlyFails;
56
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
56
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
57
import org.netbeans.modules.project.ant.Util;
58
import org.netbeans.spi.project.AuxiliaryConfiguration;
57
import org.netbeans.spi.project.AuxiliaryConfiguration;
59
import org.netbeans.spi.project.CacheDirectoryProvider;
58
import org.netbeans.spi.project.CacheDirectoryProvider;
60
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
Lines 156-167 Link Here
156
        Element data = h.getPrimaryConfigurationData(true);
155
        Element data = h.getPrimaryConfigurationData(true);
157
        assertEquals("correct element name", "data", data.getLocalName());
156
        assertEquals("correct element name", "data", data.getLocalName());
158
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
157
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
159
        Element stuff = Util.findElement(data, "shared-stuff", "urn:test:shared");
158
        Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
160
        assertNotNull("had nested stuff in it", stuff);
159
        assertNotNull("had nested stuff in it", stuff);
161
        data = h.getPrimaryConfigurationData(false);
160
        data = h.getPrimaryConfigurationData(false);
162
        assertEquals("correct element name", "data", data.getLocalName());
161
        assertEquals("correct element name", "data", data.getLocalName());
163
        assertEquals("correct element namespace", "urn:test:private", data.getNamespaceURI());
162
        assertEquals("correct element namespace", "urn:test:private", data.getNamespaceURI());
164
        stuff = Util.findElement(data, "private-stuff", "urn:test:private");
163
        stuff = XMLUtil.findElement(data, "private-stuff", "urn:test:private");
165
        assertNotNull("had nested stuff in it", stuff);
164
        assertNotNull("had nested stuff in it", stuff);
166
    }
165
    }
167
    
166
    
Lines 181-187 Link Here
181
        }
180
        }
182
        assertEquals("correct element name", "data", data.getLocalName());
181
        assertEquals("correct element name", "data", data.getLocalName());
183
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
182
        assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
184
        Element stuff = Util.findElement(data, "shared-stuff", "urn:test:shared");
183
        Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
185
        /* This now retains the former contents:
184
        /* This now retains the former contents:
186
        assertNull("had no stuff in it", stuff);
185
        assertNull("had no stuff in it", stuff);
187
         */
186
         */
Lines 192-204 Link Here
192
        pm.saveProject(p);
191
        pm.saveProject(p);
193
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
192
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
194
        Element root = doc.getDocumentElement();
193
        Element root = doc.getDocumentElement();
195
        Element type = Util.findElement(root, "type", AntProjectHelper.PROJECT_NS);
194
        Element type = XMLUtil.findElement(root, "type", AntProjectHelper.PROJECT_NS);
196
        assertEquals("correct restored type", "test", Util.findText(type));
195
        assertEquals("correct restored type", "test", XMLUtil.findText(type));
197
        Element config = Util.findElement(root, "configuration", AntProjectHelper.PROJECT_NS);
196
        Element config = XMLUtil.findElement(root, "configuration", AntProjectHelper.PROJECT_NS);
198
        assertNotNull("have <configuration>", config);
197
        assertNotNull("have <configuration>", config);
199
        data = Util.findElement(config, "data", "urn:test:shared");
198
        data = XMLUtil.findElement(config, "data", "urn:test:shared");
200
        assertNotNull("have <data>", data);
199
        assertNotNull("have <data>", data);
201
        Element details = Util.findElement(data, "details", "urn:test:shared");
200
        Element details = XMLUtil.findElement(data, "details", "urn:test:shared");
202
        assertNotNull("have <details>", details);
201
        assertNotNull("have <details>", details);
203
    }
202
    }
204
    
203
    
Lines 463-469 Link Here
463
    public void testPutPrimaryConfigurationData() throws Exception {
462
    public void testPutPrimaryConfigurationData() throws Exception {
464
        h.addAntProjectListener(l);
463
        h.addAntProjectListener(l);
465
        Element data = h.getPrimaryConfigurationData(true);
464
        Element data = h.getPrimaryConfigurationData(true);
466
        assertNotNull("<shared-stuff/> is there to start", Util.findElement(data, "shared-stuff", "urn:test:shared"));
465
        assertNotNull("<shared-stuff/> is there to start", XMLUtil.findElement(data, "shared-stuff", "urn:test:shared"));
467
        assertTrue("project is not initially modified", !pm.isModified(p));
466
        assertTrue("project is not initially modified", !pm.isModified(p));
468
        assertEquals("gPCD fires no events", 0, l.events().length);
467
        assertEquals("gPCD fires no events", 0, l.events().length);
469
        assertNotNull("config data has an owner document", data.getOwnerDocument());
468
        assertNotNull("config data has an owner document", data.getOwnerDocument());
Lines 471-477 Link Here
471
        data.appendChild(nue);
470
        data.appendChild(nue);
472
        assertTrue("project is not modified after uncommitted change", !pm.isModified(p));
471
        assertTrue("project is not modified after uncommitted change", !pm.isModified(p));
473
        assertEquals("no events fired after uncommitted change", 0, l.events().length);
472
        assertEquals("no events fired after uncommitted change", 0, l.events().length);
474
        assertEquals("after uncommitted change gPCD does not yet have new <misc/>", null, Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared"));
473
        assertEquals("after uncommitted change gPCD does not yet have new <misc/>", null, XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared"));
475
        h.putPrimaryConfigurationData(data, true);
474
        h.putPrimaryConfigurationData(data, true);
476
        assertTrue("project is modified after committed change", pm.isModified(p));
475
        assertTrue("project is modified after committed change", pm.isModified(p));
477
        AntProjectEvent[] evs = l.events();
476
        AntProjectEvent[] evs = l.events();
Lines 479-506 Link Here
479
        assertEquals("correct helper", h, evs[0].getHelper());
478
        assertEquals("correct helper", h, evs[0].getHelper());
480
        assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
479
        assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
481
        assertTrue("expected change", evs[0].isExpected());
480
        assertTrue("expected change", evs[0].isExpected());
482
        nue = Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
481
        nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
483
        assertNotNull("after committed change gPCD has new <misc/>", nue);
482
        assertNotNull("after committed change gPCD has new <misc/>", nue);
484
        assertEquals("new element name is correct", "misc", nue.getLocalName());
483
        assertEquals("new element name is correct", "misc", nue.getLocalName());
485
        assertEquals("new element namespace is correct", "urn:test:shared", nue.getNamespaceURI());
484
        assertEquals("new element namespace is correct", "urn:test:shared", nue.getNamespaceURI());
486
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
485
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
487
        Element configuration = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
486
        Element configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
488
        assertNotNull("still has <configuration> on disk", configuration);
487
        assertNotNull("still has <configuration> on disk", configuration);
489
        data = Util.findElement(configuration, "data", "urn:test:shared");
488
        data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
490
        assertNotNull("still has <data> on disk", data);
489
        assertNotNull("still has <data> on disk", data);
491
        nue = Util.findElement(data, "misc", "urn:test:shared");
490
        nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
492
        assertEquals("<misc/> not yet on disk", null, nue);
491
        assertEquals("<misc/> not yet on disk", null, nue);
493
        pm.saveProject(p);
492
        pm.saveProject(p);
494
        assertTrue("project is not modified after save", !pm.isModified(p));
493
        assertTrue("project is not modified after save", !pm.isModified(p));
495
        assertEquals("saving changes fires no new events", 0, l.events().length);
494
        assertEquals("saving changes fires no new events", 0, l.events().length);
496
        nue = Util.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
495
        nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
497
        assertNotNull("after save gPCD still has new <misc/>", nue);
496
        assertNotNull("after save gPCD still has new <misc/>", nue);
498
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
497
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
499
        configuration = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
498
        configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
500
        assertNotNull("still has <configuration> on disk", configuration);
499
        assertNotNull("still has <configuration> on disk", configuration);
501
        data = Util.findElement(configuration, "data", "urn:test:shared");
500
        data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
502
        assertNotNull("still has <data> on disk", data);
501
        assertNotNull("still has <data> on disk", data);
503
        nue = Util.findElement(data, "misc", "urn:test:shared");
502
        nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
504
        assertNotNull("<misc/> now on disk", nue);
503
        assertNotNull("<misc/> now on disk", nue);
505
        // #42147: changes made on disk should result in firing of an AntProjectEvent
504
        // #42147: changes made on disk should result in firing of an AntProjectEvent
506
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
505
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
Lines 516-527 Link Here
516
        assertFalse("unexpected change", evs[0].isExpected());
515
        assertFalse("unexpected change", evs[0].isExpected());
517
        assertEquals("correct new display name", "Some New Name", ProjectUtils.getInformation(p).getDisplayName());
516
        assertEquals("correct new display name", "Some New Name", ProjectUtils.getInformation(p).getDisplayName());
518
        data = h.getPrimaryConfigurationData(true);
517
        data = h.getPrimaryConfigurationData(true);
519
        Element stuff = Util.findElement(data, "other-shared-stuff", "urn:test:shared");
518
        Element stuff = XMLUtil.findElement(data, "other-shared-stuff", "urn:test:shared");
520
        assertNotNull("have <other-shared-stuff/> now", stuff);
519
        assertNotNull("have <other-shared-stuff/> now", stuff);
521
        AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
520
        AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
522
        data = aux.getConfigurationFragment("data", "urn:test:shared-aux", true);
521
        data = aux.getConfigurationFragment("data", "urn:test:shared-aux", true);
523
        assertNotNull("have aux <data>", data);
522
        assertNotNull("have aux <data>", data);
524
        stuff = Util.findElement(data, "other-aux-shared-stuff", "urn:test:shared-aux");
523
        stuff = XMLUtil.findElement(data, "other-aux-shared-stuff", "urn:test:shared-aux");
525
        assertNotNull("have <other-aux-shared-stuff/> now", stuff);
524
        assertNotNull("have <other-aux-shared-stuff/> now", stuff);
526
        // XXX try private.xml too
525
        // XXX try private.xml too
527
        // XXX try modifying both XML files, or different parts of the same, and saving in a batch
526
        // XXX try modifying both XML files, or different parts of the same, and saving in a batch
Lines 551-557 Link Here
551
        assertNotNull("found shared <data>", data);
550
        assertNotNull("found shared <data>", data);
552
        assertEquals("correct name", "data", data.getLocalName());
551
        assertEquals("correct name", "data", data.getLocalName());
553
        assertEquals("correct namespace", "urn:test:shared-aux", data.getNamespaceURI());
552
        assertEquals("correct namespace", "urn:test:shared-aux", data.getNamespaceURI());
554
        Element stuff = Util.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
553
        Element stuff = XMLUtil.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
555
        assertNotNull("found <aux-shared-stuff/>", stuff);
554
        assertNotNull("found <aux-shared-stuff/>", stuff);
556
        assertEquals("gCF fires no changes", 0, l.events().length);
555
        assertEquals("gCF fires no changes", 0, l.events().length);
557
        // Check write of shared data.
556
        // Check write of shared data.
Lines 567-577 Link Here
567
        pm.saveProject(p);
566
        pm.saveProject(p);
568
        assertEquals("saving project fires no new changes", 0, l.events().length);
567
        assertEquals("saving project fires no new changes", 0, l.events().length);
569
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
568
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
570
        Element config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
569
        Element config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
571
        assertNotNull("<configuration> still exists", config);
570
        assertNotNull("<configuration> still exists", config);
572
        data = Util.findElement(config, "data", "urn:test:shared-aux");
571
        data = XMLUtil.findElement(config, "data", "urn:test:shared-aux");
573
        assertNotNull("<data> still exists", data);
572
        assertNotNull("<data> still exists", data);
574
        stuff = Util.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
573
        stuff = XMLUtil.findElement(data, "aux-shared-stuff", "urn:test:shared-aux");
575
        assertNotNull("still have <aux-shared-stuff/>", stuff);
574
        assertNotNull("still have <aux-shared-stuff/>", stuff);
576
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
575
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
577
        // Check read of private data.
576
        // Check read of private data.
Lines 579-585 Link Here
579
        assertNotNull("found shared <data>", data);
578
        assertNotNull("found shared <data>", data);
580
        assertEquals("correct name", "data", data.getLocalName());
579
        assertEquals("correct name", "data", data.getLocalName());
581
        assertEquals("correct namespace", "urn:test:private-aux", data.getNamespaceURI());
580
        assertEquals("correct namespace", "urn:test:private-aux", data.getNamespaceURI());
582
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
581
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
583
        assertNotNull("found <aux-private-stuff/>", stuff);
582
        assertNotNull("found <aux-private-stuff/>", stuff);
584
        assertEquals("gCF fires no changes", 0, l.events().length);
583
        assertEquals("gCF fires no changes", 0, l.events().length);
585
        // Check write of private data.
584
        // Check write of private data.
Lines 596-604 Link Here
596
        assertEquals("saving project fires no new changes", 0, l.events().length);
595
        assertEquals("saving project fires no new changes", 0, l.events().length);
597
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
596
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
598
        config = doc.getDocumentElement();
597
        config = doc.getDocumentElement();
599
        data = Util.findElement(config, "data", "urn:test:private-aux");
598
        data = XMLUtil.findElement(config, "data", "urn:test:private-aux");
600
        assertNotNull("<data> still exists", data);
599
        assertNotNull("<data> still exists", data);
601
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
600
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
602
        assertNotNull("still have <aux-private-stuff/>", stuff);
601
        assertNotNull("still have <aux-private-stuff/>", stuff);
603
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
602
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
604
        // Check that missing fragments are not returned.
603
        // Check that missing fragments are not returned.
Lines 625-635 Link Here
625
        data = aux.getConfigurationFragment("hello", "urn:test:whatever", true);
624
        data = aux.getConfigurationFragment("hello", "urn:test:whatever", true);
626
        assertNotNull("can retrieve new frag", data);
625
        assertNotNull("can retrieve new frag", data);
627
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
626
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
628
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
627
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
629
        assertNotNull("<configuration> still exists", config);
628
        assertNotNull("<configuration> still exists", config);
630
        data = Util.findElement(config, "hello", "urn:test:whatever");
629
        data = XMLUtil.findElement(config, "hello", "urn:test:whatever");
631
        assertNotNull("<hello> still exists", data);
630
        assertNotNull("<hello> still exists", data);
632
        assertEquals("correct nested contents too", "stuff", Util.findText(data));
631
        assertEquals("correct nested contents too", "stuff", XMLUtil.findText(data));
633
        // Try removing a fragment.
632
        // Try removing a fragment.
634
        assertFalse("project is unmodified", pm.isModified(p));
633
        assertFalse("project is unmodified", pm.isModified(p));
635
        assertTrue("can remove new frag", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
634
        assertTrue("can remove new frag", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
Lines 637-645 Link Here
637
        assertNull("now frag is gone", aux.getConfigurationFragment("hello", "urn:test:whatever", true));
636
        assertNull("now frag is gone", aux.getConfigurationFragment("hello", "urn:test:whatever", true));
638
        pm.saveProject(p);
637
        pm.saveProject(p);
639
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
638
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
640
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
639
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
641
        assertNotNull("<configuration> still exists", config);
640
        assertNotNull("<configuration> still exists", config);
642
        data = Util.findElement(config, "hello", "urn:test:whatever");
641
        data = XMLUtil.findElement(config, "hello", "urn:test:whatever");
643
        assertNull("now <hello> is gone", data);
642
        assertNull("now <hello> is gone", data);
644
        assertFalse("cannot remove a frag that is not there", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
643
        assertFalse("cannot remove a frag that is not there", aux.removeConfigurationFragment("hello", "urn:test:whatever", true));
645
        assertFalse("trying to remove a nonexistent frag does not modify project", pm.isModified(p));
644
        assertFalse("trying to remove a nonexistent frag does not modify project", pm.isModified(p));
Lines 659-665 Link Here
659
        aux.putConfigurationFragment(data, true);
658
        aux.putConfigurationFragment(data, true);
660
        pm.saveProject(p);
659
        pm.saveProject(p);
661
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
660
        doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
662
        config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
661
        config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
663
        String[] names = new String[]{"aaa-namespace", "aaaa-namespace", "bbb-name-sp", "bbb-namespace", "bbb-namespace-1", "ccc-namespace", "data-urn:test:shared", "data-urn:test:shared-aux"};
662
        String[] names = new String[]{"aaa-namespace", "aaaa-namespace", "bbb-name-sp", "bbb-namespace", "bbb-namespace-1", "ccc-namespace", "data-urn:test:shared", "data-urn:test:shared-aux"};
664
        int count = 0;
663
        int count = 0;
665
        NodeList list = config.getChildNodes();
664
        NodeList list = config.getChildNodes();
Lines 684-690 Link Here
684
        assertNotNull("AuxiliaryConfiguration present", aux);
683
        assertNotNull("AuxiliaryConfiguration present", aux);
685
684
686
        Element data = aux.getConfigurationFragment("data", "urn:test:private-aux", false);
685
        Element data = aux.getConfigurationFragment("data", "urn:test:private-aux", false);
687
        Element stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
686
        Element stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
688
        assertNotNull("found <aux-private-stuff/>", stuff);
687
        assertNotNull("found <aux-private-stuff/>", stuff);
689
        // Check write of private data.
688
        // Check write of private data.
690
        stuff.setAttribute("attr", "val");
689
        stuff.setAttribute("attr", "val");
Lines 710-718 Link Here
710
        //check the data are written:
709
        //check the data are written:
711
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
710
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
712
        Element config = doc.getDocumentElement();
711
        Element config = doc.getDocumentElement();
713
        data = Util.findElement(config, "data", "urn:test:private-aux");
712
        data = XMLUtil.findElement(config, "data", "urn:test:private-aux");
714
        assertNotNull("<data> still exists", data);
713
        assertNotNull("<data> still exists", data);
715
        stuff = Util.findElement(data, "aux-private-stuff", "urn:test:private-aux");
714
        stuff = XMLUtil.findElement(data, "aux-private-stuff", "urn:test:private-aux");
716
        assertNotNull("still have <aux-private-stuff/>", stuff);
715
        assertNotNull("still have <aux-private-stuff/>", stuff);
717
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
716
        assertEquals("attr written correctly", "val", stuff.getAttribute("attr"));
718
        
717
        
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/GeneratedFilesHelperTest.java (-3 / +3 lines)
Lines 52-64 Link Here
52
import org.netbeans.api.project.TestUtil;
52
import org.netbeans.api.project.TestUtil;
53
import org.netbeans.junit.NbTestCase;
53
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.modules.project.ant.AntBuildExtenderAccessor;
54
import org.netbeans.modules.project.ant.AntBuildExtenderAccessor;
55
import org.netbeans.modules.project.ant.Util;
56
import org.netbeans.spi.project.AuxiliaryConfiguration;
55
import org.netbeans.spi.project.AuxiliaryConfiguration;
57
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileObject;
58
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
59
import org.openide.modules.SpecificationVersion;
58
import org.openide.modules.SpecificationVersion;
60
import org.openide.util.Utilities;
59
import org.openide.util.Utilities;
61
import org.openide.util.test.MockLookup;
60
import org.openide.util.test.MockLookup;
61
import org.openide.xml.XMLUtil;
62
import org.w3c.dom.Document;
62
import org.w3c.dom.Document;
63
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
64
import org.w3c.dom.NodeList;
64
import org.w3c.dom.NodeList;
Lines 111-117 Link Here
111
        assertNull("No build-impl.xml yet", bi);
111
        assertNull("No build-impl.xml yet", bi);
112
        // Modify shared data in a project.
112
        // Modify shared data in a project.
113
        Element primdata = h.getPrimaryConfigurationData(true);
113
        Element primdata = h.getPrimaryConfigurationData(true);
114
        Element oldDisplayName = Util.findElement(primdata, "display-name", "urn:test:shared");
114
        Element oldDisplayName = XMLUtil.findElement(primdata, "display-name", "urn:test:shared");
115
        assertNotNull("had a <display-name> before", oldDisplayName);
115
        assertNotNull("had a <display-name> before", oldDisplayName);
116
        Element displayName = primdata.getOwnerDocument().createElementNS("urn:test:shared", "display-name");
116
        Element displayName = primdata.getOwnerDocument().createElementNS("urn:test:shared", "display-name");
117
        displayName.appendChild(primdata.getOwnerDocument().createTextNode("New Name"));
117
        displayName.appendChild(primdata.getOwnerDocument().createTextNode("New Name"));
Lines 132-138 Link Here
132
        NodeList l = doc.getElementsByTagName("description");
132
        NodeList l = doc.getElementsByTagName("description");
133
        assertEquals("one <description> in build-impl.xml", 1, l.getLength());
133
        assertEquals("one <description> in build-impl.xml", 1, l.getLength());
134
        el = (Element)l.item(0);
134
        el = (Element)l.item(0);
135
        assertEquals("correct description", "New Name", Util.findText(el));
135
        assertEquals("correct description", "New Name", XMLUtil.findText(el));
136
        // Clear build-impl.xml to test if it is rewritten.
136
        // Clear build-impl.xml to test if it is rewritten.
137
        bi.delete();
137
        bi.delete();
138
        // Now make some irrelevant change - e.g. to private.xml - and check that there is no modification.
138
        // Now make some irrelevant change - e.g. to private.xml - and check that there is no modification.
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ProjectGeneratorTest.java (-2 / +2 lines)
Lines 49-61 Link Here
49
import org.netbeans.api.project.TestUtil;
49
import org.netbeans.api.project.TestUtil;
50
import org.netbeans.junit.NbTestCase;
50
import org.netbeans.junit.NbTestCase;
51
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
51
import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton;
52
import org.netbeans.modules.project.ant.Util;
53
import org.netbeans.api.project.ProjectInformation;
52
import org.netbeans.api.project.ProjectInformation;
54
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
55
import org.openide.filesystems.FileUtil;
54
import org.openide.filesystems.FileUtil;
56
import org.openide.util.Mutex;
55
import org.openide.util.Mutex;
57
import org.openide.util.MutexException;
56
import org.openide.util.MutexException;
58
import org.openide.util.test.MockLookup;
57
import org.openide.util.test.MockLookup;
58
import org.openide.xml.XMLUtil;
59
import org.w3c.dom.Document;
59
import org.w3c.dom.Document;
60
import org.w3c.dom.Element;
60
import org.w3c.dom.Element;
61
import org.w3c.dom.NodeList;
61
import org.w3c.dom.NodeList;
Lines 142-148 Link Here
142
                    NodeList l = doc.getElementsByTagNameNS(AntProjectHelper.PROJECT_NS, "type");
142
                    NodeList l = doc.getElementsByTagNameNS(AntProjectHelper.PROJECT_NS, "type");
143
                    assertEquals("one <type>", 1, l.getLength());
143
                    assertEquals("one <type>", 1, l.getLength());
144
                    Element el = (Element)l.item(0);
144
                    Element el = (Element)l.item(0);
145
                    assertEquals("correct saved type", "test", Util.findText(el));
145
                    assertEquals("correct saved type", "test", XMLUtil.findText(el));
146
                    l = doc.getElementsByTagNameNS("urn:test:shared", "shared-stuff");
146
                    l = doc.getElementsByTagNameNS("urn:test:shared", "shared-stuff");
147
                    assertEquals("one <shared-stuff>", 1, l.getLength());
147
                    assertEquals("one <shared-stuff>", 1, l.getLength());
148
                    doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
148
                    doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PRIVATE_XML_PATH);
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java (-8 / +8 lines)
Lines 63-69 Link Here
63
import org.netbeans.api.queries.CollocationQuery;
63
import org.netbeans.api.queries.CollocationQuery;
64
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.junit.NbTestCase;
65
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
65
import org.netbeans.modules.project.ant.ProjectLibraryProvider;
66
import org.netbeans.modules.project.ant.Util;
67
import org.netbeans.spi.project.AuxiliaryConfiguration;
66
import org.netbeans.spi.project.AuxiliaryConfiguration;
68
import org.netbeans.spi.project.SubprojectProvider;
67
import org.netbeans.spi.project.SubprojectProvider;
69
import org.netbeans.spi.queries.CollocationQueryImplementation;
68
import org.netbeans.spi.queries.CollocationQueryImplementation;
Lines 71-76 Link Here
71
import org.openide.filesystems.FileUtil;
70
import org.openide.filesystems.FileUtil;
72
import org.openide.util.lookup.Lookups;
71
import org.openide.util.lookup.Lookups;
73
import org.openide.util.test.MockLookup;
72
import org.openide.util.test.MockLookup;
73
import org.openide.xml.XMLUtil;
74
import org.w3c.dom.Document;
74
import org.w3c.dom.Document;
75
import org.w3c.dom.Element;
75
import org.w3c.dom.Element;
76
import org.w3c.dom.NodeList;
76
import org.w3c.dom.NodeList;
Lines 342-350 Link Here
342
        assertTrue("Project is still modified", pm.isModified(p));
342
        assertTrue("Project is still modified", pm.isModified(p));
343
        pm.saveProject(p);
343
        pm.saveProject(p);
344
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
344
        Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
345
        Element config = Util.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
345
        Element config = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
346
        assertNotNull("have <configuration>", config);
346
        assertNotNull("have <configuration>", config);
347
        Element references = Util.findElement(config, ReferenceHelper.REFS_NAME, ReferenceHelper.REFS_NS);
347
        Element references = XMLUtil.findElement(config, ReferenceHelper.REFS_NAME, ReferenceHelper.REFS_NS);
348
        assertNotNull("have <references>", references);
348
        assertNotNull("have <references>", references);
349
        NodeList nl = references.getElementsByTagNameNS(ReferenceHelper.REFS_NS, "reference");
349
        NodeList nl = references.getElementsByTagNameNS(ReferenceHelper.REFS_NS, "reference");
350
        assertEquals("have three <reference>s", 3, nl.getLength());
350
        assertEquals("have three <reference>s", 3, nl.getLength());
Lines 386-394 Link Here
386
            Element reference = (Element)nl.item(i);
386
            Element reference = (Element)nl.item(i);
387
            for (int j = 0; j < 6; j++) {
387
            for (int j = 0; j < 6; j++) {
388
                String elementName = elementNames[j];
388
                String elementName = elementNames[j];
389
                Element element = Util.findElement(reference, elementName, ReferenceHelper.REFS_NS);
389
                Element element = XMLUtil.findElement(reference, elementName, ReferenceHelper.REFS_NS);
390
                assertNotNull("had element " + elementName + " in ref #" + i, element);
390
                assertNotNull("had element " + elementName + " in ref #" + i, element);
391
                assertEquals("correct text in " + elementName + " in ref #" + i, values[i][j], Util.findText(element));
391
                assertEquals("correct text in " + elementName + " in ref #" + i, values[i][j], XMLUtil.findText(element));
392
            }
392
            }
393
        }
393
        }
394
    }
394
    }
Lines 1080-1088 Link Here
1080
        Element refs = p.getLookup().lookup(AuxiliaryConfiguration.class).getConfigurationFragment(ReferenceHelper.REFS_NAME, namespace, true);
1080
        Element refs = p.getLookup().lookup(AuxiliaryConfiguration.class).getConfigurationFragment(ReferenceHelper.REFS_NAME, namespace, true);
1081
        assertNotNull(refs);
1081
        assertNotNull(refs);
1082
        List<String> actualScriptLocations = new ArrayList<String>();
1082
        List<String> actualScriptLocations = new ArrayList<String>();
1083
        for (Element ref : Util.findSubElements(refs)) {
1083
        for (Element ref : XMLUtil.findSubElements(refs)) {
1084
            Element script = Util.findElement(ref, "script", namespace);
1084
            Element script = XMLUtil.findElement(ref, "script", namespace);
1085
            actualScriptLocations.add(Util.findText(script));
1085
            actualScriptLocations.add(XMLUtil.findText(script));
1086
        }
1086
        }
1087
        assertEquals(Arrays.asList(scriptLocations), actualScriptLocations);
1087
        assertEquals(Arrays.asList(scriptLocations), actualScriptLocations);
1088
    }
1088
    }

Return to bug 136595