From: Mathieu Baudier Date: Tue, 17 Jul 2012 12:34:30 +0000 (+0000) Subject: Move to Commons Base X-Git-Tag: argeo-commons-2.1.30~879 X-Git-Url: https://git.argeo.org/?a=commitdiff_plain;h=7611aca758f48999a53b0b5a18ece2b1cd343216;p=lgpl%2Fargeo-commons.git Move to Commons Base git-svn-id: https://svn.argeo.org/commons/trunk@5483 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/base/plugins/org.argeo.osgi.ui.explorer/.classpath b/base/plugins/org.argeo.osgi.ui.explorer/.classpath new file mode 100644 index 000000000..c5931a083 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/.classpath @@ -0,0 +1,7 @@ + + + >> + + + + diff --git a/base/plugins/org.argeo.osgi.ui.explorer/.project b/base/plugins/org.argeo.osgi.ui.explorer/.project new file mode 100644 index 000000000..1a4f4d3bd --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/.project @@ -0,0 +1,28 @@ + + + org.argeo.osgi.ui.explorer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/base/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs b/base/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..9916a2282 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sun Sep 04 16:04:00 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/base/plugins/org.argeo.osgi.ui.explorer/build.properties b/base/plugins/org.argeo.osgi.ui.explorer/build.properties new file mode 100644 index 000000000..4f799f2d3 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/build.properties @@ -0,0 +1,6 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + .,\ + icons/,\ + plugin.xml diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/active.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/active.gif new file mode 100644 index 000000000..7d24707ee Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/active.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif new file mode 100644 index 000000000..e9a6bd966 Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif new file mode 100644 index 000000000..298871653 Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif new file mode 100644 index 000000000..e9a6bd966 Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif new file mode 100644 index 000000000..f4a1ea150 Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif b/base/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif new file mode 100644 index 000000000..563743d39 Binary files /dev/null and b/base/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif differ diff --git a/base/plugins/org.argeo.osgi.ui.explorer/plugin.xml b/base/plugins/org.argeo.osgi.ui.explorer/plugin.xml new file mode 100644 index 000000000..848025bbd --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/plugin.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/base/plugins/org.argeo.osgi.ui.explorer/pom.xml b/base/plugins/org.argeo.osgi.ui.explorer/pom.xml new file mode 100644 index 000000000..c41870960 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + + org.argeo.commons.osgi + 1.1.4-SNAPSHOT + plugins + .. + + org.argeo.osgi.ui.explorer + Commons OSGi Explorer + + + + org.apache.felix + maven-bundle-plugin + + + lazy + org.argeo.osgi.ui.explorer.OsgiExplorerPlugin + org.eclipse.ui;resolution:=optional, + org.eclipse.rap.ui;resolution:=optional, + org.eclipse.core.runtime + org.argeo.osgi.ui.explorer.* + + + + + + + + org.argeo.tp + org.eclipse.osgi + + + + org.argeo.commons.eclipse + org.argeo.eclipse.ui + 1.1.4-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rcp + 1.1.4-SNAPSHOT + provided + + + org.argeo.commons.eclipse + org.argeo.eclipse.ui.rcp + 1.1.4-SNAPSHOT + provided + + + diff --git a/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java new file mode 100644 index 000000000..8e3fae677 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.osgi.ui.explorer; + +import org.eclipse.swt.graphics.Image; + +/** Shared icons. */ +public class OsgiExplorerImages { + public final static Image INSTALLED = OsgiExplorerPlugin + .getImageDescriptor("icons/installed.gif").createImage(); + public final static Image RESOLVED = OsgiExplorerPlugin.getImageDescriptor( + "icons/resolved.gif").createImage(); + public final static Image STARTING = OsgiExplorerPlugin.getImageDescriptor( + "icons/starting.gif").createImage(); + public final static Image ACTIVE = OsgiExplorerPlugin.getImageDescriptor( + "icons/active.gif").createImage(); +} diff --git a/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java new file mode 100644 index 000000000..3b759b1e2 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.osgi.ui.explorer; + +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +/** OSGi explorer perspective (to be enriched declaratively) */ +public class OsgiExplorerPerspective implements IPerspectiveFactory { + + public void createInitialLayout(IPageLayout layout) { + layout.setEditorAreaVisible(true); + layout.setFixed(false); + + } + +} diff --git a/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java new file mode 100644 index 000000000..72bcd0c57 --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.osgi.ui.explorer; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class OsgiExplorerPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.argeo.osgi.ui.explorer"; //$NON-NLS-1$ + + // The shared instance + private static OsgiExplorerPlugin plugin; + + /** + * The constructor + */ + public OsgiExplorerPlugin() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static OsgiExplorerPlugin getDefault() { + return plugin; + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + +} diff --git a/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java new file mode 100644 index 000000000..3adb450ef --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.osgi.ui.explorer.views; + +import java.util.Comparator; + +import org.argeo.eclipse.ui.ColumnViewerComparator; +import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils; +import org.argeo.osgi.ui.explorer.OsgiExplorerImages; +import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; + +/** + * Overview of the bundles as a table. Equivalent to Equinox 'ss' console + * command. + */ +public class BundlesView extends ViewPart { + private TableViewer viewer; + + @Override + public void createPartControl(Composite parent) { + viewer = new TableViewer(parent); + viewer.setContentProvider(new BundleContentProvider()); + viewer.getTable().setHeaderVisible(true); + + EclipseUiSpecificUtils.enableToolTipSupport(viewer); + + // ID + TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); + column.getColumn().setWidth(30); + column.getColumn().setText("ID"); + column.getColumn().setAlignment(SWT.RIGHT); + column.setLabelProvider(new ColumnLabelProvider() { + public String getText(Object element) { + return Long.toString(((Bundle) element).getBundleId()); + } + }); + new ColumnViewerComparator(column, new Comparator() { + public int compare(Bundle o1, Bundle o2) { + return (int) (o1.getBundleId() - o2.getBundleId()); + } + }); + + // State + column = new TableViewerColumn(viewer, SWT.NONE); + column.getColumn().setWidth(18); + column.getColumn().setText("State"); + column.setLabelProvider(new StateLabelProvider()); + new ColumnViewerComparator(column, new Comparator() { + public int compare(Bundle o1, Bundle o2) { + return o1.getState() - o2.getState(); + } + }); + + // Symbolic name + column = new TableViewerColumn(viewer, SWT.NONE); + column.getColumn().setWidth(300); + column.getColumn().setText("Symbolic Name"); + column.setLabelProvider(new ColumnLabelProvider() { + public String getText(Object element) { + return ((Bundle) element).getSymbolicName(); + } + }); + new ColumnViewerComparator(column, new Comparator() { + public int compare(Bundle o1, Bundle o2) { + return o1.getSymbolicName().compareTo(o2.getSymbolicName()); + } + }); + + // Version + column = new TableViewerColumn(viewer, SWT.NONE); + column.getColumn().setWidth(150); + column.getColumn().setText("Version"); + column.setLabelProvider(new ColumnLabelProvider() { + public String getText(Object element) { + return ((Bundle) element).getVersion().toString(); + } + }); + new ColumnViewerComparator(column, new Comparator() { + public int compare(Bundle o1, Bundle o2) { + return o1.getVersion().compareTo(o2.getVersion()); + } + }); + + viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle() + .getBundleContext()); + + } + + @Override + public void setFocus() { + if (viewer != null) + viewer.getControl().setFocus(); + } + + /** Content provider managing the array of bundles */ + private static class BundleContentProvider implements + IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + if (inputElement instanceof BundleContext) { + BundleContext bc = (BundleContext) inputElement; + return bc.getBundles(); + } + return null; + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + /** Label provider for the state column */ + private static class StateLabelProvider extends ColumnLabelProvider { + @Override + public Image getImage(Object element) { + Integer state = ((Bundle) element).getState(); + switch (state) { + case Bundle.UNINSTALLED: + return OsgiExplorerImages.INSTALLED; + case Bundle.INSTALLED: + return OsgiExplorerImages.INSTALLED; + case Bundle.RESOLVED: + return OsgiExplorerImages.RESOLVED; + case Bundle.STARTING: + return OsgiExplorerImages.STARTING; + case Bundle.STOPPING: + return OsgiExplorerImages.STARTING; + case Bundle.ACTIVE: + return OsgiExplorerImages.ACTIVE; + default: + return null; + } + } + + @Override + public String getText(Object element) { + return null; + } + + @Override + public String getToolTipText(Object element) { + Bundle bundle = (Bundle) element; + Integer state = bundle.getState(); + switch (state) { + case Bundle.UNINSTALLED: + return "UNINSTALLED"; + case Bundle.INSTALLED: + return "INSTALLED"; + case Bundle.RESOLVED: + return "RESOLVED"; + case Bundle.STARTING: + String activationPolicy = bundle.getHeaders() + .get(Constants.BUNDLE_ACTIVATIONPOLICY).toString(); + if (activationPolicy != null + && activationPolicy.equals(Constants.ACTIVATION_LAZY)) + return "<>"; + return "STARTING"; + case Bundle.STOPPING: + return "STOPPING"; + case Bundle.ACTIVE: + return "ACTIVE"; + default: + return null; + } + } + + } +} diff --git a/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java new file mode 100644 index 000000000..ba7d816ca --- /dev/null +++ b/base/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java @@ -0,0 +1,379 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.argeo.osgi.ui.explorer.views; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.eclipse.ui.TreeParent; +import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; + +/** Experimental The OSGi runtime from a module perspective. */ +public class ModulesView extends ViewPart { + private final static Log log = LogFactory.getLog(ModulesView.class); + + private TreeViewer viewer; + + private PackageAdmin packageAdmin; + + private Comparator exportedPackageComparator = new Comparator() { + + public int compare(ExportedPackage o1, ExportedPackage o2) { + if (!o1.getName().equals(o2.getName())) + return o1.getName().compareTo(o2.getName()); + else + return o1.getVersion().compareTo(o2.getVersion()); + } + }; + + @Override + public void createPartControl(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new ModulesContentProvider()); + viewer.setLabelProvider(new ModulesLabelProvider()); + viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle() + .getBundleContext()); + } + + @Override + public void setFocus() { + viewer.getTree().setFocus(); + } + + private class ModulesContentProvider implements ITreeContentProvider { + + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof BundleContext) { + BundleContext bundleContext = (BundleContext) parentElement; + Bundle[] bundles = bundleContext.getBundles(); + + TreeParent bundlesNode = new TreeParent("Bundles"); + for (Bundle bundle : bundles) { + if (bundle.getState() == Bundle.ACTIVE) + bundlesNode.addChild(new BundleNode(bundle)); + } + + // scan packages + ServiceReference paSr = bundleContext + .getServiceReference(PackageAdmin.class.getName()); + // TODO: make a cleaner referencing + packageAdmin = (PackageAdmin) bundleContext.getService(paSr); + + Bundle bundle1 = null; + Bundle bundle2 = null; + + Map> importedPackages = new HashMap>(); + Map> packages = new TreeMap>(); + for (Bundle bundle : bundles) { + if (bundle.getSymbolicName() + .equals("org.argeo.security.ui")) + bundle1 = bundle; + if (bundle.getSymbolicName().equals( + "org.argeo.security.equinox")) + bundle2 = bundle; + + ExportedPackage[] pkgs = packageAdmin + .getExportedPackages(bundle); + if (pkgs != null) + for (ExportedPackage pkg : pkgs) { + if (!packages.containsKey(pkg.getName())) + packages.put(pkg.getName(), + new TreeSet( + exportedPackageComparator)); + Set expPackages = (Set) packages + .get(pkg.getName()); + expPackages.add(pkg); + + // imported + for (Bundle b : pkg.getImportingBundles()) { + if (bundle.getBundleId() != b.getBundleId()) { + if (!importedPackages.containsKey(b)) + importedPackages + .put(b, + new TreeSet( + exportedPackageComparator)); + Set impPackages = (Set) importedPackages + .get(b); + impPackages.add(pkg); + } + } + } + } + + TreeParent mPackageNode = new TreeParent("Multiple Packages"); + // TreeParent aPackageNode = new TreeParent("All Packages"); + for (String packageName : packages.keySet()) { + Set pkgs = packages.get(packageName); + if (pkgs.size() > 1) { + MultiplePackagesNode mpn = new MultiplePackagesNode( + packageName, pkgs); + mPackageNode.addChild(mpn); + // aPackageNode.addChild(mpn); + } else { + // aPackageNode.addChild(new ExportedPackageNode(pkgs + // .iterator().next())); + } + } + + return new Object[] { bundlesNode, mPackageNode };// , + // aPackageNode + // }; + } else if (parentElement instanceof TreeParent) { + return ((TreeParent) parentElement).getChildren(); + } else { + return null; + } + } + + public Object getParent(Object element) { + // TODO Auto-generated method stub + return null; + } + + public boolean hasChildren(Object element) { + if (element instanceof TreeParent) { + return ((TreeParent) element).hasChildren(); + } + return false; + } + + public void dispose() { + // TODO Auto-generated method stub + + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + + } + + } + + protected Map dependencySpace(Bundle bundle, + Map> importedPackages, + Map> traces) { + log.debug("Dependency space for " + bundle.getSymbolicName()); + Map space = new TreeMap(); + fillDependencySpace(space, bundle, importedPackages, + bundle.getSymbolicName(), traces); + return space; + } + + /** Recursive */ + protected void fillDependencySpace(Map space, + Bundle bundle, Map> importedPackages, + String currTrace, Map> traces) { + if (importedPackages.containsKey(bundle)) { + Set imports = importedPackages.get(bundle); + // log.debug("## Fill dependency space for " + bundle + " : "); + for (ExportedPackage pkg : imports) { + if (!traces.containsKey(pkg.getName())) + traces.put(pkg.getName(), new TreeSet()); + traces.get(pkg.getName()).add(currTrace); + if (!space.containsKey(pkg.getName())) { + space.put(pkg.getName(), pkg); + Bundle exportingBundle = pkg.getExportingBundle(); + // if (bundle.getBundleId() != + // exportingBundle.getBundleId()) + fillDependencySpace(space, exportingBundle, + importedPackages, currTrace + " > " + + exportingBundle.getSymbolicName(), traces); + } + } + } + } + + private class ModulesLabelProvider extends LabelProvider implements + ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + public String getColumnText(Object element, int columnIndex) { + return getText(element); + } + + } + + class BundleNode extends TreeParent { + private final Bundle bundle; + + public BundleNode(Bundle bundle) { + super(bundle.getSymbolicName()); + this.bundle = bundle; + + // Registered services + ServiceReference[] registeredServices = bundle + .getRegisteredServices(); + if (registeredServices != null) { + TreeParent registeredServicesNode = new TreeParent( + "Registered Services"); + addChild(registeredServicesNode); + for (ServiceReference sr : registeredServices) { + if (sr != null) + registeredServicesNode + .addChild(new ServiceReferenceNode(sr)); + } + } + + // Used services + ServiceReference[] usedServices = bundle.getRegisteredServices(); + if (usedServices != null) { + TreeParent usedServicesNode = new TreeParent("Used Services"); + addChild(usedServicesNode); + for (ServiceReference sr : usedServices) { + if (sr != null) + usedServicesNode.addChild(new ServiceReferenceNode(sr)); + } + } + } + + public Bundle getBundle() { + return bundle; + } + + } + + class ServiceReferenceNode extends TreeParent { + private final ServiceReference serviceReference; + + public ServiceReferenceNode(ServiceReference serviceReference) { + super(serviceReference.toString()); + this.serviceReference = serviceReference; + + Bundle[] usedBundles = serviceReference.getUsingBundles(); + if (usedBundles != null) { + TreeParent usingBundles = new TreeParent("Using Bundles"); + addChild(usingBundles); + for (Bundle b : usedBundles) { + if (b != null) + usingBundles.addChild(new TreeParent(b + .getSymbolicName())); + } + } + + TreeParent properties = new TreeParent("Properties"); + addChild(properties); + for (String key : serviceReference.getPropertyKeys()) { + properties.addChild(new TreeParent(key + "=" + + serviceReference.getProperty(key))); + } + + } + + public ServiceReference getServiceReference() { + return serviceReference; + } + + } + + class MultiplePackagesNode extends TreeParent { + private String packageName; + private Set exportedPackages; + + public MultiplePackagesNode(String packageName, + Set exportedPackages) { + super(packageName); + this.packageName = packageName; + this.exportedPackages = exportedPackages; + for (ExportedPackage pkg : exportedPackages) { + addChild(new ExportedPackageNode(pkg)); + } + } + + } + + class ConflictingPackageNode extends TreeParent { + private ExportedPackage exportedPackage; + + public ConflictingPackageNode(ExportedPackage exportedPackage) { + super(exportedPackage.getName() + " - " + + exportedPackage.getVersion() + " (" + + exportedPackage.getExportingBundle() + ")"); + this.exportedPackage = exportedPackage; + + TreeParent bundlesNode = new TreeParent("Dependent Bundles"); + this.addChild(bundlesNode); + Map bundles = new TreeMap(); + for (Bundle b : exportedPackage.getImportingBundles()) { + bundles.put(b.getSymbolicName(), b); + } + for (String key : bundles.keySet()) { + addDependentBundles(bundlesNode, bundles.get(key)); + } + } + } + + protected void addDependentBundles(TreeParent parent, Bundle bundle) { + TreeParent bundleNode = new TreeParent(bundle.toString()); + parent.addChild(bundleNode); + Map bundles = new TreeMap(); + ExportedPackage[] pkgs = packageAdmin.getExportedPackages(bundle); + if (pkgs != null) + for (ExportedPackage pkg : pkgs) { + for (Bundle b : pkg.getImportingBundles()) { + if (!bundles.containsKey(b.getSymbolicName()) + && b.getBundleId() != bundle.getBundleId()) { + bundles.put(b.getSymbolicName(), b); + } + } + } + + for (String key : bundles.keySet()) { + addDependentBundles(bundleNode, bundles.get(key)); + } + } + + class ExportedPackageNode extends TreeParent { + private ExportedPackage exportedPackage; + + public ExportedPackageNode(ExportedPackage exportedPackage) { + super(exportedPackage.getName() + " - " + + exportedPackage.getVersion() + " (" + + exportedPackage.getExportingBundle() + ")"); + this.exportedPackage = exportedPackage; + for (Bundle bundle : exportedPackage.getImportingBundles()) { + addChild(new BundleNode(bundle)); + } + } + } +} diff --git a/base/plugins/pom.xml b/base/plugins/pom.xml new file mode 100644 index 000000000..01d9d0a06 --- /dev/null +++ b/base/plugins/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + + org.argeo.commons + 1.1.4-SNAPSHOT + osgi + .. + + org.argeo.commons.osgi + plugins + Commons OSGi Eclipse Plugins + pom + + org.argeo.osgi.ui.explorer + + + + + src/main/resources + + + . + + plugin.xml + META-INF/** + icons/** + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + + plugin.xml + META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId};singleton:=true + + + + + + diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.classpath b/osgi/plugins/org.argeo.osgi.ui.explorer/.classpath deleted file mode 100644 index c5931a083..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - >> - - - - diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.project b/osgi/plugins/org.argeo.osgi.ui.explorer/.project deleted file mode 100644 index 1a4f4d3bd..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.osgi.ui.explorer - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs b/osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 9916a2282..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Sun Sep 04 16:04:00 CEST 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/build.properties b/osgi/plugins/org.argeo.osgi.ui.explorer/build.properties deleted file mode 100644 index 4f799f2d3..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/build.properties +++ /dev/null @@ -1,6 +0,0 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = META-INF/,\ - .,\ - icons/,\ - plugin.xml diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif deleted file mode 100644 index 7d24707ee..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/active.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif deleted file mode 100644 index e9a6bd966..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/bundles.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif deleted file mode 100644 index 298871653..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/installed.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif deleted file mode 100644 index e9a6bd966..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/osgi_explorer.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif deleted file mode 100644 index f4a1ea150..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/resolved.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif b/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif deleted file mode 100644 index 563743d39..000000000 Binary files a/osgi/plugins/org.argeo.osgi.ui.explorer/icons/starting.gif and /dev/null differ diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml b/osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml deleted file mode 100644 index 848025bbd..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/plugin.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/pom.xml b/osgi/plugins/org.argeo.osgi.ui.explorer/pom.xml deleted file mode 100644 index c41870960..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - 4.0.0 - - org.argeo.commons.osgi - 1.1.4-SNAPSHOT - plugins - .. - - org.argeo.osgi.ui.explorer - Commons OSGi Explorer - - - - org.apache.felix - maven-bundle-plugin - - - lazy - org.argeo.osgi.ui.explorer.OsgiExplorerPlugin - org.eclipse.ui;resolution:=optional, - org.eclipse.rap.ui;resolution:=optional, - org.eclipse.core.runtime - org.argeo.osgi.ui.explorer.* - - - - - - - - org.argeo.tp - org.eclipse.osgi - - - - org.argeo.commons.eclipse - org.argeo.eclipse.ui - 1.1.4-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rcp - 1.1.4-SNAPSHOT - provided - - - org.argeo.commons.eclipse - org.argeo.eclipse.ui.rcp - 1.1.4-SNAPSHOT - provided - - - diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java deleted file mode 100644 index 8e3fae677..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerImages.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.osgi.ui.explorer; - -import org.eclipse.swt.graphics.Image; - -/** Shared icons. */ -public class OsgiExplorerImages { - public final static Image INSTALLED = OsgiExplorerPlugin - .getImageDescriptor("icons/installed.gif").createImage(); - public final static Image RESOLVED = OsgiExplorerPlugin.getImageDescriptor( - "icons/resolved.gif").createImage(); - public final static Image STARTING = OsgiExplorerPlugin.getImageDescriptor( - "icons/starting.gif").createImage(); - public final static Image ACTIVE = OsgiExplorerPlugin.getImageDescriptor( - "icons/active.gif").createImage(); -} diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java deleted file mode 100644 index 3b759b1e2..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPerspective.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.osgi.ui.explorer; - -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; - -/** OSGi explorer perspective (to be enriched declaratively) */ -public class OsgiExplorerPerspective implements IPerspectiveFactory { - - public void createInitialLayout(IPageLayout layout) { - layout.setEditorAreaVisible(true); - layout.setFixed(false); - - } - -} diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java deleted file mode 100644 index 72bcd0c57..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/OsgiExplorerPlugin.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.osgi.ui.explorer; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class OsgiExplorerPlugin extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.argeo.osgi.ui.explorer"; //$NON-NLS-1$ - - // The shared instance - private static OsgiExplorerPlugin plugin; - - /** - * The constructor - */ - public OsgiExplorerPlugin() { - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext - * ) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext - * ) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static OsgiExplorerPlugin getDefault() { - return plugin; - } - - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } - -} diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java deleted file mode 100644 index 3adb450ef..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/BundlesView.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.osgi.ui.explorer.views; - -import java.util.Comparator; - -import org.argeo.eclipse.ui.ColumnViewerComparator; -import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils; -import org.argeo.osgi.ui.explorer.OsgiExplorerImages; -import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.ViewPart; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; - -/** - * Overview of the bundles as a table. Equivalent to Equinox 'ss' console - * command. - */ -public class BundlesView extends ViewPart { - private TableViewer viewer; - - @Override - public void createPartControl(Composite parent) { - viewer = new TableViewer(parent); - viewer.setContentProvider(new BundleContentProvider()); - viewer.getTable().setHeaderVisible(true); - - EclipseUiSpecificUtils.enableToolTipSupport(viewer); - - // ID - TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); - column.getColumn().setWidth(30); - column.getColumn().setText("ID"); - column.getColumn().setAlignment(SWT.RIGHT); - column.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - return Long.toString(((Bundle) element).getBundleId()); - } - }); - new ColumnViewerComparator(column, new Comparator() { - public int compare(Bundle o1, Bundle o2) { - return (int) (o1.getBundleId() - o2.getBundleId()); - } - }); - - // State - column = new TableViewerColumn(viewer, SWT.NONE); - column.getColumn().setWidth(18); - column.getColumn().setText("State"); - column.setLabelProvider(new StateLabelProvider()); - new ColumnViewerComparator(column, new Comparator() { - public int compare(Bundle o1, Bundle o2) { - return o1.getState() - o2.getState(); - } - }); - - // Symbolic name - column = new TableViewerColumn(viewer, SWT.NONE); - column.getColumn().setWidth(300); - column.getColumn().setText("Symbolic Name"); - column.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - return ((Bundle) element).getSymbolicName(); - } - }); - new ColumnViewerComparator(column, new Comparator() { - public int compare(Bundle o1, Bundle o2) { - return o1.getSymbolicName().compareTo(o2.getSymbolicName()); - } - }); - - // Version - column = new TableViewerColumn(viewer, SWT.NONE); - column.getColumn().setWidth(150); - column.getColumn().setText("Version"); - column.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - return ((Bundle) element).getVersion().toString(); - } - }); - new ColumnViewerComparator(column, new Comparator() { - public int compare(Bundle o1, Bundle o2) { - return o1.getVersion().compareTo(o2.getVersion()); - } - }); - - viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle() - .getBundleContext()); - - } - - @Override - public void setFocus() { - if (viewer != null) - viewer.getControl().setFocus(); - } - - /** Content provider managing the array of bundles */ - private static class BundleContentProvider implements - IStructuredContentProvider { - public Object[] getElements(Object inputElement) { - if (inputElement instanceof BundleContext) { - BundleContext bc = (BundleContext) inputElement; - return bc.getBundles(); - } - return null; - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - } - - /** Label provider for the state column */ - private static class StateLabelProvider extends ColumnLabelProvider { - @Override - public Image getImage(Object element) { - Integer state = ((Bundle) element).getState(); - switch (state) { - case Bundle.UNINSTALLED: - return OsgiExplorerImages.INSTALLED; - case Bundle.INSTALLED: - return OsgiExplorerImages.INSTALLED; - case Bundle.RESOLVED: - return OsgiExplorerImages.RESOLVED; - case Bundle.STARTING: - return OsgiExplorerImages.STARTING; - case Bundle.STOPPING: - return OsgiExplorerImages.STARTING; - case Bundle.ACTIVE: - return OsgiExplorerImages.ACTIVE; - default: - return null; - } - } - - @Override - public String getText(Object element) { - return null; - } - - @Override - public String getToolTipText(Object element) { - Bundle bundle = (Bundle) element; - Integer state = bundle.getState(); - switch (state) { - case Bundle.UNINSTALLED: - return "UNINSTALLED"; - case Bundle.INSTALLED: - return "INSTALLED"; - case Bundle.RESOLVED: - return "RESOLVED"; - case Bundle.STARTING: - String activationPolicy = bundle.getHeaders() - .get(Constants.BUNDLE_ACTIVATIONPOLICY).toString(); - if (activationPolicy != null - && activationPolicy.equals(Constants.ACTIVATION_LAZY)) - return "<>"; - return "STARTING"; - case Bundle.STOPPING: - return "STOPPING"; - case Bundle.ACTIVE: - return "ACTIVE"; - default: - return null; - } - } - - } -} diff --git a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java b/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java deleted file mode 100644 index ba7d816ca..000000000 --- a/osgi/plugins/org.argeo.osgi.ui.explorer/src/main/java/org/argeo/osgi/ui/explorer/views/ModulesView.java +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright (C) 2007-2012 Mathieu Baudier - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.osgi.ui.explorer.views; - -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.eclipse.ui.TreeParent; -import org.argeo.osgi.ui.explorer.OsgiExplorerPlugin; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.part.ViewPart; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.packageadmin.ExportedPackage; -import org.osgi.service.packageadmin.PackageAdmin; - -/** Experimental The OSGi runtime from a module perspective. */ -public class ModulesView extends ViewPart { - private final static Log log = LogFactory.getLog(ModulesView.class); - - private TreeViewer viewer; - - private PackageAdmin packageAdmin; - - private Comparator exportedPackageComparator = new Comparator() { - - public int compare(ExportedPackage o1, ExportedPackage o2) { - if (!o1.getName().equals(o2.getName())) - return o1.getName().compareTo(o2.getName()); - else - return o1.getVersion().compareTo(o2.getVersion()); - } - }; - - @Override - public void createPartControl(Composite parent) { - viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - viewer.setContentProvider(new ModulesContentProvider()); - viewer.setLabelProvider(new ModulesLabelProvider()); - viewer.setInput(OsgiExplorerPlugin.getDefault().getBundle() - .getBundleContext()); - } - - @Override - public void setFocus() { - viewer.getTree().setFocus(); - } - - private class ModulesContentProvider implements ITreeContentProvider { - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof BundleContext) { - BundleContext bundleContext = (BundleContext) parentElement; - Bundle[] bundles = bundleContext.getBundles(); - - TreeParent bundlesNode = new TreeParent("Bundles"); - for (Bundle bundle : bundles) { - if (bundle.getState() == Bundle.ACTIVE) - bundlesNode.addChild(new BundleNode(bundle)); - } - - // scan packages - ServiceReference paSr = bundleContext - .getServiceReference(PackageAdmin.class.getName()); - // TODO: make a cleaner referencing - packageAdmin = (PackageAdmin) bundleContext.getService(paSr); - - Bundle bundle1 = null; - Bundle bundle2 = null; - - Map> importedPackages = new HashMap>(); - Map> packages = new TreeMap>(); - for (Bundle bundle : bundles) { - if (bundle.getSymbolicName() - .equals("org.argeo.security.ui")) - bundle1 = bundle; - if (bundle.getSymbolicName().equals( - "org.argeo.security.equinox")) - bundle2 = bundle; - - ExportedPackage[] pkgs = packageAdmin - .getExportedPackages(bundle); - if (pkgs != null) - for (ExportedPackage pkg : pkgs) { - if (!packages.containsKey(pkg.getName())) - packages.put(pkg.getName(), - new TreeSet( - exportedPackageComparator)); - Set expPackages = (Set) packages - .get(pkg.getName()); - expPackages.add(pkg); - - // imported - for (Bundle b : pkg.getImportingBundles()) { - if (bundle.getBundleId() != b.getBundleId()) { - if (!importedPackages.containsKey(b)) - importedPackages - .put(b, - new TreeSet( - exportedPackageComparator)); - Set impPackages = (Set) importedPackages - .get(b); - impPackages.add(pkg); - } - } - } - } - - TreeParent mPackageNode = new TreeParent("Multiple Packages"); - // TreeParent aPackageNode = new TreeParent("All Packages"); - for (String packageName : packages.keySet()) { - Set pkgs = packages.get(packageName); - if (pkgs.size() > 1) { - MultiplePackagesNode mpn = new MultiplePackagesNode( - packageName, pkgs); - mPackageNode.addChild(mpn); - // aPackageNode.addChild(mpn); - } else { - // aPackageNode.addChild(new ExportedPackageNode(pkgs - // .iterator().next())); - } - } - - return new Object[] { bundlesNode, mPackageNode };// , - // aPackageNode - // }; - } else if (parentElement instanceof TreeParent) { - return ((TreeParent) parentElement).getChildren(); - } else { - return null; - } - } - - public Object getParent(Object element) { - // TODO Auto-generated method stub - return null; - } - - public boolean hasChildren(Object element) { - if (element instanceof TreeParent) { - return ((TreeParent) element).hasChildren(); - } - return false; - } - - public void dispose() { - // TODO Auto-generated method stub - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // TODO Auto-generated method stub - - } - - } - - protected Map dependencySpace(Bundle bundle, - Map> importedPackages, - Map> traces) { - log.debug("Dependency space for " + bundle.getSymbolicName()); - Map space = new TreeMap(); - fillDependencySpace(space, bundle, importedPackages, - bundle.getSymbolicName(), traces); - return space; - } - - /** Recursive */ - protected void fillDependencySpace(Map space, - Bundle bundle, Map> importedPackages, - String currTrace, Map> traces) { - if (importedPackages.containsKey(bundle)) { - Set imports = importedPackages.get(bundle); - // log.debug("## Fill dependency space for " + bundle + " : "); - for (ExportedPackage pkg : imports) { - if (!traces.containsKey(pkg.getName())) - traces.put(pkg.getName(), new TreeSet()); - traces.get(pkg.getName()).add(currTrace); - if (!space.containsKey(pkg.getName())) { - space.put(pkg.getName(), pkg); - Bundle exportingBundle = pkg.getExportingBundle(); - // if (bundle.getBundleId() != - // exportingBundle.getBundleId()) - fillDependencySpace(space, exportingBundle, - importedPackages, currTrace + " > " - + exportingBundle.getSymbolicName(), traces); - } - } - } - } - - private class ModulesLabelProvider extends LabelProvider implements - ITableLabelProvider { - - public Image getColumnImage(Object element, int columnIndex) { - // TODO Auto-generated method stub - return null; - } - - public String getColumnText(Object element, int columnIndex) { - return getText(element); - } - - } - - class BundleNode extends TreeParent { - private final Bundle bundle; - - public BundleNode(Bundle bundle) { - super(bundle.getSymbolicName()); - this.bundle = bundle; - - // Registered services - ServiceReference[] registeredServices = bundle - .getRegisteredServices(); - if (registeredServices != null) { - TreeParent registeredServicesNode = new TreeParent( - "Registered Services"); - addChild(registeredServicesNode); - for (ServiceReference sr : registeredServices) { - if (sr != null) - registeredServicesNode - .addChild(new ServiceReferenceNode(sr)); - } - } - - // Used services - ServiceReference[] usedServices = bundle.getRegisteredServices(); - if (usedServices != null) { - TreeParent usedServicesNode = new TreeParent("Used Services"); - addChild(usedServicesNode); - for (ServiceReference sr : usedServices) { - if (sr != null) - usedServicesNode.addChild(new ServiceReferenceNode(sr)); - } - } - } - - public Bundle getBundle() { - return bundle; - } - - } - - class ServiceReferenceNode extends TreeParent { - private final ServiceReference serviceReference; - - public ServiceReferenceNode(ServiceReference serviceReference) { - super(serviceReference.toString()); - this.serviceReference = serviceReference; - - Bundle[] usedBundles = serviceReference.getUsingBundles(); - if (usedBundles != null) { - TreeParent usingBundles = new TreeParent("Using Bundles"); - addChild(usingBundles); - for (Bundle b : usedBundles) { - if (b != null) - usingBundles.addChild(new TreeParent(b - .getSymbolicName())); - } - } - - TreeParent properties = new TreeParent("Properties"); - addChild(properties); - for (String key : serviceReference.getPropertyKeys()) { - properties.addChild(new TreeParent(key + "=" - + serviceReference.getProperty(key))); - } - - } - - public ServiceReference getServiceReference() { - return serviceReference; - } - - } - - class MultiplePackagesNode extends TreeParent { - private String packageName; - private Set exportedPackages; - - public MultiplePackagesNode(String packageName, - Set exportedPackages) { - super(packageName); - this.packageName = packageName; - this.exportedPackages = exportedPackages; - for (ExportedPackage pkg : exportedPackages) { - addChild(new ExportedPackageNode(pkg)); - } - } - - } - - class ConflictingPackageNode extends TreeParent { - private ExportedPackage exportedPackage; - - public ConflictingPackageNode(ExportedPackage exportedPackage) { - super(exportedPackage.getName() + " - " - + exportedPackage.getVersion() + " (" - + exportedPackage.getExportingBundle() + ")"); - this.exportedPackage = exportedPackage; - - TreeParent bundlesNode = new TreeParent("Dependent Bundles"); - this.addChild(bundlesNode); - Map bundles = new TreeMap(); - for (Bundle b : exportedPackage.getImportingBundles()) { - bundles.put(b.getSymbolicName(), b); - } - for (String key : bundles.keySet()) { - addDependentBundles(bundlesNode, bundles.get(key)); - } - } - } - - protected void addDependentBundles(TreeParent parent, Bundle bundle) { - TreeParent bundleNode = new TreeParent(bundle.toString()); - parent.addChild(bundleNode); - Map bundles = new TreeMap(); - ExportedPackage[] pkgs = packageAdmin.getExportedPackages(bundle); - if (pkgs != null) - for (ExportedPackage pkg : pkgs) { - for (Bundle b : pkg.getImportingBundles()) { - if (!bundles.containsKey(b.getSymbolicName()) - && b.getBundleId() != bundle.getBundleId()) { - bundles.put(b.getSymbolicName(), b); - } - } - } - - for (String key : bundles.keySet()) { - addDependentBundles(bundleNode, bundles.get(key)); - } - } - - class ExportedPackageNode extends TreeParent { - private ExportedPackage exportedPackage; - - public ExportedPackageNode(ExportedPackage exportedPackage) { - super(exportedPackage.getName() + " - " - + exportedPackage.getVersion() + " (" - + exportedPackage.getExportingBundle() + ")"); - this.exportedPackage = exportedPackage; - for (Bundle bundle : exportedPackage.getImportingBundles()) { - addChild(new BundleNode(bundle)); - } - } - } -} diff --git a/osgi/plugins/pom.xml b/osgi/plugins/pom.xml deleted file mode 100644 index 01d9d0a06..000000000 --- a/osgi/plugins/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - 4.0.0 - - org.argeo.commons - 1.1.4-SNAPSHOT - osgi - .. - - org.argeo.commons.osgi - plugins - Commons OSGi Eclipse Plugins - pom - - org.argeo.osgi.ui.explorer - - - - - src/main/resources - - - . - - plugin.xml - META-INF/** - icons/** - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - - plugin.xml - META-INF/MANIFEST.MF - - - - - org.apache.felix - maven-bundle-plugin - - - ${project.artifactId};singleton:=true - - - - - -