Skip to content

Commit b972042

Browse files
committed
chore(micronauts): Fix CheckStyle, Idea's and Sonar's issues
1 parent 77ae6c1 commit b972042

29 files changed

+818
-562
lines changed

src/main/java/org/terasology/Application.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
3+
14
package org.terasology;
25

36
import io.micronaut.runtime.Micronaut;
47

5-
public class Application {
8+
public final class Application {
9+
private Application() {
10+
}
611

712
public static void main(String[] args) {
813
Micronaut.run(Application.class, args);

src/main/java/org/terasology/module/RemoteModuleExtension.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,11 @@ public enum RemoteModuleExtension {
3131
private final String key;
3232
private final Class<?> valueType;
3333

34-
private RemoteModuleExtension(String key, Class<?> valueType) {
34+
RemoteModuleExtension(String key, Class<?> valueType) {
3535
this.key = key;
3636
this.valueType = valueType;
3737
}
3838

39-
public String getKey() {
40-
return key;
41-
}
42-
43-
public Class<?> getValueType() {
44-
return valueType;
45-
}
46-
4739
public static URL getDownloadUrl(ModuleMetadata meta) {
4840
return meta.getExtension(DOWNLOAD_URL.getKey(), URL.class);
4941
}
@@ -67,4 +59,12 @@ public static long getArtifactSize(ModuleMetadata meta) {
6759
public static void setArtifactSize(ModuleMetadata meta, long size) {
6860
meta.setExtension(ARTIFACT_SIZE.getKey(), size);
6961
}
62+
63+
public String getKey() {
64+
return key;
65+
}
66+
67+
public Class<?> getValueType() {
68+
return valueType;
69+
}
7070
}

src/main/java/org/terasology/web/controllers/ModuleController.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2015 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163

174
package org.terasology.web.controllers;
185

@@ -40,7 +27,13 @@
4027
import org.terasology.web.version.VersionInfo;
4128

4229
import java.net.URI;
43-
import java.util.*;
30+
import java.util.ArrayList;
31+
import java.util.Collection;
32+
import java.util.Collections;
33+
import java.util.Comparator;
34+
import java.util.List;
35+
import java.util.Map;
36+
import java.util.Set;
4437

4538
/**
4639
* TODO Type description
@@ -72,7 +65,7 @@ public ModuleController(
7265

7366
@Get("show")
7467
@View("module-list")
75-
public HttpResponse show() {
68+
public HttpResponse<Map<Object, Object>> show() {
7669
logger.info("Requested module list as HTML");
7770

7871
Set<Name> names = model.getModuleIds();
@@ -93,7 +86,7 @@ public HttpResponse show() {
9386

9487
@Get("show/{module}")
9588
@View("module-list")
96-
public HttpResponse showModule(@PathVariable("module") String module) {
89+
public HttpResponse<Map<Object, Object>> showModule(@PathVariable("module") String module) {
9790
logger.info("Requested module versions as HTML");
9891

9992
Name name = new Name(module);
@@ -112,7 +105,7 @@ public HttpResponse showModule(@PathVariable("module") String module) {
112105
}
113106

114107
@Get("list/{module}/latest")
115-
public HttpResponse listModuleLatest(HttpRequest httpRequest, @PathVariable("module") String module) {
108+
public HttpResponse<Map<Object, Object>> listModuleLatest(HttpRequest<?> httpRequest, @PathVariable("module") String module) {
116109
URI uri = httpRequest.getUri();
117110
logger.info("Requested lastest module info as HTML");
118111
int pathLen = uri.getPath().length();
@@ -127,7 +120,7 @@ public HttpResponse listModuleLatest(HttpRequest httpRequest, @PathVariable("mod
127120
}
128121

129122
@Get("show/{module}/latest")
130-
public HttpResponse showModuleLatest(HttpRequest httpRequest, @PathVariable("module") String module) {
123+
public HttpResponse<Map<Object, Object>> showModuleLatest(HttpRequest<?> httpRequest, @PathVariable("module") String module) {
131124
URI uriInfo = httpRequest.getUri();
132125
logger.info("Requested lastest module info as HTML");
133126
int pathLen = uriInfo.getPath().length();
@@ -143,7 +136,7 @@ public HttpResponse showModuleLatest(HttpRequest httpRequest, @PathVariable("mod
143136

144137
@Get("show/{module}/{version}")
145138
@View("module-info")
146-
public HttpResponse showModuleVersion(@PathVariable("module") String module, @PathVariable("version") String version) {
139+
public HttpResponse<Map<Object, Object>> showModuleVersion(@PathVariable("module") String module, @PathVariable("version") String version) {
147140
logger.info("Requested module info as HTML");
148141

149142
try {

src/main/java/org/terasology/web/controllers/ServerController.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
/*
2-
* Copyright 2015 MovingBlocks
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
163

174
package org.terasology.web.controllers;
185

196
import com.google.common.collect.ImmutableMap;
207
import io.micronaut.http.HttpResponse;
218
import io.micronaut.http.MediaType;
22-
import io.micronaut.http.annotation.*;
9+
import io.micronaut.http.annotation.Body;
10+
import io.micronaut.http.annotation.Controller;
11+
import io.micronaut.http.annotation.Get;
12+
import io.micronaut.http.annotation.Post;
13+
import io.micronaut.http.annotation.Produces;
14+
import io.micronaut.http.annotation.QueryValue;
2315
import io.micronaut.views.ModelAndView;
2416
import io.micronaut.views.View;
2517
import org.slf4j.Logger;
@@ -31,28 +23,28 @@
3123
import org.terasology.web.version.VersionInfo;
3224

3325
import java.io.IOException;
34-
import java.net.URISyntaxException;
3526
import java.util.Collections;
3627
import java.util.List;
28+
import java.util.Map;
3729

3830
/**
39-
*
31+
* Controller which servers WEB for meta-server
4032
*/
4133
@Controller("/servers/")
4234
@Produces(MediaType.TEXT_HTML)
4335
public class ServerController {
4436

4537
private static final Logger logger = LoggerFactory.getLogger(ServerController.class);
4638

47-
private ServerListService model;
39+
private final ServerListService model;
4840

4941
public ServerController(ServerListService model) {
5042
this.model = model;
5143
}
5244

5345
@Get("show")
5446
@View("server-list")
55-
public HttpResponse show() {
47+
public HttpResponse<Map<Object, Object>> show() {
5648
logger.info("Requested server list as HTML");
5749
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
5850
.put("items", list())
@@ -63,7 +55,7 @@ public HttpResponse show() {
6355

6456
@Get("add")
6557
@View("add")
66-
public HttpResponse add() {
58+
public HttpResponse<Map<Object, Object>> add() {
6759
logger.info("Requested add as HTML");
6860
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
6961
.put("name", "")
@@ -78,7 +70,7 @@ public HttpResponse add() {
7870

7971
@Get("edit")
8072
@View("edit")
81-
public HttpResponse edit(@QueryValue(value = "index", defaultValue = "-1") int index) throws IOException {
73+
public HttpResponse<Map<Object, Object>> edit(@QueryValue(value = "index", defaultValue = "-1") int index) throws IOException {
8274
List<ServerEntry> servers = model.getServers();
8375

8476
if (index < 0 || index >= servers.size()) {
@@ -100,20 +92,31 @@ public HttpResponse edit(@QueryValue(value = "index", defaultValue = "-1") int i
10092
}
10193

10294
@Post("add")
103-
public ModelAndView add(@Body ServerForm serverForm) throws URISyntaxException {
95+
public ModelAndView<Map<Object, Object>> add(@Body ServerForm serverForm) {
10496

10597
boolean active = "on".equals(serverForm.getActiveOn());
106-
logger.info("Requested addition: name: {}, address: {}, port:{}, owner:{}, active:{}", serverForm.getName(), serverForm.getAddress(), serverForm.getPort(), serverForm.getOwner(), active);
107-
108-
Result response = model.addServer(serverForm.getName(), serverForm.getAddress(), serverForm.getPort(), serverForm.getOwner(), active, serverForm.getSecret());
98+
logger.info("Requested addition: name: {}, address: {}, port:{}, owner:{}, active:{}",
99+
serverForm.getName(),
100+
serverForm.getAddress(),
101+
serverForm.getPort(),
102+
serverForm.getOwner(),
103+
active);
104+
105+
Result response = model.addServer(
106+
serverForm.getName(),
107+
serverForm.getAddress(),
108+
serverForm.getPort(),
109+
serverForm.getOwner(),
110+
active,
111+
serverForm.getSecret());
109112

110113
if (response.isSuccess()) {
111114
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
112115
.put("items", list())
113116
.put("message", response.getMessage())
114117
.put("version", VersionInfo.getVersion())
115118
.build();
116-
return new ModelAndView("list", dataModel);
119+
return new ModelAndView<>("list", dataModel);
117120
} else {
118121
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
119122
.put("name", serverForm.getName())
@@ -124,12 +127,12 @@ public ModelAndView add(@Body ServerForm serverForm) throws URISyntaxException {
124127
.put("error", response.getMessage())
125128
.put("version", VersionInfo.getVersion())
126129
.build();
127-
return new ModelAndView("add", dataModel);
130+
return new ModelAndView<>("add", dataModel);
128131
}
129132
}
130133

131134
@Post("remove")
132-
public ModelAndView remove(@Body ServerForm serverForm) throws URISyntaxException {
135+
public ModelAndView<Map<Object, Object>> remove(@Body ServerForm serverForm) {
133136

134137
boolean active = "on".equals(serverForm.getActiveOn());
135138
Result response = model.removeServer(serverForm.getAddress(), serverForm.getPort(), serverForm.getSecret());
@@ -139,7 +142,7 @@ public ModelAndView remove(@Body ServerForm serverForm) throws URISyntaxExceptio
139142
.put("message", response.getMessage())
140143
.put("version", VersionInfo.getVersion())
141144
.build();
142-
return new ModelAndView("list", dataModel);
145+
return new ModelAndView<>("list", dataModel);
143146
} else {
144147
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
145148
.put("name", serverForm.getName())
@@ -150,12 +153,12 @@ public ModelAndView remove(@Body ServerForm serverForm) throws URISyntaxExceptio
150153
.put("error", response.getMessage())
151154
.put("version", VersionInfo.getVersion())
152155
.build();
153-
return new ModelAndView("edit", dataModel);
156+
return new ModelAndView<>("edit", dataModel);
154157
}
155158
}
156159

157160
@Post("update")
158-
public ModelAndView update(@Body ServerForm serverForm) throws URISyntaxException {
161+
public ModelAndView<Map<Object, Object>> update(@Body ServerForm serverForm) {
159162

160163
boolean active = "on".equals(serverForm.getActiveOn());
161164
Result response = model.updateServer(serverForm.getName(), serverForm.getAddress(), serverForm.getPort(), serverForm.getOwner(), active, serverForm.getActiveOn());
@@ -165,7 +168,7 @@ public ModelAndView update(@Body ServerForm serverForm) throws URISyntaxExceptio
165168
.put("message", response.getMessage())
166169
.put("version", VersionInfo.getVersion())
167170
.build();
168-
return new ModelAndView("list", dataModel);
171+
return new ModelAndView<>("list", dataModel);
169172
} else {
170173
ImmutableMap<Object, Object> dataModel = ImmutableMap.builder()
171174
.put("name", serverForm.getName())
@@ -176,7 +179,7 @@ public ModelAndView update(@Body ServerForm serverForm) throws URISyntaxExceptio
176179
.put("error", response.getMessage())
177180
.put("version", VersionInfo.getVersion())
178181
.build();
179-
return new ModelAndView("edit", dataModel);
182+
return new ModelAndView<>("edit", dataModel);
180183
}
181184
}
182185

src/main/java/org/terasology/web/controllers/api/ApiModuleController.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
// Copyright 2020 The Terasology Foundation
2+
// SPDX-License-Identifier: Apache-2.0
3+
14
package org.terasology.web.controllers.api;
25

36
import com.google.gson.stream.JsonWriter;
47
import io.micronaut.http.HttpResponse;
58
import io.micronaut.http.MediaType;
6-
import io.micronaut.http.annotation.*;
9+
import io.micronaut.http.annotation.Consumes;
10+
import io.micronaut.http.annotation.Controller;
11+
import io.micronaut.http.annotation.Get;
12+
import io.micronaut.http.annotation.PathVariable;
13+
import io.micronaut.http.annotation.Post;
14+
import io.micronaut.http.annotation.Produces;
715
import org.slf4j.Logger;
816
import org.slf4j.LoggerFactory;
917
import org.terasology.module.Module;
@@ -43,7 +51,7 @@ public ApiModuleController(
4351
}
4452

4553
@Get("list")
46-
public HttpResponse list() {
54+
public HttpResponse<String> list() {
4755
logger.info("Requested module list as json");
4856

4957
List<ModuleMetadata> sortedModuleMetadatas = model.getModuleIds()
@@ -58,7 +66,7 @@ public HttpResponse list() {
5866

5967

6068
@Get("list/latest")
61-
public HttpResponse listLatest() {
69+
public HttpResponse<String> listLatest() {
6270
logger.info("Requested lastest info as json");
6371

6472
List<ModuleMetadata> sortedModuleMetadatas = model.getModuleIds()
@@ -72,7 +80,7 @@ public HttpResponse listLatest() {
7280
}
7381

7482
@Get("list/{module}")
75-
public HttpResponse listModule(@PathVariable("module") String moduleName) {
83+
public HttpResponse<String> listModule(@PathVariable("module") String moduleName) {
7684
logger.info("Requested module versions as json");
7785

7886
Name name = new Name(moduleName);
@@ -84,7 +92,7 @@ public HttpResponse listModule(@PathVariable("module") String moduleName) {
8492
}
8593

8694
@Get("list/{module}/{version}")
87-
public HttpResponse listModuleVersion(@PathVariable("module") String moduleName, @PathVariable("version") String versionStr) {
95+
public HttpResponse<String> listModuleVersion(@PathVariable("module") String moduleName, @PathVariable("version") String versionStr) {
8896
logger.info("Requested single module info as json");
8997
try {
9098
Version version = new Version(versionStr);
@@ -107,7 +115,7 @@ public HttpResponse listModuleVersion(@PathVariable("module") String moduleName,
107115
}
108116

109117
@Post("update")
110-
public HttpResponse updateModulePost(Job jobState) {
118+
public HttpResponse<String> updateModulePost(Job jobState) {
111119
String job = jobState.getName();
112120

113121
logger.info("Requested module update for {}", job);
@@ -118,7 +126,7 @@ public HttpResponse updateModulePost(Job jobState) {
118126
}
119127

120128
@Post("update-all")
121-
public HttpResponse updateAllModulesPost() {
129+
public HttpResponse<String> updateAllModulesPost() {
122130

123131
logger.info("Requested complete module update");
124132

@@ -127,7 +135,7 @@ public HttpResponse updateAllModulesPost() {
127135
return HttpResponse.ok();
128136
}
129137

130-
private HttpResponse createResponse(List<ModuleMetadata> sortedModuleMetadatas) {
138+
private HttpResponse<String> createResponse(List<ModuleMetadata> sortedModuleMetadatas) {
131139
StringWriter response = new StringWriter();
132140
try (JsonWriter writer = new JsonWriter(response)) {
133141
writer.beginArray();

0 commit comments

Comments
 (0)