Browse Source

Add name to api/rules/list

tags/5.2-RC1
Simon Brandhof 8 years ago
parent
commit
ca7396b9e6

+ 4
- 0
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java View File

@@ -63,6 +63,10 @@ public class ListAction implements RulesWsAction {
.clear()
.setRepository(dto.getRepositoryKey())
.setKey(dto.getRuleKey());
String name = dto.getName();
if (!Strings.isNullOrEmpty(name)) {
ruleBuilder.setName(name);
}
String internalKey = dto.getConfigKey();
if (!Strings.isNullOrEmpty(internalKey)) {
ruleBuilder.setInternalKey(internalKey);

+ 4
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ListActionTest.java View File

@@ -50,8 +50,8 @@ public class ListActionTest {

@Test
public void return_rules_in_protobuf() throws Exception {
dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), RuleTesting.newDto(RuleKey.of("java", "S001")).setConfigKey(null));
dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), RuleTesting.newDto(RuleKey.of("java", "S002")).setConfigKey("I002"));
dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), RuleTesting.newDto(RuleKey.of("java", "S001")).setConfigKey(null).setName(null));
dbTester.getDbClient().ruleDao().insert(dbTester.getSession(), RuleTesting.newDto(RuleKey.of("java", "S002")).setConfigKey("I002").setName("Rule Two"));
dbTester.getSession().commit();

TestResponse response = tester.newRequest()
@@ -64,7 +64,9 @@ public class ListActionTest {

assertThat(listResponse.getRules(0).getKey()).isEqualTo("S001");
assertThat(listResponse.getRules(0).hasInternalKey()).isFalse();
assertThat(listResponse.getRules(0).hasName()).isFalse();
assertThat(listResponse.getRules(1).getKey()).isEqualTo("S002");
assertThat(listResponse.getRules(1).getInternalKey()).isEqualTo("I002");
assertThat(listResponse.getRules(1).getName()).isEqualTo("Rule Two");
}
}

+ 162
- 4
sonar-ws/src/main/gen-java/org/sonarqube/ws/Rules.java View File

@@ -187,6 +187,20 @@ public final class Rules {
*/
com.google.protobuf.ByteString
getInternalKeyBytes();

/**
* <code>optional string name = 4;</code>
*/
boolean hasName();
/**
* <code>optional string name = 4;</code>
*/
java.lang.String getName();
/**
* <code>optional string name = 4;</code>
*/
com.google.protobuf.ByteString
getNameBytes();
}
/**
* Protobuf type {@code sonarqube.ws.rules.ListResponse.Rule}
@@ -258,6 +272,12 @@ public final class Rules {
internalKey_ = bs;
break;
}
case 34: {
com.google.protobuf.ByteString bs = input.readBytes();
bitField0_ |= 0x00000008;
name_ = bs;
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -424,10 +444,53 @@ public final class Rules {
}
}

public static final int NAME_FIELD_NUMBER = 4;
private java.lang.Object name_;
/**
* <code>optional string name = 4;</code>
*/
public boolean hasName() {
return ((bitField0_ & 0x00000008) == 0x00000008);
}
/**
* <code>optional string name = 4;</code>
*/
public java.lang.String getName() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
}
}
/**
* <code>optional string name = 4;</code>
*/
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}

private void initFields() {
repository_ = "";
key_ = "";
internalKey_ = "";
name_ = "";
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
@@ -451,6 +514,9 @@ public final class Rules {
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeBytes(3, getInternalKeyBytes());
}
if (((bitField0_ & 0x00000008) == 0x00000008)) {
output.writeBytes(4, getNameBytes());
}
getUnknownFields().writeTo(output);
}

@@ -472,6 +538,10 @@ public final class Rules {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(3, getInternalKeyBytes());
}
if (((bitField0_ & 0x00000008) == 0x00000008)) {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(4, getNameBytes());
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
@@ -595,6 +665,8 @@ public final class Rules {
bitField0_ = (bitField0_ & ~0x00000002);
internalKey_ = "";
bitField0_ = (bitField0_ & ~0x00000004);
name_ = "";
bitField0_ = (bitField0_ & ~0x00000008);
return this;
}

@@ -635,6 +707,10 @@ public final class Rules {
to_bitField0_ |= 0x00000004;
}
result.internalKey_ = internalKey_;
if (((from_bitField0_ & 0x00000008) == 0x00000008)) {
to_bitField0_ |= 0x00000008;
}
result.name_ = name_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
@@ -666,6 +742,11 @@ public final class Rules {
internalKey_ = other.internalKey_;
onChanged();
}
if (other.hasName()) {
bitField0_ |= 0x00000008;
name_ = other.name_;
onChanged();
}
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
@@ -921,6 +1002,82 @@ public final class Rules {
return this;
}

private java.lang.Object name_ = "";
/**
* <code>optional string name = 4;</code>
*/
public boolean hasName() {
return ((bitField0_ & 0x00000008) == 0x00000008);
}
/**
* <code>optional string name = 4;</code>
*/
public java.lang.String getName() {
java.lang.Object ref = name_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>optional string name = 4;</code>
*/
public com.google.protobuf.ByteString
getNameBytes() {
java.lang.Object ref = name_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
name_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string name = 4;</code>
*/
public Builder setName(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000008;
name_ = value;
onChanged();
return this;
}
/**
* <code>optional string name = 4;</code>
*/
public Builder clearName() {
bitField0_ = (bitField0_ & ~0x00000008);
name_ = getDefaultInstance().getName();
onChanged();
return this;
}
/**
* <code>optional string name = 4;</code>
*/
public Builder setNameBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
bitField0_ |= 0x00000008;
name_ = value;
onChanged();
return this;
}

// @@protoc_insertion_point(builder_scope:sonarqube.ws.rules.ListResponse.Rule)
}

@@ -1501,11 +1658,12 @@ public final class Rules {
descriptor;
static {
java.lang.String[] descriptorData = {
"\n\016ws-rules.proto\022\022sonarqube.ws.rules\"\203\001\n" +
"\n\016ws-rules.proto\022\022sonarqube.ws.rules\"\221\001\n" +
"\014ListResponse\0224\n\005rules\030\001 \003(\0132%.sonarqube" +
".ws.rules.ListResponse.Rule\032=\n\004Rule\022\022\n\nr" +
".ws.rules.ListResponse.Rule\032K\n\004Rule\022\022\n\nr" +
"epository\030\001 \001(\t\022\013\n\003key\030\002 \001(\t\022\024\n\014internal" +
"_key\030\003 \001(\tB\033\n\020org.sonarqube.wsB\005RulesH\001"
"_key\030\003 \001(\t\022\014\n\004name\030\004 \001(\tB\033\n\020org.sonarqub" +
"e.wsB\005RulesH\001"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -1530,7 +1688,7 @@ public final class Rules {
internal_static_sonarqube_ws_rules_ListResponse_Rule_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_sonarqube_ws_rules_ListResponse_Rule_descriptor,
new java.lang.String[] { "Repository", "Key", "InternalKey", });
new java.lang.String[] { "Repository", "Key", "InternalKey", "Name", });
}

// @@protoc_insertion_point(outer_class_scope)

+ 1
- 0
sonar-ws/src/main/protobuf/ws-rules.proto View File

@@ -31,6 +31,7 @@ message ListResponse {
optional string repository = 1;
optional string key = 2;
optional string internal_key = 3;
optional string name = 4;
}

repeated Rule rules = 1;

Loading…
Cancel
Save