KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
15 import org.eclipse.ant.core.AntCorePlugin;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.*;
19
20 /**
21  * An Ant task which refreshes the Eclipse Platform's view of the local filesystem.
22  *
23  * @see IResource#refreshLocal(int, IProgressMonitor)
24  */

25 public class RefreshLocalTask extends Task {
26     /**
27      * Unique identifier constant (value <code>"DEPTH_ZERO"</code>)
28      * indicating that refreshes should be performed only on the target
29      * resource itself
30      */

31     public static final String JavaDoc DEPTH_ZERO = "zero"; //$NON-NLS-1$
32

33     /**
34      * Unique identifier constant (value <code>"DEPTH_ONE"</code>)
35      * indicating that refreshes should be performed on the target
36      * resource and its children
37      */

38     public static final String JavaDoc DEPTH_ONE = "one"; //$NON-NLS-1$
39

40     /**
41      * Unique identifier constant (value <code>"DEPTH_INFINITE"</code>)
42      * indicating that refreshes should be performed on the target
43      * resource and all of its recursive children
44      */

45     public static final String JavaDoc DEPTH_INFINITE = "infinite"; //$NON-NLS-1$
46

47     /**
48      * The resource to refresh.
49      */

50     protected IResource resource;
51
52     /**
53      * The depth to refresh to.
54      */

55     protected int depth = IResource.DEPTH_INFINITE;
56
57     /**
58      * Constructs a new <code>RefreshLocal</code> instance.
59      */

60     public RefreshLocalTask() {
61         super();
62     }
63
64     /**
65      * Performs the refresh operation.
66      *
67      * @exception BuildException thrown if a problem occurs during execution.
68      */

69     public void execute() throws BuildException {
70         if (resource == null)
71             throw new BuildException(Policy.bind("exception.resourceNotSpecified")); //$NON-NLS-1$
72
try {
73             IProgressMonitor monitor = null;
74             Hashtable JavaDoc references = getProject().getReferences();
75             if (references != null)
76                 monitor = (IProgressMonitor) references.get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR);
77             resource.refreshLocal(depth, monitor);
78         } catch (CoreException e) {
79             throw new BuildException(e);
80         }
81     }
82
83     /**
84      * Sets the depth of this task appropriately. The specified argument must
85      * by one of <code>RefreshLocal.DEPTH_ZERO</code>, <code>RefreshLocal.DEPTH_ONE</code>
86      * or <code>RefreshLocal.DEPTH_INFINITE</code>.
87      *
88      * @param value the depth to refresh to
89      */

90     public void setDepth(String JavaDoc value) {
91         if (DEPTH_ZERO.equalsIgnoreCase(value))
92             depth = IResource.DEPTH_ZERO;
93         else if (DEPTH_ONE.equalsIgnoreCase(value))
94             depth = IResource.DEPTH_ONE;
95         else if (DEPTH_INFINITE.equalsIgnoreCase(value))
96             depth = IResource.DEPTH_INFINITE;
97     }
98
99     /**
100      * Sets the root of the workspace resource tree to refresh.
101      *
102      * @param value the root value
103      */

104     public void setResource(String JavaDoc value) {
105         IPath path = new Path(value);
106         resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
107         if (resource == null) {
108             // if it does not exist we guess it is a folder or a project
109
if (path.segmentCount() > 1)
110                 resource = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
111             else {
112                 resource = ResourcesPlugin.getWorkspace().getRoot().getProject(value);
113                 if (!resource.exists())
114                     log(Policy.bind("warning.projectDoesNotExist", value), Project.MSG_WARN); //$NON-NLS-1$
115
}
116         }
117     }
118
119 }
120
Popular Tags