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 OptionalImportPackageResolution extends AbstractManifestMarkerResolution {
23 
24 	private String fPackageName;
25 
OptionalImportPackageResolution(int type, String packageName, IMarker marker)26 	public OptionalImportPackageResolution(int type, String packageName, IMarker marker) {
27 		super(type, marker);
28 		fPackageName = packageName;
29 	}
30 
31 	@Override
createChange(BundleModel model)32 	protected void createChange(BundleModel model) {
33 		fPackageName = marker.getAttribute("packageName", (String) null); //$NON-NLS-1$
34 		Bundle bundle = (Bundle) model.getBundle();
35 		ImportPackageHeader header = (ImportPackageHeader) bundle.getManifestHeader(Constants.IMPORT_PACKAGE);
36 		if (header != null) {
37 			ImportPackageObject pkg = header.getPackage(fPackageName);
38 			if (pkg != null)
39 				pkg.setOptional(true);
40 		}
41 	}
42 
43 	@Override
getDescription()44 	public String getDescription() {
45 		return NLS.bind(PDEUIMessages.OptionalImportPkgResolution_description, fPackageName);
46 	}
47 
48 	@Override
getLabel()49 	public String getLabel() {
50 		return NLS.bind(PDEUIMessages.OptionalImportPkgResolution_label, fPackageName);
51 	}
52 
53 }
54