1 package net.sourceforge.phpeclipse.wiki.builder;
3 import java.io.IOException;
6 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
7 import net.sourceforge.phpeclipse.wiki.export.WikiExporter;
8 import net.sourceforge.phpeclipse.wiki.preferences.Util;
10 import org.eclipse.core.internal.resources.Folder;
11 import org.eclipse.core.resources.ICommand;
12 import org.eclipse.core.resources.IFile;
13 import org.eclipse.core.resources.IFolder;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.IResourceDelta;
17 import org.eclipse.core.resources.IResourceDeltaVisitor;
18 import org.eclipse.core.resources.IncrementalProjectBuilder;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.NullProgressMonitor;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.ui.IWorkbench;
25 import org.eclipse.ui.PlatformUI;
27 public class WikiBuilder extends IncrementalProjectBuilder {
29 class WikiVisitor implements IResourceDeltaVisitor {
34 public WikiVisitor(String binBasePath, String srcBasePath) {
35 fBinBasePath = binBasePath;
36 fSrcBasePath = srcBasePath;
39 public boolean visit(IResourceDelta delta) {
40 IResource resource = delta.getResource();
42 System.out.println(resource.toString());
44 if (delta.getKind() == IResourceDelta.REMOVED && resource.getType() == IResource.FILE) {
45 // remove this file from the wiki publishing directory
46 String htmlName = Util.getHTMLFileName((IFile) resource, fBinBasePath, fSrcBasePath);
47 if (htmlName != null) {
48 java.io.File file = new java.io.File(htmlName);
55 //only interested in changed resources at this point (not added or removed)
56 if (delta.getKind() != IResourceDelta.CHANGED)
58 //only interested in content changes
59 if ((delta.getFlags() & IResourceDelta.CONTENT) == 0)
61 if (resource.getType() == IResource.FILE) {
62 CreatePageAction.createPage((IFile) resource);
68 public static final String BUILDER_ID = "net.sourceforge.phpeclipse.wiki.wikibuilder";
70 private static final boolean DEBUG = false;
72 private IProject fProject;
74 private IWorkbench workbench;
76 public WikiBuilder() {
77 workbench = PlatformUI.getWorkbench();
81 protected IProject[] build(int kind, Map args, IProgressMonitor _monitor) {
83 fProject = getProject();
84 ICommand[] commands = fProject.getDescription().getBuildSpec();
85 boolean found = false;
86 for (int i = 0; i < commands.length; i++) {
87 if (commands[i].getBuilderName().equals(BUILDER_ID)) {
92 // fProject.hasNature()
93 if (found && fProject != null && fProject.isAccessible()) {
96 _monitor = new NullProgressMonitor();
98 case INCREMENTAL_BUILD:
100 System.out.println("INCREMENTAL_BUILD requested");
104 // we don't need auto build, because on every save we create a new *.html file ?
107 System.out.println("AUTO_BUILD requested");
113 System.out.println("FULL_BUILD requested");
118 // unknown build kind requested;
120 // fProject.refreshLocal(1,_monitor);
122 } catch (Exception x) {
125 return new IProject[0];
128 private void fullBuild(IProgressMonitor monitor) throws CoreException, IOException {
130 WikiExporter wikiExporter = new WikiExporter();
131 String srcBasePath = Util.getProjectsWikiTextsPath(fProject);
132 String basePath = Util.getProjectsWikiOutputPath(fProject, WikiEditorPlugin.HTML_OUTPUT_PATH);
133 wikiExporter.export(fProject, basePath, srcBasePath, monitor);
134 } catch (IOException e) {
136 } catch (CoreException e) {
138 } catch (InstantiationException e) {
140 } catch (IllegalAccessException e) {
142 } catch (ClassNotFoundException e) {
147 private void incrementalBuild() throws CoreException, IOException {
148 IResourceDelta delta = getDelta(fProject);
149 String srcBasePath = Util.getProjectsWikiTextsPath(fProject);
150 String basePath = Util.getProjectsWikiOutputPath(fProject, WikiEditorPlugin.HTML_OUTPUT_PATH);
151 IResourceDeltaVisitor visitor = new WikiVisitor(basePath, srcBasePath);
153 delta.accept(visitor);