Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 10, 2024
2 parents 723ede8 + 30e8b52 commit 1e40db9
Show file tree
Hide file tree
Showing 381 changed files with 9,370 additions and 7,095 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: chmod +x gradlew

- name: Build
run: ./gradlew --no-daemon :api:bootJar
run: ./gradlew --no-daemon :api:shadowJar

- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand Down
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
.PHONY: api desktop bootRun build install
.PHONY: api desktop build install

ifeq ($(OS),Windows_NT)
api:
gradlew.bat api:bootJar
gradlew.bat api:shadowJar

desktop:
cd desktop && npm run electron:build

bootRun:
gradlew.bat api:bootRun --args='--server.port=7000'
else
api:
./gradlew api:bootJar
./gradlew api:shadowJar

desktop:
cd desktop && npm run electron:build:deb

bootRun:
./gradlew api:bootRun --args='--server.port=7000'

install:
sudo dpkg -i desktop/release/nebulosa_0.1.0_amd64.deb
endif
Expand Down
16 changes: 4 additions & 12 deletions api/Main.run.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false"
name="Main"
type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME"
value="nebulosa.api.MainKt"/>
<configuration default="false" name="Main" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="nebulosa.api.MainKt"/>
<module name="nebulosa.api.main"/>
<option name="PROGRAM_PARAMETERS"
value="--server.port=7000 --spring.jpa.show-sql=true --logging.level.nebulosa=DEBUG"/>
<option name="PROGRAM_PARAMETERS" value="--port=7000 --debug"/>
<shortenClasspath name="NONE"/>
<method v="2">
<option name="Gradle.BeforeRunTask"
enabled="true"
tasks="build"
externalProjectPath="$PROJECT_DIR$/api"
vmOptions=""
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" externalProjectPath="$PROJECT_DIR$/api" vmOptions=""
scriptParameters="-x test"/>
</method>
</configuration>
Expand Down
36 changes: 15 additions & 21 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm")
id("org.springframework.boot") version "3.3.2"
id("io.spring.dependency-management") version "1.1.6"
kotlin("plugin.spring")
kotlin("kapt")
id("io.objectbox")
id("com.gradleup.shadow")
}

dependencies {
implementation(project(":nebulosa-alignment"))
implementation(project(":nebulosa-astap"))
implementation(project(":nebulosa-astrometrynet"))
implementation(project(":nebulosa-alpaca-indi"))
implementation(project(":nebulosa-common"))
implementation(project(":nebulosa-autofocus"))
implementation(project(":nebulosa-curve-fitting"))
implementation(project(":nebulosa-guiding-phd2"))
implementation(project(":nebulosa-hips2fits"))
implementation(project(":nebulosa-horizons"))
implementation(project(":nebulosa-image"))
implementation(project(":nebulosa-indi-client"))
implementation(project(":nebulosa-job-manager"))
implementation(project(":nebulosa-log"))
implementation(project(":nebulosa-lx200-protocol"))
implementation(project(":nebulosa-nova"))
Expand All @@ -29,6 +28,7 @@ dependencies {
implementation(project(":nebulosa-simbad"))
implementation(project(":nebulosa-siril"))
implementation(project(":nebulosa-stellarium-protocol"))
implementation(project(":nebulosa-util"))
implementation(project(":nebulosa-wcs"))
implementation(project(":nebulosa-xisf"))
implementation(libs.rx)
Expand All @@ -37,29 +37,23 @@ dependencies {
implementation(libs.eventbus)
implementation(libs.okhttp)
implementation(libs.oshi)
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude(module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-websocket") {
exclude(module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-undertow")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
kapt("org.springframework:spring-context-indexer:6.1.12")
implementation(libs.javalin)
implementation(libs.koin)
implementation(libs.airline)

testImplementation(project(":nebulosa-astrobin-api"))
testImplementation(project(":nebulosa-skycatalog-stellarium"))
testImplementation(project(":nebulosa-test"))
}

tasks.withType<BootJar> {
archiveFileName = "api.jar"
destinationDirectory = file("$rootDir/desktop")
tasks.withType<ShadowJar> {
isZip64 = true

archiveFileName.set("api.jar")
destinationDirectory.set(file("../desktop"))

manifest {
attributes["Start-Class"] = "nebulosa.api.MainKt"
attributes["Main-Class"] = "nebulosa.api.MainKt"
}
}

Expand Down
47 changes: 12 additions & 35 deletions api/src/main/kotlin/nebulosa/api/Main.kt
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
package nebulosa.api

import com.github.rvesse.airline.SingleCommand
import com.sun.jna.Platform
import nebulosa.time.SystemClock
import org.springframework.boot.runApplication
import java.nio.file.Path
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
import javax.swing.filechooser.FileSystemView
import kotlin.io.path.Path
import kotlin.io.path.createDirectories
import kotlin.io.path.deleteIfExists
import kotlin.io.path.exists
import kotlin.io.path.listDirectoryEntries

const val APP_DIR_KEY = "app.dir"

fun initAppDirectory(): Path {
val appPath = when {
Platform.isLinux() -> Path.of(System.getProperty("user.home"), ".nebulosa")
Platform.isWindows() -> Path.of(FileSystemView.getFileSystemView().defaultDirectory.path, "Nebulosa")
Platform.isLinux() -> Path(System.getProperty("user.home"), ".nebulosa")
Platform.isWindows() -> Path(FileSystemView.getFileSystemView().defaultDirectory.path, "Nebulosa")
else -> throw IllegalStateException("unsupported operating system")
}

appPath.createDirectories()
System.setProperty("app.dir", "$appPath")
return appPath
}

private fun Path.clearLogIfPastDays(days: Long = 7L) {
if (exists()) {
val pastDays = LocalDate.now(SystemClock).minusDays(days)

for (entry in listDirectoryEntries("nebulosa-*.log")) {
val logDate = entry.fileName.toString()
.replace("nebulosa-", "")
.replace(".log", "")
.let { runCatching { LocalDate.parse(it, DateTimeFormatter.ISO_LOCAL_DATE) }.getOrNull() }
?: continue

if (pastDays.isAfter(logDate)) {
entry.deleteIfExists()
}
}
}
.createDirectories()
.also { System.setProperty(APP_DIR_KEY, "$it") }
}

fun main(args: Array<String>) {
with(initAppDirectory()) {
Path.of("$this", "logs").createDirectories().clearLogIfPastDays()
Path.of("$this", "data").createDirectories().also { System.setProperty("DATA_PATH", "$it") }
}
initAppDirectory()

// Sets default locale to en_US.
Locale.setDefault(Locale.ENGLISH)

// Run the Spring Boot application.
runApplication<Nebulosa>(*args)
val parser = SingleCommand.singleCommand(Nebulosa::class.java)
val nebulosa = parser.parse(*args)
nebulosa.run()
}
78 changes: 70 additions & 8 deletions api/src/main/kotlin/nebulosa/api/Nebulosa.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,82 @@
package nebulosa.api

import ch.qos.logback.classic.Level
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jsonMapper
import com.github.rvesse.airline.annotations.Command
import com.github.rvesse.airline.annotations.Option
import io.javalin.Javalin
import io.javalin.json.JavalinJackson
import nebulosa.api.atlas.Location
import nebulosa.api.beans.modules.DeviceModule
import nebulosa.api.inject.*
import nebulosa.json.PathModule
import nebulosa.log.loggerFor
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent
import org.springframework.context.event.EventListener
import org.koin.core.context.startKoin
import org.slf4j.LoggerFactory
import java.util.concurrent.ConcurrentHashMap

@SpringBootApplication
class Nebulosa {
@Command(name = "nebulosa")
class Nebulosa : Runnable, AutoCloseable {

@EventListener
private fun onServletWebServerInitializedEvent(event: ServletWebServerInitializedEvent) {
LOG.info("server is started at port: ${event.webServer.port}")
@Option(name = ["-h", "--host"])
private var host = "0.0.0.0"

@Option(name = ["-p", "--port"])
private var port = 0

@Option(name = ["-d", "--debug"])
private var debug = false

private lateinit var app: Javalin

override fun run() {
if (debug) {
with(LoggerFactory.getLogger("nebulosa") as ch.qos.logback.classic.Logger) {
level = Level.DEBUG
}
}

// Run the server.
app = Javalin.create { config ->
config.showJavalinBanner = false
// JACKSON
config.jsonMapper(JavalinJackson(OBJECT_MAPPER))
// CORS
config.bundledPlugins.enableCors { cors ->
cors.addRule {
it.anyHost()
it.exposeHeader("X-Image-Info")
}
}
}.start(host, port)

koinApp.modules(appModule(app))
koinApp.modules(objectMapperModule(OBJECT_MAPPER))
koinApp.modules(servicesModule())
koinApp.modules(controllersModule())
startKoin(koinApp)

LOG.info("server is started at port: {}", app.port())
}

override fun close() {
app.stop()
}

companion object {

@JvmStatic private val LOG = loggerFor<Nebulosa>()

@JvmStatic private val OBJECT_MAPPER = jsonMapper {
addModule(JavaTimeModule())
addModule(PathModule())
addModule(DeviceModule())
disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
}
}
}
Loading

0 comments on commit 1e40db9

Please sign in to comment.