Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added the uninstalled bundles

  • Loading branch information...
commit 8e95fa5e6f4b097dedead3add3dcef27ed57c9d3 1 parent 43cd3f6
Antoine Toulme atoulme authored
1  .gitignore
View
@@ -0,0 +1 @@
+target
BIN  icons/obj16/refresh.gif
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2  src/main/java/org/intalio/eclipse/bundle/doctor/BundlePlugin.java
View
@@ -86,6 +86,8 @@ protected void initializeImageRegistry(ImageRegistry reg) {
imageDescriptorFromPlugin(PLUGIN_ID, "icons/obj16/frgmt_obj.gif"));
reg.put("icons/obj16/plugin_obj.gif",
imageDescriptorFromPlugin(PLUGIN_ID, "icons/obj16/plugin_obj.gif"));
+ reg.put("icons/obj16/refresh.gif",
+ imageDescriptorFromPlugin(PLUGIN_ID, "icons/obj16/refresh.gif"));
}
}
5 src/main/java/org/intalio/eclipse/bundle/doctor/IBundleManager.java
View
@@ -35,7 +35,10 @@
public interface IBundleManager {
/**
- * @return all the bundles currently installed in this instance.
+ * @return all the bundles currently installed in this instance, plus all
+ * those that aren't installed but are present in the dropins.
+ *
+ * This method is expensive and should be called with caution.
*/
public Collection<RequiredBundle> getAllBundles();
99 src/main/java/org/intalio/eclipse/bundle/doctor/internal/BundleManager.java
View
@@ -15,17 +15,27 @@
package org.intalio.eclipse.bundle.doctor.internal;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdmin;
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.framework.internal.core.AbstractBundle;
+import org.intalio.eclipse.bundle.doctor.BundlePlugin;
import org.intalio.eclipse.bundle.doctor.IBundleManager;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -36,8 +46,7 @@
/**
- * The BundleInfo is the object that contains the bundles.
- *
+ * The bundle manager is the object that contains the bundles.
*
* @author <a href="http://www.intalio.com">Intalio Inc.</a>
* @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
@@ -62,9 +71,9 @@ public void close() {
public Collection<RequiredBundle> getAllBundles() {
PackageAdmin packageAdmin = (PackageAdmin) _bundleTracker.getService();
List<RequiredBundle> required = new ArrayList<RequiredBundle>();
- for (RequiredBundle r : packageAdmin.getRequiredBundles(null)) {
- required.add(r);
- }
+ required.addAll(Arrays.asList(packageAdmin.getRequiredBundles(null)));
+
+ required.addAll(findDisabledPlugins(extractLocations(required)));
Collections.sort(required, new Comparator<RequiredBundle>() {
public int compare(RequiredBundle o1, RequiredBundle o2) {
return o1.getSymbolicName().compareTo(o2.getSymbolicName());
@@ -73,6 +82,84 @@ public int compare(RequiredBundle o1, RequiredBundle o2) {
return required;
}
+ private List<String> extractLocations(List<RequiredBundle> required) {
+ List<String> locations = new ArrayList<String>();
+ for (RequiredBundle b : required) {
+ locations.add(((BaseData) ((AbstractBundle) b.getBundle()).getBundleData()).getBundleFile().getBaseFile().getAbsolutePath());
+ }
+ return locations;
+ }
+
+ private List<RequiredBundle> findDisabledPlugins(List<String> locations) {
+ File platform = new File(Platform.getInstallLocation().getURL().getFile());
+ File pluginsDir = new File(platform, "plugins");
+ File dropinsDir = new File(platform, "dropins");
+ // now look them up
+ List<RequiredBundle> bundles = new ArrayList<RequiredBundle>();
+ bundles.addAll(internalFindInDirectory(pluginsDir, false, locations));
+ bundles.addAll(internalFindInDirectory(dropinsDir, true, locations));
+ return bundles;
+ }
+
+ private List<RequiredBundle> internalFindInDirectory(File dir, boolean lookInSubFolders, List<String> ignore) {
+ List<RequiredBundle> bundles = new ArrayList<RequiredBundle>();
+ for (File f : dir.listFiles()) {
+ if (ignore.contains(f.getAbsolutePath())) {
+ continue;
+ }
+ if (!f.isDirectory() && f.getName().endsWith(".jar")) {// if it's a jar
+ JarFile jarFile = null;
+ try {
+ jarFile = new JarFile(f);
+ Manifest manifest = jarFile.getManifest();
+ if (manifest.getMainAttributes().getValue(ManifestBasedBundle.SYMBOLIC_NAME_ENTRY) != null) {
+ bundles.add(new ManifestBasedBundle(manifest, f.getAbsolutePath()));
+ }
+ } catch (IOException e) {
+ BundlePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
+ BundlePlugin.PLUGIN_ID, e.getMessage(), e));
+ } finally {
+ if (jarFile != null) {
+ try {
+ jarFile.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
+ } else if (f.isDirectory()) {//maybe a directory
+ //check if it contains META-INF/MANIFEST.MF
+ File manifestFile = new File(f, "META-INF" + File.pathSeparator
+ + "MANIFEST.MF");
+ if (manifestFile.exists()) {
+ InputStream input = null;
+ try {
+ input = new FileInputStream(manifestFile);
+ Manifest manifest = new Manifest(input);
+ if (manifest.getMainAttributes().containsKey(
+ ManifestBasedBundle.SYMBOLIC_NAME_ENTRY)) {
+ bundles.add(new ManifestBasedBundle(manifest,
+ f.getAbsolutePath()));
+ }
+ } catch(IOException e) {
+ BundlePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
+ BundlePlugin.PLUGIN_ID, e.getMessage(), e));
+ } finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e1) {
+ }
+ }
+ }
+ } else if (lookInSubFolders) {
+ bundles.addAll(internalFindInDirectory(f, true, ignore));
+ }
+ }
+ }
+ return bundles;
+ }
+
public Collection<Bundle> getFragments(Bundle bundle) {
PackageAdmin packageAdmin = (PackageAdmin) _bundleTracker.getService();
List<Bundle> bundles = new ArrayList<Bundle>();
@@ -103,7 +190,7 @@ public int compare(Bundle o1, Bundle o2) {
}
@SuppressWarnings("restriction")
- public void install(BundleInfo bundle) throws BundleException {
+ public void install(BundleInfo bundle) {
FrameworkAdmin framework = (FrameworkAdmin) _framework.getService();
BundlesState state = framework.getRunningManipulator().getBundlesState();
state.installBundle(bundle);
77 src/main/java/org/intalio/eclipse/bundle/doctor/internal/ManifestBasedBundle.java
View
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * Copyright (c) 2009, Intalio Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intalio Inc. - initial API and implementation
+ *******************************************************************************/
+package org.intalio.eclipse.bundle.doctor.internal;
+
+import java.util.jar.Manifest;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.RequiredBundle;
+
+/**
+ * An implementation of RequiredBundle for bundles that aren't installed just yet.
+ *
+ *
+ * @author <a href="http://www.intalio.com">Intalio Inc.</a>
+ * @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
+ */
+public class ManifestBasedBundle implements RequiredBundle {
+
+ public static final String SYMBOLIC_NAME_ENTRY = "Bundle-SymbolicName";
+
+ public static final String VERSION_ENTRY = "Bundle-Version";
+
+ private String _symbolicName = null;
+
+ private String _version = null;
+
+ private String _absolutePath;
+
+ public ManifestBasedBundle(Manifest m, String absolutePath) {
+ this(m.getMainAttributes().getValue(SYMBOLIC_NAME_ENTRY).split(";")[0],
+ m.getMainAttributes().getValue(VERSION_ENTRY), absolutePath);
+ }
+ public ManifestBasedBundle(String name, String version, String absolutePath) {
+ _symbolicName = name;
+ _version = version;
+ _absolutePath = absolutePath;
+ }
+
+ public Bundle getBundle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Bundle[] getRequiringBundles() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getSymbolicName() {
+ return _symbolicName;
+ }
+
+ public Version getVersion() {
+ return Version.parseVersion(_version);
+ }
+
+ public boolean isRemovalPending() {
+ return false;
+ }
+
+ /**
+ * @return the abolute path to the jar of the directory
+ */
+ public String getAbsolutePath() {
+ return _absolutePath;
+ }
+
+}
46 src/main/java/org/intalio/eclipse/bundle/doctor/view/BundleLabelProvider.java
View
@@ -14,13 +14,21 @@
*/
package org.intalio.eclipse.bundle.doctor.view;
+import org.eclipse.jface.viewers.IColorDecorator;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontDecorator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.eclipse.osgi.framework.internal.core.BundleFragment;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.PlatformUI;
import org.intalio.eclipse.bundle.doctor.BundlePlugin;
+import org.intalio.eclipse.bundle.doctor.internal.ManifestBasedBundle;
import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.RequiredBundle;
@@ -33,12 +41,13 @@
* @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
*/
public class BundleLabelProvider extends LabelProvider implements
- ILabelProvider {
+ ILabelProvider, IColorProvider {
@Override
public String getText(Object element) {
if (element instanceof RequiredBundle) {
- return getText(((RequiredBundle) element).getBundle());
+ return NLS.bind("{0} ({1})", ((RequiredBundle) element).getSymbolicName(),
+ ((RequiredBundle) element).getVersion());
} else if (element instanceof Bundle) {
return NLS.bind("{0} ({1})", ((Bundle) element).getSymbolicName(),
((AbstractBundle) element).getVersion());
@@ -60,6 +69,10 @@ public String getText(Object element) {
@Override
public Image getImage(Object element) {
if (element instanceof RequiredBundle) {
+ if (((RequiredBundle) element).getBundle() == null) {
+ return BundlePlugin.getDefault().getImageRegistry().
+ get("icons/obj16/ext_plugin_obj.gif");
+ }
return getImage(((RequiredBundle) element).getBundle());
} else if (element instanceof Bundle) {
switch (((Bundle) element).getState()) {
@@ -82,4 +95,33 @@ public Image getImage(Object element) {
}
return super.getImage(element);
}
+
+ public Font decorateFont(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Color decorateBackground(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Color decorateForeground(Object element) {
+ if (element instanceof ManifestBasedBundle) {
+ return PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ }
+ return null;
+ }
+
+ public Color getBackground(Object element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Color getForeground(Object element) {
+ if (element instanceof ManifestBasedBundle) {
+ return PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_GRAY);
+ }
+ return null;
+ }
}
112 src/main/java/org/intalio/eclipse/bundle/doctor/view/BundleView.java
View
@@ -13,28 +13,37 @@
*/
package org.intalio.eclipse.bundle.doctor.view;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.ui.internal.misc.StringMatcher;
import org.eclipse.ui.part.ViewPart;
import org.intalio.eclipse.bundle.doctor.BundlePlugin;
import org.intalio.eclipse.bundle.doctor.IBundleManager;
+import org.intalio.eclipse.bundle.doctor.internal.ManifestBasedBundle;
import org.intalio.eclipse.bundle.doctor.wizard.InstallWizard;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -50,6 +59,11 @@
*/
public class BundleView extends ViewPart {
+ /**
+ * An action to activate the current plugin under selection
+ * @author <a href="http://www.intalio.com">Intalio Inc.</a>
+ * @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
+ */
private class ActivateAction extends Action {
@Override
@@ -79,9 +93,69 @@ public void run() {
}
_viewer.refresh();
}
+
+ @Override
+ public boolean isEnabled() {
+ Object elt = ((IStructuredSelection) _viewer.getSelection()).getFirstElement();
+ if (elt instanceof RequiredBundle) {
+ elt = ((RequiredBundle) elt).getBundle();
+ }
+ return elt != null;
+ }
}
+ /**
+ * Install a bundle selected in the tree.
+ * @author <a href="http://www.intalio.com">Intalio Inc.</a>
+ * @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
+ */
private class InstallAction extends Action {
+
+ @Override
+ public String getText() {
+ return "Install";
+ }
+
+ @Override
+ public void run() {
+ Object elt = ((IStructuredSelection) _viewer.getSelection()).getFirstElement();
+ String location = null;
+ String symbolicName = null;
+ if (elt instanceof ManifestBasedBundle) {
+ location = ((ManifestBasedBundle)elt).getAbsolutePath();
+ symbolicName = ((ManifestBasedBundle)elt).getSymbolicName();
+ } else {
+ throw new IllegalArgumentException("Don't know how to handle this bundle :" + elt);
+ }
+ try {
+ BundlePlugin.getDefault().getBundleManager().
+ install(new URL("file", "", location).toString());
+ } catch (Exception e) {
+ MessageDialog.openError(getSite().getShell(),
+ NLS.bind("Error while installing {0}", symbolicName),
+ e.getMessage());
+ e.printStackTrace();
+ }
+ _viewer.refresh();
+ }
+
+ @Override
+ public boolean isEnabled() {
+ Object elt = ((IStructuredSelection) _viewer.getSelection()).getFirstElement();
+ if (elt instanceof RequiredBundle) {
+ elt = ((RequiredBundle) elt).getBundle();
+ }
+ return elt == null || (elt instanceof Bundle
+ && ((Bundle) elt).getState() == Bundle.UNINSTALLED);
+ }
+ }
+
+ /**
+ * An action to install a plugin through a wizard.
+ * @author <a href="http://www.intalio.com">Intalio Inc.</a>
+ * @author <a href="mailto:atoulme@intalio.com">Antoine Toulme</a>
+ */
+ private class InstallWizardAction extends Action {
@Override
public String getText() {
@@ -102,10 +176,14 @@ public void run() {
@Override
public void createPartControl(Composite parent) {
parent.setLayout(new GridLayout());
- Group filterGroup = new Group(parent, SWT.NONE);
- filterGroup.setLayout(new FillLayout());
- filterGroup.setText("(Filter the bundles by name)");
- _filterText = new Text(filterGroup, SWT.NONE);
+ Composite toolbar = new Composite(parent, SWT.NONE);
+ toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ TableWrapLayout toolbarLayout = new TableWrapLayout();
+ toolbarLayout.numColumns = 2;
+ toolbar.setLayout(toolbarLayout);
+
+ _filterText = new Text(toolbar, SWT.SEARCH | SWT.CANCEL);
+ _filterText.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB));
_filterText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (_viewer != null && !_viewer.getTree().isDisposed()) {
@@ -113,7 +191,23 @@ public void modifyText(ModifyEvent e) {
}
}
});
- filterGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Composite buttonsComposite = new Composite(toolbar, SWT.NONE);
+ buttonsComposite.setLayout(new TableWrapLayout());
+ buttonsComposite.setLayoutData(new TableWrapData(TableWrapData.RIGHT));
+ ImageHyperlink refreshButton = new ImageHyperlink(buttonsComposite, SWT.NONE);
+ refreshButton.setImage(BundlePlugin.getDefault().getImageRegistry().
+ get("icons/obj16/refresh.gif"));
+ refreshButton.addHyperlinkListener(new HyperlinkAdapter() {
+
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ if (_viewer != null && !_viewer.getTree().isDisposed()) {
+ _viewer.refresh();
+ }
+ }
+ });
+
_viewer = new TreeViewer(parent);
_viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
_viewer.setContentProvider(new BundleContentProvider());
@@ -138,11 +232,15 @@ public boolean select(Viewer viewer, Object parentElement,
}
});
}
+
+
private MenuManager createMenuManager() {
MenuManager mgr = new MenuManager();
mgr.add(new ActivateAction());
mgr.add(new InstallAction());
+ mgr.add(new Separator());
+ mgr.add(new InstallWizardAction());
return mgr;
}
10 src/main/java/org/intalio/eclipse/bundle/doctor/view/TreeNode.java
View
@@ -14,6 +14,7 @@
package org.intalio.eclipse.bundle.doctor.view;
import org.intalio.eclipse.bundle.doctor.BundlePlugin;
+import org.intalio.eclipse.bundle.doctor.internal.ManifestBasedBundle;
import org.osgi.service.packageadmin.RequiredBundle;
@@ -41,11 +42,16 @@ public TreeNode(int type, RequiredBundle bundle) {
* @return its children depending on its type.
*/
public Object[] getChildren() {
+ if (_bundle instanceof ManifestBasedBundle) {
+ return new Object[] {};
+ }
switch(_type) {
case FRAGMENTS:
- return BundlePlugin.getDefault().getBundleManager().getFragments(_bundle.getBundle()).toArray();
+ return BundlePlugin.getDefault().getBundleManager().
+ getFragments(_bundle.getBundle()).toArray();
case DEPENDENCIES:
- return BundlePlugin.getDefault().getBundleManager().getRequiringBundles(_bundle).toArray();
+ return BundlePlugin.getDefault().getBundleManager().
+ getRequiringBundles(_bundle).toArray();
default:
throw new IllegalArgumentException("Invalid node type");
}
Please sign in to comment.
Something went wrong with that request. Please try again.