use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.
the class P2Handler method getGroupInstallableUnits.
private Set<IInstallableUnit> getGroupInstallableUnits(URI uri, IProgressMonitor monitor) throws ProvisionException, OperationCanceledException {
IMetadataRepository metadataRepo = getMetadataRepositoryManager().loadRepository(uri, monitor);
// Works for feature and its contents
IQuery<IInstallableUnit> query = QueryUtil.createIUGroupQuery();
IQueryResult<IInstallableUnit> queryResult = metadataRepo.query(query, monitor);
return queryResult.toUnmodifiableSet();
}
use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.
the class P2Handler method getDefaultProfile.
private IProfile getDefaultProfile() throws ProvisionException {
IProfileRegistry service = (IProfileRegistry) getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
IProfile profile = service.getProfile(IProfileRegistry.SELF);
if (profile == null) {
// $NON-NLS-1$
throw new ProvisionException("Unable to access p2 profile - This is not possible when starting the application from the IDE!");
}
return profile;
}
use of org.eclipse.equinox.p2.core.ProvisionException in project archi by archimatetool.
the class P2PluginDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
setTitle(Messages.P2PluginDialog_1);
setMessage(Messages.P2PluginDialog_2);
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
container.setLayout(new GridLayout(1, false));
Composite tableComp = new Composite(container, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
tableComp.setLayout(layout);
GridData gd = new GridData(GridData.FILL_BOTH);
tableComp.setLayoutData(gd);
viewer = new TableViewer(tableComp, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(viewer.getTable());
viewer.getTable().setHeaderVisible(true);
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
column.getColumn().setText(Messages.P2PluginDialog_3);
column = new TableViewerColumn(viewer, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
column.getColumn().setText(Messages.P2PluginDialog_4);
column = new TableViewerColumn(viewer, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
column.getColumn().setText(Messages.P2PluginDialog_5);
column = new TableViewerColumn(viewer, SWT.NONE);
layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
column.getColumn().setText(Messages.P2PluginDialog_6);
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
try {
return P2Handler.getInstance().getInstalledFeatures().toArray();
} catch (ProvisionException ex) {
ex.printStackTrace();
}
return new Object[0];
}
});
class LabelCellProvider extends LabelProvider implements ITableLabelProvider {
@Override
public Image getColumnImage(Object element, int columnIndex) {
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof IInstallableUnit) {
IInstallableUnit iu = (IInstallableUnit) element;
switch(columnIndex) {
case 0:
return iu.getProperty(IInstallableUnit.PROP_NAME, null);
case 1:
return iu.getVersion().toString();
case 2:
return iu.getId();
case 3:
return iu.getProperty(IInstallableUnit.PROP_PROVIDER, null);
default:
break;
}
}
return element.toString();
}
}
viewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
IInstallableUnit u1 = (IInstallableUnit) e1;
IInstallableUnit u2 = (IInstallableUnit) e2;
return u1.getProperty(IInstallableUnit.PROP_NAME, null).compareToIgnoreCase(u2.getProperty(IInstallableUnit.PROP_NAME, null));
}
});
viewer.setLabelProvider(new LabelCellProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getButton(UNINSTALL).setEnabled(!event.getSelection().isEmpty());
}
});
// anything will do //$NON-NLS-1$
viewer.setInput("");
return area;
}
use of org.eclipse.equinox.p2.core.ProvisionException 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);
}
}
}
}
}
use of org.eclipse.equinox.p2.core.ProvisionException in project epp.mpc by eclipse.
the class AbstractProvisioningOperation method addRepositories.
protected List<IMetadataRepository> addRepositories(SubMonitor monitor) throws URISyntaxException, ProvisionException {
// tell p2 that it's okay to use these repositories
ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
RepositoryTracker repositoryTracker = ProvisioningUI.getDefaultUI().getRepositoryTracker();
repositoryLocations = new HashSet<URI>();
if (addedRepositoryLocations == null) {
addedRepositoryLocations = new HashSet<URI>();
}
Set<URI> knownRepositories = new HashSet<URI>(Arrays.asList(repositoryTracker.getKnownRepositories(session)));
monitor.setWorkRemaining(items.size() * 5);
for (CatalogItem descriptor : items) {
String siteUrl = descriptor.getSiteUrl();
if (siteUrl != null) {
URI uri = URLUtil.toURI(siteUrl);
if (repositoryLocations.add(uri) && !knownRepositories.contains(uri)) {
checkCancelled(monitor);
repositoryTracker.addRepository(uri, null, session);
addedRepositoryLocations.add(uri);
}
}
monitor.worked(1);
}
// fetch meta-data for these repositories
ArrayList<IMetadataRepository> repositories = new ArrayList<IMetadataRepository>();
monitor.setWorkRemaining(repositories.size());
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
for (URI uri : repositoryLocations) {
checkCancelled(monitor);
IMetadataRepository repository = manager.loadRepository(uri, monitor.newChild(1));
repositories.add(repository);
}
return repositories;
}
Aggregations