KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > builders > UpdateSiteBuilder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.core.builders;
12
13 import java.util.Map JavaDoc;
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                 // Only check projects with feature nature
39
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                 // see if this is it
49
IFile candidate = (IFile) resource;
50                 if (candidate.getName().equals("site.xml")) { //$NON-NLS-1$
51
// That's it, but only check it if it has been added or changed
52
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 JavaDoc 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             // Full build
71
IProject project = getProject();
72             IFile file = project.getFile("site.xml"); //$NON-NLS-1$
73
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 JavaDoc 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