Skip to content

Commit

Permalink
Prepping new release
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Jul 5, 2024
1 parent 242c8e2 commit 35c0b57
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ repositories {
}

dependencies {
testImplementation("ch.qos.logback:logback-classic:1.5.1")
testImplementation("ch.qos.logback:logback-classic:1.5.6")
testImplementation("org.slf4j:slf4j-jdk-platform-logging:2.0.12")
}

group = "org.mbari.commons"
version = "0.0.6"
version = "0.0.7"
extra["artifactIdForMaven"] = project.name

java {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mbari.jcommons.util;

import java.util.concurrent.locks.ReentrantLock;


public class AutoCloseableLock extends ReentrantLock implements AutoCloseable {

public AutoCloseableLock lockAndGet() {
lock();
return this;
}

@Override
public void close() {
unlock();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* }
* }
*
* @see https://debugagent.com/relearning-java-thread-primitives
* From https://debugagent.com/relearning-java-thread-primitives
*
* @deprecated Use {@link AutoCloseableLock} instead
*
*/

public class CloseableLock implements AutoCloseable, Lock {
private final Lock lock;

Expand Down
2 changes: 1 addition & 1 deletion scommons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ java {

dependencies {
api(project(":jcommons"))
implementation("org.scala-lang:scala3-library_3:3.3.1")
implementation("org.scala-lang:scala3-library_3:3.3.3")
implementation("com.github.rwl:jtransforms:2.4.0")
implementation("org.typelevel:spire_3:0.18.0")
implementation("org.apache.commons:commons-math3:3.6.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.function.Supplier
/**
* Add fluent logging to System.Logger. Usage:
* {{{
* import org.fathomnet.support.etc.jdk.Logging.{given, *}
* import org.fathomnet.support.etc.jdk.Loggers.{given, *}
* given log: Logger = Sytem.getLogger("my.logger")
*
* log.atInfo.log("Hello World")
Expand All @@ -17,7 +17,7 @@ import java.util.function.Supplier
* }}}
* * @author Brian Schlining
*/
object Logging:
object Loggers:

case class LoggerBuilder(
logger: Logger,
Expand Down
18 changes: 18 additions & 0 deletions scommons/src/main/scala/org/mbari/scommons/etc/jdk/Uris.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package org.mbari.scommons.etc.jdk

import java.net.URI
import Loggers.given
import scala.util.control.NonFatal
import java.net.HttpURLConnection

object Uris:

private val log = System.getLogger(getClass.getName)

def filename(uri: URI): String = uri.getPath.split('/').last

def exists(uri: URI): Boolean = try
HttpURLConnection.setFollowRedirects(false)
val connection = uri.toURL.openConnection().asInstanceOf[HttpURLConnection]
connection.setRequestMethod("HEAD")
connection.getResponseCode == HttpURLConnection.HTTP_OK
catch
case NonFatal(e) =>
log
.atWarn
.withCause(e)
.log(s"Failed to connect to $uri")
false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.mbari.scommons.math

import org.mbari.scommons.etc.jdk.Logging.given
import org.mbari.scommons.etc.jdk.Loggers.given
import java.lang.System.Logger.Level

/**
Expand Down
25 changes: 6 additions & 19 deletions scommons/src/main/scala/org/mbari/scommons/util/ISO8601.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,21 @@ import java.time.format.DateTimeFormatter
import java.time.ZoneId
import java.time.Instant
import scala.util.Try
import org.mbari.scommons.etc.jdk.Instants

@deprecated("Use org.mbari.scommons.Instants instead", "0.0.7")
object ISO8601:

private val utcZone = ZoneId.of("UTC")
val TimeFormatter: DateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME.withZone(utcZone)
val CompactTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(utcZone)
val CompactTimeFormatterMs: DateTimeFormatter =
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss.SSSX").withZone(utcZone)
val CompactTimeFormatterNs: DateTimeFormatter =
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss.SSSSSSX").withZone(utcZone)

def parseIso8601(s: String): Either[Throwable, Instant] =
val tried = Try(Instant.from(CompactTimeFormatter.parse(s))) orElse
Try(Instant.from(TimeFormatter.parse(s))) orElse
Try(Instant.from(CompactTimeFormatterMs.parse(s))) orElse
Try(Instant.from(CompactTimeFormatterNs.parse(s)))
tried.toEither

Instants.parseIso8601(s) match
case Some(i) => Right(i)
case None => Left(new IllegalArgumentException(s"Could not parse $s as an ISO8601 timestamp"))


/**
* Parse a string in common ISO8601 formats into an Instant
* @param timestamp
* @return
*/
def parse(timestamp: String): Option[Instant] =
Try(formatMillis.parse(timestamp))
.orElse(Try(formatSeconds.parse(timestamp)))
.orElse(Try(DateTimeFormatter.ISO_INSTANT.parse(timestamp)))
.toOption
.map(Instant.from)
def parse(timestamp: String): Option[Instant] = Instants.parseIso8601(timestamp)

0 comments on commit 35c0b57

Please sign in to comment.