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.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 RemoveBuildEntryResolution extends BuildEntryMarkerResolution {
25 
RemoveBuildEntryResolution(int type, IMarker marker)26 	public RemoveBuildEntryResolution(int type, IMarker marker) {
27 		super(type, marker);
28 	}
29 
30 	@Override
getLabel()31 	public String getLabel() {
32 		if (fToken == null)
33 			return NLS.bind(PDEUIMessages.RemoveBuildEntryResolution_removeEntry, fEntry);
34 		return NLS.bind(PDEUIMessages.RemoveBuildEntryResolution_removeToken, fToken, fEntry);
35 	}
36 
37 	@Override
createChange(Build build)38 	protected void createChange(Build build) {
39 		try {
40 			fEntry = (String) marker.getAttribute(PDEMarkerFactory.BK_BUILD_ENTRY);
41 			fToken = (String) marker.getAttribute(PDEMarkerFactory.BK_BUILD_TOKEN);
42 		} catch (CoreException e) {
43 		}
44 		try {
45 			BuildEntry buildEntry = (BuildEntry) build.getEntry(fEntry);
46 			if (buildEntry == null)
47 				return;
48 			if (fToken == null)
49 				build.remove(buildEntry);
50 			else {
51 				buildEntry.removeToken(fToken);
52 				if (buildEntry.getTokens().length == 0) {
53 					build.remove(buildEntry);
54 				}
55 			}
56 		} catch (CoreException e) {
57 		}
58 	}
59 
60 }
61