1 11 package org.eclipse.pde.internal.core.builders; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.IResourceDelta; 19 import org.eclipse.core.resources.IResourceDeltaVisitor; 20 import org.eclipse.core.resources.IncrementalProjectBuilder; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.IProgressMonitor; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.pde.internal.core.PDECore; 25 import org.eclipse.pde.internal.core.natures.PDE; 26 import org.eclipse.pde.internal.core.PDECoreMessages; 27 28 public class UpdateSiteBuilder extends IncrementalProjectBuilder { 29 class DeltaVisitor implements IResourceDeltaVisitor { 30 private IProgressMonitor monitor; 31 public DeltaVisitor(IProgressMonitor monitor) { 32 this.monitor = monitor; 33 } 34 public boolean visit(IResourceDelta delta) { 35 IResource resource = delta.getResource(); 36 37 if (resource instanceof IProject) { 38 IProject project = (IProject) resource; 40 try { 41 return (project.hasNature(PDE.SITE_NATURE)); 42 } catch (CoreException e) { 43 PDECore.logException(e); 44 return false; 45 } 46 } 47 if (resource instanceof IFile) { 48 IFile candidate = (IFile) resource; 50 if (candidate.getName().equals("site.xml")) { if (delta.getKind() != IResourceDelta.REMOVED) { 53 checkFile(candidate, monitor); 54 return true; 55 } 56 } 57 } 58 return true; 59 } 60 } 61 62 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) 63 throws CoreException { 64 65 IResourceDelta delta = null; 66 if (kind != FULL_BUILD) 67 delta = getDelta(getProject()); 68 69 if (delta == null || kind == FULL_BUILD) { 70 IProject project = getProject(); 72 IFile file = project.getFile("site.xml"); if (file.exists()) { 74 checkFile(file, monitor); 75 } 76 } else { 77 delta.accept(new DeltaVisitor(monitor)); 78 } 79 return null; 80 } 81 82 private void checkFile(IFile file, IProgressMonitor monitor) { 83 String message = 84 NLS.bind(PDECoreMessages.Builders_verifying, file.getFullPath().toString()); 85 monitor.subTask(message); 86 UpdateSiteErrorReporter reporter = new UpdateSiteErrorReporter(file); 87 DefaultSAXParser.parse(file, reporter); 88 if (reporter.getErrorCount() == 0) { 89 reporter.validateContent(monitor); 90 } 91 monitor.subTask(PDECoreMessages.Builders_updating); 92 monitor.done(); 93 } 94 95 } 96 | Popular Tags |