KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ProjectXMLManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.SortedSet JavaDoc;
34 import java.util.TreeSet JavaDoc;
35 import org.netbeans.api.project.ProjectManager;
36 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider;
37 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider.NbModuleType;
38 import org.netbeans.modules.apisupport.project.suite.SuiteProjectType;
39 import org.netbeans.modules.apisupport.project.ui.customizer.ModuleDependency;
40 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
41 import org.openide.ErrorManager;
42 import org.openide.filesystems.FileLock;
43 import org.openide.filesystems.FileObject;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.xml.XMLUtil;
46 import org.w3c.dom.Document JavaDoc;
47 import org.w3c.dom.Element JavaDoc;
48 import org.netbeans.modules.apisupport.project.universe.ModuleList;
49 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
50 import org.netbeans.modules.apisupport.project.universe.TestModuleDependency;
51 import org.w3c.dom.Node JavaDoc;
52 import org.w3c.dom.NodeList JavaDoc;
53
54 /**
55  * Convenience class for managing project's <em>project.xml</em> file. You
56  * should explicitly enclose a <em>complete</em> operation within write access
57  * to prevent race conditions. Use {@link ProjectManager#saveProject} to apply
58  * changes <em>physically</em>.
59  */

60 public final class ProjectXMLManager {
61     
62     /** Equal to AntProjectHelper.PROJECT_NS which is package private. */
63     // XXX is there a better way? (impact of imposibility to use ProjectGenerator)
64
private static final String JavaDoc PROJECT_NS =
65             "http://www.netbeans.org/ns/project/1"; // NOI18N
66

67     // elements constants
68
private static final String JavaDoc BINARY_ORIGIN = "binary-origin"; // NOI18N
69
private static final String JavaDoc BUILD_PREREQUISITE = "build-prerequisite"; // NOI18N
70
private static final String JavaDoc CLASS_PATH_BINARY_ORIGIN = "binary-origin"; //NOI18N
71
private static final String JavaDoc CLASS_PATH_EXTENSION = "class-path-extension"; // NOI18N
72
private static final String JavaDoc CLASS_PATH_RUNTIME_PATH = "runtime-relative-path"; //NOI18N
73
private static final String JavaDoc CODE_NAME_BASE = "code-name-base"; // NOI18N
74
private static final String JavaDoc COMPILE_DEPENDENCY = "compile-dependency"; // NOI18N
75
private static final String JavaDoc DATA = "data"; // NOI18N
76
private static final String JavaDoc DEPENDENCY = "dependency"; // NOI18N
77
private static final String JavaDoc EXTRA_COMPILATION_UNIT = "extra-compilation-unit"; // NOI18N
78
private static final String JavaDoc FRIEND = "friend"; // NOI18N
79
private static final String JavaDoc FRIEND_PACKAGES = "friend-packages"; // NOI18N
80
private static final String JavaDoc IMPLEMENTATION_VERSION = "implementation-version"; // NOI18N
81
private static final String JavaDoc MODULE_DEPENDENCIES = "module-dependencies"; // NOI18N
82
private static final String JavaDoc PACKAGE = "package"; // NOI18N
83
private static final String JavaDoc PUBLIC_PACKAGES= "public-packages"; // NOI18N
84
private static final String JavaDoc RELEASE_VERSION = "release-version"; // NOI18N
85
private static final String JavaDoc RUN_DEPENDENCY = "run-dependency"; // NOI18N
86
private static final String JavaDoc SPECIFICATION_VERSION = "specification-version"; // NOI18N
87
private static final String JavaDoc STANDALONE = "standalone"; // NOI18N
88
private static final String JavaDoc SUBPACKAGES = "subpackages"; // NOI18N
89
private static final String JavaDoc SUITE_COMPONENT = "suite-component"; // NOI18N
90
private static final String JavaDoc TEST_DEPENDENCIES = "test-dependencies"; // NOI18N
91
private static final String JavaDoc TEST_TYPE_NAME = "name"; // NOI18N
92
private static final String JavaDoc TEST_DEPENDENCY = "test-dependency"; // NOI18N
93
private static final String JavaDoc TEST_DEPENDENCY_CNB = "code-name-base"; // NOI18N
94
private static final String JavaDoc TEST_DEPENDENCY_RECURSIVE = "recursive"; // NOI18N
95
private static final String JavaDoc TEST_DEPENDENCY_COMPILE = "compile-dependency"; // NOI18N
96
private static final String JavaDoc TEST_DEPENDENCY_TEST = "test"; // NOI18N
97
private static final String JavaDoc TEST_TYPE = "test-type"; //NOI18N
98

99     private final NbModuleProject project;
100     private NbPlatform customPlaf;
101     
102     private String JavaDoc cnb;
103     private SortedSet JavaDoc<ModuleDependency> directDeps;
104     private ManifestManager.PackageExport[] publicPackages;
105     private String JavaDoc[] cpExtensions;
106     private String JavaDoc[] friends;
107     
108     // cached confData element for easy access with getConfData
109
private Element JavaDoc confData;
110     
111     /** Creates a new instance of {@link ProjectXMLManager}. */
112     public ProjectXMLManager(final NbModuleProject project) {
113         this.project = project;
114     }
115     
116     /**
117      * Utility mehtod for getting the {@link ProjectXMLManager instance}
118      * associated with a project in the given directory.
119      *
120      * @throws IOException if the project under a given <code>projectDir</code>
121      * was recognized but could not be loaded (see {@link ProjectManager#findProject}).
122      */

123     public static ProjectXMLManager getInstance(final File JavaDoc projectDir) throws IOException JavaDoc {
124         FileObject dir = FileUtil.toFileObject(projectDir);
125         NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(dir);
126         return new ProjectXMLManager(p);
127     }
128     
129     public void setModuleType(NbModuleType moduleType) {
130         Element JavaDoc confData = getConfData();
131         Document JavaDoc doc = confData.getOwnerDocument();
132         
133         Element JavaDoc standaloneEl = findElement(confData, ProjectXMLManager.STANDALONE);
134         if (standaloneEl != null && moduleType == NbModuleProvider.STANDALONE) {
135             // nothing needs to be done - standalone is already set
136
return;
137         }
138         
139         Element JavaDoc suiteCompEl = findElement(confData, ProjectXMLManager.SUITE_COMPONENT);
140         if (suiteCompEl != null && moduleType == NbModuleProvider.SUITE_COMPONENT) {
141             // nothing needs to be done - suiteCompEl is already set
142
return;
143         }
144         
145         if (suiteCompEl == null && standaloneEl == null && moduleType == NbModuleProvider.NETBEANS_ORG) {
146             // nothing needs to be done - nb.org modules don't have any element
147
return;
148         }
149         
150         // Ok, we get here. So clean up....
151
if (suiteCompEl != null) {
152             confData.removeChild(suiteCompEl);
153         }
154         if (standaloneEl != null) {
155             confData.removeChild(standaloneEl);
156         }
157         
158         // ....and create element for new module type.
159
Element JavaDoc newModuleType = createTypeElement(doc, moduleType);
160         if (newModuleType != null) {
161             confData.insertBefore(newModuleType, findModuleDependencies(confData));
162         }
163         project.putPrimaryConfigurationData(confData);
164     }
165     
166     /**
167      * Returns direct module dependencies using default module's platform. See
168      * {@link #getDirectDependencies(NbPlatform)} for more details to which
169      * this method delegates.
170      */

171     public SortedSet JavaDoc<ModuleDependency> getDirectDependencies() throws IOException JavaDoc {
172         return getDirectDependencies(null);
173     }
174     
175     /**
176      * Returns sorted direct module dependencies using {@link
177      * ModuleDependency#CNB_COMPARATOR} allowing to pass a custom platform.
178      * Since no two modules with the same code name base may be set as a
179      * dependency. Also this is ordering used in the <em>project.xml</em>.
180      */

181     public SortedSet JavaDoc<ModuleDependency> getDirectDependencies(final NbPlatform customPlaf) throws IOException JavaDoc {
182         if (this.customPlaf == customPlaf && this.directDeps != null) {
183             return this.directDeps;
184         }
185         this.customPlaf = customPlaf;
186         SortedSet JavaDoc<ModuleDependency> directDeps = new TreeSet JavaDoc(ModuleDependency.CNB_COMPARATOR);
187         Element JavaDoc moduleDependencies = findModuleDependencies(getConfData());
188         assert moduleDependencies != null : "Cannot find <module-dependencies> for: " + project;
189         List JavaDoc<Element JavaDoc> deps = Util.findSubElements(moduleDependencies);
190         File JavaDoc prjDirF = project.getProjectDirectoryFile();
191         ModuleList ml;
192         if (customPlaf != null) {
193             ml = ModuleList.getModuleList(prjDirF, customPlaf.getDestDir());
194         } else {
195             ml = ModuleList.getModuleList(prjDirF);
196         }
197         for (Iterator JavaDoc it = deps.iterator(); it.hasNext(); ) {
198             Element JavaDoc depEl = (Element JavaDoc)it.next();
199             
200             Element JavaDoc cnbEl = findElement(depEl, ProjectXMLManager.CODE_NAME_BASE);
201             String JavaDoc cnb = Util.findText(cnbEl);
202             ModuleEntry me = ml.getEntry(cnb);
203             if (me == null) {
204                 // XXX might be e.g. shown in nb.errorForreground and "disabled"
205
Util.err.log(ErrorManager.WARNING,
206                         "Detected dependency on module which cannot be found in " + // NOI18N
207
"the current module's universe (platform, suite): " + // NOI18N
208
cnb + " (skipping)"); // NOI18N
209
continue;
210             }
211             
212             Element JavaDoc runDepEl = findElement(depEl, ProjectXMLManager.RUN_DEPENDENCY);
213             if (runDepEl == null) {
214                 if (!directDeps.add(new ModuleDependency(me))) {
215                     String JavaDoc errMessage = "Corrupted project metadata (project.xml). " + // NOI18N
216
"Duplicate dependency entry found: " + me; // NOI18N
217
Util.err.log(ErrorManager.WARNING, errMessage);
218                     throw new IllegalStateException JavaDoc(errMessage);
219                 }
220                 continue;
221             }
222             
223             Element JavaDoc relVerEl = findElement(runDepEl, ProjectXMLManager.RELEASE_VERSION);
224             String JavaDoc relVer = null;
225             if (relVerEl != null) {
226                 relVer = Util.findText(relVerEl);
227             }
228             
229             Element JavaDoc specVerEl = findElement(runDepEl, ProjectXMLManager.SPECIFICATION_VERSION);
230             String JavaDoc specVer = null;
231             if (specVerEl != null) {
232                 specVer = Util.findText(specVerEl);
233             }
234             
235             Element JavaDoc compDepEl = findElement(depEl, ProjectXMLManager.COMPILE_DEPENDENCY);
236             Element JavaDoc impleVerEl = findElement(runDepEl, ProjectXMLManager.IMPLEMENTATION_VERSION);
237             
238             ModuleDependency depToAdd = new ModuleDependency(
239                     me, relVer, specVer, compDepEl != null, impleVerEl != null);
240             if (!directDeps.add(depToAdd)) {
241                 String JavaDoc errMessage = "Corrupted project metadata (project.xml). " + // NOI18N
242
"Duplicate dependency entry found: " + depToAdd; // NOI18N
243
Util.err.log(ErrorManager.WARNING, errMessage);
244                 throw new IllegalStateException JavaDoc(errMessage);
245             }
246         }
247         this.directDeps = Collections.unmodifiableSortedSet(directDeps);
248         return this.directDeps;
249     }
250     
251     /** Remove given dependency from the configuration data. */
252     public void removeDependency(String JavaDoc cnbToRemove) {
253         Element JavaDoc confData = getConfData();
254         Element JavaDoc moduleDependencies = findModuleDependencies(confData);
255         List JavaDoc<Element JavaDoc> currentDeps = Util.findSubElements(moduleDependencies);
256         for (Iterator JavaDoc it = currentDeps.iterator(); it.hasNext(); ) {
257             Element JavaDoc dep = (Element JavaDoc)it.next();
258             Element JavaDoc cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
259             String JavaDoc cnb = Util.findText(cnbEl);
260             if (cnbToRemove.equals(cnb)) {
261                 moduleDependencies.removeChild(dep);
262             }
263         }
264         project.putPrimaryConfigurationData(confData);
265     }
266     
267     /**
268      * Use this for removing more than one dependencies. It's faster then
269      * iterating and using <code>removeDependency</code> for every entry.
270      */

271     public void removeDependencies(Collection JavaDoc<ModuleDependency> depsToDelete) {
272         Set JavaDoc cnbsToDelete = new HashSet JavaDoc(depsToDelete.size());
273         for (Iterator JavaDoc it = depsToDelete.iterator(); it.hasNext(); ) {
274             cnbsToDelete.add(((ModuleDependency) it.next()).
275                     getModuleEntry().getCodeNameBase());
276         }
277         removeDependenciesByCNB(cnbsToDelete);
278     }
279     
280     /**
281      * Use this for removing more than one dependencies. It's faster then
282      * iterating and using <code>removeDependency</code> for every entry.
283      */

284     public void removeDependenciesByCNB(Collection JavaDoc<String JavaDoc> cnbsToDelete) {
285         Element JavaDoc confData = getConfData();
286         Element JavaDoc moduleDependencies = findModuleDependencies(confData);
287         List JavaDoc<Element JavaDoc> currentDeps = Util.findSubElements(moduleDependencies);
288         for (Iterator JavaDoc it = currentDeps.iterator(); it.hasNext(); ) {
289             Element JavaDoc dep = (Element JavaDoc)it.next();
290             Element JavaDoc cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
291             String JavaDoc cnb = Util.findText(cnbEl);
292             if (cnbsToDelete.remove(cnb)) {
293                 moduleDependencies.removeChild(dep);
294             }
295             if (cnbsToDelete.size() == 0) {
296                 break; // everything was deleted
297
}
298         }
299         if (cnbsToDelete.size() != 0) {
300             Util.err.log(ErrorManager.WARNING,
301                     "Some modules weren't deleted: " + cnbsToDelete); // NOI18N
302
}
303         project.putPrimaryConfigurationData(confData);
304     }
305     
306     public void editDependency(ModuleDependency origDep, ModuleDependency newDep) {
307         Element JavaDoc confData = getConfData();
308         Element JavaDoc moduleDependencies = findModuleDependencies(confData);
309         List JavaDoc<Element JavaDoc> currentDeps = Util.findSubElements(moduleDependencies);
310         for (Iterator JavaDoc it = currentDeps.iterator(); it.hasNext(); ) {
311             Element JavaDoc dep = (Element JavaDoc) it.next();
312             Element JavaDoc cnbEl = findElement(dep, ProjectXMLManager.CODE_NAME_BASE);
313             String JavaDoc cnb = Util.findText(cnbEl);
314             if (cnb.equals(origDep.getModuleEntry().getCodeNameBase())) {
315                 moduleDependencies.removeChild(dep);
316                 Element JavaDoc nextDep = it.hasNext() ? (Element JavaDoc) it.next() : null;
317                 createModuleDependencyElement(moduleDependencies, newDep, nextDep);
318                 break;
319             }
320         }
321         project.putPrimaryConfigurationData(confData);
322     }
323     
324     /**
325      * Adds given dependency.
326      */

327     public void addDependency(ModuleDependency md) throws IOException JavaDoc {
328         addDependencies(Collections.singleton(md));
329     }
330     
331     /**
332      * Adds given modules as module-dependencies for the project.
333      */

334     public void addDependencies(final Set JavaDoc<ModuleDependency> toAdd) throws IOException JavaDoc {
335         SortedSet JavaDoc deps = new TreeSet JavaDoc(getDirectDependencies());
336         if (deps.addAll(toAdd)) {
337             replaceDependencies(deps);
338         }
339     }
340     
341     /**
342      * Replaces all original dependencies with the given <code>newDeps</code>.
343      */

344     public void replaceDependencies(final Set JavaDoc<ModuleDependency> newDeps) {
345         Element JavaDoc confData = getConfData();
346         Document JavaDoc doc = confData.getOwnerDocument();
347         Element JavaDoc moduleDependencies = findModuleDependencies(confData);
348         confData.removeChild(moduleDependencies);
349         moduleDependencies = createModuleElement(doc, ProjectXMLManager.MODULE_DEPENDENCIES);
350         Element JavaDoc before = findTestDependenciesElement(confData);
351         if (before == null) {
352             before = findPublicPackagesElement(confData);
353         }
354         if (before == null) {
355             before = findFriendsElement(confData);
356         }
357         assert before != null : "There must be " + PUBLIC_PACKAGES + " or " // NOI18N
358
+ FRIEND_PACKAGES + " element according to XSD"; // NOI18N
359
confData.insertBefore(moduleDependencies, before);
360         SortedSet JavaDoc<ModuleDependency> sortedDeps = new TreeSet JavaDoc(newDeps);
361         for (Iterator JavaDoc it = sortedDeps.iterator(); it.hasNext(); ) {
362             ModuleDependency md = (ModuleDependency) it.next();
363             createModuleDependencyElement(moduleDependencies, md, null);
364         }
365         project.putPrimaryConfigurationData(confData);
366         this.directDeps = sortedDeps;
367     }
368     
369     public void removeClassPathExtensions() {
370         Element JavaDoc confData = getConfData();
371         NodeList JavaDoc nl = confData.getElementsByTagNameNS(NbModuleProjectType.NAMESPACE_SHARED,
372                 ProjectXMLManager.CLASS_PATH_EXTENSION);
373         for (int i = 0; i < nl.getLength(); i++) {
374             confData.removeChild(nl.item(i));
375         }
376         project.putPrimaryConfigurationData(confData);
377     }
378     
379     /**
380      * Removes test dependency under type <code>testType</code>, indentified
381      * by <code>cnbToRemove</code>. Does not remove whole 610test type even if
382      * removed test dependency was the last one.
383      */

384     public boolean removeTestDependency(String JavaDoc testType, String JavaDoc cnbToRemove){
385         boolean wasRemoved = false;
386         Element JavaDoc confData = getConfData();
387         Element JavaDoc testModuleDependenciesEl = findTestDependenciesElement(confData);
388         List JavaDoc/*<Element>*/ testTypesList = Util.findSubElements(testModuleDependenciesEl);
389         Element JavaDoc testTypeRemoveEl = null;
390         for (Iterator JavaDoc it = testTypesList.iterator(); it.hasNext(); ) {
391             Element JavaDoc type = (Element JavaDoc)it.next();
392             Element JavaDoc nameEl = findElement(type, TEST_TYPE_NAME);
393             String JavaDoc nameOfType = Util.findText(nameEl);
394             if (testType.equals(nameOfType)) {
395                 testTypeRemoveEl = type;
396             }
397         }
398         //found such a test type
399
if (testTypeRemoveEl != null){
400             List JavaDoc/*<Element>*/ testDepList = Util.findSubElements(testTypeRemoveEl);
401             for (Iterator JavaDoc it = testDepList.iterator(); it.hasNext();) {
402                 Element JavaDoc el = (Element JavaDoc) it.next();
403                 Element JavaDoc cnbEl = findElement(el, TEST_DEPENDENCY_CNB);
404                 if(cnbEl == null) {
405                     continue; //name node, continue
406
}
407                 String JavaDoc cnb = Util.findText(cnbEl);
408                 if (cnbToRemove.equals(cnb)) {
409                     // found test dependency with desired CNB
410
testTypeRemoveEl.removeChild(el);
411                     wasRemoved = true;
412                     project.putPrimaryConfigurationData(confData);
413                 }
414             }
415         }
416         return wasRemoved;
417     }
418     
419     /**
420      * Adds new test dependency to <code>project.xml</code>. Currently only two test types are
421      * supported - <code>UNIT</code> and <code>QA_FUNCTIONAL</code>. Test dependencies under
422      * test types are sorted by CNB.
423      */

424     public void addTestDependency(String JavaDoc testType, TestModuleDependency newTestDep) throws IOException JavaDoc {
425         final String JavaDoc UNIT = TestModuleDependency.UNIT;
426         final String JavaDoc QA_FUNCTIONAL = TestModuleDependency.QA_FUNCTIONAL;
427         assert (UNIT.equals(testType) || QA_FUNCTIONAL.equals(testType)) : "Current impl.supports only " + QA_FUNCTIONAL +
428                 " or " + UNIT + " tests"; // NOI18N
429
File JavaDoc projectDir = FileUtil.toFile(project.getProjectDirectory());
430         ModuleList ml = ModuleList.getModuleList(projectDir);
431         Map JavaDoc map = new HashMap JavaDoc(getTestDependencies(ml));
432         Set JavaDoc testDependenciesSet = (Set JavaDoc) map.get(testType);
433         if(testDependenciesSet == null) {
434             testDependenciesSet = new TreeSet JavaDoc();
435             map.put(testType, testDependenciesSet);
436         } else {
437             testDependenciesSet = new TreeSet JavaDoc();
438             testDependenciesSet.addAll((Set JavaDoc) map.get(testType));
439         }
440         if (!testDependenciesSet.add(newTestDep)) {
441             return; //nothing new to add, dep is already there, finished
442
}
443         Element JavaDoc confData = getConfData();
444         Document JavaDoc doc = confData.getOwnerDocument();
445         Element JavaDoc testModuleDependenciesEl = findTestDependenciesElement(confData);
446         if (testModuleDependenciesEl == null) { // test dependencies element does not exist, create it
447
Element JavaDoc before = findPublicPackagesElement(confData);
448             if (before == null) {
449                 before = findFriendsElement(confData);
450             }
451             assert before != null : "There must be " + PUBLIC_PACKAGES + " or " // NOI18N
452
+ FRIEND_PACKAGES + " element according to XSD"; // NOI18N
453
testModuleDependenciesEl= createModuleElement(doc, TEST_DEPENDENCIES);
454             confData.insertBefore(testModuleDependenciesEl, before);
455         }
456         Element JavaDoc testTypeEl = null;
457         List JavaDoc listOfTestTypes = Util.findSubElements(testModuleDependenciesEl);
458         //iterate through test types to determine if testType exist
459
for (Iterator JavaDoc it = listOfTestTypes.iterator(); it.hasNext();) {
460             Element JavaDoc tt = (Element JavaDoc) it.next();
461             Node JavaDoc nameNode = findElement(tt, "name");
462             assert nameNode!=null : "should be some child with name";
463             //Node nameNode = tt.getFirstChild();
464
//nameNode.getNodeName()
465
assert (TEST_TYPE_NAME.equals(nameNode.getLocalName())) : "name node should be first child, but was:"+nameNode.getLocalName() +
466                     "or" + nameNode.getNodeName(); //NOI18N
467
//equals
468
if(nameNode.getTextContent().equals(testType)) {
469                 testTypeEl = tt;
470             }
471         }
472         //? new or existing test type?
473
if (testTypeEl == null){
474             //this test type, does not exist, create it, and add new test dependency
475
Element JavaDoc newTestTypeEl = createNewTestTypeElement(doc, testType);
476             testModuleDependenciesEl.appendChild(newTestTypeEl);
477             createTestModuleDependencyElement(newTestTypeEl, newTestDep);
478             project.putPrimaryConfigurationData(confData);
479             return;
480         } else {
481             //testtype exists, refresh it
482
Node JavaDoc beforeWhat = testTypeEl.getNextSibling();
483             testModuleDependenciesEl.removeChild(testTypeEl);
484             Element JavaDoc refreshedTestTypeEl = createNewTestTypeElement(doc, testType);
485             if(beforeWhat == null) {
486                 testModuleDependenciesEl.appendChild(refreshedTestTypeEl);
487             } else {
488                 testModuleDependenciesEl.insertBefore(refreshedTestTypeEl, beforeWhat);
489             }
490             for (Iterator JavaDoc it = testDependenciesSet.iterator(); it.hasNext(); ) {
491                 TestModuleDependency tmd = (TestModuleDependency) it.next();
492                 createTestModuleDependencyElement(refreshedTestTypeEl, tmd);
493                 project.putPrimaryConfigurationData(confData);
494             }
495         }
496     }
497     
498     private Element JavaDoc createNewTestTypeElement(Document JavaDoc doc, String JavaDoc testTypeName){
499         Element JavaDoc newTestTypeEl = createModuleElement(doc, TEST_TYPE);
500         Element JavaDoc nameOfTestTypeEl = createModuleElement(doc, TEST_TYPE_NAME, testTypeName);
501         newTestTypeEl.appendChild(nameOfTestTypeEl);
502         return newTestTypeEl;
503     }
504     
505     
506     private void createTestModuleDependencyElement(Element JavaDoc testTypeElement, TestModuleDependency tmd) {
507         Document JavaDoc doc = testTypeElement.getOwnerDocument();
508         Element JavaDoc tde = createModuleElement(doc, TEST_DEPENDENCY);
509         testTypeElement.appendChild(tde);
510         tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_CNB, tmd.getModule().getCodeNameBase()));
511         if(tmd.isRecursive()) {
512             tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_RECURSIVE));
513         }
514         if(tmd.isCompile()) {
515             tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_COMPILE));
516         }
517         if(tmd.isTest()) {
518             tde.appendChild(createModuleElement(doc, TEST_DEPENDENCY_TEST));
519         }
520     }
521     
522     
523     /**
524      * Gives a map from test type (e.g. <em>unit</em> or <em>qa-functional</em>)
525      * to the set of {@link TestModuleDependency dependencies} belonging to it.
526      */

527     public Map JavaDoc<String JavaDoc,Set JavaDoc<TestModuleDependency>> getTestDependencies(final ModuleList ml) {
528         Element JavaDoc testDepsEl = findTestDependenciesElement(getConfData());
529         
530         Map JavaDoc<String JavaDoc,Set JavaDoc<TestModuleDependency>> testDeps = new HashMap JavaDoc();
531         
532         if (testDepsEl != null) {
533             for (Iterator JavaDoc typesIt = Util.findSubElements(testDepsEl).iterator(); typesIt.hasNext();) {
534                 Element JavaDoc typeEl = (Element JavaDoc) typesIt.next();
535                 Element JavaDoc testTypeEl = findElement(typeEl, TEST_TYPE_NAME);
536                 String JavaDoc testType = null;
537                 if (testTypeEl != null) {
538                     testType = Util.findText(testTypeEl);
539                 }
540                 if (testType == null) {
541                     testType = TestModuleDependency.UNIT; // default variant
542
}
543                 Set JavaDoc<TestModuleDependency> directTestDeps = new HashSet JavaDoc();
544                 for (Iterator JavaDoc depsIt = Util.findSubElements(typeEl).iterator() ; depsIt.hasNext();) {
545                     Element JavaDoc depEl = (Element JavaDoc) depsIt.next();
546                     if (depEl.getTagName().equals(TEST_DEPENDENCY)) {
547                         // parse test dep
548
Element JavaDoc cnbEl = findElement(depEl, TEST_DEPENDENCY_CNB);
549                         boolean test = findElement(depEl, TEST_DEPENDENCY_TEST) != null;
550                         String JavaDoc cnb = null;
551                         if (cnbEl != null) {
552                             cnb = Util.findText(cnbEl);
553                         }
554                         boolean recursive = findElement(depEl, TEST_DEPENDENCY_RECURSIVE) != null;
555                         boolean compile = findElement(depEl, TEST_DEPENDENCY_COMPILE) != null;
556                         if (cnb != null) {
557                             ModuleEntry me = ml.getEntry(cnb);
558                             if (me != null) {
559                                 directTestDeps.add(new TestModuleDependency(me, test, recursive, compile));
560                             }
561                         }
562                     }
563                 }
564                 testDeps.put(testType, directTestDeps);
565             }
566         }
567         return testDeps;
568     }
569     
570     /**
571      * Replace existing classpath extensions with new values.
572      * @param newValues &lt;key=runtime-path(String), value=binary-path(String)&gt;
573      */

574     public void replaceClassPathExtensions(final Map JavaDoc newValues) {
575         removeClassPathExtensions();
576         if (newValues != null && newValues.size() > 0) {
577             Element JavaDoc confData = getConfData();
578             Document JavaDoc doc = confData.getOwnerDocument();
579             Iterator JavaDoc it = newValues.entrySet().iterator();
580             while (it.hasNext()) {
581                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
582                 Element JavaDoc cpel = createModuleElement(doc, ProjectXMLManager.CLASS_PATH_EXTENSION);
583                 Element JavaDoc runtime = createModuleElement(doc, ProjectXMLManager.CLASS_PATH_RUNTIME_PATH,
584                         (String JavaDoc)entry.getKey());
585                 Element JavaDoc binary = createModuleElement(doc, ProjectXMLManager.CLASS_PATH_BINARY_ORIGIN,
586                         (String JavaDoc)entry.getValue());
587                 cpel.appendChild(runtime);
588                 cpel.appendChild(binary);
589                 confData.appendChild(cpel);
590                 
591             }
592             project.putPrimaryConfigurationData(confData);
593         }
594     }
595     
596     /**
597      * Replaces all original public packages with the given
598      * <code>newPackages</code>. Also removes friend packages if there are any
599      * since those two mutually exclusive.
600      */

601     public void replacePublicPackages(String JavaDoc[] newPackages) {
602         removePublicAndFriends();
603         Element JavaDoc confData = getConfData();
604         Document JavaDoc doc = confData.getOwnerDocument();
605         Element JavaDoc publicPackagesEl = createModuleElement(doc, ProjectXMLManager.PUBLIC_PACKAGES);
606         
607         insertPublicOrFriend(publicPackagesEl);
608         
609         for (int i = 0; i < newPackages.length; i++) {
610             publicPackagesEl.appendChild(
611                     createModuleElement(doc, ProjectXMLManager.PACKAGE, newPackages[i]));
612         }
613         project.putPrimaryConfigurationData(confData);
614         publicPackages = null; // XXX cleaner would be to listen on changes in helper
615
}
616     
617     /** Position public-packages or friend-packages according to XSD. */
618     private void insertPublicOrFriend(Element JavaDoc packagesEl) {
619         Element JavaDoc beforeEl = findElement(getConfData(), ProjectXMLManager.CLASS_PATH_EXTENSION);
620         if (beforeEl == null) {
621             beforeEl = findElement(getConfData(), ProjectXMLManager.EXTRA_COMPILATION_UNIT);
622         }
623         getConfData().insertBefore(packagesEl, beforeEl);
624     }
625     
626     /**
627      * Replaces all original friends with the given <code>friends</code> with
628      * <code>packagesToExpose</code> as exposed packages to those friends. Also
629      * removes public packages if there are any since those two are mutually
630      * exclusive.
631      */

632     public void replaceFriends(String JavaDoc[] friends, String JavaDoc[] packagesToExpose) {
633         removePublicAndFriends();
634         Element JavaDoc confData = getConfData();
635         Document JavaDoc doc = confData.getOwnerDocument();
636         Element JavaDoc friendPackages = createModuleElement(doc, ProjectXMLManager.FRIEND_PACKAGES);
637         insertPublicOrFriend(friendPackages);
638         for (int i = 0; i < friends.length; i++) {
639             friendPackages.appendChild(
640                     createModuleElement(doc, ProjectXMLManager.FRIEND, friends[i]));
641         }
642         for (int i = 0; i < packagesToExpose.length; i++) {
643             friendPackages.appendChild(
644                     createModuleElement(doc, ProjectXMLManager.PACKAGE, packagesToExpose[i]));
645         }
646         project.putPrimaryConfigurationData(confData);
647         publicPackages = null;
648     }
649     
650     /**
651      * Returns an array of {@link ManifestManager.PackageExport}s of all
652      * exposed public packages. Method considers both <em>package</em> and
653      * <em>subpackages</em> elements with the recursivity flag set
654      * appropriately for returned entries.
655      *
656      * @return array of {@link ManifestManager.PackageExport}. May be empty but
657      * not <code>null</code>.
658      */

659     public ManifestManager.PackageExport[] getPublicPackages() {
660         if (publicPackages == null) {
661             publicPackages = ProjectXMLManager.findPublicPackages(getConfData());
662         }
663         return publicPackages;
664     }
665     
666     /** Returns all friends or <code>null</code> if there are none. */
667     public String JavaDoc[] getFriends() {
668         if (friends == null) {
669             friends = ProjectXMLManager.findFriends(getConfData());
670         }
671         return friends;
672     }
673     
674     
675     /**
676      * Returns paths of all libraries bundled within a project this
677      * <em>manager</em> manage. So the result should be an array of
678      * <code>String</code>s each representing a relative path to the project's
679      * external library (jar/zip).
680      * @return an array of strings (may be empty)
681      */

682     public String JavaDoc[] getBinaryOrigins() {
683         if (cpExtensions != null) {
684             return cpExtensions;
685         }
686         
687         List JavaDoc<Element JavaDoc> cpExtEls = Util.findSubElements(getConfData());
688         Set JavaDoc<String JavaDoc> binaryOrigs = new TreeSet JavaDoc();
689         for (Iterator JavaDoc it = cpExtEls.iterator(); it.hasNext(); ) {
690             Element JavaDoc cpExtEl = (Element JavaDoc) it.next();
691             if (CLASS_PATH_EXTENSION.equals(cpExtEl.getTagName())) {
692                 Element JavaDoc binOrigEl = findElement(cpExtEl, BINARY_ORIGIN);
693                 if (binOrigEl != null) {
694                     binaryOrigs.add(Util.findText(binOrigEl));
695                 }
696             }
697         }
698         return cpExtensions = (String JavaDoc[]) binaryOrigs.toArray(new String JavaDoc[binaryOrigs.size()]);
699     }
700     
701     /** Returns code-name-base. */
702     public String JavaDoc getCodeNameBase() {
703         if (cnb == null) {
704             Element JavaDoc cnbEl = findElement(getConfData(), ProjectXMLManager.CODE_NAME_BASE);
705             cnb = Util.findText(cnbEl);
706         }
707         return cnb;
708     }
709     
710     /** Package-private for unit tests only. */
711     static void createModuleDependencyElement(
712             Element JavaDoc moduleDependencies, ModuleDependency md, Element JavaDoc nextSibling) {
713         
714         Document JavaDoc doc = moduleDependencies.getOwnerDocument();
715         Element JavaDoc modDepEl = createModuleElement(doc, ProjectXMLManager.DEPENDENCY);
716         moduleDependencies.insertBefore(modDepEl, nextSibling);
717         
718         modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.CODE_NAME_BASE,
719                 md.getModuleEntry().getCodeNameBase()));
720         if (md.hasCompileDependency()) {
721             modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.BUILD_PREREQUISITE));
722             modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.COMPILE_DEPENDENCY));
723         }
724         
725         Element JavaDoc runDepEl = createModuleElement(doc, ProjectXMLManager.RUN_DEPENDENCY);
726         modDepEl.appendChild(runDepEl);
727         
728         String JavaDoc rv = md.getReleaseVersion();
729         if (rv != null && !rv.trim().equals("")) {
730             runDepEl.appendChild(createModuleElement(
731                     doc, ProjectXMLManager.RELEASE_VERSION, rv));
732         }
733         if (md.hasImplementationDepedendency()) {
734             runDepEl.appendChild(createModuleElement(
735                     doc, ProjectXMLManager.IMPLEMENTATION_VERSION));
736         } else {
737             String JavaDoc sv = md.getSpecificationVersion();
738             if (sv != null && !"".equals(sv)) { // NOI18N
739
runDepEl.appendChild(createModuleElement(
740                         doc, ProjectXMLManager.SPECIFICATION_VERSION, sv));
741             }
742         }
743     }
744     
745     /** Removes public-packages and friend-packages elements. */
746     private void removePublicAndFriends() {
747         Element JavaDoc friendPackages = findFriendsElement(getConfData());
748         if (friendPackages != null) {
749             getConfData().removeChild(friendPackages);
750         }
751         Element JavaDoc publicPackages = findPublicPackagesElement(getConfData());
752         if (publicPackages != null) {
753             getConfData().removeChild(publicPackages);
754         }
755     }
756     
757     private static Element JavaDoc findElement(Element JavaDoc parentEl, String JavaDoc elementName) {
758         return Util.findElement(parentEl, elementName, NbModuleProjectType.NAMESPACE_SHARED);
759     }
760     
761     /** Package-private for unit tests only. */
762     static Element JavaDoc findModuleDependencies(Element JavaDoc parentEl) {
763         return findElement(parentEl, ProjectXMLManager.MODULE_DEPENDENCIES);
764     }
765     
766     private static Element JavaDoc findTestDependenciesElement(Element JavaDoc parentEl) {
767         return findElement(parentEl, ProjectXMLManager.TEST_DEPENDENCIES);
768     }
769     
770     private static Element JavaDoc findPublicPackagesElement(Element JavaDoc parentEl) {
771         return findElement(parentEl, ProjectXMLManager.PUBLIC_PACKAGES);
772     }
773     
774     private static Element JavaDoc findFriendsElement(Element JavaDoc parentEl) {
775         return findElement(parentEl, ProjectXMLManager.FRIEND_PACKAGES);
776     }
777     
778     private static Element JavaDoc createModuleElement(Document JavaDoc doc, String JavaDoc name) {
779         return doc.createElementNS(NbModuleProjectType.NAMESPACE_SHARED, name);
780     }
781     
782     private static Element JavaDoc createModuleElement(Document JavaDoc doc, String JavaDoc name, String JavaDoc innerText) {
783         Element JavaDoc el = createModuleElement(doc, name);
784         el.appendChild(doc.createTextNode(innerText));
785         return el;
786     }
787     
788     private static Element JavaDoc createSuiteElement(Document JavaDoc doc, String JavaDoc name) {
789         return doc.createElementNS(SuiteProjectType.NAMESPACE_SHARED, name);
790     }
791     
792     private static Element JavaDoc createSuiteElement(Document JavaDoc doc, String JavaDoc name, String JavaDoc innerText) {
793         Element JavaDoc el = createSuiteElement(doc, name);
794         el.appendChild(doc.createTextNode(innerText));
795         return el;
796     }
797     
798     /**
799      * Find packages in public-packages or friend-packages section. Method
800      * considers both <em>package</em> and <em>subpackages</em> elements with
801      * the recursivity flag set appropriately for returned entries.
802      */

803     private static Set JavaDoc<ManifestManager.PackageExport> findAllPackages(Element JavaDoc parent) {
804         Set JavaDoc<ManifestManager.PackageExport> packages = new HashSet JavaDoc();
805         List JavaDoc<Element JavaDoc> pkgEls = Util.findSubElements(parent);
806         for (Iterator JavaDoc it = pkgEls.iterator(); it.hasNext(); ) {
807             Element JavaDoc pkgEl = (Element JavaDoc) it.next();
808             if (PACKAGE.equals(pkgEl.getTagName())) {
809                 packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), false));
810             } else if (SUBPACKAGES.equals(pkgEl.getTagName())) {
811                 packages.add(new ManifestManager.PackageExport(Util.findText(pkgEl), true));
812             }
813         }
814         return packages;
815     }
816     
817     /**
818      * Utility method for finding public packages. Method considers both
819      * <em>package</em> and <em>subpackages</em> elements with the recursivity
820      * flag set appropriately for returned entries.
821      *
822      * @return array of {@link ManifestManager.PackageExport}. May be empty but
823      * not <code>null</code>.
824      */

825     public static ManifestManager.PackageExport[] findPublicPackages(final Element JavaDoc confData) {
826         Element JavaDoc ppEl = findPublicPackagesElement(confData);
827         Set JavaDoc<ManifestManager.PackageExport> pps = new HashSet JavaDoc();
828         if (ppEl != null) {
829             pps.addAll(findAllPackages(ppEl));
830         }
831         ppEl = findFriendsElement(confData);
832         if (ppEl != null) {
833             pps.addAll(findAllPackages(ppEl));
834         }
835         return pps.isEmpty() ? ManifestManager.EMPTY_EXPORTED_PACKAGES :
836             (ManifestManager.PackageExport[]) pps.toArray(new ManifestManager.PackageExport[pps.size()]);
837     }
838     
839     /** Utility method for finding friend. */
840     public static String JavaDoc[] findFriends(final Element JavaDoc confData) {
841         Element JavaDoc friendsEl = findFriendsElement(confData);
842         if (friendsEl != null) {
843             List JavaDoc<Element JavaDoc> friendEls = Util.findSubElements(friendsEl);
844             Set JavaDoc<String JavaDoc> friends = new TreeSet JavaDoc();
845             for (Iterator JavaDoc it = friendEls.iterator(); it.hasNext(); ) {
846                 Element JavaDoc friendEl = (Element JavaDoc) it.next();
847                 if (FRIEND.equals(friendEl.getTagName())) {
848                     friends.add(Util.findText(friendEl));
849                 }
850             }
851             String JavaDoc[] result = new String JavaDoc[friends.size()];
852             return (String JavaDoc[]) friends.toArray(result);
853         }
854         return null;
855     }
856     
857     /**
858      * Generates a basic <em>project.xml</em> templates into the given
859      * <code>projectXml</code> for <em>standalone</em> or <em>module in
860      * suite</em> module.
861      */

862     static void generateEmptyModuleTemplate(FileObject projectXml, String JavaDoc cnb,
863             NbModuleType moduleType) throws IOException JavaDoc {
864         
865         Document JavaDoc prjDoc = XMLUtil.createDocument("project", PROJECT_NS, null, null); // NOI18N
866

867         // generate general project elements
868
Element JavaDoc typeEl = prjDoc.createElementNS(PROJECT_NS, "type"); // NOI18N
869
typeEl.appendChild(prjDoc.createTextNode(NbModuleProjectType.TYPE));
870         prjDoc.getDocumentElement().appendChild(typeEl);
871         Element JavaDoc confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
872
prjDoc.getDocumentElement().appendChild(confEl);
873         
874         // generate NB Module project type specific elements
875
Element JavaDoc dataEl = createModuleElement(confEl.getOwnerDocument(), DATA);
876         confEl.appendChild(dataEl);
877         Document JavaDoc dataDoc = dataEl.getOwnerDocument();
878         dataEl.appendChild(createModuleElement(dataDoc, CODE_NAME_BASE, cnb));
879         Element JavaDoc moduleTypeEl = createTypeElement(dataDoc, moduleType);
880         if (moduleTypeEl != null) {
881             dataEl.appendChild(moduleTypeEl);
882         }
883         dataEl.appendChild(createModuleElement(dataDoc, MODULE_DEPENDENCIES));
884         dataEl.appendChild(createModuleElement(dataDoc, PUBLIC_PACKAGES));
885         
886         // store document to disk
887
ProjectXMLManager.safelyWrite(projectXml, prjDoc);
888     }
889     
890     /**
891      * Create a library wrapper project.xml.
892      *
893      * @param publicPackages set of <code>String</code>s representing the packages
894      * @param extensions &lt;key=runtime path(String), value=binary path (String)&gt;
895      */

896     static void generateLibraryModuleTemplate(FileObject projectXml, String JavaDoc cnb,
897             NbModuleType moduleType, Set JavaDoc publicPackages, Map JavaDoc extensions) throws IOException JavaDoc {
898         
899         Document JavaDoc prjDoc = XMLUtil.createDocument("project", PROJECT_NS, null, null); // NOI18N
900

901         // generate general project elements
902
Element JavaDoc typeEl = prjDoc.createElementNS(PROJECT_NS, "type"); // NOI18N
903
typeEl.appendChild(prjDoc.createTextNode(NbModuleProjectType.TYPE));
904         prjDoc.getDocumentElement().appendChild(typeEl);
905         Element JavaDoc confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
906
prjDoc.getDocumentElement().appendChild(confEl);
907         
908         // generate NB Module project type specific elements
909
Element JavaDoc dataEl = createModuleElement(confEl.getOwnerDocument(), DATA);
910         confEl.appendChild(dataEl);
911         Document JavaDoc dataDoc = dataEl.getOwnerDocument();
912         dataEl.appendChild(createModuleElement(dataDoc, CODE_NAME_BASE, cnb));
913         Element JavaDoc moduleTypeEl = createTypeElement(dataDoc, moduleType);
914         if (moduleTypeEl != null) {
915             dataEl.appendChild(moduleTypeEl);
916         }
917         dataEl.appendChild(createModuleElement(dataDoc, MODULE_DEPENDENCIES));
918         Element JavaDoc packages = createModuleElement(dataDoc, PUBLIC_PACKAGES);
919         dataEl.appendChild(packages);
920         Iterator JavaDoc it = publicPackages.iterator();
921         while (it.hasNext()) {
922             packages.appendChild(createModuleElement(dataDoc, PACKAGE, (String JavaDoc)it.next()));
923         }
924         it = extensions.entrySet().iterator();
925         while (it.hasNext()) {
926             Element JavaDoc cp = createModuleElement(dataDoc, CLASS_PATH_EXTENSION);
927             dataEl.appendChild(cp);
928             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)it.next();
929             cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_RUNTIME_PATH, (String JavaDoc)entry.getKey()));
930             cp.appendChild(createModuleElement(dataDoc, CLASS_PATH_BINARY_ORIGIN, (String JavaDoc)entry.getValue()));
931         }
932         
933         // store document to disk
934
ProjectXMLManager.safelyWrite(projectXml, prjDoc);
935     }
936     
937     private static Element JavaDoc createTypeElement(Document JavaDoc dataDoc, NbModuleType type) {
938         Element JavaDoc result = null;
939         if (type == NbModuleProvider.STANDALONE) {
940             result = createModuleElement(dataDoc, STANDALONE);
941         } else if (type == NbModuleProvider.SUITE_COMPONENT) {
942             result = createModuleElement(dataDoc, SUITE_COMPONENT);
943         }
944         return result;
945     }
946     
947     /**
948      * Generates a basic <em>project.xml</em> templates into the given
949      * <code>projectXml</code> for <em>Suite</em>.
950      */

951     public static void generateEmptySuiteTemplate(FileObject projectXml, String JavaDoc name) throws IOException JavaDoc {
952         // XXX this method could be moved in a future (depends on how complex
953
// suite's project.xml will be) to the .suite package dedicated class
954
Document JavaDoc prjDoc = XMLUtil.createDocument("project", PROJECT_NS, null, null); // NOI18N
955

956         // generate general project elements
957
Element JavaDoc typeEl = prjDoc.createElementNS(PROJECT_NS, "type"); // NOI18N
958
typeEl.appendChild(prjDoc.createTextNode(SuiteProjectType.TYPE));
959         prjDoc.getDocumentElement().appendChild(typeEl);
960         Element JavaDoc confEl = prjDoc.createElementNS(PROJECT_NS, "configuration"); // NOI18N
961
prjDoc.getDocumentElement().appendChild(confEl);
962         
963         // generate NB Suite project type specific elements
964
Element JavaDoc dataEl = createSuiteElement(confEl.getOwnerDocument(), DATA);
965         confEl.appendChild(dataEl);
966         Document JavaDoc dataDoc = dataEl.getOwnerDocument();
967         dataEl.appendChild(createSuiteElement(dataDoc, "name", name)); // NOI18N
968

969         // store document to disk
970
ProjectXMLManager.safelyWrite(projectXml, prjDoc);
971     }
972     
973     private static void safelyWrite(FileObject projectXml, Document JavaDoc prjDoc) throws IOException JavaDoc {
974         FileLock lock = projectXml.lock();
975         try {
976             OutputStream JavaDoc os = projectXml.getOutputStream(lock);
977             try {
978                 XMLUtil.write(prjDoc, os, "UTF-8"); // NOI18N
979
} finally {
980                 os.close();
981             }
982         } finally {
983             lock.releaseLock();
984         }
985     }
986     
987     private Element JavaDoc getConfData() {
988         if (confData == null) {
989             confData = project.getPrimaryConfigurationData();
990         }
991         return confData;
992     }
993     
994 }
995
Popular Tags