1 11 package org.eclipse.pde.internal.ui.correction; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.jdt.core.IClasspathEntry; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.JavaCore; 21 import org.eclipse.jdt.core.JavaModelException; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.pde.core.build.IBuildEntry; 24 import org.eclipse.pde.internal.build.IBuildPropertiesConstants; 25 import org.eclipse.pde.internal.core.builders.BuildErrorReporter; 26 import org.eclipse.pde.internal.core.text.build.Build; 27 import org.eclipse.pde.internal.core.text.build.BuildEntry; 28 import org.eclipse.pde.internal.ui.PDEUIMessages; 29 30 public class AddSourceBuildEntryResolution extends BuildEntryMarkerResolution { 31 32 public AddSourceBuildEntryResolution(int type, IMarker marker) { 33 super(type, marker); 34 } 35 36 public String getLabel() { 37 return NLS.bind(PDEUIMessages.AddSourceBuildEntryResolution_label, fEntry); 38 } 39 40 protected void createChange(Build build) { 41 try { 42 BuildEntry buildEntry = (BuildEntry)build.getEntry(fEntry); 43 boolean unlistedOnly = true; 44 if (buildEntry == null) { 45 buildEntry = new BuildEntry(fEntry, build.getModel()); 46 unlistedOnly = false; 47 } 48 String [] unlisted = getSourcePaths(build, unlistedOnly); 49 for (int i = 0; i < unlisted.length; i++) { 50 if (unlisted[i] == null) 51 break; 52 buildEntry.addToken(unlisted[i]); 53 } 54 } catch (CoreException e) { 55 } 56 } 57 58 private String [] getSourcePaths(Build build, boolean unlistedOnly) { 59 IProject project = build.getModel().getUnderlyingResource().getProject(); 60 try { 61 if (project.hasNature(JavaCore.NATURE_ID)) { 62 ArrayList sourceEntries = new ArrayList (); 63 IBuildEntry[] entries = build.getBuildEntries(); 64 if (unlistedOnly) 65 for (int i = 0; i < entries.length; i++) 66 if (entries[i].getName().startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX)) 67 sourceEntries.add(entries[i]); 68 69 IJavaProject jp = JavaCore.create(project); 70 IClasspathEntry[] cpes = jp.getRawClasspath(); 71 return BuildErrorReporter.getUnlistedClasspaths(sourceEntries, project, cpes); 72 } 73 } catch (JavaModelException e) { 74 } catch (CoreException e) { 75 } 76 return null; 77 } 78 } 79 | Popular Tags |