Index: StandardModule.java =================================================================== RCS file: /cvs/core/bootstrap/src/org/netbeans/StandardModule.java,v retrieving revision 1.1.8.1 diff -u -r1.1.8.1 StandardModule.java --- StandardModule.java 15 Sep 2005 18:52:56 -0000 1.1.8.1 +++ StandardModule.java 9 Jun 2006 19:17:38 -0000 @@ -102,6 +102,10 @@ super(mgr, ev, history, reloadable, autoload, eager); this.jar = jar; loadManifest(); + findPatches(calculateCodeNameBase(manifest)); + Manifest patchedManifest = null; + if ((patchedManifest = findPatchedManifest()) != null) + manifest = patchedManifest; parseManifest(); findExtensionsAndVariants(manifest); // Check if some other module already listed this one in Class-Path. @@ -113,6 +117,37 @@ moduleJARs.add(jar); } + private void findPatches(String codeNameBase) { + // #9273: load any modules/patches/this-code-name/*.jar files first: + File patchdir = new File(new File(jar.getParentFile(), "patches"), // NOI18N + codeNameBase.replace('.', '-')); // NOI18N + scanForPatches(patchdir); + // Use of the following system property is not supported, but is used + // by e.g. XTest to influence installed modules without changing the build. + // Format is -Dnetbeans.patches.org.nb.mods.foo=/path/to.file.jar:/path/to/dir + String patchesClassPath = System.getProperty("netbeans.patches." + getCodeNameBase()); // NOI18N + if (patchesClassPath != null) { + StringTokenizer tokenizer = new StringTokenizer(patchesClassPath, File.pathSeparator); + while (tokenizer.hasMoreElements()) { + String element = (String) tokenizer.nextElement(); + File fileElement = new File(element); + if (fileElement.exists()) { + if (patches == null) { + patches = new HashSet(15); + } + patches.add(fileElement); + } + } + } + + if (patches != null) { + Iterator it = patches.iterator(); + while (it.hasNext()) { + events.log(Events.PATCH, it.next()); + } + } + } + /** Get a localized attribute. * First, if OpenIDE-Module-Localizing-Bundle was given, the specified * bundle file (in all locale JARs as well as base JAR) is searched for @@ -242,6 +277,28 @@ } } + private Manifest loadPatchJarManifest(File patchJar) throws IOException { + Util.err.log("loading patch jar manifest of " + patchJar); + File jarBeingOpened = null; // for annotation purposes + try { + jarBeingOpened = patchJar; + JarFile jarFile = new JarFile(patchJar, false); + try { + Manifest m = jarFile.getManifest(); + if (m != null) + return m; + } finally { + jarFile.close(); + } + } catch (IOException e) { + if (jarBeingOpened != null) { + Util.err.annotate(e, ErrorManager.UNKNOWN, "While loading patch jar manifest from: " + jarBeingOpened, null, null, null); // NOI18N + } + throw e; + } + return null; + } + /** Open the JAR, load its manifest, and do related things. */ private void loadManifest() throws IOException { Util.err.log("loading manifest of " + jar); @@ -326,27 +383,7 @@ } } } - // #9273: load any modules/patches/this-code-name/*.jar files first: - File patchdir = new File(new File(jar.getParentFile(), "patches"), // NOI18N - getCodeNameBase().replace('.', '-')); // NOI18N - scanForPatches(patchdir); - // Use of the following system property is not supported, but is used - // by e.g. XTest to influence installed modules without changing the build. - // Format is -Dnetbeans.patches.org.nb.mods.foo=/path/to.file.jar:/path/to/dir - String patchesClassPath = System.getProperty("netbeans.patches." + getCodeNameBase()); // NOI18N - if (patchesClassPath != null) { - StringTokenizer tokenizer = new StringTokenizer(patchesClassPath, File.pathSeparator); - while (tokenizer.hasMoreElements()) { - String element = (String) tokenizer.nextElement(); - File fileElement = new File(element); - if (fileElement.exists()) { - if (patches == null) { - patches = new HashSet(15); - } - patches.add(fileElement); - } - } - } + Util.err.log("localeVariants of " + jar + ": " + localeVariants); Util.err.log("plainExtensions of " + jar + ": " + plainExtensions); Util.err.log("localeExtensions of " + jar + ": " + localeExtensions); @@ -505,6 +542,27 @@ /** Count which release() call is really being checked. */ private transient int releaseCount = 0; + private Manifest findPatchedManifest() { + if (patches != null) { + Iterator itr = patches.iterator(); + while (itr.hasNext()) { + File file = (File)itr.next(); + try { + Manifest m = loadPatchJarManifest(file); + Attributes patchAttr = m.getMainAttributes(); + String str = patchAttr.getValue("OpenIDE-Module-Patch-Manifest"); + + if (str != null && new Boolean(str).booleanValue()) { + return m; + } + } catch (Exception e) { + + } + } + } + return null; + } + /** Reload this module. Access from ModuleManager. * If an exception is thrown, the module is considered * to be in an invalid state. @@ -515,6 +573,10 @@ String codeNameBase1 = getCodeNameBase(); localizedProps = null; loadManifest(); + findPatches(calculateCodeNameBase(manifest)); + Manifest patchedManifest = null; + if ((patchedManifest = findPatchedManifest()) != null) + manifest = patchedManifest; parseManifest(); findExtensionsAndVariants(manifest); String codeNameBase2 = getCodeNameBase();