From ca7396b9e6815c2e70d410f3b634fc10528a65ec Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 30 Jul 2015 15:58:16 +0200 Subject: [PATCH] Add name to api/rules/list --- .../org/sonar/server/rule/ws/ListAction.java | 4 + .../sonar/server/rule/ws/ListActionTest.java | 6 +- .../main/gen-java/org/sonarqube/ws/Rules.java | 166 +++++++++++++++++- sonar-ws/src/main/protobuf/ws-rules.proto | 1 + 4 files changed, 171 insertions(+), 6 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java index 52be58caef3..8a4d5d0ce4c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/ListAction.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ListActionTest.java index fd9aea6d1eb..21578d44051 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ListActionTest.java @@ -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"); } } diff --git a/sonar-ws/src/main/gen-java/org/sonarqube/ws/Rules.java b/sonar-ws/src/main/gen-java/org/sonarqube/ws/Rules.java index 346793fee19..7786e5aa761 100644 --- a/sonar-ws/src/main/gen-java/org/sonarqube/ws/Rules.java +++ b/sonar-ws/src/main/gen-java/org/sonarqube/ws/Rules.java @@ -187,6 +187,20 @@ public final class Rules { */ com.google.protobuf.ByteString getInternalKeyBytes(); + + /** + * optional string name = 4; + */ + boolean hasName(); + /** + * optional string name = 4; + */ + java.lang.String getName(); + /** + * optional string name = 4; + */ + 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_; + /** + * optional string name = 4; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional string name = 4; + */ + 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; + } + } + /** + * optional string name = 4; + */ + 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_ = ""; + /** + * optional string name = 4; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional string name = 4; + */ + 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; + } + } + /** + * optional string name = 4; + */ + 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; + } + } + /** + * optional string name = 4; + */ + public Builder setName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + name_ = value; + onChanged(); + return this; + } + /** + * optional string name = 4; + */ + public Builder clearName() { + bitField0_ = (bitField0_ & ~0x00000008); + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * optional string name = 4; + */ + 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) diff --git a/sonar-ws/src/main/protobuf/ws-rules.proto b/sonar-ws/src/main/protobuf/ws-rules.proto index 264137d0935..43a04956ebb 100644 --- a/sonar-ws/src/main/protobuf/ws-rules.proto +++ b/sonar-ws/src/main/protobuf/ws-rules.proto @@ -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; -- 2.39.5