1 19 20 package org.netbeans.modules.web.project.ui.customizer; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.MalformedURLException ; 25 import java.net.URI ; 26 import java.net.URL ; 27 import java.util.*; 28 import javax.swing.ButtonModel ; 29 import javax.swing.ComboBoxModel ; 30 import javax.swing.DefaultListModel ; 31 import javax.swing.ListCellRenderer ; 32 33 import javax.swing.table.DefaultTableModel ; 34 import javax.swing.text.BadLocationException ; 35 import javax.swing.text.Document ; 36 import javax.swing.text.PlainDocument ; 37 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 38 import org.netbeans.modules.web.project.ProjectWebModule; 39 40 import org.netbeans.modules.web.project.SourceRoots; 41 import org.netbeans.modules.web.project.classpath.ClassPathSupport; 42 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 43 import org.netbeans.spi.project.support.ant.ui.StoreGroup; 44 45 import org.openide.ErrorManager; 46 import org.openide.filesystems.FileUtil; 47 import org.openide.modules.SpecificationVersion; 48 import org.openide.util.MutexException; 49 import org.openide.util.Mutex; 50 import org.netbeans.api.project.Project; 51 import org.netbeans.api.project.ProjectManager; 52 import org.netbeans.api.queries.CollocationQuery; 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.spi.project.support.ant.AntProjectHelper; 57 import org.netbeans.spi.project.support.ant.EditableProperties; 58 import org.netbeans.spi.project.support.ant.PropertyUtils; 59 import org.netbeans.spi.project.support.ant.ReferenceHelper; 60 import org.netbeans.modules.web.project.WebProjectUtil; 61 import org.netbeans.modules.web.project.UpdateHelper; 62 import org.netbeans.modules.web.project.Utils; 63 import org.netbeans.modules.web.project.WebProject; 64 import org.netbeans.modules.web.project.classpath.ClassPathSupport.Item; 65 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; 66 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 67 import org.openide.filesystems.FileObject; 68 import org.openide.filesystems.URLMapper; 69 70 75 public class WebProjectProperties { 76 77 public static final String J2EE_1_4 = "1.4"; public static final String J2EE_1_3 = "1.3"; 80 public static final String WEB_PROJECT_NAME = "web.project.name"; public static final String JAVA_PLATFORM = "platform.active"; public static final String J2EE_PLATFORM = "j2ee.platform"; 85 87 public static final String SOURCE_ROOT = "source.root"; public static final String BUILD_FILE = "buildfile"; public static final String LIBRARIES_DIR = "lib.dir"; public static final String DIST_DIR = "dist.dir"; public static final String DIST_WAR = "dist.war"; public static final String DIST_WAR_EAR = "dist.ear.war"; public static final String JAVAC_CLASSPATH = "javac.classpath"; public static final String DEBUG_CLASSPATH = "debug.classpath"; public static final String JSPCOMPILATION_CLASSPATH = "jspcompilation.classpath"; 97 public static final String WAR_NAME = "war.name"; public static final String WAR_EAR_NAME = "war.ear.name"; public static final String WAR_COMPRESS = "jar.compress"; public static final String WAR_PACKAGE = "war.package"; public static final String WAR_CONTENT_ADDITIONAL = "war.content.additional"; 103 public static final String LAUNCH_URL_RELATIVE = "client.urlPart"; public static final String DISPLAY_BROWSER = "display.browser"; public static final String CONTEXT_PATH = "context.path"; public static final String J2EE_SERVER_INSTANCE = "j2ee.server.instance"; public static final String J2EE_SERVER_TYPE = "j2ee.server.type"; public static final String J2EE_PLATFORM_CLASSPATH = "j2ee.platform.classpath"; public static final String JAVAC_SOURCE = "javac.source"; public static final String JAVAC_DEBUG = "javac.debug"; public static final String JAVAC_DEPRECATION = "javac.deprecation"; public static final String JAVAC_COMPILER_ARG = "javac.compilerargs"; public static final String JAVAC_TARGET = "javac.target"; public static final String SRC_DIR = "src.dir"; public static final String TEST_SRC_DIR = "test.src.dir"; public static final String CONF_DIR = "conf.dir"; public static final String WEB_DOCBASE_DIR = "web.docbase.dir"; public static final String RESOURCE_DIR = "resource.dir"; public static final String BUILD_DIR = "build.dir"; public static final String BUILD_WEB_DIR = "build.web.dir"; public static final String BUILD_EAR_WEB_DIR = "build.ear.web.dir"; public static final String BUILD_GENERATED_DIR = "build.generated.dir"; public static final String BUILD_CLASSES_DIR = "build.classes.dir"; public static final String BUILD_EAR_CLASSES_DIR = "build.ear.classes.dir"; public static final String BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; public static final String BUILD_WEB_EXCLUDES = "build.web.excludes"; public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; public static final String NO_DEPENDENCIES="no.dependencies"; 130 public static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; public static final String BUILD_TEST_RESULTS_DIR = "build.test.results.dir"; public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; public static final String RUN_TEST_CLASSPATH = "run.test.classpath"; public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; 136 public static final String JAVADOC_PRIVATE="javadoc.private"; public static final String JAVADOC_NO_TREE="javadoc.notree"; public static final String JAVADOC_USE="javadoc.use"; public static final String JAVADOC_NO_NAVBAR="javadoc.nonavbar"; public static final String JAVADOC_NO_INDEX="javadoc.noindex"; public static final String JAVADOC_SPLIT_INDEX="javadoc.splitindex"; public static final String JAVADOC_AUTHOR="javadoc.author"; public static final String JAVADOC_VERSION="javadoc.version"; public static final String JAVADOC_WINDOW_TITLE="javadoc.windowtitle"; public static final String JAVADOC_ENCODING="javadoc.encoding"; public static final String JAVADOC_ADDITIONALPARAM="javadoc.additionalparam"; 148 public static final String COMPILE_JSPS = "compile.jsps"; 150 public static final String TAG_WEB_MODULE_LIBRARIES = "web-module-libraries"; public static final String TAG_WEB_MODULE__ADDITIONAL_LIBRARIES = "web-module-additional-libraries"; 153 public static final String APPLICATION_ARGS = "application.args"; public static final String JAVADOC_PREVIEW="javadoc.preview"; 157 public static final String WS_DEBUG_CLASSPATHS = "ws.debug.classpaths"; public static final String WS_WEB_DOCBASE_DIRS = "ws.web.docbase.dirs"; 160 public static final String DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; 162 public static final String ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; 164 public static final String [] WELL_KNOWN_PATHS = new String [] { 166 "${" + JAVAC_CLASSPATH + "}", "${" + JAVAC_TEST_CLASSPATH + "}", "${" + RUN_TEST_CLASSPATH + "}", "${" + BUILD_CLASSES_DIR + "}", "${" + BUILD_TEST_CLASSES_DIR + "}", }; 172 173 public static final String LIBRARY_PREFIX = "${libs."; public static final String LIBRARY_SUFFIX = ".classpath}"; public static final String ANT_ARTIFACT_PREFIX = "${reference."; 178 public ClassPathSupport cs; 179 180 private List newFrameworks; 182 183 185 DefaultTableModel SOURCE_ROOTS_MODEL; 187 DefaultTableModel TEST_ROOTS_MODEL; 188 Document WEB_DOCBASE_DIR_MODEL; 189 ComboBoxModel JAVAC_SOURCE_MODEL; 190 191 ClassPathUiSupport.ClassPathTableModel JAVAC_CLASSPATH_MODEL; 193 DefaultListModel JAVAC_TEST_CLASSPATH_MODEL; 194 DefaultListModel RUN_TEST_CLASSPATH_MODEL; 195 ComboBoxModel PLATFORM_MODEL; 196 ListCellRenderer CLASS_PATH_LIST_RENDERER; 197 ListCellRenderer PLATFORM_LIST_RENDERER; 198 WebClassPathUi.ClassPathTableCellItemRenderer CLASS_PATH_TABLE_ITEM_RENDERER; 199 200 ButtonModel JAVAC_DEPRECATION_MODEL; 202 ButtonModel JAVAC_DEBUG_MODEL; 203 ButtonModel NO_DEPENDENCIES_MODEL; 204 Document JAVAC_COMPILER_ARG_MODEL; 205 ButtonModel COMPILE_JSP_MODEL; 206 207 Document WAR_NAME_MODEL; 209 Document BUILD_CLASSES_EXCLUDES_MODEL; 210 ButtonModel WAR_COMPRESS_MODEL; 211 ButtonModel WAR_PACKAGE_MODEL; 212 WarIncludesUiSupport.ClasspathTableModel WAR_CONTENT_ADDITIONAL_MODEL; 213 214 ButtonModel JAVADOC_PRIVATE_MODEL; 216 ButtonModel JAVADOC_NO_TREE_MODEL; 217 ButtonModel JAVADOC_USE_MODEL; 218 ButtonModel JAVADOC_NO_NAVBAR_MODEL; 219 ButtonModel JAVADOC_NO_INDEX_MODEL; 220 ButtonModel JAVADOC_SPLIT_INDEX_MODEL; 221 ButtonModel JAVADOC_AUTHOR_MODEL; 222 ButtonModel JAVADOC_VERSION_MODEL; 223 Document JAVADOC_WINDOW_TITLE_MODEL; 224 ButtonModel JAVADOC_PREVIEW_MODEL; 225 Document JAVADOC_ADDITIONALPARAM_MODEL; 226 227 Document J2EE_PLATFORM_MODEL; 229 Document CONTEXT_PATH_MODEL; 230 Document LAUNCH_URL_RELATIVE_MODEL; 231 ButtonModel DISPLAY_BROWSER_MODEL; 232 ComboBoxModel J2EE_SERVER_INSTANCE_MODEL; 233 234 private WebProject project; 236 private ReferenceHelper refHelper; 237 private UpdateHelper updateHelper; 238 private PropertyEvaluator evaluator; 239 240 private StoreGroup privateGroup; 241 private StoreGroup projectGroup; 242 243 private Properties additionalProperties; 244 245 private static boolean needsUpdate = false; 246 247 private static String serverId; 248 private static String cp; 249 250 public static final String JAVA_SOURCE_BASED= "java.source.based"; 251 252 253 public WebProjectProperties(WebProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper) { 254 this.project = project; 255 this.updateHelper = updateHelper; 256 257 updateHelper.setProjectUpdateListener(new UpdateHelper.ProjectUpdateListener() { 259 public void projectUpdated() { 260 needsUpdate = true; 261 } 262 }); 263 264 this.evaluator = evaluator; 265 this.refHelper = refHelper; 266 267 this.cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), WELL_KNOWN_PATHS, LIBRARY_PREFIX, LIBRARY_SUFFIX, ANT_ARTIFACT_PREFIX); 268 269 privateGroup = new StoreGroup(); 270 projectGroup = new StoreGroup(); 271 272 additionalProperties = new Properties(); 273 274 init(); } 276 277 WebProject getProject() { 278 return project; 279 } 280 281 283 private void init() { 284 285 CLASS_PATH_LIST_RENDERER = new WebClassPathUi.ClassPathListCellRenderer( evaluator ); 286 CLASS_PATH_TABLE_ITEM_RENDERER = new WebClassPathUi.ClassPathTableCellItemRenderer( evaluator ); 287 288 SOURCE_ROOTS_MODEL = WebSourceRootsUi.createModel( project.getSourceRoots() ); 290 TEST_ROOTS_MODEL = WebSourceRootsUi.createModel( project.getTestSourceRoots() ); 291 WEB_DOCBASE_DIR_MODEL = projectGroup.createStringDocument( evaluator, WEB_DOCBASE_DIR ); 292 293 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 295 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 296 297 JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createTableModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES) ); 298 JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 299 RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 300 PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); 301 PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); 302 JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(J2EE_PLATFORM)); 303 304 JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION ); 306 JAVAC_DEBUG_MODEL = privateGroup.createToggleButtonModel( evaluator, JAVAC_DEBUG ); 307 NO_DEPENDENCIES_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, NO_DEPENDENCIES ); 308 JAVAC_COMPILER_ARG_MODEL = projectGroup.createStringDocument( evaluator, JAVAC_COMPILER_ARG ); 309 COMPILE_JSP_MODEL = projectGroup.createToggleButtonModel( evaluator, COMPILE_JSPS ); 310 311 WAR_NAME_MODEL = projectGroup.createStringDocument( evaluator, WAR_NAME ); 313 BUILD_CLASSES_EXCLUDES_MODEL = projectGroup.createStringDocument( evaluator, BUILD_CLASSES_EXCLUDES ); 314 WAR_COMPRESS_MODEL = projectGroup.createToggleButtonModel( evaluator, WAR_COMPRESS ); 315 WAR_PACKAGE_MODEL = projectGroup.createToggleButtonModel( evaluator, WAR_PACKAGE ); 316 WAR_CONTENT_ADDITIONAL_MODEL = WarIncludesUiSupport.createTableModel( cs.itemsList( (String )projectProperties.get( WAR_CONTENT_ADDITIONAL ), ClassPathSupport.TAG_WEB_MODULE__ADDITIONAL_LIBRARIES)); 317 318 JAVADOC_PRIVATE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_PRIVATE ); 320 JAVADOC_NO_TREE_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_TREE ); 321 JAVADOC_USE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_USE ); 322 JAVADOC_NO_NAVBAR_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_NAVBAR ); 323 JAVADOC_NO_INDEX_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_INDEX ); 324 JAVADOC_SPLIT_INDEX_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_SPLIT_INDEX ); 325 JAVADOC_AUTHOR_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_AUTHOR ); 326 JAVADOC_VERSION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_VERSION ); 327 JAVADOC_WINDOW_TITLE_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_WINDOW_TITLE ); 328 JAVADOC_PREVIEW_MODEL = privateGroup.createToggleButtonModel( evaluator, JAVADOC_PREVIEW ); 329 JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM ); 330 331 J2EE_PLATFORM_MODEL = projectGroup.createStringDocument(evaluator, J2EE_PLATFORM); 333 LAUNCH_URL_RELATIVE_MODEL = projectGroup.createStringDocument(evaluator, LAUNCH_URL_RELATIVE); 334 DISPLAY_BROWSER_MODEL = projectGroup.createToggleButtonModel(evaluator, DISPLAY_BROWSER); 335 J2EE_SERVER_INSTANCE_MODEL = J2eePlatformUiSupport.createPlatformComboBoxModel(privateProperties.getProperty( J2EE_SERVER_INSTANCE ), projectProperties.getProperty(J2EE_PLATFORM)); 336 try { 337 CONTEXT_PATH_MODEL = new PlainDocument (); 338 CONTEXT_PATH_MODEL.remove(0, CONTEXT_PATH_MODEL.getLength()); 339 ProjectWebModule wm = (ProjectWebModule) project.getLookup().lookup(ProjectWebModule.class); 340 String contextPath = wm.getContextPath(); 341 if (contextPath != null) { 342 CONTEXT_PATH_MODEL.insertString(0, contextPath, null); 343 } 344 } catch (BadLocationException exc) { 345 } 347 } 348 349 public void save() { 350 try { 351 ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 353 public Object run() throws IOException { 354 storeProperties(); 355 return null; 356 } 357 }); 358 ProjectManager.getDefault().saveProject(project); 360 361 if (newFrameworks != null) { 364 for(int i = 0; i < newFrameworks.size(); i++) 365 ((WebFrameworkProvider) newFrameworks.get(i)).extend(project.getAPIWebModule()); 366 367 newFrameworks.clear(); 368 } 369 370 if (cp != null) { 374 ProjectWebModule wm = (ProjectWebModule) project.getLookup().lookup(ProjectWebModule.class); 375 String oldCP = wm.getContextPath(serverId); 376 if (!cp.equals(oldCP)) 377 wm.setContextPath(serverId, cp); 378 } 379 } 380 catch (MutexException e) { 381 ErrorManager.getDefault().notify((IOException )e.getException()); 382 } 383 catch ( IOException ex ) { 384 ErrorManager.getDefault().notify( ex ); 385 } 386 } 387 388 private void storeProperties() throws IOException { 389 391 resolveProjectDependencies(); 393 394 storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL ); 396 storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL ); 397 398 if(needsUpdate) { 400 ClassPathUiSupport.ClassPathTableModel cptm = getJavaClassPathModel(); 402 403 ArrayList cpItemsToRemove = new ArrayList(); 404 for(int i = 0; i < cptm.getRowCount(); i++) { 405 Object item = cptm.getValueAt(i,0); 406 if (item instanceof ClassPathSupport.Item) { 407 ClassPathSupport.Item cpti = (ClassPathSupport.Item)item; 408 String propertyName = cpti.getReference(); 409 if(propertyName != null) { 410 String libname = propertyName.substring("${libs.".length()); 411 if(libname.indexOf(".classpath}") != -1) libname = libname.substring(0, libname.indexOf(".classpath}")); 412 413 if("servlet24".equals(libname) || "jsp20".equals(libname)) { cpItemsToRemove.add(cpti); 415 } 416 } 417 } 418 } 419 420 Iterator remove = cpItemsToRemove.iterator(); 422 while(remove.hasNext()) { 423 ClassPathSupport.Item cpti = (ClassPathSupport.Item)remove.next(); 424 cptm.getDefaultListModel().removeElement(cpti); 425 } 426 427 } 430 431 String [] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ), ClassPathSupport.TAG_WEB_MODULE_LIBRARIES ); 433 String [] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ), null ); 434 String [] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ), null ); 435 String [] war_includes = cs.encodeToStrings( WarIncludesUiSupport.getIterator( WAR_CONTENT_ADDITIONAL_MODEL ), ClassPathSupport.TAG_WEB_MODULE__ADDITIONAL_LIBRARIES ); 436 437 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 439 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 440 441 if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) { 443 JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); } 445 446 projectGroup.store( projectProperties ); 448 privateGroup.store( privateProperties ); 449 450 if(needsUpdate) { 452 javac_test_cp = new String [] { 454 "${javac.classpath}:", "${build.classes.dir}:", "${libs.junit.classpath}", }; 458 run_test_cp = new String [] { 459 "${javac.test.classpath}:", "${build.test.classes.dir}", }; 462 projectProperties.setProperty(DEBUG_TEST_CLASSPATH, new String [] { 463 "${run.test.classpath}", }); 465 466 needsUpdate = false; 467 } 468 469 projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp ); 471 projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp ); 472 projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); 473 474 projectProperties.setProperty( WAR_CONTENT_ADDITIONAL, war_includes ); 475 476 SpecificationVersion sourceLevel = (SpecificationVersion) JAVAC_SOURCE_MODEL.getSelectedItem(); 478 PlatformUiSupport.storePlatform (projectProperties, updateHelper, PLATFORM_MODEL.getSelectedItem(), sourceLevel); 479 480 if ( NO_DEPENDENCIES_MODEL.isSelected() ) { projectProperties.remove( NO_DEPENDENCIES ); } 484 485 if (J2EE_SERVER_INSTANCE_MODEL.getSelectedItem() != null) { 487 setNewServerInstanceValue(J2eePlatformUiSupport.getServerInstanceID(J2EE_SERVER_INSTANCE_MODEL.getSelectedItem()), project, projectProperties, privateProperties); 488 } 489 490 try { 492 String cp = CONTEXT_PATH_MODEL.getText(0, CONTEXT_PATH_MODEL.getLength()); 493 if (cp == null) { 494 cp = "/" + PropertyUtils.getUsablePropertyName(project.getName()); } else if (!isCorrectCP(cp)) { 496 if (cp.startsWith("/")) cp = cp.substring(1); 498 cp = "/" + PropertyUtils.getUsablePropertyName(cp); } 500 501 setNewContextPathValue(cp, project, projectProperties, privateProperties); 502 } catch (BadLocationException exc) { 503 } 505 506 storeAdditionalProperties(projectProperties); 507 508 ArrayList libs = new ArrayList (); 509 libs.addAll(ClassPathUiSupport.getList(JAVAC_CLASSPATH_MODEL.getDefaultListModel())); 510 libs.addAll(WarIncludesUiSupport.getList(WAR_CONTENT_ADDITIONAL_MODEL)); 511 512 storeLibrariesLocations (libs.iterator(), privateProperties); 513 514 updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); 516 updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); 517 518 } 519 520 private static boolean isCorrectCP(String contextPath) { 521 if (contextPath.length() == 0) { 522 return true; 523 } else if (!contextPath.startsWith("/")) { return false; 525 } else if (contextPath.endsWith("/")) { return false; 527 } else if (contextPath.indexOf("//") >= 0) { return false; 529 } else if (contextPath.indexOf(' ') >= 0) { return false; 531 } 532 return true; 533 } 534 535 private void storeAdditionalProperties(EditableProperties projectProperties) { 536 for (Iterator i = additionalProperties.keySet().iterator(); i.hasNext();) { 537 String key = i.next().toString(); 538 projectProperties.put(key, additionalProperties.getProperty(key)); 539 } 540 } 541 542 544 public static String getAntPropertyName( String property ) { 545 if ( property != null && 546 property.startsWith( "${" ) && property.endsWith( "}" ) ) { return property.substring( 2, property.length() - 1 ); 549 } 550 else { 551 return property; 552 } 553 } 554 555 static boolean isAntProperty (String string) { 556 return string != null && string.startsWith( "${" ) && string.endsWith( "}" ); } 558 559 562 private void resolveProjectDependencies() { 563 564 Set oldArtifacts = new HashSet(); 566 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 567 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.Item.PATH_IN_WAR_LIB ) ); 568 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 569 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 570 571 Set newArtifacts = new HashSet(); 572 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ) ); 573 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) ); 574 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) ); 575 576 Set removed = new HashSet( oldArtifacts ); 578 removed.removeAll( newArtifacts ); 579 Set added = new HashSet(newArtifacts); 580 added.removeAll(oldArtifacts); 581 582 for( Iterator it = removed.iterator(); it.hasNext(); ) { 585 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 586 if ( item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT || 587 item.getType() == ClassPathSupport.Item.TYPE_JAR ) { 588 refHelper.destroyReference(item.getReference()); 589 } 590 } 591 592 EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 594 boolean changed = false; 595 596 for( Iterator it = removed.iterator(); it.hasNext(); ) { 597 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 598 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 599 String prop = item.getReference(); 601 prop = prop.substring(2, prop.length()-1); 602 ep.remove(prop); 603 changed = true; 604 } 605 } 606 File projDir = FileUtil.toFile(updateHelper.getAntProjectHelper().getProjectDirectory()); 607 for( Iterator it = added.iterator(); it.hasNext(); ) { 608 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 609 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 610 String prop = cs.getLibraryReference( item ); 613 prop = prop.substring(2, prop.length()-1); String value = relativizeLibraryClasspath(prop, projDir); 615 if (value != null) { 616 ep.setProperty(prop, value); 617 ep.setComment(prop, new String []{ 618 "# Property "+prop+" is set here just to make sharing of project simpler.", "# The library definition has always preference over this property."}, false); changed = true; 622 } 623 } 624 } 625 if (changed) { 626 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 627 } 628 } 629 630 636 private String relativizeLibraryClasspath(String property, File projectDir) { 637 String value = PropertyUtils.getGlobalProperties().getProperty(property); 638 if (value == null) { 640 return null; 641 } 642 String [] paths = PropertyUtils.tokenizePath(value); 643 StringBuffer sb = new StringBuffer (); 644 for (int i=0; i<paths.length; i++) { 645 File f = updateHelper.getAntProjectHelper().resolveFile(paths[i]); 646 if (CollocationQuery.areCollocated(f, projectDir)) { 647 sb.append(PropertyUtils.relativizeFile(projectDir, f)); 648 } else { 649 return null; 650 } 651 if (i+1<paths.length) { 652 sb.append(File.pathSeparatorChar); 653 } 654 } 655 if (sb.length() == 0) { 656 return null; 657 } else { 658 return sb.toString(); 659 } 660 } 661 662 private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException { 663 Vector data = tableModel.getDataVector(); 664 URL [] rootURLs = new URL [data.size()]; 665 String []rootLabels = new String [data.size()]; 666 for (int i=0; i<data.size();i++) { 667 File f = ((File )((Vector)data.elementAt(i)).elementAt(0)); 668 rootURLs[i] = WebProjectUtil.getRootURL(f,null); 669 rootLabels[i] = (String ) ((Vector)data.elementAt(i)).elementAt(1); 670 } 671 roots.putRoots(rootURLs,rootLabels); 672 } 673 674 public Object get(String propertyName) { 675 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 676 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 677 678 if (J2EE_SERVER_INSTANCE.equals(propertyName)) 679 return privateProperties.getProperty(J2EE_SERVER_INSTANCE); 680 else 681 return projectProperties.getProperty(propertyName); 682 683 } 685 686 public void put( String propertyName, String value ) { 687 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 688 projectProperties.put(propertyName, value); 689 if (J2EE_SERVER_INSTANCE.equals (propertyName)) { 690 projectProperties.put (J2EE_SERVER_TYPE, Deployment.getDefault ().getServerID ((String ) value)); 691 } 692 } 693 694 public void store() { 695 save(); 696 } 697 698 public static void setServerInstance(final Project project, final UpdateHelper helper, final String serverInstanceID) { 699 ProjectManager.mutex().writeAccess(new Runnable () { 700 public void run() { 701 try { 702 EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 703 EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 704 setNewServerInstanceValue(serverInstanceID, project, projectProps, privateProps); 705 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 706 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 707 ProjectManager.getDefault().saveProject(project); 708 } 709 catch (IOException e) { 710 ErrorManager.getDefault().notify(e); 711 } 712 } 713 }); 714 } 715 716 717 void putAdditionalProperty(String propertyName, String propertyValue) { 718 additionalProperties.setProperty(propertyName, propertyValue); 719 } 720 721 private static void setNewServerInstanceValue(String newServInstID, Project project, EditableProperties projectProps, EditableProperties privateProps) { 722 String oldServInstID = privateProps.getProperty(J2EE_SERVER_INSTANCE); 724 if (oldServInstID != null) { 725 J2eePlatform oldJ2eePlatform = Deployment.getDefault().getJ2eePlatform(oldServInstID); 726 if (oldJ2eePlatform != null) { 727 ((WebProject)project).unregisterJ2eePlatformListener(oldJ2eePlatform); 728 } 729 } 730 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(newServInstID); 731 if (j2eePlatform == null) { 732 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "J2EE platform is null."); 735 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 739 740 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 741 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH); 742 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH); 743 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH); 744 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JSR109_SUPPORT); 745 746 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 747 return; 748 } 749 ((WebProject) project).registerJ2eePlatformListener(j2eePlatform); 750 String classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries()); 751 privateProps.setProperty(J2EE_PLATFORM_CLASSPATH, classpath); 752 753 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) { 755 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE); 756 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH, 757 Utils.toClasspathString(wsClasspath)); 758 } else { 759 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 760 } 761 762 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSGEN)) { 763 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSGEN); 764 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH, 765 Utils.toClasspathString(wsClasspath)); 766 } else { 767 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH); 768 } 769 770 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSIMPORT)) { 771 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSIMPORT); 772 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH, 773 Utils.toClasspathString(wsClasspath)); 774 } else { 775 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH); 776 } 777 778 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSIT)) { 779 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSIT); 780 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSIT_CLASSPATH, 781 Utils.toClasspathString(wsClasspath)); 782 } else { 783 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIT_CLASSPATH); 784 } 785 786 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP)) { 787 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_JWSDP); 788 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH, 789 Utils.toClasspathString(wsClasspath)); 790 } else { 791 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH); 792 } 793 794 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109)) { 796 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_JSR109_SUPPORT, 797 "true"); } else { 799 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JSR109_SUPPORT); 800 } 801 802 projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID)); 804 805 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 807 808 File projectFolder = FileUtil.toFile(project.getProjectDirectory()); 810 try { 811 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.WAR, newServInstID); } catch (IOException ioe) { 813 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 814 } 815 File antDeployPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(newServInstID); 816 if (antDeployPropsFile == null) { 817 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 818 } else { 819 privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, antDeployPropsFile.getAbsolutePath()); 820 } 821 } 822 823 private static void setNewContextPathValue(String contextPath, Project project, EditableProperties projectProps, EditableProperties privateProps) { 824 if (contextPath == null) 825 return; 826 827 cp = contextPath; 828 serverId = privateProps.getProperty(J2EE_SERVER_INSTANCE); 829 } 830 831 public ClassPathUiSupport.ClassPathTableModel getJavaClassPathModel() { 832 return JAVAC_CLASSPATH_MODEL; 833 } 834 835 851 public static void storeLibrariesLocations (Iterator classpath, EditableProperties privateProps) { 852 ArrayList exLibs = new ArrayList (); 853 Iterator propKeys = privateProps.keySet().iterator(); 854 while (propKeys.hasNext()) { 855 String key = (String ) propKeys.next(); 856 if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || (key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { exLibs.add(key); 859 } 860 } 861 while (classpath.hasNext()) { 862 ClassPathSupport.Item item = (Item)classpath.next(); 863 ArrayList files = new ArrayList (); 864 ArrayList dirs = new ArrayList (); 865 getFilesForItem (item, files, dirs); 866 String key; 867 if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) { 868 String ref = item.getType() == ClassPathSupport.Item.TYPE_LIBRARY ? item.getRaw() : item.getReference(); 869 for (int i = 0; i < files.size(); i++) { 870 File f = (File ) files.get(i); 871 key = getAntPropertyName(ref)+".libfile." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 874 } 875 } 876 if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) { 877 String ref = item.getType() == ClassPathSupport.Item.TYPE_LIBRARY ? item.getRaw() : item.getReference(); 878 for (int i = 0; i < dirs.size(); i++) { 879 File f = (File ) dirs.get(i); 880 key = getAntPropertyName(ref)+".libdir." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 883 } 884 } 885 } 886 Iterator unused = exLibs.iterator(); 887 while (unused.hasNext()) { 888 privateProps.remove(unused.next()); 889 } 890 } 891 892 public static final void getFilesForItem (ClassPathSupport.Item item, List files, List dirs) { 893 if (item.isBroken()) { 894 return ; 895 } 896 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 897 List roots = item.getLibrary().getContent("classpath"); for (Iterator it = roots.iterator(); it.hasNext();) { 899 URL rootUrl = (URL ) it.next(); 900 FileObject root = URLMapper.findFileObject (rootUrl); 901 902 if (root == null) 904 continue; 905 906 if ("jar".equals(rootUrl.getProtocol())) { root = FileUtil.getArchiveFile (root); 908 } 909 File f = FileUtil.toFile(root); 910 if (f != null) { 911 if (f.isFile()) { 912 files.add(f); 913 } else { 914 dirs.add(f); 915 } 916 } 917 } 918 } 919 if (item.getType() == ClassPathSupport.Item.TYPE_JAR) { 920 File root = item.getFile(); 921 if (root != null) { 922 if (root.isFile()) { 923 files.add(root); 924 } else { 925 dirs.add(root); 926 } 927 } 928 } 929 if (item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT) { 930 String artifactFolder = item.getArtifact().getScriptLocation().getParent(); 931 URI roots[] = item.getArtifact().getArtifactLocations(); 932 for (int i = 0; i < roots.length; i++) { 933 String root = artifactFolder + File.separator + roots [i]; 934 if (root.endsWith(File.separator)) { 935 dirs.add(new File (root)); 936 } else { 937 files.add(new File (root)); 938 } 939 } 940 } 941 } 942 943 public void setNewFrameworks(List frameworks) { 944 newFrameworks = frameworks; 945 } 946 } 947 | Popular Tags |