Skip to content

Add Spotless Gradle plugin configuration and apply it #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions agent/src/main/java/org/openremote/agent/custom/CustomAgent.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* 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;
Expand All @@ -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:
*
* <ul>
* <li>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)
* <li>Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that corresponds to this {@link Agent}
* <li>Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor} rather than an
* {@link org.openremote.model.asset.AssetDescriptor}
* <li>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)
* <li>Must define a {@link org.openremote.model.asset.agent.Protocol} implementation that
* corresponds to this {@link Agent}
* <li>Must have a public static final {@link org.openremote.model.asset.agent.AgentDescriptor}
* rather than an {@link org.openremote.model.asset.AssetDescriptor}
* </ul>
*/
@Entity
public class CustomAgent extends Agent<CustomAgent, CustomProtocol, DefaultAgentLink> {

public enum Option {
ONE,
TWO,
THREE
};
public enum Option {
ONE,
TWO,
THREE
};

public static final ValueDescriptor<Option> OPTION_VALUE_DESCRIPTOR = new ValueDescriptor<>("customAgentOption", Option.class);
public static final ValueDescriptor<Option> OPTION_VALUE_DESCRIPTOR =
new ValueDescriptor<>("customAgentOption", Option.class);

public static final AttributeDescriptor<Option> OPTION_ATTRIBUTE_DESCRIPTOR = new AttributeDescriptor<>("option", OPTION_VALUE_DESCRIPTOR);
public static final AttributeDescriptor<Option> OPTION_ATTRIBUTE_DESCRIPTOR =
new AttributeDescriptor<>("option", OPTION_VALUE_DESCRIPTOR);

public static final AgentDescriptor<CustomAgent, CustomProtocol, DefaultAgentLink> DESCRIPTOR = new AgentDescriptor<>(
CustomAgent.class, CustomProtocol.class, DefaultAgentLink.class
);
public static final AgentDescriptor<CustomAgent, CustomProtocol, DefaultAgentLink> DESCRIPTOR =
new AgentDescriptor<>(CustomAgent.class, CustomProtocol.class, DefaultAgentLink.class);

protected CustomAgent() {
}
protected CustomAgent() {}

public CustomAgent(String name) {
super(name);
}
public CustomAgent(String name) {
super(name);
}

@Override
public CustomProtocol getProtocolInstance() {
return new CustomProtocol(this);
}
@Override
public CustomProtocol getProtocolInstance() {
return new CustomProtocol(this);
}

public Optional<Option> getOption() {
return getAttributes().getValue(OPTION_ATTRIBUTE_DESCRIPTOR);
}
public Optional<Option> getOption() {
return getAttributes().getValue(OPTION_ATTRIBUTE_DESCRIPTOR);
}

public CustomAgent setOption(Option value) {
getAttributes().getOrCreate(OPTION_ATTRIBUTE_DESCRIPTOR).setValue(value);
return this;
}
public CustomAgent setOption(Option value) {
getAttributes().getOrCreate(OPTION_ATTRIBUTE_DESCRIPTOR).setValue(value);
return this;
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* Copyright 2021, 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
Expand All @@ -15,17 +12,18 @@
* 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 <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package org.openremote.agent.custom;

import org.openremote.model.AssetModelProvider;

public class CustomAgentModelProvider implements AssetModelProvider {

@Override
public boolean useAutoScan() {
return true;
}
@Override
public boolean useAutoScan() {
return true;
}
}
85 changes: 40 additions & 45 deletions agent/src/main/java/org/openremote/agent/custom/CustomProtocol.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,68 +12,66 @@
* 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 <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.agent.custom;

import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;

import java.util.logging.Logger;

import org.openremote.agent.protocol.AbstractProtocol;
import org.openremote.model.Container;
import org.openremote.model.asset.agent.DefaultAgentLink;
import org.openremote.model.attribute.Attribute;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.syslog.SyslogCategory;

import java.util.logging.Logger;

import static org.openremote.model.syslog.SyslogCategory.PROTOCOL;

/**
* A custom protocol that is used by the {@link CustomAgent}; there is a one-to-one mapping between an {@link
* CustomAgent} {@link org.openremote.model.asset.Asset} and its' {@link org.openremote.model.asset.agent.Protocol}.
* This example does nothing useful but is intended to show where protocol classes should be created.
* A custom protocol that is used by the {@link CustomAgent}; there is a one-to-one mapping between
* an {@link CustomAgent} {@link org.openremote.model.asset.Asset} and its' {@link
* org.openremote.model.asset.agent.Protocol}. This example does nothing useful but is intended to
* show where protocol classes should be created.
*/
public class CustomProtocol extends AbstractProtocol<CustomAgent, DefaultAgentLink> {

public static final String PROTOCOL_DISPLAY_NAME = "Custom";
private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, CustomProtocol.class);
protected boolean running;

public CustomProtocol(CustomAgent agent) {
super(agent);
}

@Override
protected void doStart(Container container) throws Exception {
running = true;
}

@Override
protected void doStop(Container container) throws Exception {

}
public static final String PROTOCOL_DISPLAY_NAME = "Custom";
private static final Logger LOG = SyslogCategory.getLogger(PROTOCOL, CustomProtocol.class);
protected boolean running;

@Override
protected void doLinkAttribute(String assetId, Attribute<?> attribute, DefaultAgentLink agentLink) throws RuntimeException {
public CustomProtocol(CustomAgent agent) {
super(agent);
}

}
@Override
protected void doStart(Container container) throws Exception {
running = true;
}

@Override
protected void doUnlinkAttribute(String assetId, Attribute<?> attribute, DefaultAgentLink agentLink) {
@Override
protected void doStop(Container container) throws Exception {}

}
@Override
protected void doLinkAttribute(String assetId, Attribute<?> attribute, DefaultAgentLink agentLink)
throws RuntimeException {}

@Override
protected void doLinkedAttributeWrite(DefaultAgentLink agentLink, AttributeEvent event, Object processedValue) {
@Override
protected void doUnlinkAttribute(
String assetId, Attribute<?> attribute, DefaultAgentLink agentLink) {}

}
@Override
protected void doLinkedAttributeWrite(
DefaultAgentLink agentLink, AttributeEvent event, Object processedValue) {}

@Override
public String getProtocolName() {
return PROTOCOL_DISPLAY_NAME;
}
@Override
public String getProtocolName() {
return PROTOCOL_DISPLAY_NAME;
}

@Override
public String getProtocolInstanceUri() {
return "custom://" + agent.getOption();
}
@Override
public String getProtocolInstanceUri() {
return "custom://" + agent.getOption();
}
}
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ scmVersion {
}
}

buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2' }
}
dependencies {
classpath 'com.diffplug.spotless:spotless-plugin-gradle:7.0.3'
}
}

allprojects {
// Apply common project setup
apply from: "${project.rootDir}/project.gradle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/*
* Copyright 2021, 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
Expand All @@ -15,26 +12,22 @@
* 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 <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package org.openremote.manager.custom;

import org.openremote.model.Container;
import org.openremote.model.ContainerService;

public class CustomService implements ContainerService {
@Override
public void init(Container container) throws Exception {

}

@Override
public void start(Container container) throws Exception {

}
@Override
public void init(Container container) throws Exception {}

@Override
public void stop(Container container) throws Exception {
@Override
public void start(Container container) throws Exception {}

}
@Override
public void stop(Container container) throws Exception {}
}
Loading
Loading