Skip to content

Commit 0eaef38

Browse files
committed
rework fix pmd systemprintln, guardlogstatement
1 parent 03f6849 commit 0eaef38

File tree

4 files changed

+79
-145
lines changed

4 files changed

+79
-145
lines changed

examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88
import java.io.FileNotFoundException;
99
import java.io.IOException;
1010
import java.util.Scanner;
11-
import java.util.logging.Level;
12-
import java.util.logging.Logger;
1311

1412
final class AuthenticationExample {
15-
private static final Logger LOGGER = Logger.getLogger(AuthenticationExample.class.getName());
1613

1714
private static final String SERVICE_ACCOUNT_KEY_PATH = "/path/to/sa_key.json";
1815
private static final String PRIVATE_KEY_PATH = "/path/to/private_key.pem";
1916
private static final String SERVICE_ACCOUNT_MAIL = "name-1234@sa.stackit.cloud";
2017

21-
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
18+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.SystemPrintln"})
2219
public static void main(String[] args) {
2320
/* OPTION 1: setting the paths to service account key (and private key) as configuration */
2421
try {
@@ -33,9 +30,7 @@ public static void main(String[] args) {
3330
ListOrganizationsResponse response =
3431
api.listOrganizations(null, SERVICE_ACCOUNT_MAIL, null, null, null);
3532

36-
if (LOGGER.isLoggable(Level.INFO)) {
37-
LOGGER.info(response.toString());
38-
}
33+
System.out.println(response.toString());
3934
} catch (ApiException | IOException e) {
4035
throw new IllegalStateException(e);
4136
}
@@ -57,9 +52,7 @@ public static void main(String[] args) {
5752
serviceAccountKeyContent.append(myReader.nextLine());
5853
}
5954
} catch (FileNotFoundException e) {
60-
if (LOGGER.isLoggable(Level.SEVERE)) {
61-
LOGGER.severe("File not found: " + serviceAccountKeyPath);
62-
}
55+
System.err.println("File not found: " + serviceAccountKeyPath);
6356
return;
6457
}
6558

@@ -72,9 +65,7 @@ public static void main(String[] args) {
7265
privateKeyContent.append(myReader.nextLine());
7366
}
7467
} catch (FileNotFoundException e) {
75-
if (LOGGER.isLoggable(Level.SEVERE)) {
76-
LOGGER.severe("File not found: " + privateKeyPath);
77-
}
68+
System.err.println("File not found: " + privateKeyPath);
7869
return;
7970
}
8071

@@ -93,9 +84,7 @@ public static void main(String[] args) {
9384
ListOrganizationsResponse response =
9485
api.listOrganizations(null, SERVICE_ACCOUNT_MAIL, null, null, null);
9586

96-
if (LOGGER.isLoggable(Level.INFO)) {
97-
LOGGER.info(response.toString());
98-
}
87+
System.out.println(response.toString());
9988
} catch (ApiException | IOException e) {
10089
throw new IllegalStateException(e);
10190
}
@@ -132,9 +121,7 @@ public static void main(String[] args) {
132121
ListOrganizationsResponse response =
133122
api.listOrganizations(null, SERVICE_ACCOUNT_MAIL, null, null, null);
134123

135-
if (LOGGER.isLoggable(Level.INFO)) {
136-
LOGGER.info(response.toString());
137-
}
124+
System.out.println(response.toString());
138125
} catch (ApiException | IOException e) {
139126
throw new IllegalStateException(e);
140127
}

examples/custom-http-client/src/main/java/cloud/stackit/sdk/customhttpclient/examples/CustomHttpClientExample.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import cloud.stackit.sdk.iaas.model.*;
88
import java.io.IOException;
99
import java.util.UUID;
10-
import java.util.logging.Level;
11-
import java.util.logging.Logger;
1210
import okhttp3.OkHttpClient;
1311

1412
/*
@@ -24,8 +22,8 @@
2422
*
2523
* */
2624
public class CustomHttpClientExample {
27-
private static final Logger LOGGER = Logger.getLogger(CustomHttpClientExample.class.getName());
2825

26+
@SuppressWarnings("PMD.SystemPrintln")
2927
public static void main(String[] args) throws IOException {
3028
// Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
3129
// STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
@@ -41,19 +39,17 @@ public static void main(String[] args) throws IOException {
4139
// the id of your STACKIT project, read from env var for this example
4240
String projectIdString = System.getenv("STACKIT_PROJECT_ID");
4341
if (projectIdString == null || projectIdString.isEmpty()) {
44-
LOGGER.severe("Environment variable 'STACKIT_PROJECT_ID' not found.");
42+
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
4543
return;
4644
}
4745
UUID projectId = UUID.fromString(projectIdString);
4846

4947
try {
5048
/* list all servers */
5149
ServerListResponse servers = iaasApi.listServers(projectId, false, null);
52-
if (LOGGER.isLoggable(Level.INFO)) {
53-
LOGGER.info("\nAvailable servers: ");
54-
for (Server server : servers.getItems()) {
55-
LOGGER.info("* " + server.getId() + " | " + server.getName());
56-
}
50+
System.out.println("\nAvailable servers: ");
51+
for (Server server : servers.getItems()) {
52+
System.out.println("* " + server.getId() + " | " + server.getName());
5753
}
5854
} catch (ApiException e) {
5955
throw new IllegalStateException(e);

0 commit comments

Comments
 (0)