1 /******************************************************************************* 2 * Copyright (c) 2006, 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 java.util.regex.Pattern; 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.pde.internal.core.ibundle.IBundle; 19 import org.eclipse.pde.internal.core.text.bundle.*; 20 import org.eclipse.pde.internal.core.util.PatternConstructor; 21 import org.eclipse.pde.internal.ui.PDEPlugin; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 import org.eclipse.pde.internal.ui.wizards.tools.IOrganizeManifestsSettings; 24 import org.osgi.framework.Constants; 25 26 public class AddExportPackageMarkerResolution extends AbstractManifestMarkerResolution { 27 28 private String fValues; 29 AddExportPackageMarkerResolution(IMarker mark, int type, String values)30 public AddExportPackageMarkerResolution(IMarker mark, int type, String values) { 31 super(type, mark); 32 this.fValues = values; 33 this.marker = mark; 34 } 35 36 @Override getLabel()37 public String getLabel() { 38 return PDEUIMessages.AddExportPackageResolution_Label; 39 } 40 41 @Override createChange(BundleModel model)42 protected void createChange(BundleModel model) { 43 IBundle bundle = model.getBundle(); 44 if (bundle instanceof Bundle) { 45 Bundle bun = (Bundle) bundle; 46 ExportPackageHeader header = (ExportPackageHeader) bun.getManifestHeader(Constants.EXPORT_PACKAGE); 47 if (header == null) { 48 bundle.setHeader(Constants.EXPORT_PACKAGE, ""); //$NON-NLS-1$ 49 header = (ExportPackageHeader) bun.getManifestHeader(Constants.EXPORT_PACKAGE); 50 } 51 processPackages(header, false); 52 } 53 } 54 processPackages(ExportPackageHeader header, boolean setInternal)55 protected void processPackages(ExportPackageHeader header, boolean setInternal) { 56 fValues = marker.getAttribute("packages", null); //$NON-NLS-1$ 57 if (fValues == null) { 58 return; 59 } 60 String[] packages = fValues.split(","); //$NON-NLS-1$ 61 String filter = PDEPlugin.getDefault().getDialogSettings().get(IOrganizeManifestsSettings.PROP_INTERAL_PACKAGE_FILTER); 62 if (filter == null) 63 filter = IOrganizeManifestsSettings.VALUE_DEFAULT_FILTER; 64 Pattern pat = PatternConstructor.createPattern(filter, false); 65 for (String packageId : packages) { 66 ExportPackageObject obj = header.addPackage(packageId); 67 if (setInternal){ 68 obj.setInternal(setInternal); 69 continue; 70 } 71 if (pat.matcher(packageId).matches()) 72 obj.setInternal(true); 73 } 74 } 75 76 } 77