1 11 package org.eclipse.pde.internal.core.builders; 12 13 import java.util.Locale ; 14 import java.util.Map ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IResourceDelta; 20 import org.eclipse.core.resources.IResourceDeltaVisitor; 21 import org.eclipse.core.resources.IncrementalProjectBuilder; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.osgi.util.NLS; 25 import org.eclipse.pde.internal.core.PDECore; 26 import org.eclipse.pde.internal.core.WorkspaceModelManager; 27 import org.eclipse.pde.internal.core.natures.PDE; 28 import org.eclipse.pde.internal.core.PDECoreMessages; 29 import org.osgi.framework.Bundle; 30 31 public class FeatureConsistencyChecker extends IncrementalProjectBuilder { 32 class DeltaVisitor implements IResourceDeltaVisitor { 33 private IProgressMonitor monitor; 34 public DeltaVisitor(IProgressMonitor monitor) { 35 this.monitor = monitor; 36 } 37 public boolean visit(IResourceDelta delta) { 38 IResource resource = delta.getResource(); 39 40 if (resource instanceof IProject) { 41 IProject project = (IProject) resource; 43 try { 44 return (project.hasNature(PDE.FEATURE_NATURE)); 45 } catch (CoreException e) { 46 PDECore.logException(e); 47 return false; 48 } 49 } 50 if (resource instanceof IFile) { 51 IFile candidate = (IFile) resource; 53 if (isManifestFile(candidate)) { 54 if (delta.getKind() != IResourceDelta.REMOVED) { 56 checkFile(candidate, monitor); 57 return true; 58 } 59 } 60 } 61 return false; 62 } 63 } 64 65 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) 66 throws CoreException { 67 if (PDECore.getDefault().getBundle().getState() != Bundle.ACTIVE || monitor.isCanceled()) 68 return new IProject[0]; 69 70 if (WorkspaceModelManager.isBinaryProject(getProject())) 71 return new IProject[0]; 72 73 IResourceDelta delta = null; 74 75 if (kind != FULL_BUILD) 76 delta = getDelta(getProject()); 77 78 if (delta == null || kind == FULL_BUILD) { 79 checkProject(monitor); 81 } else { 82 delta.accept(new DeltaVisitor(monitor)); 83 } 84 return new IProject[0]; 85 } 86 87 private void checkProject(IProgressMonitor monitor) { 88 IFile file = getProject().getFile("feature.xml"); if (file.exists()) { 90 checkFile(file, monitor); 91 } 92 } 93 94 private void checkFile(IFile file, IProgressMonitor monitor) { 95 String message = 96 NLS.bind(PDECoreMessages.Builders_verifying, file.getFullPath().toString()); 97 monitor.subTask(message); 98 FeatureErrorReporter reporter = new FeatureErrorReporter(file); 99 DefaultSAXParser.parse(file, reporter); 100 if (reporter.getErrorCount() == 0) { 101 reporter.validateContent(monitor); 102 } 103 monitor.subTask(PDECoreMessages.Builders_updating); 104 monitor.done(); 105 } 106 107 private boolean isManifestFile(IFile file) { 108 return file.getParent().equals(file.getProject()) 109 && file.getName().toLowerCase(Locale.ENGLISH).equals("feature.xml"); } 111 112 113 114 } 115 | Popular Tags |