Java Code Examples for org.openide.modules.ModuleInfo#isEnabled()

The following examples show how to use org.openide.modules.ModuleInfo#isEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public final boolean isEnabled() {
    Boolean e = cacheEnabled;
    if (e != null) {
        return e;
    }

    for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
        if (cnbs.contains(mi.getCodeNameBase())) {
            if (!FeatureManager.showInAU(mi)) {
                continue;
            }
            return cacheEnabled = mi.isEnabled();
        }
    }
    return cacheEnabled = false;
}
 
Example 2
Source File: WizardAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static Class<?> getClass(String className) {
    Collection<? extends ModuleInfo> modules = Lookup.getDefault().lookupAll(ModuleInfo.class);
    for (ModuleInfo module : modules) {
        if (module.isEnabled()) {
            try {
                Class<?> implClass = module.getClassLoader().loadClass(className);
                if (WizardPanel.class.isAssignableFrom(implClass)) {
                    //noinspection unchecked
                    return (Class<?>) implClass;
                }
            } catch (ClassNotFoundException e) {
                // it's ok, continue
            }
        }
    }
    return null;
}
 
Example 3
Source File: WindowManagerParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Checks if module for given mode exists.
 * @return true if mode is valid - its module exists
 */
private boolean acceptMode (ModeParser modeParser, ModeConfig config) {
    InternalConfig cfg = modeParser.getInternalConfig();
    //Check module info
    if (cfg.moduleCodeNameBase != null) {
        ModuleInfo curModuleInfo = PersistenceManager.findModule
        (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
         cfg.moduleSpecificationVersion);
        if (curModuleInfo == null) {
            PersistenceManager.LOG.info("Cannot find module \'" +
                      cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " + 
                      cfg.moduleSpecificationVersion + "\' for wsmode with name \'" + config.name + "\'"); // NOI18N
        }
        if ((curModuleInfo != null) && curModuleInfo.isEnabled()) {
            //Module is present and is enabled
            return true;
        } else {
            //Module is NOT present (it could be deleted offline)
            //or is NOT enabled
            return false;
        }
    } else {
        //No module info
        return true;
    }
}
 
Example 4
Source File: WindowManagerParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Checks if module for given group exists.
 * @return true if group is valid - its module exists
 */
private boolean acceptGroup (GroupParser groupParser, GroupConfig config) {
    InternalConfig cfg = groupParser.getInternalConfig();
    //Check module info
    if (cfg.moduleCodeNameBase != null) {
        ModuleInfo curModuleInfo = PersistenceManager.findModule
                                    (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
                                     cfg.moduleSpecificationVersion);
        if (curModuleInfo == null) {
            
            PersistenceManager.LOG.log(Level.FINE, "Cannot find module \'" +
                      cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " + 
                      cfg.moduleSpecificationVersion + "\' for group with name \'" + config.name + "\'"); // NOI18N
            
        }
        if ((curModuleInfo != null) && curModuleInfo.isEnabled()) {
            //Module is present and is enabled
            return true;
        } else {
            return false;
        }
    } else {
        //No module info
        return true;
    }
}
 
Example 5
Source File: GroupParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Checks if module for given tcGroup exists.
 * @return true if tcGroup is valid - its module exists
 */
private boolean acceptTCGroup (TCGroupParser tcGroupParser, TCGroupConfig config) {
    InternalConfig cfg = tcGroupParser.getInternalConfig();
    //Check module info
    if (cfg.moduleCodeNameBase != null) {
        ModuleInfo curModuleInfo = PersistenceManager.findModule
                                    (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
                                     cfg.moduleSpecificationVersion);
        if (curModuleInfo == null) {
            PersistenceManager.LOG.fine("Cannot find module \'" +
                      cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " + 
                      cfg.moduleSpecificationVersion + "\' for tcgrp with name \'" + config.tc_id + "\'"); // NOI18N
        }
        if ((curModuleInfo != null) && curModuleInfo.isEnabled()) {
            //Module is present and is enabled
            return true;
        } else {
            //Module is NOT present (it could be deleted offline)
            //or is NOT enabled
            return false;
        }
    } else {
        //No module info
        return true;
    }
}
 
Example 6
Source File: SerialDataConvertor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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(
                    "Warning: unknown module code base: " + // NOI18N
                    moduleCodeBase + " in " +  // NOI18N
                    getDataObject().getPrimaryFile());
            }
        } else {
            moduleMissing = false;
        }
    } else {
        mi = ModuleInfoManager.getDefault().getModule(moduleCodeBase);
    }
    
    return !moduleMissing && (mi == null || mi.isEnabled());
}
 
Example 7
Source File: OperatorUIRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static <T> Class<T> getClassAttribute(FileObject fileObject,
                                             String attributeName,
                                             Class<T> expectedType,
                                             boolean required) {
    String className = (String) fileObject.getAttribute(attributeName);
    if (className == null || className.isEmpty()) {
        if (required) {
            throw new IllegalArgumentException(String.format("Missing attribute '%s' of type %s",
                                                             attributeName, expectedType.getName()));
        }
        return null;
    }

    Collection<? extends ModuleInfo> modules = Lookup.getDefault().lookupAll(ModuleInfo.class);
    for (ModuleInfo module : modules) {
        if (module.isEnabled()) {
            try {
                Class<?> implClass = module.getClassLoader().loadClass(className);
                if (expectedType.isAssignableFrom(implClass)) {
                    //noinspection unchecked
                    return (Class<T>) implClass;
                } else {
                    throw new IllegalArgumentException(String.format("Value %s of attribute '%s' must be a %s",
                                                                     implClass.getName(),
                                                                     attributeName,
                                                                     expectedType.getName()));
                }
            } catch (ClassNotFoundException e) {
                // it's ok, continue
            }
        }
    }
    return null;
}
 
Example 8
Source File: PlatformInstallIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void initialize(WizardDescriptor wiz) {
    this.wizard = wiz;
    List<GeneralPlatformInstall> installers = InstallerRegistry.getDefault().getAllInstallers();
    if (installers.isEmpty()) {
        //Probably fixed by: #178256
        final Collection<? extends ModuleInfo> infos = Lookup.getDefault().lookupAll(ModuleInfo.class);
        final StringBuilder sb = new StringBuilder("No PlatformInstallFound in Lookup, enabled modules:\n");    //NOI18N
        for (ModuleInfo info : infos) {
            if (info.isEnabled()) {
                sb.append(info.getDisplayName());
                sb.append('('); //NOI18N
                sb.append(info.getCodeName());
                sb.append(")\n"); //NOI18N
            }
        }
        throw new IllegalStateException(sb.toString());
    } else if (installers.size()>1) {
        panelIndex = 0;
        hasSelectorPanel = true;
    }
    else {
        if (installers.get(0) instanceof CustomPlatformInstall) {
            panelIndex = 3;
            hasSelectorPanel = false;
            this.typeIterator = ((CustomPlatformInstall) installers.get(0)).createIterator();
            if (this.typeIterator == null)
                throw new NullPointerException ();
        }
        else {
            panelIndex = 1;
            hasSelectorPanel = false;
            this.locationPanel.setPlatformInstall((PlatformInstall) installers.get(0));
        }
    }            
    updatePanelsList(new JComponent[]{((JComponent)current().getComponent())}, this.typeIterator);
    this.wizard.setTitle(NbBundle.getMessage(PlatformInstallIterator.class,"TXT_AddPlatformTitle"));
    panelNumber = 0;
    wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, // NOI18N
        new Integer(panelNumber));
}
 
Example 9
Source File: LayerManager.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static <T> Class<T> getClassAttribute(FileObject fileObject,
                                             String attributeName,
                                             Class<T> expectedType,
                                             boolean required) {
    String className = (String) fileObject.getAttribute(attributeName);
    if (className == null || className.isEmpty()) {
        if (required) {
            throw new IllegalArgumentException(String.format("Missing attribute '%s' of type %s",
                                                             attributeName, expectedType.getName()));
        }
        return null;
    }

    Collection<? extends ModuleInfo> modules = Lookup.getDefault().lookupAll(ModuleInfo.class);
    for (ModuleInfo module : modules) {
        if (module.isEnabled()) {
            try {
                Class<?> implClass = module.getClassLoader().loadClass(className);
                if (expectedType.isAssignableFrom(implClass)) {
                    //noinspection unchecked
                    return (Class<T>) implClass;
                } else {
                    throw new IllegalArgumentException(String.format("Value %s of attribute '%s' must be a %s",
                                                                     implClass.getName(),
                                                                     attributeName,
                                                                     expectedType.getName()));
                }
            } catch (ClassNotFoundException e) {
                // it's ok, continue
            }
        }
    }
    return null;
}
 
Example 10
Source File: WizardDeadTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isModuleEnabled() {
    for (ModuleInfo inf : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
        if ("org.netbeans.modules.java.kit".equals(inf.getCodeNameBase())) {
            return inf.isEnabled();
        }
    }
    fail("Java Kit not found!");
    return false;
}
 
Example 11
Source File: FeatureManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent evt) {
    if (ModuleInfo.PROP_ENABLED.equals(evt.getPropertyName())) {
        ModuleInfo mi = (ModuleInfo)evt.getSource();
        if (!noCnbCheck && enabledCnbs.contains(mi.getCodeNameBase()) && mi.isEnabled()) {
            return;
        }
        fireChange();
        if (mi.isEnabled()) {
            enabledCnbs.add(mi.getCodeNameBase());
        } else {
            enabledCnbs.remove(mi.getCodeNameBase());
        }
    }
}
 
Example 12
Source File: OpenProjectList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkModuleInfo(ModuleInfo info) {
    if (info.isEnabled())  {
        return;
    }
    Collection<Project> toRemove = new ArrayList<Project>(openProjectsModuleInfos.get(info));
    if (toRemove.size() > 0) {
        for (Project prj : toRemove) {
            removeModuleInfo(prj, info);
        }
        close(toRemove.toArray(new Project[toRemove.size()]), false);
    }
}
 
Example 13
Source File: JarBundleFile.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private BundleEntry findEntry(String why, final String name) {
    if (!name.equals("META-INF/MANIFEST.MF") && // NOI18N
        data != null && 
        data.getLocation() != null && 
        data.getLocation().startsWith("netigso://") // NOI18N
    ) { 
        String cnb = data.getLocation().substring(10);
        for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
            if (mi.getCodeNameBase().equals(cnb)) {
                if (!mi.isEnabled()) {
                    break;
                }
                final URL url = mi.getClassLoader().getResource(name);
                if (url != null) {
                    return new ModuleEntry(url, name);
                } else {
                    break;
                }
            }
        }
    }
    
    if ("/".equals(name)) { // NOI18N
        return new RootEntry(this); // NOI18N
    }
    
    BundleEntry u;
    for (;;) {
        BundleFile d = delegate(why, name);
        u = d.getEntry(name);
        if (u != null || d == delegate) {
            break;
        }
    }
    return u;
}
 
Example 14
Source File: OperationsTestImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void assertInstalledModule (UpdateUnit toInstallUnit) throws InterruptedException {
    ModuleInfo info = getModuleInfos ().get (toInstallUnit.getCodeName ());
    assertNotNull (info);
    int timeout = 250;
    while (! info.isEnabled () && timeout-- > 0) {
        Thread.sleep (10);
    }
    assertTrue (info.getCodeNameBase (), info.isEnabled ());
    assertNotNull (Utilities.toModule (toInstallUnit.getCodeName (), null));
    assertTrue (Utilities.toModule (toInstallUnit.getCodeName (), null).isEnabled ());
}
 
Example 15
Source File: WWLayerRegistry.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static <T> Class<T> getClassAttribute(final FileObject fileObject,
                                             final String attributeName,
                                             final Class<T> expectedType,
                                             final boolean required) {
    final String className = (String) fileObject.getAttribute(attributeName);
    if (className == null || className.isEmpty()) {
        if (required) {
            throw new IllegalArgumentException(String.format("Missing attribute '%s' of type %s",
                                                             attributeName, expectedType.getName()));
        }
        return null;
    }

    final Collection<? extends ModuleInfo> modules = Lookup.getDefault().lookupAll(ModuleInfo.class);
    for (ModuleInfo module : modules) {
        if (module.isEnabled()) {
            try {
                final Class<?> implClass = module.getClassLoader().loadClass(className);
                if (expectedType.isAssignableFrom(implClass)) {
                    //noinspection unchecked
                    return (Class<T>) implClass;
                } else {
                    throw new IllegalArgumentException(String.format("Value %s of attribute '%s' must be a %s",
                                                                     implClass.getName(),
                                                                     attributeName,
                                                                     expectedType.getName()));
                }
            } catch (ClassNotFoundException e) {
                // it's ok, continue
            }
        }
    }
    return null;
}
 
Example 16
Source File: Lookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void listenOnDisabledModules() {
    Collection<? extends ModuleInfo> allInstances = moduleLookupResult.allInstances();
    synchronized (moduleChangeListeners) {
        for (ModuleInfo mi : allInstances) {
            if (!mi.isEnabled() && !disabledModuleChangeListeners.containsKey(mi)) {
                ModuleChangeListener l = new ModuleChangeListener(null);
                mi.addPropertyChangeListener(WeakListeners.propertyChange(l, mi));
                disabledModuleChangeListeners.put(mi, l);
            }
        }
    }
}
 
Example 17
Source File: TabSwitchSpeedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void enableModulesFromCluster(String cluster) throws Exception {
    Pattern p = Pattern.compile(cluster);
    String dirs = System.getProperty("netbeans.dirs");
    int cnt = 0;
    for (String c : dirs.split(File.pathSeparator)) {
        if (!p.matcher(c).find()) {
            continue;
        }
        
        File cf = new File(c);
        File ud = new File(System.getProperty("netbeans.user"));
        turnModules(ud, cf);
        cnt++;
    }
    if (cnt == 0) {
        fail("Cannot find cluster " + cluster + " in " + dirs);
    }
    
    FileUtil.getConfigRoot().getFileSystem().refresh(false);
    LOOP: for (int i = 0; i < 20; i++) {
        Thread.sleep(1000);
        for (ModuleInfo info : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
            if (!info.isEnabled()) {
                System.err.println("not enabled yet " + info);
                continue LOOP;
            }
        }
    }
}
 
Example 18
Source File: AbstractTestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if module is enabled else <code>false</code>.
 */
public static boolean isModuleEnabled(String codeName) {
    ModuleInfo mi = getModuleInfo(codeName);
    if (mi == null) {
        throw new IllegalArgumentException("Invalid codeName: " + codeName);
    }
    
    return mi.isEnabled();
}
 
Example 19
Source File: ModuleInfoManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public PCL(ModuleInfo mi) {
    this.mi = mi;
    wasModuleEnabled = mi.isEnabled();
    mi.addPropertyChangeListener(this);
}
 
Example 20
Source File: EnableJ2EEEnablesJavaTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testEnablingJ2EEEnablesJavaViaAutoUpdateManager() throws Exception {
    FeatureInfo j2ee = null;
    FeatureInfo java = null;
    for (FeatureInfo f : FeatureManager.features()) {
        if (f.getCodeNames().contains("org.netbeans.modules.j2ee.kit")) {
            j2ee = f;
        }
        if (f.getCodeNames().contains("org.netbeans.modules.java.kit")) {
            java = f;
        }
    }
    if (j2ee == null) {
        return;
    }
    assertNotNull("java feature found", java);

    List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.FEATURE);
    UpdateElement j2eeUE = null;
    StringBuilder sb = new StringBuilder();
    for (UpdateUnit uu : units) {
        sb.append(uu.getCodeName()).append('\n');
        if (uu.getCodeName().equals("fod.org.netbeans.modules.j2ee.kit")) {
            j2eeUE = uu.getInstalled();
        }
    }
    assertNotNull("J2EE found: " + sb, j2eeUE);
    OperationContainer<OperationSupport> cc = OperationContainer.createForEnable();
    OperationInfo<OperationSupport> info = cc.add(j2eeUE);
    cc.add(info.getRequiredElements());
    cc.getSupport().doOperation(null);


    Set<String> expectedNames = new HashSet<String>(java.getCodeNames());
    for (ModuleInfo mi : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
        if (mi.isEnabled()) {
            expectedNames.remove(mi.getCodeNameBase());
        } else {
            for (Dependency d : mi.getDependencies()) {
                if (d.getType() == Dependency.TYPE_JAVA) {
                    SpecificationVersion v1 = new SpecificationVersion(d.getVersion());
                    SpecificationVersion v2 = Dependency.JAVA_SPEC;
                    if (v2.compareTo(v1) < 0) {
                        // test is running insufficient runtime
                        expectedNames.remove(mi.getCodeNameBase());
                    }
                }
            }
        }
    }
    if (!expectedNames.isEmpty()) {
        fail(
            "java cluster shall be fully enabled, but this was missing:\n" +
            expectedNames.toString().replace(',', '\n')
        );
    }
}