KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 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                 // Only check projects with feature nature
33
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                 // see if this is it
43
IFile candidate = (IFile) resource;
44                 if (isManifestFile(candidate)) {
45                     // That's it, but only check it if it has been added or changed
46
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             // Full build
71
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"); //$NON-NLS-1$
80
if (file.exists()) {
81             checkFile(file, monitor);
82         }
83     }
84     
85     private void checkFile(IFile file, IProgressMonitor monitor) {
86         String JavaDoc 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"); //$NON-NLS-1$
101
}
102     
103
104     
105 }
106
Popular Tags