1
2
3
4
5
6
7
8 package org.codehaus.metaclass.tools.tasks;
9
10 import org.apache.tools.ant.BuildException;
11 import org.apache.tools.ant.Project;
12 import org.apache.tools.ant.Task;
13
14 /***
15 * An ant task to add one plugin set to another.
16 *
17 * @author Peter Donald
18 * @version $Revision: 1.3 $ $Date: 2003/11/29 09:28:02 $
19 */
20 public abstract class AddToPluginSetTask
21 extends Task
22 {
23 /*** The rexpected type of plugin. */
24 private Class m_type;
25
26 /*** The PluginSet that will be added to. */
27 private String m_dest;
28
29 /*** The PluginSet that will be added. */
30 private String m_source;
31
32 /***
33 * Create task.
34 *
35 * @param type the expected type of PluginSet.
36 */
37 AddToPluginSetTask( final Class type )
38 {
39 m_type = type;
40 }
41
42 /***
43 * Set the dest for PluginSet to add to.
44 *
45 * @param dest the dest for PluginSet to add to.
46 */
47 public void setDest( final String dest )
48 {
49 m_dest = dest;
50 }
51
52 /***
53 * Set the id of PluginSet that will be added.
54 *
55 * @param source the id of PluginSet that will be added.
56 */
57 public void setSource( final String source )
58 {
59 m_source = source;
60 }
61
62 /***
63 * Join PluginSets.
64 *
65 * @throws BuildException if bad ids specified
66 */
67 public void execute()
68 throws BuildException
69 {
70 validate();
71 final Object destObject = getProject().getReference( m_dest );
72 final Object sourceObject = getProject().getReference( m_source );
73 if( !m_type.isInstance( destObject ) )
74 {
75 final String message =
76 "Object referenced by dest is not a " +
77 m_type.getName();
78 throw new BuildException( message );
79 }
80 if( !m_type.isInstance( sourceObject ) )
81 {
82 final String message =
83 "Object referenced by source is not a " +
84 m_type.getName();
85 throw new BuildException( message );
86 }
87
88 final PluginSet base = (PluginSet)destObject;
89 final PluginSet other = (PluginSet)sourceObject;
90 log( "Adding " + other + " to " + base, Project.MSG_DEBUG );
91 base.addPluginSet( other );
92 }
93
94 /***
95 * Validate correct attributes have been specified.
96 */
97 void validate()
98 {
99 if( null == m_dest )
100 {
101 throw new BuildException( "dest not specified" );
102 }
103 if( null == m_source )
104 {
105 throw new BuildException( "source not specified" );
106 }
107 }
108 }