Skip to content

Commit

Permalink
Merge pull request #813 from SpineEventEngine/promote-closeable
Browse files Browse the repository at this point in the history
Promote `Closeable` inteface from `io.spine.server`
  • Loading branch information
alexander-yevsyukov authored Feb 3, 2024
2 parents 722a87e + 5adec40 commit 8bb9617
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package io.spine.internal.dependency
)
object Protobuf {
private const val group = "com.google.protobuf"
const val version = "3.25.1"
const val version = "3.25.2"
/**
* The Java library containing proto definitions of Google Protobuf.
*/
Expand Down
18 changes: 9 additions & 9 deletions dependencies.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-base:2.0.0-SNAPSHOT.196`
# Dependencies of `io.spine:spine-base:2.0.0-SNAPSHOT.197`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -30,15 +30,15 @@
* **Project URL:** [https://github.com/google/j2objc/](https://github.com/google/j2objc/)
* **License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

1. **Group** : com.google.protobuf. **Name** : protobuf-java. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-java. **Version** : 3.25.2.
* **Project URL:** [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/)
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : com.google.protobuf. **Name** : protobuf-java-util. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-java-util. **Version** : 3.25.2.
* **Project URL:** [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/)
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : com.google.protobuf. **Name** : protobuf-kotlin. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-kotlin. **Version** : 3.25.2.
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : org.checkerframework. **Name** : checker-qual. **Version** : 3.40.0.
Expand Down Expand Up @@ -208,18 +208,18 @@
* **Project URL:** [https://github.com/google/j2objc/](https://github.com/google/j2objc/)
* **License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)

1. **Group** : com.google.protobuf. **Name** : protobuf-java. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-java. **Version** : 3.25.2.
* **Project URL:** [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/)
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : com.google.protobuf. **Name** : protobuf-java-util. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-java-util. **Version** : 3.25.2.
* **Project URL:** [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/)
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : com.google.protobuf. **Name** : protobuf-kotlin. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protobuf-kotlin. **Version** : 3.25.2.
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)

1. **Group** : com.google.protobuf. **Name** : protoc. **Version** : 3.25.1.
1. **Group** : com.google.protobuf. **Name** : protoc. **Version** : 3.25.2.
* **Project URL:** [https://developers.google.com/protocol-buffers/](https://developers.google.com/protocol-buffers/)
* **License:** [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
* **License:** [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Expand Down Expand Up @@ -771,4 +771,4 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Mon Jan 08 14:50:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sat Feb 03 21:50:00 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>base</artifactId>
<version>2.0.0-SNAPSHOT.196</version>
<version>2.0.0-SNAPSHOT.197</version>

<inceptionYear>2015</inceptionYear>

Expand All @@ -32,19 +32,19 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.25.1</version>
<version>3.25.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.25.1</version>
<version>3.25.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-kotlin</artifactId>
<version>3.25.1</version>
<version>3.25.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -174,7 +174,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protoc</artifactId>
<version>3.25.1</version>
<version>3.25.2</version>
</dependency>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
Expand Down
84 changes: 84 additions & 0 deletions src/main/kotlin/io/spine/io/Closeable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2024, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.spine.io

/**
* Base interface for objects that may hold resources that need to be released
* at the end of the object lifecycle.
*
* A class will benefit from implementing *this* interface instead of
* [AutoCloseable] if it needs to see if the instance is [open][isOpen]
* prior to making other calls.
*
* @see isOpen
* @see checkOpen
*/
public interface Closeable : AutoCloseable {

/**
* Tells if the object is still open.
*
* Implementations must return `false` after [close] is invoked.
*/
public val isOpen: Boolean

/**
* Performs the release of the resources held by this object.
*
* Overrides to remove the checked exception from the signature.
*
* Implementations <em>may</em> require that the object implementing this interface
* invokes this method only once, and throw [IllegalStateException] for repeated invocation.
* If this is the case, and you would like to avoid [pre-checking][isOpen] consider
* using [closeIfOpen], which does the check itself.
*
* @see closeIfOpen
*/
public override fun close()

/**
* Ensures that the object [isOpen].
*
* @throws IllegalStateException otherwise
*/
@Throws(IllegalStateException::class)
public fun checkOpen() {
check(isOpen) { "`$this` is already closed." }
}

/**
* Performs the release of the resources held by this object only if it is still open.
*
* Otherwise, does nothing.
*
* @see close
*/
public fun closeIfOpen() {
if (isOpen) {
close()
}
}
}
82 changes: 82 additions & 0 deletions src/test/kotlin/io/spine/io/CloseableSpec.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2024, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.io

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows

@DisplayName("`Closeable` interface should")
internal class CloseableSpec {

@Test
fun `tell if the object is open`() {
Window(true).isOpen shouldBe true
Window(false).isOpen shouldBe false
}

@Test
fun `close the object`() {
with (Window(true)) {
close()
isOpen shouldBe false
}
}

@Test
fun `ensure that the object is open`() {
assertThrows<IllegalStateException> {
Window(false).checkOpen()
}
}

@Test
fun `close the object, if open`() {
with(Window(true)) {
isOpen shouldBe true
closeIfOpen()
isOpen shouldBe false
}
with(Window(false)) {
isOpen shouldBe false
assertDoesNotThrow { closeIfOpen() }
isOpen shouldBe false
}
}
}

private class Window(private var state: Boolean) : Closeable {

override val isOpen: Boolean
get() = state

override fun close() {
state = false
}
}
2 changes: 1 addition & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

val versionToPublish: String by extra("2.0.0-SNAPSHOT.196")
val versionToPublish: String by extra("2.0.0-SNAPSHOT.197")

0 comments on commit 8bb9617

Please sign in to comment.