1 19 20 package org.netbeans.modules.j2ee.clientproject.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.ArrayList ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Properties ; 32 import java.util.Set ; 33 import java.util.Vector ; 34 import javax.swing.ButtonModel ; 35 import javax.swing.ComboBoxModel ; 36 import javax.swing.DefaultListModel ; 37 import javax.swing.JButton ; 38 import javax.swing.JToggleButton ; 39 import javax.swing.ListCellRenderer ; 40 import javax.swing.table.DefaultTableModel ; 41 import javax.swing.text.BadLocationException ; 42 import javax.swing.text.Document ; 43 import org.netbeans.api.project.Project; 44 import org.netbeans.api.project.ProjectManager; 45 import org.netbeans.api.queries.CollocationQuery; 46 import org.netbeans.modules.j2ee.clientproject.AppClientProject; 47 import org.netbeans.modules.j2ee.clientproject.AppClientProjectUtil; 48 import org.netbeans.modules.j2ee.clientproject.SourceRoots; 49 import org.netbeans.modules.j2ee.clientproject.UpdateHelper; 50 import org.netbeans.modules.j2ee.clientproject.Utils; 51 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; 52 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 53 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 54 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 55 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 56 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 57 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 58 import org.netbeans.modules.websvc.api.client.WebServicesClientConstants; 59 import org.netbeans.spi.project.support.ant.AntProjectHelper; 60 import org.netbeans.spi.project.support.ant.EditableProperties; 61 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 62 import org.netbeans.spi.project.support.ant.PropertyUtils; 63 import org.netbeans.spi.project.support.ant.ReferenceHelper; 64 import org.netbeans.spi.project.support.ant.ui.StoreGroup; 65 import org.openide.DialogDisplayer; 66 import org.openide.ErrorManager; 67 import org.openide.NotifyDescriptor; 68 import org.openide.filesystems.FileObject; 69 import org.openide.filesystems.FileUtil; 70 import org.openide.filesystems.URLMapper; 71 import org.openide.modules.SpecificationVersion; 72 import org.openide.util.Mutex; 73 import org.openide.util.MutexException; 74 import org.openide.util.NbBundle; 75 76 79 public class AppClientProjectProperties { 80 81 private static final Integer BOOLEAN_KIND_TF = new Integer ( 0 ); 84 private static final Integer BOOLEAN_KIND_YN = new Integer ( 1 ); 85 private static final Integer BOOLEAN_KIND_ED = new Integer ( 2 ); 86 private Integer javacDebugBooleanKind; 87 private Integer javadocPreviewBooleanKind; 88 89 public static final String JAVA_EE_5 = "1.5"; public static final String J2EE_1_4 = "1.4"; public static final String J2EE_1_3 = "1.3"; 93 public static final String CAR_PROJECT_NAME = "j2ee.clientproject.name"; public static final String JAVA_PLATFORM = "platform.active"; public static final String J2EE_PLATFORM = "j2ee.platform"; 98 public static final String SOURCE_ROOT = "source.root"; public static final String BUILD_FILE = "buildfile"; public static final String META_INF = "meta.inf"; public static final String SRC_DIR = "src.dir"; public static final String LIBRARIES_DIR = "lib.dir"; public static final String RESOURCE_DIR = "resource.dir"; public static final String DIST_EAR_JAR = "dist.ear.jar"; public static final String JAR_NAME = "jar.name"; public static final String BUILD_EAR_CLASSES_DIR = "build.ear.classes.dir"; 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"; 111 112 114 public static final String DIST_DIR = "dist.dir"; public static final String DIST_JAR = "dist.jar"; public static final String JAVAC_CLASSPATH = "javac.classpath"; public static final String RUN_CLASSPATH = "run.classpath"; public static final String RUN_JVM_ARGS = "run.jvmargs"; public static final String RUN_WORK_DIR = "work.dir"; public static final String DEBUG_CLASSPATH = "debug.classpath"; public static final String JAR_COMPRESS = "jar.compress"; public static final String MAIN_CLASS = "main.class"; public static final String JAVAC_SOURCE = "javac.source"; public static final String JAVAC_TARGET = "javac.target"; public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; 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 RUN_TEST_CLASSPATH = "run.test.classpath"; public static final String BUILD_DIR = "build.dir"; public static final String BUILD_CLASSES_DIR = "build.classes.dir"; 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 BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; public static final String NO_DEPENDENCIES="no.dependencies"; public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; 139 140 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"; 152 public static final String CLIENT_NAME = "j2ee.clientName"; 154 public static final String APPLICATION_ARGS = "application.args"; public static final String JAVADOC_PREVIEW="javadoc.preview"; public static final String DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; 159 public static final String ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; 161 public static final String APPCLIENT_MAINCLASS_ARGS = "j2ee.appclient.mainclass.args"; 163 public static final String APPCLIENT_TOOL_RUNTIME = "j2ee.appclient.tool.runtime"; public static final String APPCLIENT_TOOL_MAINCLASS = "j2ee.appclient.tool.mainclass"; public static final String APPCLIENT_TOOL_JVMOPTS = "j2ee.appclient.tool.jvmoptions"; public static final String APPCLIENT_TOOL_ARGS = "j2ee.appclient.tool.args"; 168 172 public static final String J2EE_PLATFORM_APPCLIENT_ARGS = "j2ee.appclient.args"; 174 public static final String [] WELL_KNOWN_PATHS = new String [] { 176 "${" + JAVAC_CLASSPATH + "}", "${" + JAVAC_TEST_CLASSPATH + "}", "${" + RUN_CLASSPATH + "}", "${" + RUN_TEST_CLASSPATH + "}", "${" + BUILD_CLASSES_DIR + "}", "${" + BUILD_TEST_CLASSES_DIR + "}", }; 183 184 public static final String LIBRARY_PREFIX = "${libs."; public static final String LIBRARY_SUFFIX = ".classpath}"; public static final String ANT_ARTIFACT_PREFIX = "${reference."; 190 ClassPathSupport cs; 191 192 193 197 199 DefaultTableModel SOURCE_ROOTS_MODEL; 201 DefaultTableModel TEST_ROOTS_MODEL; 202 Document META_INF_MODEL; 203 ComboBoxModel JAVAC_SOURCE_MODEL; 204 205 ClassPathUiSupport.ClassPathTableModel JAVAC_CLASSPATH_MODEL; 207 DefaultListModel JAVAC_TEST_CLASSPATH_MODEL; 208 DefaultListModel RUN_CLASSPATH_MODEL; 209 DefaultListModel RUN_TEST_CLASSPATH_MODEL; 210 ComboBoxModel PLATFORM_MODEL; 211 ListCellRenderer CLASS_PATH_LIST_RENDERER; 212 ListCellRenderer PLATFORM_LIST_RENDERER; 213 ListCellRenderer JAVAC_SOURCE_RENDERER; 214 215 AppClientClassPathUi.ClassPathTableCellItemRenderer CLASS_PATH_TABLE_ITEM_RENDERER; 216 217 218 ButtonModel JAVAC_DEPRECATION_MODEL; 220 ButtonModel JAVAC_DEBUG_MODEL; 221 ButtonModel NO_DEPENDENCIES_MODEL; 222 Document JAVAC_COMPILER_ARG_MODEL; 223 224 226 Document DIST_JAR_MODEL; 228 Document BUILD_CLASSES_EXCLUDES_MODEL; 229 ButtonModel JAR_COMPRESS_MODEL; 230 231 ButtonModel JAVADOC_PRIVATE_MODEL; 233 ButtonModel JAVADOC_NO_TREE_MODEL; 234 ButtonModel JAVADOC_USE_MODEL; 235 ButtonModel JAVADOC_NO_NAVBAR_MODEL; 236 ButtonModel JAVADOC_NO_INDEX_MODEL; 237 ButtonModel JAVADOC_SPLIT_INDEX_MODEL; 238 ButtonModel JAVADOC_AUTHOR_MODEL; 239 ButtonModel JAVADOC_VERSION_MODEL; 240 Document JAVADOC_WINDOW_TITLE_MODEL; 241 ButtonModel JAVADOC_PREVIEW_MODEL; 242 Document JAVADOC_ADDITIONALPARAM_MODEL; 243 244 Document MAIN_CLASS_MODEL; 246 Document APPLICATION_ARGS_MODEL; 247 Document RUN_JVM_ARGS_MODEL; 248 Document RUN_WORK_DIR_MODEL; 249 250 ComboBoxModel J2EE_SERVER_INSTANCE_MODEL; 251 ComboBoxModel J2EE_PLATFORM_MODEL; 252 253 254 255 257 private final AppClientProject project; 259 private final UpdateHelper updateHelper; 260 private final PropertyEvaluator evaluator; 261 private final ReferenceHelper refHelper; 262 private final GeneratedFilesHelper genFileHelper; 263 264 private final StoreGroup privateGroup; 265 private final StoreGroup projectGroup; 266 267 private final Properties additionalProperties; 268 269 public static final String JAVA_SOURCE_BASED = "java.source.based"; 270 271 AppClientProject getProject() { 272 return project; 273 } 274 275 276 public AppClientProjectProperties( AppClientProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper ) { 277 this.project = project; 278 this.updateHelper = updateHelper; 279 this.evaluator = evaluator; 280 this.refHelper = refHelper; 281 this.genFileHelper = genFileHelper; 282 this.cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), WELL_KNOWN_PATHS, LIBRARY_PREFIX, LIBRARY_SUFFIX, ANT_ARTIFACT_PREFIX ); 283 284 privateGroup = new StoreGroup(); 285 projectGroup = new StoreGroup(); 286 287 additionalProperties = new Properties (); 288 289 init(); } 291 292 294 private void init() { 295 296 CLASS_PATH_LIST_RENDERER = new AppClientClassPathUi.ClassPathListCellRenderer( evaluator ); 297 CLASS_PATH_TABLE_ITEM_RENDERER = new AppClientClassPathUi.ClassPathTableCellItemRenderer( evaluator ); 298 299 SOURCE_ROOTS_MODEL = AppClientSourceRootsUi.createModel( project.getSourceRoots() ); 301 TEST_ROOTS_MODEL = AppClientSourceRootsUi.createModel( project.getTestSourceRoots() ); 302 META_INF_MODEL = projectGroup.createStringDocument( evaluator, META_INF ); 303 304 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 306 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 307 308 JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createTableModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) ); 309 JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 310 RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_CLASSPATH ), null ) ); 311 RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 312 PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); 313 PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); 314 JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(J2EE_PLATFORM)); 315 JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer (); 316 317 JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION ); 319 320 Integer [] kind = new Integer [1]; 323 JAVAC_DEBUG_MODEL = createToggleButtonModel( evaluator, JAVAC_DEBUG, kind); 324 javacDebugBooleanKind = kind[0]; 325 326 NO_DEPENDENCIES_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, NO_DEPENDENCIES ); 327 JAVAC_COMPILER_ARG_MODEL = projectGroup.createStringDocument( evaluator, JAVAC_COMPILER_ARG ); 328 329 DIST_JAR_MODEL = projectGroup.createStringDocument( evaluator, DIST_JAR ); 331 BUILD_CLASSES_EXCLUDES_MODEL = projectGroup.createStringDocument( evaluator, BUILD_CLASSES_EXCLUDES ); 332 JAR_COMPRESS_MODEL = projectGroup.createToggleButtonModel( evaluator, JAR_COMPRESS ); 333 334 JAVADOC_PRIVATE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_PRIVATE ); 336 JAVADOC_NO_TREE_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_TREE ); 337 JAVADOC_USE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_USE ); 338 JAVADOC_NO_NAVBAR_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_NAVBAR ); 339 JAVADOC_NO_INDEX_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_INDEX ); 340 JAVADOC_SPLIT_INDEX_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_SPLIT_INDEX ); 341 JAVADOC_AUTHOR_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_AUTHOR ); 342 JAVADOC_VERSION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_VERSION ); 343 JAVADOC_WINDOW_TITLE_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_WINDOW_TITLE ); 344 JAVADOC_PREVIEW_MODEL = createToggleButtonModel ( evaluator, JAVADOC_PREVIEW, kind); 347 javadocPreviewBooleanKind = kind[0]; 348 349 JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM ); 350 MAIN_CLASS_MODEL = projectGroup.createStringDocument( evaluator, MAIN_CLASS ); 352 APPLICATION_ARGS_MODEL = privateGroup.createStringDocument( evaluator, APPLICATION_ARGS ); 353 RUN_JVM_ARGS_MODEL = projectGroup.createStringDocument( evaluator, RUN_JVM_ARGS ); 354 RUN_WORK_DIR_MODEL = privateGroup.createStringDocument( evaluator, RUN_WORK_DIR ); 355 356 J2EE_SERVER_INSTANCE_MODEL = J2eePlatformUiSupport.createPlatformComboBoxModel( 357 privateProperties.getProperty(J2EE_SERVER_INSTANCE), projectProperties.getProperty(J2EE_PLATFORM)); 358 J2EE_PLATFORM_MODEL = J2eePlatformUiSupport.createSpecVersionComboBoxModel( 359 projectProperties.getProperty( J2EE_PLATFORM )); 360 } 361 362 public void save() { 363 try { 364 Boolean result = (Boolean ) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 366 public Object run() throws IOException { 367 if ((genFileHelper.getBuildScriptState(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 368 AppClientProject.class.getResource("resources/build-impl.xsl"), getProject().findJaxWsFileObject()) & 370 GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) { if (showModifiedMessage (NbBundle.getMessage(AppClientProjectProperties.class,"TXT_ModifiedTitle"))) { 372 FileObject fo = updateHelper.getAntProjectHelper().getProjectDirectory(). 374 getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH); 375 if (fo != null) { 376 fo.delete(); 377 } 378 } 379 else { 380 return Boolean.FALSE; 381 } 382 } 383 storeProperties(); 384 return Boolean.TRUE; 385 } 386 }); 387 if (result == Boolean.TRUE) { 389 ProjectManager.getDefault().saveProject(project); 390 } 391 } 392 catch (MutexException e) { 393 ErrorManager.getDefault().notify((IOException )e.getException()); 394 } 395 catch ( IOException ex ) { 396 ErrorManager.getDefault().notify( ex ); 397 } 398 } 399 400 401 402 private void storeProperties() throws IOException { 403 405 resolveProjectDependencies(); 407 408 String [] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ); 410 String [] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ), null ); 411 String [] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ), null ); 412 String [] run_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_CLASSPATH_MODEL ), null ); 413 414 storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL ); 416 storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL ); 417 418 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 420 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 421 422 if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) { 424 JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); } 426 427 projectGroup.store( projectProperties ); 429 privateGroup.store( privateProperties ); 430 431 privateProperties.setProperty(JAVAC_DEBUG, encodeBoolean (JAVAC_DEBUG_MODEL.isSelected(), javacDebugBooleanKind)); 435 436 privateProperties.setProperty(JAVADOC_PREVIEW, encodeBoolean (JAVADOC_PREVIEW_MODEL.isSelected(), javadocPreviewBooleanKind)); 440 441 projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp ); 443 projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp ); 444 projectProperties.setProperty( RUN_CLASSPATH, run_cp ); 445 projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); 446 447 SpecificationVersion sourceLevel = (SpecificationVersion) JAVAC_SOURCE_MODEL.getSelectedItem(); 449 PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), sourceLevel); 450 451 if ( NO_DEPENDENCIES_MODEL.isSelected() ) { projectProperties.remove( NO_DEPENDENCIES ); } 455 456 if ( getDocumentText( RUN_WORK_DIR_MODEL ).trim().equals( "" ) ) { privateProperties.remove( RUN_WORK_DIR ); } 459 460 if (getDocumentText(MAIN_CLASS_MODEL).trim().equals("")) { projectProperties.remove(MAIN_CLASS); } 463 464 if (J2EE_SERVER_INSTANCE_MODEL.getSelectedItem() != null) { 466 setNewServerInstanceValue(J2eePlatformUiSupport.getServerInstanceID(J2EE_SERVER_INSTANCE_MODEL.getSelectedItem()), project, projectProperties, privateProperties); 467 } 468 469 storeAdditionalProperties(projectProperties); 470 List <ClassPathSupport.Item> cpItems = ClassPathUiSupport.getList(JAVAC_CLASSPATH_MODEL.getDefaultListModel()); 471 storeLibrariesLocations(cpItems.iterator(), privateProperties); 472 473 updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); 475 updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); 476 477 } 478 479 private void storeAdditionalProperties(EditableProperties projectProperties) { 480 for (Iterator i = additionalProperties.keySet().iterator(); i.hasNext();) { 481 String key = i.next().toString(); 482 projectProperties.put(key, additionalProperties.getProperty(key)); 483 } 484 } 485 486 private static String getDocumentText( Document document ) { 487 try { 488 return document.getText( 0, document.getLength() ); 489 } 490 catch( BadLocationException e ) { 491 return ""; } 493 } 494 495 498 private void resolveProjectDependencies() { 499 500 Set <ClassPathSupport.Item> oldArtifacts = new HashSet <ClassPathSupport.Item>(); 502 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 503 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) ); 504 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 505 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( RUN_CLASSPATH ), null ) ); 506 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 507 508 Set <ClassPathSupport.Item> newArtifacts = new HashSet <ClassPathSupport.Item>(); 509 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ) ); 510 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) ); 511 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_CLASSPATH_MODEL ) ); 512 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) ); 513 514 Set <ClassPathSupport.Item> removed = new HashSet <ClassPathSupport.Item>( oldArtifacts ); 516 removed.removeAll( newArtifacts ); 517 Set <ClassPathSupport.Item> added = new HashSet <ClassPathSupport.Item>(newArtifacts); 518 added.removeAll(oldArtifacts); 519 520 for( Iterator it = removed.iterator(); it.hasNext(); ) { 523 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 524 if ( item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT || 525 item.getType() == ClassPathSupport.Item.TYPE_JAR ) { 526 refHelper.destroyReference(item.getReference()); 527 } 528 } 529 530 EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 532 boolean changed = false; 533 534 for( Iterator it = removed.iterator(); it.hasNext(); ) { 535 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 536 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 537 String prop = item.getReference(); 539 prop = prop.substring(2, prop.length()-1); 540 ep.remove(prop); 541 changed = true; 542 } 543 } 544 File projDir = FileUtil.toFile(updateHelper.getAntProjectHelper().getProjectDirectory()); 545 for( Iterator it = added.iterator(); it.hasNext(); ) { 546 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 547 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY && !item.isBroken()) { 548 String prop = cs.getLibraryReference( item ); 551 prop = prop.substring(2, prop.length()-1); String value = relativizeLibraryClasspath(prop, projDir); 553 if (value != null) { 554 ep.setProperty(prop, value); 555 ep.setComment(prop, new String []{ 556 "# Property "+prop+" is set here just to make sharing of project simpler.", "# The library definition has always preference over this property."}, false); changed = true; 560 } 561 } 562 } 563 if (changed) { 564 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 565 } 566 } 567 568 574 private String relativizeLibraryClasspath(String property, File projectDir) { 575 String value = PropertyUtils.getGlobalProperties().getProperty(property); 576 if (value == null) { 578 return null; 579 } 580 String [] paths = PropertyUtils.tokenizePath(value); 581 StringBuffer sb = new StringBuffer (); 582 for (int i=0; i<paths.length; i++) { 583 File f = updateHelper.getAntProjectHelper().resolveFile(paths[i]); 584 if (CollocationQuery.areCollocated(f, projectDir)) { 585 sb.append(PropertyUtils.relativizeFile(projectDir, f)); 586 } else { 587 return null; 588 } 589 if (i+1<paths.length) { 590 sb.append(File.pathSeparatorChar); 591 } 592 } 593 if (sb.length() == 0) { 594 return null; 595 } else { 596 return sb.toString(); 597 } 598 } 599 600 private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException { 601 Vector data = tableModel.getDataVector(); 602 URL [] rootURLs = new URL [data.size()]; 603 String []rootLabels = new String [data.size()]; 604 for (int i=0; i<data.size();i++) { 605 File f = (File ) ((Vector )data.elementAt(i)).elementAt(0); 606 rootURLs[i] = AppClientProjectUtil.getRootURL(f,null); 607 rootLabels[i] = (String ) ((Vector )data.elementAt(i)).elementAt(1); 608 } 609 roots.putRoots(rootURLs,rootLabels); 610 } 611 612 613 public void putAdditionalProperty(String propertyName, String propertyValue) { 614 additionalProperties.setProperty(propertyName, propertyValue); 615 } 616 617 private static boolean showModifiedMessage (String title) { 618 String message = NbBundle.getMessage(AppClientProjectProperties.class,"TXT_Regenerate"); 619 JButton regenerateButton = new JButton (NbBundle.getMessage(AppClientProjectProperties.class,"CTL_RegenerateButton")); 620 regenerateButton.setDefaultCapable(true); 621 regenerateButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(AppClientProjectProperties.class,"AD_RegenerateButton")); 622 NotifyDescriptor d = new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE); 623 d.setTitle(title); 624 d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); 625 d.setOptions(new Object [] {regenerateButton, NotifyDescriptor.CANCEL_OPTION}); 626 return DialogDisplayer.getDefault().notify(d) == regenerateButton; 627 } 628 629 private static String encodeBoolean (boolean value, Integer kind) { 632 if ( kind == BOOLEAN_KIND_ED ) { 633 return value ? "on" : "off"; } 635 else if ( kind == BOOLEAN_KIND_YN ) { return value ? "yes" : "no"; } 638 else { 639 return value ? "true" : "false"; } 641 } 642 643 private static JToggleButton.ToggleButtonModel createToggleButtonModel (final PropertyEvaluator evaluator, final String propName, Integer [] kind) { 646 assert evaluator != null && propName != null && kind != null && kind.length == 1; 647 String value = evaluator.getProperty( propName ); 648 boolean isSelected = false; 649 if (value == null) { 650 isSelected = true; 651 } 652 else { 653 String lowercaseValue = value.toLowerCase(); 654 if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { kind[0] = BOOLEAN_KIND_YN; 656 } 657 else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { kind[0] = BOOLEAN_KIND_ED; 659 } 660 else { 661 kind[0] = BOOLEAN_KIND_TF; 662 } 663 664 if ( lowercaseValue.equals( "true") || lowercaseValue.equals( "yes") || lowercaseValue.equals( "on") ) { isSelected = true; 668 } 669 } 670 JToggleButton.ToggleButtonModel bm = new JToggleButton.ToggleButtonModel (); 671 bm.setSelected(isSelected ); 672 return bm; 673 } 674 675 public static void setServerInstance(final Project project, final AntProjectHelper helper, final String serverInstanceID) { 676 ProjectManager.mutex().writeAccess(new Runnable () { 677 public void run() { 678 try { 679 EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 680 EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 681 setNewServerInstanceValue(serverInstanceID, project, projectProps, privateProps); 682 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 683 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 684 ProjectManager.getDefault().saveProject(project); 685 } 686 catch (IOException e) { 687 ErrorManager.getDefault().notify(); 688 } 689 } 690 }); 691 } 692 693 private static void setNewServerInstanceValue(String newServInstID, Project project, EditableProperties projectProps, EditableProperties privateProps) { 694 String oldServInstID = privateProps.getProperty(J2EE_SERVER_INSTANCE); 696 if (oldServInstID != null) { 697 J2eePlatform oldJ2eePlatform = Deployment.getDefault().getJ2eePlatform(oldServInstID); 698 if (oldJ2eePlatform != null) { 699 ((AppClientProject)project).unregisterJ2eePlatformListener(oldJ2eePlatform); 700 } 701 } 702 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(newServInstID); 703 if (j2eePlatform == null) { 704 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "J2EE platform is null."); 707 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 711 712 privateProps.remove(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 713 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 714 privateProps.remove("wa.copy.client.jar.from"); return; 716 } 717 ((AppClientProject)project).registerJ2eePlatformListener(j2eePlatform); 718 String classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries()); 719 privateProps.setProperty(J2EE_PLATFORM_CLASSPATH, classpath); 720 721 File [] accrt = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_APP_CLIENT_RUNTIME); 723 privateProps.setProperty(APPCLIENT_TOOL_RUNTIME, Utils.toClasspathString(accrt)); 724 String jvmOpts = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_JVM_OPTS); 725 if (jvmOpts != null) { 726 privateProps.setProperty(APPCLIENT_TOOL_JVMOPTS, jvmOpts); 727 } 728 String acMain = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS); 729 if (acMain != null) { 730 privateProps.setProperty(APPCLIENT_TOOL_MAINCLASS, acMain); 731 } 732 String args = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2EE_PLATFORM_APPCLIENT_ARGS); 733 if (args != null) { 734 privateProps.setProperty(AppClientProjectProperties.APPCLIENT_TOOL_ARGS, args); 735 } 736 737 String mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS_ARGS); 738 if (mainClassArgs != null && !mainClassArgs.equals("")) { 739 if (projectProps.getProperty(CLIENT_NAME) != null) { 740 projectProps.remove(CLIENT_NAME); 741 } 742 projectProps.put(APPCLIENT_MAINCLASS_ARGS, mainClassArgs); 743 } else if ((mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, CLIENT_NAME)) != null) { 744 if (projectProps.getProperty(APPCLIENT_MAINCLASS_ARGS) != null) { 745 projectProps.remove(APPCLIENT_MAINCLASS_ARGS); 746 } 747 projectProps.put(CLIENT_NAME, mainClassArgs); 748 } 749 750 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) { 752 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE); 753 privateProps.setProperty(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH, 754 Utils.toClasspathString(wsClasspath)); 755 } else { 756 privateProps.remove(WebServicesClientConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 757 } 758 759 projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID)); 761 762 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 764 765 File projectFolder = FileUtil.toFile(project.getProjectDirectory()); 767 try { 768 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.CLIENT, newServInstID); } catch (IOException ioe) { 770 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 771 } 772 File antDeployPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(newServInstID); 773 if (antDeployPropsFile == null) { 774 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 775 } else { 776 privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, antDeployPropsFile.getAbsolutePath()); 777 } 778 779 if ("J2EE".equals(Deployment.getDefault().getServerID(newServInstID))) { File asRoot = j2eePlatform.getPlatformRoots()[0]; 784 File exFile = new File (asRoot, "lib/javaee.jar"); InstanceProperties ip = InstanceProperties.getInstanceProperties(newServInstID); 786 if (exFile.exists()) { 787 privateProps.setProperty("wa.copy.client.jar.from", new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/generated/xml/j2ee-modules").getAbsolutePath()); } else { 790 privateProps.setProperty("wa.copy.client.jar.from", new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/applications/j2ee-modules").getAbsolutePath()); } 793 } else { 794 privateProps.remove("wa.copy.client.jar.from"); } 796 797 } 798 799 public static final void getFilesForItem (ClassPathSupport.Item item, List <File > files, List <File > dirs) { 800 if (item.isBroken()) { 801 return ; 802 } 803 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 804 @SuppressWarnings ("unchecked") 805 List <URL > roots = item.getLibrary().getContent("classpath"); for (Iterator it = roots.iterator(); it.hasNext();) { 807 URL rootUrl = (URL ) it.next(); 808 FileObject root = URLMapper.findFileObject (rootUrl); 809 if ("jar".equals(rootUrl.getProtocol())) { root = FileUtil.getArchiveFile (root); 811 } 812 File f = FileUtil.toFile(root); 813 if (f != null) { 814 if (f.isFile()) { 815 files.add(f); 816 } else { 817 dirs.add(f); 818 } 819 } 820 } 821 } 822 if (item.getType() == ClassPathSupport.Item.TYPE_JAR) { 823 File root = item.getFile(); 824 if (root != null) { 825 if (root.isFile()) { 826 files.add(root); 827 } else { 828 dirs.add(root); 829 } 830 } 831 } 832 if (item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT) { 833 String artifactFolder = item.getArtifact().getScriptLocation().getParent(); 834 URI roots[] = item.getArtifact().getArtifactLocations(); 835 for (int i = 0; i < roots.length; i++) { 836 String root = artifactFolder + File.separator + roots [i]; 837 if (root.endsWith(File.separator)) { 838 dirs.add(new File (root)); 839 } else { 840 files.add(new File (root)); 841 } 842 } 843 } 844 } 845 846 862 public static void storeLibrariesLocations(Iterator <ClassPathSupport.Item> classpath, EditableProperties privateProps) { 863 List <String > exLibs = new ArrayList <String >(); 864 Iterator propKeys = privateProps.keySet().iterator(); 865 while (propKeys.hasNext()) { 866 String key = (String ) propKeys.next(); 867 if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || (key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { exLibs.add(key); 870 } 871 } 872 while (classpath.hasNext()) { 873 ClassPathSupport.Item item = (ClassPathSupport.Item)classpath.next(); 874 List <File > files = new ArrayList <File >(); 875 List <File > dirs = new ArrayList <File >(); 876 getFilesForItem (item, files, dirs); 877 String key; 878 if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) { 879 String ref = item.getReference() == null ? item.getRaw() : item.getReference(); 880 for (int i = 0; i < files.size(); i++) { 881 File f = (File ) files.get(i); 882 key = getAntPropertyName(ref)+".libfile." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 885 } 886 } 887 if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) { 888 String ref = item.getReference() == null ? item.getRaw() : item.getReference(); 889 for (int i = 0; i < dirs.size(); i++) { 890 File f = (File ) dirs.get(i); 891 key = getAntPropertyName(ref)+".libdir." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 894 } 895 } 896 } 897 Iterator unused = exLibs.iterator(); 898 while (unused.hasNext()) { 899 privateProps.remove(unused.next()); 900 } 901 } 902 903 public static String getProperty(final String property, final AntProjectHelper helper, final String path) { 904 EditableProperties props = helper.getProperties(path); 905 return props.getProperty(property); 906 } 907 908 909 public static String getAntPropertyName( String property ) { 910 if ( property != null && 911 property.startsWith( "${" ) && property.endsWith( "}" ) ) { return property.substring( 2, property.length() - 1 ); 914 } 915 else { 916 return property; 917 } 918 } 919 920 } 921 | Popular Tags |