Search in sources :

Example 76 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project knime-core by knime.

the class WorkflowTableBackendSettings method saveSettingsTo.

void saveSettingsTo(final NodeSettingsWO settings) {
    if (!m_tableBackend.equals(TableBackendRegistry.getInstance().getPre43TableBackend())) {
        NodeSettingsWO tableBackendSettings = settings.addNodeSettings(CFG_TABLE_BACKEND);
        tableBackendSettings.addString(CFG_TABLE_BACKEND_CLASS, m_tableBackend.getClass().getName());
        Bundle bundle = OSGIHelper.getBundle(m_tableBackend.getClass());
        Optional<IInstallableUnit> feature = OSGIHelper.getFeature(bundle);
        tableBackendSettings.addString(CFG_TABLE_BACKEND_BUNDLE, bundle != null ? bundle.getSymbolicName() : null);
        tableBackendSettings.addString(CFG_TABLE_BACKEND_FEATURE, feature.map(IInstallableUnit::getId).orElse(null));
        tableBackendSettings.addString(CFG_TABLE_BACKEND_SHORTNAME, m_tableBackend.getShortName());
    }
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO) Bundle(org.osgi.framework.Bundle) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 77 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project knime-core by knime.

the class InstallMissingNodesJob method run.

@Override
protected IStatus run(final IProgressMonitor monitor) {
    List<NodeAndBundleInformation> missingNodes = m_missingNodes.stream().filter(distinctByKey(i -> i.getFactoryClass())).collect(Collectors.toList());
    Set<IInstallableUnit> featuresToInstall = new HashSet<>();
    IStatus status = findExtensions(monitor, missingNodes, featuresToInstall);
    if (!status.isOK()) {
        return status;
    } else if (featuresToInstall.isEmpty()) {
        Display.getDefault().asyncExec(() -> {
            MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "No suitable extension found", "Could not find any extension(s) that provides the missing node(s).");
        });
        return Status.OK_STATUS;
    } else {
        if (!missingNodes.isEmpty()) {
            Display.getDefault().syncExec(() -> {
                MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Not all extension found", "No extensions for the following nodes were found: " + missingNodes.stream().map(i -> i.getNodeNameNotNull()).collect(Collectors.joining(", ")));
            });
        }
        startInstallJob(featuresToInstall);
        return Status.OK_STATUS;
    }
}
Also used : NodeAndBundleInformation(org.knime.core.node.NodeAndBundleInformation) IStatus(org.eclipse.core.runtime.IStatus) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 78 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project webtools.servertools by eclipse.

the class ExtensionUtility method getExistingFeatures.

private static List<Extension> getExistingFeatures(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(Messages.discoverLocalConfiguration, 100);
    IProfileRegistry profileRegistry = (IProfileRegistry) getService(Activator.getDefault().getBundle().getBundleContext(), IProfileRegistry.class.getName());
    IProfile[] profiles = profileRegistry.getProfiles();
    IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
    if (profile == null) {
        // it happens sometime , possibility of bug in profileRegistry
        for (int i = 0; i < profiles.length; i++) {
            if (profiles[i].getProfileId().equals(IProfileRegistry.SELF)) {
                profile = profiles[i];
                break;
            }
        }
    }
    List<Extension> list = new ArrayList<Extension>();
    if (profile == null)
        return list;
    IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
    // Query query = new InstallableUnitQuery("org.eclipse.wst.server.core.serverAdapter");
    // List<String> list2 = new ArrayList();
    // Query query = new ExtensionInstallableUnitQuery(list2);
    IQueryResult<IInstallableUnit> collector = profile.query(query, monitor);
    Iterator<IInstallableUnit> iter = collector.iterator();
    while (iter.hasNext()) {
        IInstallableUnit iu = iter.next();
        if (!list.contains(iu))
            list.add(new Extension(iu, null));
    }
    monitor.done();
    return list;
}
Also used : IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Example 79 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project webtools.servertools by eclipse.

the class Extension method getProvisioningPlan.

public IProvisioningPlan getProvisioningPlan(boolean explain, IProgressMonitor monitor) {
    if (plan != null)
        return plan;
    // long time = System.currentTimeMillis();
    BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
    IPlanner planner = (IPlanner) ExtensionUtility.getService(bundleContext, IPlanner.SERVICE_NAME);
    IProfileRegistry profileRegistry = (IProfileRegistry) ExtensionUtility.getService(bundleContext, IProfileRegistry.SERVICE_NAME);
    IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
    IProfile[] profiles = profileRegistry.getProfiles();
    if (profile == null) {
        // it happens sometime , possibility of bug in profileRegistry
        for (int i = 0; i < profiles.length; i++) {
            if (profiles[i].getProfileId().equals(IProfileRegistry.SELF)) {
                profile = profiles[i];
                break;
            }
        }
    }
    if (profile == null)
        return null;
    IProfileChangeRequest pcr = planner.createChangeRequest(profile);
    pcr.add(iu);
    IProvisioningAgent agent = ExtensionUtility.getAgent(bundleContext);
    if (agent == null) {
        return null;
    }
    // Get all the known repositories when installing the server adapter.
    // If these repositories are not added, it can cause install problems if
    // the server adapter relies on the list of available software install sites
    URI[] knownRepositories = null;
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager != null) {
        manager.addRepository(uri);
        // Note: IRepositoryManager.REPOSITORIES_ALL will exclude the deselected update sites
        knownRepositories = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
        // A fall back in case known repositories returns null
        if (knownRepositories == null) {
            knownRepositories = new URI[] { uri };
        }
    } else {
        knownRepositories = new URI[] { uri };
    }
    provContext = new ProvisioningContext(agent);
    // Add the new URLs to both the Metadata and Artifact repositories.
    // Note: only the IInstallableUnit that is passed into this class will be installed
    // as a server adapter. For example, if multiple update site URLs for discovery server
    // adapters are present, they will not be installed.
    provContext.setMetadataRepositories(knownRepositories);
    provContext.setArtifactRepositories(knownRepositories);
    if (!explain)
        // $NON-NLS-1$ //$NON-NLS-2$
        provContext.setProperty("org.eclipse.equinox.p2.director.explain", "false");
    // $NON-NLS-1$
    provContext.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, "true");
    plan = planner.getProvisioningPlan(pcr, provContext, monitor);
    // System.out.println("Time: " + (System.currentTimeMillis() - time)); // TODO
    return plan;
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IPlanner(org.eclipse.equinox.p2.planner.IPlanner) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) URI(java.net.URI) BundleContext(org.osgi.framework.BundleContext)

Example 80 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project webtools.servertools by eclipse.

the class ExtensionUpdateSite method getExtensions.

public List<IServerExtension> getExtensions(IProgressMonitor monitor) throws CoreException, ProvisionException {
    URI url2 = null;
    IMetadataRepositoryManager manager = null;
    IProvisioningAgent agent = null;
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    URI[] existingSites = null;
    try {
        /*
			 * To discovery the server adapter, there are three methods:
			 * 1. Looking at the site.xml (if it exists). This is the legacy method
			 * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2
			 *    update site (that may not have a site.xml). The property is necessary to identify
			 *    the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show
			 *    up regardless of whether it is a server or not
			 * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml
			 *    to use category.xml)
			 */
        BundleContext bd = org.eclipse.wst.server.discovery.internal.Activator.getDefault().getBundle().getBundleContext();
        agent = ExtensionUtility.getAgent(bd);
        url2 = new URI(url);
        // Method 1: Looking at the site.xml
        UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory();
        mrf.setAgent(ExtensionUtility.getAgent(bd));
        manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        // Sites already existing for both enabled and disabled
        URI[] existingSitesAll = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
        URI[] existingSitesDisabled = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED);
        int existingSitesAllLen = existingSitesAll == null ? 0 : existingSitesAll.length;
        int existingSitesDisabledLen = existingSitesDisabled == null ? 0 : existingSitesDisabled.length;
        existingSites = new URI[existingSitesAllLen + existingSitesDisabledLen];
        if (existingSitesAllLen > 0) {
            System.arraycopy(existingSitesAll, 0, existingSites, 0, existingSitesAllLen);
        }
        if (existingSitesDisabledLen > 0) {
            System.arraycopy(existingSitesDisabled, 0, existingSites, existingSitesAllLen, existingSitesDisabledLen);
        }
        // If the site.xml does not exist, the load will throw a org.eclipse.equinox.p2.core.ProvisionException
        try {
            IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            list = getInstallableUnits(repo, query, url2, monitor);
        } catch (ProvisionException pe) {
            // $NON-NLS-1$
            Trace.trace(Trace.WARNING, "Error getting update site information", pe);
        }
        // specifying any server adapters there or no site.xml exists)
        if (list.isEmpty()) {
            manager.addRepository(url2);
            // Need to query for all IUs
            IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor);
            int size = list2.size();
            for (int i = 0; i < size; i++) {
                Extension e = (Extension) list2.get(i);
                IInstallableUnit[] iuArr = e.getIUs();
                if (iuArr != null && iuArr.length > 0) {
                    if (iuArr[0] != null) {
                        if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) {
                            list.add(e);
                        }
                    }
                }
            }
        }
        // a provider property with org.eclipse.wst.server.core.serverAdapter
        if (list.isEmpty()) {
            manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
            manager.addRepository(url2);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            list = getInstallableUnits(repo, query, url2, monitor);
        }
        return list;
    } catch (ProvisionException e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        throw e;
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        return new ArrayList<IServerExtension>(0);
    } finally {
        if (url2 != null && url2.getPath().length() != 0 && manager != null) {
            if (existingSites != null && existingSites.length > 0) {
                boolean urlExists = false;
                for (URI uri : existingSites) {
                    if (uri.getPath().equals(url2.getPath())) {
                        urlExists = true;
                        break;
                    }
                }
                // If site did not exist before, remove it as it was added with load
                if (!urlExists) {
                    manager.removeRepository(url2);
                }
            }
        }
    }
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) UpdateSiteMetadataRepositoryFactory(org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) BundleContext(org.osgi.framework.BundleContext)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)153 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)44 File (java.io.File)38 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)25 HashSet (java.util.HashSet)18 IStatus (org.eclipse.core.runtime.IStatus)18 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)16 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)11 CoreException (org.eclipse.core.runtime.CoreException)11 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)11 ResourceUtil.resourceFile (org.eclipse.tycho.p2.tools.test.util.ResourceUtil.resourceFile)11 URI (java.net.URI)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)9 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)9 Status (org.eclipse.core.runtime.Status)8 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8