KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > ant > IncrementalBuild


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.core.resources.ant;
12
13 import java.util.Hashtable JavaDoc;
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Task;
16 import org.eclipse.ant.core.AntCorePlugin;
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20
21 /**
22  * Ant task which runs the platform's incremental build facilities.
23  *
24  * @see IProject#build(int, IProgressMonitor)
25  * @see IWorkspace#build(int, IProgressMonitor)
26  */

27 public class IncrementalBuild extends Task {
28     private String JavaDoc builder;
29     private String JavaDoc project;
30     private int kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
31
32     /**
33      * Unique identifier constant (value <code>"incremental"</code>)
34      * indicating that an incremental build should be performed.
35      */

36     public final static String JavaDoc KIND_INCREMENTAL = "incremental"; //$NON-NLS-1$
37

38     /**
39      * Unique identifier constant (value <code>"full"</code>)
40      * indicating that a full build should be performed.
41      */

42     public final static String JavaDoc KIND_FULL = "full"; //$NON-NLS-1$
43

44     /**
45      * Unique identifier constant (value <code>"auto"</code>)
46      * indicating that an auto build should be performed.
47      */

48     public final static String JavaDoc KIND_AUTO = "auto"; //$NON-NLS-1$
49

50     /**
51      * Unique identifier constant (value <code>"clean"</code>)
52      * indicating that a CLEAN build should be performed.
53      */

54     public final static String JavaDoc KIND_CLEAN = "clean"; //$NON-NLS-1$
55

56     /**
57      * Constructs an <code>IncrementalBuild</code> instance.
58      */

59     public IncrementalBuild() {
60         super();
61     }
62
63     /**
64      * Executes this task.
65      *
66      * @exception BuildException thrown if a problem occurs during execution
67      */

68     public void execute() throws BuildException {
69         try {
70             IProgressMonitor monitor = null;
71             Hashtable JavaDoc references = getProject().getReferences();
72             if (references != null)
73                 monitor = (IProgressMonitor) references.get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
74             if (project == null) {
75                 ResourcesPlugin.getWorkspace().build(kind, monitor);
76             } else {
77                 IProject targetProject = ResourcesPlugin.getWorkspace().getRoot().getProject(project);
78                 if (builder == null)
79                     targetProject.build(kind, monitor);
80                 else
81                     targetProject.build(kind, builder, null, monitor);
82             }
83         } catch (CoreException e) {
84             throw new BuildException(e);
85         }
86     }
87
88     /**
89      * Sets the name of the receiver's builder.
90      *
91      * @param value the name of the receiver's builder
92      */

93     public void setBuilder(String JavaDoc value) {
94         builder = value;
95     }
96
97     /**
98      * Sets the receiver's kind> attribute. This value must be one
99      * of: <code>IncrementalBuild.KIND_FULL</code>,
100      * <code>IncrementalBuild.KIND_AUTO</code>,
101      * <code>IncrementalBuild.KIND_INCREMENTAL</code>,
102      * <code>IncrementalBuild.KIND_CLEAN</code>.
103      *
104      * @param value the receiver's kind attribute
105      */

106     public void setKind(String JavaDoc value) {
107         if (IncrementalBuild.KIND_FULL.equalsIgnoreCase(value))
108             kind = IncrementalProjectBuilder.FULL_BUILD;
109         else if (IncrementalBuild.KIND_AUTO.equalsIgnoreCase(value))
110             kind = IncrementalProjectBuilder.AUTO_BUILD;
111         else if (IncrementalBuild.KIND_CLEAN.equalsIgnoreCase(value))
112             kind = IncrementalProjectBuilder.CLEAN_BUILD;
113         else if (IncrementalBuild.KIND_INCREMENTAL.equalsIgnoreCase(value))
114             kind = IncrementalProjectBuilder.INCREMENTAL_BUILD;
115     }
116
117     /**
118      * Sets the receiver's target project.
119      *
120      * @param value the receiver's target project
121      */

122     public void setProject(String JavaDoc value) {
123         project = value;
124     }
125 }
126
Popular Tags