1 /******************************************************************************* 2 * Copyright (c) 2007, 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 * Gary Duprex <Gary.Duprex@aspectstools.com> - bug 150225 14 *******************************************************************************/ 15 package org.eclipse.pde.internal.ui.correction; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.jdt.launching.JavaRuntime; 19 import org.eclipse.jdt.launching.environments.IExecutionEnvironment; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.pde.internal.core.ibundle.IManifestHeader; 22 import org.eclipse.pde.internal.core.text.bundle.BundleModel; 23 import org.eclipse.pde.internal.core.text.bundle.RequiredExecutionEnvironmentHeader; 24 import org.eclipse.pde.internal.ui.PDEUIMessages; 25 import org.osgi.framework.Constants; 26 27 public class AddDefaultExecutionEnvironmentResolution extends AbstractManifestMarkerResolution { 28 29 private String id; 30 AddDefaultExecutionEnvironmentResolution(int type, String id, IMarker marker)31 public AddDefaultExecutionEnvironmentResolution(int type, String id, IMarker marker) { 32 super(type, marker); 33 this.id = id; 34 } 35 36 @Override createChange(BundleModel model)37 protected void createChange(BundleModel model) { 38 id = this.marker.getAttribute("ee_id", null); //$NON-NLS-1$ 39 40 IManifestHeader header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); 41 if (header == null) { 42 // Initialize header with empty value 43 model.getBundle().setHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, ""); //$NON-NLS-1$ 44 } 45 46 // Get header 47 header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); 48 49 if (header != null && header instanceof RequiredExecutionEnvironmentHeader) { 50 IExecutionEnvironment ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(id); 51 ((RequiredExecutionEnvironmentHeader) header).addExecutionEnvironment(ee); 52 } 53 } 54 55 @Override getLabel()56 public String getLabel() { 57 return NLS.bind(PDEUIMessages.AddDefaultExecutionEnvironment_label, id); 58 } 59 } 60