1 /******************************************************************************* 2 * Copyright (c) 2005, 2019 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.pde.internal.ui.correction; 15 16 import org.eclipse.core.resources.IMarker; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.pde.internal.core.text.bundle.*; 19 import org.eclipse.pde.internal.ui.PDEUIMessages; 20 import org.osgi.framework.Constants; 21 22 public class OptionalRequireBundleResolution extends AbstractManifestMarkerResolution { 23 24 private String fBundleId; 25 OptionalRequireBundleResolution(int type, String bundleId, IMarker marker)26 public OptionalRequireBundleResolution(int type, String bundleId, IMarker marker) { 27 super(type, marker); 28 fBundleId = bundleId; 29 } 30 31 @Override createChange(BundleModel model)32 protected void createChange(BundleModel model) { 33 fBundleId= marker.getAttribute("bundleId", (String) null); //$NON-NLS-1$ 34 Bundle bundle = (Bundle) model.getBundle(); 35 RequireBundleHeader header = (RequireBundleHeader) bundle.getManifestHeader(Constants.REQUIRE_BUNDLE); 36 if (header != null) { 37 RequireBundleObject[] requiredBundles = header.getRequiredBundles(); 38 for (RequireBundleObject requiredBundle : requiredBundles) { 39 if (fBundleId.equals(requiredBundle.getId())) 40 requiredBundle.setOptional(true); 41 } 42 } 43 } 44 45 @Override getDescription()46 public String getDescription() { 47 return NLS.bind(PDEUIMessages.OptionalRequireBundleResolution_description, fBundleId); 48 } 49 50 @Override getLabel()51 public String getLabel() { 52 return NLS.bind(PDEUIMessages.OptionalRequireBundleResolution_label, fBundleId); 53 } 54 55 } 56