Java Code Examples for org.osgi.framework.Bundle#UNINSTALLED

The following examples show how to use org.osgi.framework.Bundle#UNINSTALLED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BundleStates.java    From wisdom with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the String form of the given OSGi bundle state.
 *
 * @param state the state
 * @return the string form.
 */
public static String from(int state) {
    switch (state) {
        case Bundle.ACTIVE:
            return ACTIVE;
        case Bundle.INSTALLED:
            return INSTALLED;
        case Bundle.RESOLVED:
            return RESOLVED;
        case Bundle.STARTING:
            return STARTING;
        case Bundle.STOPPING:
            return STOPPING;
        case Bundle.UNINSTALLED:
            return UNINSTALLED;
        default:
            return "UNKNOWN (" + Integer.toString(state) + ")";
    }
}
 
Example 2
Source File: AbstractConciergeTestCase.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/** Returns bundle state as readable string. */
protected String getBundleStateAsString(final int state) {
	switch (state) {
	case Bundle.INSTALLED:
		return "INSTALLED";
	case Bundle.RESOLVED:
		return "RESOLVED";
	case Bundle.ACTIVE:
		return "ACTIVE";
	case Bundle.STARTING:
		return "STARTING";
	case Bundle.STOPPING:
		return "STOPPING";
	case Bundle.UNINSTALLED:
		return "UNINSTALLED";
	default:
		return "UNKNOWN state: " + state;
	}
}
 
Example 3
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get bundle state as a constant length string. Show state left adjusted as
 * 12 character string.
 *
 * @param bundle
 *          the bundle
 * @return The bundles state
 */
public static String showState(Bundle bundle)
{
  switch (bundle.getState()) {
  case Bundle.INSTALLED:
    return "installed   ";
  case Bundle.RESOLVED:
    return "resolved    ";
  case Bundle.STARTING:
    return "starting    ";
  case Bundle.ACTIVE:
    return "active      ";
  case Bundle.STOPPING:
    return "stopping    ";
  case Bundle.UNINSTALLED:
    return "uninstalled ";
  default:
    return "ILLEGAL <" + bundle.getState() + "> ";
  }
}
 
Example 4
Source File: DeployedBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void uninstall()
    throws BundleException {
  if (bundle != null) {
    if (Bundle.UNINSTALLED != bundle.getState()) {
      DirDeployerImpl.log("uninstall " + this);
      bundle.uninstall();
      installedBundles.remove(bundle.getBundleId());
      saveState();
      bundleControl.unregister();
    }
    bundle = null;
  }
  else if (DeployedBundleControlState.FAILED == state) {
    bundleControl.unregister();
  }
  try {
    MarkerFile.clearAllMarkers(file);
  } catch (IOException e) {
    // TODO Auto-generated catch block
   //  e.printStackTrace();
  }
}
 
Example 5
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.PackageAdmin#getRequiredBundles(java.lang.String)
 */
public RequiredBundle[] getRequiredBundles(final String symbolicName) {
	final Bundle[] bundles = context.getBundles();

	final ArrayList<RequiredBundle> result = new ArrayList<RequiredBundle>();

	for (final Bundle bundle : bundles) {
		if (bundle.getState() == Bundle.INSTALLED || bundle.getState() == Bundle.UNINSTALLED) {
			continue;
		}

		final BundleRevision rev = bundle.adapt(BundleRevision.class);
		if (isFragment(rev)) {
			continue;
		}

		if (symbolicName == null || symbolicName.equals(rev.getSymbolicName())) {
			result.add(new RequiredBundleImpl(rev));
		}
	}

	return toArrayOrNull(result, RequiredBundle.class);
}
 
Example 6
Source File: ExplorerPreferencePage.java    From eclipse-explorer with Eclipse Public License 1.0 6 votes vote down vote up
private static String getBundleInfo(Bundle bundle) {
    String name = bundle.getHeaders().get("Bundle-Name");
    String ver = bundle.getVersion().toString();
    // UNINSTALLED,INSTALLED, RESOLVED, STARTING, STOPPING, ACTIVE.
    String stStr = "unknown";
    int st = bundle.getState();
    if (st == Bundle.UNINSTALLED) {
        stStr = "uninstalled";
    }
    else if (st == Bundle.INSTALLED) {
        stStr = "installed";
    }
    else if (st == Bundle.RESOLVED) {
        stStr = "resolved";
    }
    else if (st == Bundle.STARTING) {
        stStr = "starting";
    }
    else if (st == Bundle.STOPPING) {
        stStr = "stopping";
    }
    else if (st == Bundle.ACTIVE) {
        stStr = "active";
    }
    return String.format("%s(%s):%s", name, ver, stStr);
}
 
Example 7
Source File: BundleGeneration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 */
HeaderDictionary getHeaders0(String locale) {
  if (cachedRawHeaders == null) {
    cachedRawHeaders = archive.getUnlocalizedAttributes();
  }
  if ("".equals(locale)) {
    return (HeaderDictionary)cachedRawHeaders.clone();
  }
  if (bundle.state != Bundle.UNINSTALLED) {
    final String base = cachedRawHeaders.get(Constants.BUNDLE_LOCALIZATION);
    try {
      return localize(getLocaleDictionary(locale, base));
    } catch (final RuntimeException e) {
      // We assume that we got an exception because we got
      // state change during the operation. Check!
      // NYI
      if (true) {
        throw e;
      }
    }
  }
  return null;
}
 
Example 8
Source File: Spin.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Color getColor(int state) {
  switch(state) {
  case Bundle.INSTALLED:
    return installedColor;
  case Bundle.ACTIVE:
    return activeColor;
  case Bundle.RESOLVED:
    return resolvedColor;
  case Bundle.UNINSTALLED:
    return uninstalledColor;
  case Bundle.STARTING:
    return startingColor;
  case Bundle.STOPPING:
    return stoppingColor;
  }

  return Color.black;
}
 
Example 9
Source File: AbstractResourceBundleProvider.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method provides common functionality for {@link ModuleTypeProvider} and {@link TemplateProvider} to process
 * the bundles. For {@link RuleResourceBundleImporter} this method is overridden.
 * <p>
 * Checks for availability of the needed {@link Parser}. If it is not available - the bundle is added into
 * {@link #waitingProviders} and the execution of the method ends.
 * <p>
 * If it is available, the execution of the method continues with checking if the version of the bundle is changed.
 * If the version is changed - removes persistence of old variants of the objects, provided by this bundle.
 * <p>
 * Continues with loading the new version of these objects. If this bundle is added for the very first time, only
 * loads the provided objects.
 * <p>
 * The loading can fail because of {@link IOException}.
 *
 * @param bundle it is a {@link Bundle} which has to be processed, because it provides resources for automation
 *            objects.
 */
protected void processAutomationProvider(Bundle bundle) {
    Enumeration<URL> urlEnum = null;
    try {
        if (bundle.getState() != Bundle.UNINSTALLED) {
            urlEnum = bundle.findEntries(path, null, true);
        }
    } catch (IllegalStateException e) {
        logger.debug("Can't read from resource of bundle with ID {}. The bundle is uninstalled.",
                bundle.getBundleId(), e);
        processAutomationProviderUninstalled(bundle);
    }
    Vendor vendor = new Vendor(bundle.getSymbolicName(), bundle.getVersion().toString());
    List<String> previousPortfolio = getPreviousPortfolio(vendor);
    List<String> newPortfolio = new LinkedList<>();
    if (urlEnum != null) {
        while (urlEnum.hasMoreElements()) {
            URL url = urlEnum.nextElement();
            if (url.getPath().endsWith(File.separator)) {
                continue;
            }
            String parserType = getParserType(url);
            Parser<E> parser = parsers.get(parserType);
            updateWaitingProviders(parser, bundle, url);
            if (parser != null) {
                Set<E> parsedObjects = parseData(parser, url, bundle);
                if (!parsedObjects.isEmpty()) {
                    addNewProvidedObjects(newPortfolio, previousPortfolio, parsedObjects);
                }
            }
        }
        putNewPortfolio(vendor, newPortfolio);
    }
    removeUninstalledObjects(previousPortfolio, newPortfolio);
}
 
Example 10
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * store the profile.
 * 
 */
private void storeProfile() {
	final BundleImpl[] bundleArray = bundles
			.toArray(new BundleImpl[bundles.size()]);
	for (int i = 0; i < bundleArray.length; i++) {
		if (bundleArray[i].state != Bundle.UNINSTALLED) {
			bundleArray[i].updateMetadata();
		}
	}
	storeMetadata();
}
 
Example 11
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
protected final void checkBundleNotUninstalled()
		throws IllegalArgumentException {
	if (state == Bundle.UNINSTALLED) {
		throw new IllegalArgumentException("Bundle " + toString()
				+ " has been uninstalled");
	}
}
 
Example 12
Source File: StartLevelController.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private BundleImpl checkBundle(Bundle b) {
  if (b instanceof BundleImpl) {
    final BundleImpl res = (BundleImpl)b;
    if (res.fwCtx == st.fwCtx) {
      if (res.state != Bundle.UNINSTALLED) {
        return res;
      }
      throw new IllegalArgumentException("Bundle is in UNINSTALLED state");
    }
  }
  throw new IllegalArgumentException("Bundle doesn't belong to the same framework as the StartLevel service");
}
 
Example 13
Source File: TableDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String getToolTipText(int row, int column)
{
  String tt = "";

  if (column >= 0 && row >= 0) {

    final Bundle b = getBundle(row);

    switch (column) {
    case COL_ID:
    case COL_LOCATION:
    case COL_STATE:
    case COL_STARTLEVEL:
    case COL_DESC:
    case COL_NAME:
    case COL_VENDOR:
    case COL_SYMBOLIC_NAME:
    case COL_VERSION:
      tt = Util.bundleInfo(b);
      break;
    default:
      break;
    }
    if (b.getState() == Bundle.UNINSTALLED) {
      tt = "Bundle is uninstalled";
    }
  }

  return tt;
}
 
Example 14
Source File: AbstractResourceBundleProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method provides common functionality for {@link ModuleTypeProvider} and {@link TemplateProvider} to process
 * the bundles. For {@link RuleResourceBundleImporter} this method is overridden.
 * <p>
 * Checks for availability of the needed {@link Parser}. If it is not available - the bundle is added into
 * {@link #waitingProviders} and the execution of the method ends.
 * <p>
 * If it is available, the execution of the method continues with checking if the version of the bundle is changed.
 * If the version is changed - removes persistence of old variants of the objects, provided by this bundle.
 * <p>
 * Continues with loading the new version of these objects. If this bundle is added for the very first time, only
 * loads the provided objects.
 * <p>
 * The loading can fail because of {@link IOException}.
 *
 * @param bundle it is a {@link Bundle} which has to be processed, because it provides resources for automation
 *            objects.
 */
protected void processAutomationProvider(Bundle bundle) {
    Enumeration<URL> urlEnum = null;
    try {
        if (bundle.getState() != Bundle.UNINSTALLED) {
            urlEnum = bundle.findEntries(path, null, true);
        }
    } catch (IllegalStateException e) {
        logger.debug("Can't read from resource of bundle with ID {}. The bundle is uninstalled.",
                bundle.getBundleId(), e);
        processAutomationProviderUninstalled(bundle);
    }
    Vendor vendor = new Vendor(bundle.getSymbolicName(), bundle.getVersion().toString());
    List<String> previousPortfolio = getPreviousPortfolio(vendor);
    List<String> newPortfolio = new LinkedList<String>();
    if (urlEnum != null) {
        while (urlEnum.hasMoreElements()) {
            URL url = urlEnum.nextElement();
            if (url.getPath().endsWith(File.separator)) {
                continue;
            }
            String parserType = getParserType(url);
            Parser<E> parser = parsers.get(parserType);
            updateWaitingProviders(parser, bundle, url);
            if (parser != null) {
                Set<E> parsedObjects = parseData(parser, url, bundle);
                if (parsedObjects != null && !parsedObjects.isEmpty()) {
                    addNewProvidedObjects(newPortfolio, previousPortfolio, parsedObjects);
                }
            }
        }
        putNewPortfolio(vendor, newPortfolio);
    }
    removeUninstalledObjects(previousPortfolio, newPortfolio);
}
 
Example 15
Source File: RepositoryDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Bundle getBundle()
{
  if (bundle != null && bundle.getState() == Bundle.UNINSTALLED) {
    // Clear stale bundle reference.
    bundle = null;
  }
  if (bundle == null) {
    // Check to see if there is a bundle now.
    bundle = RepositoryDisplayer.getBundle(resource);
  }
  return bundle;
}
 
Example 16
Source File: StartLevelController.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
boolean canStart(BundleImpl b) {
  return b.getState() != Bundle.UNINSTALLED;
}
 
Example 17
Source File: ClosureHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public StringBuffer bundleInfo(Bundle[] targets)
{
  final StringBuffer sb = new StringBuffer();

  startFont(sb);
  final Set<Bundle> closure =
    new TreeSet<Bundle>(Util.bundleIdComparator);

  for (final Bundle target : targets) {
    int state = target.getState();
    if (state != Bundle.INSTALLED && state != Bundle.UNINSTALLED ) {
      closure.addAll(Util.getClosure(target, null));
    } else {
      sb.append("Bundle #");
      sb.append(target.getBundleId());
      sb.append(" is in ");
      sb.append(state == Bundle.INSTALLED ? "INSTALLED" : "UNINSTALLED");
      sb.append(" state, closure not available");
      return sb;
    }
  }

  boolean containsUninstalled = false;
  if (closure.size() == 0) {
    sb.append("No dependencies");
  } else {
    sb.append("<b>Dependencies via capabilities and services</b><br>");
    for (final Bundle depB : closure) {
      sb.append("&nbsp;&nbsp;");
      if (depB.getState() != Bundle.UNINSTALLED) {
        Util.bundleLink(sb, depB);
      } else {
        sb.append("<b>UNINSTALLED</b>, ");
        sb.append(Util.getBundleName(depB));
        containsUninstalled  = true;
      }
      sb.append("<br>");
    }
  }

  sb.append("<br>");

  // Add xarsg info if we seem to be running knopflerfish
  if (targets.length > 0
      && (-1 != targets[0].getClass().getName().indexOf("knopflerfish"))) {
    if (!containsUninstalled) {
      final String xargs =
          Util.getXARGS(null, closure).toString();
      sb.append("<hr>");
      startFont(sb);
      sb.append("<b>Suggested startup .xargs file</b><br>\n");
      sb.append("</font>");

      sb.append("<pre>");
      sb.append("<font size=\"-2\">");
      // sb.append(Text.replace(xargs, "\n", "<br>"));
      sb.append(xargs);
      sb.append("</font>");
      sb.append("</pre>");
    } else {
      sb.append("<hr>");
      startFont(sb);
      sb.append("<b>Suggested startup .xargs not available when closure contains uninstalled bundles</b><br>\n");
      sb.append("</font>");         
    }
  }

  sb.append("</font>");

  return sb;
}
 
Example 18
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * set the current startlevel but does not update the metadata.
 * 
 * @param targetLevel
 *            the startlevel.
 * 
 */
protected void setLevel(final Bundle[] bundleArray, final int targetLevel,
		final boolean all) {
	if (startlevel == targetLevel) {
		return;
	}
	final boolean up = targetLevel > startlevel;

	final int levels = up ? targetLevel - startlevel
			: startlevel - targetLevel;
	final MultiMap<Integer, AbstractBundle> startLevels = new MultiMap<Integer, AbstractBundle>(
			0);
	// prepare startlevels
	for (int i = 0; i < bundleArray.length; i++) {
		final AbstractBundle bundle = (AbstractBundle) bundleArray[i];
		if (bundle == Concierge.this || bundle.state == Bundle.UNINSTALLED
				|| up && bundle.autostart == AUTOSTART_STOPPED
				|| !up && bundle.state == Bundle.RESOLVED) {
			continue;
		}
		final int offset;
		if (up) {
			offset = bundle.startlevel - startlevel - 1;
		} else {
			offset = startlevel - bundle.startlevel;
		}
		if (offset >= 0 && offset < levels) {
			startLevels.insert(new Integer(offset), bundle);
		}
	}

	for (int i = 0; i < levels; i++) {
		if (up) {
			startlevel++;
		} else {
			startlevel--;
		}
		final List<AbstractBundle> list = startLevels.get(new Integer(i));
		if (list == null) {
			continue;
		}
		final BundleImpl[] toProcess = list
				.toArray(new BundleImpl[list.size()]);
		for (int j = 0; j < toProcess.length; j++) {
			try {
				if (up) {
					// transient is implicit
					toProcess[j]
							.activate(toProcess[j].isActivationPolicyUsed()
									? Bundle.START_ACTIVATION_POLICY : 0);
				} else {
					if (toProcess[toProcess.length - j - 1]
							.getState() == Bundle.UNINSTALLED) {
						continue;
					}
					// transient is implicit
					toProcess[toProcess.length - j - 1].stopBundle();
				}
			} catch (final BundleException be) {
				if (be.getNestedException() != null) {
					be.getNestedException().printStackTrace();
				}
				be.printStackTrace();
				notifyFrameworkListeners(FrameworkEvent.ERROR,
						up ? toProcess[j]
								: toProcess[toProcess.length - j - 1],
						be);
			} catch (final Throwable t) {
				t.printStackTrace();
				notifyFrameworkListeners(FrameworkEvent.ERROR,
						up ? toProcess[j]
								: toProcess[toProcess.length - j - 1],
						t);
			}
		}
	}

	startlevel = targetLevel;
}
 
Example 19
Source File: AutomationResourceBundlesTracker.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Activate
protected void activate(BundleContext bc) {
    bTracker = new BundleTracker<Bundle>(bc, ~Bundle.UNINSTALLED, this);
    bTracker.open();
}
 
Example 20
Source File: AbstractResourceBundleProvider.java    From openhab-core with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * This method is called before the {@link Parser} services to be added to the {@code ServiceTracker} and storing
 * them in the {@link #parsers} into the memory, for fast access on demand. The returned service object is stored in
 * the {@code ServiceTracker} and is available from the {@code getService} and {@code getServices} methods.
 * <p>
 * Also if there are bundles that were stored in {@link #waitingProviders}, to be processed later, because of
 * missing {@link Parser} for particular format,
 * <p>
 * and then the {@link Parser} service appears, they will be processed.
 *
 * @param parser {@link Parser} service
 * @param properties of the service that has been added.
 */
protected void addParser(Parser<E> parser, Map<String, String> properties) {
    String parserType = properties.get(Parser.FORMAT);
    parserType = parserType == null ? Parser.FORMAT_JSON : parserType;
    parsers.put(parserType, parser);
    for (Bundle bundle : waitingProviders.keySet()) {
        if (bundle.getState() != Bundle.UNINSTALLED) {
            processAutomationProvider(bundle);
        }
    }
}