1 19 20 package org.netbeans.modules.j2ee.clientproject.api; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.io.PrintWriter ; 26 import java.math.BigDecimal ; 27 import java.util.Stack ; 28 import org.netbeans.api.java.platform.JavaPlatform; 29 import org.netbeans.api.java.platform.JavaPlatformManager; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.api.java.project.JavaProjectConstants; 33 import org.netbeans.modules.j2ee.clientproject.AppClientProject; 34 import org.netbeans.modules.j2ee.clientproject.AppClientProjectType; 35 import org.netbeans.modules.j2ee.clientproject.AppClientProvider; 36 import org.netbeans.modules.j2ee.clientproject.UpdateHelper; 37 import org.netbeans.modules.j2ee.clientproject.Utils; 38 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 39 import org.netbeans.modules.j2ee.clientproject.ui.customizer.PlatformUiSupport; 40 import org.netbeans.modules.j2ee.dd.api.client.AppClient; 41 import org.netbeans.modules.j2ee.dd.api.client.DDProvider; 42 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 43 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 44 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 45 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 46 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 47 import org.netbeans.modules.websvc.api.client.WebServicesClientConstants; 48 import org.netbeans.spi.project.support.ant.AntProjectHelper; 49 import org.netbeans.spi.project.support.ant.EditableProperties; 50 import org.netbeans.spi.project.support.ant.ProjectGenerator; 51 import org.netbeans.spi.project.support.ant.PropertyUtils; 52 import org.netbeans.spi.project.support.ant.ReferenceHelper; 53 import org.openide.filesystems.FileObject; 54 import org.openide.filesystems.FileUtil; 55 import org.openide.filesystems.Repository; 56 import org.openide.filesystems.FileStateInvalidException; 57 import org.openide.loaders.DataFolder; 58 import org.openide.loaders.DataObject; 59 import org.openide.util.Mutex; 60 import org.openide.util.MutexException; 61 import org.openide.ErrorManager; 62 import org.openide.filesystems.FileLock; 63 import org.openide.modules.SpecificationVersion; 64 import org.openide.util.NbBundle; 65 import org.w3c.dom.Document ; 66 import org.w3c.dom.Element ; 67 import org.w3c.dom.NodeList ; 68 69 72 public class AppClientProjectGenerator { 73 74 private static final String DEFAULT_CONF_FOLDER = "conf"; private static final String DEFAULT_SRC_FOLDER = "src"; private static final String DEFAULT_TEST_FOLDER = "test"; private static final String DEFAULT_RESOURCE_FOLDER = "setup"; private static final String DEFAULT_JAVA_FOLDER = "java"; private static final String DEFAULT_BUILD_DIR = "build"; 81 public static final String MINIMUM_ANT_VERSION = "1.6.5"; 83 private static final String MANIFEST_FILE = "MANIFEST.MF"; 85 private AppClientProjectGenerator() {} 86 87 99 public static AntProjectHelper createProject(File dir, String name, String mainClass, String j2eeLevel, String serverInstanceID) throws IOException { 100 FileObject fo = createProjectDir(dir); 101 102 FileObject srcRoot = fo.createFolder(DEFAULT_SRC_FOLDER); 103 FileObject javaRoot = srcRoot.createFolder(DEFAULT_JAVA_FOLDER); 104 FileObject confRoot = srcRoot.createFolder(DEFAULT_CONF_FOLDER); 105 fo.createFolder(DEFAULT_TEST_FOLDER); 106 107 String resource = (J2eeModule.JAVA_EE_5.equals(j2eeLevel) 109 ? "org-netbeans-modules-j2ee-clientproject/application-client-5.xml" : "org-netbeans-modules-j2ee-clientproject/application-client-1.4.xml"); FileObject ddFile = FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource(resource), confRoot, "application-client"); AppClient appClient = DDProvider.getDefault().getDDRoot(ddFile); 113 appClient.setDisplayName(name); 114 appClient.write(ddFile); 115 116 AntProjectHelper h = createProject(fo, name, DEFAULT_SRC_FOLDER, DEFAULT_TEST_FOLDER, 117 null, null, null,mainClass, j2eeLevel, serverInstanceID); 118 119 EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 120 ep.put(AppClientProjectProperties.SOURCE_ROOT, DEFAULT_SRC_FOLDER); ep.setProperty(AppClientProjectProperties.META_INF, "${"+AppClientProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_CONF_FOLDER); ep.setProperty(AppClientProjectProperties.SRC_DIR, "${"+AppClientProjectProperties.SOURCE_ROOT+"}/"+DEFAULT_JAVA_FOLDER); h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 124 125 Project p = ProjectManager.getDefault().findProject(fo); 126 ProjectManager.getDefault().saveProject(p); 127 128 if ( mainClass != null ) { 129 createMainClass( mainClass, javaRoot ); 130 } 131 132 createManifest(confRoot, MANIFEST_FILE); 133 134 return h; 135 } 136 137 152 public static AntProjectHelper importProject(final File dir, final String name, 153 final File [] sourceFolders, final File [] testFolders, final File confFolder, final File libFolder, String j2eeLevel, String serverInstanceID) throws IOException { 154 assert sourceFolders != null && testFolders != null: "Package roots can't be null"; final FileObject dirFO = createProjectDir(dir); 156 final AntProjectHelper h = createProject(dirFO, name, null, null, 157 confFolder.getAbsolutePath(), (libFolder == null ? null : libFolder.getAbsolutePath()), 158 null, null, j2eeLevel, serverInstanceID); 159 final AppClientProject p = (AppClientProject) ProjectManager.getDefault().findProject(dirFO); 160 final ReferenceHelper refHelper = p.getReferenceHelper(); 161 try { 162 ProjectManager.mutex().writeAccess( new Mutex.ExceptionAction() { 163 public Object run() throws Exception { 164 Element data = h.getPrimaryConfigurationData(true); 165 Document doc = data.getOwnerDocument(); 166 NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); assert nl.getLength() == 1; 168 Element sourceRoots = (Element ) nl.item(0); 169 nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); assert nl.getLength() == 1; 171 Element testRoots = (Element ) nl.item(0); 172 for (int i=0; i<sourceFolders.length; i++) { 173 String propName = "src.dir" + (i == 0 ? "" : Integer.toString(i+1)); String srcReference = refHelper.createForeignFileReference(sourceFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA); 175 Element root = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute("id",propName); sourceRoots.appendChild(root); 178 EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 179 props.put(propName,srcReference); 180 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } 182 183 if (testFolders.length == 0) { 184 String testLoc = NbBundle.getMessage(AppClientProjectGenerator.class,"TXT_DefaultTestFolderName"); 185 File f = new File (dir,testLoc); 186 f.mkdirs(); 187 String propName = "test.src.dir"; Element root = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute("id",propName); root.setAttribute("name",NbBundle.getMessage(AppClientProjectGenerator.class, "NAME_test.src.dir")); 191 testRoots.appendChild(root); 192 EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 193 props.put(propName,testLoc); 194 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); } else { 196 for (int i=0; i<testFolders.length; i++) { 197 if (!testFolders[i].exists()) { 198 testFolders[i].mkdirs(); 199 } 200 String propName = "test.src.dir" + (i == 0 ? "" : Integer.toString(i+1)); String testReference = refHelper.createForeignFileReference(testFolders[i], JavaProjectConstants.SOURCES_TYPE_JAVA); 202 Element root = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute("id",propName); testRoots.appendChild(root); 205 EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); props.put(propName,testReference); 207 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 208 } 209 } 210 h.putPrimaryConfigurationData(data,true); 211 ProjectManager.getDefault().saveProject(p); 212 return null; 213 } 214 }); 215 } catch (MutexException me ) { 216 ErrorManager.getDefault().notify(me); 217 } 218 FileObject confFolderFO = FileUtil.toFileObject(confFolder); 220 FileObject appClientXML = confFolderFO == null ? null 221 : confFolderFO.getFileObject(AppClientProvider.FILE_DD); 222 if (appClientXML != null) { 223 try { 224 AppClient root = DDProvider.getDefault().getDDRoot(appClientXML); 226 boolean writeDD = false; 227 if (new BigDecimal (AppClient.VERSION_1_3).equals(root.getVersion()) && J2eeModule.J2EE_14.equals(j2eeLevel)) { root.setVersion(new BigDecimal (AppClient.VERSION_1_4)); 229 writeDD = true; 230 } 231 String 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(appClientXML); 239 } 240 } catch (IOException e) { 241 ErrorManager.getDefault().notify(e); 242 } 243 } else { 244 String resource = (J2eeModule.JAVA_EE_5.equals(j2eeLevel) 246 ? "org-netbeans-modules-j2ee-clientproject/application-client-5.xml" : "org-netbeans-modules-j2ee-clientproject/application-client-1.4.xml"); FileUtil.copyFile(Repository.getDefault().getDefaultFileSystem().findResource(resource), 249 confFolderFO, "application-client"); } 251 createManifest(confFolderFO, MANIFEST_FILE); 252 return h; 253 } 254 255 271 public static AntProjectHelper importProject(final File dir, final String name, 272 final File [] sourceFolders, final File [] testFolders, final File confFolder, 273 final File libFolder, String j2eeLevel, String serverInstanceID,boolean fromJavaSource) throws IOException { 274 AntProjectHelper h = importProject(dir,name,sourceFolders,testFolders, 275 confFolder,libFolder,j2eeLevel,serverInstanceID); 276 EditableProperties subEp = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 277 subEp.setProperty(AppClientProjectProperties.JAVA_SOURCE_BASED,fromJavaSource+""); h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,subEp); 279 Project subP = ProjectManager.getDefault().findProject(h.getProjectDirectory()); 280 ProjectManager.getDefault().saveProject(subP); 281 return h; 282 } 283 private static AntProjectHelper createProject(FileObject dirFO, String name, 284 String srcRoot, String testRoot, String configFiles, String libraries, 285 String resources, String mainClass, String j2eeLevel, 286 String serverInstanceID) throws IOException { 287 AntProjectHelper h = ProjectGenerator.createProject(dirFO, AppClientProjectType.TYPE); 288 Element data = h.getPrimaryConfigurationData(true); 289 Document doc = data.getOwnerDocument(); 290 Element nameEl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); nameEl.appendChild(doc.createTextNode(name)); 292 data.appendChild(nameEl); 293 Element minant = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "minimum-ant-version"); minant.appendChild(doc.createTextNode(MINIMUM_ANT_VERSION)); data.appendChild(minant); 296 297 301 EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 302 Element sourceRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); if (srcRoot != null) { 304 Element root = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute("id","src.dir"); root.setAttribute("name",NbBundle.getMessage(AppClientProjectGenerator.class, "NAME_src.dir")); 307 sourceRoots.appendChild(root); 308 ep.setProperty("src.dir", srcRoot); } 310 data.appendChild(sourceRoots); 311 Element testRoots = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); if (testRoot != null) { 313 Element root = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute("id","test.src.dir"); root.setAttribute("name",NbBundle.getMessage(AppClientProjectGenerator.class, "NAME_test.src.dir")); 316 testRoots.appendChild(root); 317 ep.setProperty("test.src.dir", testRoot); } 319 data.appendChild(testRoots); 320 h.putPrimaryConfigurationData(data, true); 321 322 if (configFiles != null) { 323 ep.setProperty(AppClientProjectProperties.META_INF, configFiles); 324 } 325 if (libraries != null) { 326 ep.setProperty(AppClientProjectProperties.LIBRARIES_DIR, libraries); 327 } 328 329 if (resources != null) { 330 ep.setProperty(AppClientProjectProperties.RESOURCE_DIR, resources); 331 } else { 332 ep.setProperty(AppClientProjectProperties.RESOURCE_DIR, DEFAULT_RESOURCE_FOLDER); 333 } 334 335 ep.setProperty(AppClientProjectProperties.DIST_EAR_JAR, "${"+AppClientProjectProperties.DIST_DIR+"}/" + "${" + AppClientProjectProperties.JAR_NAME + "}"); ep.setProperty(AppClientProjectProperties.JAR_NAME, PropertyUtils.getUsablePropertyName(name) + ".jar"); ep.setProperty(AppClientProjectProperties.BUILD_EAR_CLASSES_DIR, "${"+AppClientProjectProperties.BUILD_DIR+"}/ear-module"); 340 ep.setProperty("dist.dir", "dist"); ep.setComment("dist.dir", new String [] {"# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_dist.dir")}, false); ep.setProperty(AppClientProjectProperties.DIST_JAR, "${"+AppClientProjectProperties.DIST_DIR+"}/" + "${" + AppClientProjectProperties.JAR_NAME + "}"); ep.setProperty("javac.classpath", new String [0]); ep.setProperty("build.sysclasspath", "ignore"); ep.setComment("build.sysclasspath", new String [] {"# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_build.sysclasspath")}, false); ep.setProperty("run.classpath", new String [] { "${javac.classpath}:", "${build.classes.dir}", }); 351 ep.setProperty("debug.classpath", new String [] { "${run.classpath}", }); 354 ep.setProperty("jar.compress", "false"); if (mainClass != null) { 356 ep.setProperty("main.class", mainClass); } 358 359 ep.setProperty("javac.compilerargs", ""); ep.setComment("javac.compilerargs", new String [] { "# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_javac.compilerargs"), }, false); 363 364 JavaPlatform defaultPlatform = JavaPlatformManager.getDefault().getDefaultPlatform(); 365 SpecificationVersion v = defaultPlatform.getSpecification().getVersion(); 366 String sourceLevel = v.toString(); 367 if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7")) 369 sourceLevel = "1.5"; 370 ep.setProperty(AppClientProjectProperties.JAVAC_SOURCE, sourceLevel); ep.setProperty(AppClientProjectProperties.JAVAC_TARGET, sourceLevel); 373 ep.setProperty("javac.deprecation", "false"); ep.setProperty("javac.test.classpath", new String [] { "${javac.classpath}:", "${build.classes.dir}:", "${libs.junit.classpath}", }); 379 ep.setProperty("run.test.classpath", new String [] { "${javac.test.classpath}:", "${build.test.classes.dir}", }); 383 ep.setProperty("debug.test.classpath", new String [] { "${run.test.classpath}", }); 386 387 ep.setProperty("build.generated.dir", "${build.dir}/generated"); 390 ep.setProperty("build.dir", DEFAULT_BUILD_DIR); ep.setComment("build.dir", new String [] {"# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_build.dir")}, false); ep.setProperty("build.classes.dir", "${build.dir}/jar"); ep.setProperty("build.test.classes.dir", "${build.dir}/test/classes"); ep.setProperty("build.test.results.dir", "${build.dir}/test/results"); ep.setProperty("build.classes.excludes", "**/*.java,**/*.form"); ep.setProperty("dist.javadoc.dir", "${dist.dir}/javadoc"); ep.setProperty(AppClientProjectProperties.JAVA_PLATFORM, "default_platform"); 400 ep.setProperty("run.jvmargs", ""); ep.setComment("run.jvmargs", new String [] { "# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_run.jvmargs"), "# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_run.jvmargs_2"), "# " + NbBundle.getMessage(AppClientProjectGenerator.class, "COMMENT_run.jvmargs_3"), }, false); 406 407 ep.setProperty(AppClientProjectProperties.JAVADOC_PRIVATE, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_NO_TREE, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_USE, "true"); ep.setProperty(AppClientProjectProperties.JAVADOC_NO_NAVBAR, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_NO_INDEX, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_SPLIT_INDEX, "true"); ep.setProperty(AppClientProjectProperties.JAVADOC_AUTHOR, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_VERSION, "false"); ep.setProperty(AppClientProjectProperties.JAVADOC_WINDOW_TITLE, ""); ep.setProperty(AppClientProjectProperties.JAVADOC_ENCODING, ""); ep.setProperty(AppClientProjectProperties.JAVADOC_ADDITIONALPARAM, ""); 419 Deployment deployment = Deployment.getDefault(); 420 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 421 if (!j2eePlatform.getSupportedSpecVersions(J2eeModule.CLIENT).contains(j2eeLevel)) { 422 ErrorManager.getDefault().log(ErrorManager.WARNING, 423 NbBundle.getMessage(AppClientProjectGenerator.class, "MSG_Warning_SpecLevelNotSupported", new Object [] {j2eeLevel, Deployment.getDefault().getServerInstanceDisplayName(serverInstanceID)})); 425 } 426 ep.setProperty(AppClientProjectProperties.J2EE_SERVER_TYPE, deployment.getServerID(serverInstanceID)); 427 ep.setProperty(AppClientProjectProperties.J2EE_PLATFORM, j2eeLevel); 428 ep.setProperty("manifest.file", "${" +AppClientProjectProperties.META_INF + "}/" + MANIFEST_FILE); 430 String mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS_ARGS); 431 if (mainClassArgs != null && !mainClassArgs.equals("")) { 432 ep.put(AppClientProjectProperties.APPCLIENT_MAINCLASS_ARGS, mainClassArgs); 433 } else if ((mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, AppClientProjectProperties.CLIENT_NAME)) 434 != null) { 435 ep.put(AppClientProjectProperties.CLIENT_NAME, mainClassArgs); 436 } 437 h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 438 439 ep = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 441 File [] accrt = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_APP_CLIENT_RUNTIME); 443 ep.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_RUNTIME, Utils.toClasspathString(accrt)); 444 String acMain = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS); 445 if (acMain != null) { 446 ep.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_MAINCLASS, acMain); 447 } 448 String jvmOpts = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_JVM_OPTS); 449 if (jvmOpts != null) { 450 ep.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_JVMOPTS, jvmOpts); 451 } 452 String args = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, 453 AppClientProjectProperties.J2EE_PLATFORM_APPCLIENT_ARGS); 454 if (args != null) { 455 ep.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_ARGS, args); 456 } 457 458 ep.setProperty(AppClientProjectProperties.J2EE_SERVER_INSTANCE, serverInstanceID); 459 String classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries()); 461 ep.setProperty(AppClientProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath); 462 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) { 464 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE); 465 ep.setProperty(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH, 466 Utils.toClasspathString(wsClasspath)); 467 } 468 469 if ("J2EE".equals(deployment.getServerID(serverInstanceID))) { File asRoot = j2eePlatform.getPlatformRoots()[0]; 474 File exFile = new File (asRoot, "lib/javaee.jar"); InstanceProperties ip = InstanceProperties.getInstanceProperties(serverInstanceID); 476 if (exFile.exists()) { 477 ep.setProperty("wa.copy.client.jar.from", new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/generated/xml/j2ee-modules").getAbsolutePath()); } else { 480 ep.setProperty("wa.copy.client.jar.from", new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/applications/j2ee-modules").getAbsolutePath()); } 483 } else { 484 ep.remove("wa.copy.client.jar.from"); } 486 487 File projectFolder = FileUtil.toFile(dirFO); 489 try { 490 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, AppClientProjectProperties.ANT_DEPLOY_BUILD_SCRIPT), 491 J2eeModule.CLIENT, serverInstanceID); 492 } catch (IOException ioe) { 493 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 494 } 495 File deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID); 496 if (deployAntPropsFile != null) { 497 ep.setProperty(AppClientProjectProperties.DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath()); 498 } 499 500 h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 501 502 return h; 503 } 504 505 private static FileObject createProjectDir(File dir) throws IOException { 506 Stack stack = new Stack (); 507 while (!dir.exists()) { 508 stack.push (dir.getName()); 509 dir = dir.getParentFile(); 510 } 511 FileObject dirFO = FileUtil.toFileObject (dir); 512 if (dirFO == null) { 513 refreshFileSystem(dir); 514 dirFO = FileUtil.toFileObject (dir); 515 } 516 assert dirFO != null; 517 while (!stack.isEmpty()) { 518 dirFO = dirFO.createFolder((String )stack.pop()); 519 } 520 return dirFO; 521 } 522 523 private static void createMainClass( String mainClassName, FileObject srcFolder ) throws IOException { 524 525 int lastDotIdx = mainClassName.lastIndexOf( '.' ); 526 String mName, pName; 527 if ( lastDotIdx == -1 ) { 528 mName = mainClassName.trim(); 529 pName = null; 530 } else { 531 mName = mainClassName.substring( lastDotIdx + 1 ).trim(); 532 pName = mainClassName.substring( 0, lastDotIdx ).trim(); 533 } 534 535 if ( mName.length() == 0 ) { 536 return; 537 } 538 539 FileObject mainTemplate = Repository.getDefault().getDefaultFileSystem().findResource( "Templates/Classes/Main.java" ); 541 if ( mainTemplate == null ) { 542 return; } 544 545 DataObject mt = DataObject.find( mainTemplate ); 546 547 FileObject pkgFolder = srcFolder; 548 if ( pName != null ) { 549 String fName = pName.replace( '.', '/' ); pkgFolder = FileUtil.createFolder( srcFolder, fName ); 551 } 552 DataFolder pDf = DataFolder.findFolder( pkgFolder ); 553 mt.createFromTemplate( pDf, mName ); 554 555 } 556 557 558 private static void refreshFileSystem(final File dir) throws FileStateInvalidException { 559 File rootF = dir; 560 while (rootF.getParentFile() != null) { 561 rootF = rootF.getParentFile(); 562 } 563 FileObject dirFO = FileUtil.toFileObject(rootF); 564 assert dirFO != null : "At least disk roots must be mounted! " + rootF; dirFO.getFileSystem().refresh(false); 566 } 567 568 575 public static void setPlatform(final AntProjectHelper helper, final String platformName, final String sourceLevel) { 578 ProjectManager.mutex().writeAccess(new Runnable () { 579 public void run() { 580 try { 581 AppClientProject project = (AppClientProject)ProjectManager.getDefault().findProject(helper.getProjectDirectory()); 582 UpdateHelper updateHelper = project.getUpdateHelper(); 583 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 584 String finalPlatformName = platformName; 585 if (finalPlatformName == null) { 586 finalPlatformName = JavaPlatformManager.getDefault().getDefaultPlatform().getDisplayName(); 587 } 588 589 String srcLevel = sourceLevel; 591 if (sourceLevel.equals("1.6") || sourceLevel.equals("1.7")) 592 srcLevel = "1.5"; 593 PlatformUiSupport.storePlatform(ep, updateHelper, finalPlatformName, srcLevel != null ? new SpecificationVersion(srcLevel) : null); 594 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 595 ProjectManager.getDefault().saveProject(ProjectManager.getDefault().findProject(helper.getProjectDirectory())); 596 } catch (IOException e) { 597 ErrorManager.getDefault().notify(e); 598 } 599 } 600 }); 601 } 602 603 609 private static void createManifest(FileObject dir, String path) throws IOException { 610 if (dir.getFileObject(path) == null) { 611 FileObject manifest = FileUtil.createData(dir, path); 612 FileLock lock = manifest.lock(); 613 try { 614 OutputStream os = manifest.getOutputStream(lock); 615 try { 616 PrintWriter pw = new PrintWriter (os); 617 pw.println("Manifest-Version: 1.0"); pw.println("X-COMMENT: Main-Class will be added automatically by build"); pw.println(); pw.flush(); 621 } finally { 622 os.close(); 623 } 624 } finally { 625 lock.releaseLock(); 626 } 627 } 628 } 629 630 } 631 632 633 | Popular Tags |