KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ecm > taskdefs > TempdirTask


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ecm.taskdefs;
31
32 /**
33  ** <p>Creates a temporary directory.</p>
34  **
35  ** <p><bold>Parameters</bold></p>
36  ** <tr>
37  ** <td><bold>Attributes</bold></td>
38  ** <td><bold>Description</bold></td>
39  ** <td><bold>Required</bold></td>
40  ** </tr>
41  ** <tr>
42  ** <td>dir</td>
43  ** <td>The property in which the directory name is stored.</td>
44  ** <td>Yes</td>
45  ** </tr>
46  **/

47 public class TempdirTask
48 extends org.apache.tools.ant.Task
49 {
50     //
51
private String JavaDoc _dirprop;
52
53     // default constructor
54
public
55     TempdirTask()
56     {
57         //
58
_dirprop = null;
59     }
60
61     //
62
// internal operations
63
//
64

65     // NOTE: check required attributes, properties, environment, ...
66
private void
67     validate()
68     throws org.apache.tools.ant.BuildException
69     {
70         String JavaDoc msg = "";
71
72         // check dir attribute
73
if ((_dirprop==null) || (_dirprop.equals(""))) {
74             msg = "dir attribute is missing";
75             throw new org.apache.tools.ant.BuildException(msg);
76         }
77     }
78
79     //
80
// attribute setters
81
//
82

83     final public void
84     setDir(String JavaDoc dirprop)
85     {
86         _dirprop = dirprop;
87     }
88
89     //
90
// org.apache.tools.ant.Task
91
//
92

93     final public void
94     execute()
95     throws org.apache.tools.ant.BuildException
96     {
97         validate();
98
99         // create a temporary directory
100
java.io.File JavaDoc tempdir = FileHelper.createTempDir();
101         String JavaDoc dirname = tempdir.getPath();
102
103         // set property
104
getProject().setProperty(_dirprop, dirname);
105     }
106 }
107
Popular Tags