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 ManifestConsistencyChecker extends IncrementalProjectBuilder { 23 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) 24 throws CoreException { 25 26 if (PDECore.getDefault().getBundle().getState() != Bundle.ACTIVE || monitor.isCanceled()) 27 return new IProject[0]; 28 29 IProject project = getProject(); 30 31 if (!WorkspaceModelManager.isBinaryPluginProject(project)) 33 checkThisProject(monitor); 34 return new IProject[0]; 35 } 36 37 private void checkThisProject(IProgressMonitor monitor) { 38 IProject project = getProject(); 39 IFile file = project.getFile("plugin.xml"); if (!file.exists()) 41 file = project.getFile("fragment.xml"); 43 if (file.exists()) { 44 checkFile(file, monitor); 45 } else { 46 IFile manifestFile = project.getFile("META-INF/MANIFEST.MF"); if (manifestFile.exists()) 48 checkManifestFileOnly(manifestFile, monitor); 49 } 50 } 51 52 private void checkManifestFileOnly(IFile file, IProgressMonitor monitor) { 53 if (monitor.isCanceled()) 54 return; 55 String message = NLS.bind(PDEMessages.Builders_verifying, file.getFullPath().toString()); 56 monitor.subTask(message); 57 58 BundleErrorReporter reporter = new BundleErrorReporter(file); 59 if (reporter != null) { 60 reporter.validateContent(monitor); 61 monitor.subTask(PDEMessages.Builders_updating); 62 } 63 monitor.done(); 64 } 65 66 private void checkFile(IFile file, IProgressMonitor monitor) { 67 if (monitor.isCanceled()) 68 return; 69 String message = NLS.bind(PDEMessages.Builders_verifying, file.getFullPath().toString()); 70 monitor.subTask(message); 71 72 IFile bundleManifest = file.getProject().getFile("META-INF/MANIFEST.MF"); XMLErrorReporter reporter = null; 74 BundleErrorReporter bundleReporter = null; 75 if (bundleManifest.exists()) { 76 reporter = new ExtensionsErrorReporter(file); 77 bundleReporter = new BundleErrorReporter(bundleManifest); 78 } else if (file.getName().equals("plugin.xml")) { reporter = new PluginErrorReporter(file); 80 } else if (file.getName().equals("fragment.xml")){ reporter = new FragmentErrorReporter(file); 82 } 83 if (reporter != null) { 84 ValidatingSAXParser.parse(file, reporter); 85 reporter.validateContent(monitor); 86 monitor.subTask(PDEMessages.Builders_updating); 87 } 88 if (bundleReporter != null) { 89 bundleReporter.validateContent(monitor); 90 monitor.subTask(PDEMessages.Builders_updating); 91 } 92 monitor.done(); 93 } 94 95 } 96 | Popular Tags |