Skip to content

Commit

Permalink
fix SonarCloud warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MCMicS committed Jan 16, 2023
1 parent 4a9830f commit 9fbf6c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Jenkins Plugin 0.13.15 for Jetbrains products
# Jenkins Plugin 0.13.16 for Jetbrains products
[![Build Status](https://app.travis-ci.com/MCMicS/jenkins-control-plugin.svg?branch=master)](https://app.travis-ci.com/MCMicS/jenkins-control-plugin)
[![Plugin Compatibility](https://github.com/MCMicS/jenkins-control-plugin/actions/workflows/compatibility.yml/badge.svg)](https://github.com/MCMicS/jenkins-control-plugin/actions/workflows/compatibility.yml)

Expand All @@ -19,7 +19,7 @@

### Current Release
* [Idea 2021.2 - 2022.1.4](../../releases/latest/download/jenkins-control-plugin-2021.2.zip)
* [Idea 2022.2 or newer](../../releases/download/v0.13.15-2/jenkins-control-plugin-2022.2.zip)
* [Idea 2022.2 or newer](../../releases/latest/download/jenkins-control-plugin-2022.2.zip)

[//]: # (* [Idea 2022.2 or newer](../../releases/latest/download/jenkins-control-plugin-2022.2.zip))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Jenkins createWorkspace(String jsonData) {
final JsonObject jsonObject = parseJson(jsonData);
final Optional<View> primaryView = Optional.ofNullable((JsonObject) jsonObject.get(PRIMARY_VIEW)).map(this::getView);

final String description = getStringOrDefaultForNull(jsonObject, SERVER_DESCRIPTION, StringUtils.EMPTY);
final String description = getNonNullStringOrDefaultForNull(jsonObject, SERVER_DESCRIPTION, StringUtils.EMPTY);
final String jenkinsUrl = getServerUrl(jsonObject);
final Jenkins jenkins = new Jenkins(description, jenkinsUrl);
primaryView.ifPresent(jenkins::setPrimaryView);
Expand Down Expand Up @@ -265,8 +265,8 @@ private JobType getJobType(@NotNull JsonObject jobObject) {

@NotNull
private Job getJob(JsonObject jsonObject) {
final String name = jsonObject.getString(createJsonKey(JOB_NAME));
final String fullName = getStringOrDefaultForNull(jsonObject, JOB_FULL_NAME, name);
final String name = getStringNonNull(jsonObject, JOB_NAME);
final String fullName = getNonNullStringOrDefaultForNull(jsonObject, JOB_FULL_NAME, name);
final JobType jobType = getJobType(jsonObject);
final String displayName = getDisplayName(jsonObject);
final String fullDisplayName = getFullDisplayName(jsonObject);
Expand Down Expand Up @@ -481,11 +481,10 @@ public List<String> getFillValueItems(String fillValueItemsData) {
return values;
}

@NotNull
private String getServerUrl(JsonObject jsonObject) {
private @NotNull String getServerUrl(JsonObject jsonObject) {
final Optional<View> primaryView = Optional.ofNullable((JsonObject) jsonObject.get(PRIMARY_VIEW)).map(this::getView);
final String primaryViewUrl = primaryView.map(View::getUrl).orElse(StringUtils.EMPTY);
return getStringOrDefaultForNull(jsonObject, SERVER_URL, primaryViewUrl);
return getNonNullStringOrDefaultForNull(jsonObject, SERVER_URL, primaryViewUrl);
}

@NotNull
Expand Down Expand Up @@ -533,4 +532,13 @@ private void checkJsonDataAndThrowExceptionIfNecessary(String jsonData) {
@Nullable String defaultValue) {
return Optional.ofNullable(jsonObject.getStringOrDefault(createJsonKey(key, defaultValue))).orElse(defaultValue);
}

private @NotNull String getNonNullStringOrDefaultForNull(JsonObject jsonObject, @NotNull String key,
@NotNull String defaultValue) {
return getStringOrDefaultForNull(jsonObject, key, defaultValue);
}

private @NotNull String getStringNonNull(JsonObject jsonObject, @NotNull String key) {
return Optional.ofNullable(jsonObject.getString(createJsonKey(key))).orElse(StringUtils.EMPTY);
}
}

0 comments on commit 9fbf6c8

Please sign in to comment.