Skip to content

Commit 859bbdb

Browse files
committed
fix:
1. add CHANGES.md 2. PropertyResolver code style format 3. Revoke configurations cause the line num to be disordered
1 parent 444ce9b commit 859bbdb

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Apollo 2.4.0
88
* [Update the server config link in system info page](https://github.com/apolloconfig/apollo/pull/5204)
99
* [Feature support portal restTemplate Client connection pool config](https://github.com/apolloconfig/apollo/pull/5200)
1010
* [Feature added the ability for administrators to globally search for Value](https://github.com/apolloconfig/apollo/pull/5182)
11-
11+
* [Fix: The problem of duplicate comments and blank lines](https://github.com/apolloconfig/apollo/pull/5232)
1212
------------------
13-
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
13+
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
5858
List<ItemDTO> baseCommentItems = new ArrayList<>();
5959
// blank items
6060
List<ItemDTO> baseBlankItems = new ArrayList<>();
61-
if(!CollectionUtils.isEmpty(baseItems)) {
61+
if (!CollectionUtils.isEmpty(baseItems)) {
6262

6363
baseCommentItems = baseItems.stream().filter(itemDTO -> isCommentItem(itemDTO)).sorted(Comparator.comparing(ItemDTO::getLineNum)).collect(Collectors.toList());
6464

@@ -81,7 +81,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
8181
//comment item
8282
if (isCommentItem(newItem)) {
8383
ItemDTO oldItemDTO = null;
84-
if(!CollectionUtils.isEmpty(baseCommentItems)) {
84+
if (!CollectionUtils.isEmpty(baseCommentItems)) {
8585
oldItemDTO = baseCommentItems.remove(0);
8686
}
8787

@@ -91,7 +91,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List<ItemDTO>
9191
} else if (isBlankItem(newItem)) {
9292

9393
ItemDTO oldItemDTO = null;
94-
if(!CollectionUtils.isEmpty(baseBlankItems)) {
94+
if (!CollectionUtils.isEmpty(baseBlankItems)) {
9595
oldItemDTO = baseBlankItems.remove(0);
9696
}
9797

@@ -119,7 +119,7 @@ private boolean isHasRepeatKey(String[] newItems, @NotNull Set<String> repeatKey
119119
String[] kv = parseKeyValueFromItem(item);
120120
if (kv != null) {
121121
String key = kv[0].toLowerCase();
122-
if(!keys.add(key)){
122+
if (!keys.add(key)) {
123123
repeatKeys.add(key);
124124
}
125125
} else {
@@ -144,17 +144,17 @@ private String[] parseKeyValueFromItem(String item) {
144144
}
145145

146146
private void handleCommentLine(Long namespaceId, ItemDTO oldItemByLine, String newItem, int lineCounter, ItemChangeSets changeSets) {
147-
if(null == oldItemByLine ){
147+
if (null == oldItemByLine) {
148148
changeSets.addCreateItem(buildCommentItem(0L, namespaceId, newItem, lineCounter));
149-
}else if(!StringUtils.equals(oldItemByLine.getComment(), newItem) || lineCounter != oldItemByLine.getLineNum()) {
149+
} else if (!StringUtils.equals(oldItemByLine.getComment(), newItem) || lineCounter != oldItemByLine.getLineNum()) {
150150
changeSets.addUpdateItem(buildCommentItem(oldItemByLine.getId(), namespaceId, newItem, lineCounter));
151151
}
152152
}
153153

154154
private void handleBlankLine(Long namespaceId, ItemDTO oldItem, int lineCounter, ItemChangeSets changeSets) {
155-
if(null == oldItem ){
155+
if (null == oldItem) {
156156
changeSets.addCreateItem(buildBlankItem(0L, namespaceId, lineCounter));
157-
}else if (lineCounter != oldItem.getLineNum()) {
157+
} else if (lineCounter != oldItem.getLineNum()) {
158158
changeSets.addUpdateItem(buildBlankItem(oldItem.getId(), namespaceId, lineCounter));
159159
}
160160
}
@@ -173,12 +173,12 @@ private void handleNormalLine(Long namespaceId, Map<String, ItemDTO> keyMapOldIt
173173

174174
ItemDTO oldItem = keyMapOldItem.get(newKey);
175175

176-
if (oldItem == null) {//new item
176+
//new item
177+
if (oldItem == null) {
177178
changeSets.addCreateItem(buildNormalItem(0L, namespaceId, newKey, newValue, "", lineCounter));
178-
} else if (!newValue.equals(oldItem.getValue()) || lineCounter != oldItem.getLineNum()) {//update item
179-
changeSets.addUpdateItem(
180-
buildNormalItem(oldItem.getId(), namespaceId, newKey, newValue, oldItem.getComment(),
181-
lineCounter));
179+
//update item
180+
} else if (!newValue.equals(oldItem.getValue()) || lineCounter != oldItem.getLineNum()) {
181+
changeSets.addUpdateItem(buildNormalItem(oldItem.getId(), namespaceId, newKey, newValue, oldItem.getComment(), lineCounter));
182182
}
183183
keyMapOldItem.remove(newKey);
184184
}
@@ -197,7 +197,7 @@ private boolean isBlankItem(ItemDTO item) {
197197
}
198198

199199
private boolean isBlankItem(String line) {
200-
return Strings.nullToEmpty(line).trim().isEmpty();
200+
return Strings.nullToEmpty(line).trim().isEmpty();
201201
}
202202

203203
private void deleteNormalKVItem(Map<String, ItemDTO> baseKeyMapItem, ItemChangeSets changeSets) {
@@ -210,8 +210,8 @@ private void deleteNormalKVItem(Map<String, ItemDTO> baseKeyMapItem, ItemChangeS
210210
private void deleteCommentAndBlankItem(List<ItemDTO> baseCommentItems,
211211
List<ItemDTO> baseBlankItems,
212212
ItemChangeSets changeSets) {
213-
baseCommentItems.forEach(oldItemDTO-> changeSets.addDeleteItem(oldItemDTO));
214-
baseBlankItems.forEach(oldItemDTO-> changeSets.addDeleteItem(oldItemDTO));
213+
baseCommentItems.forEach(oldItemDTO -> changeSets.addDeleteItem(oldItemDTO));
214+
baseBlankItems.forEach(oldItemDTO -> changeSets.addDeleteItem(oldItemDTO));
215215
}
216216

217217
private ItemDTO buildCommentItem(Long id, Long namespaceId, String comment, int lineNum) {

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,10 @@ public void revokeItem(String appId, Env env, String clusterName, String namespa
231231
ItemDTO oldItem = oldKeyMapItem.get(key);
232232
if (oldItem == null) {
233233
ItemDTO deletedItemDto = deletedItemDTOs.computeIfAbsent(key, k -> new ItemDTO());
234-
changeSets.addCreateItem(buildNormalItem(0L, namespaceId,key,value,deletedItemDto.getComment(),lineNum.get()));
235-
} else if (!oldItem.getValue().equals(value) || lineNum.get() != oldItem
236-
.getLineNum()) {
237-
changeSets.addUpdateItem(buildNormalItem(oldItem.getId(), namespaceId, key,
238-
value, oldItem.getComment(), lineNum.get()));
234+
int newLineNum = 0 == deletedItemDto.getLineNum() ? lineNum.get() : deletedItemDto.getLineNum();
235+
changeSets.addCreateItem(buildNormalItem(0L, namespaceId, key, value, deletedItemDto.getComment(), newLineNum));
236+
} else if (!oldItem.getValue().equals(value) || lineNum.get() != oldItem.getLineNum()) {
237+
changeSets.addUpdateItem(buildNormalItem(oldItem.getId(), namespaceId, key, value, oldItem.getComment(), oldItem.getLineNum()));
239238
}
240239
oldKeyMapItem.remove(key);
241240
lineNum.set(lineNum.get() + 1);

0 commit comments

Comments
 (0)