1 19 20 package org.netbeans.modules.j2ee.ejbjarproject.ui.customizer; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.math.BigDecimal ; 25 import java.net.MalformedURLException ; 26 import java.net.URI ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.HashSet ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Properties ; 33 import java.util.Set ; 34 import java.util.Vector ; 35 import javax.swing.ButtonModel ; 36 import javax.swing.ComboBoxModel ; 37 import javax.swing.DefaultListModel ; 38 import javax.swing.ListCellRenderer ; 39 import javax.swing.table.DefaultTableModel ; 40 import javax.swing.text.Document ; 41 import org.netbeans.api.queries.CollocationQuery; 42 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 43 import org.netbeans.modules.j2ee.ejbjarproject.SourceRoots; 44 import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper; 45 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 46 import org.openide.ErrorManager; 47 import org.openide.filesystems.FileUtil; 48 import org.openide.modules.SpecificationVersion; 49 import org.openide.util.MutexException; 50 import org.openide.util.Mutex; 51 import org.netbeans.api.project.Project; 52 import org.netbeans.api.project.ProjectManager; 53 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 54 import org.netbeans.spi.project.support.ant.AntProjectHelper; 55 import org.netbeans.spi.project.support.ant.EditableProperties; 56 import org.netbeans.spi.project.support.ant.ReferenceHelper; 57 import org.netbeans.spi.project.support.ant.ui.StoreGroup; 58 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 59 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 60 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 61 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 62 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; 63 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProject; 64 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectUtil; 65 import org.netbeans.modules.j2ee.ejbjarproject.Utils; 66 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 67 import org.netbeans.spi.project.support.ant.PropertyUtils; 68 import org.openide.filesystems.FileObject; 69 import org.openide.filesystems.URLMapper; 70 71 72 79 public class EjbJarProjectProperties { 80 81 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"; 85 public static final String EJB_PROJECT_NAME = "j2ee.ejbjarproject.name"; public static final String JAVA_PLATFORM = "platform.active"; public static final String J2EE_PLATFORM = "j2ee.platform"; 90 92 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_JAR = "dist.jar"; public static final String DIST_EAR_JAR = "dist.ear.jar"; public static final String JAVAC_CLASSPATH = "javac.classpath"; public static final String DEBUG_CLASSPATH = "debug.classpath"; 101 public static final String JAR_NAME = "jar.name"; public static final String JAR_COMPRESS = "jar.compress"; 104 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_TARGET = "javac.target"; 112 public static final String JAVAC_COMPILER_ARG = "javac.compilerargs"; public static final String SRC_DIR = "src.dir"; public static final String TEST_SRC_DIR = "test.src.dir"; public static final String META_INF = "meta.inf"; public static final String RESOURCE_DIR = "resource.dir"; public static final String BUILD_DIR = "build.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"; 123 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"; 129 public static final String NO_DEPENDENCIES="no.dependencies"; public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; 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"; 143 public static final String META_INF_EXCLUDES="meta.inf.excludes"; 145 public static final String JAVADOC_PREVIEW="javadoc.preview"; 148 public static final String DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; 150 public static final String ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; 152 public static final String JAVA_SOURCE_BASED = "java.source.based"; 153 154 public static final String [] WELL_KNOWN_PATHS = new String [] { 155 "${" + JAVAC_CLASSPATH + "}", "${" + JAVAC_TEST_CLASSPATH + "}", "${" + RUN_TEST_CLASSPATH + "}", "${" + BUILD_CLASSES_DIR + "}", "${" + BUILD_TEST_CLASSES_DIR + "}" }; 161 162 public static final String LIBRARY_PREFIX = "${libs."; public static final String LIBRARY_SUFFIX = ".classpath}"; public static final String ANT_ARTIFACT_PREFIX = "${reference."; 167 private ClassPathSupport cs; 168 169 170 174 176 DefaultTableModel SOURCE_ROOTS_MODEL; 178 DefaultTableModel TEST_ROOTS_MODEL; 179 Document META_INF_MODEL; 180 ComboBoxModel JAVAC_SOURCE_MODEL; 181 182 ClassPathUiSupport.ClassPathTableModel JAVAC_CLASSPATH_MODEL; 184 DefaultListModel JAVAC_TEST_CLASSPATH_MODEL; 185 186 DefaultListModel RUN_TEST_CLASSPATH_MODEL; 188 ComboBoxModel PLATFORM_MODEL; 189 ListCellRenderer CLASS_PATH_LIST_RENDERER; 190 ListCellRenderer PLATFORM_LIST_RENDERER; 191 EjbJarClassPathUi.ClassPathTableCellItemRenderer CLASS_PATH_TABLE_ITEM_RENDERER; 192 193 ButtonModel JAVAC_DEPRECATION_MODEL; 195 ButtonModel JAVAC_DEBUG_MODEL; 196 ButtonModel NO_DEPENDENCIES_MODEL; 197 Document JAVAC_COMPILER_ARG_MODEL; 198 199 201 Document DIST_JAR_MODEL; 203 Document BUILD_CLASSES_EXCLUDES_MODEL; 204 ButtonModel JAR_COMPRESS_MODEL; 205 206 ButtonModel JAVADOC_PRIVATE_MODEL; 208 ButtonModel JAVADOC_NO_TREE_MODEL; 209 ButtonModel JAVADOC_USE_MODEL; 210 ButtonModel JAVADOC_NO_NAVBAR_MODEL; 211 ButtonModel JAVADOC_NO_INDEX_MODEL; 212 ButtonModel JAVADOC_SPLIT_INDEX_MODEL; 213 ButtonModel JAVADOC_AUTHOR_MODEL; 214 ButtonModel JAVADOC_VERSION_MODEL; 215 Document JAVADOC_WINDOW_TITLE_MODEL; 216 ButtonModel JAVADOC_PREVIEW_MODEL; 217 Document JAVADOC_ADDITIONALPARAM_MODEL; 218 219 ComboBoxModel J2EE_SERVER_INSTANCE_MODEL; 221 ComboBoxModel J2EE_PLATFORM_MODEL; 222 223 225 private EjbJarProject project; 227 private PropertyEvaluator evaluator; 228 private ReferenceHelper refHelper; 229 private UpdateHelper updateHelper; 230 231 private StoreGroup privateGroup; 232 private StoreGroup projectGroup; 233 234 private Properties additionalProperties; 235 236 Project getProject() { 237 return project; 238 } 239 240 241 public EjbJarProjectProperties(EjbJarProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper ) { 242 this.project = project; 243 this.updateHelper = updateHelper; 244 this.evaluator = evaluator; 245 this.refHelper = refHelper; 246 247 cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), WELL_KNOWN_PATHS, LIBRARY_PREFIX, LIBRARY_SUFFIX, ANT_ARTIFACT_PREFIX ); 248 249 privateGroup = new StoreGroup(); 250 projectGroup = new StoreGroup(); 251 252 additionalProperties = new Properties (); 253 254 init(); } 256 257 259 private void init() { 260 261 CLASS_PATH_LIST_RENDERER = new EjbJarClassPathUi.ClassPathListCellRenderer( evaluator ); 262 CLASS_PATH_TABLE_ITEM_RENDERER = new EjbJarClassPathUi.ClassPathTableCellItemRenderer( evaluator ); 263 264 SOURCE_ROOTS_MODEL = EjbJarSourceRootsUi.createModel( project.getSourceRoots() ); 266 TEST_ROOTS_MODEL = EjbJarSourceRootsUi.createModel( project.getTestSourceRoots() ); 267 META_INF_MODEL = projectGroup.createStringDocument( evaluator, META_INF ); 268 269 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 271 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 272 273 JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createTableModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) ); 274 JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 275 RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 276 PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); 277 PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); 278 JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(J2EE_PLATFORM)); 279 280 JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION ); 282 JAVAC_DEBUG_MODEL = privateGroup.createToggleButtonModel( evaluator, JAVAC_DEBUG ); 283 NO_DEPENDENCIES_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, NO_DEPENDENCIES ); 284 JAVAC_COMPILER_ARG_MODEL = projectGroup.createStringDocument( evaluator, JAVAC_COMPILER_ARG ); 285 286 DIST_JAR_MODEL = projectGroup.createStringDocument( evaluator, DIST_JAR ); 288 BUILD_CLASSES_EXCLUDES_MODEL = projectGroup.createStringDocument( evaluator, BUILD_CLASSES_EXCLUDES ); 289 JAR_COMPRESS_MODEL = projectGroup.createToggleButtonModel( evaluator, JAR_COMPRESS ); 290 291 JAVADOC_PRIVATE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_PRIVATE ); 293 JAVADOC_NO_TREE_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_TREE ); 294 JAVADOC_USE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_USE ); 295 JAVADOC_NO_NAVBAR_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_NAVBAR ); 296 JAVADOC_NO_INDEX_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_INDEX ); 297 JAVADOC_SPLIT_INDEX_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_SPLIT_INDEX ); 298 JAVADOC_AUTHOR_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_AUTHOR ); 299 JAVADOC_VERSION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_VERSION ); 300 JAVADOC_WINDOW_TITLE_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_WINDOW_TITLE ); 301 JAVADOC_PREVIEW_MODEL = privateGroup.createToggleButtonModel( evaluator, JAVADOC_PREVIEW ); 302 JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM ); 303 304 J2EE_SERVER_INSTANCE_MODEL = J2eePlatformUiSupport.createPlatformComboBoxModel( 306 privateProperties.getProperty( J2EE_SERVER_INSTANCE )); 307 J2EE_PLATFORM_MODEL = J2eePlatformUiSupport.createSpecVersionComboBoxModel( 308 projectProperties.getProperty( J2EE_PLATFORM )); 309 } 310 311 public void save() { 312 try { 313 ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 315 public Object run() throws IOException { 316 storeProperties(); 317 return null; 318 } 319 }); 320 ProjectManager.getDefault().saveProject(project); 322 } 323 catch (MutexException e) { 324 ErrorManager.getDefault().notify((IOException )e.getException()); 325 } 326 catch ( IOException ex ) { 327 ErrorManager.getDefault().notify( ex ); 328 } 329 } 330 331 private void storeProperties() throws IOException { 332 334 resolveProjectDependenciesNew(); 336 337 String [] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ); 339 String [] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ), null ); 340 String [] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ), null ); 341 342 storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL ); 344 storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL ); 345 346 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 348 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 349 350 if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) { 352 JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); } 354 355 projectGroup.store( projectProperties ); 357 privateGroup.store( privateProperties ); 358 359 projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp ); 361 projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp ); 362 projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); 363 364 SpecificationVersion sourceLevel = (SpecificationVersion) JAVAC_SOURCE_MODEL.getSelectedItem(); 366 PlatformUiSupport.storePlatform (projectProperties, updateHelper, PLATFORM_MODEL.getSelectedItem(), sourceLevel); 367 368 if ( NO_DEPENDENCIES_MODEL.isSelected() ) { projectProperties.remove( NO_DEPENDENCIES ); } 372 373 if (J2EE_SERVER_INSTANCE_MODEL.getSelectedItem() != null) { 375 setNewServerInstanceValue(J2eePlatformUiSupport.getServerInstanceID(J2EE_SERVER_INSTANCE_MODEL.getSelectedItem()), project, projectProperties, privateProperties); 376 } 377 378 String oldJ2eeVersion = projectProperties.getProperty(J2EE_PLATFORM); 380 String newJ2eeVersion = J2eePlatformUiSupport.getSpecVersion(J2EE_PLATFORM_MODEL.getSelectedItem()); 381 if (oldJ2eeVersion != null && newJ2eeVersion != null) { 382 if (oldJ2eeVersion.equals(J2EE_1_3) && newJ2eeVersion.equals(J2EE_1_4)) { 383 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbJarModules[] = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJars(project); 384 if (ejbJarModules.length > 0) { 385 FileObject ddFo = ejbJarModules[0].getDeploymentDescriptor(); 386 if (ddFo != null) { 387 EjbJar ddRoot = DDProvider.getDefault().getMergedDDRoot(ejbJarModules[0].getMetadataUnit()); 388 if (ddRoot != null) { 389 ddRoot.setVersion(new BigDecimal (EjbJar.VERSION_2_1)); 390 ddRoot.write(ddFo); 391 } 392 } 393 } 394 } 395 396 projectProperties.setProperty(J2EE_PLATFORM, newJ2eeVersion); 398 } 399 400 storeAdditionalProperties(projectProperties); 401 402 storeLibrariesLocations (ClassPathUiSupport.getList(JAVAC_CLASSPATH_MODEL.getDefaultListModel()).iterator(), privateProperties); 403 404 updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); 406 updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); 407 408 } 409 410 private void storeAdditionalProperties(EditableProperties projectProperties) { 411 for (Iterator i = additionalProperties.keySet().iterator(); i.hasNext();) { 412 String key = i.next().toString(); 413 projectProperties.put(key, additionalProperties.getProperty(key)); 414 } 415 } 416 417 420 private void resolveProjectDependenciesNew() { 421 422 Set oldArtifacts = new HashSet (); 424 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 425 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_CLASSPATH ), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES ) ); 426 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ), null ) ); 427 oldArtifacts.addAll( cs.itemsList( (String )projectProperties.get( RUN_TEST_CLASSPATH ), null ) ); 428 429 Set newArtifacts = new HashSet (); 430 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL.getDefaultListModel() ) ); 431 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) ); 432 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) ); 433 434 Set removed = new HashSet ( oldArtifacts ); 436 removed.removeAll( newArtifacts ); 437 Set added = new HashSet (newArtifacts); 438 added.removeAll(oldArtifacts); 439 440 for( Iterator it = removed.iterator(); it.hasNext(); ) { 443 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 444 if ( item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT || 445 item.getType() == ClassPathSupport.Item.TYPE_JAR ) { 446 refHelper.destroyReference(item.getReference()); 447 } 448 } 449 450 EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 452 boolean changed = false; 453 454 for( Iterator it = removed.iterator(); it.hasNext(); ) { 455 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 456 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 457 String prop = item.getReference(); 459 prop = prop.substring(2, prop.length()-1); 460 ep.remove(prop); 461 changed = true; 462 } 463 } 464 File projDir = FileUtil.toFile(updateHelper.getAntProjectHelper().getProjectDirectory()); 465 for( Iterator it = added.iterator(); it.hasNext(); ) { 466 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 467 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 468 String prop = cs.getLibraryReference( item ); 471 prop = prop.substring(2, prop.length()-1); String value = relativizeLibraryClasspath(prop, projDir); 473 if (value != null) { 474 ep.setProperty(prop, value); 475 ep.setComment(prop, new String []{ 476 "# Property "+prop+" is set here just to make sharing of project simpler.", "# The library definition has always preference over this property."}, false); changed = true; 480 } 481 } 482 } 483 if (changed) { 484 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 485 } 486 } 487 488 494 private String relativizeLibraryClasspath(String property, File projectDir) { 495 String value = PropertyUtils.getGlobalProperties().getProperty(property); 496 if (value == null) { 498 return null; 499 } 500 String [] paths = PropertyUtils.tokenizePath(value); 501 StringBuffer sb = new StringBuffer (); 502 for (int i=0; i<paths.length; i++) { 503 File f = updateHelper.getAntProjectHelper().resolveFile(paths[i]); 504 if (CollocationQuery.areCollocated(f, projectDir)) { 505 sb.append(PropertyUtils.relativizeFile(projectDir, f)); 506 } else { 507 return null; 508 } 509 if (i+1<paths.length) { 510 sb.append(File.pathSeparatorChar); 511 } 512 } 513 if (sb.length() == 0) { 514 return null; 515 } else { 516 return sb.toString(); 517 } 518 } 519 520 private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException { 521 Vector data = tableModel.getDataVector(); 522 URL [] rootURLs = new URL [data.size()]; 523 String []rootLabels = new String [data.size()]; 524 for (int i=0; i<data.size();i++) { 525 File f = ((File )((Vector )data.elementAt(i)).elementAt(0)); 526 rootURLs[i] = EjbJarProjectUtil.getRootURL(f,null); 527 rootLabels[i] = (String ) ((Vector )data.elementAt(i)).elementAt(1); 528 } 529 roots.putRoots(rootURLs,rootLabels); 530 } 531 532 public static void setServerInstance(final Project project, final AntProjectHelper helper, final String serverInstanceID) { 533 ProjectManager.mutex().writeAccess(new Runnable () { 534 public void run() { 535 try { 536 EditableProperties projectProps = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 537 EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 538 setNewServerInstanceValue(serverInstanceID, project, projectProps, privateProps); 539 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProps); 540 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 541 ProjectManager.getDefault().saveProject(project); 542 } 543 catch (IOException e) { 544 ErrorManager.getDefault().notify(); 545 } 546 } 547 }); 548 } 549 550 551 void putAdditionalProperty(String propertyName, String propertyValue) { 552 additionalProperties.setProperty(propertyName, propertyValue); 553 } 554 555 private static void setNewServerInstanceValue(String newServInstID, Project project, EditableProperties projectProps, EditableProperties privateProps) { 556 String oldServInstID = privateProps.getProperty(J2EE_SERVER_INSTANCE); 558 if (oldServInstID != null) { 559 J2eePlatform oldJ2eePlatform = Deployment.getDefault().getJ2eePlatform(oldServInstID); 560 if (oldJ2eePlatform != null) { 561 ((EjbJarProject)project).unregisterJ2eePlatformListener(oldJ2eePlatform); 562 } 563 } 564 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(newServInstID); 565 if (j2eePlatform == null) { 566 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "J2EE platform is null."); 569 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 573 574 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 575 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH); 576 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH); 577 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIT_CLASSPATH); 578 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH); 579 580 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 581 return; 582 } 583 ((EjbJarProject)project).registerJ2eePlatformListener(j2eePlatform); 584 String classpath = Utils.toClasspathString(j2eePlatform.getClasspathEntries()); 585 privateProps.setProperty(J2EE_PLATFORM_CLASSPATH, classpath); 586 587 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) { 589 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSCOMPILE); 590 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH, 591 Utils.toClasspathString(wsClasspath)); 592 } else { 593 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSCOMPILE_CLASSPATH); 594 } 595 596 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSGEN)) { 597 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSGEN); 598 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH, 599 Utils.toClasspathString(wsClasspath)); 600 } else { 601 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSGEN_CLASSPATH); 602 } 603 604 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSIMPORT)) { 605 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSIMPORT); 606 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH, 607 Utils.toClasspathString(wsClasspath)); 608 } else { 609 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIMPORT_CLASSPATH); 610 } 611 612 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSIT)) { 613 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_WSIT); 614 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_WSIT_CLASSPATH, 615 Utils.toClasspathString(wsClasspath)); 616 } else { 617 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_WSIT_CLASSPATH); 618 } 619 620 if (j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP)) { 621 File [] wsClasspath = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_JWSDP); 622 privateProps.setProperty(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH, 623 Utils.toClasspathString(wsClasspath)); 624 } else { 625 privateProps.remove(WebServicesConstants.J2EE_PLATFORM_JWSDP_CLASSPATH); 626 } 627 628 projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(newServInstID)); 630 631 privateProps.setProperty(J2EE_SERVER_INSTANCE, newServInstID); 633 634 File projectFolder = FileUtil.toFile(project.getProjectDirectory()); 636 try { 637 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.EJB, newServInstID); } catch (IOException ioe) { 639 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 640 } 641 File deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(newServInstID); 642 if (deployAntPropsFile == null) { 643 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 644 } else { 645 privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath()); 646 } 647 } 648 649 public static String getProperty(final String property, final AntProjectHelper helper, final String path) { 650 EditableProperties props = helper.getProperties(path); 651 return props.getProperty(property); 652 } 653 654 public static String getAntPropertyName( String property ) { 655 if ( property != null && 656 property.startsWith( "${" ) && property.endsWith( "}" ) ) { return property.substring( 2, property.length() - 1 ); 659 } 660 else { 661 return property; 662 } 663 } 664 665 681 public static void storeLibrariesLocations (Iterator classpath, EditableProperties privateProps) { 682 ArrayList exLibs = new ArrayList (); 683 Iterator propKeys = privateProps.keySet().iterator(); 684 while (propKeys.hasNext()) { 685 String key = (String ) propKeys.next(); 686 if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || (key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { exLibs.add(key); 689 } 690 } 691 while (classpath.hasNext()) { 692 ClassPathSupport.Item item = (ClassPathSupport.Item)classpath.next(); 693 ArrayList files = new ArrayList (); 694 ArrayList dirs = new ArrayList (); 695 getFilesForItem (item, files, dirs); 696 String key; 697 if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) { 698 String ref = item.getReference() == null ? item.getRaw() : item.getReference(); 699 for (int i = 0; i < files.size(); i++) { 700 File f = (File ) files.get(i); 701 key = getAntPropertyName(ref)+".libfile." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 704 } 705 } 706 if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) { 707 String ref = item.getReference() == null ? item.getRaw() : item.getReference(); 708 for (int i = 0; i < dirs.size(); i++) { 709 File f = (File ) dirs.get(i); 710 key = getAntPropertyName(ref)+".libdir." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 713 } 714 } 715 } 716 Iterator unused = exLibs.iterator(); 717 while (unused.hasNext()) { 718 privateProps.remove(unused.next()); 719 } 720 } 721 722 public static final void getFilesForItem (ClassPathSupport.Item item, List files, List dirs) { 723 if (item.isBroken()) { 724 return ; 725 } 726 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 727 List roots = item.getLibrary().getContent("classpath"); for (Iterator it = roots.iterator(); it.hasNext();) { 729 URL rootUrl = (URL ) it.next(); 730 FileObject root = URLMapper.findFileObject (rootUrl); 731 if ("jar".equals(rootUrl.getProtocol())) { root = FileUtil.getArchiveFile (root); 733 } 734 File f = FileUtil.toFile(root); 735 if (f != null) { 736 if (f.isFile()) { 737 files.add(f); 738 } else { 739 dirs.add(f); 740 } 741 } 742 } 743 } 744 if (item.getType() == ClassPathSupport.Item.TYPE_JAR) { 745 File root = item.getFile(); 746 if (root != null) { 747 if (root.isFile()) { 748 files.add(root); 749 } else { 750 dirs.add(root); 751 } 752 } 753 } 754 if (item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT) { 755 String artifactFolder = item.getArtifact().getScriptLocation().getParent(); 756 URI roots[] = item.getArtifact().getArtifactLocations(); 757 for (int i = 0; i < roots.length; i++) { 758 String root = artifactFolder + File.separator + roots [i]; 759 if (root.endsWith(File.separator)) { 760 dirs.add(new File (root)); 761 } else { 762 files.add(new File (root)); 763 } 764 } 765 } 766 } 767 } 768 | Popular Tags |