KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > api > EjbJarProjectGenerator


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbjarproject.api;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.math.BigDecimal JavaDoc;
25 import java.util.Stack JavaDoc;
26 import org.netbeans.api.java.platform.JavaPlatform;
27 import org.netbeans.api.java.platform.JavaPlatformManager;
28 import org.netbeans.api.java.project.JavaProjectConstants;
29 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
31 import org.netbeans.modules.j2ee.ejbjarproject.*;
32 import org.netbeans.spi.project.support.ant.PropertyUtils;
33 import org.netbeans.spi.project.support.ant.ReferenceHelper;
34 import org.openide.ErrorManager;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileStateInvalidException;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.filesystems.Repository;
39 import org.netbeans.api.project.Project;
40 import org.netbeans.api.project.ProjectManager;
41 import org.netbeans.spi.project.support.ant.AntProjectHelper;
42 import org.netbeans.spi.project.support.ant.EditableProperties;
43 import org.netbeans.spi.project.support.ant.ProjectGenerator;
44 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
45 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
46 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
47 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
48 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
49 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.PlatformUiSupport;
50 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants;
51 import org.openide.modules.SpecificationVersion;
52 import org.openide.util.Mutex;
53 import org.openide.util.MutexException;
54 import org.openide.util.NbBundle;
55 import org.w3c.dom.Document JavaDoc;
56 import org.w3c.dom.Element JavaDoc;
57 import org.w3c.dom.NodeList JavaDoc;
58
59 /**
60  * Create a fresh EjbProject from scratch or by importing and exisitng ejb module
61  * in one of the recognized directory structures.
62  *
63  * @author Pavel Buzek
64  */

65 public class EjbJarProjectGenerator {
66     
67     private static final String JavaDoc DEFAULT_DOC_BASE_FOLDER = "conf"; //NOI18N
68
private static final String JavaDoc DEFAULT_SRC_FOLDER = "src"; //NOI18N
69
private static final String JavaDoc DEFAULT_TEST_FOLDER = "test"; //NOI18N
70
private static final String JavaDoc DEFAULT_RESOURCE_FOLDER = "setup"; //NOI18N
71
private static final String JavaDoc DEFAULT_JAVA_FOLDER = "java"; //NOI18N
72
private static final String JavaDoc DEFAULT_BUILD_DIR = "build"; //NOI18N
73

74     public static final String JavaDoc MINIMUM_ANT_VERSION = "1.6";
75     
76     private EjbJarProjectGenerator() {}
77
78     /**
79      * Create a new empty EjbJar project.
80      * @param dir the top-level directory (need not yet exist but if it does it must be empty)
81      * @param name the code name for the project
82      * @return the helper object permitting it to be further customized
83      * @throws IOException in case something went wrong
84      */

85     public static AntProjectHelper createProject(File JavaDoc dir, String JavaDoc name, String JavaDoc j2eeLevel, String JavaDoc serverInstanceID) throws IOException JavaDoc {
86         FileObject fo = createProjectDir(dir);
87
88         FileObject srcRoot = fo.createFolder(DEFAULT_SRC_FOLDER); // NOI18N
89
srcRoot.createFolder(DEFAULT_JAVA_FOLDER); //NOI18N
90
FileObject testRoot = fo.createFolder(DEFAULT_TEST_FOLDER);
91         FileObject confRoot = srcRoot.createFolder(DEFAULT_DOC_BASE_FOLDER); // NOI18N
92

93         //create a default manifest
94
FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-j2ee-ejbjarproject/MANIFEST.MF"), confRoot, "MANIFEST"); //NOI18N
95

96         AntProjectHelper h = setupProject (fo, name, "src", "test", null, null, null, j2eeLevel, serverInstanceID);
97         EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
98         ep.put (EjbJarProjectProperties.SOURCE_ROOT, DEFAULT_SRC_FOLDER); //NOI18N
99
ep.setProperty(EjbJarProjectProperties.META_INF, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_DOC_BASE_FOLDER); //NOI18N
100
ep.setProperty(EjbJarProjectProperties.SRC_DIR, "${"+EjbJarProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_JAVA_FOLDER); //NOI18N
101
ep.setProperty(EjbJarProjectProperties.META_INF_EXCLUDES, "sun-cmp-mappings.xml"); // NOI18N
102
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
103         
104         Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory ());
105         ProjectManager.getDefault().saveProject(p);
106
107         // create ejb-jar.xml
108
if (!J2eeModule.JAVA_EE_5.equals(j2eeLevel)) {
109             String JavaDoc resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-2.1.xml";
110             FileObject ddFile = FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource(resource), confRoot, "ejb-jar"); //NOI18N
111
EjbJar ejbJar = DDProvider.getDefault().getMergedDDRoot(
112                     org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(ddFile).getMetadataUnit());
113             ejbJar.setDisplayName(name);
114             ejbJar.write(ddFile);
115         }
116
117         return h;
118     }
119     
120     /**
121      * Import project from source or exploded archive
122      * @param dir root directory of project
123      * @param name name of the project
124      * @param sourceFolders Array of folders that hold the projects source
125      * or exploded archive
126      * @param testFolders folders that hold test code for the project
127      * @param configFilesBase Folder that holds the projects config files
128      * like deployment descriptors
129      * @param libFolder the libraries associated with the project
130      * @param j2eeLevel spec revision level
131      * @param serverInstanceID id of target server
132      * @param fromJavaSources flag whether the project is from source or
133      * exploded archive of class files
134      * @throws java.io.IOException if something goes wrong
135      * @return The AntProjectHelper for the project
136      */

137     public static AntProjectHelper importProject(final File JavaDoc dir, final String JavaDoc name,
138             final File JavaDoc[] sourceFolders, final File JavaDoc[] testFolders,
139             final File JavaDoc configFilesBase, final File JavaDoc libFolder, final String JavaDoc j2eeLevel,
140             String JavaDoc serverInstanceID, boolean fromJavaSources) throws IOException JavaDoc {
141         
142         AntProjectHelper retVal = importProject(dir,name,sourceFolders,testFolders,
143                 configFilesBase,libFolder,j2eeLevel,serverInstanceID);
144         EditableProperties subEp = retVal.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
145         subEp.setProperty(EjbJarProjectProperties.JAVA_SOURCE_BASED,fromJavaSources+""); // NOI18N
146
retVal.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,subEp);
147         Project subP = ProjectManager.getDefault().findProject(retVal.getProjectDirectory());
148         ProjectManager.getDefault().saveProject(subP);
149         return retVal;
150     }
151     
152    public static AntProjectHelper importProject(final File JavaDoc dir, final String JavaDoc name,
153             final File JavaDoc[] sourceFolders, final File JavaDoc[] testFolders,
154             final File JavaDoc configFilesBase, final File JavaDoc libFolder, final String JavaDoc j2eeLevel, String JavaDoc serverInstanceID) throws IOException JavaDoc {
155         assert sourceFolders != null && testFolders != null: "Package roots can't be null"; //NOI18N
156
final FileObject dirFO = createProjectDir (dir);
157         // this constructor creates only java application type
158
final AntProjectHelper h = setupProject(dirFO, name, null, null,
159                 configFilesBase, (libFolder == null ? null : libFolder), null, j2eeLevel, serverInstanceID);
160         final EjbJarProject p = (EjbJarProject) ProjectManager.getDefault().findProject(dirFO);
161         final ReferenceHelper refHelper = p.getReferenceHelper();
162         try {
163         ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction () {
164             public Object JavaDoc run() throws Exception JavaDoc {
165                 Element JavaDoc data = h.getPrimaryConfigurationData(true);
166                 Document JavaDoc doc = data.getOwnerDocument();
167                 NodeList JavaDoc nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots");
168                 assert nl.getLength() == 1;
169                 Element JavaDoc sourceRoots = (Element JavaDoc) nl.item(0);
170                 nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N
171
assert nl.getLength() == 1;
172                 Element JavaDoc testRoots = (Element JavaDoc) nl.item(0);
173                 for (int i=0; i<sourceFolders.length; i++) {
174                     String JavaDoc propName = "src.dir" + (i == 0 ? "" : Integer.toString (i+1)); //NOI18N
175
String JavaDoc srcReference = refHelper.createForeignFileReference(sourceFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA);
176                     Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
177
root.setAttribute ("id",propName); //NOI18N
178
sourceRoots.appendChild(root);
179                     EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
180                     props.put(propName,srcReference);
181                     h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); // #47609
182
}
183
184                 if (testFolders.length == 0) {
185                     String JavaDoc testLoc = NbBundle.getMessage (EjbJarProjectGenerator.class,"TXT_DefaultTestFolderName");
186                     File JavaDoc f = new File JavaDoc (dir,testLoc);
187                     f.mkdirs();
188                     String JavaDoc propName = "test.src.dir";
189                     Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
190
root.setAttribute ("id",propName); //NOI18N
191
root.setAttribute ("name",NbBundle.getMessage(EjbJarProjectGenerator.class, "NAME_test.src.dir"));
192                     testRoots.appendChild(root);
193                     EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
194                     props.put(propName,testLoc);
195                     h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); // #47609
196
}
197                 else {
198                     for (int i=0; i<testFolders.length; i++) {
199                         if (!testFolders[i].exists()) {
200                             testFolders[i].mkdirs();
201                         }
202                         String JavaDoc propName = "test.src.dir" + (i == 0 ? "" : Integer.toString (i+1)); //NOI18N
203
String JavaDoc testReference = refHelper.createForeignFileReference(testFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA);
204                         Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
205
root.setAttribute ("id",propName); //NOI18N
206
testRoots.appendChild(root);
207                         EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); // #47609
208
props.put(propName,testReference);
209                         h.putProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
210                     }
211                 }
212                 h.putPrimaryConfigurationData(data,true);
213                 ProjectManager.getDefault().saveProject (p);
214                 return null;
215             }
216         });
217         } catch (MutexException me ) {
218             ErrorManager.getDefault().notify (me);
219         }
220         // AB: fix for #53170: if j2eeLevel is 1.4 and ejb-jar.xml is version 2.0, we upgrade it to version 2.1
221
FileObject ejbJarXml = FileUtil.toFileObject(configFilesBase).getFileObject("ejb-jar.xml"); // NOI18N
222
if (ejbJarXml != null) {
223             try {
224                 EjbJar root = DDProvider.getDefault().getMergedDDRoot(
225                         org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(ejbJarXml).getMetadataUnit());
226                 boolean writeDD = false;
227                 if (new BigDecimal JavaDoc(EjbJar.VERSION_2_0).equals(root.getVersion()) && j2eeLevel.equals(EjbJarProjectProperties.J2EE_1_4)) { // NOI18N
228
root.setVersion(new BigDecimal JavaDoc(EjbJar.VERSION_2_1));
229                     writeDD = true;
230                 }
231                 // also set the display name if not set (#55733)
232
String JavaDoc dispName = root.getDefaultDisplayName();
233                 if (null == dispName || dispName.trim().length() == 0) {
234                     root.setDisplayName(name);
235                     writeDD = true;
236                 }
237                 if (writeDD)
238                     root.write(ejbJarXml);
239             }
240             catch (IOException JavaDoc e) {
241                 ErrorManager.getDefault().notify(e);
242             }
243         }
244         return h;
245     }
246
247     private static String JavaDoc createFileReference(ReferenceHelper refHelper, FileObject projectFO, FileObject referencedFO) {
248         if (FileUtil.isParentOf(projectFO, referencedFO)) {
249             return relativePath(projectFO, referencedFO);
250         } else {
251             return refHelper.createForeignFileReference(FileUtil.toFile(referencedFO), null);
252         }
253     }
254     
255     private static String JavaDoc relativePath (FileObject parent, FileObject child) {
256         if (child.equals (parent))
257             return "";
258         if (!FileUtil.isParentOf (parent, child))
259             throw new IllegalArgumentException JavaDoc ("Cannot find relative path, " + parent + " is not parent of " + child);
260         return child.getPath ().substring (parent.getPath ().length () + 1);
261     }
262     
263     private static AntProjectHelper setupProject (FileObject dirFO, String JavaDoc name,
264             String JavaDoc srcRoot, String JavaDoc testRoot, File JavaDoc configFiles, File JavaDoc libraries, String JavaDoc resources,
265             String JavaDoc j2eeLevel, String JavaDoc serverInstanceID) throws IOException JavaDoc {
266         AntProjectHelper h = ProjectGenerator.createProject(dirFO, EjbJarProjectType.TYPE);
267         final EjbJarProject prj = (EjbJarProject) ProjectManager.getDefault().findProject(h.getProjectDirectory());
268         final ReferenceHelper referenceHelper = prj.getReferenceHelper();
269         Element JavaDoc data = h.getPrimaryConfigurationData(true);
270         Document JavaDoc doc = data.getOwnerDocument();
271         Element JavaDoc nameEl = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
272
nameEl.appendChild(doc.createTextNode(name));
273         data.appendChild(nameEl);
274         Element JavaDoc minant = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "minimum-ant-version"); // NOI18N
275
minant.appendChild(doc.createTextNode(MINIMUM_ANT_VERSION));
276         data.appendChild(minant);
277
278         // TODO: ma154696: not sure if needed
279
// Element addLibs = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "ejb-module-additional-libraries"); //NOI18N
280
// data.appendChild(addLibs);
281

282         EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
283         Element JavaDoc sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N
284
if (srcRoot != null) {
285             Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
286
root.setAttribute ("id","src.dir"); //NOI18N
287
root.setAttribute ("name",NbBundle.getMessage(EjbJarProjectGenerator.class, "NAME_src.dir"));
288             sourceRoots.appendChild(root);
289             ep.setProperty("src.dir", srcRoot); // NOI18N
290
}
291         data.appendChild (sourceRoots);
292         Element JavaDoc testRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N
293
if (testRoot != null) {
294             Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
295
root.setAttribute ("id","test.src.dir"); //NOI18N
296
root.setAttribute ("name",NbBundle.getMessage(EjbJarProjectGenerator.class, "NAME_test.src.dir"));
297             testRoots.appendChild (root);
298             ep.setProperty("test.src.dir", testRoot); // NOI18N
299
}
300         data.appendChild (testRoots);
301         h.putPrimaryConfigurationData(data, true);
302         
303         if (resources != null) {
304             ep.setProperty(EjbJarProjectProperties.RESOURCE_DIR, resources);
305         } else {
306             ep.setProperty(EjbJarProjectProperties.RESOURCE_DIR, DEFAULT_RESOURCE_FOLDER);
307         }
308         
309         JavaPlatform defaultPlatform = JavaPlatformManager.getDefault().getDefaultPlatform();
310         SpecificationVersion v = defaultPlatform.getSpecification().getVersion();
311         String JavaDoc sourceLevel = v.toString();
312         // #89131: these levels are not actually distinct from 1.5.
313
if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7"))
314             sourceLevel = "1.5";
315         ep.setProperty(EjbJarProjectProperties.JAVAC_SOURCE, sourceLevel); //NOI18N
316
ep.setProperty(EjbJarProjectProperties.JAVAC_TARGET, sourceLevel); //NOI18N
317

318         ep.setProperty(EjbJarProjectProperties.JAVAC_CLASSPATH, "");
319         
320         ep.setProperty(EjbJarProjectProperties.DIST_DIR, "dist");
321         ep.setProperty(EjbJarProjectProperties.DIST_JAR, "${"+EjbJarProjectProperties.DIST_DIR+"}/" + "${" + EjbJarProjectProperties.JAR_NAME + "}");
322         //XXX the name of the dist.ear.jar file should be different, but now it cannot be since the name is used as a key in module provider mapping
323
ep.setProperty(EjbJarProjectProperties.DIST_EAR_JAR, "${"+EjbJarProjectProperties.DIST_DIR+"}/" + "${" + EjbJarProjectProperties.JAR_NAME + "}");
324         ep.setProperty(EjbJarProjectProperties.J2EE_PLATFORM, j2eeLevel);
325         ep.setProperty(EjbJarProjectProperties.JAR_NAME, PropertyUtils.getUsablePropertyName(name) + ".jar");
326         ep.setProperty(EjbJarProjectProperties.JAR_COMPRESS, "false");
327 // ep.setProperty(EjbJarProjectProperties.JAR_CONTENT_ADDITIONAL, "");
328

329         Deployment deployment = Deployment.getDefault ();
330         ep.setProperty(EjbJarProjectProperties.J2EE_SERVER_TYPE, deployment.getServerID (serverInstanceID));
331         ep.setProperty(EjbJarProjectProperties.JAVAC_DEBUG, "true");
332         ep.setProperty(EjbJarProjectProperties.JAVAC_DEPRECATION, "false");
333         
334         ep.setProperty(EjbJarProjectProperties.JAVAC_TEST_CLASSPATH, new String JavaDoc[] {
335             "${javac.classpath}:", // NOI18N
336
"${build.classes.dir}:", // NOI18N
337
"${libs.junit.classpath}", // NOI18N
338
});
339         ep.setProperty(EjbJarProjectProperties.RUN_TEST_CLASSPATH, new String JavaDoc[] {
340             "${javac.test.classpath}:", // NOI18N
341
"${build.test.classes.dir}", // NOI18N
342
});
343         ep.setProperty(EjbJarProjectProperties.DEBUG_TEST_CLASSPATH, new String JavaDoc[] {
344             "${run.test.classpath}", // NOI18N
345
});
346         
347         ep.setProperty(EjbJarProjectProperties.BUILD_DIR, DEFAULT_BUILD_DIR);
348         ep.setProperty(EjbJarProjectProperties.BUILD_TEST_CLASSES_DIR, "${build.dir}/test/classes"); // NOI18N
349
ep.setProperty(EjbJarProjectProperties.BUILD_TEST_RESULTS_DIR, "${build.dir}/test/results"); // NOI18N
350
ep.setProperty(EjbJarProjectProperties.BUILD_GENERATED_DIR, "${"+EjbJarProjectProperties.BUILD_DIR+"}/generated");
351         ep.setProperty(EjbJarProjectProperties.BUILD_CLASSES_DIR, "${"+EjbJarProjectProperties.BUILD_DIR+"}/jar");
352         ep.setProperty(EjbJarProjectProperties.BUILD_EAR_CLASSES_DIR, "${"+EjbJarProjectProperties.BUILD_DIR+"}/ear-module");
353         ep.setProperty(EjbJarProjectProperties.BUILD_CLASSES_EXCLUDES, "**/*.java,**/*.form,**/.nbattrs");
354         ep.setProperty(EjbJarProjectProperties.DIST_JAVADOC_DIR, "${"+EjbJarProjectProperties.DIST_DIR+"}/javadoc");
355         ep.setProperty(EjbJarProjectProperties.JAVA_PLATFORM, "default_platform");
356         ep.setProperty(EjbJarProjectProperties.DEBUG_CLASSPATH, "${"+EjbJarProjectProperties.JAVAC_CLASSPATH+"}:${"+EjbJarProjectProperties.BUILD_CLASSES_DIR+"}");
357         ep.setProperty(EjbJarProjectProperties.JAVADOC_PRIVATE, "false"); // NOI18N
358
ep.setProperty(EjbJarProjectProperties.JAVADOC_NO_TREE, "false"); // NOI18N
359
ep.setProperty(EjbJarProjectProperties.JAVADOC_USE, "true"); // NOI18N
360
ep.setProperty(EjbJarProjectProperties.JAVADOC_NO_NAVBAR, "false"); // NOI18N
361
ep.setProperty(EjbJarProjectProperties.JAVADOC_NO_INDEX, "false"); // NOI18N
362
ep.setProperty(EjbJarProjectProperties.JAVADOC_SPLIT_INDEX, "true"); // NOI18N
363
ep.setProperty(EjbJarProjectProperties.JAVADOC_AUTHOR, "false"); // NOI18N
364
ep.setProperty(EjbJarProjectProperties.JAVADOC_VERSION, "false"); // NOI18N
365
ep.setProperty(EjbJarProjectProperties.JAVADOC_WINDOW_TITLE, ""); // NOI18N
366
ep.setProperty(EjbJarProjectProperties.JAVADOC_ENCODING, ""); // NOI18N
367
ep.setProperty(EjbJarProjectProperties.JAVADOC_PREVIEW, "true"); // NOI18N
368
ep.setProperty(EjbJarProjectProperties.JAVADOC_ADDITIONALPARAM, ""); // NOI18N
369

370         h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
371         
372         if (configFiles != null) {
373             String JavaDoc ref = createFileReference(referenceHelper, dirFO, FileUtil.toFileObject(configFiles));
374             EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
375             props.setProperty(EjbJarProjectProperties.META_INF, ref);
376             h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
377         }
378         if (libraries != null) {
379             String JavaDoc ref = createFileReference(referenceHelper, dirFO, FileUtil.toFileObject(libraries));
380             EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
381             props.setProperty(EjbJarProjectProperties.LIBRARIES_DIR, ref);
382             h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
383         }
384         
385         ep = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
386         ep.setProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE, serverInstanceID);
387         
388         // set j2ee.platform.classpath
389
J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
390         if (!j2eePlatform.getSupportedSpecVersions(J2eeModule.EJB).contains(j2eeLevel)) {
391             ErrorManager.getDefault().log(ErrorManager.WARNING, "J2EE level:" + j2eeLevel + " not supported by server " + Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID) + " for module type EJB");
392         }
393         String JavaDoc classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries());
394         ep.setProperty(EjbJarProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath);
395         
396         // set j2ee.platform.wscompile.classpath
397
if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) {
398             File JavaDoc[] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE);
399             ep.setProperty(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH,
400                     Utils.toClasspathString(wsClasspath));
401         }
402         
403         // ant deployment support
404
File JavaDoc projectFolder = FileUtil.toFile(dirFO);
405         try {
406             AntDeploymentHelper.writeDeploymentScript(new File JavaDoc(projectFolder, EjbJarProjectProperties.ANT_DEPLOY_BUILD_SCRIPT),
407                     J2eeModule.EJB, serverInstanceID);
408         } catch (IOException JavaDoc ioe) {
409             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
410         }
411         File JavaDoc deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID);
412         if (deployAntPropsFile != null) {
413             ep.setProperty(EjbJarProjectProperties.DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath());
414         }
415         
416         h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
417         Project p = ProjectManager.getDefault().findProject(dirFO);
418         ProjectManager.getDefault().saveProject(p);
419         return h;
420     }
421
422     private static FileObject createProjectDir (File JavaDoc dir) throws IOException JavaDoc {
423         Stack JavaDoc stack = new Stack JavaDoc ();
424         while (!dir.exists()) {
425             stack.push (dir.getName());
426             dir = dir.getParentFile();
427         }
428         FileObject dirFO = FileUtil.toFileObject (dir);
429         if (dirFO == null) {
430             refreshFileSystem(dir);
431             dirFO = FileUtil.toFileObject (dir);
432         }
433         assert dirFO != null;
434         while (!stack.isEmpty()) {
435             dirFO = dirFO.createFolder((String JavaDoc)stack.pop());
436         }
437         return dirFO;
438     }
439
440     private static void refreshFileSystem (final File JavaDoc dir) throws FileStateInvalidException {
441         File JavaDoc rootF = dir;
442         while (rootF.getParentFile() != null) {
443             rootF = rootF.getParentFile();
444         }
445         FileObject dirFO = FileUtil.toFileObject(rootF);
446         assert dirFO != null : "At least disk roots must be mounted! " + rootF; // NOI18N
447
dirFO.getFileSystem().refresh(false);
448     }
449
450     // AB: this method is also called from the enterprise application, so we can't pass UpdateHelper here
451
// well, actually we can, but let's not expose too many classes
452
public static void setPlatform(final AntProjectHelper helper, final String JavaDoc platformName, final String JavaDoc sourceLevel) {
453         ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
454             public void run() {
455                 try {
456                     EjbJarProject project = (EjbJarProject)ProjectManager.getDefault().findProject(helper.getProjectDirectory());
457                     UpdateHelper updateHelper = project.getUpdateHelper();
458                     EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
459                     String JavaDoc finalPlatformName = platformName;
460                     if (finalPlatformName == null)
461                         finalPlatformName = JavaPlatformManager.getDefault().getDefaultPlatform().getDisplayName();
462                     
463                     // #89131: these levels are not actually distinct from 1.5.
464
String JavaDoc srcLevel = sourceLevel;
465                     if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7"))
466                         srcLevel = "1.5";
467                     PlatformUiSupport.storePlatform(ep, updateHelper, finalPlatformName, srcLevel != null ? new SpecificationVersion(srcLevel) : null);
468                     helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
469                     ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(helper.getProjectDirectory()));
470                 }
471                 catch (IOException JavaDoc e) {
472                     ErrorManager.getDefault().notify(e);
473                 }
474             }
475         });
476     }
477 }
478
Popular Tags