1 19 20 package org.netbeans.modules.web.project.api; 21 22 import org.netbeans.api.java.project.JavaProjectConstants; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 26 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 27 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 28 import org.netbeans.modules.web.api.webmodule.WebModule; 29 import org.netbeans.modules.web.project.*; 30 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; 31 import org.netbeans.spi.project.support.ant.AntProjectHelper; 32 import org.netbeans.spi.project.support.ant.EditableProperties; 33 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 34 import org.netbeans.spi.project.support.ant.ProjectGenerator; 35 import org.netbeans.spi.project.support.ant.PropertyUtils; 36 import org.netbeans.spi.project.support.ant.ReferenceHelper; 37 import org.openide.ErrorManager; 38 import org.openide.filesystems.FileObject; 39 import org.openide.filesystems.FileSystem; 40 import org.openide.filesystems.FileUtil; 41 import org.openide.filesystems.FileLock; 42 import org.openide.filesystems.Repository; 43 import org.openide.loaders.DataFolder; 44 import org.openide.loaders.DataObject; 45 import org.openide.util.Mutex; 46 import org.openide.util.MutexException; 47 import org.openide.util.NbBundle; 48 import org.w3c.dom.Document ; 49 import org.w3c.dom.Element ; 50 51 import java.io.*; 52 import java.util.Enumeration ; 53 import java.util.LinkedList ; 54 import java.util.List ; 55 56 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 57 import org.netbeans.modules.web.project.classpath.ClassPathSupport; 58 import org.netbeans.modules.web.project.classpath.WebProjectClassPathExtender; 59 import org.netbeans.modules.web.project.ui.customizer.PlatformUiSupport; 60 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 61 import org.openide.modules.SpecificationVersion; 62 import org.w3c.dom.NodeList ; 63 64 import org.netbeans.modules.web.project.ui.wizards.FileSearchUtility; 65 66 72 public class WebProjectUtilities { 73 74 77 public static final String SRC_STRUCT_BLUEPRINTS = "BluePrints"; 79 82 public static final String SRC_STRUCT_JAKARTA = "Jakarta"; 84 private static final String DEFAULT_DOC_BASE_FOLDER = "web"; private static final String DEFAULT_SRC_FOLDER = "src"; private static final String DEFAULT_RESOURCE_FOLDER = "setup"; private static final String DEFAULT_JAVA_FOLDER = "java"; private static final String DEFAULT_CONF_FOLDER = "conf"; private static final String DEFAULT_BUILD_DIR = "build"; 91 private static final String DEFAULT_TEST_FOLDER = "test"; 93 private static final String WEB_INF = "WEB-INF"; private static final String SOURCE_ROOT_REF = "${" + WebProjectProperties.SOURCE_ROOT + "}"; 96 public static final String MINIMUM_ANT_VERSION = "1.6"; 97 98 private WebProjectUtilities() {} 99 100 108 @Deprecated 109 public static AntProjectHelper createProject(File dir, String name, String serverInstanceID, String sourceStructure, String j2eeLevel, String contextPath) 110 throws IOException { 111 WebProjectCreateData createData = new WebProjectCreateData(); 112 createData.setProjectDir(dir); 113 createData.setName(name); 114 createData.setServerInstanceID(serverInstanceID); 115 createData.setSourceStructure(sourceStructure); 116 createData.setJavaEEVersion(j2eeLevel); 117 createData.setContextPath(contextPath); 118 return createProject(createData); 119 } 120 121 127 public static AntProjectHelper createProject(final WebProjectCreateData createData) throws IOException { 128 File dir = createData.getProjectDir(); 129 String name = createData.getName(); 130 String serverInstanceID = createData.getServerInstanceID(); 131 String sourceStructure = createData.getSourceStructure(); 132 String j2eeLevel = createData.getJavaEEVersion(); 133 String contextPath = createData.getContextPath(); 134 String javaPlatformName = createData.getJavaPlatformName(); 135 String sourceLevel = createData.getSourceLevel(); 136 137 assert dir != null: "Project folder can't be null"; assert name != null: "Project name can't be null"; assert serverInstanceID != null: "Server instance ID can't be null"; assert sourceStructure != null: "Source structure can't be null"; assert j2eeLevel != null: "Java EE version can't be null"; 143 final boolean createBluePrintsStruct = SRC_STRUCT_BLUEPRINTS.equals(sourceStructure); 144 final boolean createJakartaStructure = SRC_STRUCT_JAKARTA.equals(sourceStructure); 145 146 final FileObject fo = Utils.getValidEmptyDir(dir); 147 AntProjectHelper h = setupProject (fo, name, serverInstanceID, j2eeLevel); 148 149 FileObject srcFO = fo.createFolder(DEFAULT_SRC_FOLDER); 150 FileObject confFolderFO = null; 151 152 if (createBluePrintsStruct) { 153 srcFO.createFolder(DEFAULT_JAVA_FOLDER); 154 confFolderFO = srcFO.createFolder(DEFAULT_CONF_FOLDER); 155 } 156 157 if(createJakartaStructure) { 158 confFolderFO = fo.createFolder(DEFAULT_CONF_FOLDER); 159 } 160 161 if(confFolderFO != null) { 163 FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/MANIFEST.MF"), confFolderFO, "MANIFEST"); } 165 166 FileUtil.createFolder(fo, DEFAULT_TEST_FOLDER); 168 169 FileObject webFO = fo.createFolder(DEFAULT_DOC_BASE_FOLDER); 170 final FileObject webInfFO = webFO.createFolder(WEB_INF); 171 String webXMLContent = null; 174 if (J2eeModule.JAVA_EE_5.equals(j2eeLevel)) 175 webXMLContent = readResource (Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/web-2.5.xml").getInputStream ()); else if (WebModule.J2EE_14_LEVEL.equals(j2eeLevel)) 177 webXMLContent = readResource (Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/web-2.4.xml").getInputStream ()); else if (WebModule.J2EE_13_LEVEL.equals(j2eeLevel)) 179 webXMLContent = readResource (Repository.getDefault().getDefaultFileSystem().findResource("org-netbeans-modules-web-project/web-2.3.xml").getInputStream ()); assert webXMLContent != null : "Cannot find web.xml template for J2EE specification level:" + j2eeLevel; 181 final String webXmlText = webXMLContent; 182 FileSystem fs = webInfFO.getFileSystem(); 183 fs.runAtomicAction(new FileSystem.AtomicAction() { 184 public void run() throws IOException { 185 FileObject webXML = FileUtil.createData(webInfFO, "web.xml"); FileLock lock = webXML.lock(); 187 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(webXML.getOutputStream(lock))); 188 try { 189 bw.write(webXmlText); 190 } 191 finally { 192 bw.close(); 193 lock.releaseLock(); 194 } 195 } 196 }); 197 198 EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 199 Element data = h.getPrimaryConfigurationData(true); 200 Document doc = data.getOwnerDocument(); 201 Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); 203 Element rootSrc = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); rootSrc.setAttribute ("id",WebProjectProperties.SRC_DIR); rootSrc.setAttribute ("name",NbBundle.getMessage(WebProjectUtilities.class, "NAME_src.dir")); sourceRoots.appendChild(rootSrc); 207 if (createBluePrintsStruct) 208 ep.setProperty(WebProjectProperties.SRC_DIR, DEFAULT_SRC_FOLDER + "/" + DEFAULT_JAVA_FOLDER); else 210 ep.setProperty(WebProjectProperties.SRC_DIR, DEFAULT_SRC_FOLDER); 212 data.appendChild (sourceRoots); 213 Element testRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); 215 Element rootTest = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); rootTest.setAttribute ("id",WebProjectProperties.TEST_SRC_DIR); rootTest.setAttribute ("name",NbBundle.getMessage(WebProjectUtilities.class, "NAME_test.src.dir")); testRoots.appendChild (rootTest); 219 ep.setProperty(WebProjectProperties.TEST_SRC_DIR, DEFAULT_TEST_FOLDER); 221 data.appendChild (testRoots); 222 h.putPrimaryConfigurationData(data, true); 223 224 ep.put (WebProjectProperties.SOURCE_ROOT, createBluePrintsStruct ? DEFAULT_SRC_FOLDER : "."); 226 ep.setProperty(WebProjectProperties.WEB_DOCBASE_DIR, DEFAULT_DOC_BASE_FOLDER); 227 if (createBluePrintsStruct) { 228 ep.setProperty(WebProjectProperties.SRC_DIR, "${" + WebProjectProperties.SOURCE_ROOT + "}/" + DEFAULT_JAVA_FOLDER); 229 ep.setProperty(WebProjectProperties.CONF_DIR, "${" + WebProjectProperties.SOURCE_ROOT + "}/" + DEFAULT_CONF_FOLDER); 230 } else { 231 ep.setProperty(WebProjectProperties.SRC_DIR, DEFAULT_SRC_FOLDER); 232 } 233 234 if(createJakartaStructure) { 235 ep.setProperty(WebProjectProperties.CONF_DIR, DEFAULT_CONF_FOLDER); 236 } 237 238 ep.setProperty(WebProjectProperties.RESOURCE_DIR, DEFAULT_RESOURCE_FOLDER); 239 ep.setProperty(WebProjectProperties.LIBRARIES_DIR, "${" + WebProjectProperties.WEB_DOCBASE_DIR + "}/WEB-INF/lib"); 241 Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory ()); 242 UpdateHelper updateHelper = ((WebProject) p).getUpdateHelper(); 243 244 if (sourceLevel != null && (sourceLevel.equals("1.6") || sourceLevel.equals("1.7"))) 246 sourceLevel = "1.5"; 247 PlatformUiSupport.storePlatform(ep, updateHelper, javaPlatformName, sourceLevel != null ? new SpecificationVersion(sourceLevel) : null); 248 249 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 250 251 ProjectManager.getDefault().saveProject(p); 252 253 createIndexJSP(webFO); 255 256 ProjectWebModule pwm = (ProjectWebModule) p.getLookup ().lookup (ProjectWebModule.class); 257 if (pwm != null) pwm.setContextPath(contextPath); 259 260 return h; 261 } 262 263 271 @Deprecated 272 public static AntProjectHelper importProject(File dir, String name, FileObject wmFO, FileObject javaRoot, FileObject docBase, FileObject libFolder, String j2eeLevel, String serverInstanceID, String buildfile) throws IOException { 273 WebProjectCreateData createData = new WebProjectCreateData(); 274 createData.setProjectDir(dir); 275 createData.setName(name); 276 createData.setWebModuleFO(wmFO); 277 createData.setSourceFolders(new File[] {FileUtil.toFile(javaRoot)}); 278 createData.setTestFolders(null); 279 createData.setDocBase(docBase); 280 createData.setLibFolder(libFolder); 281 createData.setJavaEEVersion(j2eeLevel); 282 createData.setServerInstanceID(serverInstanceID); 283 createData.setBuildfile(buildfile); 284 return importProject(createData); 285 } 286 287 295 @Deprecated 296 public static AntProjectHelper importProject(final File dir, String name, FileObject wmFO, final File[] sourceFolders, File[] tstFolders, FileObject docBase, FileObject libFolder, String j2eeLevel, String serverInstanceID, String buildfile) throws IOException { 297 WebProjectCreateData createData = new WebProjectCreateData(); 298 createData.setProjectDir(dir); 299 createData.setName(name); 300 createData.setWebModuleFO(wmFO); 301 createData.setSourceFolders(sourceFolders); 302 createData.setTestFolders(tstFolders); 303 createData.setDocBase(docBase); 304 createData.setLibFolder(libFolder); 305 createData.setJavaEEVersion(j2eeLevel); 306 createData.setServerInstanceID(serverInstanceID); 307 createData.setBuildfile(buildfile); 308 return importProject(createData); 309 } 310 311 317 public static AntProjectHelper importProject(final WebProjectCreateData createData) throws IOException { 318 final File dir = createData.getProjectDir(); 319 String name = createData.getName(); 320 FileObject wmFO = createData.getWebModuleFO(); 321 final File[] sourceFolders = createData.getSourceFolders(); 322 File[] tstFolders = createData.getTestFolders(); 323 FileObject docBase = createData.getDocBase(); 324 FileObject libFolder = createData.getLibFolder(); 325 String j2eeLevel = createData.getJavaEEVersion(); 326 String serverInstanceID = createData.getServerInstanceID(); 327 String buildfile = createData.getBuildfile(); 328 String javaPlatformName = createData.getJavaPlatformName(); 329 String sourceLevel = createData.getSourceLevel(); 330 boolean javaSourceBased = createData.getJavaSourceBased(); 331 332 assert dir != null: "Project folder can't be null"; assert name != null: "Project name can't be null"; assert wmFO != null: "File object representation of the imported web project location can't be null"; assert sourceFolders != null: "Source package root can't be null"; assert docBase != null: "Web Pages folder can't be null"; assert serverInstanceID != null: "Server instance ID can't be null"; assert j2eeLevel != null: "Java EE version can't be null"; 340 FileObject fo = Utils.getValidDir(dir); 341 342 final AntProjectHelper antProjectHelper = setupProject(fo, name, serverInstanceID, j2eeLevel); 343 final WebProject p = (WebProject) ProjectManager.getDefault().findProject(antProjectHelper.getProjectDirectory()); 344 final ReferenceHelper referenceHelper = p.getReferenceHelper(); 345 EditableProperties ep = new EditableProperties(true); 346 347 if (FileUtil.isParentOf(fo, wmFO) || fo.equals(wmFO)) { 348 ep.setProperty(WebProjectProperties.SOURCE_ROOT, "."); } else { 350 ep.setProperty(WebProjectProperties.SOURCE_ROOT, 351 referenceHelper.createForeignFileReference(FileUtil.toFile(wmFO), null)); 352 } 353 ep.setProperty(WebProjectProperties.WEB_DOCBASE_DIR, createFileReference(referenceHelper, fo, wmFO, docBase)); 354 355 final File[] testFolders = tstFolders; 356 try { 357 ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction () { 358 public Object run() throws Exception { 359 Element data = antProjectHelper.getPrimaryConfigurationData(true); 360 Document doc = data.getOwnerDocument(); 361 362 Element sourceRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); data.appendChild (sourceRoots); 364 Element testRoots = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); data.appendChild (testRoots); 366 367 NodeList nl = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); 368 assert nl.getLength() == 1; 369 sourceRoots = (Element ) nl.item(0); 370 nl = data.getElementsByTagNameNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); assert nl.getLength() == 1; 372 testRoots = (Element ) nl.item(0); 373 for (int i=0; i<sourceFolders.length; i++) { 374 String propName = "src.dir" + (i == 0 ? "" : Integer.toString (i+1)); String srcReference = referenceHelper.createForeignFileReference(sourceFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA); 376 Element root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute ("id",propName); root.setAttribute ("name",NbBundle.getMessage(WebProjectUtilities.class, "NAME_src.dir")); sourceRoots.appendChild(root); 380 EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 381 props.put(propName,srcReference); 382 antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } 384 385 if (testFolders == null || testFolders.length == 0) { 386 EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 387 props.put("test.src.dir", ""); 388 antProjectHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } 390 else { 391 for (int i=0; i<testFolders.length; i++) { 392 if (!testFolders[i].exists()) { 393 testFolders[i].mkdirs(); 394 } 395 396 String name = testFolders[i].getName(); 397 String propName = "test." + name + ".dir"; int rootIndex = 1; 399 EditableProperties props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 400 while (props.containsKey(propName)) { 401 rootIndex++; 402 propName = "test." + name + rootIndex + ".dir"; } 404 String testReference = referenceHelper.createForeignFileReference(testFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA); 405 Element root = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute ("id",propName); root.setAttribute ("name",NbBundle.getMessage(WebProjectUtilities.class, "NAME_test.src.dir")); testRoots.appendChild(root); 409 props = antProjectHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); props.put(propName,testReference); 411 antProjectHelper.putProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 412 } 413 } 414 antProjectHelper.putPrimaryConfigurationData(data,true); 415 ProjectManager.getDefault().saveProject (p); 416 return null; 417 } 418 }); 419 } catch (MutexException me ) { 420 ErrorManager.getDefault().notify (me); 421 } 422 423 if (libFolder != null) { 424 ep.setProperty(WebProjectProperties.LIBRARIES_DIR, createFileReference(referenceHelper, fo, wmFO, libFolder)); 425 426 if (libFolder.isFolder()) { 428 FileObject children [] = libFolder.getChildren (); 429 List libs = new LinkedList (); 430 for (int i = 0; i < children.length; i++) { 431 if (FileUtil.isArchiveFile(children[i])) 432 libs.add(children[i]); 433 } 434 FileObject[] libsArray = new FileObject[libs.size()]; 435 libs.toArray(libsArray); 436 WebProjectClassPathExtender classPathExtender = (WebProjectClassPathExtender) p.getLookup().lookup(WebProjectClassPathExtender.class); 437 classPathExtender.addArchiveFiles(WebProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupport.TAG_WEB_MODULE_LIBRARIES); 438 } 441 } 442 443 if (!GeneratedFilesHelper.BUILD_XML_PATH.equals(buildfile)) { 444 ep.setProperty(WebProjectProperties.BUILD_FILE, buildfile); 445 } 446 447 Enumeration ch = FileSearchUtility.getChildrenToDepth(fo, 4, true); 450 String confDir = ""; while (ch.hasMoreElements ()) { 452 FileObject f = (FileObject) ch.nextElement (); 453 if (f.isFolder() && f.getName().equalsIgnoreCase("conf")) { confDir = FileUtil.getRelativePath(fo, f); 455 break; 456 } 457 } 458 if (confDir.equals("")) { fo.createFolder(DEFAULT_CONF_FOLDER); 461 ep.setProperty(WebProjectProperties.CONF_DIR, DEFAULT_CONF_FOLDER); 462 } else 463 ep.setProperty(WebProjectProperties.CONF_DIR, confDir); 465 ep.setProperty(WebProjectProperties.RESOURCE_DIR, DEFAULT_RESOURCE_FOLDER); 468 469 ep.setProperty(WebProjectProperties.JAVA_SOURCE_BASED,javaSourceBased+""); 470 471 UpdateHelper updateHelper = ((WebProject) p).getUpdateHelper(); 472 if (sourceLevel != null && (sourceLevel.equals("1.6") || sourceLevel.equals("1.7"))) 474 sourceLevel = "1.5"; 475 PlatformUiSupport.storePlatform(ep, updateHelper, javaPlatformName, sourceLevel != null ? new SpecificationVersion(sourceLevel) : null); 476 477 Utils.updateProperties(antProjectHelper, AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 480 481 ProjectManager.getDefault().saveProject(p); 482 483 return antProjectHelper; 484 } 485 486 private static String createFileReference(ReferenceHelper refHelper, FileObject projectFO, FileObject sourceprojectFO, FileObject referencedFO) { 487 if (FileUtil.isParentOf(projectFO, referencedFO)) { 488 return relativePath(projectFO, referencedFO); 489 } else if (FileUtil.isParentOf(sourceprojectFO, referencedFO)) { 490 String s = relativePath(sourceprojectFO, referencedFO); 491 return s.length() > 0 ? SOURCE_ROOT_REF + "/" + s : SOURCE_ROOT_REF; } else { 493 return refHelper.createForeignFileReference(FileUtil.toFile(referencedFO), null); 494 } 495 } 496 497 private static String relativePath (FileObject parent, FileObject child) { 498 if (child.equals (parent)) 499 return ""; if (!FileUtil.isParentOf (parent, child)) 501 throw new IllegalArgumentException ("Cannot find relative path, " + parent + " is not parent of " + child); 502 return child.getPath ().substring (parent.getPath ().length () + 1); 503 } 504 505 private static AntProjectHelper setupProject (FileObject dirFO, String name, String serverInstanceID, String j2eeLevel) throws IOException { 506 AntProjectHelper h = ProjectGenerator.createProject(dirFO, WebProjectType.TYPE); 507 Element data = h.getPrimaryConfigurationData(true); 508 Document doc = data.getOwnerDocument(); 509 Element nameEl = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); nameEl.appendChild(doc.createTextNode(name)); 511 data.appendChild(nameEl); 512 Element minant = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "minimum-ant-version"); minant.appendChild(doc.createTextNode(MINIMUM_ANT_VERSION)); data.appendChild(minant); 515 516 Element wmLibs = doc.createElementNS (WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "web-module-libraries"); data.appendChild (wmLibs); 518 519 Element addLibs = doc.createElementNS(WebProjectType.PROJECT_CONFIGURATION_NAMESPACE, "web-module-additional-libraries"); data.appendChild(addLibs); 521 522 h.putPrimaryConfigurationData(data, true); 523 EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 524 ep.setProperty(WebProjectProperties.DIST_DIR, "dist"); ep.setProperty(WebProjectProperties.DIST_WAR, "${"+WebProjectProperties.DIST_DIR+"}/${" + WebProjectProperties.WAR_NAME + "}"); ep.setProperty(WebProjectProperties.DIST_WAR_EAR, "${" + WebProjectProperties.DIST_DIR+"}/${" + WebProjectProperties.WAR_EAR_NAME + "}"); 529 ep.setProperty(WebProjectProperties.JAVAC_CLASSPATH, ""); 531 ep.setProperty(WebProjectProperties.JSPCOMPILATION_CLASSPATH, "${jspc.classpath}:${javac.classpath}"); 532 533 ep.setProperty(WebProjectProperties.J2EE_PLATFORM, j2eeLevel); 534 535 ep.setProperty(WebProjectProperties.WAR_NAME, PropertyUtils.getUsablePropertyName(name) + ".war"); ep.setProperty(WebProjectProperties.WAR_EAR_NAME, PropertyUtils.getUsablePropertyName(name) + ".war"); 539 ep.setProperty(WebProjectProperties.WAR_COMPRESS, "false"); ep.setProperty(WebProjectProperties.WAR_PACKAGE, "true"); ep.setProperty(WebProjectProperties.WAR_CONTENT_ADDITIONAL, ""); 543 ep.setProperty(WebProjectProperties.LAUNCH_URL_RELATIVE, ""); ep.setProperty(WebProjectProperties.DISPLAY_BROWSER, "true"); Deployment deployment = Deployment.getDefault (); 546 ep.setProperty(WebProjectProperties.J2EE_SERVER_TYPE, deployment.getServerID (serverInstanceID)); 547 548 ep.setProperty(WebProjectProperties.JAVAC_DEBUG, "true"); ep.setProperty(WebProjectProperties.JAVAC_DEPRECATION, "false"); ep.setProperty("javac.compilerargs", ""); ep.setComment("javac.compilerargs", new String [] { "# " + NbBundle.getMessage(WebProjectUtilities.class, "COMMENT_javac.compilerargs"), }, false); 554 555 ep.setProperty(WebProjectProperties.JAVAC_TEST_CLASSPATH, new String [] { 556 "${javac.classpath}:", "${build.classes.dir}:", "${libs.junit.classpath}", }); 560 ep.setProperty(WebProjectProperties.RUN_TEST_CLASSPATH, new String [] { 561 "${javac.test.classpath}:", "${build.test.classes.dir}", }); 564 ep.setProperty(WebProjectProperties.DEBUG_TEST_CLASSPATH, new String [] { 565 "${run.test.classpath}", }); 567 568 ep.setProperty(WebProjectProperties.BUILD_DIR, DEFAULT_BUILD_DIR); 569 ep.setProperty(WebProjectProperties.BUILD_TEST_CLASSES_DIR, "${build.dir}/test/classes"); ep.setProperty(WebProjectProperties.BUILD_TEST_RESULTS_DIR, "${build.dir}/test/results"); ep.setProperty(WebProjectProperties.BUILD_WEB_DIR, "${"+WebProjectProperties.BUILD_DIR+"}/web"); ep.setProperty(WebProjectProperties.BUILD_EAR_WEB_DIR, "${"+WebProjectProperties.BUILD_DIR+"}/ear-module"); ep.setProperty(WebProjectProperties.BUILD_GENERATED_DIR, "${"+WebProjectProperties.BUILD_DIR+"}/generated"); ep.setProperty(WebProjectProperties.BUILD_CLASSES_DIR, "${"+WebProjectProperties.BUILD_WEB_DIR+"}/WEB-INF/classes"); ep.setProperty(WebProjectProperties.BUILD_EAR_CLASSES_DIR, "${"+WebProjectProperties.BUILD_EAR_WEB_DIR+"}/WEB-INF/classes"); ep.setProperty(WebProjectProperties.BUILD_CLASSES_EXCLUDES, "**/*.java,**/*.form"); ep.setProperty(WebProjectProperties.BUILD_WEB_EXCLUDES, "${"+ WebProjectProperties.BUILD_CLASSES_EXCLUDES +"}"); ep.setProperty(WebProjectProperties.DIST_JAVADOC_DIR, "${"+WebProjectProperties.DIST_DIR+"}/javadoc"); ep.setProperty(WebProjectProperties.NO_DEPENDENCIES, "false"); ep.setProperty(WebProjectProperties.JAVA_PLATFORM, "default_platform"); ep.setProperty(WebProjectProperties.DEBUG_CLASSPATH, "${"+WebProjectProperties.JAVAC_CLASSPATH+"}:${"+WebProjectProperties.BUILD_CLASSES_DIR+"}:${"+WebProjectProperties.BUILD_EAR_CLASSES_DIR+"}"); 583 ep.setProperty("runmain.jvmargs", ""); ep.setComment("runmain.jvmargs", new String [] { "# " + NbBundle.getMessage(WebProjectUtilities.class, "COMMENT_runmain.jvmargs"), "# " + NbBundle.getMessage(WebProjectUtilities.class, "COMMENT_runmain.jvmargs_2"), }, false); 588 589 ep.setProperty(WebProjectProperties.JAVADOC_PRIVATE, "false"); ep.setProperty(WebProjectProperties.JAVADOC_NO_TREE, "false"); ep.setProperty(WebProjectProperties.JAVADOC_USE, "true"); ep.setProperty(WebProjectProperties.JAVADOC_NO_NAVBAR, "false"); ep.setProperty(WebProjectProperties.JAVADOC_NO_INDEX, "false"); ep.setProperty(WebProjectProperties.JAVADOC_SPLIT_INDEX, "true"); ep.setProperty(WebProjectProperties.JAVADOC_AUTHOR, "false"); ep.setProperty(WebProjectProperties.JAVADOC_VERSION, "false"); ep.setProperty(WebProjectProperties.JAVADOC_WINDOW_TITLE, ""); ep.setProperty(WebProjectProperties.JAVADOC_ENCODING, ""); ep.setProperty(WebProjectProperties.JAVADOC_PREVIEW, "true"); ep.setProperty(WebProjectProperties.JAVADOC_ADDITIONALPARAM, ""); 602 ep.setProperty(WebProjectProperties.COMPILE_JSPS, "false"); 604 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 605 606 ep = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 607 ep.setProperty(WebProjectProperties.J2EE_SERVER_INSTANCE, serverInstanceID); 608 609 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 611 if (!j2eePlatform.getSupportedSpecVersions(J2eeModule.WAR).contains(j2eeLevel)) { 612 ErrorManager.getDefault().log(ErrorManager.WARNING, "J2EE level:" + j2eeLevel + " not supported by server " + Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID) + " for module type WAR"); 613 } 614 String classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries()); 615 ep.setProperty(WebProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath); 616 617 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) { 619 File[] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE); 620 ep.setProperty(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH, 621 Utils.toClasspathString(wsClasspath)); 622 } 623 624 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSIMPORT)) { 626 File[] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSIMPORT); 627 ep.setProperty(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH, 628 Utils.toClasspathString(wsClasspath)); 629 } 630 631 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSGEN)) { 633 File[] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSGEN); 634 ep.setProperty(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH, 635 Utils.toClasspathString(wsClasspath)); 636 } 637 638 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109)) { 640 ep.setProperty(WebServicesConstants.J2EE_PLATFORM_JSR109_SUPPORT, 641 "true"); } 643 644 File projectFolder = FileUtil.toFile(dirFO); 646 try { 647 AntDeploymentHelper.writeDeploymentScript(new File(projectFolder, WebProjectProperties.ANT_DEPLOY_BUILD_SCRIPT), 648 J2eeModule.WAR, serverInstanceID); 649 } catch (IOException ioe) { 650 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 651 } 652 File deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID); 653 if (deployAntPropsFile != null) { 654 ep.setProperty(WebProjectProperties.DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath()); 655 } 656 657 h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 658 659 return h; 660 } 661 662 private static void createIndexJSP(FileObject webFolder) throws IOException { 663 FileObject jspTemplate = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/JSP_Servlet/JSP.jsp" ); 665 if (jspTemplate == null) 666 return; 668 DataObject mt = DataObject.find(jspTemplate); 669 DataFolder webDf = DataFolder.findFolder(webFolder); 670 mt.createFromTemplate(webDf, "index"); } 672 673 private static String readResource(InputStream is) throws IOException { 674 StringBuffer sb = new StringBuffer (); 676 String lineSep = System.getProperty("line.separator"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); 678 String line = br.readLine(); 679 while (line != null) { 680 sb.append(line); 681 sb.append(lineSep); 682 line = br.readLine(); 683 } 684 br.close(); 685 return sb.toString(); 686 } 687 688 } 689 | Popular Tags |