KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > ui > customizer > AppClientProjectProperties


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.j2ee.clientproject.ui.customizer;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URI JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Properties JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.Vector JavaDoc;
34 import javax.swing.ButtonModel JavaDoc;
35 import javax.swing.ComboBoxModel JavaDoc;
36 import javax.swing.DefaultListModel JavaDoc;
37 import javax.swing.JButton JavaDoc;
38 import javax.swing.JToggleButton JavaDoc;
39 import javax.swing.ListCellRenderer JavaDoc;
40 import javax.swing.table.DefaultTableModel JavaDoc;
41 import javax.swing.text.BadLocationException JavaDoc;
42 import javax.swing.text.Document JavaDoc;
43 import org.netbeans.api.project.Project;
44 import org.netbeans.api.project.ProjectManager;
45 import org.netbeans.api.queries.CollocationQuery;
46 import org.netbeans.modules.j2ee.clientproject.AppClientProject;
47 import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil;
48 import org.netbeans.modules.j2ee.clientproject.SourceRoots;
49 import org.netbeans.modules.j2ee.clientproject.UpdateHelper;
50 import org.netbeans.modules.j2ee.clientproject.Utils;
51 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport;
52 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper;
53 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
54 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
55 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
56 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
57 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper;
58 import org.netbeans.modules.websvc.api.client.WebServicesClientConstants;
59 import org.netbeans.spi.project.support.ant.AntProjectHelper;
60 import org.netbeans.spi.project.support.ant.EditableProperties;
61 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
62 import org.netbeans.spi.project.support.ant.PropertyUtils;
63 import org.netbeans.spi.project.support.ant.ReferenceHelper;
64 import org.netbeans.spi.project.support.ant.ui.StoreGroup;
65 import org.openide.DialogDisplayer;
66 import org.openide.ErrorManager;
67 import org.openide.NotifyDescriptor;
68 import org.openide.filesystems.FileObject;
69 import org.openide.filesystems.FileUtil;
70 import org.openide.filesystems.URLMapper;
71 import org.openide.modules.SpecificationVersion;
72 import org.openide.util.Mutex;
73 import org.openide.util.MutexException;
74 import org.openide.util.NbBundle;
75
76 /**
77  * @author Petr Hrebejk
78  */

79 public class AppClientProjectProperties {
80     
81     //Hotfix of the issue #70058
82
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
83
private static final Integer JavaDoc BOOLEAN_KIND_TF = new Integer JavaDoc( 0 );
84     private static final Integer JavaDoc BOOLEAN_KIND_YN = new Integer JavaDoc( 1 );
85     private static final Integer JavaDoc BOOLEAN_KIND_ED = new Integer JavaDoc( 2 );
86     private Integer JavaDoc javacDebugBooleanKind;
87     private Integer JavaDoc javadocPreviewBooleanKind;
88     
89     public static final String JavaDoc JAVA_EE_5 = "1.5"; // NOI18N
90
public static final String JavaDoc J2EE_1_4 = "1.4"; // NOI18N
91
public static final String JavaDoc J2EE_1_3 = "1.3"; // NOI18N
92

93     // Special properties of the project
94
public static final String JavaDoc CAR_PROJECT_NAME = "j2ee.clientproject.name"; // NOI18N
95
public static final String JavaDoc JAVA_PLATFORM = "platform.active"; // NOI18N
96
public static final String JavaDoc J2EE_PLATFORM = "j2ee.platform"; // NOI18N
97

98     public static final String JavaDoc SOURCE_ROOT = "source.root"; // NOI18N
99
public static final String JavaDoc BUILD_FILE = "buildfile"; // NOI18N
100
public static final String JavaDoc META_INF = "meta.inf"; // NOI18N
101
public static final String JavaDoc SRC_DIR = "src.dir"; // NOI18N
102
public static final String JavaDoc LIBRARIES_DIR = "lib.dir"; //NOI18N
103
public static final String JavaDoc RESOURCE_DIR = "resource.dir"; // NOI18N
104
public static final String JavaDoc DIST_EAR_JAR = "dist.ear.jar"; //NOI18N
105
public static final String JavaDoc JAR_NAME = "jar.name"; // NOI18N
106
public static final String JavaDoc BUILD_EAR_CLASSES_DIR = "build.ear.classes.dir"; // NOI18N
107
public static final String JavaDoc J2EE_SERVER_INSTANCE = "j2ee.server.instance"; // NOI18N
108
public static final String JavaDoc J2EE_SERVER_TYPE = "j2ee.server.type"; // NOI18N
109
public static final String JavaDoc J2EE_PLATFORM_CLASSPATH = "j2ee.platform.classpath"; //NOI18N
110

111     
112     // Properties stored in the PROJECT.PROPERTIES
113
/** root of external web module sources (full path), ".." if the sources are within project folder */
114     public static final String JavaDoc DIST_DIR = "dist.dir"; // NOI18N
115
public static final String JavaDoc DIST_JAR = "dist.jar"; // NOI18N
116
public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; // NOI18N
117
public static final String JavaDoc RUN_CLASSPATH = "run.classpath"; // NOI18N
118
public static final String JavaDoc RUN_JVM_ARGS = "run.jvmargs"; // NOI18N
119
public static final String JavaDoc RUN_WORK_DIR = "work.dir"; // NOI18N
120
public static final String JavaDoc DEBUG_CLASSPATH = "debug.classpath"; // NOI18N
121
public static final String JavaDoc JAR_COMPRESS = "jar.compress"; // NOI18N
122
public static final String JavaDoc MAIN_CLASS = "main.class"; // NOI18N
123
public static final String JavaDoc JAVAC_SOURCE = "javac.source"; // NOI18N
124
public static final String JavaDoc JAVAC_TARGET = "javac.target"; // NOI18N
125
public static final String JavaDoc JAVAC_TEST_CLASSPATH = "javac.test.classpath"; // NOI18N
126
public static final String JavaDoc JAVAC_DEBUG = "javac.debug"; // NOI18N
127
public static final String JavaDoc JAVAC_DEPRECATION = "javac.deprecation"; // NOI18N
128
public static final String JavaDoc JAVAC_COMPILER_ARG = "javac.compilerargs"; //NOI18N
129
public static final String JavaDoc RUN_TEST_CLASSPATH = "run.test.classpath"; // NOI18N
130
public static final String JavaDoc BUILD_DIR = "build.dir"; // NOI18N
131
public static final String JavaDoc BUILD_CLASSES_DIR = "build.classes.dir"; // NOI18N
132
public static final String JavaDoc BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N
133
public static final String JavaDoc BUILD_TEST_RESULTS_DIR = "build.test.results.dir"; // NOI18N
134
public static final String JavaDoc BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; // NOI18N
135
public static final String JavaDoc DIST_JAVADOC_DIR = "dist.javadoc.dir"; // NOI18N
136
public static final String JavaDoc NO_DEPENDENCIES="no.dependencies"; // NOI18N
137
public static final String JavaDoc DEBUG_TEST_CLASSPATH = "debug.test.classpath"; // NOI18N
138

139     
140     public static final String JavaDoc JAVADOC_PRIVATE="javadoc.private"; // NOI18N
141
public static final String JavaDoc JAVADOC_NO_TREE="javadoc.notree"; // NOI18N
142
public static final String JavaDoc JAVADOC_USE="javadoc.use"; // NOI18N
143
public static final String JavaDoc JAVADOC_NO_NAVBAR="javadoc.nonavbar"; // NOI18N
144
public static final String JavaDoc JAVADOC_NO_INDEX="javadoc.noindex"; // NOI18N
145
public static final String JavaDoc JAVADOC_SPLIT_INDEX="javadoc.splitindex"; // NOI18N
146
public static final String JavaDoc JAVADOC_AUTHOR="javadoc.author"; // NOI18N
147
public static final String JavaDoc JAVADOC_VERSION="javadoc.version"; // NOI18N
148
public static final String JavaDoc JAVADOC_WINDOW_TITLE="javadoc.windowtitle"; // NOI18N
149
public static final String JavaDoc JAVADOC_ENCODING="javadoc.encoding"; // NOI18N
150
public static final String JavaDoc JAVADOC_ADDITIONALPARAM="javadoc.additionalparam"; // NOI18N
151

152     public static final String JavaDoc CLIENT_NAME = "j2ee.clientName"; // NOI18N
153

154     // Properties stored in the PRIVATE.PROPERTIES
155
public static final String JavaDoc APPLICATION_ARGS = "application.args"; // NOI18N
156
public static final String JavaDoc JAVADOC_PREVIEW="javadoc.preview"; // NOI18N
157
public static final String JavaDoc DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; //NOI18N
158

159     public static final String JavaDoc ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; // NOI18N
160

161     public static final String JavaDoc APPCLIENT_MAINCLASS_ARGS = "j2ee.appclient.mainclass.args"; // NOI18N
162

163     public static final String JavaDoc APPCLIENT_TOOL_RUNTIME = "j2ee.appclient.tool.runtime"; // NOI18N
164
public static final String JavaDoc APPCLIENT_TOOL_MAINCLASS = "j2ee.appclient.tool.mainclass"; // NOI18N
165
public static final String JavaDoc APPCLIENT_TOOL_JVMOPTS = "j2ee.appclient.tool.jvmoptions"; // NOI18N
166
public static final String JavaDoc APPCLIENT_TOOL_ARGS = "j2ee.appclient.tool.args"; // NOI18N
167

168     /**
169      * "API" contract between Application Client and Glassfish plugin's
170      * J2eePlatformImpl implementation.
171      */

172     public static final String JavaDoc J2EE_PLATFORM_APPCLIENT_ARGS = "j2ee.appclient.args"; // NOI18N
173

174     // Well known paths
175
public static final String JavaDoc[] WELL_KNOWN_PATHS = new String JavaDoc[] {
176             "${" + JAVAC_CLASSPATH + "}", // NOI18N
177
"${" + JAVAC_TEST_CLASSPATH + "}", // NOI18N
178
"${" + RUN_CLASSPATH + "}", // NOI18N
179
"${" + RUN_TEST_CLASSPATH + "}", // NOI18N
180
"${" + BUILD_CLASSES_DIR + "}", // NOI18N
181
"${" + BUILD_TEST_CLASSES_DIR + "}", // NOI18N
182
};
183     
184     // Prefixes and suffixes of classpath
185
public static final String JavaDoc LIBRARY_PREFIX = "${libs."; // NOI18N
186
public static final String JavaDoc LIBRARY_SUFFIX = ".classpath}"; // NOI18N
187
// XXX looks like there is some kind of API missing in ReferenceHelper?
188
public static final String JavaDoc ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N
189

190     ClassPathSupport cs;
191     
192     
193     // SOURCE ROOTS
194
// public static final String SOURCE_ROOTS = "__virtual_source_roots__"; //NOI18N
195
// public static final String TEST_ROOTS = "__virtual_test_roots__"; // NOI18N
196

197     // MODELS FOR VISUAL CONTROLS
198

199     // CustomizerSources
200
DefaultTableModel JavaDoc SOURCE_ROOTS_MODEL;
201     DefaultTableModel JavaDoc TEST_ROOTS_MODEL;
202     Document JavaDoc META_INF_MODEL;
203     ComboBoxModel JavaDoc JAVAC_SOURCE_MODEL;
204      
205     // CustomizerLibraries
206
ClassPathUiSupport.ClassPathTableModel JAVAC_CLASSPATH_MODEL;
207     DefaultListModel JavaDoc JAVAC_TEST_CLASSPATH_MODEL;
208     DefaultListModel JavaDoc RUN_CLASSPATH_MODEL;
209     DefaultListModel JavaDoc RUN_TEST_CLASSPATH_MODEL;
210     ComboBoxModel JavaDoc PLATFORM_MODEL;
211     ListCellRenderer JavaDoc CLASS_PATH_LIST_RENDERER;
212     ListCellRenderer JavaDoc PLATFORM_LIST_RENDERER;
213     ListCellRenderer JavaDoc JAVAC_SOURCE_RENDERER;
214     
215     AppClientClassPathUi.ClassPathTableCellItemRenderer CLASS_PATH_TABLE_ITEM_RENDERER;
216     
217     
218     // CustomizerCompile
219
ButtonModel JavaDoc JAVAC_DEPRECATION_MODEL;
220     ButtonModel JavaDoc JAVAC_DEBUG_MODEL;
221     ButtonModel JavaDoc NO_DEPENDENCIES_MODEL;
222     Document JavaDoc JAVAC_COMPILER_ARG_MODEL;
223     
224     // CustomizerCompileTest
225

226     // CustomizerJar
227
Document JavaDoc DIST_JAR_MODEL;
228     Document JavaDoc BUILD_CLASSES_EXCLUDES_MODEL;
229     ButtonModel JavaDoc JAR_COMPRESS_MODEL;
230                 
231     // CustomizerJavadoc
232
ButtonModel JavaDoc JAVADOC_PRIVATE_MODEL;
233     ButtonModel JavaDoc JAVADOC_NO_TREE_MODEL;
234     ButtonModel JavaDoc JAVADOC_USE_MODEL;
235     ButtonModel JavaDoc JAVADOC_NO_NAVBAR_MODEL;
236     ButtonModel JavaDoc JAVADOC_NO_INDEX_MODEL;
237     ButtonModel JavaDoc JAVADOC_SPLIT_INDEX_MODEL;
238     ButtonModel JavaDoc JAVADOC_AUTHOR_MODEL;
239     ButtonModel JavaDoc JAVADOC_VERSION_MODEL;
240     Document JavaDoc JAVADOC_WINDOW_TITLE_MODEL;
241     ButtonModel JavaDoc JAVADOC_PREVIEW_MODEL;
242     Document JavaDoc JAVADOC_ADDITIONALPARAM_MODEL;
243
244     // CustomizerRun
245
Document JavaDoc MAIN_CLASS_MODEL;
246     Document JavaDoc APPLICATION_ARGS_MODEL;
247     Document JavaDoc RUN_JVM_ARGS_MODEL;
248     Document JavaDoc RUN_WORK_DIR_MODEL;
249     
250     ComboBoxModel JavaDoc J2EE_SERVER_INSTANCE_MODEL;
251     ComboBoxModel JavaDoc J2EE_PLATFORM_MODEL;
252     
253
254
255     // CustomizerRunTest
256

257     // Private fields ----------------------------------------------------------
258
private final AppClientProject project;
259     private final UpdateHelper updateHelper;
260     private final PropertyEvaluator evaluator;
261     private final ReferenceHelper refHelper;
262     private final GeneratedFilesHelper genFileHelper;
263     
264     private final StoreGroup privateGroup;
265     private final StoreGroup projectGroup;
266     
267     private final Properties JavaDoc additionalProperties;
268
269     public static final String JavaDoc JAVA_SOURCE_BASED = "java.source.based";
270     
271     AppClientProject getProject() {
272         return project;
273     }
274     
275     /** Creates a new instance of J2SEUIProperties and initializes them */
276     public AppClientProjectProperties( AppClientProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper ) {
277         this.project = project;
278         this.updateHelper = updateHelper;
279         this.evaluator = evaluator;
280         this.refHelper = refHelper;
281         this.genFileHelper = genFileHelper;
282         this.cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), WELL_KNOWN_PATHS, LIBRARY_PREFIX, LIBRARY_SUFFIX, ANT_ARTIFACT_PREFIX );
283                 
284         privateGroup = new StoreGroup();
285         projectGroup = new StoreGroup();
286         
287         additionalProperties = new Properties JavaDoc();
288         
289         init(); // Load known properties
290
}
291
292     /** Initializes the visual models
293      */

294     private void init() {
295         
296         CLASS_PATH_LIST_RENDERER = new AppClientClassPathUi.ClassPathListCellRenderer( evaluator );
297         CLASS_PATH_TABLE_ITEM_RENDERER = new AppClientClassPathUi.ClassPathTableCellItemRenderer( evaluator );
298         
299         // CustomizerSources
300
SOURCE_ROOTS_MODEL = AppClientSourceRootsUi.createModel( project.getSourceRoots() );
301         TEST_ROOTS_MODEL = AppClientSourceRootsUi.createModel( project.getTestSourceRoots() );
302         META_INF_MODEL = projectGroup.createStringDocument( evaluator, META_INF );
303                 
304         // CustomizerLibraries
305
EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
306         EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH );
307         
308         JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createTableModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) );
309         JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) );
310         RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( RUN_CLASSPATH ), null ) );
311         RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( RUN_TEST_CLASSPATH ), null ) );
312         PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM));
313         PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer();
314         JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(J2EE_PLATFORM));
315         JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer ();
316                 
317         // CustomizerCompile
318
JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION );
319                 
320         //Hotfix of the issue #70058
321
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
322
Integer JavaDoc[] kind = new Integer JavaDoc[1];
323         JAVAC_DEBUG_MODEL = createToggleButtonModel( evaluator, JAVAC_DEBUG, kind);
324         javacDebugBooleanKind = kind[0];
325         
326         NO_DEPENDENCIES_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, NO_DEPENDENCIES );
327         JAVAC_COMPILER_ARG_MODEL = projectGroup.createStringDocument( evaluator, JAVAC_COMPILER_ARG );
328         
329         // CustomizerJar
330
DIST_JAR_MODEL = projectGroup.createStringDocument( evaluator, DIST_JAR );
331         BUILD_CLASSES_EXCLUDES_MODEL = projectGroup.createStringDocument( evaluator, BUILD_CLASSES_EXCLUDES );
332         JAR_COMPRESS_MODEL = projectGroup.createToggleButtonModel( evaluator, JAR_COMPRESS );
333         
334         // CustomizerJavadoc
335
JAVADOC_PRIVATE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_PRIVATE );
336         JAVADOC_NO_TREE_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_TREE );
337         JAVADOC_USE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_USE );
338         JAVADOC_NO_NAVBAR_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_NAVBAR );
339         JAVADOC_NO_INDEX_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_INDEX );
340         JAVADOC_SPLIT_INDEX_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_SPLIT_INDEX );
341         JAVADOC_AUTHOR_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_AUTHOR );
342         JAVADOC_VERSION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_VERSION );
343         JAVADOC_WINDOW_TITLE_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_WINDOW_TITLE );
344         //Hotfix of the issue #70058
345
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
346
JAVADOC_PREVIEW_MODEL = createToggleButtonModel ( evaluator, JAVADOC_PREVIEW, kind);
347         javadocPreviewBooleanKind = kind[0];
348         
349         JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM );
350         // CustomizerRun
351
MAIN_CLASS_MODEL = projectGroup.createStringDocument( evaluator, MAIN_CLASS );
352         APPLICATION_ARGS_MODEL = privateGroup.createStringDocument( evaluator, APPLICATION_ARGS );
353         RUN_JVM_ARGS_MODEL = projectGroup.createStringDocument( evaluator, RUN_JVM_ARGS );
354         RUN_WORK_DIR_MODEL = privateGroup.createStringDocument( evaluator, RUN_WORK_DIR );
355
356         J2EE_SERVER_INSTANCE_MODEL = J2eePlatformUiSupport.createPlatformComboBoxModel(
357                 privateProperties.getProperty(J2EE_SERVER_INSTANCE), projectProperties.getProperty(J2EE_PLATFORM));
358         J2EE_PLATFORM_MODEL = J2eePlatformUiSupport.createSpecVersionComboBoxModel(
359             projectProperties.getProperty( J2EE_PLATFORM ));
360     }
361     
362     public void save() {
363         try {
364             // Store properties
365
Boolean JavaDoc result = (Boolean JavaDoc) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
366                 public Object JavaDoc run() throws IOException JavaDoc {
367                     if ((genFileHelper.getBuildScriptState(GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
368                         AppClientProject.class.getResource("resources/build-impl.xsl"), //NOI18N
369
getProject().findJaxWsFileObject()) &
370                             GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) { //NOI18N
371
if (showModifiedMessage (NbBundle.getMessage(AppClientProjectProperties.class,"TXT_ModifiedTitle"))) {
372                             //Delete user modified build-impl.xml
373
FileObject fo = updateHelper.getAntProjectHelper().getProjectDirectory().
374                                 getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH);
375                             if (fo != null) {
376                                 fo.delete();
377                             }
378                         }
379                         else {
380                             return Boolean.FALSE;
381                         }
382                     }
383                     storeProperties();
384                     return Boolean.TRUE;
385                 }
386             });
387             // and save the project
388
if (result == Boolean.TRUE) {
389                 ProjectManager.getDefault().saveProject(project);
390             }
391         }
392         catch (MutexException e) {
393             ErrorManager.getDefault().notify((IOException JavaDoc)e.getException());
394         }
395         catch ( IOException JavaDoc ex ) {
396             ErrorManager.getDefault().notify( ex );
397         }
398     }
399     
400     
401         
402     private void storeProperties() throws IOException JavaDoc {
403         // Store special properties
404

405         // Modify the project dependencies properly
406
resolveProjectDependencies();
407         
408         // Encode all paths (this may change the project properties)
409
String JavaDoc[] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES );
410         String JavaDoc[] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ), null );
411         String JavaDoc[] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ), null );
412         String JavaDoc[] run_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_CLASSPATH_MODEL ), null );
413                 
414         // Store source roots
415
storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL );
416         storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL );
417                 
418         // Store standard properties
419
EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
420         EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH );
421         
422         // Assure inegrity which can't shound not be assured in UI
423
if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) {
424             JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); // Can't split non existing index
425
}
426                                 
427         // Standard store of the properties
428
projectGroup.store( projectProperties );
429         privateGroup.store( privateProperties );
430         
431         //Hotfix of the issue #70058
432
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
433
//Save javac.debug
434
privateProperties.setProperty(JAVAC_DEBUG, encodeBoolean (JAVAC_DEBUG_MODEL.isSelected(), javacDebugBooleanKind));
435                 
436         //Hotfix of the issue #70058
437
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
438
//Save javadoc.preview
439
privateProperties.setProperty(JAVADOC_PREVIEW, encodeBoolean (JAVADOC_PREVIEW_MODEL.isSelected(), javadocPreviewBooleanKind));
440                 
441         // Save all paths
442
projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp );
443         projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp );
444         projectProperties.setProperty( RUN_CLASSPATH, run_cp );
445         projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp );
446         
447         //Handle platform selection and javac.source javac.target properties
448
SpecificationVersion sourceLevel = (SpecificationVersion) JAVAC_SOURCE_MODEL.getSelectedItem();
449         PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), sourceLevel);
450                                 
451         // Handle other special cases
452
if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N
453
projectProperties.remove( NO_DEPENDENCIES ); // Remove the property completely if not set
454
}
455
456         if ( getDocumentText( RUN_WORK_DIR_MODEL ).trim().equals( "" ) ) { // NOI18N
457
privateProperties.remove( RUN_WORK_DIR ); // Remove the property completely if not set
458
}
459         
460         if (getDocumentText(MAIN_CLASS_MODEL).trim().equals("")) { // NOI18N
461
projectProperties.remove(MAIN_CLASS); // Remove the property completely if not set
462
}
463         
464         // Set new server instance ID
465
if (J2EE_SERVER_INSTANCE_MODEL.getSelectedItem() != null) {
466             setNewServerInstanceValue(J2eePlatformUiSupport.getServerInstanceID(J2EE_SERVER_INSTANCE_MODEL.getSelectedItem()), project, projectProperties, privateProperties);
467         }
468         
469         storeAdditionalProperties(projectProperties);
470         List JavaDoc<ClassPathSupport.Item> cpItems = ClassPathUiSupport.getList(JAVAC_CLASSPATH_MODEL.getDefaultListModel());
471         storeLibrariesLocations(cpItems.iterator(), privateProperties);
472         
473         // Store the property changes into the project
474
updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties );
475         updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties );
476         
477     }
478   
479     private void storeAdditionalProperties(EditableProperties projectProperties) {
480         for (Iterator JavaDoc i = additionalProperties.keySet().iterator(); i.hasNext();) {
481             String JavaDoc key = i.next().toString();
482             projectProperties.put(key, additionalProperties.getProperty(key));
483         }
484     }
485     
486     private static String JavaDoc getDocumentText( Document JavaDoc document ) {
487         try {
488             return document.getText( 0, document.getLength() );
489         }
490         catch( BadLocationException JavaDoc e ) {
491             return ""; // NOI18N
492
}
493     }
494     
495     /** Finds out what are new and removed project dependencies and
496      * applyes the info to the project
497      */

498     private void resolveProjectDependencies() {
499             
500         // Create a set of old and new artifacts.
501
Set JavaDoc<ClassPathSupport.Item> oldArtifacts = new HashSet JavaDoc<ClassPathSupport.Item>();
502         EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
503         oldArtifacts.addAll( cs.itemsList( (String JavaDoc)projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) );
504         oldArtifacts.addAll( cs.itemsList( (String JavaDoc)projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) );
505         oldArtifacts.addAll( cs.itemsList( (String JavaDoc)projectProperties.get( RUN_CLASSPATH ), null ) );
506         oldArtifacts.addAll( cs.itemsList( (String JavaDoc)projectProperties.get( RUN_TEST_CLASSPATH ), null ) );
507                    
508         Set JavaDoc<ClassPathSupport.Item> newArtifacts = new HashSet JavaDoc<ClassPathSupport.Item>();
509         newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ) );
510         newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) );
511         newArtifacts.addAll( ClassPathUiSupport.getList( RUN_CLASSPATH_MODEL ) );
512         newArtifacts.addAll( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) );
513                 
514         // Create set of removed artifacts and remove them
515
Set JavaDoc<ClassPathSupport.Item> removed = new HashSet JavaDoc<ClassPathSupport.Item>( oldArtifacts );
516         removed.removeAll( newArtifacts );
517         Set JavaDoc<ClassPathSupport.Item> added = new HashSet JavaDoc<ClassPathSupport.Item>(newArtifacts);
518         added.removeAll(oldArtifacts);
519         
520         // 1. first remove all project references. The method will modify
521
// project property files, so it must be done separately
522
for( Iterator JavaDoc it = removed.iterator(); it.hasNext(); ) {
523             ClassPathSupport.Item item = (ClassPathSupport.Item)it.next();
524             if ( item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT ||
525                     item.getType() == ClassPathSupport.Item.TYPE_JAR ) {
526                 refHelper.destroyReference(item.getReference());
527             }
528         }
529         
530         // 2. now read project.properties and modify rest
531
EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
532         boolean changed = false;
533         
534         for( Iterator JavaDoc it = removed.iterator(); it.hasNext(); ) {
535             ClassPathSupport.Item item = (ClassPathSupport.Item)it.next();
536             if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
537                 // remove helper property pointing to library jar if there is any
538
String JavaDoc prop = item.getReference();
539                 prop = prop.substring(2, prop.length()-1);
540                 ep.remove(prop);
541                 changed = true;
542             }
543         }
544         File JavaDoc projDir = FileUtil.toFile(updateHelper.getAntProjectHelper().getProjectDirectory());
545         for( Iterator JavaDoc it = added.iterator(); it.hasNext(); ) {
546             ClassPathSupport.Item item = (ClassPathSupport.Item)it.next();
547             if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY && !item.isBroken()) {
548                 // add property to project.properties pointing to relativized
549
// library jar(s) if possible
550
String JavaDoc prop = cs.getLibraryReference( item );
551                 prop = prop.substring(2, prop.length()-1); // XXX make a PropertyUtils method for this!
552
String JavaDoc value = relativizeLibraryClasspath(prop, projDir);
553                 if (value != null) {
554                     ep.setProperty(prop, value);
555                     ep.setComment(prop, new String JavaDoc[]{
556                         // XXX this should be I18N! Not least because the English is wrong...
557
"# Property "+prop+" is set here just to make sharing of project simpler.", // NOI18N
558
"# The library definition has always preference over this property."}, false); // NOI18N
559
changed = true;
560                 }
561             }
562         }
563         if (changed) {
564             updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
565         }
566     }
567     
568     /**
569      * Tokenize library classpath and try to relativize all the jars.
570      * @param property library property name ala "libs.someLib.classpath"
571      * @param projectDir project dir for relativization
572      * @return relativized library classpath or null if some jar is not collocated
573      */

574     private String JavaDoc relativizeLibraryClasspath(String JavaDoc property, File JavaDoc projectDir) {
575         String JavaDoc value = PropertyUtils.getGlobalProperties().getProperty(property);
576         // bugfix #42852, check if the classpath property is set, otherwise return null
577
if (value == null) {
578             return null;
579         }
580         String JavaDoc[] paths = PropertyUtils.tokenizePath(value);
581         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
582         for (int i=0; i<paths.length; i++) {
583             File JavaDoc f = updateHelper.getAntProjectHelper().resolveFile(paths[i]);
584             if (CollocationQuery.areCollocated(f, projectDir)) {
585                 sb.append(PropertyUtils.relativizeFile(projectDir, f));
586             } else {
587                 return null;
588             }
589             if (i+1<paths.length) {
590                 sb.append(File.pathSeparatorChar);
591             }
592         }
593         if (sb.length() == 0) {
594             return null;
595         } else {
596             return sb.toString();
597         }
598     }
599     
600     private void storeRoots( SourceRoots roots, DefaultTableModel JavaDoc tableModel ) throws MalformedURLException JavaDoc {
601         Vector JavaDoc data = tableModel.getDataVector();
602         URL JavaDoc[] rootURLs = new URL JavaDoc[data.size()];
603         String JavaDoc []rootLabels = new String JavaDoc[data.size()];
604         for (int i=0; i<data.size();i++) {
605             File JavaDoc f = (File JavaDoc) ((Vector JavaDoc)data.elementAt(i)).elementAt(0);
606             rootURLs[i] = AppClientProjectUtil.getRootURL(f,null);
607             rootLabels[i] = (String JavaDoc) ((Vector JavaDoc)data.elementAt(i)).elementAt(1);
608         }
609         roots.putRoots(rootURLs,rootLabels);
610     }
611     
612     /* This is used by CustomizerWSServiceHost */
613     public void putAdditionalProperty(String JavaDoc propertyName, String JavaDoc propertyValue) {
614         additionalProperties.setProperty(propertyName, propertyValue);
615     }
616     
617     private static boolean showModifiedMessage (String JavaDoc title) {
618         String JavaDoc message = NbBundle.getMessage(AppClientProjectProperties.class,"TXT_Regenerate");
619         JButton JavaDoc regenerateButton = new JButton JavaDoc (NbBundle.getMessage(AppClientProjectProperties.class,"CTL_RegenerateButton"));
620         regenerateButton.setDefaultCapable(true);
621         regenerateButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(AppClientProjectProperties.class,"AD_RegenerateButton"));
622         NotifyDescriptor d = new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE);
623         d.setTitle(title);
624         d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
625         d.setOptions(new Object JavaDoc[] {regenerateButton, NotifyDescriptor.CANCEL_OPTION});
626         return DialogDisplayer.getDefault().notify(d) == regenerateButton;
627     }
628     
629     //Hotfix of the issue #70058
630
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
631
private static String JavaDoc encodeBoolean (boolean value, Integer JavaDoc kind) {
632         if ( kind == BOOLEAN_KIND_ED ) {
633             return value ? "on" : "off"; // NOI18N
634
}
635         else if ( kind == BOOLEAN_KIND_YN ) { // NOI18N
636
return value ? "yes" : "no"; // NOI18N
637
}
638         else {
639             return value ? "true" : "false"; // NOI18N
640
}
641     }
642     
643     //Hotfix of the issue #70058
644
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
645
private static JToggleButton.ToggleButtonModel JavaDoc createToggleButtonModel (final PropertyEvaluator evaluator, final String JavaDoc propName, Integer JavaDoc[] kind) {
646         assert evaluator != null && propName != null && kind != null && kind.length == 1;
647         String JavaDoc value = evaluator.getProperty( propName );
648         boolean isSelected = false;
649         if (value == null) {
650             isSelected = true;
651         }
652         else {
653            String JavaDoc lowercaseValue = value.toLowerCase();
654            if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { // NOI18N
655
kind[0] = BOOLEAN_KIND_YN;
656            }
657            else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { // NOI18N
658
kind[0] = BOOLEAN_KIND_ED;
659            }
660            else {
661                kind[0] = BOOLEAN_KIND_TF;
662            }
663
664            if ( lowercaseValue.equals( "true") || // NOI18N
665
lowercaseValue.equals( "yes") || // NOI18N
666
lowercaseValue.equals( "on") ) { // NOI18N
667
isSelected = true;
668            }
669         }
670         JToggleButton.ToggleButtonModel JavaDoc bm = new JToggleButton.ToggleButtonModel JavaDoc();
671         bm.setSelected(isSelected );
672         return bm;
673     }
674     
675     public static void setServerInstance(final Project project, final AntProjectHelper helper, final String JavaDoc serverInstanceID) {
676         ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
677             public void run() {
678                 try {
679                     EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
680                     EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
681                     setNewServerInstanceValue(serverInstanceID, project, projectProps, privateProps);
682                     helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps);
683                     helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps);
684                     ProjectManager.getDefault().saveProject(project);
685                 }
686                 catch (IOException JavaDoc e) {
687                     ErrorManager.getDefault().notify();
688                 }
689             }
690         });
691     }
692     
693     private static void setNewServerInstanceValue(String JavaDoc newServInstID, Project project, EditableProperties projectProps, EditableProperties privateProps) {
694         // update j2ee.platform.classpath
695
String JavaDoc oldServInstID = privateProps.getProperty(J2EE_SERVER_INSTANCE);
696         if (oldServInstID != null) {
697             J2eePlatform oldJ2eePlatform = Deployment.getDefault().getJ2eePlatform(oldServInstID);
698             if (oldJ2eePlatform != null) {
699                 ((AppClientProject)project).unregisterJ2eePlatformListener(oldJ2eePlatform);
700             }
701         }
702         J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(newServInstID);
703         if (j2eePlatform == null) {
704             // probably missing server error
705
ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "J2EE platform is null."); // NOI18N
706

707             // update j2ee.server.type (throws NPE)
708
//projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID));
709
// update j2ee.server.instance
710
privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID);
711             
712             privateProps.remove(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH);
713             privateProps.remove(DEPLOY_ANT_PROPS_FILE);
714             privateProps.remove("wa.copy.client.jar.from"); // NOI18N
715
return;
716         }
717         ((AppClientProject)project).registerJ2eePlatformListener(j2eePlatform);
718         String JavaDoc classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries());
719         privateProps.setProperty(J2EE_PLATFORM_CLASSPATH, classpath);
720
721         // set j2ee.appclient environment
722
File JavaDoc[] accrt = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_APP_CLIENT_RUNTIME);
723         privateProps.setProperty(APPCLIENT_TOOL_RUNTIME, Utils.toClasspathString(accrt));
724         String JavaDoc jvmOpts = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_JVM_OPTS);
725         if (jvmOpts != null) {
726             privateProps.setProperty(APPCLIENT_TOOL_JVMOPTS, jvmOpts);
727         }
728         String JavaDoc acMain = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS);
729         if (acMain != null) {
730             privateProps.setProperty(APPCLIENT_TOOL_MAINCLASS, acMain);
731         }
732         String JavaDoc args = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2EE_PLATFORM_APPCLIENT_ARGS);
733         if (args != null) {
734             privateProps.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_ARGS, args);
735         }
736
737         String JavaDoc mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS_ARGS);
738         if (mainClassArgs != null && !mainClassArgs.equals("")) {
739             if (projectProps.getProperty(CLIENT_NAME) != null) {
740                 projectProps.remove(CLIENT_NAME);
741             }
742             projectProps.put(APPCLIENT_MAINCLASS_ARGS, mainClassArgs);
743         } else if ((mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, CLIENT_NAME)) != null) {
744             if (projectProps.getProperty(APPCLIENT_MAINCLASS_ARGS) != null) {
745                 projectProps.remove(APPCLIENT_MAINCLASS_ARGS);
746             }
747             projectProps.put(CLIENT_NAME, mainClassArgs);
748         }
749         
750         // update j2ee.platform.wscompile.classpath
751
if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) {
752             File JavaDoc[] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE);
753             privateProps.setProperty(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH,
754                     Utils.toClasspathString(wsClasspath));
755         } else {
756             privateProps.remove(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH);
757         }
758         
759         // update j2ee.server.type
760
projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID));
761         
762         // update j2ee.server.instance
763
privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID);
764         
765         // ant deployment support
766
File JavaDoc projectFolder = FileUtil.toFile(project.getProjectDirectory());
767         try {
768             AntDeploymentHelper.writeDeploymentScript(new File JavaDoc(projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.CLIENT, newServInstID); // NOI18N
769
} catch (IOException JavaDoc ioe) {
770             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
771         }
772         File JavaDoc antDeployPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(newServInstID);
773         if (antDeployPropsFile == null) {
774             privateProps.remove(DEPLOY_ANT_PROPS_FILE);
775         } else {
776             privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, antDeployPropsFile.getAbsolutePath());
777         }
778         
779         //WORKAROUND for --retrieve option in asadmin deploy command
780
//works only for local domains
781
//see also http://www.netbeans.org/issues/show_bug.cgi?id=82929
782
if ("J2EE".equals(Deployment.getDefault().getServerID(newServInstID))) { // NOI18N
783
File JavaDoc asRoot = j2eePlatform.getPlatformRoots()[0];
784             File JavaDoc exFile = new File JavaDoc(asRoot, "lib/javaee.jar"); // NOI18N
785
InstanceProperties ip = InstanceProperties.getInstanceProperties(newServInstID);
786             if (exFile.exists()) {
787                 privateProps.setProperty("wa.copy.client.jar.from", // NOI18N
788
new File JavaDoc(ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/generated/xml/j2ee-modules").getAbsolutePath()); // NOI18N
789
} else {
790                 privateProps.setProperty("wa.copy.client.jar.from", // NOI18N
791
new File JavaDoc(ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/applications/j2ee-modules").getAbsolutePath()); // NOI18N
792
}
793         } else {
794             privateProps.remove("wa.copy.client.jar.from"); // NOI18N
795
}
796         
797     }
798
799     public static final void getFilesForItem (ClassPathSupport.Item item, List JavaDoc<File JavaDoc> files, List JavaDoc<File JavaDoc> dirs) {
800         if (item.isBroken()) {
801             return ;
802         }
803         if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
804             @SuppressWarnings JavaDoc("unchecked")
805             List JavaDoc<URL JavaDoc> roots = item.getLibrary().getContent("classpath"); //NOI18N
806
for (Iterator JavaDoc it = roots.iterator(); it.hasNext();) {
807                 URL JavaDoc rootUrl = (URL JavaDoc) it.next();
808                 FileObject root = URLMapper.findFileObject (rootUrl);
809                 if ("jar".equals(rootUrl.getProtocol())) { //NOI18N
810
root = FileUtil.getArchiveFile (root);
811                 }
812                 File JavaDoc f = FileUtil.toFile(root);
813                 if (f != null) {
814                     if (f.isFile()) {
815                         files.add(f);
816                     } else {
817                         dirs.add(f);
818                     }
819                 }
820             }
821         }
822         if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
823             File JavaDoc root = item.getFile();
824             if (root != null) {
825                 if (root.isFile()) {
826                     files.add(root);
827                 } else {
828                     dirs.add(root);
829                 }
830             }
831         }
832         if (item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT) {
833             String JavaDoc artifactFolder = item.getArtifact().getScriptLocation().getParent();
834             URI JavaDoc roots[] = item.getArtifact().getArtifactLocations();
835             for (int i = 0; i < roots.length; i++) {
836                 String JavaDoc root = artifactFolder + File.separator + roots [i];
837                 if (root.endsWith(File.separator)) {
838                     dirs.add(new File JavaDoc (root));
839                 } else {
840                     files.add(new File JavaDoc (root));
841                 }
842             }
843         }
844     }
845     
846      /** Store locations of libraries in the classpath param that have more the one
847      * file into the properties in the following format:
848      *
849      * <ul>
850      * <li>libs.foo.classpath.libdir.1=C:/foo
851      * <li>libs.foo.classpath.libdirs=1
852      * <li>libs.foo.classpath.libfile.1=C:/bar/a.jar
853      * <li>libs.foo.classpath.libfile.2=C:/bar/b.jar
854      * <li>libs.foo.classpath.libfiles=1
855      * </ul>
856      * This is needed for the Ant copy task as it cannot copy more the one file
857      * and it needs different handling for files and directories.
858      * <br>
859      * It removes all properties that match this format that were in the {@link #properties}
860      * but are not in the {@link #classpath}.
861      */

862     public static void storeLibrariesLocations(Iterator JavaDoc<ClassPathSupport.Item> classpath, EditableProperties privateProps) {
863         List JavaDoc<String JavaDoc> exLibs = new ArrayList JavaDoc<String JavaDoc>();
864         Iterator JavaDoc propKeys = privateProps.keySet().iterator();
865         while (propKeys.hasNext()) {
866             String JavaDoc key = (String JavaDoc) propKeys.next();
867             if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || //NOI18N
868
(key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { //NOI18N
869
exLibs.add(key);
870             }
871         }
872         while (classpath.hasNext()) {
873             ClassPathSupport.Item item = (ClassPathSupport.Item)classpath.next();
874             List JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
875             List JavaDoc<File JavaDoc> dirs = new ArrayList JavaDoc<File JavaDoc>();
876             getFilesForItem (item, files, dirs);
877             String JavaDoc key;
878             if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) {
879                 String JavaDoc ref = item.getReference() == null ? item.getRaw() : item.getReference();
880                 for (int i = 0; i < files.size(); i++) {
881                     File JavaDoc f = (File JavaDoc) files.get(i);
882                     key = getAntPropertyName(ref)+".libfile." + (i+1); //NOI18N
883
privateProps.setProperty (key, "" + f.getAbsolutePath()); //NOI18N
884
exLibs.remove(key);
885                 }
886             }
887             if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) {
888                 String JavaDoc ref = item.getReference() == null ? item.getRaw() : item.getReference();
889                 for (int i = 0; i < dirs.size(); i++) {
890                     File JavaDoc f = (File JavaDoc) dirs.get(i);
891                     key = getAntPropertyName(ref)+".libdir." + (i+1); //NOI18N
892
privateProps.setProperty (key, "" + f.getAbsolutePath()); //NOI18N
893
exLibs.remove(key);
894                 }
895             }
896         }
897         Iterator JavaDoc unused = exLibs.iterator();
898         while (unused.hasNext()) {
899             privateProps.remove(unused.next());
900         }
901     }
902     
903     public static String JavaDoc getProperty(final String JavaDoc property, final AntProjectHelper helper, final String JavaDoc path) {
904         EditableProperties props = helper.getProperties(path);
905         return props.getProperty(property);
906     }
907     
908     
909     public static String JavaDoc getAntPropertyName( String JavaDoc property ) {
910         if ( property != null &&
911              property.startsWith( "${" ) && // NOI18N
912
property.endsWith( "}" ) ) { // NOI18N
913
return property.substring( 2, property.length() - 1 );
914         }
915         else {
916             return property;
917         }
918     }
919     
920 }
921
Popular Tags