Skip to content

Commit

Permalink
Add Java-Checkstyle requirement to CI (OpenEMS#1852)
Browse files Browse the repository at this point in the history
Automatically apply Checkstyle checks for Java (OpenEMS Edge + OpenEMS Backend) via the Continuous Integration pipeline.
  • Loading branch information
sfeilmeier authored Jun 5, 2022
1 parent d937ff1 commit c1290bb
Show file tree
Hide file tree
Showing 418 changed files with 2,096 additions and 895 deletions.
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "com.github.node-gradle.node" version "2.2.3"
id 'checkstyle'
}

tasks.named('wrapper') {
Expand Down Expand Up @@ -156,3 +157,21 @@ task buildAntoraDocs(dependsOn: copyBundleReadmes) {
}
}
}

/*
* Checkstyle configuration
*/
allprojects {
apply plugin: 'checkstyle'

repositories {
mavenCentral()
}

checkstyle {
toolVersion = '10.3'
configFile = file("${rootDir}/cnf/checkstyle.xml")
maxWarnings = 0
ignoreFailures false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ private BiConsumer<Point, JsonElement> createAndAddHandler(String field, Require
* 'requiredType'.
*
* @param field the field name, i.e. the Channel-Address
* @param requiredType the {@link RequiredType
* @return
* @param requiredType the {@link RequiredType}
* @return the Handler
*/
private BiConsumer<Point, JsonElement> createHandler(String field, RequiredType requiredType) {
switch (requiredType) {
Expand Down
4 changes: 2 additions & 2 deletions io.openems.common/src/io/openems/common/OpenemsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class OpenemsConstants {
* <p>
* This is the month of the release.
*/
public final static short VERSION_MINOR = 7;
public static final short VERSION_MINOR = 7;

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

/**
* The additional version string.
Expand Down
4 changes: 2 additions & 2 deletions io.openems.common/src/io/openems/common/channel/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public enum Unit {
MILLIVOLT("mV", VOLT, -3),

/**
* Unit of Voltage [uA]
* Unit of Voltage [uA].
*/
MICROVOLT("uA", VOLT, -6),

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

/**
* Unit of Current [uA]
* Unit of Current [uA].
*/
MICROAMPERE("uA", AMPERE, -6),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ protected static class Channel {
* @param toDate the end date of the export
* @param historicData the power data per channel and timestamp
* @param historicEnergy the energy data, one value per channel
* @param language the {@link Language}
* @throws IOException on error
* @throws OpenemsNamedException on error
*/
Expand Down Expand Up @@ -154,10 +155,11 @@ private static byte[] generatePayload(String edgeId, ZonedDateTime fromDate, Zon
/**
* Adds basic information like the Edge-ID, date of creation,...
*
* @param ws the {@link Worksheet}
* @param edgeId the edgeId number
* @param fromDate the fromdate the excel exported from
* @param toDate the todate the excel exported to
* @param ws the {@link Worksheet}
* @param edgeId the edgeId number
* @param fromDate the fromdate the excel exported from
* @param toDate the todate the excel exported to
* @param translationBundle the {@link ResourceBundle} for translations
*/
protected static void addBasicInfo(Worksheet ws, String edgeId, ZonedDateTime fromDate, ZonedDateTime toDate,
ResourceBundle translationBundle) {
Expand Down Expand Up @@ -185,8 +187,9 @@ protected static void addBasicInfo(Worksheet ws, String edgeId, ZonedDateTime fr
/**
* Adds the energy data header and values.
*
* @param ws the {@link Worksheet}
* @param data the energy data map
* @param ws the {@link Worksheet}
* @param data the energy data map
* @param translationBundle the {@link ResourceBundle} for translations
* @throws OpenemsNamedException on error
*/
protected static void addEnergyData(Worksheet ws, SortedMap<ChannelAddress, JsonElement> data,
Expand Down Expand Up @@ -219,8 +222,9 @@ protected static void addEnergyData(Worksheet ws, SortedMap<ChannelAddress, Json
/**
* Adds the power data header and values.
*
* @param ws the {@link Worksheet}
* @param data the power data map
* @param ws the {@link Worksheet}
* @param data the power data map
* @param translationBundle the {@link ResourceBundle} for translations
* @throws OpenemsNamedException on error
*/
protected static void addPowerData(Worksheet ws,
Expand Down
10 changes: 10 additions & 0 deletions io.openems.common/src/io/openems/common/session/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public static Language from(String languageKey) throws OpenemsException {
}
}

/**
* Get {@link Language} for given key of the language. If the language key does
* not exist, {@link Language#EN} is returned as default. The given key is
* removed all leading and trailing whitespaces and converts all characters to
* upper case.
*
* @param languageKey to get the {@link Language}
* @return the founded {@link Language} or throws an exception
* @throws OpenemsException on error
*/
public static Language from(Optional<String> languageKey) throws OpenemsException {
if (languageKey.isPresent()) {
return Language.from(languageKey.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public interface CommonTimedataService {
* Handles a {@link QueryHistoricTimeseriesExportXlxsRequest}. Exports historic
* data to an Excel file.
*
* @param edgeId the Edge-ID
* @param request the {@link QueryHistoricTimeseriesExportXlxsRequest} request
* @param edgeId the Edge-ID
* @param request the {@link QueryHistoricTimeseriesExportXlxsRequest} request
* @param language the {@link Language}
* @return the {@link QueryHistoricTimeseriesExportXlsxResponse}
* @throws OpenemsNamedException on error
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ChronoUnit getUnit() {
* @param date to remove InfluxDB offset
* @return Date without offset
*/
public ZonedDateTime revertInfluxDBOffset(ZonedDateTime date) {
public ZonedDateTime revertInfluxDbOffset(ZonedDateTime date) {
switch (this.unit) {
case DAYS:
case MONTHS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ public static Object getAsType(Class<?> type, JsonElement j) throws NotImplement
/**
* Gets a {@link JsonElement} as the given {@link OpenemsType}.
*
* @param <T> the Type for implicit casting of the result
* @param type the {@link OpenemsType}
* @param j the {@link JsonElement}
* @return an Object of the given type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ private byte[] generateXlsxFile() throws OpenemsNamedException, IOException {
try (var os = new ByteArrayOutputStream()) {
var workbook = new Workbook(os, "Historic data", null);
var ws = workbook.newWorksheet("Export");

Locale currentLocale = new Locale("en","EN");

var translationBundle = ResourceBundle
.getBundle("io.openems.common.jsonrpc.response.translation"
,currentLocale);

XlsxUtils.addBasicInfo(ws, "0", fromDate, toDate, translationBundle );

Locale currentLocale = new Locale("en", "EN");

var translationBundle = ResourceBundle.getBundle("io.openems.common.jsonrpc.response.translation",
currentLocale);

XlsxUtils.addBasicInfo(ws, "0", fromDate, toDate, translationBundle);
XlsxUtils.addEnergyData(ws, energyData, translationBundle);
XlsxUtils.addPowerData(ws, powerData, translationBundle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ public Doc doc() {
}

/**
* Gets the ModbusSlaveNatureTable.
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
* of this Component.
*
* @param accessMode the {@link AccessMode}
* @return ModbusSlaveNatureTable
* @param accessMode filters the Modbus-Records that should be shown
* @return the {@link ModbusSlaveNatureTable}
*/
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {
return ModbusSlaveNatureTable.of(Battery.class, accessMode, 100) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public Doc doc() {
}

/**
* Gets the {@link ModbusSlaveNatureTable} for Modbus/TCP Api.
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
* of this Component.
*
* @param accessMode the {@link AccessMode}
* @param accessMode filters the Modbus-Records that should be shown
* @return the {@link ModbusSlaveNatureTable}
*/
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public Doc doc() {
}

/**
* Gets the {@link ModbusSlaveNatureTable} for {@link SymmetricBatteryInverter}
* used by the Modbus/TCP Slave API.
* Used for Modbus/TCP Api Controller. Provides a Modbus table for the Channels
* of this Component.
*
* @param accessMode the {@link AccessMode}
* @param accessMode filters the Modbus-Records that should be shown
* @return the {@link ModbusSlaveNatureTable}
*/
public static ModbusSlaveNatureTable getModbusSlaveNatureTable(AccessMode accessMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BoschBpts5HybridApiClient {
private static final String REQUEST_LOG_BOOK_VIEW = "&action=get.logbookview&page=0&id=&type=BATTERY&dtype=";
private static final String GET_VALUES_URL_PART = "/cgi-bin/ipcclient.fcgi?";
private static String BASE_URL;
private String wui_sid;
private String wuiSid;
private Integer pvLeistungWatt = Integer.valueOf(0);
private Integer soc = Integer.valueOf(0);
private Integer einspeisung = Integer.valueOf(0);
Expand All @@ -42,11 +42,11 @@ public BoschBpts5HybridApiClient(String ipaddress) {
this.connect();
}

public void connect() {
protected void connect() {
try {
this.wui_sid = this.getWuiSidRequest();
this.wuiSid = this.getWuiSidRequest();
} catch (OpenemsNamedException e) {
this.wui_sid = "";
this.wuiSid = "";
e.printStackTrace();
}
}
Expand Down Expand Up @@ -77,8 +77,8 @@ private String extractWuiSidFromBody(String body) throws OpenemsException {
return body.substring(index + 9, index + 9 + 15);
}

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

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

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

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

// pvLeistungProzent = Integer.valueOf(values[1]);

this.pvLeistungWatt = this.parseWattValue(values[2]);

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

// autarkieGrad = Float.valueOf(values[5]).floatValue();

// currentOverallConsumption = parseWattValue(values[6]);

// gridStatusString = values[7];

// systemStatusString = values[9];

this.batterieLadeStrom = this.parseWattValue(values[10]);

this.einspeisung = this.parseWattValue(values[11]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ public interface BoschBpts5HybridCore extends OpenemsComponent {

public void setMeter(BoschBpts5HybridMeter boschBpts5HybridMeter);

/**
* Gets the {@link BoschBpts5HybridEss}.
*
* @return the {@link BoschBpts5HybridEss}
*/
public Optional<BoschBpts5HybridEss> getEss();

/**
* Gets the {@link BoschBpts5HybridPv}.
*
* @return the {@link BoschBpts5HybridPv}
*/
public Optional<BoschBpts5HybridPv> getPv();

/**
* Gets the {@link BoschBpts5HybridMeter}.
*
* @return the {@link BoschBpts5HybridMeter}
*/
public Optional<BoschBpts5HybridMeter> getMeter();

public enum CoreChannelId implements io.openems.edge.common.channel.ChannelId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
public class BoschBpts5HybridEss extends AbstractOpenemsComponent implements SymmetricEss, OpenemsComponent {

private final int CAPACITY = 8_800;
private static final int CAPACITY = 8_800;

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

@Activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)
public class BoschBpts5HybridPv extends AbstractOpenemsComponent implements EssDcCharger, OpenemsComponent {

private final int PEAK_POWER = 5_500;
private static final int PEAK_POWER = 5_500;

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

@Activate
void activate(ComponentContext context, Config config)
protected void activate(ComponentContext context, Config config)
throws OpenemsNamedException, ConfigurationException, IOException {
super.activate(context, config.id(), config.alias(), config.enabled());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,25 @@ public Doc doc() {
}
}

/**
* Add a Task.
*
* @param sourceId the Source-ID
* @param task the {@link MbusTask}
*/
public void addTask(String sourceId, MbusTask task);

/**
* Get the {@link MBusConnection}.
*
* @return the {@link MBusConnection}
*/
public MBusConnection getmBusConnection();

/**
* Remove the task with the given Source-ID.
*
* @param sourceId the Source-ID
*/
public void removeTask(String sourceId);
}
Loading

0 comments on commit c1290bb

Please sign in to comment.