Skip to content
Merged
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
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Java Linting

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Install dependencies
run: mvn install -DskipTests

- name: Run Checkstyle
run: mvn checkstyle:check

- name: Run PMD
run: mvn pmd:check
42 changes: 42 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="120"/>
</module>
<!-- Coding style rules -->
<module name="TreeWalker">

<!-- Naming conventions -->
<module name="ConstantName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="TypeName"/>

<!-- Imports -->
<module name="UnusedImports"/>

<!-- Formatting -->
<module name="WhitespaceAround"/>
<module name="WhitespaceAfter"/>
<module name="Indentation"/>
<module name="LeftCurly"/>
<module name="RightCurly"/>

<!-- Miscellaneous -->
<module name="VisibilityModifier"/>
<module name="NestedIfDepth">
<property name="max" value="3"/>
</module>
</module>
</module>

32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@
</extensions>

<plugins>
<!-- Checkstyle Plugin: For enforcing coding standards and style guidelines. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>

<!-- PMD Plugin:For detecting unused variables, code complexity, and other potential issues. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.16.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ public class UCloudEventAttributes {
/**
* Construct the properties object.
*
* @param hash An HMAC generated on the data portion of the CloudEvent message using the device key.
* @param hash An HMAC generated on the data portion of the CloudEvent
* message using the device key.
* @param priority uProtocol Prioritization classifications.
* @param ttl How long this event should live for after it was generated (in milliseconds).
* Events without this attribute (or value is 0) MUST NOT timeout.
* @param token Oauth2 access token to perform the access request defined in the request message.
* @param ttl How long this event should live for after it was generated
* (in milliseconds).
* Events without this attribute (or value is 0) MUST NOT
* timeout.
* @param token Oauth2 access token to perform the access request defined in
* the request message.
*/
private UCloudEventAttributes(String hash, UPriority priority, Integer ttl, String token) {
this.hash = hash;
Expand All @@ -56,28 +60,35 @@ private UCloudEventAttributes(UCloudEventAttributesBuilder builder) {
}

/**
* Static factory method for creating an empty cloud event attributes object, to avoid working with null<br>
* @return Returns an empty cloud event attributes that indicates
* that there are no added additional attributes to configure.
* Static factory method for creating an empty cloud event attributes object, to
* avoid working with null<br>
*
* @return Returns an empty cloud event attributes that indicates
* that there are no added additional attributes to configure.
*/
public static UCloudEventAttributes empty() {
return EMPTY;
}

/**
* Indicates that there are no added additional attributes to configure when building a CloudEvent.
* @return Returns true if this attributes container is an empty container and has no valuable information in building a CloudEvent.
* Indicates that there are no added additional attributes to configure when
* building a CloudEvent.
*
* @return Returns true if this attributes container is an empty container and
* has no valuable information in building a CloudEvent.
*/
public boolean isEmpty() {
return hash().isEmpty() &&
priority().isEmpty() &&
ttl().isEmpty() &&
token().isEmpty() &&
traceparent().isEmpty();
return hash().isEmpty() &&
priority().isEmpty() &&
ttl().isEmpty() &&
token().isEmpty() &&
traceparent().isEmpty();
}

/**
* An HMAC generated on the data portion of the CloudEvent message using the device key.
* An HMAC generated on the data portion of the CloudEvent message using the
* device key.
*
* @return Returns an Optional hash attribute.
*/
public Optional<String> hash() {
Expand All @@ -86,6 +97,7 @@ public Optional<String> hash() {

/**
* uProtocol Prioritization classifications.
*
* @return Returns an Optional priority attribute.
*/
public Optional<UPriority> priority() {
Expand All @@ -94,28 +106,32 @@ public Optional<UPriority> priority() {

/**
* How long this event should live for after it was generated (in milliseconds).
*
* @return Returns an Optional time to live attribute.
*/
public Optional<Integer> ttl() {
return ttl == null ? Optional.empty() : Optional.of(ttl);
}

/**
* Oauth2 access token to perform the access request defined in the request message.
* Oauth2 access token to perform the access request defined in the request
* message.
*
* @return Returns an Optional OAuth token attribute.
*/
public Optional<String> token() {
return token == null || token.isBlank() ? Optional.empty() : Optional.of(token);
}

/**
* An identifier used to correlate observability across related events.
*
* @return Returns an Optional traceparent attribute.
*/
public Optional<String> traceparent() {
return traceparent == null || traceparent.isBlank() ? Optional.empty() : Optional.of(traceparent);
}

/**
* Builder for constructing the UCloudEventAttributes.
*/
Expand All @@ -126,11 +142,15 @@ public static class UCloudEventAttributesBuilder {
private String token;
private String traceparent;

public UCloudEventAttributesBuilder() {}
public UCloudEventAttributesBuilder() {
}

/**
* add an HMAC generated on the data portion of the CloudEvent message using the device key.
* @param hash an HMAC generated on the data portion of the CloudEvent message using the device key.
* add an HMAC generated on the data portion of the CloudEvent message using the
* device key.
*
* @param hash an HMAC generated on the data portion of the CloudEvent message
* using the device key.
* @return Returns the UCloudEventAttributesBuilder with the configured hash.
*/
public UCloudEventAttributesBuilder withHash(String hash) {
Expand All @@ -140,30 +160,40 @@ public UCloudEventAttributesBuilder withHash(String hash) {

/**
* add a uProtocol Prioritization classifications.
*
* @param priority uProtocol Prioritization classifications.
* @return Returns the UCloudEventAttributesBuilder with the configured priority.
* @return Returns the UCloudEventAttributesBuilder with the configured
* priority.
*/
public UCloudEventAttributesBuilder withPriority(UPriority priority) {
this.priority = priority;
return this;
}

/**
* add a time to live which is how long this event should live for after it was generated (in milliseconds).
* add a time to live which is how long this event should live for after it was
* generated (in milliseconds).
* Events without this attribute (or value is 0) MUST NOT timeout.
* @param ttl How long this event should live for after it was generated (in milliseconds).
*
* @param ttl How long this event should live for after it was generated (in
* milliseconds).
* Events without this attribute (or value is 0) MUST NOT timeout.
* @return Returns the UCloudEventAttributesBuilder with the configured time to live.
* @return Returns the UCloudEventAttributesBuilder with the configured time to
* live.
*/
public UCloudEventAttributesBuilder withTtl(Integer ttl) {
this.ttl = ttl;
return this;
}

/**
* Add an Oauth2 access token to perform the access request defined in the request message.
* @param token An Oauth2 access token to perform the access request defined in the request message.
* @return Returns the UCloudEventAttributesBuilder with the configured OAuth token.
* Add an Oauth2 access token to perform the access request defined in the
* request message.
*
* @param token An Oauth2 access token to perform the access request defined in
* the request message.
* @return Returns the UCloudEventAttributesBuilder with the configured OAuth
* token.
*/
public UCloudEventAttributesBuilder withToken(String token) {
this.token = token;
Expand All @@ -172,16 +202,20 @@ public UCloudEventAttributesBuilder withToken(String token) {

/**
* Add an identifier used to correlate observability across related events.
* @param traceparent An identifier used to correlate observability across related events.
* @return Returns the UCloudEventAttributesBuilder with the configured traceparent.
*
* @param traceparent An identifier used to correlate observability across
* related events.
* @return Returns the UCloudEventAttributesBuilder with the configured
* traceparent.
*/
public UCloudEventAttributesBuilder withTraceparent(String traceparent) {
this.traceparent = traceparent;
return this;
}

/**
* Construct the UCloudEventAttributes from the builder.
*
* @return Returns a constructed UProperty.
*/
public UCloudEventAttributes build() {
Expand All @@ -192,8 +226,10 @@ public UCloudEventAttributes build() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
UCloudEventAttributes that = (UCloudEventAttributes) o;
return Objects.equals(hash, that.hash) && priority == that.priority
&& Objects.equals(ttl, that.ttl) && Objects.equals(token, that.token)
Expand Down
Loading