1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.awt.EventQueue ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.beans.PropertyEditor ; 26 import java.io.IOException ; 27 import java.lang.reflect.InvocationTargetException ; 28 import java.text.Collator ; 29 import java.util.Arrays ; 30 import java.util.Comparator ; 31 import java.util.HashMap ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.LinkedHashSet ; 35 import java.util.Map ; 36 import java.util.Set ; 37 import java.util.SortedMap ; 38 import java.util.SortedSet ; 39 import java.util.TreeMap ; 40 import java.util.TreeSet ; 41 import javax.swing.event.ChangeEvent ; 42 import javax.swing.event.ChangeListener ; 43 import org.netbeans.api.java.platform.JavaPlatform; 44 import org.netbeans.api.java.platform.PlatformsCustomizer; 45 import org.netbeans.api.project.ProjectUtils; 46 import org.netbeans.modules.apisupport.project.ManifestManager; 47 import org.netbeans.modules.apisupport.project.NbModuleProject; 48 import org.netbeans.modules.apisupport.project.NbModuleProjectType; 49 import org.netbeans.modules.apisupport.project.Util; 50 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 51 import org.netbeans.modules.apisupport.project.ui.UIUtil; 52 import org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory; 53 import org.netbeans.modules.apisupport.project.ui.platform.NbPlatformCustomizer; 54 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 55 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 56 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 57 import org.openide.ErrorManager; 58 import org.openide.NotifyDescriptor; 59 import org.openide.explorer.ExplorerManager; 60 import org.openide.modules.Dependency; 61 import org.openide.modules.SpecificationVersion; 62 import org.openide.nodes.AbstractNode; 63 import org.openide.nodes.Children; 64 import org.openide.nodes.Node; 65 import org.openide.nodes.PropertySupport; 66 import org.openide.nodes.Sheet; 67 import org.openide.util.NbBundle; 68 import org.openide.util.RequestProcessor; 69 import org.w3c.dom.Element ; 70 71 76 final class SuiteCustomizerLibraries extends NbPropertyPanel.Suite 77 implements Comparator , ExplorerManager.Provider, ChangeListener { 78 private ExplorerManager manager; 79 private ModuleEntry[] platformModules; 80 private ProjectCustomizer.Category cat; 81 82 85 public SuiteCustomizerLibraries(final SuiteProperties suiteProps, ProjectCustomizer.Category cat) { 86 super(suiteProps, SuiteCustomizerLibraries.class); 87 initComponents(); 88 this.cat = cat; 89 initAccessibility(); 90 manager = new ExplorerManager(); 91 refresh(); 92 93 94 view.setProperties(new Node.Property[] { ENABLED_PROP_TEMPLATE }); 95 view.setRootVisible(false); 96 view.setDefaultActionAllowed(false); 97 98 suiteProps.getBrandingModel().addChangeListener(this); 99 suiteProps.addPropertyChangeListener(new PropertyChangeListener () { 100 public void propertyChange(PropertyChangeEvent evt) { 101 if (SuiteProperties.NB_PLATFORM_PROPERTY.equals(evt.getPropertyName())) { 102 refresh(); 103 } 104 } 105 }); 106 107 javaPlatformCombo.setRenderer(JavaPlatformComponentFactory.javaPlatformListCellRenderer()); 108 } 109 110 void refresh() { 111 refreshJavaPlatforms(); 112 refreshPlatforms(); 113 RequestProcessor.getDefault().post(new Runnable () { 114 public void run() { 115 refreshModules(); 116 } 117 }); 118 updateJavaPlatformEnabled(); 119 } 120 121 private void refreshModules() { 122 platformModules = getProperties().getActivePlatform().getModules(); 123 Node root = createPlatformModulesNode(); 124 manager.setRootContext(root); 125 synchronized (this) { 126 universe = null; 127 } 128 updateDependencyWarnings(); 129 } 130 131 private void refreshJavaPlatforms() { 132 javaPlatformCombo.setModel(JavaPlatformComponentFactory.javaPlatformListModel()); 133 javaPlatformCombo.setSelectedItem(getProperties().getActiveJavaPlatform()); 134 } 135 136 private void refreshPlatforms() { 137 platformValue.setModel(new PlatformComponentFactory.NbPlatformListModel()); platformValue.setSelectedItem(getProperties().getActivePlatform()); 139 platformValue.requestFocus(); 140 } 141 142 public void store() { 143 Set enabledClusters = new TreeSet (); 144 Set disabledModules = new TreeSet (); 145 146 Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes(); 147 for (int i = 0; i < clusters.length; i++) { 148 if (clusters[i] instanceof Enabled) { 149 Enabled e = (Enabled)clusters[i]; 150 if (e.isEnabled()) { 151 enabledClusters.add(e.getName()); 152 Node[] modules = e.getChildren().getNodes(); 153 for (int j = 0; j < modules.length; j++) { 154 if (modules[j] instanceof Enabled) { 155 Enabled m = (Enabled)modules[j]; 156 if (!m.isEnabled()) { 157 disabledModules.add(m.getName()); 158 } 159 } 160 } 161 } 162 } 163 } 164 165 getProperties().setEnabledClusters((String []) enabledClusters.toArray(new String [enabledClusters.size()])); 166 getProperties().setDisabledModules((String []) disabledModules.toArray(new String [disabledModules.size()])); 167 } 168 169 174 private void initComponents() { 176 java.awt.GridBagConstraints gridBagConstraints; 177 178 platformsPanel = new javax.swing.JPanel (); 179 platformValue = org.netbeans.modules.apisupport.project.ui.platform.PlatformComponentFactory.getNbPlatformsComboxBox(); 180 platform = new javax.swing.JLabel (); 181 managePlafsButton = new javax.swing.JButton (); 182 javaPlatformLabel = new javax.swing.JLabel (); 183 javaPlatformCombo = new javax.swing.JComboBox (); 184 javaPlatformButton = new javax.swing.JButton (); 185 filler = new javax.swing.JLabel (); 186 view = new org.openide.explorer.view.TreeTableView(); 187 viewLabel = new javax.swing.JLabel (); 188 189 setLayout(new java.awt.GridBagLayout ()); 190 191 platformsPanel.setLayout(new java.awt.GridBagLayout ()); 192 193 platformValue.addItemListener(new java.awt.event.ItemListener () { 194 public void itemStateChanged(java.awt.event.ItemEvent evt) { 195 platformValueItemStateChanged(evt); 196 } 197 }); 198 199 gridBagConstraints = new java.awt.GridBagConstraints (); 200 gridBagConstraints.gridx = 1; 201 gridBagConstraints.gridy = 1; 202 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 203 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 204 gridBagConstraints.weightx = 1.0; 205 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 12); 206 platformsPanel.add(platformValue, gridBagConstraints); 207 208 platform.setLabelFor(platformValue); 209 org.openide.awt.Mnemonics.setLocalizedText(platform, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_NetBeansPlatform")); 210 gridBagConstraints = new java.awt.GridBagConstraints (); 211 gridBagConstraints.gridx = 0; 212 gridBagConstraints.gridy = 1; 213 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 214 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 12); 215 platformsPanel.add(platform, gridBagConstraints); 216 217 org.openide.awt.Mnemonics.setLocalizedText(managePlafsButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "CTL_ManagePlatform_a")); 218 managePlafsButton.addActionListener(new java.awt.event.ActionListener () { 219 public void actionPerformed(java.awt.event.ActionEvent evt) { 220 managePlatforms(evt); 221 } 222 }); 223 224 gridBagConstraints = new java.awt.GridBagConstraints (); 225 gridBagConstraints.gridx = 2; 226 gridBagConstraints.gridy = 1; 227 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 228 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 229 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 230 platformsPanel.add(managePlafsButton, gridBagConstraints); 231 232 javaPlatformLabel.setLabelFor(javaPlatformCombo); 233 org.openide.awt.Mnemonics.setLocalizedText(javaPlatformLabel, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Java_Platform")); 234 gridBagConstraints = new java.awt.GridBagConstraints (); 235 gridBagConstraints.gridx = 0; 236 gridBagConstraints.gridy = 0; 237 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 238 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 239 platformsPanel.add(javaPlatformLabel, gridBagConstraints); 240 241 javaPlatformCombo.addItemListener(new java.awt.event.ItemListener () { 242 public void itemStateChanged(java.awt.event.ItemEvent evt) { 243 javaPlatformComboItemStateChanged(evt); 244 } 245 }); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 1; 249 gridBagConstraints.gridy = 0; 250 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 251 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 252 gridBagConstraints.weightx = 1.0; 253 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 254 platformsPanel.add(javaPlatformCombo, gridBagConstraints); 255 256 org.openide.awt.Mnemonics.setLocalizedText(javaPlatformButton, NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_Manage_Java_Platforms")); 257 javaPlatformButton.addActionListener(new java.awt.event.ActionListener () { 258 public void actionPerformed(java.awt.event.ActionEvent evt) { 259 javaPlatformButtonActionPerformed(evt); 260 } 261 }); 262 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.gridx = 2; 265 gridBagConstraints.gridy = 0; 266 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 267 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 268 platformsPanel.add(javaPlatformButton, gridBagConstraints); 269 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 0; 272 gridBagConstraints.gridy = 0; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.weightx = 1.0; 275 add(platformsPanel, gridBagConstraints); 276 277 gridBagConstraints = new java.awt.GridBagConstraints (); 278 gridBagConstraints.gridx = 0; 279 gridBagConstraints.gridy = 1; 280 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 281 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 282 gridBagConstraints.weighty = 1.0; 283 add(filler, gridBagConstraints); 284 285 view.setBorder(javax.swing.UIManager.getBorder("ScrollPane.border")); 286 gridBagConstraints = new java.awt.GridBagConstraints (); 287 gridBagConstraints.gridx = 0; 288 gridBagConstraints.gridy = 2; 289 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 290 gridBagConstraints.weightx = 1.0; 291 gridBagConstraints.weighty = 1.0; 292 add(view, gridBagConstraints); 293 294 viewLabel.setLabelFor(view); 295 org.openide.awt.Mnemonics.setLocalizedText(viewLabel, org.openide.util.NbBundle.getMessage(SuiteCustomizerLibraries.class, "LBL_PlatformModules")); 296 gridBagConstraints = new java.awt.GridBagConstraints (); 297 gridBagConstraints.gridx = 0; 298 gridBagConstraints.gridy = 1; 299 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 300 gridBagConstraints.insets = new java.awt.Insets (18, 0, 2, 0); 301 add(viewLabel, gridBagConstraints); 302 303 } 305 private void javaPlatformButtonActionPerformed(java.awt.event.ActionEvent evt) { PlatformsCustomizer.showCustomizer((JavaPlatform) javaPlatformCombo.getSelectedItem()); 307 } 309 private void javaPlatformComboItemStateChanged(java.awt.event.ItemEvent evt) { getProperties().setActiveJavaPlatform((JavaPlatform) javaPlatformCombo.getSelectedItem()); 311 } 313 private void platformValueItemStateChanged(java.awt.event.ItemEvent evt) { getProperties().setActivePlatform((NbPlatform) platformValue.getSelectedItem()); 315 refreshModules(); 316 updateJavaPlatformEnabled(); 317 } 319 private void managePlatforms(java.awt.event.ActionEvent evt) { NbPlatformCustomizer.showCustomizer(); 321 refreshPlatforms(); 322 } 324 private javax.swing.JLabel filler; 326 private javax.swing.JButton javaPlatformButton; 327 private javax.swing.JComboBox javaPlatformCombo; 328 private javax.swing.JLabel javaPlatformLabel; 329 private javax.swing.JButton managePlafsButton; 330 private javax.swing.JLabel platform; 331 private javax.swing.JComboBox platformValue; 332 private javax.swing.JPanel platformsPanel; 333 private org.openide.explorer.view.TreeTableView view; 334 private javax.swing.JLabel viewLabel; 335 337 338 private Node createPlatformModulesNode() { 339 HashSet disabledModuleCNB = new HashSet (Arrays.asList(getProperties().getDisabledModules())); 340 HashSet enabledClusters = new HashSet (Arrays.asList(getProperties().getEnabledClusters())); 341 342 HashMap clusterToChildren = new HashMap (); 343 344 Children.SortedArray clusters = new Children.SortedArray(); 345 clusters.setComparator(this); 346 AbstractNode n = new AbstractNode(clusters); 347 n.setName(getMessage("LBL_ModuleListClusters")); 348 n.setDisplayName(getMessage("LBL_ModuleListClustersModules")); 349 350 for (int i = 0; i < platformModules.length; i++) { 351 Children clusterChildren = (Children)clusterToChildren.get(platformModules[i].getClusterDirectory()); 352 if (clusterChildren == null) { 353 Children.SortedArray modules = new Children.SortedArray(); 354 modules.setComparator(this); 355 clusterChildren = modules; 356 357 String clusterName = platformModules[i].getClusterDirectory().getName(); 358 Enabled cluster = new Enabled(modules, enabledClusters.contains(clusterName)); 359 cluster.setName(clusterName); 360 cluster.setIconBaseWithExtension(SuiteProject.SUITE_ICON_PATH); 361 clusterToChildren.put(platformModules[i].getClusterDirectory(), modules); 362 n.getChildren().add(new Node[] { cluster }); 363 } 364 365 String cnb = platformModules[i].getCodeNameBase(); 366 AbstractNode module = new Enabled(Children.LEAF, !disabledModuleCNB.contains(cnb)); 367 module.setName(cnb); 368 module.setDisplayName(platformModules[i].getLocalizedName()); 369 String desc = platformModules[i].getShortDescription(); 370 String tooltip; 371 if (desc != null) { 372 if (desc.startsWith("<html>")) { tooltip = "<html>" + NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_desc", cnb, desc.substring(6)); 374 } else { 375 tooltip = NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_desc", cnb, desc); 376 } 377 } else { 378 tooltip = NbBundle.getMessage(SuiteCustomizerLibraries.class, "SuiteCustomizerLibraries.HINT_module_no_desc", cnb); 379 } 380 module.setShortDescription(tooltip); 381 module.setIconBaseWithExtension(NbModuleProject.NB_PROJECT_ICON_PATH); 382 383 clusterChildren.add(new Node[] { module }); 384 } 385 386 return n; 387 } 388 389 public int compare(Object o1, Object o2) { 390 Node n1 = (Node)o1; 391 Node n2 = (Node)o2; 392 393 return n1.getDisplayName().compareTo(n2.getDisplayName()); 394 } 395 396 public ExplorerManager getExplorerManager() { 397 return manager; 398 } 399 400 private static final Set <String > DISABLED_PLATFORM_MODULES = new HashSet (); 401 402 static { 403 DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.autoupdate"); DISABLED_PLATFORM_MODULES.add("org.openide.execution"); DISABLED_PLATFORM_MODULES.add("org.netbeans.core.execution"); DISABLED_PLATFORM_MODULES.add("org.openide.io"); DISABLED_PLATFORM_MODULES.add("org.netbeans.core.output2"); DISABLED_PLATFORM_MODULES.add("org.netbeans.core.multiview"); DISABLED_PLATFORM_MODULES.add("org.netbeans.modules.favorites"); DISABLED_PLATFORM_MODULES.add("org.openide.compat"); DISABLED_PLATFORM_MODULES.add("org.openide.util.enumerations"); } 420 421 public void stateChanged(ChangeEvent ev) { 422 if (getProperties().getBrandingModel().isBrandingEnabled()) { 423 Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes(); 429 for (int i = 0; i < clusters.length; i++) { 430 if (clusters[i] instanceof Enabled) { 431 Enabled e = (Enabled) clusters[i]; 432 if (!e.isEnabled()) { 433 return; 434 } else { 435 Node[] modules = e.getChildren().getNodes(); 436 for (int j = 0; j < modules.length; j++) { 437 if (modules[j] instanceof Enabled) { 438 Enabled m = (Enabled) modules[j]; 439 if (!m.isEnabled()) { 440 return; 441 } 442 } 443 } 444 } 445 } 446 } 447 if (!UIUtil.showAcceptCancelDialog( 449 getMessage("SuiteCustomizerLibraries.title.exclude_ide_modules"), 450 getMessage("SuiteCustomizerLibraries.text.exclude_ide_modules"), 451 getMessage("SuiteCustomizerLibraries.button.exclude"), 452 getMessage("SuiteCustomizerLibraries.button.skip"), 453 NotifyDescriptor.QUESTION_MESSAGE)) { 454 return; 455 } 456 for (int i = 0; i < clusters.length; i++) { 458 if (clusters[i] instanceof Enabled) { 459 Enabled e = (Enabled) clusters[i]; 460 if (e.getName().startsWith("platform")) { Node[] modules = e.getChildren().getNodes(); 462 for (int j = 0; j < modules.length; j++) { 463 if (modules[j] instanceof Enabled) { 464 Enabled m = (Enabled) modules[j]; 465 if (DISABLED_PLATFORM_MODULES.contains(m.getName())) { 466 m.setEnabled(false); 467 } 468 } 469 } 470 } else { 471 e.setEnabled(false); 472 } 473 } 474 } 475 } 476 } 477 478 final class Enabled extends AbstractNode { 479 private boolean enabled; 480 private Children standard; 481 482 public Enabled(Children ch, boolean enabled) { 483 super(ch); 484 this.standard = ch; 485 this.enabled = enabled; 486 487 Sheet s = Sheet.createDefault(); 488 Sheet.Set ss = s.get(Sheet.PROPERTIES); 489 ss.put(new EnabledProp(this)); 490 setSheet(s); 491 } 492 493 public void setEnabled(boolean s) { 494 if (s == enabled) { 495 return; 496 } 497 enabled = s; 498 Node[] all = standard.getNodes(); 500 for (int i = 0; i < all.length; i++) { 501 Node nn = all[i]; 502 if (nn instanceof Enabled) { 503 Enabled en = (Enabled)nn; 504 en.firePropertyChange(null, null, null); 505 } 506 } 507 Node n = getParentNode(); 509 if (n instanceof Enabled) { 510 Enabled en = (Enabled)n; 511 en.firePropertyChange(null, null, null); 512 } 513 updateDependencyWarnings(); 514 } 515 516 public boolean isEnabled() { 517 return enabled; 518 } 519 } 520 521 private static final EnabledProp ENABLED_PROP_TEMPLATE = new EnabledProp(null); 522 private static final class EnabledProp extends PropertySupport.ReadWrite { 523 524 private Enabled node; 525 private PropertyEditor editor; 526 527 public EnabledProp(Enabled node) { 528 super("enabled", Boolean.TYPE, getMessage("LBL_ModuleListEnabled"), getMessage("LBL_ModuleListEnabledShortDescription")); 529 this.node = node; 530 } 531 532 public void setValue(Object val) throws IllegalAccessException , IllegalArgumentException , InvocationTargetException { 533 node.setEnabled(((Boolean )val).booleanValue()); 534 } 535 536 public Object getValue() throws IllegalAccessException , InvocationTargetException { 537 Children ch = node.getChildren(); 538 if (ch == Children.LEAF) { 539 return Boolean.valueOf(node.isEnabled()); 540 } else { 541 Node[] arr = ch.getNodes(); 542 boolean on = false; 543 boolean off = false; 544 for (int i = 0; i < arr.length; i++) { 545 Enabled n = (Enabled)arr[i]; 546 if (n.isEnabled()) { 547 on = true; 548 } else { 549 off = true; 550 } 551 552 if (on && off && node.isEnabled()) { 553 return null; 554 } 555 } 556 557 return Boolean.valueOf(on && node.isEnabled()); 558 } 559 } 560 561 public boolean canWrite() { 562 Node parent = node.getParentNode(); 563 if (parent instanceof Enabled) { 564 return ((Enabled)parent).isEnabled(); 566 } 567 return true; 568 } 569 570 public PropertyEditor getPropertyEditor() { 571 if (editor == null) { 572 editor = super.getPropertyEditor(); 573 } 574 return editor; 575 } 576 577 } 578 579 private static String getMessage(String key) { 580 return NbBundle.getMessage(CustomizerDisplay.class, key); 581 } 582 583 private void initAccessibility() { 584 managePlafsButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ManagePlafsButton")); 585 platformValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PlatformValue")); 586 javaPlatformCombo.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JavaPlatformCombo")); 587 javaPlatformButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JavaPlatformButton")); 588 } 589 590 592 interface UniverseModule { 593 String getCodeNameBase(); 594 int getReleaseVersion(); 595 SpecificationVersion getSpecificationVersion(); 596 String getImplementationVersion(); 597 Set <String > getProvidedTokens(); 598 Set <String > getRequiredTokens(); 599 Set <Dependency> getModuleDependencies(); 600 String getCluster(); 601 String getDisplayName(); 602 } 603 604 private static abstract class AbstractUniverseModule implements UniverseModule { 605 protected final ManifestManager mm; 606 protected AbstractUniverseModule(ManifestManager mm) { 607 this.mm = mm; 608 } 609 public int getReleaseVersion() { 610 String s = mm.getReleaseVersion(); 611 return s != null ? Integer.parseInt(s) : -1; 612 } 613 public String getImplementationVersion() { 614 return mm.getImplementationVersion(); 615 } 616 public Set <String > getProvidedTokens() { 617 return new HashSet (Arrays.asList(mm.getProvidedTokens())); 618 } 619 public Set <String > getRequiredTokens() { 620 Set s = new HashSet (Arrays.asList(mm.getRequiredTokens())); 621 Iterator it = s.iterator(); 622 while (it.hasNext()) { 623 String tok = (String ) it.next(); 624 if (tok.startsWith("org.openide.modules.ModuleFormat") || tok.startsWith("org.openide.modules.os.")) { it.remove(); 626 } 627 } 628 s.addAll(Arrays.asList(mm.getNeededTokens())); 629 return s; 630 } 631 public String toString() { 632 return getCodeNameBase(); 633 } 634 } 635 636 private static final class PlatformModule extends AbstractUniverseModule { 637 private final ModuleEntry entry; 638 public PlatformModule(ModuleEntry entry) throws IOException { 639 super(ManifestManager.getInstanceFromJAR(entry.getJarLocation())); 640 this.entry = entry; 641 } 642 public String getCodeNameBase() { 643 return entry.getCodeNameBase(); 644 } 645 public SpecificationVersion getSpecificationVersion() { 646 String s = entry.getSpecificationVersion(); 647 return s != null ? new SpecificationVersion(s) : null; 648 } 649 public Set <Dependency> getModuleDependencies() { 650 return mm.getModuleDependencies(); 651 } 652 public String getCluster() { 653 return entry.getClusterDirectory().getName(); 654 } 655 public String getDisplayName() { 656 return entry.getLocalizedName(); 657 } 658 } 659 660 private static final class SuiteModule extends AbstractUniverseModule { 661 private final NbModuleProject project; 662 private final Set <Dependency> dependencies; 663 public SuiteModule(NbModuleProject project) { 664 super(ManifestManager.getInstance(project.getManifest(), false)); 665 this.project = project; 666 dependencies = new HashSet (); 667 Element dataE = project.getPrimaryConfigurationData(); 669 Element depsE = Util.findElement(dataE, "module-dependencies", NbModuleProjectType.NAMESPACE_SHARED); Iterator <Element > deps = Util.findSubElements(depsE).iterator(); 671 while (deps.hasNext()) { 672 Element dep = (Element ) deps.next(); 673 Element run = Util.findElement(dep, "run-dependency", NbModuleProjectType.NAMESPACE_SHARED); if (run == null) { 675 continue; 676 } 677 String text = Util.findText(Util.findElement(dep, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED)); Element relverE = Util.findElement(run, "release-version", NbModuleProjectType.NAMESPACE_SHARED); if (relverE != null) { 680 text += '/' + Util.findText(relverE); 681 } 682 Element specverE = Util.findElement(run, "specification-version", NbModuleProjectType.NAMESPACE_SHARED); if (specverE != null) { 684 text += " > " + Util.findText(specverE); 685 } else { 686 Element implver = Util.findElement(run, "implementation-version", NbModuleProjectType.NAMESPACE_SHARED); if (implver != null) { 688 text += " = *"; } 691 } 692 dependencies.addAll(Dependency.create(Dependency.TYPE_MODULE, text)); 693 } 694 } 695 public String getCodeNameBase() { 696 return project.getCodeNameBase(); 697 } 698 public SpecificationVersion getSpecificationVersion() { 699 String s = project.getSpecVersion(); 700 return s != null ? new SpecificationVersion(s) : null; 701 } 702 public Set <Dependency> getModuleDependencies() { 703 return dependencies; 704 } 705 public String getCluster() { 706 return null; 707 } 708 public String getDisplayName() { 709 return ProjectUtils.getInformation(project).getDisplayName(); 710 } 711 } 712 713 private RequestProcessor.Task updateDependencyWarningsTask; 714 private void updateDependencyWarnings() { 715 if (updateDependencyWarningsTask == null) { 717 updateDependencyWarningsTask = RequestProcessor.getDefault().create(new Runnable () { 718 public void run() { 719 doUpdateDependencyWarnings(); 720 } 721 }); 722 } 723 updateDependencyWarningsTask.schedule(0); 724 } 725 726 static Set <UniverseModule> loadUniverseModules(ModuleEntry[] platformModules, Set <NbModuleProject> suiteModules) throws IOException { 727 Set universe = new LinkedHashSet (); 728 Iterator <NbModuleProject> it = suiteModules.iterator(); 729 while (it.hasNext()) { 730 universe.add(new SuiteModule((NbModuleProject) it.next())); 731 } 732 for (int i = 0; i < platformModules.length; i++) { 733 universe.add(new PlatformModule(platformModules[i])); 734 } 735 return universe; 736 } 737 738 static String [] findWarning(Set <UniverseModule> universeModules, Set <String > enabledClusters, Set <String > disabledModules) { 739 SortedMap <String ,UniverseModule> sortedModules = new TreeMap (); 740 Set <UniverseModule> excluded = new HashSet (); 741 Map <String ,Set <UniverseModule>> providers = new HashMap (); 742 Iterator it = universeModules.iterator(); 743 while (it.hasNext()) { 744 UniverseModule m = (UniverseModule) it.next(); 745 String cnb = m.getCodeNameBase(); 746 String cluster = m.getCluster(); 747 if (cluster != null && (!enabledClusters.contains(cluster) || disabledModules.contains(cnb))) { 748 excluded.add(m); 749 } 750 sortedModules.put(cnb, m); 751 Iterator <String > provides = m.getProvidedTokens().iterator(); 752 while (provides.hasNext()) { 753 String tok = (String ) provides.next(); 754 Set <UniverseModule> providersOf = (Set ) providers.get(tok); 755 if (providersOf == null) { 756 providersOf = new TreeSet (UNIVERSE_MODULE_COMPARATOR); 757 providers.put(tok, providersOf); 758 } 759 providersOf.add(m); 760 } 761 } 762 it = sortedModules.values().iterator(); 763 while (it.hasNext()) { 764 UniverseModule m = (UniverseModule) it.next(); 765 if (excluded.contains(m)) { 766 continue; 767 } 768 String [] warning = findWarning(m, sortedModules, providers, excluded); 769 if (warning != null) { 770 return warning; 771 } 772 } 773 return null; 774 } 775 private static final Comparator <UniverseModule> UNIVERSE_MODULE_COMPARATOR = new Comparator () { 776 Collator COLL = Collator.getInstance(); 777 public int compare(Object o1, Object o2) { 778 return COLL.compare(((UniverseModule) o1).getDisplayName(), ((UniverseModule) o2).getDisplayName()); 779 } 780 }; 781 782 private Set <UniverseModule> universe; 783 private synchronized void doUpdateDependencyWarnings() { 784 if (universe == null) { 785 try { 786 Set <NbModuleProject> suiteModules = getProperties().getSubModules(); 787 universe = loadUniverseModules(platformModules, suiteModules); 788 } catch (IOException e) { 789 Util.err.notify(ErrorManager.INFORMATIONAL, e); 790 return; } 792 } 793 794 Set enabledClusters = new TreeSet (); 795 Set disabledModules = new TreeSet (); 796 797 Node[] clusters = getExplorerManager().getRootContext().getChildren().getNodes(); 798 for (int i = 0; i < clusters.length; i++) { 799 if (clusters[i] instanceof Enabled) { 800 Enabled e = (Enabled) clusters[i]; 801 if (e.isEnabled()) { 802 enabledClusters.add(e.getName()); 803 Node[] modules = e.getChildren().getNodes(); 804 for (int j = 0; j < modules.length; j++) { 805 if (modules[j] instanceof Enabled) { 806 Enabled m = (Enabled) modules[j]; 807 if (!m.isEnabled()) { 808 disabledModules.add(m.getName()); 809 } 810 } 811 } 812 } 813 } 814 } 815 816 final String [] warning = findWarning(universe, enabledClusters, disabledModules); 817 818 EventQueue.invokeLater(new Runnable () { 819 public void run() { 820 if (warning != null) { 821 String key = warning[0]; 822 String [] args = new String [warning.length - 1]; 823 System.arraycopy(warning, 1, args, 0, args.length); 824 cat.setErrorMessage(NbBundle.getMessage(SuiteCustomizerLibraries.class, key, args)); 825 } else { 826 cat.setErrorMessage(null); 827 } 828 } 829 }); 830 831 } 832 833 private static String [] findWarning(UniverseModule m, Map <String ,UniverseModule> modules, Map <String ,Set <UniverseModule>> providers, Set <UniverseModule> excluded) { 834 SortedSet <Dependency> deps = new TreeSet (new Comparator () { 836 public int compare(Object o1, Object o2) { 837 Dependency d1 = (Dependency) o1; 838 Dependency d2 = (Dependency) o2; 839 return d1.getName().compareTo(d2.getName()); 840 } 841 }); 842 deps.addAll(m.getModuleDependencies()); 843 Iterator it = deps.iterator(); 844 while (it.hasNext()) { 845 Dependency d = (Dependency) it.next(); 846 String codename = d.getName(); 847 String cnb; 848 int mrvLo, mrvHi; 849 int slash = codename.lastIndexOf('/'); 850 if (slash == -1) { 851 cnb = codename; 852 mrvLo = -1; 853 mrvHi = -1; 854 } else { 855 cnb = codename.substring(0, slash); 856 String mrv = codename.substring(slash + 1); 857 int dash = mrv.lastIndexOf('-'); 858 if (dash == -1) { 859 mrvLo = mrvHi = Integer.parseInt(mrv); 860 } else { 861 mrvLo = Integer.parseInt(mrv.substring(0, dash)); 862 mrvHi = Integer.parseInt(mrv.substring(dash + 1)); 863 } 864 } 865 UniverseModule dep = (UniverseModule) modules.get(cnb); 866 if (dep == null) { 867 if (m.getCluster() != null) { 868 return new String [] {"ERR_platform_no_dep", m.getDisplayName(), m.getCluster(), cnb}; 869 } else { 870 return new String [] {"ERR_suite_no_dep", m.getDisplayName(), cnb}; 871 } 872 } 873 if (excluded.contains(dep)) { 874 assert dep.getCluster() != null; 875 if (m.getCluster() != null) { 876 return new String [] {"ERR_platform_excluded_dep", m.getDisplayName(), m.getCluster(), dep.getDisplayName(), dep.getCluster()}; 877 } else { 878 return new String [] {"ERR_suite_excluded_dep", m.getDisplayName(), dep.getDisplayName(), dep.getCluster()}; 879 } 880 } 881 if (dep.getReleaseVersion() < mrvLo || dep.getReleaseVersion() > mrvHi) { 882 if (m.getCluster() != null) { 883 return new String [] {"ERR_platform_bad_dep_mrv", m.getDisplayName(), m.getCluster(), dep.getDisplayName()}; 884 } else { 885 return new String [] {"ERR_suite_bad_dep_mrv", m.getDisplayName(), dep.getDisplayName()}; 886 } 887 } 888 if (d.getComparison() == Dependency.COMPARE_SPEC) { 889 SpecificationVersion needed = new SpecificationVersion(d.getVersion()); 890 SpecificationVersion found = dep.getSpecificationVersion(); 891 if (found == null || found.compareTo(needed) < 0) { 892 if (m.getCluster() != null) { 893 return new String [] {"ERR_platform_bad_dep_spec", m.getDisplayName(), m.getCluster(), dep.getDisplayName()}; 894 } else { 895 return new String [] {"ERR_suite_bad_dep_spec", m.getDisplayName(), dep.getDisplayName()}; 896 } 897 } 898 } else if (d.getComparison() == Dependency.COMPARE_IMPL) { 899 String needed = d.getVersion(); 900 if (!needed.equals("*") && !needed.equals(dep.getImplementationVersion())) { assert m.getCluster() != null; 902 return new String [] {"ERR_platform_bad_dep_impl", m.getDisplayName(), m.getCluster(), dep.getDisplayName()}; 903 } 904 } 905 } 906 Iterator toks = new TreeSet (m.getRequiredTokens()).iterator(); 908 while (toks.hasNext()) { 909 String tok = (String ) toks.next(); 910 UniverseModule wouldBeProvider = null; 911 boolean found = false; 912 Set <UniverseModule> possibleProviders = (Set ) providers.get(tok); 913 if (possibleProviders != null) { 914 it = possibleProviders.iterator(); 915 while (it.hasNext()) { 916 UniverseModule p = (UniverseModule) it.next(); 917 if (excluded.contains(p)) { 918 if (wouldBeProvider == null) { 919 wouldBeProvider = p; 920 } 921 } else { 922 found = true; 923 break; 924 } 925 } 926 } 927 if (!found) { 928 if (wouldBeProvider != null) { 929 assert wouldBeProvider.getCluster() != null; 930 if (m.getCluster() != null) { 931 return new String [] {"ERR_platform_only_excluded_providers", tok, m.getDisplayName(), m.getCluster(), wouldBeProvider.getDisplayName(), wouldBeProvider.getCluster()}; } else { 933 return new String [] {"ERR_suite_only_excluded_providers", tok, m.getDisplayName(), wouldBeProvider.getDisplayName(), wouldBeProvider.getCluster()}; } 935 } else { 936 if (m.getCluster() != null) { 937 return new String [] {"ERR_platform_no_providers", tok, m.getDisplayName(), m.getCluster()}; } else { 939 return new String [] {"ERR_suite_no_providers", tok, m.getDisplayName()}; } 941 } 942 } 943 } 944 return null; 946 } 947 948 private void updateJavaPlatformEnabled() { boolean enabled = ((NbPlatform) platformValue.getSelectedItem()).getHarnessVersion() >= NbPlatform.HARNESS_VERSION_50u1; 950 javaPlatformCombo.setEnabled(enabled); 951 javaPlatformButton.setEnabled(enabled); } 953 954 } 955 | Popular Tags |