Line | |
---|
1 | package ise.antelope.tasks;
|
---|
2 |
|
---|
3 | import ise.antelope.tasks.typedefs.*;
|
---|
4 |
|
---|
5 | import java.rmi.server.ObjID;
|
---|
6 | import java.rmi.server.UID;
|
---|
7 | import org.apache.tools.ant.BuildException;
|
---|
8 |
|
---|
9 | import org.apache.tools.ant.Task;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * A task to generate a unique ID.
|
---|
13 | *
|
---|
14 | * @author Dale Anson, [email protected]
|
---|
15 | * @since Ant 1.6
|
---|
16 | * @version $Revision: 1.1 $
|
---|
17 | */
|
---|
18 | public class UIDTask extends Task {
|
---|
19 |
|
---|
20 |
|
---|
21 | private String name = null;
|
---|
22 | private boolean asInt = false;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * @param n a name for this UID
|
---|
26 | */
|
---|
27 | public void setName(String n) {
|
---|
28 | name = n;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void setInt(boolean b) {
|
---|
32 | asInt = b;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /** Generate a unique id and store it in the project with the given name. */
|
---|
36 | public void execute() {
|
---|
37 | if (name == null)
|
---|
38 | throw new BuildException("name attribute cannot be null");
|
---|
39 | if (asInt)
|
---|
40 | getProject().setProperty(name, String.valueOf(new ObjID().hashCode()));
|
---|
41 | else
|
---|
42 | getProject().setProperty(name, new UID().toString());
|
---|
43 | }
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.