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.jdt.launching.JavaRuntime;
18 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
19 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
20 import org.eclipse.pde.internal.core.text.bundle.*;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22 import org.osgi.framework.Constants;
23 
24 public class RemoveUnknownExecEnvironments extends AbstractManifestMarkerResolution {
25 
RemoveUnknownExecEnvironments(int type, IMarker marker)26 	public RemoveUnknownExecEnvironments(int type, IMarker marker) {
27 		super(type, marker);
28 	}
29 
30 	@Override
createChange(BundleModel model)31 	protected void createChange(BundleModel model) {
32 		IManifestHeader header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
33 		if (header instanceof RequiredExecutionEnvironmentHeader) {
34 			RequiredExecutionEnvironmentHeader reqHeader = (RequiredExecutionEnvironmentHeader) header;
35 			ExecutionEnvironment[] bundleEnvs = reqHeader.getEnvironments();
36 			IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
37 			for (ExecutionEnvironment bundleEnv : bundleEnvs) {
38 				boolean found = false;
39 				for (IExecutionEnvironment systemEnv : systemEnvs) {
40 					if (bundleEnv.getName().equals(systemEnv.getId())) {
41 						found = true;
42 						break;
43 					}
44 				}
45 				if (!found)
46 					reqHeader.removeExecutionEnvironment(bundleEnv);
47 			}
48 		}
49 	}
50 
51 	@Override
getLabel()52 	public String getLabel() {
53 		return PDEUIMessages.RemoveUnknownExecEnvironments_label;
54 	}
55 
56 }
57