Skip to content

Commit

Permalink
Replaced Path.of with Paths.get. Should be now compatible with Java 8…
Browse files Browse the repository at this point in the history
…. Bumped version to 1.5.2-SNAPSHOT
  • Loading branch information
MarioRivis committed Feb 15, 2022
1 parent cb2c611 commit 8789b11
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ versions:
- java version "(?<version>.+)"
- (?i)openjdk(?-i) version "(?<version>.+)"
- name: Python
min: 3.8
min: 3.9
win: python -V
unix: python -V
unix: python3 -V
match:
- Python (?<version>.+)
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'

- name: Extract Semver
id: semver_parser
run: |
Expand Down
6 changes: 3 additions & 3 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<parent>
<groupId>org.dxworks.voyager</groupId>
<artifactId>parent</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>api</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.4.31</kotlin.version>
</properties>

Expand Down
8 changes: 4 additions & 4 deletions dx-voyager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
<parent>
<artifactId>parent</artifactId>
<groupId>org.dxworks.voyager</groupId>
<version>1.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dx-voyager</artifactId>

<properties>
<version>$tag_version</version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<main.class>org.dxworks.voyager.MainKt</main.class>
<jar.final.name>dx-voyager</jar.final.name>
</properties>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>org.dxworks.voyager</groupId>
<artifactId>api</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
9 changes: 5 additions & 4 deletions dx-voyager/src/main/kotlin/org/dxworks/voyager/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import org.apache.commons.io.FileUtils
import org.dxworks.voyager.mission.MissionControl
import org.dxworks.voyager.doctor.versionDoctor
import org.dxworks.voyager.instruments.Instrument
import org.dxworks.voyager.instruments.InstrumentGatherer
import org.dxworks.voyager.mission.MissionControl
import org.dxworks.voyager.report.MissionSummary
import org.dxworks.voyager.results.ResultsContainer
import org.dxworks.voyager.utils.*
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileFilter
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import kotlin.system.exitProcess

Expand Down Expand Up @@ -79,7 +79,7 @@ fun main(args: Array<String>) {

log.info(if (instrumentResults.isEmpty()) "Nothing to package" else "Packaging results")

val reports = Path.of(".").toFile()
val reports = Paths.get(".").toFile()
.listFiles(FileFilter { FileSystems.getDefault().getPathMatcher("glob:**/*.log").matches(it.toPath()) })
?: emptyArray()

Expand All @@ -94,7 +94,8 @@ fun main(args: Array<String>) {
}


clean(containerContent.map { it.file }.filter { it != missionControl.missionFile && it.nameWithoutExtension != missionReport })
clean(containerContent.map { it.file }
.filter { it != missionControl.missionFile && it.nameWithoutExtension != missionReport })
}

private fun getInitialisedMissionControl(args: Array<String>): MissionControl {
Expand Down
10 changes: 5 additions & 5 deletions dx-voyager/src/main/kotlin/org/dxworks/voyager/doctor/Doctor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.dxworks.voyager.mission.MissionControl
import org.dxworks.voyager.utils.versionGroupName
import org.dxworks.voyager.utils.yamlMapper
import org.slf4j.LoggerFactory
import java.nio.file.Path
import java.nio.file.Paths


fun versionDoctor(doctorFile: String): Boolean {
Expand All @@ -22,13 +22,13 @@ fun versionDoctor(doctorFile: String): Boolean {
log.info("---------------------------------------------")
log.info("Checking ${rule.name}")
val process = MissionControl.get().getProcessBuilder()
.directory(Path.of(rule.dir ?: ".").toFile())
.directory(Paths.get(rule.dir ?: ".").toFile())
.command(commandInterpreterName, interpreterArg, rule.exec)
.start()
process.waitFor()

val std = String(process.inputStream.readAllBytes())
val err = String(process.errorStream.readAllBytes())
val std = String(process.inputStream.readBytes())
val err = String(process.errorStream.readBytes())

log.info(rule.exec)
std.split("\n").forEach { log.info(it) }
Expand Down Expand Up @@ -61,4 +61,4 @@ fun versionDoctor(doctorFile: String): Boolean {
}

private fun readDoctorConfig(doctorFile: String) =
yamlMapper.readValue<DoctorConfig>(Path.of(doctorFile).toFile())
yamlMapper.readValue<DoctorConfig>(Paths.get(doctorFile).toFile())
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileFilter
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.concurrent.thread

data class Instrument(val path: String, val configuration: InstrumentConfiguration) {
Expand Down Expand Up @@ -138,17 +138,17 @@ data class Instrument(val path: String, val configuration: InstrumentConfigurati
fun getResults(): InstrumentResult? {
return configuration.results?.let { results ->
InstrumentResult(this, results.flatMap { resultDir ->
val dir = Path.of(processTemplate(resultDir.dir)).toFile()
val dir = Paths.get(processTemplate(resultDir.dir)).toFile()
if (resultDir.files.isEmpty()) {
listOf(FileAndAlias(dir, Path.of(name, dir.name).toString()))
listOf(FileAndAlias(dir, Paths.get(name, dir.name).toString()))
} else {
val pathMatchers = resultDir.files.map { "glob:$it" }.map(FileSystems.getDefault()::getPathMatcher)
dir.walkTopDown().filter { file ->
pathMatchers.any { it.matches(dir.toPath().relativize(file.toPath())) }
}.map {
FileAndAlias(
it,
Path.of(name, dir.name, dir.toPath().relativize(it.toPath()).toString())
Paths.get(name, dir.name, dir.toPath().relativize(it.toPath()).toString())
.toString()
)
}.toList()
Expand Down Expand Up @@ -192,7 +192,7 @@ data class Instrument(val path: String, val configuration: InstrumentConfigurati
.toMap()

val processTemplate = processTemplate(exec, repoFolderField, repoNameField)
val dir = Path.of(command.dir?.let { dir -> processTemplate(dir, repoFolderField, repoNameField) } ?: path)
val dir = Paths.get(command.dir?.let { dir -> processTemplate(dir, repoFolderField, repoNameField) } ?: path)
.toFile()
log.info("thread $thread Running command $identifier: $processTemplate in ${dir.path}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import org.dxworks.voyager.api.global.GlobalConfig
import org.dxworks.voyager.api.mission.MissionConfig
import org.dxworks.voyager.api.utils.pathEnv
import org.dxworks.voyager.api.utils.pathEnvSeparator
import java.nio.file.Path
import java.nio.file.Paths

class EnvironmentManager(private val globalConfig: GlobalConfig, private val missionConfig: MissionConfig? = null) {

private val runtimeEnvironment = globalConfig.runtimes.values.joinToString(
separator = pathEnvSeparator,
postfix = pathEnvSeparator
) {
Path.of(it).toAbsolutePath().toString()
Paths.get(it).toAbsolutePath().toString()
}

fun populateEnv(instrumentEnv: Map<String, String>, commandEnv: Map<String, String>, env: MutableMap<String, String>) {
fun populateEnv(
instrumentEnv: Map<String, String>,
commandEnv: Map<String, String>,
env: MutableMap<String, String>
) {
populatePathEnv(env)
env.putAll(instrumentEnv.filterNotNullValues())
env.putAll(commandEnv.filterNotNullValues())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import org.dxworks.voyager.api.mission.MissionConfig
import org.dxworks.voyager.instruments.Instrument
import org.dxworks.voyager.utils.*
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.system.exitProcess

class MissionControl private constructor() {
private val globalConfigFile = Path.of(globalConfigName).toFile()
private val globalConfigFile = Paths.get(globalConfigName).toFile()
private val globalConfig: GlobalConfig = if (globalConfigFile.exists()) {
yamlMapper.readValue(globalConfigFile)
} else {
GlobalConfig()
}
val target: File
get() = Path.of(missionConfig.target).toFile()
get() = Paths.get(missionConfig.target).toFile()
val instrumentsDir: File
get() = (missionConfig.instrumentsDir ?: globalConfig.instrumentsDir)?.let { Path.of(it).toFile() }
get() = (missionConfig.instrumentsDir ?: globalConfig.instrumentsDir)?.let { Paths.get(it).toFile() }
?: defaultInstrumentsDir()

private fun defaultInstrumentsDir() =
Expand All @@ -47,7 +47,7 @@ class MissionControl private constructor() {
}

fun setMissionSource(sourceFile: String) {
val file = Path.of(sourceFile).toFile()
val file = Paths.get(sourceFile).toFile()
if (file.exists()) {
missionFile = file.absoluteFile
missionHome = missionFile.parentFile
Expand Down Expand Up @@ -125,9 +125,10 @@ class MissionControl private constructor() {
environmentManager.populatePathEnv(environment())
}

fun getProcessBuilder(instrumentEnv: Map<String, String>, commandEnv: Map<String, String>) = ProcessBuilder().apply {
environmentManager.populateEnv(instrumentEnv, commandEnv, environment())
}
fun getProcessBuilder(instrumentEnv: Map<String, String>, commandEnv: Map<String, String>) =
ProcessBuilder().apply {
environmentManager.populateEnv(instrumentEnv, commandEnv, environment())
}

fun getThread(name: String): Int {
return missionConfig.instruments[name]?.thread ?: defaultThreadId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ data class MissionSummary(
private fun formatElapsedTime(millis: Long): String {
val duration = Duration.ofMillis(millis)
val sb = StringBuilder()
val days = duration.toDaysPart()
val hours = duration.toHoursPart()
val minutes = duration.toMinutesPart()
val days = duration.toDays()
val hours = duration.toHours()
val minutes = duration.toMinutes()
if (days > 0)
sb.append("$days d ")
if (hours > 0)
sb.append("$hours h ")
if (minutes > 0)
sb.append("$minutes m ")
sb.append("${duration.toSecondsPart()}.${duration.toMillis()} s")
sb.append("${duration.seconds}.${duration.toMillis()} s")
return sb.toString()
}
}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<groupId>org.dxworks.voyager</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.5.0-SNAPSHOT</version>
<version>1.5.2-SNAPSHOT</version>
<modules>
<module>api</module>
<module>dx-voyager</module>
</modules>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<kotlin.version>1.4.31</kotlin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.6.10</kotlin.version>
</properties>

<licenses>
Expand Down

0 comments on commit 8789b11

Please sign in to comment.