1 /*******************************************************************************2 * Copyright (c) 2005, 2006 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Eclipse Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/epl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11 package org.eclipse.pde.internal.ui.correction;12 13 import org.eclipse.jdt.launching.JavaRuntime;14 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;15 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;16 import org.eclipse.pde.internal.core.text.bundle.BundleModel;17 import org.eclipse.pde.internal.core.text.bundle.ExecutionEnvironment;18 import org.eclipse.pde.internal.core.text.bundle.RequiredExecutionEnvironmentHeader;19 import org.eclipse.pde.internal.ui.PDEUIMessages;20 import org.osgi.framework.Constants;21 22 public class RemoveUnknownExecEnvironments extends AbstractManifestMarkerResolution {23 24 public RemoveUnknownExecEnvironments(int type) {25 super(type);26 }27 28 protected void createChange(BundleModel model) {29 IManifestHeader header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);30 if (header instanceof RequiredExecutionEnvironmentHeader) {31 RequiredExecutionEnvironmentHeader reqHeader = (RequiredExecutionEnvironmentHeader)header;32 ExecutionEnvironment[] bundleEnvs = reqHeader.getEnvironments();33 IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();34 for (int i = 0; i < bundleEnvs.length; i++) {35 boolean found = false;36 for (int j = 0; j < systemEnvs.length; j++) {37 if (bundleEnvs[i].getName().equals(systemEnvs[j].getId())) {38 found = true;39 break;40 }41 }42 if (!found)43 reqHeader.removeExecutionEnvironment(bundleEnvs[i]);44 }45 }46 }47 48 public String getLabel() {49 return PDEUIMessages.RemoveUnknownExecEnvironments_label;50 }51 52 }53