use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.
the class SerialDataConvertor method isModuleEnabled.
private boolean isModuleEnabled(SerialDataConvertor.SettingsInstance si) {
ModuleInfo mi = null;
if (miUnInitialized) {
moduleCodeBase = getModuleCodeNameBase(si);
miUnInitialized = false;
if (moduleCodeBase != null) {
mi = ModuleInfoManager.getDefault().getModule(moduleCodeBase);
moduleMissing = (mi == null);
if (mi != null) {
ModuleInfoManager.getDefault().registerPropertyChangeListener(this, mi);
} else {
XMLSettingsSupport.err.warning(// NOI18N
"Warning: unknown module code base: " + moduleCodeBase + // NOI18N
" in " + getDataObject().getPrimaryFile());
}
} else {
moduleMissing = false;
}
} else {
mi = ModuleInfoManager.getDefault().getModule(moduleCodeBase);
}
return !moduleMissing && (mi == null || mi.isEnabled());
}
use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.
the class SerialDataConvertor method propertyChange.
public void propertyChange(PropertyChangeEvent evt) {
if (evt == null)
return;
String name = evt.getPropertyName();
if (name == null)
return;
else // setting was changed
if (name == SaveSupport.PROP_SAVE)
provideSaveCookie();
else // .settings file was changed
if (name == SaveSupport.PROP_FILE_CHANGED) {
miUnInitialized = true;
if (moduleCodeBase != null) {
ModuleInfo mi = ModuleInfoManager.getDefault().getModule(moduleCodeBase);
ModuleInfoManager.getDefault().unregisterPropertyChangeListener(this, mi);
}
instanceCookieChanged(null);
} else if (ModuleInfo.PROP_ENABLED.equals(evt.getPropertyName())) {
instanceCookieChanged(null);
}
}
use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.
the class NbLoaderPool method readPool.
/**
* Reads loader from the input stream.
* @param ois object input stream to read from
*/
private static synchronized void readPool(ObjectInputStream ois, NbLoaderPool pool) throws IOException, ClassNotFoundException {
/*installBefores = (Map)*/
ois.readObject();
/*installAfters = (Map)*/
ois.readObject();
HashSet<Class> classes = new HashSet<Class>();
LinkedList<DataLoader> l = new LinkedList<DataLoader>();
Iterator<? extends ModuleInfo> mit = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
Map<String, ModuleInfo> modules = new HashMap<String, ModuleInfo>();
while (mit.hasNext()) {
ModuleInfo m = mit.next();
modules.put(m.getCodeNameBase(), m);
}
for (; ; ) {
Object o1 = ois.readObject();
if (o1 == null) {
if (err.isLoggable(Level.FINE))
err.fine("reading null");
break;
}
NbMarshalledObject obj;
if (o1 instanceof String) {
String name = (String) o1;
if (name.length() > 0 && name.charAt(0) == '=') {
// NOI18N
// #27190: unmodified loader, just here for the ordering.
String cname = name.substring(1);
DataLoader dl = names2Loaders.get(cname);
if (dl != null) {
if (err.isLoggable(Level.FINE))
err.fine("reading unmodified " + cname);
l.add(dl);
classes.add(dl.getClass());
} else {
// No such known loaded - presumably disabled module.
if (err.isLoggable(Level.FINE))
err.fine("skipping unmodified nonexistent " + cname);
}
continue;
}
// Module information.
int rel = ois.readInt();
String spec = (String) ois.readObject();
obj = (NbMarshalledObject) ois.readObject();
ModuleInfo m = modules.get(name);
if (m == null) {
if (err.isLoggable(Level.FINE))
err.fine("No known module " + name + ", skipping loader");
continue;
}
if (!m.isEnabled()) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is disabled, skipping loader");
continue;
}
if (m.getCodeNameRelease() < rel) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is too old (major vers.), skipping loader");
continue;
}
if (spec != null) {
SpecificationVersion v = m.getSpecificationVersion();
if (v == null || v.compareTo(new SpecificationVersion(spec)) < 0) {
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is too old (spec. vers.), skipping loader");
continue;
}
}
if (err.isLoggable(Level.FINE))
err.fine("Module " + name + " is OK, will try to restore loader");
} else {
// Loader with no known module, or backward compatibility.
obj = (NbMarshalledObject) o1;
}
Exception t = null;
try {
DataLoader loader = (DataLoader) obj.get();
if (loader == null) {
// issue 38658)
continue;
}
Class<?> clazz = loader.getClass();
if (err.isLoggable(Level.FINE))
err.fine("reading modified " + clazz.getName());
l.add(loader);
classes.add(clazz);
} catch (IOException ex) {
t = ex;
} catch (ClassNotFoundException ex) {
t = ex;
}
}
// Read system loaders. But not into any particular order.
for (; ; ) {
NbMarshalledObject obj = (NbMarshalledObject) ois.readObject();
if (obj == null) {
if (err.isLoggable(Level.FINE))
err.fine("reading null");
break;
}
Exception t = null;
try {
// Just reads its shared state, nothing more.
DataLoader loader = (DataLoader) obj.get();
if (err.isLoggable(Level.FINE))
err.fine("reading " + loader.getClass().getName());
} catch (IOException ex) {
t = ex;
} catch (ClassNotFoundException ex) {
t = ex;
}
}
if (err.isLoggable(Level.FINE))
err.fine("done reading");
// Explanation: modules are permitted to restoreDefault () before
// the loader pool is de-externalized. This means that all loader manifest
// sections will add a default-instance entry to the pool at startup
// time. Later, when the pool is restored, this may reorder existing ones,
// as well as change properties. But if any loader is missing (typically
// due to failed deserialization), it will nonetheless be added to the end
// now (and the pool resorted just in case).
Iterator it = loaders.iterator();
while (it.hasNext()) {
DataLoader loader = (DataLoader) it.next();
if (!classes.contains(loader.getClass())) {
l.add(loader);
}
}
// NOI18N
if (l.size() > new HashSet<DataLoader>(l).size())
throw new IllegalStateException("Duplicates in " + l);
loaders = l;
// Always "resort": if the existing order was in fact compatible with the
// current install-befores/afters, then this is no op (besides firing an
// update event). Cf. #29671.
resort(pool);
}
use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.
the class NbLoaderPool method writePool.
/**
* Stores all the objects into stream.
* @param oos object output stream to write to
*/
private static synchronized void writePool(ObjectOutputStream oos, NbLoaderPool pool) throws IOException {
if (err.isLoggable(Level.FINE))
err.fine("writePool");
// No longer bother storing these (#29671):
oos.writeObject(new HashMap());
oos.writeObject(new HashMap());
Iterator it = loaders.iterator();
while (it.hasNext()) {
DataLoader l = (DataLoader) it.next();
if (!isModified(l)) {
// #27190 - no real need to write this in detail.
String c = l.getClass().getName();
if (err.isLoggable(Level.FINE))
err.fine("writing unmodified " + c);
// '=' not a permissible part of a cnb, so this distinguishes it
// NOI18N
oos.writeObject("=" + c);
continue;
}
NbMarshalledObject obj;
try {
obj = new NbMarshalledObject(l);
} catch (IOException ex) {
err.log(Level.WARNING, null, ex);
obj = null;
}
if (obj != null) {
if (err.isLoggable(Level.FINE))
err.fine("writing modified " + l.getClass().getName());
// Find its module, if any.
boolean found = false;
ModuleInfo m = Modules.getDefault().ownerOf(l.getClass());
if (m != null && m.isEnabled()) {
if (err.isLoggable(Level.FINE))
err.fine("belongs to module: " + m.getCodeNameBase());
oos.writeObject(m.getCodeNameBase());
int r = m.getCodeNameRelease();
// might be -1, note
oos.writeInt(r);
SpecificationVersion v = m.getSpecificationVersion();
if (v != null) {
oos.writeObject(v.toString());
} else {
oos.writeObject(null);
}
found = true;
}
if (!found) {
if (err.isLoggable(Level.FINE))
err.fine("does not belong to any module");
// just write the NbMarshalledObject<DataLoader> itself;
// we need to support that for compatibility of old loader
// pools anyway
}
oos.writeObject(obj);
}
}
if (err.isLoggable(Level.FINE))
err.fine("writing null");
oos.writeObject(null);
// Write out system loaders now:
Enumeration e = pool.allLoaders();
while (e.hasMoreElements()) {
DataLoader l = (DataLoader) e.nextElement();
if (loaders.contains(l))
continue;
if (!isModified(l)) {
// #27190 again. No need to write anything
String c = l.getClass().getName();
if (err.isLoggable(Level.FINE))
err.fine("skipping unmodified " + c);
continue;
}
NbMarshalledObject obj;
try {
obj = new NbMarshalledObject(l);
} catch (IOException ex) {
err.log(Level.WARNING, null, ex);
obj = null;
}
if (obj != null) {
if (err.isLoggable(Level.FINE))
err.fine("writing " + l.getClass().getName());
// No associated module, no need to write such info.
oos.writeObject(obj);
}
}
if (err.isLoggable(Level.FINE))
err.fine("writing null");
oos.writeObject(null);
if (err.isLoggable(Level.FINE))
err.fine("done writing");
}
use of org.openide.modules.ModuleInfo in project constellation by constellation-app.
the class MostRecentModules method getModules.
/**
* Return a list of modules ordered by descending version number.
* <p>
* The build process modifies the version number of modules so that the
* first two parts are maintained and the next two parts are the yyyymmdd
* date and hhmmss time of the build as integers.
* <p>
* The module list is ordered by just the build part of the version if the
* SpecificationVersion has four elements.
*
* @return A list of modules ordered by most recent version.
*/
public static List<ModuleInfo> getModules() {
final Collection<? extends ModuleInfo> modules = Lookup.getDefault().lookupAll(ModuleInfo.class);
final List<ModuleInfo> moduleList = new ArrayList<>();
for (final ModuleInfo mi : modules) {
if (!mi.getCodeNameBase().startsWith("org.netbeans") && !mi.getCodeNameBase().startsWith("org.apache") && !mi.getCodeNameBase().startsWith("org.openide") && !mi.getCodeNameBase().startsWith("org.jdesktop") && !mi.getCodeNameBase().startsWith("net.java.html")) {
moduleList.add(mi);
}
}
moduleList.sort((final ModuleInfo mi1, final ModuleInfo mi2) -> {
final SpecificationVersion specver1 = mi1.getSpecificationVersion();
final SpecificationVersion specver2 = mi2.getSpecificationVersion();
final String[] v1 = specver1.toString().split("\\.");
final String[] v2 = specver2.toString().split("\\.");
if (v1.length == 4 && v2.length == 4) {
int comp = Integer.compare(Integer.parseInt(v2[2]), Integer.parseInt(v1[2]));
if (comp == 0) {
comp = Integer.compare(Integer.parseInt(v2[3]), Integer.parseInt(v1[3]));
}
return comp;
}
return specver2.compareTo(specver1);
});
return moduleList;
}
Aggregations