KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > FreeformProjectGenerator


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.ant.freeform;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.api.project.ProjectManager;
30 import org.netbeans.api.queries.CollocationQuery;
31 import org.netbeans.modules.ant.freeform.spi.ProjectConstants;
32 import org.netbeans.modules.ant.freeform.spi.support.Util;
33 import org.netbeans.spi.project.AuxiliaryConfiguration;
34 import org.netbeans.spi.project.support.ant.AntProjectHelper;
35 import org.netbeans.spi.project.support.ant.EditableProperties;
36 import org.netbeans.spi.project.support.ant.ProjectGenerator;
37 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
38 import org.netbeans.spi.project.support.ant.PropertyUtils;
39 import org.openide.filesystems.FileObject;
40 import org.openide.filesystems.FileStateInvalidException;
41 import org.openide.filesystems.FileUtil;
42 import org.openide.util.NbBundle;
43 import org.w3c.dom.Document JavaDoc;
44 import org.w3c.dom.Element JavaDoc;
45 import org.w3c.dom.Node JavaDoc;
46
47 /**
48  * Reads/writes project.xml.
49  *
50  * @author Jesse Glick, David Konecny, Pavel Buzek
51  */

52 public class FreeformProjectGenerator {
53
54     /** Keep root elements in the order specified by project's XML schema. */
55     private static final String JavaDoc[] rootElementsOrder = new String JavaDoc[]{"name", "properties", "folders", "ide-actions", "export", "view", "subprojects"}; // NOI18N
56
private static final String JavaDoc[] viewElementsOrder = new String JavaDoc[]{"items", "context-menu"}; // NOI18N
57

58     // this order is not required by schema, but follow it to minimize randomness a bit
59
//private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder"}; // NOI18N
60
private static final String JavaDoc[] viewItemElementsOrder = new String JavaDoc[]{"source-folder", "source-file"}; // NOI18N
61
private static final String JavaDoc[] contextMenuElementsOrder = new String JavaDoc[]{"ide-action", "separator", "action"}; // NOI18N
62

63     private FreeformProjectGenerator() {}
64
65     public static AntProjectHelper createProject(File JavaDoc location, File JavaDoc dir, String JavaDoc name, File JavaDoc antScript) throws IOException JavaDoc {
66         FileObject dirFO = createProjectDir(dir);
67         FileObject locationFO = FileUtil.toFileObject(location);
68         AntProjectHelper h = createProject(locationFO, dirFO, name, antScript);
69         Project p = ProjectManager.getDefault().findProject(dirFO);
70         ProjectManager.getDefault().saveProject(p);
71         return h;
72     }
73     
74     private static AntProjectHelper createProject(final FileObject locationFO, final FileObject dirFO, final String JavaDoc name, final File JavaDoc antScript) throws IOException JavaDoc {
75         final AntProjectHelper[] h = new AntProjectHelper[1];
76         final IOException JavaDoc[] ioe = new IOException JavaDoc[1];
77         ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
78                 public void run() {
79                     Project p;
80                     try {
81                         h[0] = ProjectGenerator.createProject(dirFO, FreeformProjectType.TYPE);
82                         p = ProjectManager.getDefault().findProject(dirFO);
83                     } catch (IOException JavaDoc e) {
84                         ioe[0] = e;
85                         return;
86                     }
87                     AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
88                     assert aux != null;
89
90                     Element JavaDoc data = Util.getPrimaryConfigurationData(h[0]);
91                     Document JavaDoc doc = data.getOwnerDocument();
92
93                     Node JavaDoc comment = doc.createComment(" " + NbBundle.getMessage(FreeformProjectGenerator.class, "LBL_Manual_Editing_Warning") + " ");
94                     data.appendChild(comment);
95                     
96                     Element JavaDoc nm = doc.createElementNS(FreeformProjectType.NS_GENERAL, "name"); // NOI18N
97
nm.appendChild(doc.createTextNode(name)); // NOI18N
98
data.appendChild(nm);
99                     Element JavaDoc props = doc.createElementNS(FreeformProjectType.NS_GENERAL, "properties"); // NOI18N
100
File JavaDoc locationF = FileUtil.toFile(locationFO);
101                     File JavaDoc dirF = FileUtil.toFile(dirFO);
102                     Map JavaDoc<String JavaDoc,String JavaDoc> properties = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
103                     if (!locationFO.equals(dirFO)) {
104                         Element JavaDoc property = doc.createElementNS(FreeformProjectType.NS_GENERAL, "property"); // NOI18N
105
property.setAttribute("name", ProjectConstants.PROP_PROJECT_LOCATION); // NOI18N
106
String JavaDoc path;
107                         if (CollocationQuery.areCollocated(dirF, locationF)) {
108                             path = PropertyUtils.relativizeFile(dirF, locationF); // NOI18N
109
} else {
110                             path = locationF.getAbsolutePath();
111                         }
112                         property.appendChild(doc.createTextNode(path));
113                         props.appendChild(property);
114                         properties.put(ProjectConstants.PROP_PROJECT_LOCATION, path);
115                     }
116                     String JavaDoc antPath = "build.xml"; // NOI18N
117
if (antScript != null) {
118                         Element JavaDoc property = doc.createElementNS(FreeformProjectType.NS_GENERAL, "property"); // NOI18N
119
property.setAttribute("name", ProjectConstants.PROP_ANT_SCRIPT); // NOI18N
120
antPath = Util.relativizeLocation(locationF, dirF, antScript);
121                         property.appendChild(doc.createTextNode(antPath));
122                         properties.put(ProjectConstants.PROP_ANT_SCRIPT, antPath);
123                         antPath = "${"+ProjectConstants.PROP_ANT_SCRIPT+"}"; // NOI18N
124
props.appendChild(property);
125                     }
126                     //#56344:Always write a <properties> element to project.xml of a generated freeform
127
// if (props.getChildNodes().getLength() > 0) {
128
data.appendChild(props);
129 // }
130
Util.putPrimaryConfigurationData(h[0], data);
131                     putBuildXMLSourceFile(h[0], antPath);
132                 }
133             }
134         );
135
136         if (ioe[0] != null) {
137             throw ioe[0];
138         }
139         return h[0];
140     }
141
142     private static FileObject createProjectDir(File JavaDoc dir) throws IOException JavaDoc {
143         FileObject dirFO;
144         if(!dir.exists()) {
145             //Refresh before mkdir not to depend on window focus
146
refreshFileSystem (dir);
147             dir.mkdirs();
148             refreshFileSystem (dir);
149         }
150         dirFO = FileUtil.toFileObject(dir);
151         assert dirFO != null : "No such dir on disk: " + dir; // NOI18N
152
assert dirFO.isFolder() : "Not really a dir: " + dir; // NOI18N
153
return dirFO;
154     }
155
156
157     private static void refreshFileSystem (final File JavaDoc dir) throws FileStateInvalidException {
158         File JavaDoc rootF = dir;
159         while (rootF.getParentFile() != null) {
160             rootF = rootF.getParentFile();
161         }
162         FileObject dirFO = FileUtil.toFileObject(rootF);
163         assert dirFO != null : "At least disk roots must be mounted! " + rootF; // NOI18N
164
dirFO.getFileSystem().refresh(false);
165     }
166
167     /**
168      * Read target mappings from project.
169      * @param helper AntProjectHelper instance
170      * @return list of TargetMapping instances
171      */

172     public static List JavaDoc<TargetMapping> getTargetMappings(AntProjectHelper helper) {
173         //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
174
List JavaDoc<TargetMapping> list = new ArrayList JavaDoc<TargetMapping>();
175         Element JavaDoc genldata = Util.getPrimaryConfigurationData(helper);
176         Element JavaDoc actionsEl = Util.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
177
if (actionsEl == null) {
178             return list;
179         }
180         for (Element JavaDoc actionEl : Util.findSubElements(actionsEl)) {
181             TargetMapping tm = new TargetMapping();
182             tm.name = actionEl.getAttribute("name"); // NOI18N
183
List JavaDoc<String JavaDoc> targetNames = new ArrayList JavaDoc<String JavaDoc>();
184             EditableProperties props = new EditableProperties(false);
185             for (Element JavaDoc subEl : Util.findSubElements(actionEl)) {
186                 if (subEl.getLocalName().equals("target")) { // NOI18N
187
targetNames.add(Util.findText(subEl));
188                     continue;
189                 }
190                 if (subEl.getLocalName().equals("script")) { // NOI18N
191
tm.script = Util.findText(subEl);
192                     continue;
193                 }
194                 if (subEl.getLocalName().equals("context")) { // NOI18N
195
TargetMapping.Context ctx = new TargetMapping.Context();
196                     for (Element JavaDoc contextSubEl : Util.findSubElements(subEl)) {
197                         if (contextSubEl.getLocalName().equals("property")) { // NOI18N
198
ctx.property = Util.findText(contextSubEl);
199                             continue;
200                         }
201                         if (contextSubEl.getLocalName().equals("format")) { // NOI18N
202
ctx.format = Util.findText(contextSubEl);
203                             continue;
204                         }
205                         if (contextSubEl.getLocalName().equals("folder")) { // NOI18N
206
ctx.folder = Util.findText(contextSubEl);
207                             continue;
208                         }
209                         if (contextSubEl.getLocalName().equals("pattern")) { // NOI18N
210
ctx.pattern = Util.findText(contextSubEl);
211                             continue;
212                         }
213                         if (contextSubEl.getLocalName().equals("arity")) { // NOI18N
214
Element JavaDoc sepFilesEl = Util.findElement(contextSubEl, "separated-files", FreeformProjectType.NS_GENERAL); // NOI18N
215
if (sepFilesEl != null) {
216                                 ctx.separator = Util.findText(sepFilesEl);
217                             }
218                             continue;
219                         }
220                     }
221                     tm.context = ctx;
222                 }
223                 if (subEl.getLocalName().equals("property")) { // NOI18N
224
readProperty(subEl, props);
225                     continue;
226                 }
227             }
228             tm.targets = targetNames;
229             if (props.keySet().size() > 0) {
230                 tm.properties = props;
231             }
232             list.add(tm);
233         }
234         return list;
235     }
236     
237     private static void readProperty(Element JavaDoc propertyElement, EditableProperties props) {
238         String JavaDoc key = propertyElement.getAttribute("name"); // NOI18N
239
String JavaDoc value = Util.findText(propertyElement);
240         props.setProperty(key, value);
241     }
242
243     /**
244      * Update target mappings of the project. Project is left modified and
245      * you must save it explicitely.
246      * @param helper AntProjectHelper instance
247      * @param mappings list of <TargetMapping> instances to store
248      */

249     public static void putTargetMappings(AntProjectHelper helper, List JavaDoc<TargetMapping> mappings) {
250         //assert ProjectManager.mutex().isWriteAccess();
251
Element JavaDoc data = Util.getPrimaryConfigurationData(helper);
252         Document JavaDoc doc = data.getOwnerDocument();
253         Element JavaDoc actions = Util.findElement(data, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
254
if (actions != null) {
255             data.removeChild(actions);
256         }
257         
258         actions = doc.createElementNS(FreeformProjectType.NS_GENERAL, "ide-actions"); // NOI18N
259
for (TargetMapping tm : mappings) {
260             Element JavaDoc action = doc.createElementNS(FreeformProjectType.NS_GENERAL, "action"); //NOI18N
261
assert tm.name != null && tm.name.length() > 0;
262             action.setAttribute("name", tm.name); // NOI18N
263
if (tm.script != null) {
264                 Element JavaDoc script = doc.createElementNS(FreeformProjectType.NS_GENERAL, "script"); //NOI18N
265
script.appendChild(doc.createTextNode(tm.script));
266                 action.appendChild(script);
267             }
268             if (tm.targets != null) {
269                 for (String JavaDoc targetName : tm.targets) {
270                     Element JavaDoc target = doc.createElementNS(FreeformProjectType.NS_GENERAL, "target"); //NOI18N
271
target.appendChild(doc.createTextNode(targetName));
272                     action.appendChild(target);
273                 }
274             }
275             if (tm.properties != null) {
276                 writeProperties(tm.properties, doc, action);
277             }
278             if (tm.context != null) {
279                 Element JavaDoc context = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context"); //NOI18N
280
TargetMapping.Context ctx = tm.context;
281                 assert ctx.property != null;
282                 Element JavaDoc property = doc.createElementNS(FreeformProjectType.NS_GENERAL, "property"); //NOI18N
283
property.appendChild(doc.createTextNode(ctx.property));
284                 context.appendChild(property);
285                 assert ctx.folder != null;
286                 Element JavaDoc folder = doc.createElementNS(FreeformProjectType.NS_GENERAL, "folder"); //NOI18N
287
folder.appendChild(doc.createTextNode(ctx.folder));
288                 context.appendChild(folder);
289                 if (ctx.pattern != null) {
290                     Element JavaDoc pattern = doc.createElementNS(FreeformProjectType.NS_GENERAL, "pattern"); //NOI18N
291
pattern.appendChild(doc.createTextNode(ctx.pattern));
292                     context.appendChild(pattern);
293                 }
294                 assert ctx.format != null;
295                 Element JavaDoc format = doc.createElementNS(FreeformProjectType.NS_GENERAL, "format"); //NOI18N
296
format.appendChild(doc.createTextNode(ctx.format));
297                 context.appendChild(format);
298                 Element JavaDoc arity = doc.createElementNS(FreeformProjectType.NS_GENERAL, "arity"); // NOI18N
299
if (ctx.separator != null) {
300                     Element JavaDoc sepFilesEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "separated-files"); // NOI18N
301
sepFilesEl.appendChild(doc.createTextNode(ctx.separator));
302                     arity.appendChild(sepFilesEl);
303                 } else {
304                     arity.appendChild(doc.createElementNS(FreeformProjectType.NS_GENERAL, "one-file-only")); // NOI18N
305
}
306                 context.appendChild(arity);
307                 action.appendChild(context);
308             }
309             actions.appendChild(action);
310         }
311         Util.appendChildElement(data, actions, rootElementsOrder);
312         Util.putPrimaryConfigurationData(helper, data);
313     }
314     
315     private static void writeProperties(EditableProperties props, Document JavaDoc doc, Element JavaDoc element) {
316         for (Map.Entry JavaDoc<String JavaDoc,String JavaDoc> entry : props.entrySet()) {
317             Element JavaDoc property = doc.createElementNS(FreeformProjectType.NS_GENERAL, "property"); //NOI18N
318
property.setAttribute("name", entry.getKey()); // NOI18N
319
property.appendChild(doc.createTextNode(entry.getValue()));
320             element.appendChild(property);
321         }
322     }
323     
324     /**
325      * Update context menu actions. Project is left modified and
326      * you must save it explicitely. This method stores all IDE actions
327      * before the custom actions what means that user's customization by hand
328      * (e.g. order of items) is lost.
329      * @param helper AntProjectHelper instance
330      * @param mappings list of <TargetMapping> instances for which the context
331      * menu actions will be created
332      */

333     public static void putContextMenuAction(AntProjectHelper helper, List JavaDoc<TargetMapping> mappings) {
334         //assert ProjectManager.mutex().isWriteAccess();
335
Element JavaDoc data = Util.getPrimaryConfigurationData(helper);
336         Document JavaDoc doc = data.getOwnerDocument();
337         Element JavaDoc viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
338
if (viewEl == null) {
339             viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
340
Util.appendChildElement(data, viewEl, rootElementsOrder);
341         }
342         Element JavaDoc contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
343
if (contextMenuEl == null) {
344             contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
345
Util.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
346         }
347         for (Element JavaDoc ideActionEl : Util.findSubElements(contextMenuEl)) {
348             if (!ideActionEl.getLocalName().equals("ide-action")) { // NOI18N
349
continue;
350             }
351             contextMenuEl.removeChild(ideActionEl);
352         }
353         for (TargetMapping tm : mappings) {
354             if (tm.context != null) {
355                 // ignore context sensitive actions
356
continue;
357             }
358             Element JavaDoc ideAction = doc.createElementNS(FreeformProjectType.NS_GENERAL, "ide-action"); //NOI18N
359
ideAction.setAttribute("name", tm.name); // NOI18N
360
Util.appendChildElement(contextMenuEl, ideAction, contextMenuElementsOrder);
361         }
362         Util.putPrimaryConfigurationData(helper, data);
363     }
364     
365     /**
366      * Read custom context menu actions from project.
367      * @param helper AntProjectHelper instance
368      * @return list of CustomTarget instances
369      */

370     public static List JavaDoc<CustomTarget> getCustomContextMenuActions(AntProjectHelper helper) {
371         //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
372
List JavaDoc<CustomTarget> list = new ArrayList JavaDoc<CustomTarget>();
373         Element JavaDoc genldata = Util.getPrimaryConfigurationData(helper);
374         Element JavaDoc viewEl = Util.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
375
if (viewEl == null) {
376             return list;
377         }
378         Element JavaDoc contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
379
if (contextMenuEl == null) {
380             return list;
381         }
382         for (Element JavaDoc actionEl : Util.findSubElements(contextMenuEl)) {
383             if (!actionEl.getLocalName().equals("action")) { // NOI18N
384
continue;
385             }
386             CustomTarget ct = new CustomTarget();
387             List JavaDoc<String JavaDoc> targetNames = new ArrayList JavaDoc<String JavaDoc>();
388             EditableProperties props = new EditableProperties(false);
389             for (Element JavaDoc subEl : Util.findSubElements(actionEl)) {
390                 if (subEl.getLocalName().equals("target")) { // NOI18N
391
targetNames.add(Util.findText(subEl));
392                     continue;
393                 }
394                 if (subEl.getLocalName().equals("script")) { // NOI18N
395
ct.script = Util.findText(subEl);
396                     continue;
397                 }
398                 if (subEl.getLocalName().equals("label")) { // NOI18N
399
ct.label = Util.findText(subEl);
400                     continue;
401                 }
402                 if (subEl.getLocalName().equals("property")) { // NOI18N
403
readProperty(subEl, props);
404                     continue;
405                 }
406             }
407             ct.targets = targetNames;
408             if (props.keySet().size() > 0) {
409                 ct.properties = props;
410             }
411             list.add(ct);
412         }
413         return list;
414     }
415     
416     /**
417      * Update custom context menu actions of the project. Project is left modified and
418      * you must save it explicitely. This method stores all custom actions
419      * after the IDE actions what means that user's customization by hand
420      * (e.g. order of items) is lost.
421      * @param helper AntProjectHelper instance
422      * @param list of <CustomTarget> instances to store
423      */

424     public static void putCustomContextMenuActions(AntProjectHelper helper, List JavaDoc<CustomTarget> customTargets) {
425         //assert ProjectManager.mutex().isWriteAccess();
426
Element JavaDoc data = Util.getPrimaryConfigurationData(helper);
427         Document JavaDoc doc = data.getOwnerDocument();
428         Element JavaDoc viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
429
if (viewEl == null) {
430             viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
431
Util.appendChildElement(data, viewEl, rootElementsOrder);
432         }
433         Element JavaDoc contextMenuEl = Util.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
434
if (contextMenuEl == null) {
435             contextMenuEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "context-menu"); // NOI18N
436
Util.appendChildElement(viewEl, contextMenuEl, viewElementsOrder);
437         }
438         for (Element JavaDoc actionEl : Util.findSubElements(contextMenuEl)) {
439             if (!actionEl.getLocalName().equals("action")) { // NOI18N
440
continue;
441             }
442             contextMenuEl.removeChild(actionEl);
443         }
444         for (CustomTarget ct : customTargets) {
445             Element JavaDoc action = doc.createElementNS(FreeformProjectType.NS_GENERAL, "action"); //NOI18N
446
if (ct.script != null) {
447                 Element JavaDoc script = doc.createElementNS(FreeformProjectType.NS_GENERAL, "script"); //NOI18N
448
script.appendChild(doc.createTextNode(ct.script)); // NOI18N
449
action.appendChild(script);
450             }
451             Element JavaDoc label = doc.createElementNS(FreeformProjectType.NS_GENERAL, "label"); //NOI18N
452
label.appendChild(doc.createTextNode(ct.label)); // NOI18N
453
action.appendChild(label);
454             if (ct.targets != null) {
455                 for (String JavaDoc targetName : ct.targets) {
456                     Element JavaDoc target = doc.createElementNS(FreeformProjectType.NS_GENERAL, "target"); //NOI18N
457
target.appendChild(doc.createTextNode(targetName)); // NOI18N
458
action.appendChild(target);
459                 }
460             }
461             if (ct.properties != null) {
462                 writeProperties(ct.properties, doc, action);
463             }
464             Util.appendChildElement(contextMenuEl, action, contextMenuElementsOrder);
465         }
466         Util.putPrimaryConfigurationData(helper, data);
467     }
468     
469     /**
470      * Structure describing custom target mapping.
471      * Data in the struct are in the same format as they are stored in XML.
472      */

473     public static final class CustomTarget {
474         public List JavaDoc<String JavaDoc> targets;
475         public String JavaDoc label;
476         public String JavaDoc script;
477         public EditableProperties properties;
478     }
479     
480     /**
481      * Structure describing target mapping.
482      * Data in the struct are in the same format as they are stored in XML.
483      */

484     public static final class TargetMapping {
485         public String JavaDoc script;
486         public List JavaDoc<String JavaDoc> targets;
487         public String JavaDoc name;
488         public EditableProperties properties;
489         public Context context; // may be null
490

491         public static final class Context {
492             public String JavaDoc property;
493             public String JavaDoc format;
494             public String JavaDoc folder;
495             public String JavaDoc pattern; // may be null
496
public String JavaDoc separator; // may be null
497
}
498     }
499
500     private static void putBuildXMLSourceFile(AntProjectHelper helper, String JavaDoc antPath) {
501         Element JavaDoc data = Util.getPrimaryConfigurationData(helper);
502         Document JavaDoc doc = data.getOwnerDocument();
503         Element JavaDoc viewEl = Util.findElement(data, "view", FreeformProjectType.NS_GENERAL); // NOI18N
504
if (viewEl == null) {
505             viewEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "view"); // NOI18N
506
Util.appendChildElement(data, viewEl, rootElementsOrder);
507         }
508         Element JavaDoc itemsEl = Util.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
509
if (itemsEl == null) {
510             itemsEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "items"); // NOI18N
511
Util.appendChildElement(viewEl, itemsEl, viewElementsOrder);
512         }
513         Element JavaDoc fileEl = doc.createElementNS(FreeformProjectType.NS_GENERAL, "source-file"); // NOI18N
514
Element JavaDoc el = doc.createElementNS(FreeformProjectType.NS_GENERAL, "location"); // NOI18N
515
el.appendChild(doc.createTextNode(antPath)); // NOI18N
516
fileEl.appendChild(el);
517         Util.appendChildElement(itemsEl, fileEl, viewItemElementsOrder);
518         Util.putPrimaryConfigurationData(helper, data);
519     }
520
521     /**
522      * Returns Ant script of the freeform project
523      * represented by the given AntProjectHelper.
524      * @param helper AntProjectHelper of freeform project
525      * @param ev evaluator of the freeform project
526      * @return Ant script FileObject or null if it cannot be found
527      */

528     public static FileObject getAntScript(AntProjectHelper helper, PropertyEvaluator ev) {
529         //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
530
String JavaDoc antScript = ev.getProperty(ProjectConstants.PROP_ANT_SCRIPT);
531         if (antScript != null) {
532             File JavaDoc f= helper.resolveFile(antScript);
533             if (!f.exists()) {
534                 return null;
535             }
536             FileObject fo = FileUtil.toFileObject(f);
537             return fo;
538         } else {
539             FileObject fo = helper.getProjectDirectory().getFileObject("build.xml"); // NOI18N
540
return fo;
541         }
542     }
543
544 }
545
Popular Tags