KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > tools > ComponentMetaAntTask


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package org.apache.avalon.fortress.tools;
20
21 import java.io.File JavaDoc;
22
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.Task;
26
27 import com.thoughtworks.qdox.ant.AbstractQdoxTask;
28
29 /**
30  * The Ant plugin to extract Fortress meta-data from Java sources.
31  *
32  * @author <a HREF="mailto:dev@excalibur.apache.org">The Excalibur Team</a>
33  * @version CVS $Revision: 1.1 $ $Date: 2005/12/25 08:29:44 $
34  */

35 public class ComponentMetaAntTask extends AbstractQdoxTask
36 {
37
38     /**
39      * Wrap the Ant logger
40      */

41     private class AntBuildLogger implements BuildLogger
42     {
43         private Task m_task;
44
45         private AntBuildLogger()
46         {
47             //Disallow use, mst use constructor below that supplies Ant data
48
}
49
50         public AntBuildLogger( Task task )
51         {
52             m_task = task;
53         }
54
55         public void debug( String JavaDoc message )
56         {
57             m_task.log( message, Project.MSG_DEBUG );
58         }
59
60         public void error( String JavaDoc message )
61         {
62             m_task.log( message, Project.MSG_ERR );
63         }
64
65         public void info( String JavaDoc message )
66         {
67             m_task.log( message, Project.MSG_INFO );
68         }
69
70         public void warn( String JavaDoc message )
71         {
72             m_task.log( message, Project.MSG_WARN );
73         }
74     }
75
76     /**
77      * The destination directory for metadata files.
78      */

79     private File JavaDoc m_destDir;
80
81     public void execute() throws BuildException
82     {
83
84         validate();
85
86         log( "Writing Info descriptors as property files (.meta)." );
87         super.execute();
88
89         ComponentMetaInfoCollector collector = new ComponentMetaInfoCollector( new AntBuildLogger( this ) );
90         collector.setAllClasses( allClasses );
91         collector.setDestDir( m_destDir );
92         try
93         {
94             collector.execute();
95         }
96         catch ( Exception JavaDoc e )
97         {
98             throw new BuildException( e.getMessage(), e );
99         }
100     }
101
102     /**
103      * Validate that the parameters are valid.
104      */

105     private void validate()
106     {
107         if ( null == m_destDir )
108         {
109             final String JavaDoc message = "DestDir (" + m_destDir + ") not specified";
110             throw new BuildException( message );
111         }
112
113         if ( !m_destDir.isDirectory() )
114         {
115             final String JavaDoc message = "DestDir (" + m_destDir + ") is not a directory.";
116             throw new BuildException( message );
117         }
118
119         if ( !m_destDir.exists() && !m_destDir.mkdirs() )
120         {
121             final String JavaDoc message = "DestDir (" + m_destDir + ") could not be created.";
122             throw new BuildException( message );
123         }
124     }
125
126     /**
127      * Set the destination directory for the meta information.
128      *
129      * @param destDir The destination directory
130      */

131     public void setDestDir( final File JavaDoc destDir )
132     {
133         m_destDir = destDir;
134     }
135
136 }
137
Popular Tags