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