1 19 20 package org.netbeans.modules.apisupport.project; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyChangeSupport ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.net.URI ; 29 import java.net.URL ; 30 import java.util.Arrays ; 31 import java.util.Enumeration ; 32 import java.util.HashMap ; 33 import java.util.Iterator ; 34 import java.util.Map ; 35 import java.util.WeakHashMap ; 36 import java.util.jar.Manifest ; 37 import javax.swing.Icon ; 38 import javax.swing.ImageIcon ; 39 import org.netbeans.api.java.classpath.ClassPath; 40 import org.netbeans.api.java.classpath.GlobalPathRegistry; 41 import org.netbeans.api.java.project.JavaProjectConstants; 42 import org.netbeans.api.project.FileOwnerQuery; 43 import org.netbeans.api.project.Project; 44 import org.netbeans.api.project.ProjectManager; 45 import org.netbeans.api.project.ProjectInformation; 46 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider.NbModuleType; 47 import org.netbeans.modules.apisupport.project.metainf.ServiceNodeHandler; 48 import org.netbeans.modules.apisupport.project.queries.ModuleProjectClassPathExtender; 49 import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerProviderImpl; 50 import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; 51 import org.netbeans.spi.project.AuxiliaryConfiguration; 52 import org.netbeans.spi.project.support.ant.AntProjectEvent; 53 import org.netbeans.spi.project.support.ant.AntProjectHelper; 54 import org.netbeans.spi.project.support.ant.AntProjectListener; 55 import org.netbeans.spi.project.support.ant.EditableProperties; 56 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 57 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; 58 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 59 import org.netbeans.spi.project.support.ant.SourcesHelper; 60 import org.netbeans.spi.project.ui.PrivilegedTemplates; 61 import org.netbeans.spi.project.ui.ProjectOpenedHook; 62 import org.netbeans.spi.queries.FileBuiltQueryImplementation; 63 import org.openide.ErrorManager; 64 import org.openide.filesystems.FileChangeAdapter; 65 import org.openide.filesystems.FileEvent; 66 import org.openide.filesystems.FileObject; 67 import org.openide.filesystems.FileUtil; 68 import org.openide.util.Lookup; 69 import org.openide.util.Mutex; 70 import org.openide.util.NbBundle; 71 import org.openide.util.Utilities; 72 import org.openide.util.lookup.Lookups; 73 import org.w3c.dom.Element ; 74 import org.netbeans.modules.apisupport.project.queries.AccessibilityQueryImpl; 75 import org.netbeans.modules.apisupport.project.queries.UnitTestForSourceQueryImpl; 76 import org.netbeans.modules.apisupport.project.queries.SourceLevelQueryImpl; 77 import org.netbeans.modules.apisupport.project.queries.AntArtifactProviderImpl; 78 import org.netbeans.modules.apisupport.project.queries.ClassPathProviderImpl; 79 import org.netbeans.modules.apisupport.project.queries.JavadocForBinaryImpl; 80 import org.netbeans.modules.apisupport.project.queries.SourceForBinaryImpl; 81 import org.netbeans.modules.apisupport.project.queries.SubprojectProviderImpl; 82 import org.netbeans.modules.apisupport.project.spi.NbModuleProvider; 83 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 84 import org.netbeans.modules.apisupport.project.universe.ModuleList; 85 import org.netbeans.modules.apisupport.project.ui.ModuleActions; 86 import org.netbeans.modules.apisupport.project.ui.ModuleLogicalView; 87 import org.netbeans.modules.apisupport.project.ui.ModuleOperations; 88 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo; 89 import org.netbeans.modules.apisupport.project.universe.ModuleEntry; 90 import org.netbeans.spi.project.support.LookupProviderSupport; 91 import org.netbeans.spi.project.ui.RecommendedTemplates; 92 import org.netbeans.spi.project.ui.support.UILookupMergerSupport; 93 import org.openide.modules.SpecificationVersion; 94 95 99 public final class NbModuleProject implements Project { 100 101 public static final String NB_PROJECT_ICON_PATH = 102 "org/netbeans/modules/apisupport/project/resources/module.gif"; 104 private static final Icon NB_PROJECT_ICON = new ImageIcon ( 105 Utilities.loadImage(NB_PROJECT_ICON_PATH)); 106 107 public static final String SOURCES_TYPE_JAVAHELP = "javahelp"; 109 private final AntProjectHelper helper; 110 private final Evaluator eval; 111 private Lookup lookup; 112 private Map <FileObject,Element > extraCompilationUnits; 113 private final GeneratedFilesHelper genFilesHelper; 114 private final NbModuleProviderImpl typeProvider; 115 116 NbModuleProject(AntProjectHelper helper) throws IOException { 117 this.helper = helper; 118 genFilesHelper = new GeneratedFilesHelper(helper); 119 Util.err.log("Loading project in " + getProjectDirectory()); 120 if (getCodeNameBase() == null) { 121 throw new IOException ("Misconfigured project in " + FileUtil.getFileDisplayName(getProjectDirectory()) + " has no defined <code-name-base>"); } 123 typeProvider = new NbModuleProviderImpl(); 124 if (typeProvider.getModuleType() == NbModuleProvider.NETBEANS_ORG && ModuleList.findNetBeansOrg(getProjectDirectoryFile()) == null) { 125 throw new IOException ("netbeans.org-type module not in a complete netbeans.org source root: " + this); } 128 eval = new Evaluator(this, typeProvider); 129 FileBuiltQueryImplementation fileBuilt; 130 if (supportsUnitTests()) { 132 fileBuilt = helper.createGlobFileBuiltQuery(eval, new String [] { 133 "${src.dir}/*.java", "${test.unit.src.dir}/*.java", }, new String [] { 136 "${build.classes.dir}/*.class", "${build.test.unit.classes.dir}/*.class", }); 139 } else { 140 fileBuilt = helper.createGlobFileBuiltQuery(eval, new String [] { 141 "${src.dir}/*.java", }, new String [] { 143 "${build.classes.dir}/*.class", }); 145 } 146 final SourcesHelper sourcesHelper = new SourcesHelper(helper, eval); 147 sourcesHelper.addPrincipalSourceRoot("${src.dir}", NbBundle.getMessage(NbModuleProject.class, "LBL_source_packages"), null, null); sourcesHelper.addPrincipalSourceRoot("${test.unit.src.dir}", NbBundle.getMessage(NbModuleProject.class, "LBL_unit_test_packages"), null, null); sourcesHelper.addTypedSourceRoot("${src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_source_packages"), null, null); 154 sourcesHelper.addTypedSourceRoot("${test.unit.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_unit_test_packages"), null, null); 156 sourcesHelper.addTypedSourceRoot("${test.qa-functional.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_functional_test_packages"), null, null); 157 sourcesHelper.addTypedSourceRoot("${test.qa-performance.src.dir}", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_performance_test_packages"), null, null); 158 FileObject testDir = helper.getProjectDirectory().getFileObject("test"); if (testDir != null) { 161 Enumeration <? extends FileObject> kids = testDir.getChildren(false); 162 while (kids.hasMoreElements()) { 163 FileObject testSubdir = (FileObject) kids.nextElement(); 164 if (!testSubdir.isFolder()) { 165 continue; 166 } 167 String name = testSubdir.getNameExt(); 168 if (testDir.getFileObject("build-" + name + ".xml") == null) { continue; 170 } 171 if (name.equals("unit") || name.equals("qa-functional") || name.equals("qa-performance")) { continue; 174 } 175 sourcesHelper.addTypedSourceRoot("test/" + name + "/src", JavaProjectConstants.SOURCES_TYPE_JAVA, NbBundle.getMessage(NbModuleProject.class, "LBL_unknown_test_packages", name), null, null); 176 } 177 } 178 if (helper.resolveFileObject("javahelp/manifest.mf") == null) { sourcesHelper.addTypedSourceRoot("javahelp", SOURCES_TYPE_JAVAHELP, NbBundle.getMessage(NbModuleProject.class, "LBL_javahelp_packages"), null, null); 181 } 182 Iterator it = getExtraCompilationUnits().entrySet().iterator(); 183 while (it.hasNext()) { 184 Map.Entry entry = (Map.Entry ) it.next(); 185 Element ecu = (Element ) entry.getValue(); 186 Element pkgrootEl = Util.findElement(ecu, "package-root", NbModuleProjectType.NAMESPACE_SHARED); String pkgrootS = Util.findText(pkgrootEl); 188 FileObject pkgroot = (FileObject) entry.getKey(); 189 sourcesHelper.addTypedSourceRoot(pkgrootS, JavaProjectConstants.SOURCES_TYPE_JAVA, pkgroot.getNameExt(), null, null); 190 } 191 ProjectManager.mutex().postWriteRequest(new Runnable () { 193 public void run() { 194 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); 195 } 196 }); 197 lookup = Lookups.fixed(new Object [] { 198 this, 199 new Info(), 200 helper.createAuxiliaryConfiguration(), 201 helper.createCacheDirectoryProvider(), 202 new SavedHook(), 203 new OpenedHook(), 204 new ModuleActions(this), 205 new ClassPathProviderImpl(this), 206 new SourceForBinaryImpl(this), 207 new JavadocForBinaryImpl(this), 208 new UnitTestForSourceQueryImpl(this), 209 new ModuleLogicalView(this), 210 new SubprojectProviderImpl(this), 211 fileBuilt, 212 new AccessibilityQueryImpl(this), 213 new SourceLevelQueryImpl(this), 214 helper.createSharabilityQuery(evaluator(), new String [0], new String [] { 215 "build", }), 218 sourcesHelper.createSources(), 219 new AntArtifactProviderImpl(this, helper, evaluator()), 220 new CustomizerProviderImpl(this, getHelper(), evaluator()), 221 new SuiteProviderImpl(), 222 typeProvider, 223 new PrivilegedTemplatesImpl(), 224 new ModuleProjectClassPathExtender(this), 225 new LocalizedBundleInfoProvider(), 226 new ModuleOperations(this), 227 new ServiceNodeHandler(this), 228 LookupProviderSupport.createSourcesMerger(), 229 UILookupMergerSupport.createPrivilegedTemplatesMerger(), 230 UILookupMergerSupport.createRecommendedTemplatesMerger(), 231 232 }); 233 lookup = LookupProviderSupport.createCompositeLookup(lookup, "Projects/org-netbeans-modules-apisupport-project/Lookup"); } 235 236 public String toString() { 237 return "NbModuleProject[" + getProjectDirectory() + "]"; } 239 240 public Lookup getLookup() { 241 return lookup; 242 } 243 244 public FileObject getProjectDirectory() { 245 return helper.getProjectDirectory(); 246 } 247 248 public File getProjectDirectoryFile() { 249 return FileUtil.toFile(getProjectDirectory()); 250 } 251 252 255 public int getMinimumHarnessVersion() { 256 if (helper.createAuxiliaryConfiguration().getConfigurationFragment(NbModuleProjectType.NAME_SHARED, NbModuleProjectType.NAMESPACE_SHARED_2, true) != null) { 257 return NbPlatform.HARNESS_VERSION_50; 258 } else { 259 return NbPlatform.HARNESS_VERSION_55u1; 260 } 261 } 262 263 267 public Element getPrimaryConfigurationData() { 268 return ProjectManager.mutex().readAccess(new Mutex.Action<Element >() { 269 public Element run() { 270 AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration(); 271 Element data = ac.getConfigurationFragment(NbModuleProjectType.NAME_SHARED, NbModuleProjectType.NAMESPACE_SHARED_2, true); 272 if (data != null) { 273 return Util.translateXML(data, NbModuleProjectType.NAMESPACE_SHARED); 274 } else { 275 return helper.getPrimaryConfigurationData(true); 276 } 277 } 278 }); 279 } 280 281 285 public void putPrimaryConfigurationData(final Element data) { 286 ProjectManager.mutex().writeAccess(new Mutex.Action<Void >() { 287 public Void run() { 288 AuxiliaryConfiguration ac = helper.createAuxiliaryConfiguration(); 289 if (ac.getConfigurationFragment(NbModuleProjectType.NAME_SHARED, NbModuleProjectType.NAMESPACE_SHARED_2, true) != null) { 290 ac.putConfigurationFragment(Util.translateXML(data, NbModuleProjectType.NAMESPACE_SHARED_2), true); 291 } else { 292 helper.putPrimaryConfigurationData(data, true); 293 } 294 return null; 295 } 296 }); 297 } 298 299 300 public String getSourceDirectoryPath() { 301 return evaluator().getProperty("src.dir"); } 303 304 private NbModuleProvider.NbModuleType getModuleType() { 305 Element data = getPrimaryConfigurationData(); 306 if (Util.findElement(data, "suite-component", NbModuleProjectType.NAMESPACE_SHARED) != null) { return NbModuleProvider.SUITE_COMPONENT; 308 } else if (Util.findElement(data, "standalone", NbModuleProjectType.NAMESPACE_SHARED) != null) { return NbModuleProvider.STANDALONE; 310 } else { 311 return NbModuleProvider.NETBEANS_ORG; 312 } 313 } 314 315 public FileObject getManifestFile() { 316 return helper.resolveFileObject(evaluator().getProperty("manifest.mf")); } 318 319 public Manifest getManifest() { 320 return Util.getManifest(getManifestFile()); 321 } 322 323 public AntProjectHelper getHelper() { 324 return helper; 325 } 326 327 public PropertyEvaluator evaluator() { 328 return eval; 329 } 330 331 private final Map <String ,FileObject> directoryCache = new WeakHashMap <String ,FileObject>(); 332 333 private FileObject getDir(String prop) { 334 if (directoryCache.containsKey(prop)) { 336 return directoryCache.get(prop); 337 } else { 338 String v = evaluator().getProperty(prop); 339 assert v != null : "No value for " + prop; 340 FileObject f = helper.resolveFileObject(v); 341 directoryCache.put(prop, f); 342 return f; 343 } 344 } 345 346 public FileObject getSourceDirectory() { 347 return getDir("src.dir"); } 349 350 public FileObject getTestSourceDirectory() { 351 return getDir("test.unit.src.dir"); } 353 354 public FileObject getFunctionalTestSourceDirectory() { 355 return getDir("test.qa-functional.src.dir"); } 357 358 public FileObject getPerformanceTestSourceDirectory() { 359 return getDir("test.qa-performance.src.dir"); } 361 362 public File getClassesDirectory() { 363 String classesDir = evaluator().getProperty("build.classes.dir"); return helper.resolveFile(classesDir); 365 } 366 367 public File getTestClassesDirectory() { 368 String testClassesDir = evaluator().getProperty("build.test.unit.classes.dir"); return helper.resolveFile(testClassesDir); 370 } 371 372 public FileObject getJavaHelpDirectory() { 373 if (helper.resolveFileObject("javahelp/manifest.mf") != null) { return null; 376 } 377 return helper.resolveFileObject("javahelp"); } 379 380 public File getModuleJarLocation() { 381 return helper.resolveFile(evaluator().evaluate("${cluster}/${module.jar}")); } 384 385 public String getCodeNameBase() { 386 Element config = getPrimaryConfigurationData(); 387 Element cnb = Util.findElement(config, "code-name-base", NbModuleProjectType.NAMESPACE_SHARED); if (cnb != null) { 389 return Util.findText(cnb); 390 } else { 391 return null; 392 } 393 } 394 395 public String getSpecVersion() { 396 Manifest m = getManifest(); 398 if (m != null) { 399 String manVersion = m.getMainAttributes().getValue("OpenIDE-Module-Specification-Version"); if (manVersion != null) { 401 return stripExcessZeros(manVersion); 402 } 403 } 404 return stripExcessZeros(evaluator().getProperty(SingleModuleProperties.SPEC_VERSION_BASE)); 405 } 406 private static String stripExcessZeros(String spec) { return spec != null ? spec.replaceAll("(\\.[0-9]+)\\.0$", "$1") : null; } 409 410 413 public String getPathWithinNetBeansOrg() { 414 FileObject nbroot = getNbrootFileObject(null); 415 if (nbroot != null) { 416 return FileUtil.getRelativePath(nbroot, getProjectDirectory()); 417 } else { 418 return null; 419 } 420 } 421 422 private File getNbroot() { 423 return getNbroot(null); 424 } 425 private File getNbroot(PropertyEvaluator eval) { 426 File dir = getProjectDirectoryFile(); 427 File nbroot = ModuleList.findNetBeansOrg(dir); 428 if (nbroot != null) { 429 return nbroot; 430 } else { 431 NbPlatform platform = getPlatform(eval); 433 if (platform != null) { 434 URL [] roots = platform.getSourceRoots(); 435 for (int i = 0; i < roots.length; i++) { 436 if (roots[i].getProtocol().equals("file")) { File f = new File (URI.create(roots[i].toExternalForm())); 438 if (ModuleList.isNetBeansOrg(f)) { 439 return f; 440 } 441 } 442 } 443 } 444 return null; 446 } 447 } 448 449 public File getNbrootFile(String path) { 450 return getNbrootFile(path, null); 451 } 452 File getNbrootFile(String path, PropertyEvaluator eval) { 453 File nbroot = getNbroot(eval); 454 if (nbroot != null) { 455 return new File (nbroot, path.replace('/', File.separatorChar)); 456 } else { 457 return null; 458 } 459 } 460 461 public FileObject getNbrootFileObject(String path) { 462 File f = path != null ? getNbrootFile(path) : getNbroot(); 463 if (f != null) { 464 return FileUtil.toFileObject(f); 465 } else { 466 return null; 467 } 468 } 469 470 public ModuleList getModuleList() throws IOException { 471 NbPlatform p = getPlatform(false); 472 if (p == null) { 473 return ModuleList.getModuleList(getProjectDirectoryFile(), NbPlatform.getDefaultPlatform().getDestDir()); 475 } 476 ModuleList ml = ModuleList.getModuleList(getProjectDirectoryFile(), p.getDestDir()); 477 if (ml.getEntry(getCodeNameBase()) == null) { 478 ModuleList.refresh(); 479 ml = ModuleList.getModuleList(getProjectDirectoryFile()); 480 if (ml.getEntry(getCodeNameBase()) == null) { 481 Util.err.log(ErrorManager.WARNING, "Project in " + FileUtil.getFileDisplayName(getProjectDirectory()) + " does not appear to be listed in its own module list; some sort of misconfiguration (e.g. not listed in its own suite)"); } 484 } 485 return ml; 486 528 } 529 530 537 public NbPlatform getPlatform(boolean fallback) { 538 NbPlatform p = getPlatform(null); 539 if (fallback && (p == null || !p.isValid())) { 540 p = NbPlatform.getDefaultPlatform(); 541 } 542 return p; 543 } 544 545 private NbPlatform getPlatform(PropertyEvaluator eval) { 546 File file = getPlatformFile(eval); 547 if (file == null) { 548 return null; 549 } 550 return NbPlatform.getPlatformByDestDir(file); 551 } 552 553 private File getPlatformFile(PropertyEvaluator eval) { 554 if (eval == null) { 555 eval = evaluator(); 556 } 557 String prop = eval.getProperty("netbeans.dest.dir"); if (prop == null) { 559 return null; 560 } 561 return getHelper().resolveFile(prop); 562 } 563 564 567 public boolean supportsJavadoc() { 568 if (evaluator().getProperty("module.javadoc.packages") != null) { 569 return true; 570 } 571 Element config = getPrimaryConfigurationData(); 572 Element pubPkgs = Util.findElement(config, "public-packages", NbModuleProjectType.NAMESPACE_SHARED); if (pubPkgs == null) { 574 pubPkgs = Util.findElement(config, "friend-packages", NbModuleProjectType.NAMESPACE_SHARED); } 577 return pubPkgs != null && !Util.findSubElements(pubPkgs).isEmpty(); 578 } 579 580 public boolean supportsUnitTests() { 581 return getTestSourceDirectory() != null; 582 } 583 584 588 public Map <FileObject,Element > getExtraCompilationUnits() { 589 if (extraCompilationUnits == null) { 590 extraCompilationUnits = new HashMap <FileObject,Element >(); 591 for (Element ecu : Util.findSubElements(getPrimaryConfigurationData())) { 592 if (ecu.getLocalName().equals("extra-compilation-unit")) { Element pkgrootEl = Util.findElement(ecu, "package-root", NbModuleProjectType.NAMESPACE_SHARED); String pkgrootS = Util.findText(pkgrootEl); 595 String pkgrootEval = evaluator().evaluate(pkgrootS); 596 FileObject pkgroot = getHelper().resolveFileObject(pkgrootEval); 597 if (pkgroot == null) { 598 Util.err.log(ErrorManager.WARNING, "Could not find package-root " + pkgrootEval + " for " + getCodeNameBase()); 599 continue; 600 } 601 extraCompilationUnits.put(pkgroot, ecu); 602 } 603 } 604 } 605 return extraCompilationUnits; 606 } 607 608 609 public String getJavacSource() { 610 String javacSource = evaluator().getProperty("javac.source"); 611 assert javacSource != null; 612 return javacSource; 613 } 614 615 619 public void open() { 620 getLookup().lookup(OpenedHook.class).projectOpened(); 621 } 622 623 627 public LocalizedBundleInfo getBundleInfo() { 628 return getLookup().lookup(LocalizedBundleInfo.Provider.class).getLocalizedBundleInfo(); 629 } 630 631 632 633 public void setRunInAtomicAction(boolean runInAtomicAction) { 634 eval.setRunInAtomicAction(runInAtomicAction); 635 } 636 637 private final class Info implements ProjectInformation, PropertyChangeListener { 638 639 private final PropertyChangeSupport changeSupport = new PropertyChangeSupport (this); 640 641 private String displayName; 642 643 Info() {} 644 645 public String getName() { 646 String cnb = getCodeNameBase(); 647 return cnb != null ? cnb : getProjectDirectory().toString(); 648 } 649 650 public String getDisplayName() { 651 if (displayName == null) { 652 LocalizedBundleInfo bundleInfo = getBundleInfo(); 653 if (bundleInfo != null) { 654 displayName = bundleInfo.getDisplayName(); 655 } 656 } 657 if (displayName == null) { 658 displayName = getName(); 659 } 660 assert displayName != null : NbModuleProject.this; 661 return displayName; 662 } 663 664 private void setDisplayName(String newDisplayName) { 665 String oldDisplayName = getDisplayName(); 666 displayName = newDisplayName == null ? getName() : newDisplayName; 667 firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME, oldDisplayName, displayName); 668 } 669 670 public Icon getIcon() { 671 return NB_PROJECT_ICON; 672 } 673 674 public Project getProject() { 675 return NbModuleProject.this; 676 } 677 678 public void addPropertyChangeListener(PropertyChangeListener pchl) { 679 changeSupport.addPropertyChangeListener(pchl); 680 } 681 682 public void removePropertyChangeListener(PropertyChangeListener pchl) { 683 changeSupport.removePropertyChangeListener(pchl); 684 } 685 686 private void firePropertyChange(String propName, Object oldValue, Object newValue) { 687 changeSupport.firePropertyChange(propName, oldValue, newValue); 688 } 689 690 public void propertyChange(PropertyChangeEvent evt) { 691 if (evt.getPropertyName() == ProjectInformation.PROP_DISPLAY_NAME) { 692 setDisplayName((String ) evt.getNewValue()); 693 } 694 } 695 696 } 697 698 final class OpenedHook extends ProjectOpenedHook { 699 700 private ClassPath[] boot, source, compile; 701 702 OpenedHook() {} 703 704 protected void projectOpened() { 705 if (getModuleType() == NbModuleProvider.STANDALONE) { 707 ProjectManager.mutex().writeAccess(new Mutex.Action<Void >() { 709 public Void run() { 710 String path = "nbproject/private/platform-private.properties"; EditableProperties ep = getHelper().getProperties(path); 712 File buildProperties = new File (System.getProperty("netbeans.user"), "build.properties"); ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); getHelper().putProperties(path, ep); 715 try { 716 ProjectManager.getDefault().saveProject(NbModuleProject.this); 717 } catch (IOException e) { 718 ErrorManager.getDefault().notify(e); 719 } 720 return null; 721 } 722 }); 723 } 724 ClassPathProviderImpl cpProvider = lookup.lookup(ClassPathProviderImpl.class); 726 ClassPath[] _boot = cpProvider.getProjectClassPaths(ClassPath.BOOT); 727 assert _boot != null : "No BOOT path"; 728 ClassPath[] _source = cpProvider.getProjectClassPaths(ClassPath.SOURCE); 729 assert _source != null : "No SOURCE path"; 730 ClassPath[] _compile = cpProvider.getProjectClassPaths(ClassPath.COMPILE); 731 assert _compile != null : "No COMPILE path"; 732 GlobalPathRegistry.getDefault().register(ClassPath.BOOT, _boot); 734 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, _source); 735 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, _compile); 736 boot = _boot; 737 source = _source; 738 compile = _compile; 739 if (getModuleType() != NbModuleProvider.NETBEANS_ORG) { 741 try { 742 refreshBuildScripts(true); 743 } catch (IOException e) { 744 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 745 } 746 } 747 } 748 749 protected void projectClosed() { 750 try { 751 ProjectManager.getDefault().saveProject(NbModuleProject.this); 752 } catch (IOException e) { 753 Util.err.notify(e); 754 } 755 756 758 assert boot != null && source != null && compile != null : "#46802: project being closed which was never opened?? " + NbModuleProject.this; 760 GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, boot); 761 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, source); 762 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, compile); 763 boot = null; 764 source = null; 765 compile = null; 766 } 767 768 } 769 770 public void notifyDeleting() { 771 eval.removeListeners(); 772 } 773 774 private final class SavedHook extends ProjectXmlSavedHook { 775 776 SavedHook() {} 777 778 protected void projectXmlSaved() throws IOException { 779 if (getModuleType() != NbModuleProvider.NETBEANS_ORG) { 781 refreshBuildScripts(false); 782 } 783 } 784 785 } 786 787 private void refreshBuildScripts(boolean checkForProjectXmlModified) throws IOException { 788 genFilesHelper.refreshBuildScript( 789 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 790 NbModuleProject.class.getResource("resources/build-impl.xsl"), checkForProjectXmlModified); 792 genFilesHelper.refreshBuildScript( 793 GeneratedFilesHelper.BUILD_XML_PATH, 794 NbModuleProject.class.getResource("resources/build.xsl"), checkForProjectXmlModified); 796 } 797 798 private final class SuiteProviderImpl implements SuiteProvider { 799 800 public File getSuiteDirectory() { 801 String suiteDir = evaluator().getProperty("suite.dir"); return suiteDir == null ? null : helper.resolveFile(suiteDir); 803 } 804 805 } 806 807 private class NbModuleProviderImpl implements NbModuleProvider, AntProjectListener { 808 809 private NbModuleType type; 810 811 public NbModuleProviderImpl() { 812 getHelper().addAntProjectListener(this); 813 } 814 815 public NbModuleType getModuleType() { 816 if (type == null) { 817 type = NbModuleProject.this.getModuleType(); 818 } 819 return type; 820 } 821 822 public void configurationXmlChanged(AntProjectEvent ev) { 823 if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { 824 type = null; 825 } 826 } 827 828 public void propertiesChanged(AntProjectEvent ev) { 829 } 831 public String getSpecVersion() { 832 return NbModuleProject.this.getSpecVersion(); 833 } 834 835 public String getCodeNameBase() { 836 return NbModuleProject.this.getCodeNameBase(); 837 } 838 839 public String getSourceDirectoryPath() { 840 return NbModuleProject.this.getSourceDirectoryPath(); 841 } 842 843 public FileObject getSourceDirectory() { 844 return NbModuleProject.this.getSourceDirectory(); 845 } 846 847 public FileObject getManifestFile() { 848 return NbModuleProject.this.getManifestFile(); 849 } 850 851 public String getResourceDirectoryPath(boolean inTests) { 852 return evaluator().getProperty(inTests ? "test.unit.src.dir" : "src.dir"); 853 } 854 855 public boolean addDependency(String codeNameBase, String releaseVersion, 856 SpecificationVersion version, 857 boolean useInCompiler) throws IOException { 858 return Util.addDependency(NbModuleProject.this, codeNameBase, releaseVersion, version, useInCompiler); 859 } 860 861 public SpecificationVersion getDependencyVersion(String codenamebase) throws IOException { 862 ModuleList moduleList = getModuleList(); 863 ModuleEntry entry = moduleList.getEntry(codenamebase); SpecificationVersion current = new SpecificationVersion(entry.getSpecificationVersion()); 865 return current; 866 867 } 868 869 public String getProjectFilePath() { 870 return "nbproject/project.xml"; 871 } 872 873 public File getActivePlatformLocation() { 874 return NbModuleProject.this.getPlatformFile(null); 875 } 876 877 878 } 879 880 private static final class PrivilegedTemplatesImpl implements PrivilegedTemplates, RecommendedTemplates { 881 882 private static final String [] PRIVILEGED_NAMES = new String [] { 883 "Templates/Classes/Class.java", "Templates/Classes/Package", "Templates/Classes/Interface.java", "Templates/JUnit/SimpleJUnitTest.java", "Templates/NetBeansModuleDevelopment/newAction", "Templates/NetBeansModuleDevelopment/emptyLibraryDescriptor", "Templates/NetBeansModuleDevelopment/newLoader", "Templates/NetBeansModuleDevelopment/newProject", "Templates/NetBeansModuleDevelopment/newWindow", "Templates/NetBeansModuleDevelopment/newWizard", }; 896 static { 897 assert PRIVILEGED_NAMES.length <= 10 : "Too many privileged templates to fit! extras will be ignored: " + 898 Arrays.asList(PRIVILEGED_NAMES).subList(10, PRIVILEGED_NAMES.length); 899 } 900 901 private static final String [] RECOMMENDED_TYPES = new String [] { 902 "java-classes", "java-main-class", "java-forms", "java-beans", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "junit", "simple-files", "nbm-specific", "nbm-specific2", }; 915 916 public String [] getPrivilegedTemplates() { 917 return PRIVILEGED_NAMES; 918 } 919 920 public String [] getRecommendedTypes() { 921 return RECOMMENDED_TYPES; 922 } 923 } 924 925 private final class LocalizedBundleInfoProvider implements LocalizedBundleInfo.Provider { 926 927 private LocalizedBundleInfo bundleInfo; 928 929 public LocalizedBundleInfo getLocalizedBundleInfo() { 930 if (bundleInfo == null) { 931 Manifest mf = getManifest(); 932 FileObject srcFO = getSourceDirectory(); 933 if (mf != null && srcFO != null) { 934 bundleInfo = Util.findLocalizedBundleInfo(srcFO, getManifest()); 935 } 936 if (bundleInfo != null) { 937 bundleInfo.addPropertyChangeListener(getLookup().lookup(Info.class)); 938 } 939 if (mf != null) { 940 getManifestFile().addFileChangeListener(new FileChangeAdapter() { 941 public void fileChanged(FileEvent fe) { 942 bundleInfo = null; 944 } 945 }); 946 } 947 } 948 return bundleInfo; 949 } 950 } 951 952 } 953 | Popular Tags |