KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > builders > ManifestConsistencyChecker


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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         // Ignore binary plug-in projects
32
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"); //$NON-NLS-1$
40
if (!file.exists())
41             file = project.getFile("fragment.xml"); //$NON-NLS-1$
42

43         if (file.exists()) {
44             checkFile(file, monitor);
45         } else {
46             IFile manifestFile = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
47
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 JavaDoc 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 JavaDoc message = NLS.bind(PDEMessages.Builders_verifying, file.getFullPath().toString());
70         monitor.subTask(message);
71
72         IFile bundleManifest = file.getProject().getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
73
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")) { //$NON-NLS-1$
79
reporter = new PluginErrorReporter(file);
80         } else if (file.getName().equals("fragment.xml")){ //$NON-NLS-1$
81
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