18
18
*/
19
19
package org .elasticsearch .action .admin .cluster .node .info ;
20
20
21
+ import org .elasticsearch .Version ;
22
+ import org .elasticsearch .common .Strings ;
21
23
import org .elasticsearch .common .io .stream .StreamInput ;
22
24
import org .elasticsearch .common .io .stream .StreamOutput ;
23
25
import org .elasticsearch .common .io .stream .Streamable ;
29
31
import java .io .Serializable ;
30
32
31
33
public class PluginInfo implements Streamable , Serializable , ToXContent {
34
+ public static final String DESCRIPTION_NOT_AVAILABLE = "No description found." ;
35
+ public static final String VERSION_NOT_AVAILABLE = "NA" ;
36
+
32
37
static final class Fields {
33
38
static final XContentBuilderString NAME = new XContentBuilderString ("name" );
34
39
static final XContentBuilderString DESCRIPTION = new XContentBuilderString ("description" );
35
40
static final XContentBuilderString URL = new XContentBuilderString ("url" );
36
41
static final XContentBuilderString JVM = new XContentBuilderString ("jvm" );
37
42
static final XContentBuilderString SITE = new XContentBuilderString ("site" );
43
+ static final XContentBuilderString VERSION = new XContentBuilderString ("version" );
38
44
}
39
45
40
46
private String name ;
41
47
private String description ;
42
48
private boolean site ;
43
49
private boolean jvm ;
50
+ private String version ;
44
51
45
52
public PluginInfo () {
46
53
}
@@ -52,12 +59,18 @@ public PluginInfo() {
52
59
* @param description Its description
53
60
* @param site true if it's a site plugin
54
61
* @param jvm true if it's a jvm plugin
62
+ * @param version Version number is applicable (NA otherwise)
55
63
*/
56
- public PluginInfo (String name , String description , boolean site , boolean jvm ) {
64
+ public PluginInfo (String name , String description , boolean site , boolean jvm , String version ) {
57
65
this .name = name ;
58
66
this .description = description ;
59
67
this .site = site ;
60
68
this .jvm = jvm ;
69
+ if (Strings .hasText (version )) {
70
+ this .version = version ;
71
+ } else {
72
+ this .version = VERSION_NOT_AVAILABLE ;
73
+ }
61
74
}
62
75
63
76
/**
@@ -91,7 +104,7 @@ public boolean isJvm() {
91
104
/**
92
105
* We compute the URL for sites: "/_plugin/" + name + "/"
93
106
*
94
- * @return
107
+ * @return relative URL for site plugin
95
108
*/
96
109
public String getUrl () {
97
110
if (site ) {
@@ -101,6 +114,13 @@ public String getUrl() {
101
114
}
102
115
}
103
116
117
+ /**
118
+ * @return Version number for the plugin
119
+ */
120
+ public String getVersion () {
121
+ return version ;
122
+ }
123
+
104
124
public static PluginInfo readPluginInfo (StreamInput in ) throws IOException {
105
125
PluginInfo info = new PluginInfo ();
106
126
info .readFrom (in );
@@ -113,6 +133,11 @@ public void readFrom(StreamInput in) throws IOException {
113
133
this .description = in .readString ();
114
134
this .site = in .readBoolean ();
115
135
this .jvm = in .readBoolean ();
136
+ if (in .getVersion ().onOrAfter (Version .V_1_0_0_RC2 )) {
137
+ this .version = in .readString ();
138
+ } else {
139
+ this .version = VERSION_NOT_AVAILABLE ;
140
+ }
116
141
}
117
142
118
143
@ Override
@@ -121,12 +146,16 @@ public void writeTo(StreamOutput out) throws IOException {
121
146
out .writeString (description );
122
147
out .writeBoolean (site );
123
148
out .writeBoolean (jvm );
149
+ if (out .getVersion ().onOrAfter (Version .V_1_0_0_RC2 )) {
150
+ out .writeString (version );
151
+ }
124
152
}
125
153
126
154
@ Override
127
155
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
128
156
builder .startObject ();
129
157
builder .field (Fields .NAME , name );
158
+ builder .field (Fields .VERSION , version );
130
159
builder .field (Fields .DESCRIPTION , description );
131
160
if (site ) {
132
161
builder .field (Fields .URL , getUrl ());
@@ -140,21 +169,31 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
140
169
141
170
@ Override
142
171
public boolean equals (Object o ) {
143
- if (this == o ) {
144
- return true ;
145
- }
146
- if (o == null || getClass () != o .getClass ()) {
147
- return false ;
148
- }
172
+ if (this == o ) return true ;
173
+ if (o == null || getClass () != o .getClass ()) return false ;
149
174
150
- PluginInfo p = (PluginInfo ) o ;
175
+ PluginInfo that = (PluginInfo ) o ;
151
176
152
- return name .equals (p .getName ());
177
+ if (!name .equals (that .name )) return false ;
178
+ if (version != null ? !version .equals (that .version ) : that .version != null ) return false ;
179
+
180
+ return true ;
153
181
}
154
182
155
183
@ Override
156
184
public int hashCode () {
157
185
return name .hashCode ();
158
186
}
159
187
188
+ @ Override
189
+ public String toString () {
190
+ final StringBuffer sb = new StringBuffer ("PluginInfo{" );
191
+ sb .append ("name='" ).append (name ).append ('\'' );
192
+ sb .append (", description='" ).append (description ).append ('\'' );
193
+ sb .append (", site=" ).append (site );
194
+ sb .append (", jvm=" ).append (jvm );
195
+ sb .append (", version='" ).append (version ).append ('\'' );
196
+ sb .append ('}' );
197
+ return sb .toString ();
198
+ }
160
199
}
0 commit comments