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