All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.pde.launching.OSGiLaunchConfigurationInitializer Maven / Gradle / Ivy

There is a newer version: 3.13.200
Show newest version
/*******************************************************************************
 * Copyright (c) 2006, 2015 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.launching;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.internal.core.PDEState;
import org.eclipse.pde.internal.core.TargetPlatformHelper;
import org.eclipse.pde.internal.launching.launcher.BundleLauncherHelper;

/**
 * Initializes launch configuration attributes for newly-created OSGi Framework
 * launch configurations
 * 

* Clients may instantiate or subclass this class *

*

* This class originally existed in 3.3 as * org.eclipse.pde.ui.launcher.OSGiLaunchConfigurationInitializer. *

* @since 3.6 */ public class OSGiLaunchConfigurationInitializer { protected static final String DEFAULT = "default"; //$NON-NLS-1$ /** * Initializes some attributes on a newly-created launch configuration * * @param configuration * the launch configuration */ public void initialize(ILaunchConfigurationWorkingCopy configuration) { initializeFrameworkDefaults(configuration); initializeBundleState(configuration); initializeSourcePathProvider(configuration); } /** * Sets the source provider ID * * @param configuration * the launch configuration */ protected void initializeSourcePathProvider(ILaunchConfigurationWorkingCopy configuration) { configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, PDESourcePathProvider.ID); } /** * Initializes the start level and auto-start attributes * * @param configuration * the launch configuration */ protected void initializeFrameworkDefaults(ILaunchConfigurationWorkingCopy configuration) { configuration.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true); configuration.setAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4); } /** * Initializes the checked/unchecked state of bundles * * @param configuration * the launch configuration */ protected void initializeBundleState(ILaunchConfigurationWorkingCopy configuration) { Set targetBundles = new HashSet<>(); Set workspaceBundles = new HashSet<>(); IPluginModelBase[] models = PluginRegistry.getActiveModels(); PDEState pdeState = TargetPlatformHelper.getPDEState(); for (IPluginModelBase model : models) { if (isSourceBundle(pdeState, model)) { continue; } boolean inWorkspace = model.getUnderlyingResource() != null; appendBundle(inWorkspace ? workspaceBundles : targetBundles, model); } configuration.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_BUNDLES, workspaceBundles); configuration.setAttribute(IPDELauncherConstants.SELECTED_TARGET_BUNDLES, targetBundles); configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, true); } private boolean isSourceBundle(PDEState pdeState, IPluginModelBase model) { return pdeState.getBundleSourceEntry(model.getBundleDescription().getBundleId()) != null; } private void appendBundle(Set bundleSet, IPluginModelBase model) { String id = model.getPluginBase().getId(); String value = BundleLauncherHelper.formatBundleEntry(model, getStartLevel(id), getAutoStart(id)); bundleSet.add(value); } /** * Returns the bundle's start level * * @param bundleID * the bundle ID * @return the start level for the given bundle or the string default */ protected String getStartLevel(String bundleID) { return DEFAULT; } /** * Returns whether the bundle should be started automatically * @param bundleID * the bundle ID * @return true, false, or default */ protected String getAutoStart(String bundleID) { return DEFAULT; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy