Search in sources :

Example 1 with FeatureItem

use of org.netbeans.modules.autoupdate.updateprovider.FeatureItem in project netbeans-rcp-lite by outersky.

the class UpdateUnitFactory method appendUpdateItems.

Map<String, UpdateUnit> appendUpdateItems(Map<String, UpdateUnit> originalUnits, UpdateProvider provider) {
    assert originalUnits != null : "Map of original UnitImpl cannot be null";
    boolean trusted = UpdateUnitProviderImpl.loadTrusted(provider);
    Map<String, UpdateItem> items;
    try {
        items = provider.getUpdateItems();
    } catch (IOException ioe) {
        log.log(Level.INFO, "Cannot read UpdateItem from UpdateProvider " + provider, ioe);
        return originalUnits;
    }
    assert items != null : "UpdateProvider[" + provider.getName() + "] should return non-null items.";
    // append updates
    for (String simpleItemId : items.keySet()) {
        UpdateElement updateEl = null;
        try {
            // create UpdateItemImpl
            UpdateItemImpl itemImpl = Trampoline.SPI.impl(items.get(simpleItemId));
            boolean isKitModule = false;
            if (itemImpl instanceof ModuleItem) {
                ModuleInfo mi = ((ModuleItem) itemImpl).getModuleInfo();
                assert mi != null : "ModuleInfo must be found for " + itemImpl;
                isKitModule = Utilities.isKitModule(mi);
            }
            if (itemImpl instanceof InstalledModuleItem) {
                if (isKitModule) {
                    KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
                    updateEl = Trampoline.API.createUpdateElement(impl);
                } else {
                    ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((InstalledModuleItem) itemImpl, null);
                    updateEl = Trampoline.API.createUpdateElement(impl);
                }
            } else if (itemImpl instanceof ModuleItem) {
                if (isKitModule) {
                    KitModuleUpdateElementImpl impl = new KitModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
                    updateEl = Trampoline.API.createUpdateElement(impl);
                } else {
                    ModuleUpdateElementImpl impl = new ModuleUpdateElementImpl((ModuleItem) itemImpl, provider.getDisplayName());
                    updateEl = Trampoline.API.createUpdateElement(impl);
                }
            } else if (itemImpl instanceof LocalizationItem) {
                updateEl = Trampoline.API.createUpdateElement(new LocalizationUpdateElementImpl((LocalizationItem) itemImpl, provider.getDisplayName()));
            } else if (itemImpl instanceof NativeComponentItem) {
                updateEl = Trampoline.API.createUpdateElement(new NativeComponentUpdateElementImpl((NativeComponentItem) itemImpl, provider.getDisplayName()));
            } else if (itemImpl instanceof FeatureItem) {
                FeatureUpdateElementImpl impl = new FeatureUpdateElementImpl.Agent((FeatureItem) itemImpl, provider.getDisplayName(), UpdateManager.TYPE.FEATURE);
                updateEl = Trampoline.API.createUpdateElement(impl);
            } else {
                assert false : "Unknown type of UpdateElement " + updateEl;
            }
        } catch (IllegalArgumentException iae) {
            log.log(Level.INFO, iae.getLocalizedMessage(), iae);
        }
        // add element to map
        if (updateEl != null) {
            Trampoline.API.impl(updateEl).setCatalogTrusted(trusted);
            addElement(originalUnits, updateEl, provider);
        }
    }
    return originalUnits;
}
Also used : UpdateElement(org.netbeans.api.autoupdate.UpdateElement) FeatureItem(org.netbeans.modules.autoupdate.updateprovider.FeatureItem) NativeComponentItem(org.netbeans.modules.autoupdate.updateprovider.NativeComponentItem) IOException(java.io.IOException) InstalledModuleItem(org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem) ModuleItem(org.netbeans.modules.autoupdate.updateprovider.ModuleItem) UpdateItemImpl(org.netbeans.modules.autoupdate.updateprovider.UpdateItemImpl) UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) ModuleInfo(org.openide.modules.ModuleInfo) LocalizationItem(org.netbeans.modules.autoupdate.updateprovider.LocalizationItem) InstalledModuleItem(org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem)

Example 2 with FeatureItem

use of org.netbeans.modules.autoupdate.updateprovider.FeatureItem in project netbeans-rcp-lite by outersky.

the class FeatureUpdateUnitImpl method initializeFeature.

private void initializeFeature() {
    if (initialized) {
        return;
    }
    List<UpdateElement> featureElements = getUpdates();
    installedElement = null;
    updateElement = null;
    UpdateElement installedFeatureElement = null;
    FeatureUpdateElementImpl featureImpl = null;
    Set<ModuleUpdateElementImpl> installedModules = new HashSet<ModuleUpdateElementImpl>();
    Set<FeatureUpdateElementImpl> installedFeatures = new HashSet<FeatureUpdateElementImpl>();
    Set<ModuleUpdateElementImpl> availableModules = new HashSet<ModuleUpdateElementImpl>();
    Set<FeatureUpdateElementImpl> availableFeatures = new HashSet<FeatureUpdateElementImpl>();
    Set<ModuleUpdateElementImpl> missingModules = new HashSet<ModuleUpdateElementImpl>();
    Set<FeatureUpdateElementImpl> missingFeatures = new HashSet<FeatureUpdateElementImpl>();
    assert featureElements != null : "FeatureUpdateUnitImpl " + getCodeName() + " contains some available elements.";
    for (UpdateElement el : featureElements) {
        featureImpl = (FeatureUpdateElementImpl) Trampoline.API.impl(el);
        boolean installed = false;
        for (ModuleUpdateElementImpl moduleImpl : featureImpl.getContainedModuleElements()) {
            installed |= moduleImpl.getUpdateUnit().getInstalled() != null;
            UpdateElement iue = moduleImpl.getUpdateUnit().getInstalled();
            UpdateElementImpl iuei = iue == null ? null : Trampoline.API.impl(iue);
            assert iuei == null || iuei instanceof ModuleUpdateElementImpl : "Impl of " + iue + " is instanceof ModuleUpdateElementImpl";
            if (iue != null) {
                installedModules.add((ModuleUpdateElementImpl) iuei);
            } else {
                LOG.log(Level.FINER, this.getCodeName() + " misses required module " + moduleImpl.getUpdateElement());
                missingModules.add(moduleImpl);
            }
            if (!moduleImpl.getUpdateUnit().getAvailableUpdates().isEmpty()) {
                UpdateElement aue = moduleImpl.getUpdateUnit().getAvailableUpdates().get(0);
                UpdateElementImpl auei = Trampoline.API.impl(aue);
                assert auei instanceof ModuleUpdateElementImpl : "Impl of " + aue + " is instanceof ModuleUpdateElementImpl";
                availableModules.add((ModuleUpdateElementImpl) auei);
                LOG.log(Level.FINER, this + " has a update of module " + moduleImpl.getUpdateElement() + " to " + auei.getUpdateElement());
            }
        }
        for (FeatureUpdateElementImpl dependingFeatureImpl : featureImpl.getDependingFeatures()) {
            installed |= dependingFeatureImpl.getUpdateUnit().getInstalled() != null;
            UpdateElement iue = dependingFeatureImpl.getUpdateUnit().getInstalled();
            UpdateElementImpl iuei = iue == null ? null : Trampoline.API.impl(iue);
            assert iuei == null || iuei instanceof FeatureUpdateElementImpl : "Impl of " + iue + " is instanceof FeatureUpdateElementImpl";
            if (iuei != null) {
                installedFeatures.add((FeatureUpdateElementImpl) iuei);
            } else {
                LOG.log(Level.FINER, this.getCodeName() + " misses required module " + featureImpl.getUpdateElement());
                missingFeatures.add(featureImpl);
            }
            if (!dependingFeatureImpl.getUpdateUnit().getAvailableUpdates().isEmpty()) {
                UpdateElement aue = dependingFeatureImpl.getUpdateUnit().getAvailableUpdates().get(0);
                UpdateElementImpl auei = Trampoline.API.impl(aue);
                assert auei instanceof FeatureUpdateElementImpl : "Impl of " + aue + " is instanceof FeatureUpdateElementImpl";
                availableFeatures.add((FeatureUpdateElementImpl) auei);
                LOG.log(Level.FINER, this + " has a update of feature " + dependingFeatureImpl.getUpdateElement() + " to " + auei.getUpdateElement());
            }
        }
        if (installed) {
            installedFeatureElement = el;
        }
    }
    boolean isStandalone = UpdateManager.TYPE.STANDALONE_MODULE == getType();
    // if some element is whole installed
    if (installedFeatureElement != null) {
        // create new one element contains all installed modules
        FeatureItem item = ArtificialFeaturesProvider.createFeatureItem(getCodeName(), installedModules, installedFeatures, featureImpl, isStandalone ? null : presentAddionallyDescription(installedModules, presentMissingModules(missingModules)));
        FeatureUpdateElementImpl featureElementImpl = new FeatureUpdateElementImpl(item, installedFeatureElement.getSource(), installedModules, installedFeatures, ((FeatureUpdateElementImpl) Trampoline.API.impl(installedFeatureElement)).getMissingElements(), featureImpl.getType());
        installedElement = Trampoline.API.createUpdateElement(featureElementImpl);
        featureElementImpl.setUpdateUnit(installedFeatureElement.getUpdateUnit());
    }
    // add also new update element
    if (!featureElements.isEmpty()) {
        if (!availableModules.isEmpty() || !availableFeatures.isEmpty()) {
            // add available modules or features to missing
            missingModules.addAll(availableModules);
            FeatureItem item = ArtificialFeaturesProvider.createFeatureItem(getCodeName(), availableModules, availableFeatures, featureImpl, isStandalone ? null : presentAddionallyDescription(presentUpdatableModules(/* XXX */
            missingModules), installedModules));
            FeatureUpdateElementImpl featureElementImpl = new FeatureUpdateElementImpl(item, featureElements.get(0).getSource(), availableModules, availableFeatures, null, featureImpl.getType());
            updateElement = Trampoline.API.createUpdateElement(featureElementImpl);
            featureElementImpl.setUpdateUnit(featureElements.get(0).getUpdateUnit());
            addUpdate(updateElement);
        }
    }
    initialized = true;
}
Also used : UpdateElement(org.netbeans.api.autoupdate.UpdateElement) FeatureItem(org.netbeans.modules.autoupdate.updateprovider.FeatureItem) HashSet(java.util.HashSet)

Aggregations

UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 FeatureItem (org.netbeans.modules.autoupdate.updateprovider.FeatureItem)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 InstalledModuleItem (org.netbeans.modules.autoupdate.updateprovider.InstalledModuleItem)1 LocalizationItem (org.netbeans.modules.autoupdate.updateprovider.LocalizationItem)1 ModuleItem (org.netbeans.modules.autoupdate.updateprovider.ModuleItem)1 NativeComponentItem (org.netbeans.modules.autoupdate.updateprovider.NativeComponentItem)1 UpdateItemImpl (org.netbeans.modules.autoupdate.updateprovider.UpdateItemImpl)1 UpdateItem (org.netbeans.spi.autoupdate.UpdateItem)1 ModuleInfo (org.openide.modules.ModuleInfo)1