1 package org.apache.maven.plugin.eclipse;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.Properties;
25
26 import org.codehaus.plexus.util.StringUtils;
27 import org.codehaus.plexus.util.xml.XMLWriter;
28 import org.codehaus.plexus.util.xml.Xpp3Dom;
29
30
31
32
33
34
35
36 public class BuildCommand
37 {
38
39 private String name;
40
41
42 private String triggers;
43
44
45 private Map arguments;
46
47
48
49
50 public BuildCommand()
51 {
52 }
53
54
55
56
57
58
59 public BuildCommand( String name )
60 {
61 this( name, null );
62 }
63
64 public BuildCommand( String name, Map arguments )
65 {
66 this.name = name;
67 this.arguments = arguments;
68 }
69
70 public BuildCommand( String name, String argName, String argValue )
71 {
72 this.name = name;
73 arguments = new Properties();
74 arguments.put( argName, argValue );
75 }
76
77
78
79
80
81
82
83
84 public BuildCommand( String name, String triggers, Map arguments )
85 {
86 if ( name == null )
87 {
88 throw new IllegalArgumentException( "Name must not be null." );
89 }
90
91 this.name = name;
92 this.triggers = triggers;
93
94 if ( arguments == null )
95 {
96 this.arguments = new HashMap();
97 }
98 else
99 {
100 this.arguments = new HashMap( arguments );
101 }
102
103 }
104
105
106
107
108
109
110
111
112 public BuildCommand( Xpp3Dom node )
113 {
114 Xpp3Dom nameNode = node.getChild( "name" );
115
116 if ( nameNode == null )
117 {
118 throw new IllegalArgumentException( "No name node." );
119 }
120
121 name = nameNode.getValue();
122
123 Xpp3Dom triggersNode = node.getChild( "triggers" );
124
125 if ( triggersNode != null )
126 {
127 triggers = triggersNode.getValue();
128 }
129
130 Xpp3Dom argumentsNode = node.getChild( "arguments" );
131
132 arguments = new HashMap();
133
134 if ( argumentsNode != null )
135 {
136 for ( int i = 0; i < argumentsNode.getChildCount(); ++i )
137 {
138 Xpp3Dom entry = argumentsNode.getChild( i );
139
140 if ( entry.getName().equals( "dictionary" ) )
141 {
142 Xpp3Dom key = entry.getChild( "key" );
143 Xpp3Dom value = entry.getChild( "value" );
144
145 if ( key != null && value != null )
146 {
147 this.arguments.put( key.getValue(), value.getValue() );
148 }
149 else
150 {
151
152 }
153 }
154 else
155 {
156
157 }
158 }
159 }
160 }
161
162 public void print( XMLWriter writer )
163 {
164 writer.startElement( "buildCommand" );
165 writer.startElement( "name" );
166 writer.writeText( name );
167 writer.endElement();
168
169 if ( !StringUtils.isEmpty( triggers ) )
170 {
171 writer.startElement( "triggers" );
172 writer.writeText( triggers );
173 writer.endElement();
174 }
175
176 if ( arguments != null && !arguments.isEmpty() )
177 {
178 writer.startElement( "arguments" );
179
180 writer.startElement( "dictionary" );
181
182 for ( Object o : arguments.keySet() )
183 {
184 String key = (String) o;
185
186 writer.startElement( "key" );
187 writer.writeText( key );
188 writer.endElement();
189
190 writer.startElement( "value" );
191 writer.writeText( (String) arguments.get( key ) );
192 writer.endElement();
193 }
194
195 writer.endElement();
196
197 writer.endElement();
198 }
199
200 writer.endElement();
201 }
202
203 public boolean equals( Object obj )
204 {
205 if ( obj instanceof BuildCommand )
206 {
207 BuildCommand b = (BuildCommand) obj;
208
209 return name.equals( b.name )
210 && ( triggers == null ? b.triggers == null : triggers.equals( b.triggers ) )
211 && ( arguments == null || arguments.isEmpty() ? b.arguments == null || b.arguments.isEmpty()
212 : arguments.equals( b.arguments ) );
213 }
214 else
215 {
216 return false;
217 }
218 }
219
220 public int hashCode()
221 {
222 return name.hashCode() + ( triggers == null ? 0 : 13 * triggers.hashCode() )
223 + ( arguments == null ? 0 : 17 * arguments.hashCode() );
224 }
225 }