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.Iterator; |
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 | 0 | { |
52 | 0 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public BuildCommand( String name ) |
60 | |
{ |
61 | 0 | this( name, null ); |
62 | 0 | } |
63 | |
|
64 | |
public BuildCommand( String name, Map arguments ) |
65 | 0 | { |
66 | 0 | this.name = name; |
67 | 0 | this.arguments = arguments; |
68 | 0 | } |
69 | |
|
70 | |
public BuildCommand( String name, String argName, String argValue ) |
71 | 4 | { |
72 | 4 | this.name = name; |
73 | 4 | arguments = new Properties(); |
74 | 4 | arguments.put( argName, argValue ); |
75 | 4 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public BuildCommand( String name, String triggers, Map arguments ) |
85 | 40 | { |
86 | 40 | if ( name == null ) |
87 | |
{ |
88 | 0 | throw new IllegalArgumentException( "Name must not be null." ); |
89 | |
} |
90 | |
|
91 | 40 | this.name = name; |
92 | 40 | this.triggers = triggers; |
93 | |
|
94 | 40 | if ( arguments == null ) |
95 | |
{ |
96 | 12 | this.arguments = new HashMap(); |
97 | |
} |
98 | |
else |
99 | |
{ |
100 | 28 | this.arguments = new HashMap( arguments ); |
101 | |
} |
102 | |
|
103 | 40 | } |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public BuildCommand( Xpp3Dom node ) |
113 | 0 | { |
114 | 0 | Xpp3Dom nameNode = node.getChild( "name" ); |
115 | |
|
116 | 0 | if ( nameNode == null ) |
117 | |
{ |
118 | 0 | throw new IllegalArgumentException( "No name node." ); |
119 | |
} |
120 | |
|
121 | 0 | name = nameNode.getValue(); |
122 | |
|
123 | 0 | Xpp3Dom triggersNode = node.getChild( "triggers" ); |
124 | |
|
125 | 0 | if ( triggersNode != null ) |
126 | |
{ |
127 | 0 | triggers = triggersNode.getValue(); |
128 | |
} |
129 | |
|
130 | 0 | Xpp3Dom argumentsNode = node.getChild( "arguments" ); |
131 | |
|
132 | 0 | arguments = new HashMap(); |
133 | |
|
134 | 0 | if ( argumentsNode != null ) |
135 | |
{ |
136 | 0 | for ( int i = 0; i < argumentsNode.getChildCount(); ++i ) |
137 | |
{ |
138 | 0 | Xpp3Dom entry = argumentsNode.getChild( i ); |
139 | |
|
140 | 0 | if ( entry.getName().equals( "dictionary" ) ) |
141 | |
{ |
142 | 0 | Xpp3Dom key = entry.getChild( "key" ); |
143 | 0 | Xpp3Dom value = entry.getChild( "value" ); |
144 | |
|
145 | 0 | if ( key != null && value != null ) |
146 | |
{ |
147 | 0 | this.arguments.put( key.getValue(), value.getValue() ); |
148 | |
} |
149 | |
else |
150 | |
{ |
151 | |
|
152 | |
} |
153 | |
} |
154 | |
else |
155 | |
{ |
156 | |
|
157 | |
} |
158 | |
} |
159 | |
} |
160 | 0 | } |
161 | |
|
162 | |
public void print( XMLWriter writer ) |
163 | |
{ |
164 | 0 | writer.startElement( "buildCommand" ); |
165 | 0 | writer.startElement( "name" ); |
166 | 0 | writer.writeText( name ); |
167 | 0 | writer.endElement(); |
168 | |
|
169 | 0 | if ( !StringUtils.isEmpty( triggers ) ) |
170 | |
{ |
171 | 0 | writer.startElement( "triggers" ); |
172 | 0 | writer.writeText( triggers ); |
173 | 0 | writer.endElement(); |
174 | |
} |
175 | |
|
176 | 0 | if ( arguments != null && !arguments.isEmpty() ) |
177 | |
{ |
178 | 0 | writer.startElement( "arguments" ); |
179 | |
|
180 | 0 | writer.startElement( "dictionary" ); |
181 | |
|
182 | 0 | for ( Iterator it = arguments.keySet().iterator(); it.hasNext(); ) |
183 | |
{ |
184 | 0 | String key = (String) it.next(); |
185 | |
|
186 | 0 | writer.startElement( "key" ); |
187 | 0 | writer.writeText( key ); |
188 | 0 | writer.endElement(); |
189 | |
|
190 | 0 | writer.startElement( "value" ); |
191 | 0 | writer.writeText( (String) arguments.get( key ) ); |
192 | 0 | writer.endElement(); |
193 | |
} |
194 | |
|
195 | 0 | writer.endElement(); |
196 | |
|
197 | 0 | writer.endElement(); |
198 | |
} |
199 | |
|
200 | 0 | writer.endElement(); |
201 | 0 | } |
202 | |
|
203 | |
public boolean equals( Object obj ) |
204 | |
{ |
205 | 48 | if ( obj instanceof BuildCommand ) |
206 | |
{ |
207 | 48 | BuildCommand b = (BuildCommand) obj; |
208 | |
|
209 | 48 | 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 | 0 | return false; |
217 | |
} |
218 | |
} |
219 | |
|
220 | |
public int hashCode() |
221 | |
{ |
222 | 0 | return name.hashCode() + ( triggers == null ? 0 : 13 * triggers.hashCode() ) |
223 | |
+ ( arguments == null ? 0 : 17 * arguments.hashCode() ); |
224 | |
} |
225 | |
} |