Skip to content

Commit

Permalink
Format code via Spotless
Browse files Browse the repository at this point in the history
Additionally, add a CI job that checks whether the code is formatted
properly.

Co-authored-by: Stefan Walter <stefan.walter@iml.fraunhofer.de>
Merged-by: Stefan Walter <stefan.walter@iml.fraunhofer.de>
  • Loading branch information
martingr and swltr committed Jun 11, 2024
1 parent 24bce1c commit 0e07ac5
Show file tree
Hide file tree
Showing 216 changed files with 6,502 additions and 3,074 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew build
- name: Check code formatting
run: ./gradlew spotlessCheck
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
Expand Down
15 changes: 14 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ test:
paths:
- .gradle

lint:
lint-spotless:
stage: test
interruptible: true
dependencies:
- build
script:
- echo "Running Spotless check..."
- ./gradlew spotlessCheck
cache:
key: lint_spotless-$(date +%Y-%m)
paths:
- .gradle

lint-checkstyle:
stage: test
interruptible: true
image: ${CI_REGISTRY_IMAGE}/codequality:${CODEQUALITY_IMAGE_TAG}
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ The release versions are tagged with their respective version.

=== Primary formatting rules

* Maximum line length: 100 characters.
* Do not use tabs, use spaces only.
* Indentation step size: 2 spaces.
For consistent formatting of the project's code, https://github.com/diffplug/spotless[Spotless] is used.
After making changes, make sure you run `./gradlew spotlessApply` to re-format the code.

=== IDE: NetBeans

Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ buildscript {
}
}

plugins {
id 'com.diffplug.spotless' version '6.25.0'
}

apply from: "${rootDir}/gradle/dependency-versions.gradle"
apply from: "${rootDir}/gradle/common.gradle"
apply from: "${rootDir}/gradle/java-project.gradle"
Expand Down
401 changes: 401 additions & 0 deletions config/eclipse-formatter-preferences.xml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions gradle/java-project.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'java'
apply plugin: 'org.kordamp.gradle.stats'
apply plugin: 'com.diffplug.spotless'

base.archivesName = name.toLowerCase()

Expand Down Expand Up @@ -48,3 +49,13 @@ task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from
archiveClassifier = 'sources'
from sourceSets.main.allSource
}

spotless {
java {
// Use the default import order configuration
importOrder()

// Use the Eclipse JDT formatter
eclipse('4.26').configFile("${rootDir}/config/eclipse-formatter-preferences.xml")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* A custom Guice module for project-specific configuration.
*/
public class ControlCenterInjectionModuleImpl
extends ControlCenterInjectionModule {
extends
ControlCenterInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import org.opentcs.customizations.kernel.KernelInjectionModule;

public class KernelInjectionModuleImpl
extends KernelInjectionModule {
extends
KernelInjectionModule {

/**
* Creates a new instance.
Expand All @@ -26,8 +27,12 @@ protected void configure() {
configureMqtt();

bind(CommAdapterConfiguration.class)
.toInstance(getConfigBindingProvider().get(CommAdapterConfiguration.PREFIX,
CommAdapterConfiguration.class));
.toInstance(
getConfigBindingProvider().get(
CommAdapterConfiguration.PREFIX,
CommAdapterConfiguration.class
)
);

install(new org.opentcs.commadapter.vehicle.vda5050.v1_1.KernelInjectionModuleImpl());
install(new org.opentcs.commadapter.vehicle.vda5050.v2_0.KernelInjectionModuleImpl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import org.opentcs.customizations.plantoverview.PlantOverviewInjectionModule;

public class ModelEditorInjectionModule
extends PlantOverviewInjectionModule {
extends
PlantOverviewInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
*/
package org.opentcs.commadapter.vehicle.vda5050.v1_1;

import org.opentcs.commadapter.vehicle.vda5050.v1_1.controlcenter.CommAdapterPanelFactoryImpl;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.controlcenter.AdapterPanelComponentsFactory;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.controlcenter.AdapterPanelComponentsFactory;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.controlcenter.CommAdapterPanelFactoryImpl;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.controlcenter.action.prefill.PrefillDialogFactory;
import org.opentcs.customizations.controlcenter.ControlCenterInjectionModule;

/**
* A custom Guice module for project-specific configuration.
*/
public class ControlCenterInjectionModuleImpl
extends ControlCenterInjectionModule {
extends
ControlCenterInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import com.google.inject.assistedinject.FactoryModuleBuilder;
import javax.inject.Singleton;
import org.opentcs.commadapter.vehicle.vda5050.Vda5050CommAdapterFactory;
import org.opentcs.customizations.kernel.KernelInjectionModule;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.CommAdapterFactory.V1dot1;
import org.opentcs.customizations.kernel.KernelInjectionModule;

public class KernelInjectionModuleImpl
extends KernelInjectionModule {
extends
KernelInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/
package org.opentcs.commadapter.vehicle.vda5050.v1_1;

import org.opentcs.commadapter.vehicle.vda5050.v1_1.modeleditor.ModelEditorPropertySuggestions;
import javax.inject.Singleton;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.modeleditor.ModelEditorPropertySuggestions;
import org.opentcs.customizations.plantoverview.PlantOverviewInjectionModule;

public class ModelEditorInjectionModule
extends PlantOverviewInjectionModule {
extends
PlantOverviewInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
*/
package org.opentcs.commadapter.vehicle.vda5050.v2_0;

import org.opentcs.commadapter.vehicle.vda5050.v2_0.controlcenter.CommAdapterPanelFactoryImpl;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.controlcenter.AdapterPanelComponentsFactory;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.controlcenter.AdapterPanelComponentsFactory;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.controlcenter.CommAdapterPanelFactoryImpl;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.controlcenter.action.prefill.PrefillDialogFactory;
import org.opentcs.customizations.controlcenter.ControlCenterInjectionModule;

/**
* A custom Guice module for project-specific configuration.
*/
public class ControlCenterInjectionModuleImpl
extends ControlCenterInjectionModule {
extends
ControlCenterInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import org.opentcs.customizations.kernel.KernelInjectionModule;

public class KernelInjectionModuleImpl
extends KernelInjectionModule {
extends
KernelInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/
package org.opentcs.commadapter.vehicle.vda5050.v2_0;

import org.opentcs.commadapter.vehicle.vda5050.v2_0.modeleditor.ModelEditorPropertySuggestions;
import javax.inject.Singleton;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.modeleditor.ModelEditorPropertySuggestions;
import org.opentcs.customizations.plantoverview.PlantOverviewInjectionModule;

public class ModelEditorInjectionModule
extends PlantOverviewInjectionModule {
extends
PlantOverviewInjectionModule {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,29 @@ public interface CommAdapterConfiguration {
@ConfigurationEntry(
type = "List of VDA5050 version numbers",
description = "See driver documentation.",
orderKey = "0_enable")
orderKey = "0_enable"
)
List<String> enabledVersions();

@ConfigurationEntry(
type = "Map of operating modes to the integration level",
description = "See driver documentation.",
orderKey = "1_1_changeLevel")
orderKey = "1_1_changeLevel"
)
Map<ConfigOperatingMode, ConfigIntegrationLevel> onOpModeChangeDoUpdateIntegrationLevel();

@ConfigurationEntry(
type = "Map of operating modes to a boolean",
description = "See driver documentation.",
orderKey = "1_2_withdrawOrder")
orderKey = "1_2_withdrawOrder"
)
Map<ConfigOperatingMode, Boolean> onOpModeChangeDoWithdrawOrder();

@ConfigurationEntry(
type = "Map of operating modes to a boolean",
description = "See driver documentation.",
orderKey = "1_3_resetPosition")
orderKey = "1_3_resetPosition"
)
Map<ConfigOperatingMode, Boolean> onOpModeChangeDoResetPosition();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* The example adapter's {@link VehicleCommAdapterDescription}.
*/
public class CommAdapterDescriptionImpl
extends VehicleCommAdapterDescription {
extends
VehicleCommAdapterDescription {

/**
* Creates a new instance.
Expand All @@ -24,8 +25,8 @@ public CommAdapterDescriptionImpl() {

@Override
public String getDescription() {
return ResourceBundle.getBundle("i18n/org/opentcs/commadapter/vehicle/vda5050/Bundle").
getString("commAdapterDescriptionImpl.adapterFactoryDescription");
return ResourceBundle.getBundle("i18n/org/opentcs/commadapter/vehicle/vda5050/Bundle")
.getString("commAdapterDescriptionImpl.adapterFactoryDescription");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
*/
package org.opentcs.commadapter.vehicle.vda5050;

import static java.util.Objects.requireNonNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Objects.requireNonNull;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.CommAdapterFactory.V1dot1;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.CommAdapterFactory.V2dot0;
import org.opentcs.data.model.Vehicle;
import org.opentcs.drivers.vehicle.VehicleCommAdapter;
import org.opentcs.drivers.vehicle.VehicleCommAdapterDescription;
import org.opentcs.drivers.vehicle.VehicleCommAdapterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opentcs.commadapter.vehicle.vda5050.v2_0.CommAdapterFactory.V2dot0;
import org.opentcs.commadapter.vehicle.vda5050.v1_1.CommAdapterFactory.V1dot1;

/**
* A Factory for creating a vda5050 capable comm adapter.
*/
public class CommAdapterFactoryImpl
implements VehicleCommAdapterFactory {
implements
VehicleCommAdapterFactory {

/**
* This class's Logger.
Expand Down Expand Up @@ -57,9 +59,13 @@ public class CommAdapterFactoryImpl
* @param commAdapterFactory2dot0 The factory to create a comm adapter version 2.0.
*/
@Inject
public CommAdapterFactoryImpl(CommAdapterConfiguration configuration,
@V1dot1 Vda5050CommAdapterFactory commAdapterFactory1dot1,
@V2dot0 Vda5050CommAdapterFactory commAdapterFactory2dot0) {
public CommAdapterFactoryImpl(
CommAdapterConfiguration configuration,
@V1dot1
Vda5050CommAdapterFactory commAdapterFactory1dot1,
@V2dot0
Vda5050CommAdapterFactory commAdapterFactory2dot0
) {
requireNonNull(configuration, "configuration");
requireNonNull(commAdapterFactory1dot1, "commAdapterFactory1dot1");
requireNonNull(commAdapterFactory2dot0, "commAdapterFactory2dot0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* A {@link Vda5050CommAdapterFactory} that does not provide any adapters.
*/
public class DisabledVda5050CommAdapterFactory
implements Vda5050CommAdapterFactory {
implements
Vda5050CommAdapterFactory {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ public static double checkInRange(double value, double minimum, double maximum)
public static double checkInRange(double value, double minimum, double maximum, String valueName)
throws IllegalArgumentException {
if (value < minimum || value > maximum) {
throw new IllegalArgumentException(String.format("%s is not in [%f..%f]: %f",
String.valueOf(valueName),
minimum,
maximum,
value));
throw new IllegalArgumentException(
String.format(
"%s is not in [%f..%f]: %f",
String.valueOf(valueName),
minimum,
maximum,
value
)
);
}
return value;
}
Expand Down
Loading

0 comments on commit 0e07ac5

Please sign in to comment.