Skip to content

Commit c1290bb

Browse files
authored
Add Java-Checkstyle requirement to CI (OpenEMS#1852)
Automatically apply Checkstyle checks for Java (OpenEMS Edge + OpenEMS Backend) via the Continuous Integration pipeline.
1 parent d937ff1 commit c1290bb

File tree

418 files changed

+2096
-895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

418 files changed

+2096
-895
lines changed

build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id "com.github.node-gradle.node" version "2.2.3"
3+
id 'checkstyle'
34
}
45

56
tasks.named('wrapper') {
@@ -156,3 +157,21 @@ task buildAntoraDocs(dependsOn: copyBundleReadmes) {
156157
}
157158
}
158159
}
160+
161+
/*
162+
* Checkstyle configuration
163+
*/
164+
allprojects {
165+
apply plugin: 'checkstyle'
166+
167+
repositories {
168+
mavenCentral()
169+
}
170+
171+
checkstyle {
172+
toolVersion = '10.3'
173+
configFile = file("${rootDir}/cnf/checkstyle.xml")
174+
maxWarnings = 0
175+
ignoreFailures false
176+
}
177+
}

io.openems.backend.timedata.influx/src/io/openems/backend/timedata/influx/FieldTypeConflictHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ private BiConsumer<Point, JsonElement> createAndAddHandler(String field, Require
7474
* 'requiredType'.
7575
*
7676
* @param field the field name, i.e. the Channel-Address
77-
* @param requiredType the {@link RequiredType
78-
* @return
77+
* @param requiredType the {@link RequiredType}
78+
* @return the Handler
7979
*/
8080
private BiConsumer<Point, JsonElement> createHandler(String field, RequiredType requiredType) {
8181
switch (requiredType) {

io.openems.common/src/io/openems/common/OpenemsConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class OpenemsConstants {
2222
* <p>
2323
* This is the month of the release.
2424
*/
25-
public final static short VERSION_MINOR = 7;
25+
public static final short VERSION_MINOR = 7;
2626

2727
/**
2828
* The patch version of OpenEMS.
@@ -31,7 +31,7 @@ public class OpenemsConstants {
3131
* This is always `0` for OpenEMS open source releases and reserved for private
3232
* distributions.
3333
*/
34-
public final static short VERSION_PATCH = 0;
34+
public static final short VERSION_PATCH = 0;
3535

3636
/**
3737
* The additional version string.

io.openems.common/src/io/openems/common/channel/Unit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public enum Unit {
8383
MILLIVOLT("mV", VOLT, -3),
8484

8585
/**
86-
* Unit of Voltage [uA]
86+
* Unit of Voltage [uA].
8787
*/
8888
MICROVOLT("uA", VOLT, -6),
8989

@@ -102,7 +102,7 @@ public enum Unit {
102102
MILLIAMPERE("mA", AMPERE, -3),
103103

104104
/**
105-
* Unit of Current [uA]
105+
* Unit of Current [uA].
106106
*/
107107
MICROAMPERE("uA", AMPERE, -6),
108108

io.openems.common/src/io/openems/common/jsonrpc/response/QueryHistoricTimeseriesExportXlsxResponse.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ protected static class Channel {
9494
* @param toDate the end date of the export
9595
* @param historicData the power data per channel and timestamp
9696
* @param historicEnergy the energy data, one value per channel
97+
* @param language the {@link Language}
9798
* @throws IOException on error
9899
* @throws OpenemsNamedException on error
99100
*/
@@ -154,10 +155,11 @@ private static byte[] generatePayload(String edgeId, ZonedDateTime fromDate, Zon
154155
/**
155156
* Adds basic information like the Edge-ID, date of creation,...
156157
*
157-
* @param ws the {@link Worksheet}
158-
* @param edgeId the edgeId number
159-
* @param fromDate the fromdate the excel exported from
160-
* @param toDate the todate the excel exported to
158+
* @param ws the {@link Worksheet}
159+
* @param edgeId the edgeId number
160+
* @param fromDate the fromdate the excel exported from
161+
* @param toDate the todate the excel exported to
162+
* @param translationBundle the {@link ResourceBundle} for translations
161163
*/
162164
protected static void addBasicInfo(Worksheet ws, String edgeId, ZonedDateTime fromDate, ZonedDateTime toDate,
163165
ResourceBundle translationBundle) {
@@ -185,8 +187,9 @@ protected static void addBasicInfo(Worksheet ws, String edgeId, ZonedDateTime fr
185187
/**
186188
* Adds the energy data header and values.
187189
*
188-
* @param ws the {@link Worksheet}
189-
* @param data the energy data map
190+
* @param ws the {@link Worksheet}
191+
* @param data the energy data map
192+
* @param translationBundle the {@link ResourceBundle} for translations
190193
* @throws OpenemsNamedException on error
191194
*/
192195
protected static void addEnergyData(Worksheet ws, SortedMap<ChannelAddress, JsonElement> data,
@@ -219,8 +222,9 @@ protected static void addEnergyData(Worksheet ws, SortedMap<ChannelAddress, Json
219222
/**
220223
* Adds the power data header and values.
221224
*
222-
* @param ws the {@link Worksheet}
223-
* @param data the power data map
225+
* @param ws the {@link Worksheet}
226+
* @param data the power data map
227+
* @param translationBundle the {@link ResourceBundle} for translations
224228
* @throws OpenemsNamedException on error
225229
*/
226230
protected static void addPowerData(Worksheet ws,

io.openems.common/src/io/openems/common/session/Language.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ public static Language from(String languageKey) throws OpenemsException {
3939
}
4040
}
4141

42+
/**
43+
* Get {@link Language} for given key of the language. If the language key does
44+
* not exist, {@link Language#EN} is returned as default. The given key is
45+
* removed all leading and trailing whitespaces and converts all characters to
46+
* upper case.
47+
*
48+
* @param languageKey to get the {@link Language}
49+
* @return the founded {@link Language} or throws an exception
50+
* @throws OpenemsException on error
51+
*/
4252
public static Language from(Optional<String> languageKey) throws OpenemsException {
4353
if (languageKey.isPresent()) {
4454
return Language.from(languageKey.get());

io.openems.common/src/io/openems/common/timedata/CommonTimedataService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public interface CommonTimedataService {
2323
* Handles a {@link QueryHistoricTimeseriesExportXlxsRequest}. Exports historic
2424
* data to an Excel file.
2525
*
26-
* @param edgeId the Edge-ID
27-
* @param request the {@link QueryHistoricTimeseriesExportXlxsRequest} request
26+
* @param edgeId the Edge-ID
27+
* @param request the {@link QueryHistoricTimeseriesExportXlxsRequest} request
28+
* @param language the {@link Language}
2829
* @return the {@link QueryHistoricTimeseriesExportXlsxResponse}
2930
* @throws OpenemsNamedException on error
3031
*/

io.openems.common/src/io/openems/common/timedata/Resolution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ChronoUnit getUnit() {
3737
* @param date to remove InfluxDB offset
3838
* @return Date without offset
3939
*/
40-
public ZonedDateTime revertInfluxDBOffset(ZonedDateTime date) {
40+
public ZonedDateTime revertInfluxDbOffset(ZonedDateTime date) {
4141
switch (this.unit) {
4242
case DAYS:
4343
case MONTHS:

io.openems.common/src/io/openems/common/utils/JsonUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ public static Object getAsType(Class<?> type, JsonElement j) throws NotImplement
13461346
/**
13471347
* Gets a {@link JsonElement} as the given {@link OpenemsType}.
13481348
*
1349+
* @param <T> the Type for implicit casting of the result
13491350
* @param type the {@link OpenemsType}
13501351
* @param j the {@link JsonElement}
13511352
* @return an Object of the given type

io.openems.common/test/io/openems/common/jsonrpc/response/QueryHistoricTimeseriesExportXlsxResponseTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ private byte[] generateXlsxFile() throws OpenemsNamedException, IOException {
6767
try (var os = new ByteArrayOutputStream()) {
6868
var workbook = new Workbook(os, "Historic data", null);
6969
var ws = workbook.newWorksheet("Export");
70-
71-
Locale currentLocale = new Locale("en","EN");
72-
73-
var translationBundle = ResourceBundle
74-
.getBundle("io.openems.common.jsonrpc.response.translation"
75-
,currentLocale);
76-
77-
XlsxUtils.addBasicInfo(ws, "0", fromDate, toDate, translationBundle );
70+
71+
Locale currentLocale = new Locale("en", "EN");
72+
73+
var translationBundle = ResourceBundle.getBundle("io.openems.common.jsonrpc.response.translation",
74+
currentLocale);
75+
76+
XlsxUtils.addBasicInfo(ws, "0", fromDate, toDate, translationBundle);
7877
XlsxUtils.addEnergyData(ws, energyData, translationBundle);
7978
XlsxUtils.addPowerData(ws, powerData, translationBundle);
8079

io.openems.edge.battery.api/src/io/openems/edge/battery/api/Battery.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ public Doc doc() {
220220
}
221221

222222
/**
223-
* Gets the ModbusSlaveNatureTable.
223+
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
224+
* of this Component.
224225
*
225-
* @param accessMode the {@link AccessMode}
226-
* @return ModbusSlaveNatureTable
226+
* @param accessMode filters the Modbus-Records that should be shown
227+
* @return the {@link ModbusSlaveNatureTable}
227228
*/
228229
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {
229230
return ModbusSlaveNatureTable.of(Battery.class, accessMode, 100) //

io.openems.edge.batteryinverter.api/src/io/openems/edge/batteryinverter/api/ManagedSymmetricBatteryInverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public Doc doc() {
4242
}
4343

4444
/**
45-
* Gets the {@link ModbusSlaveNatureTable} for Modbus/TCP Api.
45+
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
46+
* of this Component.
4647
*
47-
* @param accessMode the {@link AccessMode}
48+
* @param accessMode filters the Modbus-Records that should be shown
4849
* @return the {@link ModbusSlaveNatureTable}
4950
*/
5051
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {

io.openems.edge.batteryinverter.api/src/io/openems/edge/batteryinverter/api/SymmetricBatteryInverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public Doc doc() {
123123
}
124124

125125
/**
126-
* Gets the {@link ModbusSlaveNatureTable} for {@link SymmetricBatteryInverter}
127-
* used by the Modbus/TCP Slave API.
126+
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
127+
* of this Component.
128128
*
129-
* @param accessMode the {@link AccessMode}
129+
* @param accessMode filters the Modbus-Records that should be shown
130130
* @return the {@link ModbusSlaveNatureTable}
131131
*/
132132
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {

io.openems.edge.bosch.bpts5hybrid/src/io/openems/edge/bosch/bpts5hybrid/core/BoschBpts5HybridApiClient.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BoschBpts5HybridApiClient {
1919
private static final String REQUEST_LOG_BOOK_VIEW = "&action=get.logbookview&page=0&id=&type=BATTERY&dtype=";
2020
private static final String GET_VALUES_URL_PART = "/cgi-bin/ipcclient.fcgi?";
2121
private static String BASE_URL;
22-
private String wui_sid;
22+
private String wuiSid;
2323
private Integer pvLeistungWatt = Integer.valueOf(0);
2424
private Integer soc = Integer.valueOf(0);
2525
private Integer einspeisung = Integer.valueOf(0);
@@ -42,11 +42,11 @@ public BoschBpts5HybridApiClient(String ipaddress) {
4242
this.connect();
4343
}
4444

45-
public void connect() {
45+
protected void connect() {
4646
try {
47-
this.wui_sid = this.getWuiSidRequest();
47+
this.wuiSid = this.getWuiSidRequest();
4848
} catch (OpenemsNamedException e) {
49-
this.wui_sid = "";
49+
this.wuiSid = "";
5050
e.printStackTrace();
5151
}
5252
}
@@ -77,8 +77,8 @@ private String extractWuiSidFromBody(String body) throws OpenemsException {
7777
return body.substring(index + 9, index + 9 + 15);
7878
}
7979

80-
public void retreiveValues() throws OpenemsException {
81-
var postRequest = this.httpClient.POST(BASE_URL + GET_VALUES_URL_PART + this.wui_sid);
80+
protected void retreiveValues() throws OpenemsException {
81+
var postRequest = this.httpClient.POST(BASE_URL + GET_VALUES_URL_PART + this.wuiSid);
8282
postRequest.timeout(5, TimeUnit.SECONDS);
8383
postRequest.header(HttpHeader.CONTENT_TYPE, "text/plain");
8484
postRequest.content(new StringContentProvider(POST_REQUEST_DATA));
@@ -100,9 +100,9 @@ public void retreiveValues() throws OpenemsException {
100100
}
101101
}
102102

103-
public int retreiveBatterieStatus() throws OpenemsException {
103+
protected int retreiveBatterieStatus() throws OpenemsException {
104104
try {
105-
var response = this.httpClient.GET(BASE_URL + GET_VALUES_URL_PART + this.wui_sid + REQUEST_LOG_BOOK_VIEW);
105+
var response = this.httpClient.GET(BASE_URL + GET_VALUES_URL_PART + this.wuiSid + REQUEST_LOG_BOOK_VIEW);
106106

107107
var status = response.getStatus();
108108
if (status >= 300) {
@@ -132,20 +132,10 @@ private void extractValuesFromAnswer(String body) throws OpenemsNamedException {
132132

133133
var values = body.split("\\|");
134134

135-
// pvLeistungProzent = Integer.valueOf(values[1]);
136-
137135
this.pvLeistungWatt = this.parseWattValue(values[2]);
138136

139137
this.soc = Integer.valueOf(values[3]);
140138

141-
// autarkieGrad = Float.valueOf(values[5]).floatValue();
142-
143-
// currentOverallConsumption = parseWattValue(values[6]);
144-
145-
// gridStatusString = values[7];
146-
147-
// systemStatusString = values[9];
148-
149139
this.batterieLadeStrom = this.parseWattValue(values[10]);
150140

151141
this.einspeisung = this.parseWattValue(values[11]);

io.openems.edge.bosch.bpts5hybrid/src/io/openems/edge/bosch/bpts5hybrid/core/BoschBpts5HybridCore.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,25 @@ public interface BoschBpts5HybridCore extends OpenemsComponent {
1919

2020
public void setMeter(BoschBpts5HybridMeter boschBpts5HybridMeter);
2121

22+
/**
23+
* Gets the {@link BoschBpts5HybridEss}.
24+
*
25+
* @return the {@link BoschBpts5HybridEss}
26+
*/
2227
public Optional<BoschBpts5HybridEss> getEss();
2328

29+
/**
30+
* Gets the {@link BoschBpts5HybridPv}.
31+
*
32+
* @return the {@link BoschBpts5HybridPv}
33+
*/
2434
public Optional<BoschBpts5HybridPv> getPv();
2535

36+
/**
37+
* Gets the {@link BoschBpts5HybridMeter}.
38+
*
39+
* @return the {@link BoschBpts5HybridMeter}
40+
*/
2641
public Optional<BoschBpts5HybridMeter> getMeter();
2742

2843
public enum CoreChannelId implements io.openems.edge.common.channel.ChannelId {

io.openems.edge.bosch.bpts5hybrid/src/io/openems/edge/bosch/bpts5hybrid/ess/BoschBpts5HybridEss.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
public class BoschBpts5HybridEss extends AbstractOpenemsComponent implements SymmetricEss, OpenemsComponent {
3737

38-
private final int CAPACITY = 8_800;
38+
private static final int CAPACITY = 8_800;
3939

4040
@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
4141
private BoschBpts5HybridCore core;
@@ -49,7 +49,7 @@ public BoschBpts5HybridEss() {
4949
SymmetricEss.ChannelId.values(), //
5050
ChannelId.values() //
5151
);
52-
this._setCapacity(this.CAPACITY); // TODO: get from read worker
52+
this._setCapacity(CAPACITY); // TODO: get from read worker
5353
}
5454

5555
@Activate

io.openems.edge.bosch.bpts5hybrid/src/io/openems/edge/bosch/bpts5hybrid/pv/BoschBpts5HybridPv.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
public class BoschBpts5HybridPv extends AbstractOpenemsComponent implements EssDcCharger, OpenemsComponent {
3737

38-
private final int PEAK_POWER = 5_500;
38+
private static final int PEAK_POWER = 5_500;
3939

4040
@Reference(policy = ReferencePolicy.STATIC, policyOption = ReferencePolicyOption.GREEDY, cardinality = ReferenceCardinality.MANDATORY)
4141
private BoschBpts5HybridCore core;
@@ -49,11 +49,11 @@ public BoschBpts5HybridPv() {
4949
EssDcCharger.ChannelId.values(), //
5050
ChannelId.values() //
5151
);
52-
this._setMaxActualPower(this.PEAK_POWER); // TODO: get from read worker
52+
this._setMaxActualPower(PEAK_POWER); // TODO: get from read worker
5353
}
5454

5555
@Activate
56-
void activate(ComponentContext context, Config config)
56+
protected void activate(ComponentContext context, Config config)
5757
throws OpenemsNamedException, ConfigurationException, IOException {
5858
super.activate(context, config.id(), config.alias(), config.enabled());
5959

io.openems.edge.bridge.mbus/src/io/openems/edge/bridge/mbus/api/BridgeMbus.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,25 @@ public Doc doc() {
2828
}
2929
}
3030

31+
/**
32+
* Add a Task.
33+
*
34+
* @param sourceId the Source-ID
35+
* @param task the {@link MbusTask}
36+
*/
3137
public void addTask(String sourceId, MbusTask task);
3238

39+
/**
40+
* Get the {@link MBusConnection}.
41+
*
42+
* @return the {@link MBusConnection}
43+
*/
3344
public MBusConnection getmBusConnection();
3445

46+
/**
47+
* Remove the task with the given Source-ID.
48+
*
49+
* @param sourceId the Source-ID
50+
*/
3551
public void removeTask(String sourceId);
3652
}

0 commit comments

Comments
 (0)