KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 public class UpdateSiteBuilder extends IncrementalProjectBuilder {
21     class DeltaVisitor implements IResourceDeltaVisitor {
22         private IProgressMonitor monitor;
23         public DeltaVisitor(IProgressMonitor monitor) {
24             this.monitor = monitor;
25         }
26         public boolean visit(IResourceDelta delta) {
27             IResource resource = delta.getResource();
28
29             if (resource instanceof IProject) {
30                 // Only check projects with feature nature
31
IProject project = (IProject) resource;
32                 try {
33                     return (project.hasNature(PDE.SITE_NATURE));
34                 } catch (CoreException e) {
35                     PDE.logException(e);
36                     return false;
37                 }
38             }
39             if (resource instanceof IFile) {
40                 // see if this is it
41
IFile candidate = (IFile) resource;
42                 if (candidate.getName().equals("site.xml")) { //$NON-NLS-1$
43
// That's it, but only check it if it has been added or changed
44
if (delta.getKind() != IResourceDelta.REMOVED) {
45                         checkFile(candidate, monitor);
46                         return true;
47                     }
48                 }
49             }
50             return true;
51         }
52     }
53
54     protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
55         throws CoreException {
56
57         IResourceDelta delta = null;
58         if (kind != FULL_BUILD)
59             delta = getDelta(getProject());
60
61         if (delta == null || kind == FULL_BUILD) {
62             // Full build
63
IProject project = getProject();
64             IFile file = project.getFile("site.xml"); //$NON-NLS-1$
65
if (file.exists()) {
66                 checkFile(file, monitor);
67             }
68         } else {
69             delta.accept(new DeltaVisitor(monitor));
70         }
71         return null;
72     }
73     
74     private void checkFile(IFile file, IProgressMonitor monitor) {
75         String JavaDoc message =
76             NLS.bind(PDEMessages.Builders_verifying, file.getFullPath().toString());
77         monitor.subTask(message);
78         UpdateSiteErrorReporter reporter = new UpdateSiteErrorReporter(file);
79         ValidatingSAXParser.parse(file, reporter);
80         if (reporter.getErrorCount() == 0) {
81             reporter.validateContent(monitor);
82         }
83         monitor.subTask(PDEMessages.Builders_updating);
84         monitor.done();
85     }
86     
87 }
88
Popular Tags