1 19 20 package org.netbeans.modules.j2ee.earproject.ui.customizer; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.URI ; 27 import java.net.URL ; 28 import java.text.Collator ; 29 import java.util.ArrayList ; 30 import java.util.Arrays ; 31 import java.util.Collections ; 32 import java.util.HashMap ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 import java.util.LinkedHashMap ; 36 import java.util.List ; 37 import java.util.Map ; 38 import java.util.Set ; 39 import java.util.TreeSet ; 40 import java.util.jar.JarEntry ; 41 import java.util.jar.JarFile ; 42 import javax.swing.JButton ; 43 import org.netbeans.api.java.platform.JavaPlatform; 44 import org.netbeans.api.java.platform.JavaPlatformManager; 45 import org.netbeans.api.java.platform.Specification; 46 import org.netbeans.api.java.project.JavaProjectConstants; 47 import org.netbeans.api.project.Project; 48 import org.netbeans.api.project.ProjectManager; 49 import org.netbeans.api.project.ProjectUtils; 50 import org.netbeans.api.project.ant.AntArtifact; 51 import org.netbeans.api.project.ant.AntArtifactQuery; 52 import org.netbeans.api.project.libraries.Library; 53 import org.netbeans.api.project.libraries.LibraryManager; 54 import org.netbeans.api.queries.CollocationQuery; 55 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 56 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 57 import org.netbeans.modules.j2ee.dd.api.application.Application; 58 import org.netbeans.modules.j2ee.dd.api.application.DDProvider; 59 import org.netbeans.modules.j2ee.dd.api.application.Module; 60 import org.netbeans.modules.j2ee.dd.api.application.Web; 61 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper; 62 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 63 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 64 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 65 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 66 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 67 import org.netbeans.modules.j2ee.earproject.BrokenProjectSupport; 68 import org.netbeans.modules.j2ee.earproject.EarProject; 69 import org.netbeans.modules.j2ee.earproject.EarProjectGenerator; 70 import org.netbeans.modules.j2ee.earproject.UpdateHelper; 71 import org.netbeans.modules.web.api.webmodule.WebModule; 72 import org.netbeans.spi.project.SubprojectProvider; 73 import org.netbeans.spi.project.support.ant.AntBasedProjectType; 74 import org.netbeans.spi.project.support.ant.AntProjectEvent; 75 import org.netbeans.spi.project.support.ant.AntProjectHelper; 76 import org.netbeans.spi.project.support.ant.EditableProperties; 77 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 78 import org.netbeans.spi.project.support.ant.PropertyUtils; 79 import org.netbeans.spi.project.support.ant.ReferenceHelper; 80 import org.openide.DialogDisplayer; 81 import org.openide.ErrorManager; 82 import org.openide.NotifyDescriptor; 83 import org.openide.filesystems.FileObject; 84 import org.openide.filesystems.FileUtil; 85 import org.openide.filesystems.URLMapper; 86 import org.openide.modules.SpecificationVersion; 87 import org.openide.util.Mutex; 88 import org.openide.util.MutexException; 89 import org.openide.util.NbBundle; 90 import org.w3c.dom.Document ; 91 import org.w3c.dom.Element ; 92 import org.w3c.dom.Node ; 93 import org.w3c.dom.NodeList ; 94 import org.w3c.dom.Text ; 95 96 102 public final class EarProjectProperties { 103 104 public static final String J2EE_SPEC_14_LABEL = 105 NbBundle.getMessage(EarProjectProperties.class, "J2EESpecLevel_14"); 106 public static final String JAVA_EE_SPEC_50_LABEL = 107 NbBundle.getMessage(EarProjectProperties.class, "JavaEESpecLevel_50"); 108 109 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"; 114 116 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 JAVAC_CLASSPATH = "javac.classpath"; public static final String DEBUG_CLASSPATH = "debug.classpath"; public static final String RUN_CLASSPATH = "run.classpath"; public static final String JAR_NAME = "jar.name"; public static final String JAR_COMPRESS = "jar.compress"; public static final String JAR_CONTENT_ADDITIONAL = "jar.content.additional"; 128 public static final String APPLICATION_CLIENT = "app.client"; public static final String APPCLIENT_MAIN_CLASS = "main.class"; public static final String APPCLIENT_ARGS = "application.args"; public static final String APPCLIENT_JVM_OPTIONS = "j2ee.appclient.jvmoptions"; public static final String APPCLIENT_MAINCLASS_ARGS = "j2ee.appclient.mainclass.args"; 134 public static final String LAUNCH_URL_RELATIVE = "client.urlPart"; public static final String DISPLAY_BROWSER = "display.browser"; public static final String CLIENT_MODULE_URI = "client.module.uri"; public static final String J2EE_SERVER_INSTANCE = "j2ee.server.instance"; public static final String J2EE_SERVER_TYPE = "j2ee.server.type"; 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"; public static final String META_INF = "meta.inf"; public static final String RESOURCE_DIR = "resource.dir"; public static final String WEB_DOCBASE_DIR = "web.docbase.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_EXCLUDES = "build.classes.excludes"; public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; public static final String NO_DEPENDENCIES="no.dependencies"; 152 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"; 163 public static final String JAVADOC_PREVIEW="javadoc.preview"; 165 public static final String COMPILE_JSPS = "compile.jsps"; 167 public static final String CLIENT_NAME = "j2ee.clientName"; 169 171 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"; 176 180 private static final String J2EE_PLATFORM_APPCLIENT_ARGS = "j2ee.appclient.args"; 182 static final String APPCLIENT_WA_COPY_CLIENT_JAR_FROM = "wa.copy.client.jar.from"; 184 private static final String PROJECT = AntProjectHelper.PROJECT_PROPERTIES_PATH; 186 private static final String PRIVATE = AntProjectHelper.PRIVATE_PROPERTIES_PATH; 187 188 public static final String TAG_WEB_MODULE_LIBRARIES = "web-module-libraries"; public static final String TAG_WEB_MODULE__ADDITIONAL_LIBRARIES = "web-module-additional-libraries"; 193 public static final String DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; 195 public static final String ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; 197 private static final String ATTR_FILES = "files"; private static final String ATTR_DIRS = "dirs"; 200 201 static final PropertyParser STRING_PARSER = new StringParser(); 202 private static final BooleanParser BOOLEAN_PARSER = new BooleanParser(); 203 private static final InverseBooleanParser INVERSE_BOOLEAN_PARSER = new InverseBooleanParser(); 204 private final PropertyParser PATH_PARSER = new PathParser(); 205 private final PropertyParser JAVAC_CLASSPATH_PARSER = new PathParser(TAG_WEB_MODULE_LIBRARIES); 206 private final PropertyParser JAR_CONTENT_ADDITIONAL_PARSER = 207 new PathParser(TAG_WEB_MODULE__ADDITIONAL_LIBRARIES); 208 private static final PlatformParser PLATFORM_PARSER = new PlatformParser(); 209 210 private final PropertyDescriptor PROPERTY_DESCRIPTORS[] = { 212 new PropertyDescriptor( WEB_PROJECT_NAME, null, STRING_PARSER ), 213 new PropertyDescriptor( J2EE_PLATFORM, PROJECT, STRING_PARSER ), 214 215 new PropertyDescriptor( SOURCE_ROOT, PROJECT, STRING_PARSER ), 216 new PropertyDescriptor( BUILD_FILE, PROJECT, STRING_PARSER ), 217 new PropertyDescriptor( LIBRARIES_DIR, PROJECT, STRING_PARSER ), 218 new PropertyDescriptor( DIST_DIR, PROJECT, STRING_PARSER ), 219 new PropertyDescriptor( DIST_JAR, PROJECT, STRING_PARSER ), 220 new PropertyDescriptor( JAVAC_CLASSPATH, PROJECT, JAVAC_CLASSPATH_PARSER ), 221 new PropertyDescriptor( COMPILE_JSPS, PROJECT, BOOLEAN_PARSER ), 222 new PropertyDescriptor( DEBUG_CLASSPATH, PROJECT, PATH_PARSER ), 224 new PropertyDescriptor( RUN_CLASSPATH, PROJECT, PATH_PARSER ), 225 226 new PropertyDescriptor( JAR_NAME, PROJECT, STRING_PARSER ), 227 new PropertyDescriptor( JAR_COMPRESS, PROJECT, BOOLEAN_PARSER ), 228 new PropertyDescriptor( JAR_CONTENT_ADDITIONAL, PROJECT, JAR_CONTENT_ADDITIONAL_PARSER ), 229 230 new PropertyDescriptor( APPLICATION_CLIENT, PROJECT, STRING_PARSER ), 231 new PropertyDescriptor( APPCLIENT_MAIN_CLASS, PROJECT, STRING_PARSER ), 232 new PropertyDescriptor( APPCLIENT_JVM_OPTIONS, PROJECT, STRING_PARSER ), 233 new PropertyDescriptor( APPCLIENT_ARGS, PRIVATE, STRING_PARSER ), 234 235 new PropertyDescriptor( LAUNCH_URL_RELATIVE, PROJECT, STRING_PARSER ), 236 new PropertyDescriptor( CLIENT_MODULE_URI, PROJECT, STRING_PARSER ), 237 new PropertyDescriptor( DISPLAY_BROWSER, PROJECT, BOOLEAN_PARSER ), 238 new PropertyDescriptor( J2EE_SERVER_TYPE, PROJECT, STRING_PARSER ), 239 new PropertyDescriptor( J2EE_SERVER_INSTANCE, PRIVATE, STRING_PARSER ), 240 new PropertyDescriptor( JAVAC_SOURCE, PROJECT, STRING_PARSER ), 241 new PropertyDescriptor( JAVAC_DEBUG, PROJECT, BOOLEAN_PARSER ), 242 new PropertyDescriptor( JAVAC_DEPRECATION, PROJECT, BOOLEAN_PARSER ), 243 new PropertyDescriptor( JAVAC_TARGET, PROJECT, STRING_PARSER ), 244 new PropertyDescriptor( RESOURCE_DIR, PROJECT, STRING_PARSER ), 245 new PropertyDescriptor( BUILD_DIR, PROJECT, STRING_PARSER ), 246 new PropertyDescriptor( BUILD_CLASSES_EXCLUDES, PROJECT, STRING_PARSER ), 247 new PropertyDescriptor( DIST_JAVADOC_DIR, PROJECT, STRING_PARSER ), 248 new PropertyDescriptor( WEB_DOCBASE_DIR, PROJECT, STRING_PARSER ), 249 new PropertyDescriptor( NO_DEPENDENCIES, PROJECT, INVERSE_BOOLEAN_PARSER ), 250 new PropertyDescriptor( JAVA_PLATFORM, PROJECT, PLATFORM_PARSER ), 251 new PropertyDescriptor( DEPLOY_ANT_PROPS_FILE, PRIVATE, STRING_PARSER ), 252 253 new PropertyDescriptor( JAVADOC_PRIVATE, PROJECT, BOOLEAN_PARSER ), 254 new PropertyDescriptor( JAVADOC_NO_TREE, PROJECT, INVERSE_BOOLEAN_PARSER ), 255 new PropertyDescriptor( JAVADOC_USE, PROJECT, BOOLEAN_PARSER ), 256 new PropertyDescriptor( JAVADOC_NO_NAVBAR, PROJECT, INVERSE_BOOLEAN_PARSER ), 257 new PropertyDescriptor( JAVADOC_NO_INDEX, PROJECT, INVERSE_BOOLEAN_PARSER ), 258 new PropertyDescriptor( JAVADOC_SPLIT_INDEX, PROJECT, BOOLEAN_PARSER ), 259 new PropertyDescriptor( JAVADOC_AUTHOR, PROJECT, BOOLEAN_PARSER ), 260 new PropertyDescriptor( JAVADOC_VERSION, PROJECT, BOOLEAN_PARSER ), 261 new PropertyDescriptor( JAVADOC_WINDOW_TITLE, PROJECT, STRING_PARSER ), 262 new PropertyDescriptor( JAVADOC_ENCODING, PROJECT, STRING_PARSER ), 263 new PropertyDescriptor( JAVADOC_PREVIEW, PROJECT, BOOLEAN_PARSER ), 264 }; 265 266 268 269 private final Map <String , PropertyInfo> properties; 270 271 private final AntProjectHelper antProjectHelper; 272 private final ReferenceHelper refHelper; 273 private final AntBasedProjectType abpt; 274 private final UpdateHelper updateHelper; 275 private final EarProject earProject; 276 private final GeneratedFilesHelper genFilesHelper; 277 278 279 private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport (this); 280 281 public EarProjectProperties(final EarProject project, 282 final ReferenceHelper refHelper, final AntBasedProjectType abpt) { 283 this.earProject = project; 284 this.properties = new HashMap <String , PropertyInfo>(); 285 this.updateHelper = project.getUpdateHelper(); 286 this.antProjectHelper = updateHelper.getAntProjectHelper(); 287 this.refHelper = refHelper; 288 this.abpt = abpt; 289 this.genFilesHelper = project.getGeneratedFilesHelper(); 290 read(); 291 } 292 293 294 void updateContentDependency(Set <VisualClassPathItem> oldContent, Set <VisualClassPathItem> newContent) { 295 Application app = null; 296 try { 297 app = DDProvider.getDefault().getDDRoot(earProject.getAppModule().getDeploymentDescriptor()); 298 } catch (IOException ioe) { 299 ErrorManager.getDefault().log(ioe.getLocalizedMessage()); 300 } 301 302 Set <VisualClassPathItem> deleted = new HashSet (oldContent); 303 deleted.removeAll(newContent); 304 Set <VisualClassPathItem> added = new HashSet (newContent); 305 added.removeAll(oldContent); 306 307 boolean same = true; 309 if(deleted.size() == added.size()) { 310 Iterator <VisualClassPathItem> deletedIterator = deleted.iterator(); 311 Iterator <VisualClassPathItem> addedIterator = added.iterator(); 312 while (deletedIterator.hasNext() && addedIterator.hasNext()) { 313 VisualClassPathItem del = deletedIterator.next(); 314 VisualClassPathItem add = addedIterator.next(); 315 if(del != null && add != null && !del.equals(add)) { 317 same = false; 318 break; 319 } 320 } 321 } else { 322 same = false; 323 } 324 325 boolean saveNeeded = false; 326 if (null != app && !same) { 327 for (VisualClassPathItem vcpi : deleted) { 329 removeItemFromAppDD(app,vcpi); 330 } 331 for (VisualClassPathItem vcpi : added) { 333 addItemToAppDD(app,vcpi); 334 } 335 saveNeeded = true; 336 } 337 for (VisualClassPathItem vcpi : newContent) { if (!vcpi.getPathInEAR().equals(vcpi.getOrigPathInEAR())) { 339 removeItemFromAppDD(app, vcpi, vcpi.getCompletePathInArchive(true)); 340 addItemToAppDD(app, vcpi); 341 saveNeeded = true; 342 } 343 } 344 if (saveNeeded) { 345 try { 346 app.write(earProject.getAppModule().getDeploymentDescriptor()); 347 } catch (IOException ioe) { 348 ErrorManager.getDefault().log(ioe.getLocalizedMessage()); 349 } 350 } 351 } 352 353 private void removeItemFromAppDD(Application dd, VisualClassPathItem vcpi) { 354 removeItemFromAppDD(dd, vcpi, vcpi.getCompletePathInArchive()); 355 } 356 357 private void removeItemFromAppDD(final Application dd, 358 final VisualClassPathItem vcpi, final String pathInEAR) { 359 Module m = searchForModule(dd, pathInEAR); 360 if (null != m) { 361 dd.removeModule(m); 362 setClientModuleUri(""); 363 Object obj = vcpi.getObject(); 364 if (obj instanceof AntArtifact) { 365 AntArtifact aa = (AntArtifact) obj; 366 Project p = aa.getProject(); 367 J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); 368 if (null != jmp) { 369 J2eeModule jm = jmp.getJ2eeModule(); 370 if (null != jm) { 371 earProject.getAppModule().removeModuleProvider(jmp, pathInEAR); 372 } 373 } 374 } 375 } 376 } 377 378 private Module searchForModule(Application dd, String path) { 379 Module mods[] = dd.getModule(); 380 int len = 0; 381 if (null != mods) { 382 len = mods.length; 383 } 384 for (int i = 0; i < len; i++) { 385 String val = mods[i].getEjb(); 386 if (null != val && val.equals(path)) { 387 return mods[i]; 388 } 389 val = mods[i].getConnector(); 390 if (null != val && val.equals(path)) { 391 return mods[i]; 392 } 393 val = mods[i].getJava(); 394 if (null != val && val.equals(path)) { 395 return mods[i]; 396 } 397 Web w = mods[i].getWeb(); 398 val = null; 399 if ( null != w) { 400 val = w.getWebUri(); 401 } 402 if (null != val && val.equals(path)) { 403 return mods[i]; 404 } 405 } 406 return null; 407 } 408 409 public void addItemToAppDD(Application dd, VisualClassPathItem vcpi) { 410 Object obj = vcpi.getObject(); 411 String path = vcpi.getCompletePathInArchive(); Module mod = null; 413 if (obj instanceof AntArtifact) { 414 mod = getModFromAntArtifact((AntArtifact) obj, dd, path); 415 } else if (obj instanceof File ) { 416 mod = getModFromFile((File ) obj, dd, path); 417 } 418 if (mod != null && mod.getWeb() != null) { 419 replaceEmptyClientModuleUri(path); 420 } 421 Module prevMod = searchForModule(dd, path); 422 if (null == prevMod && null != mod) { 423 dd.addModule(mod); 424 } 425 } 426 427 428 private Module getModFromAntArtifact(AntArtifact aa, Application dd, String path) { 429 Project p = aa.getProject(); 430 Module mod = null; 431 try { 432 J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); 433 if (null != jmp) { 434 jmp.setServerInstanceID(earProject.getServerInstanceID()); 435 J2eeModule jm = jmp.getJ2eeModule(); 436 if (null != jm) { 437 earProject.getAppModule().addModuleProvider(jmp,path); 438 } else { 439 return null; 440 } 441 mod = (Module) dd.createBean(Application.MODULE); 442 if (jm.getModuleType() == J2eeModule.EJB) { 443 mod.setEjb(path); } else if (jm.getModuleType() == J2eeModule.WAR) { 445 Web w = (Web) mod.newWeb(); w.setWebUri(path); 447 FileObject tmp = aa.getScriptFile(); 448 if (null != tmp) { 449 tmp = tmp.getParent().getFileObject("web/WEB-INF/web.xml"); } 451 WebModule wm = null; 452 if (null != tmp) { 453 wm = (WebModule) WebModule.getWebModule(tmp); 454 } 455 String contextPath = null; 456 if (null != wm) { 457 contextPath = wm.getContextPath(); 458 } 459 if (contextPath == null) { 460 int endex = path.length() - 4; 461 if (endex < 1) { 462 endex = path.length(); 463 } 464 contextPath = path.substring(0,endex); 465 } 466 w.setContextRoot(contextPath); 467 mod.setWeb(w); 468 } else if (jm.getModuleType() == J2eeModule.CONN) { 469 mod.setConnector(path); 470 } else if (jm.getModuleType() == J2eeModule.CLIENT) { 471 mod.setJava(path); 472 } 473 } 474 } 475 catch (ClassNotFoundException cnfe) { 476 ErrorManager.getDefault().notify(cnfe); 477 } 478 return mod; 479 } 480 481 private void setClientModuleUri(String newVal) { 482 put(EarProjectProperties.CLIENT_MODULE_URI,newVal); 483 } 484 485 private void replaceEmptyClientModuleUri(String path) { 486 Object current = get(EarProjectProperties.CLIENT_MODULE_URI); 488 if (null == current) { 489 setClientModuleUri(path); 490 } 491 if (current instanceof String && ((String ) current).length() < 1) { 492 setClientModuleUri(path); 493 } 494 } 495 496 private Module getModFromFile(File f, Application dd, String path) { 497 JarFile jar = null; 498 Module mod = null; 499 try { 500 jar= new JarFile ((File ) f); 501 JarEntry ddf = jar.getJarEntry("META-INF/ejb-jar.xml"); if (null != ddf) { 503 mod = (Module) dd.createBean(Application.MODULE); 504 mod.setEjb(path); 505 } 506 ddf = jar.getJarEntry("META-INF/ra.xml"); if (null != ddf && null == mod) { 508 mod = (Module) dd.createBean(Application.MODULE); 509 mod.setConnector(path); 510 } else if (null != ddf && null != mod) { 511 return null; } 513 ddf = jar.getJarEntry("META-INF/application-client.xml"); if (null != ddf && null == mod) { 515 mod = (Module) dd.createBean(Application.MODULE); 516 mod.setJava(path); 517 } else if (null != ddf && null != mod) { 518 return null; } 520 ddf = jar.getJarEntry("WEB-INF/web.xml"); if (null != ddf && null == mod) { 522 mod = (Module) dd.createBean(Application.MODULE); 523 Web w = (Web) mod.newWeb(); 524 w.setWebUri(path); 525 int endex = path.length() - 4; 526 if (endex < 1) { 527 endex = path.length(); 528 } 529 w.setContextRoot("/"+path.substring(0,endex)); mod.setWeb(w); 531 } else if (null != ddf && null != mod) { 532 return null; } 534 ddf = jar.getJarEntry("META-INF/application.xml"); if (null != ddf) { 536 return null; 537 } 538 } catch (ClassNotFoundException cnfe) { 539 ErrorManager.getDefault().log(cnfe.getLocalizedMessage()); 540 } catch (IOException ioe) { 541 ErrorManager.getDefault().log(ioe.getLocalizedMessage()); 542 } finally { 543 try { 544 if (null != jar) { 545 jar.close(); 546 } 547 } catch (IOException ioe) { 548 } 550 } 551 return mod; 552 } 553 554 564 public void propertiesChanged(AntProjectEvent ev) { 565 566 } 567 568 572 public void addPropertyChangeListener(PropertyChangeListener l) { 573 574 propertyChangeSupport.addPropertyChangeListener (l); 575 } 576 577 581 public void removePropertyChangeListener(PropertyChangeListener l) { 582 propertyChangeSupport.removePropertyChangeListener (l); 583 } 584 585 @SuppressWarnings ("unchecked") 586 public List <VisualClassPathItem> getJarContentAdditional() { 587 List <VisualClassPathItem> vcpis = Collections.emptyList(); 588 Object o = properties.get(JAR_CONTENT_ADDITIONAL); 589 if (o instanceof PropertyInfo) { 590 PropertyInfo pi = (PropertyInfo) o; 591 Object value = pi.getValue(); 592 assert value instanceof List : JAR_CONTENT_ADDITIONAL + " is not a List: " + value.getClass(); 593 vcpis = (List ) value; 594 } 595 return vcpis; 596 } 597 598 601 public Map <String , J2eeModuleProvider> getModuleMap() { 602 Map <String , J2eeModuleProvider> mods = new HashMap <String , J2eeModuleProvider>(); 603 for (VisualClassPathItem vcpi : getJarContentAdditional()) { 604 Object obj = vcpi.getObject(); 605 Project p; 606 if (obj instanceof AntArtifact) { 607 AntArtifact aa = (AntArtifact) obj; 608 p = aa.getProject(); 609 } else { 610 continue; 611 } 612 J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); 613 if (null != jmp) { 614 J2eeModule jm = jmp.getJ2eeModule(); 615 if (null != jm) { 616 String path = vcpi.getCompletePathInArchive(); mods.put(path, jmp); 618 } 619 } 620 } 621 return mods; } 623 624 625 public void addJ2eeSubprojects(Project[] moduleProjects) { 626 List <AntArtifact> artifactList = new ArrayList <AntArtifact>(); 627 for (int i = 0; i < moduleProjects.length; i++) { 628 AntArtifact artifacts[] = AntArtifactQuery.findArtifactsByType( 629 moduleProjects[i], 630 EjbProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE); if (null != artifacts) { 632 artifactList.addAll(Arrays.asList(artifacts)); 633 } 634 } 635 List <VisualClassPathItem> newVCPIs = new ArrayList <VisualClassPathItem>(); 637 BrokenProjectSupport bps = (BrokenProjectSupport) earProject.getLookup().lookup(BrokenProjectSupport.class); 638 for (AntArtifact art : artifactList) { 639 VisualClassPathItem vcpi = VisualClassPathItem.createArtifact(art); 640 vcpi.setRaw(EarProjectProperties.JAR_CONTENT_ADDITIONAL); 641 newVCPIs.add(vcpi); 642 bps.watchAntArtifact(art); 643 } 644 List <VisualClassPathItem> vcpis = getJarContentAdditional(); 645 newVCPIs.addAll(vcpis); 646 put(EarProjectProperties.JAR_CONTENT_ADDITIONAL, newVCPIs); 647 store(); 648 } 649 650 653 Module[] getApplicationModules() { 654 Module mods[] = null; 655 try { 656 Application app = DDProvider.getDefault().getDDRoot( 657 earProject.getAppModule().getDeploymentDescriptor()); 658 mods = app.getModule(); 659 } catch (IOException ioe) { 660 ErrorManager.getDefault().log(ioe.getLocalizedMessage()); 661 } 662 if (mods == null) { 663 mods = new Module[0]; 664 } 665 return mods; 666 } 667 668 public String [] getWebUris() { 669 Module mods[] = getApplicationModules(); 670 Set <String > result = new TreeSet <String >(); 671 for (int i = 0; i < mods.length; i++) { 672 Web w = mods[i].getWeb(); 673 if (w != null) { 674 result.add(w.getWebUri()); 675 } 676 } 677 return result.toArray(new String [result.size()]); 678 } 679 680 public String [] getAppClientUris() { 681 Module mods[] = getApplicationModules(); 682 Set <String > result = new TreeSet <String >(); 683 for (int i = 0; i < mods.length; i++) { 684 if (mods[i].getJava() != null) { 685 String jarName = mods[i].getJava(); 686 String name = jarName.endsWith(".jar") ? jarName.substring(0, jarName.length() - 4) : jarName; 688 result.add(name); 690 } 691 } 692 return result.toArray(new String [result.size()]); 693 } 694 695 boolean isWebUri(String uri) { 696 return uri != null && Arrays.binarySearch(getWebUris(), uri) >= 0; 697 } 698 699 boolean isAppClientUri(String uri) { 700 return Arrays.binarySearch(getAppClientUris(), uri) >= 0; 701 } 702 703 705 static String getAntPropertyName( String property ) { 706 if ( property != null && 707 property.startsWith( "${" ) && property.endsWith( "}" ) ) { return property.substring( 2, property.length() - 1 ); 710 } 711 else { 712 return property; 713 } 714 } 715 716 static boolean isAntProperty (String string) { 717 return string != null && string.startsWith( "${" ) && string.endsWith( "}" ); } 719 720 public void put( String propertyName, Object value ) { 721 assert propertyName != null : "Unknown property " + propertyName; PropertyInfo pi = (PropertyInfo)properties.get( propertyName ); 723 pi.setValue( value ); 724 if (J2EE_SERVER_INSTANCE.equals (propertyName)) { 725 put (J2EE_SERVER_TYPE, Deployment.getDefault ().getServerID ((String ) value)); 726 } 727 } 728 729 public Object get(String propertyName) { 730 assert propertyName != null : "Unknown property " + propertyName; PropertyInfo pi = (PropertyInfo) properties.get(propertyName); 732 return pi == null ? null : pi.getValue(); 733 } 734 735 public boolean isModified( String propertyName ) { 736 PropertyInfo pi = (PropertyInfo)properties.get( propertyName ); 737 assert propertyName != null : "Unknown property " + propertyName; return pi.isModified(); 739 } 740 741 public List getSortedSubprojectsList() { 742 List <Project> subprojects = new ArrayList <Project>(); 743 addSubprojects( earProject, subprojects ); String [] displayNames = new String [subprojects.size()]; 745 746 for ( int i = 0; i < subprojects.size(); i++ ) { 748 displayNames[i] = ProjectUtils.getInformation(subprojects.get(i)).getDisplayName(); 749 } 750 751 Arrays.sort(displayNames, Collator.getInstance()); 752 return Arrays.asList(displayNames); 753 } 754 755 public EarProject getProject() { 756 return earProject; 757 } 758 759 761 private void addSubprojects( Project project, List <Project> result ) { 762 SubprojectProvider spp = (SubprojectProvider)project.getLookup().lookup( SubprojectProvider.class ); 763 764 if ( spp == null ) { 765 return; 766 } 767 768 for( Iterator it = spp.getSubprojects().iterator(); it.hasNext(); ) { 769 Project sp = (Project) it.next(); 770 if (ProjectUtils.hasSubprojectCycles(project, sp)) { 771 ErrorManager.getDefault().log(ErrorManager.WARNING, "There would be cyclic " + 772 "dependencies if the " + sp + " would be added. Skipping..."); continue; 774 } 775 if ( !result.contains( sp ) ) { 776 result.add( sp ); 777 } 778 addSubprojects( sp, result ); 779 } 780 } 781 782 785 private void read() { 786 Map <String , EditableProperties> eProps = new HashMap <String , EditableProperties>(2); 788 eProps.put( PROJECT, updateHelper.getProperties( PROJECT ) ); 789 eProps.put( PRIVATE, updateHelper.getProperties( PRIVATE ) ); 790 791 for ( int i = 0; i < PROPERTY_DESCRIPTORS.length; i++ ) { 793 PropertyDescriptor pd = PROPERTY_DESCRIPTORS[i]; 794 final String propertyName = pd.name; 795 if ( pd.dest == null ) { 796 if ( WEB_PROJECT_NAME.equals( propertyName ) ) { 798 String projectName = ProjectUtils.getInformation(earProject).getDisplayName(); 799 PropertyInfo pi = (PropertyInfo) properties.get(propertyName); 800 if (null == pi) { 801 properties.put(propertyName, new PropertyInfo(pd, projectName, projectName)); 802 } else { 803 pi.update(pd, projectName, projectName); 804 } 805 } 806 } else { 807 String raw = eProps.get( pd.dest ).getProperty( propertyName ); 809 String eval = antProjectHelper.getStandardPropertyEvaluator ().getProperty ( propertyName ); 810 PropertyInfo pi = (PropertyInfo) properties.get(propertyName); 811 if (null == pi) { 812 PropertyInfo propertyInfo = new PropertyInfo(pd, raw, eval); 813 properties.put(propertyName, propertyInfo); 814 } else { 815 pi.update(pd, raw, eval); 816 } 817 } 818 } 819 } 820 821 void initProperty(final String propertyName, final PropertyInfo propertyInfo) { 822 properties.put(propertyName, propertyInfo); 823 } 824 825 829 public void store() { 830 try { 831 Boolean result = (Boolean ) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 833 public Object run() throws IOException { 834 URL buildImplXSL = EarProject.class.getResource("resources/build-impl.xsl"); 835 int state = genFilesHelper.getBuildScriptState( 836 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, buildImplXSL); 837 if ((state & GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) { 838 if (showModifiedMessage(NbBundle.getMessage(EarProjectProperties.class,"TXT_ModifiedTitle"))) { 839 FileObject fo = updateHelper.getAntProjectHelper().getProjectDirectory(). 841 getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH); 842 if (fo != null) { 843 fo.delete(); 844 genFilesHelper.refreshBuildScript( 845 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 846 buildImplXSL, 847 false); 848 } 849 } else { 850 return false; 851 } 852 } 853 storeProperties(); 854 return true; 855 } 856 }); 857 if (result) { 859 ProjectManager.getDefault().saveProject(earProject); 860 } 861 } catch (MutexException e) { 862 ErrorManager.getDefault().notify((IOException )e.getException()); 863 } catch ( IOException ex ) { 864 ErrorManager.getDefault().notify( ex ); 865 } 866 } 867 868 private void storeProperties() { 869 resolveProjectDependencies(); 870 Boolean defaultPlatform = null; 871 872 for (Iterator it = properties.values().iterator(); it.hasNext();) { 875 PropertyInfo pi = (PropertyInfo) it.next(); 876 PropertyDescriptor pd = pi.getPropertyDescriptor(); 877 pi.encode(); 878 String newValueEncoded = pi.getNewValueEncoded(); 879 if(pd.saver != null) { 880 pd.saver.save(pi); 881 } 882 if (pd.dest == null && newValueEncoded != null && WEB_PROJECT_NAME.equals(pd.name)) { 883 assert false : "No support yet for changing name of J2SEProject; cf. J2SEProject.setName"; } 885 886 if (JAVA_PLATFORM.equals(pd.name) && newValueEncoded != null) { 887 defaultPlatform = 888 Boolean.valueOf(pi.getNewValueEncoded().equals(JavaPlatformManager.getDefault() 889 .getDefaultPlatform() 890 .getProperties() 891 .get("platform.ant.name"))); setPlatform(defaultPlatform.booleanValue(), pi.getNewValueEncoded()); 893 } 894 } 895 896 Map <String , EditableProperties> eProps = new HashMap <String , EditableProperties>(2); 899 eProps.put(PROJECT, updateHelper.getProperties(PROJECT)); 900 eProps.put(PRIVATE, updateHelper.getProperties(PRIVATE)); 901 902 for (Iterator it = properties.values().iterator(); it.hasNext();) { 904 PropertyInfo pi = (PropertyInfo) it.next(); 905 PropertyDescriptor pd = pi.getPropertyDescriptor(); 906 if(JAR_CONTENT_ADDITIONAL.equals(pd.name)) { 907 Object piValue = (pi.newValue != null ? pi.newValue : pd.parser.decode(pi.evaluatedValue, antProjectHelper, refHelper )); 909 if(piValue != null) { 910 @SuppressWarnings ("unchecked") 912 Iterator <VisualClassPathItem> newItems = ((List )piValue).iterator(); 913 @SuppressWarnings ("unchecked") 914 Iterator <VisualClassPathItem> oldItems = ((List )pi.value).iterator(); 915 storeLibrariesLocations(newItems, oldItems, eProps.get(PRIVATE)); 916 break; 917 } 918 } 919 } 920 921 for (Iterator it = properties.values().iterator(); it.hasNext();) { 923 PropertyInfo pi = (PropertyInfo) it.next(); 924 PropertyDescriptor pd = pi.getPropertyDescriptor(); 925 String newValueEncoded = pi.getNewValueEncoded(); 926 if (newValueEncoded != null && pd.dest != null) { 927 EditableProperties ep = eProps.get(pd.dest); 929 if (pd.parser instanceof PathParser) { 931 String [] items = PropertyUtils.tokenizePath(newValueEncoded); 934 for (int i = 0; i < items.length - 1; i++) { 935 items[i] += File.pathSeparatorChar; 936 } 937 ep.setProperty(pd.name, items); 938 } else if (NO_DEPENDENCIES.equals(pd.name) && newValueEncoded.equals("false")) { ep.remove(pd.name); 940 } else if (CLIENT_MODULE_URI.equals(pd.name)) { 941 if (isWebUri(newValueEncoded)) { 942 ep.setProperty(CLIENT_MODULE_URI, newValueEncoded); 944 ep.remove(APPLICATION_CLIENT); 945 } else if (isAppClientUri(newValueEncoded)) { 946 ep.setProperty(APPLICATION_CLIENT, newValueEncoded); 948 ep.setProperty(CLIENT_MODULE_URI, getClientModuleUriForAppClient()); 949 } else { 950 ep.remove(APPLICATION_CLIENT); 952 ep.remove(CLIENT_MODULE_URI); 953 } 954 } else { 955 if (JAVA_PLATFORM.equals(pd.name)) { assert defaultPlatform != null; 957 updateSourceLevel(defaultPlatform.booleanValue(), newValueEncoded, ep); 958 } else if (JAVAC_CLASSPATH.equals(pd.name)) { 959 writeWebLibraries(refHelper, (List ) pi.getValue(), 960 TAG_WEB_MODULE_LIBRARIES); 961 } else if (JAR_CONTENT_ADDITIONAL.equals(pd.name)) { 962 writeWebLibraries(refHelper, (List ) pi.getValue(), 963 TAG_WEB_MODULE__ADDITIONAL_LIBRARIES); 964 } else if (J2EE_SERVER_INSTANCE.equals(pd.name)) { 965 String serverInstanceID = (String ) pi.getValue(); 966 967 File projectFolder = FileUtil.toFile(earProject.getProjectDirectory()); 969 try { 970 AntDeploymentHelper.writeDeploymentScript(new File (projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.EAR, serverInstanceID); 971 } catch (IOException ioe) { 972 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 973 } 974 File deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID); 975 if (deployAntPropsFile == null) { 976 ep.remove(DEPLOY_ANT_PROPS_FILE); 977 } else { 978 ep.setProperty(DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath()); 979 } 980 981 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 982 EarProjectProperties.setACProperties(j2eePlatform, eProps.get(PROJECT)); 983 EarProjectProperties.setACPrivateProperties(j2eePlatform, serverInstanceID, eProps.get(PRIVATE)); 984 } 985 ep.setProperty(pd.name, newValueEncoded); 986 } 987 } 988 } 989 990 updateHelper.putProperties(PROJECT, eProps.get(PROJECT)); 992 updateHelper.putProperties(PRIVATE, eProps.get(PRIVATE)); 993 } 994 995 String getClientModuleUriForAppClient() { 996 PropertyInfo earNamePI = (PropertyInfo) properties.get(JAR_NAME); 997 assert earNamePI != null; 998 String earName = (String ) earNamePI.getValue(); 999 assert earName != null; 1000 if (earName.endsWith(".ear")) { earName = earName.substring(0, earName.length() - 4); 1002 } 1003 return earName + "/${" + APPLICATION_CLIENT + '}'; } 1005 1006 public static void setACProperties(final J2eePlatform j2eePlatform, final EditableProperties ep) { 1007 String mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS_ARGS); 1008 if (mainClassArgs != null && !mainClassArgs.equals("")) { 1009 ep.put(APPCLIENT_MAINCLASS_ARGS, mainClassArgs); 1010 ep.remove(CLIENT_NAME); 1011 } else if ((mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, CLIENT_NAME)) != null) { 1012 ep.put(CLIENT_NAME, mainClassArgs); 1013 ep.remove(APPCLIENT_MAINCLASS_ARGS); 1014 } else { 1015 ep.remove(APPCLIENT_MAINCLASS_ARGS); 1016 ep.remove(CLIENT_NAME); 1017 } 1018 } 1019 1020 private void setAndSaveACPrivateProperties(final String servInstIDs, final J2eePlatform platform) { 1021 ProjectManager.mutex().writeAccess(new Runnable () { 1022 public void run() { 1023 try { 1024 EditableProperties priv = updateHelper.getProperties(PRIVATE); 1025 setACPrivateProperties(platform, servInstIDs, priv); 1026 updateHelper.putProperties(PRIVATE, priv); 1027 ProjectManager.getDefault().saveProject(earProject); 1028 } catch (IOException e) { 1029 ErrorManager.getDefault().notify(e); 1030 } 1031 } 1032 }); 1033 } 1034 1035 public static void setACPrivateProperties(final J2eePlatform j2eePlatform, 1036 final String serverInstanceID, final EditableProperties ep) { 1037 if (!j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) { 1039 return; 1040 } 1041 File [] accrt = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_APP_CLIENT_RUNTIME); 1042 ep.setProperty(APPCLIENT_TOOL_RUNTIME, EarProjectGenerator.toClasspathString(accrt)); 1043 1044 String mainClass = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS); 1045 if (mainClass != null) { 1046 ep.setProperty(APPCLIENT_TOOL_MAINCLASS, mainClass); 1047 } 1048 1049 String jvmOpts = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_JVM_OPTS); 1050 if (jvmOpts != null) { 1051 ep.setProperty(APPCLIENT_TOOL_JVMOPTS, jvmOpts); 1052 } 1053 1054 String args = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2EE_PLATFORM_APPCLIENT_ARGS); 1055 if (args != null) { 1056 ep.setProperty(APPCLIENT_TOOL_ARGS, args); 1057 } 1058 1059 String classpath = EarProjectGenerator.toClasspathString(j2eePlatform.getClasspathEntries()); 1061 ep.setProperty("j2ee.platform.classpath", classpath); 1063 File asRoot = j2eePlatform.getPlatformRoots()[0]; 1067 InstanceProperties ip = InstanceProperties.getInstanceProperties(serverInstanceID); 1068 if (ip != null && new File (asRoot, "lib/admin-cli.jar").exists()) { File exFile = new File (asRoot, "lib/javaee.jar"); if (exFile.exists()) { 1072 ep.setProperty(APPCLIENT_WA_COPY_CLIENT_JAR_FROM, 1073 new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/generated/xml/j2ee-apps").getAbsolutePath()); } else { 1075 ep.setProperty(APPCLIENT_WA_COPY_CLIENT_JAR_FROM, 1076 new File (ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/applications/j2ee-apps").getAbsolutePath()); } 1078 } else { 1079 ep.remove(APPCLIENT_WA_COPY_CLIENT_JAR_FROM); 1080 } 1081 1082 } 1083 1084 private void updateSourceLevel(boolean defaultPlatform, String platform, EditableProperties ep) { 1085 if (defaultPlatform) { 1086 ep.setProperty(JAVAC_SOURCE, "${default.javac.source}"); ep.setProperty(JAVAC_TARGET, "${default.javac.target}"); } else { 1089 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms(); 1090 for( int i = 0; i < platforms.length; i++ ) { 1091 Specification spec = platforms[i].getSpecification(); 1092 if (!("j2se".equalsIgnoreCase(spec.getName()))) { continue; 1094 } 1095 if (platform.equals(platforms[i].getProperties().get("platform.ant.name"))) { String ver = platforms[i].getSpecification().getVersion().toString(); 1097 ep.setProperty(JAVAC_SOURCE, ver); 1098 ep.setProperty(JAVAC_TARGET, ver); 1099 return; 1100 } 1101 } 1102 } 1105 } 1106 1107 private final SpecificationVersion JDKSpec13 = new SpecificationVersion("1.3"); 1109 private void setPlatform(boolean isDefault, String platformAntID) { 1110 Element pcd = updateHelper.getPrimaryConfigurationData( true ); 1111 NodeList sps = pcd.getElementsByTagName( "explicit-platform" ); if (isDefault && sps.getLength() > 0) { 1113 pcd.removeChild(sps.item(0)); 1114 } else if (!isDefault) { 1115 Element el; 1116 if (sps.getLength() == 0) { 1117 el = pcd.getOwnerDocument().createElement("explicit-platform"); pcd.appendChild(el); 1119 } else { 1120 el = (Element )sps.item(0); 1121 } 1122 boolean explicitSource = true; 1123 JavaPlatform platform = findPlatform(platformAntID); 1124 if ((platform != null && platform.getSpecification().getVersion().compareTo(JDKSpec13) <= 0) || platform == null) { 1125 explicitSource = false; 1126 } 1127 el.setAttribute("explicit-source-supported", explicitSource ? "true" : "false"); } 1129 updateHelper.putPrimaryConfigurationData(pcd, true); 1130 } 1131 1132 public void ensurePlatformIsSet(final boolean showAlert) throws IOException { 1133 final String servInstID = (String ) get(EarProjectProperties.J2EE_SERVER_INSTANCE); 1134 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 1135 if (platform == null) { 1136 String serverType = (String ) get(EarProjectProperties.J2EE_SERVER_TYPE); 1139 if (serverType != null) { 1140 String [] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType); 1141 if (servInstIDs.length > 0) { 1142 EarProjectProperties.setServerInstance(earProject, earProject.getUpdateHelper(), servInstIDs[0]); 1143 platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]); 1144 if (platform != null) { 1145 setAndSaveACPrivateProperties(servInstIDs[0], platform); 1146 } 1147 } 1148 } 1149 if (showAlert && platform == null) { 1150 BrokenServerSupport.showAlert(); 1151 } 1152 } else { 1153 ProjectManager.mutex().writeAccess(new Runnable () { 1156 public void run() { 1157 EditableProperties privateProps = updateHelper.getProperties(PRIVATE); 1158 boolean changed = generateAntDeploymentSupport(privateProps, earProject.getProjectDirectory(), servInstID, false); 1159 if (changed) { 1160 updateHelper.putProperties(PRIVATE, privateProps); 1161 try { 1162 ProjectManager.getDefault().saveProject(earProject); 1163 } catch (IOException e) { 1164 ErrorManager.getDefault().notify(e); 1165 } 1166 } 1167 } 1168 }); 1169 } 1170 } 1171 1172 1184 private static boolean generateAntDeploymentSupport(EditableProperties privateProps, 1185 FileObject projectDirectory, String serverInstanceID, boolean force) { 1186 1187 try { 1189 File projectDir = FileUtil.toFile(projectDirectory); 1190 File antDeploymentScript = new File (projectDir, ANT_DEPLOY_BUILD_SCRIPT); 1191 if (force || !antDeploymentScript.exists()) { 1192 AntDeploymentHelper.writeDeploymentScript(antDeploymentScript, J2eeModule.EAR, serverInstanceID); 1193 } 1194 } catch (IOException ioe) { 1195 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 1196 } 1197 1198 File deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID); 1200 1201 String newDeployAntPropsFilePath = (deployAntPropsFile == null) ? null : deployAntPropsFile.getAbsolutePath(); 1202 String oldDeployAntPropsFilePath = privateProps.getProperty(DEPLOY_ANT_PROPS_FILE); 1203 1204 if (oldDeployAntPropsFilePath != null && newDeployAntPropsFilePath == null) { 1205 privateProps.remove(DEPLOY_ANT_PROPS_FILE); 1206 } else if (newDeployAntPropsFilePath != null && !newDeployAntPropsFilePath.equals(oldDeployAntPropsFilePath)) { 1207 privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, newDeployAntPropsFilePath); 1208 } else { 1209 return false; 1211 } 1212 return true; 1214 } 1215 1216 public static void setServerInstance(final Project project, final UpdateHelper helper, final String serverInstanceID) { 1217 ProjectManager.mutex().writeAccess(new Runnable () { 1218 public void run() { 1219 try { 1220 EditableProperties projectProps = helper.getProperties(PROJECT); 1221 EditableProperties privateProps = helper.getProperties(PRIVATE); 1222 1223 projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(serverInstanceID)); 1225 privateProps.setProperty(J2EE_SERVER_INSTANCE, serverInstanceID); 1226 1227 generateAntDeploymentSupport(privateProps, project.getProjectDirectory(), serverInstanceID, true); 1229 1230 helper.putProperties(PROJECT, projectProps); 1231 helper.putProperties(PRIVATE, privateProps); 1232 ProjectManager.getDefault().saveProject(project); 1233 } 1234 catch (IOException e) { 1235 ErrorManager.getDefault().notify(e); 1236 } 1237 } 1238 }); 1239 } 1240 1241 1244 private void resolveProjectDependencies() { 1245 1246 String allPaths[] = { JAVAC_CLASSPATH, JAR_CONTENT_ADDITIONAL, RUN_CLASSPATH }; 1247 1248 Set <VisualClassPathItem> oldArtifacts = new HashSet <VisualClassPathItem>(); 1250 Set <VisualClassPathItem> newArtifacts = new HashSet <VisualClassPathItem>(); 1251 for ( int i = 0; i < allPaths.length; i++ ) { 1252 PropertyInfo pi = (PropertyInfo)properties.get( allPaths[i] ); 1253 1254 @SuppressWarnings ("unchecked") 1256 List <VisualClassPathItem> oldList = (List )pi.getOldValue(); 1257 if ( oldList != null ) { 1258 oldArtifacts.addAll(oldList); 1259 } 1260 1261 @SuppressWarnings ("unchecked") 1263 List <VisualClassPathItem> newList = (List ) pi.getValue(); 1264 if ( newList != null ) { 1265 newArtifacts.addAll(newList); 1266 } 1267 1268 } 1269 1270 Set <VisualClassPathItem> removed = new HashSet <VisualClassPathItem>(oldArtifacts); 1272 removed.removeAll( newArtifacts ); 1273 Set <VisualClassPathItem> added = new HashSet <VisualClassPathItem>(newArtifacts); 1274 added.removeAll(oldArtifacts); 1275 1276 @SuppressWarnings ("unchecked") 1277 Set <VisualClassPathItem> oldContent = new HashSet <VisualClassPathItem>( 1278 (List )((PropertyInfo) properties.get(JAR_CONTENT_ADDITIONAL)).getOldValue()); 1279 @SuppressWarnings ("unchecked") 1280 Set <VisualClassPathItem> newContent = new HashSet <VisualClassPathItem>( 1281 (List ) ((PropertyInfo) properties.get(JAR_CONTENT_ADDITIONAL)).getValue()); 1282 1283 updateContentDependency(oldContent, newContent); 1284 1285 for (VisualClassPathItem vcpi : removed) { 1288 if ( vcpi.getType() == VisualClassPathItem.Type.ARTIFACT || 1289 vcpi.getType() == VisualClassPathItem.Type.JAR ) { 1290 boolean used = false; for (int i=0; i < allPaths.length; i++) { 1292 PropertyInfo pi = (PropertyInfo)properties.get( allPaths[i] ); 1293 @SuppressWarnings ("unchecked") 1294 List <VisualClassPathItem> values = (List ) pi.getOldValue(); 1295 if (values == null) { 1296 break; 1297 } 1298 for (VisualClassPathItem valcpi : values) { 1299 if (valcpi.getRaw().indexOf(vcpi.getRaw()) > -1) { 1300 used = true; 1301 break; 1302 } 1303 } 1304 } 1305 if (!used) { 1306 refHelper.destroyReference(vcpi.getRaw()); 1307 } 1308 1309 } 1310 } 1311 1312 EditableProperties ep = updateHelper.getProperties( PROJECT ); 1314 boolean changed = false; 1315 1316 for (VisualClassPathItem vcpi : removed) { 1317 if (vcpi.getType() == VisualClassPathItem.Type.LIBRARY) { 1318 String prop = vcpi.getRaw(); 1320 prop = prop.substring(2, prop.length()-1); 1321 ep.remove(prop); 1322 changed = true; 1323 } 1324 } 1325 File projDir = FileUtil.toFile(antProjectHelper.getProjectDirectory()); 1326 for (VisualClassPathItem vcpi : added) { 1327 if (vcpi.getType() == VisualClassPathItem.Type.LIBRARY) { 1328 String prop = vcpi.getRaw(); 1331 prop = prop.substring(2, prop.length()-1); 1332 String value = relativizeLibraryClasspath(prop, projDir); 1333 if (value != null) { 1334 ep.setProperty(prop, value); 1335 ep.setComment(prop, new String []{ 1336 "# Property "+prop+" is set here just to make sharing of project simpler.", "# The library definition has always preference over this property."}, false); changed = true; 1339 } 1340 } 1341 } 1342 if (changed) { 1343 updateHelper.putProperties(PROJECT, ep); 1344 } 1345 } 1346 1347 1353 private String relativizeLibraryClasspath(String property, File projectDir) { 1354 String value = PropertyUtils.getGlobalProperties().getProperty(property); 1355 if (value == null) { 1357 return null; 1358 } 1359 String [] paths = PropertyUtils.tokenizePath(value); 1360 StringBuffer sb = new StringBuffer (); 1361 for (int i=0; i<paths.length; i++) { 1362 File f = antProjectHelper.resolveFile(paths[i]); 1363 if (CollocationQuery.areCollocated(f, projectDir)) { 1364 sb.append(PropertyUtils.relativizeFile(projectDir, f)); 1365 } else { 1366 return null; 1367 } 1368 if (i+1<paths.length) { 1369 sb.append(File.pathSeparatorChar); 1370 } 1371 } 1372 if (sb.length() == 0) { 1373 return null; 1374 } else { 1375 return sb.toString(); 1376 } 1377 } 1378 1379 private class PropertyInfo { 1380 1381 private PropertyDescriptor propertyDesciptor; 1382 private Object value; 1383 private String evaluatedValue; 1384 private Object newValue; 1385 private String newValueEncoded; 1386 1387 public PropertyInfo( PropertyDescriptor propertyDescriptor, String rawValue, String evaluatedValue) { 1388 update(propertyDescriptor, rawValue, evaluatedValue); 1389 } 1390 1391 final void update(PropertyDescriptor propertyDescriptor, String rawValue, String evaluatedValue) { 1392 this.propertyDesciptor = propertyDescriptor; 1393 this.evaluatedValue = evaluatedValue; 1394 this.value = propertyDesciptor.parser.decode( rawValue, antProjectHelper, refHelper ); 1395 } 1396 1397 public PropertyDescriptor getPropertyDescriptor() { 1398 return propertyDesciptor; 1399 } 1400 1401 public void encode() { 1402 if ( isModified() ) { 1403 newValueEncoded = propertyDesciptor.parser.encode( newValue, antProjectHelper, refHelper); 1404 } 1405 else { 1406 newValueEncoded = null; 1407 } 1408 } 1409 1410 public Object getValue() { 1411 return isModified() ? newValue : value; 1412 } 1413 1414 public void setValue( Object value ) { 1415 newValue = value; 1416 } 1417 1418 public String getNewValueEncoded() { 1419 return newValueEncoded; 1420 } 1421 1422 public boolean isModified() { 1423 return newValue != null; 1424 } 1425 1426 public Object getOldValue() { 1427 return value; 1428 } 1429 } 1430 1431 static class PropertyDescriptor { 1432 1433 interface Saver { 1434 void save(PropertyInfo propertyInfo); 1435 } 1436 1437 final PropertyParser parser; 1438 final String name; 1439 final String dest; 1440 final Saver saver; 1441 1442 1447 PropertyDescriptor(String name, String dest, PropertyParser parser, Saver saver) { 1448 this.name = name; 1449 this.dest = dest; 1450 this.saver = saver; 1451 this.parser = parser; 1452 } 1453 1454 1458 PropertyDescriptor( String name, String dest, PropertyParser parser ) { 1459 this(name, dest, parser, null); 1460 } 1461 1462 } 1463 1464 private static abstract class PropertyParser { 1465 1466 public abstract Object decode( String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ); 1467 1468 public abstract String encode( Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ); 1469 1470 } 1471 1472 private static class StringParser extends PropertyParser { 1473 1474 public Object decode(String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1475 return raw; 1476 } 1477 1478 public String encode(Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1479 return (String )value; 1480 } 1481 1482 } 1483 1484 private static class BooleanParser extends PropertyParser { 1485 1486 public Object decode(String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1487 1488 if ( raw != null ) { 1489 String lowecaseRaw = raw.toLowerCase(); 1490 1491 if ( lowecaseRaw.equals( "true") || lowecaseRaw.equals( "yes") || lowecaseRaw.equals( "enabled") ) { return Boolean.TRUE; 1495 } 1496 } 1497 1498 return Boolean.FALSE; 1499 } 1500 1501 public String encode(Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1502 return ((Boolean )value).booleanValue() ? "true" : "false"; } 1504 1505 } 1506 1507 private static class InverseBooleanParser extends BooleanParser { 1508 1509 public Object decode(String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1510 return ((Boolean )super.decode( raw, antProjectHelper, refHelper )).booleanValue() ? Boolean.FALSE : Boolean.TRUE; 1511 } 1512 1513 public String encode(Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1514 return super.encode( ((Boolean )value).booleanValue() ? Boolean.FALSE : Boolean.TRUE, antProjectHelper, refHelper ); 1515 } 1516 1517 } 1518 1519 private static final String LIBRARY_PREFIX = "${libs."; private static final String ANT_ARTIFACT_PREFIX = "${reference."; 1523 private static final String [][] WELL_KNOWN_PATHS = new String [][] { 1525 { JAVAC_CLASSPATH, NbBundle.getMessage( EarProjectProperties.class, "LBL_JavacClasspath_DisplayName" ) } }; 1527 1528 private class PathParser extends PropertyParser { 1529 private final String webLibraryElementName; 1530 private static final String TAG_PATH_IN_EAR = "path-in-war"; private static final String TAG_FILE = "file"; private static final String TAG_LIBRARY = "library"; 1534 public PathParser() { 1535 this(null); 1536 } 1537 1538 public PathParser(String webLibraryElementName) { 1539 this.webLibraryElementName = webLibraryElementName; 1540 } 1541 1542 public Object decode(String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1543 Map <String , String > earIncludesMap = createEarIncludesMap(); 1544 if (raw != null) { 1545 String pe[] = PropertyUtils.tokenizePath( raw ); 1546 for( int i = 0; i < pe.length; i++ ) { 1547 final String pathItem = pe[i]; 1548 if (!earIncludesMap.containsKey(pathItem)) { 1549 earIncludesMap.put(pathItem, VisualClassPathItem.PATH_IN_EAR); } 1551 } 1552 } 1553 List <VisualClassPathItem> cpItems = new ArrayList <VisualClassPathItem>(earIncludesMap.size() ); 1554 for (Map.Entry <String , String > entry : earIncludesMap.entrySet()) { 1555 cpItems.add(createVisualClassPathItem(antProjectHelper, refHelper, 1556 entry.getKey(), entry.getValue())); 1557 } 1558 return cpItems; 1559 } 1560 1561 public String encode( Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) { 1562 Element data = null; 1563 Element webModuleLibs = null; 1564 Document doc = null; 1565 if(webLibraryElementName != null) { 1566 final String ns = abpt.getPrimaryConfigurationDataElementNamespace(true); 1567 data = updateHelper.getPrimaryConfigurationData(true); 1568 doc = data.getOwnerDocument(); 1569 webModuleLibs = (Element ) data.getElementsByTagNameNS(ns, 1570 webLibraryElementName).item(0); 1571 if (webModuleLibs == null) { 1573 webModuleLibs = doc.createElementNS(ns, webLibraryElementName); data.appendChild(webModuleLibs); 1575 } 1576 while (webModuleLibs.hasChildNodes()) { 1577 webModuleLibs.removeChild(webModuleLibs.getChildNodes().item(0)); 1578 } 1579 } 1580 StringBuffer sb = new StringBuffer (); 1581 for ( Iterator it = ((List )value).iterator(); it.hasNext(); ) { 1582 VisualClassPathItem visualClassPathItem = (VisualClassPathItem)it.next(); 1583 String pathItem = getPathItem(visualClassPathItem, refHelper); 1584 if(webLibraryElementName != null) { 1585 webModuleLibs.appendChild(createLibraryElement(doc, pathItem, visualClassPathItem)); 1586 } 1587 sb.append(pathItem); 1588 if ( it.hasNext() ) { 1589 sb.append( File.pathSeparatorChar ); 1590 } 1591 } 1592 if(webLibraryElementName != null) { 1593 updateHelper.putPrimaryConfigurationData(data, true); 1594 } 1595 return sb.toString(); 1596 } 1597 1598 private Element createLibraryElement(Document doc, String pathItem, 1599 VisualClassPathItem visualClassPathItem) { 1600 final String ns = abpt.getPrimaryConfigurationDataElementNamespace(true); 1601 Element libraryElement = doc.createElementNS(ns, 1602 TAG_LIBRARY); 1603 1604 List <File > files = new ArrayList <File >(); 1605 List <File > dirs = new ArrayList <File >(); 1606 getFilesForItem(visualClassPathItem, files, dirs); 1607 if (files.size() > 0) { 1608 libraryElement.setAttribute(ATTR_FILES, "" + files.size()); 1609 } 1610 if (dirs.size() > 0) { 1611 libraryElement.setAttribute(ATTR_DIRS, "" + dirs.size()); 1612 } 1613 1614 Element webFile = doc.createElementNS(ns, TAG_FILE); 1615 libraryElement.appendChild(webFile); 1616 webFile.appendChild(doc.createTextNode(pathItem)); 1617 if (visualClassPathItem.getPathInEAR() != VisualClassPathItem.PATH_IN_EAR_NONE) { 1618 Element pathInEar = doc.createElementNS(ns, 1619 TAG_PATH_IN_EAR); 1620 pathInEar.appendChild(doc.createTextNode(visualClassPathItem.getPathInEAR())); 1621 libraryElement.appendChild(pathInEar); 1622 } 1623 return libraryElement; 1624 } 1625 1626 private Map <String , String > createEarIncludesMap() { 1627 Map <String , String > earIncludesMap = new LinkedHashMap <String , String >(); 1628 if (webLibraryElementName != null) { 1629 Element data = updateHelper.getPrimaryConfigurationData(true); 1630 final String ns = abpt.getPrimaryConfigurationDataElementNamespace(true); 1631 Element webModuleLibs = (Element ) data.getElementsByTagNameNS(ns, webLibraryElementName).item(0); 1633 if(webModuleLibs != null) { 1634 NodeList ch = webModuleLibs.getChildNodes(); 1635 for (int i = 0; i < ch.getLength(); i++) { 1636 if (ch.item(i).getNodeType() == Node.ELEMENT_NODE) { 1637 Element library = (Element ) ch.item(i); 1638 Node webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0); 1639 NodeList pathInEarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_EAR); 1640 earIncludesMap.put(findText(webFile), pathInEarElements.getLength() > 0 ? 1641 findText(pathInEarElements.item(0)) : VisualClassPathItem.PATH_IN_EAR_NONE); 1642 } 1643 } 1644 } 1645 } 1646 return earIncludesMap; 1647 } 1648 1649 private VisualClassPathItem createVisualClassPathItem(AntProjectHelper antProjectHelper, 1650 ReferenceHelper refHelper, String raw, String pathInEAR) { 1651 for (int j = 0; j < WELL_KNOWN_PATHS.length; j++) { 1654 final String [] wellKnownPath = WELL_KNOWN_PATHS[j]; 1655 if (wellKnownPath[0].equals(getAntPropertyName(raw))) { 1656 return new VisualClassPathItem(raw, VisualClassPathItem.Type.CLASSPATH, raw, 1657 wellKnownPath[1], pathInEAR); 1658 } 1659 } 1660 if (raw.startsWith(LIBRARY_PREFIX)) { 1661 String eval = raw.substring(LIBRARY_PREFIX.length(), raw.lastIndexOf('.')); Library lib = LibraryManager.getDefault().getLibrary(eval); 1665 if (lib != null) { 1666 return new VisualClassPathItem(lib, VisualClassPathItem.Type.LIBRARY, raw, eval, pathInEAR); 1667 } else { 1668 return new VisualClassPathItem(null, VisualClassPathItem.Type.LIBRARY, raw, null, pathInEAR); 1669 } 1670 } else if (raw.startsWith(ANT_ARTIFACT_PREFIX)) { 1671 AntArtifact artifact = (AntArtifact) refHelper.findArtifactAndLocation(raw)[0]; 1672 if (artifact != null) { 1673 return VisualClassPathItem.createArtifact(artifact, raw, pathInEAR); 1675 } else { 1676 return VisualClassPathItem.createArtifact(null, raw, null, pathInEAR); 1677 } 1678 } else { 1679 String eval; 1681 if (isAntProperty(raw)) { 1682 eval = antProjectHelper.getStandardPropertyEvaluator().getProperty(getAntPropertyName(raw)); 1683 } else { 1684 eval = raw; 1685 } 1686 File f = (eval == null) ? null : antProjectHelper.resolveFile(eval); 1687 return VisualClassPathItem.createJAR(f, raw, pathInEAR, eval); 1688 } 1689 } 1690 1691 private String getPathItem(VisualClassPathItem vcpi, ReferenceHelper refHelper) { 1692 switch (vcpi.getType()) { 1693 case JAR: 1694 String pathItem = vcpi.getRaw(); 1695 if (pathItem == null) { 1696 return refHelper.createForeignFileReference((File ) vcpi.getObject(), 1698 JavaProjectConstants.ARTIFACT_TYPE_JAR); 1699 } else { 1700 return pathItem; 1701 } 1702 case ARTIFACT: 1703 if (vcpi.getObject() != null) { 1704 AntArtifact aa = (AntArtifact) vcpi.getObject(); 1705 return (String ) refHelper.addReference(aa, aa.getArtifactLocations()[0]); 1706 } else { 1707 return vcpi.getRaw(); 1708 } 1709 case LIBRARY: 1710 case CLASSPATH: 1711 return vcpi.getRaw(); 1712 default: 1713 assert false : "Unknown VisualClassPathItem type: " + vcpi.getType(); 1714 return null; 1715 } 1716 } 1717 } 1718 1719 1725 private static String findText(Node parent) { 1726 NodeList l = parent.getChildNodes(); 1727 for (int i = 0; i < l.getLength(); i++) { 1728 if (l.item(i).getNodeType() == Node.TEXT_NODE) { 1729 Text text = (Text )l.item(i); 1730 return text.getNodeValue(); 1731 } 1732 } 1733 return null; 1734 } 1735 1736 1737 private static JavaPlatform findPlatform(String platformAntID) { 1738 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms(); 1739 for(int i = 0; i < platforms.length; i++) { 1740 String normalizedName = (String )platforms[i].getProperties().get("platform.ant.name"); if (normalizedName != null && normalizedName.equals(platformAntID)) { 1742 return platforms[i]; 1743 } 1744 } 1745 return null; 1746 } 1747 1748 private static class PlatformParser extends PropertyParser { 1749 1750 public Object decode(String raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { 1751 JavaPlatform platform = findPlatform(raw); 1752 if (platform != null) { 1753 return platform.getDisplayName(); 1754 } 1755 return raw; 1757 } 1758 1759 public String encode(Object value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { 1760 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms ((String )value, 1761 new Specification ("j2se",null)); if (platforms.length == 0) { 1763 return (String )value; 1766 } else { 1767 return (String ) platforms[0].getProperties().get("platform.ant.name"); } 1769 } 1770 } 1771 1772 private void writeWebLibraries(ReferenceHelper refHelper, List value, 1773 final String elementName) { 1774 Element data = updateHelper.getPrimaryConfigurationData(true); 1775 Document doc = data.getOwnerDocument(); 1776 Element webModuleLibs = (Element ) data.getElementsByTagNameNS(abpt.getPrimaryConfigurationDataElementNamespace(true), 1777 elementName).item(0); 1779 if (webModuleLibs == null) { 1781 webModuleLibs = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), elementName); data.appendChild(webModuleLibs); 1783 } 1784 1785 while (webModuleLibs.hasChildNodes()) { 1786 webModuleLibs.removeChild(webModuleLibs.getChildNodes().item(0)); 1787 } 1788 1789 for (Iterator it = value.iterator(); it.hasNext();) { 1790 VisualClassPathItem vcpi = (VisualClassPathItem) it.next(); 1791 String library_tag_value = ""; 1792 1793 if (vcpi == null) { 1795 return; 1796 } 1797 1798 switch (vcpi.getType()) { 1799 case JAR: 1800 String raw = vcpi.getRaw(); 1801 1802 if (raw == null) { 1803 File file = (File ) vcpi.getObject(); 1805 String reference = refHelper.createForeignFileReference(file, 1806 JavaProjectConstants.ARTIFACT_TYPE_JAR); 1807 library_tag_value = reference; 1808 } else { 1809 library_tag_value = raw; 1811 } 1812 1813 break; 1814 case LIBRARY: 1815 library_tag_value = vcpi.getRaw(); 1816 break; 1817 case ARTIFACT: 1818 AntArtifact aa = (AntArtifact) vcpi.getObject(); 1819 String reference = (String ) refHelper.addReference(aa, aa.getArtifactLocations()[0]); 1820 library_tag_value = reference; 1821 break; 1822 case CLASSPATH: 1823 library_tag_value = vcpi.getRaw(); 1824 break; 1825 default: 1826 assert false : "Unknown VisualClassPathItem type: " + vcpi.getType(); 1827 } 1828 1829 Element library = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "library"); webModuleLibs.appendChild(library); 1831 Element webFile = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "file"); library.appendChild(webFile); 1833 webFile.appendChild(doc.createTextNode(library_tag_value)); 1834 String piw = vcpi.getPathInEAR(); 1835 if (piw != VisualClassPathItem.PATH_IN_EAR_NONE) { 1836 Element pathInEar = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "path-in-war"); pathInEar.appendChild(doc.createTextNode(vcpi.getPathInEAR())); 1838 library.appendChild(pathInEar); 1839 } 1840 } 1841 updateHelper.putPrimaryConfigurationData(data, true); 1842 } 1843 1844 1860 public static void storeLibrariesLocations (Iterator <VisualClassPathItem> classpath, 1861 Iterator <VisualClassPathItem> oldClasspath, EditableProperties privateProps) { 1862 List <String > exLibs = new ArrayList <String >(); 1863 Iterator propKeys = privateProps.keySet().iterator(); 1864 while (propKeys.hasNext()) { 1865 String key = (String ) propKeys.next(); 1866 if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || (key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { exLibs.add(key); 1869 } 1870 } 1871 while (classpath.hasNext()) { 1872 VisualClassPathItem item = classpath.next(); 1873 if(item.getObject() == null) { 1876 continue; 1877 } 1878 1879 List <File > files = new ArrayList <File >(); 1880 List <File > dirs = new ArrayList <File >(); 1881 getFilesForItem (item, files, dirs); 1882 String key; 1883 String ref = item.getRaw(); 1884 if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) { 1885 for (int i = 0; i < files.size(); i++) { 1886 File f = files.get(i); 1887 key = getAntPropertyName(ref)+".libfile." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 1890 } 1891 } 1892 if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) { 1893 for (int i = 0; i < dirs.size(); i++) { 1894 File f = dirs.get(i); 1895 key = getAntPropertyName(ref)+".libdir." + (i+1); privateProps.setProperty (key, "" + f.getAbsolutePath()); exLibs.remove(key); 1898 } 1899 } 1900 } 1901 Iterator unused = exLibs.iterator(); 1902 while (unused.hasNext()) { 1903 privateProps.remove(unused.next()); 1904 } 1905 } 1906 1907 public static final void getFilesForItem (VisualClassPathItem item, List <File > files, List <File > dirs) { 1908 if (item.getType() == VisualClassPathItem.Type.LIBRARY) { 1909 @SuppressWarnings ("unchecked") 1910 List <URL > roots = ((Library)item.getObject()).getContent("classpath"); for (URL rootUrl : roots) { 1912 FileObject root = URLMapper.findFileObject (rootUrl); 1913 if ("jar".equals(rootUrl.getProtocol())) { root = FileUtil.getArchiveFile (root); 1915 } 1916 File f = FileUtil.toFile(root); 1917 if (f != null) { 1918 if (f.isFile()) { 1919 files.add(f); 1920 } else { 1921 dirs.add(f); 1922 } 1923 } 1924 } 1925 } 1926 if (item.getType() == VisualClassPathItem.Type.JAR) { 1927 File root = (File )item.getObject(); 1928 if (root != null) { 1929 if (root.isFile()) { 1930 files.add(root); 1931 } else { 1932 dirs.add(root); 1933 } 1934 } 1935 } 1936 if (item.getType() == VisualClassPathItem.Type.ARTIFACT) { 1937 AntArtifact artifact = (AntArtifact)item.getObject(); 1938 if (artifact != null) { 1939 String artifactFolder = artifact.getScriptLocation().getParent(); 1940 URI roots[] = artifact.getArtifactLocations(); 1941 for (int i = 0; i < roots.length; i++) { 1942 String root = artifactFolder + File.separator + roots [i]; 1943 if (root.endsWith(File.separator)) { 1944 dirs.add(new File (root)); 1945 } else { 1946 files.add(new File (root)); 1947 } 1948 } 1949 } 1950 } 1951 } 1952 1953 private static boolean showModifiedMessage(final String title) { 1954 String message = NbBundle.getMessage(EarProjectProperties.class,"TXT_Regenerate"); 1955 JButton regenerateButton = new JButton (NbBundle.getMessage(EarProjectProperties.class,"CTL_RegenerateButton")); 1956 regenerateButton.setDefaultCapable(true); 1957 regenerateButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarProjectProperties.class,"AD_RegenerateButton")); 1958 NotifyDescriptor d = new NotifyDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE); 1959 d.setTitle(title); 1960 d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); 1961 d.setOptions(new Object [] {regenerateButton, NotifyDescriptor.CANCEL_OPTION}); 1962 return DialogDisplayer.getDefault().notify(d) == regenerateButton; 1963 } 1964 1965} 1966 | Popular Tags |