Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 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; |
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.*; |
19 |
|
20 |
/** |
21 |
* An Ant task which sets derived flag for the given resource. |
22 |
* |
23 |
* @see IResource#setDerived(boolean, IProgressMonitor) |
24 |
*/ |
25 |
public class SetDerived extends Task { |
26 |
private boolean derived = true; |
27 |
private boolean recurse = false; |
28 |
private IPath resourcePath = null; |
29 |
|
30 |
public SetDerived() { |
31 |
super(); |
32 |
} |
33 |
|
34 |
private void setDerived(IResource resource, IProgressMonitor monitor) throws CoreException { |
35 |
resource.setDerived(derived, monitor); |
36 |
if (recurse && (resource instanceof IContainer)) { |
37 |
IResource members[] = ((IContainer) resource).members(); |
38 |
for (int i = 0; i < members.length; i++) { |
39 |
setDerived(members[i], monitor); |
40 |
} |
41 |
} |
42 |
} |
43 |
|
44 |
/** |
45 |
* Executes this task. |
46 |
* |
47 |
* @exception BuildException thrown if a problem occurs during execution. |
48 |
*/ |
49 |
public void execute() throws BuildException { |
50 |
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath); |
51 |
if (resource == null) |
52 |
throw new BuildException(Policy.bind("exception.resourceNotSpecified", "eclipse.setDerived")); //$NON-NLS-1$ //$NON-NLS-2$ |
53 |
try { |
54 |
IProgressMonitor monitor = null; |
55 |
Hashtable references = getProject().getReferences(); |
56 |
if (references != null) |
57 |
monitor = (IProgressMonitor) references.get(AntCorePlugin.ECLIPSE_PROGRESS_MONITOR); |
58 |
setDerived(resource, monitor); |
59 |
} catch (CoreException e) { |
60 |
throw new BuildException(e); |
61 |
} |
62 |
} |
63 |
|
64 |
/** |
65 |
* Sets the derived flag to be used in this task. |
66 |
* |
67 |
* @param value the derived value |
68 |
*/ |
69 |
public void setDerived(String value) { |
70 |
derived = Boolean.parseBoolean(value); |
71 |
} |
72 |
|
73 |
/** |
74 |
* Sets the recurse flag. If <code>true</code> then derived flag will be set for the given resource and all its children. If <code>false</code> then it will be set only for the given resource. |
75 |
* |
76 |
* @param value the recurse value |
77 |
*/ |
78 |
public void setRecurse(String value) { |
79 |
recurse = Boolean.parseBoolean(value); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Sets the resource path for which {@link IResource#setDerived(boolean, IProgressMonitor)} will be called. |
84 |
* |
85 |
* @param value the resource path |
86 |
*/ |
87 |
public void setResourcePath(String value) { |
88 |
resourcePath = new Path(value); |
89 |
} |
90 |
} |