From ca4c9d1536ae4c034692aeda62e60acc46723e81 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Tue, 28 Jan 2025 17:21:26 +0100 Subject: [PATCH 1/2] Add Spotless Gradle plugin configuration --- build.gradle | 9 +++++++ project.gradle | 27 ++++++++++++++++++++ tools/spotless/openremote-license-header.txt | 18 +++++++++++++ ui/app/custom-react/build.gradle | 6 ++--- ui/app/custom/build.gradle | 6 ++--- 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 tools/spotless/openremote-license-header.txt diff --git a/build.gradle b/build.gradle index 0caedf150..9078856b9 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,15 @@ scmVersion { } } +buildscript { + repositories { + maven { url 'https://plugins.gradle.org/m2' } + } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:7.1.0' + } +} + allprojects { // Apply common project setup apply from: "${project.rootDir}/project.gradle" diff --git a/project.gradle b/project.gradle index 0f9c07d78..97de1ad0a 100644 --- a/project.gradle +++ b/project.gradle @@ -387,4 +387,31 @@ plugins.withType(JavaPlugin).whenPluginAdded { } } +plugins.apply('com.diffplug.spotless') + +spotless { + java { + target '**/*.java' + + googleJavaFormat() + licenseHeaderFile rootProject.file('tools/spotless/openremote-license-header.txt') + importOrder('java', 'javax', 'com', 'org') + removeUnusedImports() + formatAnnotations() + trimTrailingWhitespace() + endWithNewline() + } + + typescript { + target 'src/**/*.ts' + targetExclude( + 'src/model.ts', + 'src/restclient.ts' + ) + + eslint().configFile(rootProject.file('ui/.eslintrc.json')).tsconfigFile(rootProject.file('ui/tsconfig.json')) + licenseHeaderFile rootProject.file('tools/spotless/openremote-license-header.txt'), '(import|const|declare|export|var) ' + } +} + // POM generator diff --git a/tools/spotless/openremote-license-header.txt b/tools/spotless/openremote-license-header.txt new file mode 100644 index 000000000..2a336e1ba --- /dev/null +++ b/tools/spotless/openremote-license-header.txt @@ -0,0 +1,18 @@ +/* + * Copyright $YEAR, OpenRemote Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ diff --git a/ui/app/custom-react/build.gradle b/ui/app/custom-react/build.gradle index 797533f42..c61fa77b1 100644 --- a/ui/app/custom-react/build.gradle +++ b/ui/app/custom-react/build.gradle @@ -1,12 +1,10 @@ buildDir = "dist" -tasks.register('clean') { - dependsOn npmClean -} - tasks.register('installDist', Copy) { dependsOn npmBuild mustRunAfter(resolveTask(":manager:installDist")) from project.buildDir into "${project(':deployment').buildDir}/image/manager/app/${projectDir.name}" } + +clean.dependsOn(npmClean) diff --git a/ui/app/custom/build.gradle b/ui/app/custom/build.gradle index 797533f42..c61fa77b1 100644 --- a/ui/app/custom/build.gradle +++ b/ui/app/custom/build.gradle @@ -1,12 +1,10 @@ buildDir = "dist" -tasks.register('clean') { - dependsOn npmClean -} - tasks.register('installDist', Copy) { dependsOn npmBuild mustRunAfter(resolveTask(":manager:installDist")) from project.buildDir into "${project(':deployment').buildDir}/image/manager/app/${projectDir.name}" } + +clean.dependsOn(npmClean) From cd3a23a25e8e9746c153297b1ceb90d0e909007a Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Wed, 17 Dec 2025 17:13:00 +0100 Subject: [PATCH 2/2] Apply Spotless --- .../openremote/agent/custom/CustomAgent.java | 81 +++++++++--------- .../custom/CustomAgentModelProvider.java | 16 ++-- .../agent/custom/CustomProtocol.java | 85 +++++++++---------- .../manager/custom/CustomService.java | 25 ++---- .../openremote/model/custom/CustomAsset.java | 70 ++++++++------- .../custom/CustomAssetModelProvider.java | 15 ++-- .../openremote/model/custom/CustomData.java | 26 +++--- .../model/custom/CustomEndpointResource.java | 14 +-- .../setup/custom/CustomKeycloakSetup.java | 59 +++++++------ .../setup/custom/CustomManagerSetup.java | 25 +++--- .../setup/custom/CustomSetupTasks.java | 31 +++---- ui/app/custom-react/src/react-env.d.ts | 21 ++++- ui/app/custom/src/index.ts | 21 ++++- ui/app/custom/src/pages/page-custom.ts | 20 ++++- ui/component/model/src/index.ts | 18 ++++ ui/component/model/src/util.ts | 18 ++++ ui/component/rest/src/index.ts | 18 ++++ 17 files changed, 327 insertions(+), 236 deletions(-) diff --git a/agent/src/main/java/org/openremote/agent/custom/CustomAgent.java b/agent/src/main/java/org/openremote/agent/custom/CustomAgent.java index 2a152dec8..4610d6490 100644 --- a/agent/src/main/java/org/openremote/agent/custom/CustomAgent.java +++ b/agent/src/main/java/org/openremote/agent/custom/CustomAgent.java @@ -1,9 +1,6 @@ /* * Copyright 2017, OpenRemote Inc. * - * See the CONTRIBUTORS.txt file in the distribution for a - * full listing of individual contributors. - * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the @@ -15,10 +12,14 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-or-later */ package org.openremote.agent.custom; +import java.util.Optional; + import org.openremote.model.asset.Asset; import org.openremote.model.asset.agent.Agent; import org.openremote.model.asset.agent.AgentDescriptor; @@ -27,57 +28,57 @@ import org.openremote.model.value.ValueDescriptor; import jakarta.persistence.Entity; -import java.util.Optional; /** - * This is an example of a custom {@link Agent} type; this must be registered via an - * {@link org.openremote.model.AssetModelProvider} and must conform to the same requirements as custom {@link Asset}s and - * in addition the following requirements: + * This is an example of a custom {@link Agent} type; this must be registered via an {@link + * org.openremote.model.AssetModelProvider} and must conform to the same requirements as custom + * {@link Asset}s and in addition the following requirements: * *
    - *
  • Optionally add a custom {@link org.openremote.model.asset.agent.AgentLink} (the {@link Class#getSimpleName} must - * be unique compared to all other registered {@link org.openremote.model.asset.agent.AgentLink}s) - *
  • Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that corresponds to this {@link Agent} - *
  • Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor} rather than an - * {@link org.openremote.model.asset.AssetDescriptor} + *
  • Optionally add a custom {@link org.openremote.model.asset.agent.AgentLink} (the {@link + * Class#getSimpleName} must be unique compared to all other registered {@link + * org.openremote.model.asset.agent.AgentLink}s) + *
  • Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that + * corresponds to this {@link Agent} + *
  • Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor} + * rather than an {@link org.openremote.model.asset.AssetDescriptor} *
*/ @Entity public class CustomAgent extends Agent { - public enum Option { - ONE, - TWO, - THREE - }; + public enum Option { + ONE, + TWO, + THREE + }; - public static final ValueDescriptor