KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > jet > JETBuilder


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: JETBuilder.java,v 1.3 2005/06/08 06:15:56 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.jet;
18
19
20 import java.util.Map JavaDoc;
21
22 import org.eclipse.core.resources.IProject;
23 import org.eclipse.core.resources.IResourceDelta;
24 import org.eclipse.core.resources.IncrementalProjectBuilder;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.core.runtime.IProgressMonitor;
27 import org.eclipse.core.runtime.OperationCanceledException;
28
29
30 public class JETBuilder extends IncrementalProjectBuilder
31 {
32   /**
33    * Creates a new instances.
34    */

35   public JETBuilder()
36   {
37     super();
38   }
39
40   protected IProject[] build(int kind, Map JavaDoc arguments, IProgressMonitor monitor) throws CoreException
41   {
42     if (!getProject().exists())
43     {
44       return new IProject[0];
45     }
46     else
47     {
48       try
49       {
50         if (kind == FULL_BUILD)
51         {
52           fullBuild(monitor);
53         }
54         else
55         {
56           IResourceDelta delta = getDelta(getProject());
57           if (delta == null)
58           {
59             fullBuild(monitor);
60           }
61           else
62           {
63             incrementalBuild(delta, monitor);
64           }
65         }
66       }
67       catch (OperationCanceledException e)
68       {
69         // Do nothing for now, and avoid propagating the exception.
70
// How should builders handle cancel?
71
}
72
73       return null;
74     }
75   }
76
77   /**
78    * Does a full build.
79    */

80   protected void fullBuild(IProgressMonitor monitor) throws CoreException
81   {
82     JETNature nature = JETNature.getRuntime(getProject());
83     if (nature != null)
84     {
85       JETCompileTemplateOperation compileTemplateOperation =
86         new JETCompileTemplateOperation(getProject(), nature.getTemplateContainers());
87       compileTemplateOperation.setInBuild(true);
88       if (compileTemplateOperation.shouldCompile())
89       {
90         compileTemplateOperation.run(monitor);
91       }
92     }
93   }
94
95   /**
96    * Does an incremental build.
97    */

98   protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException
99   {
100     JETNature nature = JETNature.getRuntime(getProject());
101     if (nature != null)
102     {
103       if (delta.getKind() == IResourceDelta.ADDED ||
104             delta.getKind() == IResourceDelta.CHANGED ||
105             delta.getKind() == IResourceDelta.CONTENT ||
106             delta.getKind() == IResourceDelta.OPEN)
107       {
108         JETCompileTemplateOperation compileTemplateOperation =
109           new JETCompileTemplateOperation(getProject(), nature.getTemplateContainers());
110         compileTemplateOperation.setInBuild(true);
111         if (compileTemplateOperation.shouldCompile())
112         {
113           compileTemplateOperation.run(monitor);
114         }
115       }
116     }
117   }
118 }
119
Popular Tags