1 /******************************************************************************* 2 * Copyright (c) 2009, 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.core.runtime.CoreException; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; 20 import org.eclipse.pde.internal.core.text.build.Build; 21 import org.eclipse.pde.internal.core.text.build.BuildEntry; 22 import org.eclipse.pde.internal.ui.PDEUIMessages; 23 24 public class ReplaceBuildEntryResolution extends BuildEntryMarkerResolution { 25 ReplaceBuildEntryResolution(int type, IMarker marker)26 public ReplaceBuildEntryResolution(int type, IMarker marker) { 27 super(type, marker); 28 } 29 30 @Override getLabel()31 public String getLabel() { 32 return NLS.bind(PDEUIMessages.ReplaceBuildEntryResolution_replaceToken, fToken, fEntry); 33 } 34 35 @Override createChange(Build build)36 protected void createChange(Build build) { 37 try { 38 fEntry = (String) marker.getAttribute(PDEMarkerFactory.BK_BUILD_ENTRY); 39 fToken = (String) marker.getAttribute(PDEMarkerFactory.BK_BUILD_TOKEN); 40 } catch (CoreException e) { 41 } 42 try { 43 BuildEntry buildEntry = (BuildEntry) build.getEntry(fEntry); 44 if (buildEntry == null) 45 return; 46 if (fToken == null) 47 build.remove(buildEntry); 48 else { 49 String[] tokens = buildEntry.getTokens(); 50 for (String token : tokens) { 51 buildEntry.removeToken(token); 52 } 53 buildEntry.addToken(fToken); 54 } 55 } catch (CoreException e) { 56 } 57 } 58 } 59