/** manager which owns this module */ protectedfinal ModuleManager mgr; /** event logging (should not be much here) */ protectedfinal Events events; /** associated history object *@see<ahref="@org-netbeans-core-startup@/org/netbeans/core/startup/ModuleHistory.html">ModuleHistory</a>
*/ privatefinal Object history; /** true if currently enabled; manipulated by ModuleManager */ privateboolean enabled; /** whether it is supposed to be automatically loaded when required */ privatefinalboolean autoload; /** */ protectedboolean reloadable; /** if true, this module is eagerly turned on whenever it can be */ privatefinalboolean eager; /** currently active module classloader */ protected ClassLoader classloader;
// Access from ModuleManager: void setEnabled(boolean enabled) { /* #13647: actually can happen if loading of bootstrap modules is rolled back: */ if (isFixed() && ! enabled) thrownew IllegalStateException("Cannot disable a fixed module: " + this); // NOI18N this.enabled = enabled;
}
/** Normally a module once created and managed is valid *(thatis,eitherinstalledornot,butatleastmanaged). *Ifitisdeletedanyremainingreferencestoitbecome *invalid.
*/ publicboolean isValid() { return mgr.get(getCodeNameBase()) == this;
}
/** Is this module automatically loaded? *Ifso,noinformationaboutitsstateiskept *permanentlybeyondtheexistenceofitsJARfile; *itisenabledwhensomerealmoduleneedsittobe, *anddisabledwhenthisisnolongerthecase. *@see<ahref="https://bz.apache.org/netbeans/show_bug.cgi?id=9779">#9779</a>
*/ publicboolean isAutoload() { return autoload;
}
/** Is this module eagerly enabled? *Ifso,noinformationaboutitsstateiskeptpermanently. *Itisturnedonwheneveritcanbe,i.e.wheneveritmeetsallof *itsdependencies.Thismaybeusedtoimplement"bridge"moduleswith *simplefunctionalitythatjustdependontwonormalmodules. *Amodulemaynotbesimultaneouslyeagerandautoload. *@see<ahref="https://bz.apache.org/netbeans/show_bug.cgi?id=17501">#17501</a> *@sinceorg.netbeans.core/11.3
*/ publicboolean isEager() { return eager;
}
/** Get an associated arbitrary attribute. *Rightnow,simplyprovidesthemainattributesofthemanifest. *Inthefuturesomeofthesecouldbesuppressed(ifonlyofdangerous *interest,e.g.Class-Path)orenhancedwithotherinformationavailable *fromthecore(ifneeded).
*/
@Override public Object getAttribute(String attr) { return getManifest().getMainAttributes().getValue(attr);
}
@Override public String getCodeName() { return data().getCodeName();
}
public @Override String[] getProvides() { return data().getProvides();
} /** Test whether the module provides a given token or not. *@sinceJST-PENDINGagainusedfromNbProblemDisplayer
*/ publicfinalboolean provides(String token) {
String[] provides = getProvides(); if (provides == null) { returnfalse;
} for (int i = 0; i < provides.length; i++) { if (provides[i].equals(token)) { returntrue;
}
} returnfalse;
}
@Override public SpecificationVersion getSpecificationVersion() { return data().getSpecificationVersion();
}
@Override public String getImplementationVersion() { return data().getImplementationVersion();
}
@Override public String getBuildVersion() { return data().getBuildVersion();
}
public @Override boolean owns(Class<?> clazz) {
ClassLoader cl = clazz.getClassLoader(); if (cl instanceof Util.ModuleProvider) { return ((Util.ModuleProvider) cl).getModule() == this;
} if (cl != classloader) { returnfalse;
}
String _codeName = findClasspathModuleCodeName(clazz); if (_codeName != null) { return _codeName.equals(getCodeName());
} returntrue; // not sure...
}
static String findClasspathModuleCodeName(Class<?> clazz) { // #157798: in JNLP or otherwise classpath mode, all modules share a CL.
CodeSource src = clazz.getProtectionDomain().getCodeSource(); if (src != null) { try {
URL loc = src.getLocation(); if (loc.toString().matches(".+\\.jar")) { // URLClassLoader inconsistency.
loc = new URL("jar:" + loc + "!/");
}
URL manifest = new URL(loc, "META-INF/MANIFEST.MF");
InputStream is = manifest.openStream(); try { returnnew Manifest(is).getMainAttributes().getValue("OpenIDE-Module");
} finally {
is.close();
}
} catch (IOException x) {
Logger.getLogger(Module.class.getName()).log(Level.FINE, null, x);
}
} returnnull;
}
/** Get all packages exported by this module to other modules. *@returnalist(possiblyempty)ofexportedpackages,ornulltoexporteverything *@sinceorg.netbeans.core/1>1.4 *@see"#19621"
*/ public PackageExport[] getPublicPackages() { return data().getPublicPackages();
}
/** Checks whether we use friends attribute and if so, then *whetherthenameofmoduleislistedthere.
*/ boolean isDeclaredAsFriend (Module module) {
Set<String> friendNames = data().getFriendNames(); if (friendNames == null) { returntrue;
} return friendNames.contains(module.getCodeNameBase());
}
/** Parse information from the current manifest. *Includescodename,specificationversion,anddependencies. *Ifanythingisinaninvalidformat,throwsanexceptionwith *somekindofdescriptionoftheproblem.
*/ protectedvoid parseManifest() throws InvalidException {
data();
}
/** Get all JARs loaded by this module. *Includesthemoduleitself,anylocalevariantsofthemodule, *anyextensionsspecifiedwithClass-Path,anylocalevariants *ofthoseextensions. *Thelistwillbeinclasspathorder(patchesfirst). *CurrentlythetempJARisprovidedinthecaseoftestmodules,toprevent *sporadicZIPfileexceptionswhenbackgroundthreads(likeJavaparsing)tries *toopenlibrariesfoundinthelibrarypath. *JARsalreadypresentintheclasspathare<em>not</em>listed. *@returnalistofJARs
*/ publicabstract List<File> getAllJars();
/** Is this module supposed to be easily reloadable? *Ifso,itissuitablefortestinginsidetheIDE. *ControlswhetheracopyoftheJARfileismadebefore *passingittotheclassloader,whichcanaffectlocking *andrefreshingoftheJAR.
*/ publicboolean isReloadable() { return reloadable;
}
/** Set whether this module is supposed to be reloadable. *Hasnoimmediateeffect,onlyimpactswhathappensthe *nexttimeitisenabled(afterhavingbeendisabledif *necessary). *Mustbecalledfromwithinawritemutex. *@paramrwhetherthemoduleshouldbeconsideredreloadable
*/ publicabstractvoid setReloadable(boolean r);
/** Reload this module. Access from ModuleManager. *Ifanexceptionisthrown,themoduleisconsidered *tobeinaninvalidstate. *@sinceJST-PENDING:neededfromModuleSystem
*/ publicabstractvoid reload() throws IOException;
// impl of ModuleInfo method public @Override ClassLoader getClassLoader() throws IllegalArgumentException { if (!enabled) { thrownew IllegalArgumentException("Not enabled: " + getCodeNameBase()); // NOI18N
} assert classloader != null : "Should have had a non-null loader for " + this; return classloader;
}
// Access from ModuleManager: /** Turn on the classloader. Passed a list of parent modules to use. *Theparentsshouldalreadyhavehadtheirclassloadersinitialized.
*/ protectedabstractvoid classLoaderUp(Set<Module> parents) throws IOException;
/** Turn off the classloader and release all resources. */ protectedabstractvoid classLoaderDown(); /** Should be called after turning off the classloader of one or more modules & GC'ing. */ protectedabstractvoid cleanup();
/** Notify the module that it is being deleted. */ protectedabstractvoid destroy();
/** Get the JAR this module is packaged in. *Maybenullformodulesinstalledspecially,e.g. *automaticallyfromtheclasspath. *@see#isFixed
*/ public File getJarFile() { returnnull;
}
/** Get the JAR manifest. *Shouldneverbenull,evenifdisabled. *Mightchangeifamoduleisreloaded. *Itisnotguaranteedthatchangeeventswillbefired *forchangesinthisproperty.
*/ publicabstract Manifest getManifest();
/** Get the history object representing what has happened to this module before. *@see<ahref="@org-netbeans-core-startup@/org/netbeans/core/startup/ModuleHistory.html">ModuleHistory</a>
*/ publicfinal Object getHistory() { return history;
}
/** Finds out if a module has been assigned with a specific start level. *StartlevelisonlyusefulforOSGibundles.Otherwiseitisalwayszero. * *@return-1,ifnospecificlevelisassigned,non-negativeintegerifso *@since2.43
*/ publicfinalint getStartLevel() { return getStartLevelImpl();
}
int getStartLevelImpl() { return -1;
}
/** String representation for debugging. */ public @Override String toString() {
String s = "Module:" + getCodeNameBase(); // NOI18N if (!isValid()) s += "[invalid]"; // NOI18N return s;
}
/** Locates resource in this module. May search only the main JAR *ofthemodule(whichiswhatitdoesincaseofOSGibundles). *Shouldbeaslightweightaspossible-e.g.ifitisOKtonot *initializesomethinginthemodulewhileperformingthismethod, *thesomethingshouldnotbeinitialized(e.g.OSGibundlesare *notresolved). * *@paramresourcespathtotheresourceswearelookingfor *@since2.49
*/ public Enumeration<URL> findResources(String resources) { try { // #149136
ClassLoader cl = getClassLoader();
if (cl instanceof ProxyClassLoader) { return ((ProxyClassLoader) cl).findResources(resources);
} //TODO: other ClassLoaders - what can we expect here? can fallback to getResources for JVM classloaders, and nothing else should be here? thrownew IllegalStateException("Unexpected ClassLoader: " + cl + ".");
} catch (Exception x) {
Exceptions.printStackTrace(x); return Enumerations.empty();
}
}
/** To be overriden to empty in FixedModule & co. */ void refineDependencies(Set<Dependency> dependencies) { // Permit the concrete installer to make some changes:
mgr.refineDependencies(this, dependencies);
}
/** Is this module a wrapper around OSGi? *@returntrue,ifthemoduleisbuildaroundOSGi *@since2.51
*/ publicfinalboolean isNetigso() { return isNetigsoImpl();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.