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

The following examples show how to use org.openide.modules.ModuleInfo#getCodeNameBase() . 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: AntBridge.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get a map from enabled module code name bases to class loaders containing
 * JARs from ant/nblib/*.jar.
 */
private static Map<String,ClassLoader> createCustomDefClassLoaders(ClassLoader main) throws IOException {
    Map<String,ClassLoader> m = new HashMap<String,ClassLoader>();
    ModuleInfo[] modules = miscListener.getEnabledModules();
    InstalledFileLocator ifl = InstalledFileLocator.getDefault();
    for (ModuleInfo module : modules) {
        String cnb = module.getCodeNameBase();
        String cnbDashes = cnb.replace('.', '-');
        File lib = ifl.locate("ant/nblib/" + cnbDashes + ".jar", cnb, false); // NOI18N
        if (lib == null) {
            if (main.getResource(cnb.replace('.', '/') + "/antlib.xml") != null) { // NOI18N
                // Run-in-classpath mode.
                m.put(cnb, main);
            }
            continue;
        }
        ClassLoader l = createAuxClassLoader(lib, main, module.getClassLoader());
        m.put(cnb, l);
    }
    return m;
}
 
Example 2
Source File: NbInstaller.java    From netbeans with Apache License 2.0 6 votes vote down vote up
final String findProperty(ModuleInfo m, String name, boolean localized) {
    final String fullName = m.getCodeNameBase() + '.' + name;
    final String nullValue = "\u0000"; // NOI18N
    if (modulePropertiesCached) {
        String val = moduleProperties.getProperty(fullName);
        if (nullValue.equals(val)) { 
            return null;
        }
        if (val != null) {
            return val;
        }
        LOG.log(Level.FINE, "not cached value: {0} for {1}", new Object[]{name, m});
    } 
    Object p = localized ? m.getLocalizedAttribute(name) : m.getAttribute(name);
    if (p == null) {
        moduleProperties.setProperty(fullName, nullValue);
        Stamps.getModulesJARs().scheduleSave(this, CACHE, false);
        return null;
    }
    String prop = p instanceof String ? (String)p : null;
    if (prop != null) {
        moduleProperties.setProperty(fullName, prop);
        Stamps.getModulesJARs().scheduleSave(this, CACHE, false);
    }
    return prop;
}
 
Example 3
Source File: InstalledUpdateProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, UpdateItem> getUpdateItems () throws IOException {
    Map<String, UpdateItem> res = new HashMap<String, UpdateItem> ();
    for (ModuleInfo info : defaultProvider().getModuleInfos (true).values ()) {
        Date time = null; // XXX: it's too expensive, should be extracted lazy - Utilities.readInstallTimeFromUpdateTracking (info);
        String installTime = null;
        if (time != null) {
            installTime = Utilities.formatDate(time);
        }
        UpdateItemImpl impl = new InstalledModuleItem (
                info.getCodeNameBase (),
                info.getSpecificationVersion () == null ? null : info.getSpecificationVersion ().toString (),
                info,
                null, // XXX author
                null, // installed cluster
                installTime

                );

        UpdateItem updateItem = Utilities.createUpdateItem (impl);
        res.put (info.getCodeName () + '_' + info.getSpecificationVersion (), updateItem);
    }
    return res;
}
 
Example 4
Source File: InstallConfig.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isPack( ModuleInfo mi ) {
    String moduleName = mi.getCodeNameBase();
    for( String pn : packNames ) {
        if( moduleName.startsWith(pn) )
            return true;
    }
    return false;
}
 
Example 5
Source File: AuxiliaryConfigBasedPreferencesProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String findCNBForClass(@NonNull Class<?> cls) {
    String absolutePath;
    ModuleInfo owner = Modules.getDefault().ownerOf(cls);
    if (owner != null) {
        absolutePath = owner.getCodeNameBase();
    } else {
        absolutePath = cls.getName().replaceFirst("(^|\\.)[^.]+$", "");//NOI18N
    }
    return absolutePath.replace('.', '-');
}
 
Example 6
Source File: FeatureDependsOnFeatureTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, UpdateItem> getUpdateItems() throws IOException {
    Map<String, UpdateItem> items = InstalledModuleProvider.getDefault().getUpdateItems();
    assertNotNull("Installed modules must found.", items);
    int size = items.size();
    assertTrue("Count of installed modules are more then once.", size > 1);
    String pilotName = items.keySet().iterator().next();
    assertNotNull(pilotName + "must found", items.get(pilotName));
    UpdateItem pilotItem = items.get(pilotName);
    assertNotNull("Impl of " + pilotItem + " available", Trampoline.SPI.impl(pilotItem));
    UpdateItemImpl pilotItemImpl = Trampoline.SPI.impl(pilotItem);
    assertTrue("Impl of " + pilotItem + "is ModuleItem", pilotItemImpl instanceof ModuleItem);
    ModuleItem pilotModuleItem = (ModuleItem) pilotItemImpl;
    SpecificationVersion pilotSV = new SpecificationVersion(pilotModuleItem.getSpecificationVersion());
    assertTrue("a dot is present in " + pilotSV, pilotSV.toString().indexOf('.') != -1);
    int dot = pilotSV.toString().indexOf('.');
    String postSpec = pilotSV.toString().substring(dot + 1);
    String preSpec = pilotSV.toString().substring(0, dot);
    Integer digit = 0;
    try {
        digit = Integer.parseInt(preSpec) + 1;
    } catch (NumberFormatException nfe) {
        fail(nfe.getLocalizedMessage());
    }
    SpecificationVersion higherSV = new SpecificationVersion(digit + "." + postSpec);
    assertTrue(higherSV + " is more then " + pilotSV, higherSV.compareTo(pilotSV) > 0);
    String higherDep = pilotModuleItem.getModuleInfo().getCodeNameBase() + " > " + higherSV;

    Set<String> deps = new HashSet<String>(items.size());
    for (String id : items.keySet()) {
        String dep = null;
        if (!pilotName.equals(id)) {
            UpdateItem item = items.get(id);
            assertNotNull("Impl of " + item + " available", Trampoline.SPI.impl(item));
            UpdateItemImpl itemImpl = Trampoline.SPI.impl(item);
            assertTrue("Impl of " + item + "is ModuleItem", itemImpl instanceof ModuleItem);
            ModuleItem moduleItem = (ModuleItem) itemImpl;
            Module m = Utilities.toModule(moduleItem.getModuleInfo());
            if (m != null && m.getProblems().isEmpty()) {
                dep = moduleItem.getModuleInfo().getCodeNameBase() + " > " + moduleItem.getSpecificationVersion();
            }
        } else {
            dep = higherDep;
        }
        if (dep != null) {
            deps.add(dep);
        }
    }
    Map<String, UpdateItem> res = InstalledModuleProvider.getDefault().getUpdateItems();
    ModuleInfo info = pilotModuleItem.getModuleInfo();
    UpdateItemImpl higherItemImpl = new InstalledModuleItem(
            info.getCodeNameBase(),
            higherSV.toString(),
            new HackedModuleInfo(info, higherSV),
            null, // XXX author
            null, // installed cluster
            null);
    UpdateItem higherModuleItem = Utilities.createUpdateItem(higherItemImpl);

    res.put("testFeatureDependsOnModules",
            UpdateItem.createFeature(
            "testFeatureDependsOnModules",
            "1.0",
            deps,
            null,
            null,
            null));
    res.put(pilotName, higherModuleItem);
    res.put("testDependsOnFeature", UpdateItem.createFeature(
            "testDependsOnFeature", "1.3",
            Collections.singleton("testFeatureDependsOnModules"),
            null, null, null));
    return res;
}
 
Example 7
Source File: FeatureNotUpToDateTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Map<String, UpdateItem> getUpdateItems () throws IOException {
    Map<String, UpdateItem> items = InstalledModuleProvider.getDefault().getUpdateItems ();
    assertNotNull ("Installed modules must found.", items);
    int size = items.size ();
    assertTrue ("Count of installed modules are more then once.", size > 1);
    String pilotName = items.keySet ().iterator ().next ();
    assertNotNull (pilotName + "must found", items.get (pilotName));
    UpdateItem pilotItem = items.get (pilotName);
    assertNotNull ("Impl of " + pilotItem + " available", Trampoline.SPI.impl (pilotItem));
    UpdateItemImpl pilotItemImpl = Trampoline.SPI.impl (pilotItem);
    assertTrue ("Impl of " + pilotItem + "is ModuleItem", pilotItemImpl instanceof ModuleItem);
    ModuleItem pilotModuleItem = (ModuleItem) pilotItemImpl;
    SpecificationVersion pilotSV = new SpecificationVersion (pilotModuleItem.getSpecificationVersion ());
    assertTrue ("a dot is present in " + pilotSV, pilotSV.toString ().indexOf ('.') != -1);
    int dot = pilotSV.toString ().indexOf ('.');
    String postSpec = pilotSV.toString ().substring (dot + 1);
    String preSpec = pilotSV.toString ().substring (0, dot);
    Integer digit = 0;
    try {
        digit = Integer.parseInt (preSpec) + 1;
    } catch (NumberFormatException nfe) {
        fail (nfe.getLocalizedMessage ());
    }
    SpecificationVersion higherSV = new SpecificationVersion (digit + "." + postSpec);
    assertTrue (higherSV + " is more then " + pilotSV, higherSV.compareTo (pilotSV) > 0);
    String higherDep = pilotModuleItem.getModuleInfo ().getCodeNameBase () + " > " + higherSV;

    Set<String> deps = new HashSet<String> (items.size ());
    for (String id : items.keySet ()) {
        String dep;
        if (! pilotName.equals (id)) {
            UpdateItem item = items.get (id);
            assertNotNull ("Impl of " + item + " available", Trampoline.SPI.impl (item));
            UpdateItemImpl itemImpl = Trampoline.SPI.impl (item);
            assertTrue ("Impl of " + item + "is ModuleItem", itemImpl instanceof ModuleItem);
            ModuleItem moduleItem = (ModuleItem) itemImpl;
            dep = moduleItem.getModuleInfo ().getCodeNameBase () + " > " + moduleItem.getSpecificationVersion ();
        } else {
            dep = higherDep;
        }
        deps.add (dep);
    }
    Map<String, UpdateItem> res = InstalledModuleProvider.getDefault().getUpdateItems ();
    ModuleInfo info = pilotModuleItem.getModuleInfo ();
    UpdateItemImpl higherItemImpl = new InstalledModuleItem (
            info.getCodeNameBase (),
            higherSV.toString (),
            new HackedModuleInfo (info, higherSV),
            null, // XXX author
            null, // installed cluster
            null);
    UpdateItem higherModuleItem = Utilities.createUpdateItem (higherItemImpl);
    
    res.put ("testFeatureVsStandaloneModules",
            UpdateItem.createFeature (
                "testFeatureVsStandaloneModules",
                "1.0",
                deps,
                null,
                null,
                null));
    res.put (pilotName, higherModuleItem);
    return res;
}
 
Example 8
Source File: InstallConfig.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isErgonomicsPack( ModuleInfo mi ) {
    String moduleName = mi.getCodeNameBase();
    return moduleName.startsWith(ergonomicsPackName) && mi.isEnabled();
}