blob: bee7e19af168923102edf942b6e138910d4437bf [file] [log] [blame]
package org.eclipse.ui.navigator.internal;
/*******************************************************************************
* Copyright (c) 2003, 2005 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import java.net.URL;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;
/**
* A set of static methods that provide an nicer interface to common platform
* operations related to bundle management.
*
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part of a work in
* progress. There is a guarantee neither that this API will work nor that it will remain the same.
* Please do not use this API without consulting with the Platform/UI team.
* </p>
*
* @since 3.2
*/
public class BundleUtility {
public static boolean isActive(Bundle bundle) {
if (bundle == null)
return false;
return bundle.getState() == Bundle.ACTIVE;
}
public static boolean isActivated(Bundle bundle) {
return bundle != null && (bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0;
}
// TODO: needs a better name
public static boolean isReady(Bundle bundle) {
return bundle != null && isReady(bundle.getState());
}
public static boolean isReady(int bundleState) {
return (bundleState & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0;
}
public static boolean isActive(String bundleId) {
return isActive(Platform.getBundle(bundleId));
}
public static boolean isActivated(String bundleId) {
return isActivated(Platform.getBundle(bundleId));
}
public static boolean isReady(String bundleId) {
return isReady(Platform.getBundle(bundleId));
}
public static URL find(Bundle bundle, String path) {
if (bundle == null)
return null;
return Platform.find(bundle, new Path(path));
}
public static URL find(String bundleId, String path) {
return find(Platform.getBundle(bundleId), path);
}
public static void log(String bundleId, Throwable exception) {
Bundle bundle = Platform.getBundle(bundleId);
if (bundle == null)
return;
IStatus status = new Status(IStatus.ERROR, bundleId, IStatus.ERROR,
exception.getMessage() == null ? "" : exception.getMessage(), //$NON-NLS-1$
exception);
Platform.getLog(bundle).log(status);
}
}