Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
create modsman-packutil
Browse files Browse the repository at this point in the history
  • Loading branch information
sargunv committed Apr 18, 2020
1 parent 7608205 commit 45fc6e7
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ jobs:
steps:

- uses: actions/checkout@v2

- name: Fetch unshallow
run: |
git fetch --prune --tags --unshallow
echo $(git describe --tags --always --first-parent)
- uses: actions/setup-java@v1
with:
java-version: '11'

- name: Install
run: ./gradlew distZip --info --stacktrace


- name: Create CLI dist zip
run: ./gradlew :modsman-cli:distZip --info --stacktrace

- name: Create PackUtil jar
run: ./gradlew :modsman-packutil:build --info --stacktrace

- uses: WyriHaximus/github-action-get-previous-tag@0.1.0
id: get_tag

- uses: actions/create-release@v1
id: create_release
env:
Expand All @@ -36,7 +39,7 @@ jobs:
release_name: Modsman v${{ github.ref }}
draft: false
prerelease: true

- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -45,3 +48,12 @@ jobs:
asset_path: ./modsman-cli/build/distributions/modsman-cli-${{ steps.get_tag.outputs.tag }}.zip
asset_name: modsman-cli-${{ steps.get_tag.outputs.tag }}.zip
asset_content_type: application/zip

- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./modsman-packutil/build/libs/modsman-packutil-${{ steps.get_tag.outputs.tag }}.jar
asset_name: modsman-packutil-${{ steps.get_tag.outputs.tag }}.zip
asset_content_type: application/java-archive
2 changes: 1 addition & 1 deletion modsman-cli/src/main/kotlin/modsman/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fun main(args: Array<String>) {
.addCommand(ListCommand)
.addCommand(ListOutdatedCommand)
.build()
jc.programName = "modsman"
jc.programName = "modsman-cli"

try {
jc.parse(*args)
Expand Down
24 changes: 24 additions & 0 deletions modsman-packutil/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
kotlin("jvm")
application
id("com.github.johnrengelman.shadow") version "5.2.0"
}

dependencies {
implementation(project(":modsman-core"))
implementation(group = "com.beust", name = "jcommander", version = "1.71")
}

application {
mainClassName = "modsman.packutil.MainKt"
}

tasks {
shadowJar {
// defaults to project.name
// archiveBaseName.set("${project.name}-fat")

// defaults to all, so removing this overrides the normal, non-fat jar
archiveClassifier.set("")
}
}
89 changes: 89 additions & 0 deletions modsman-packutil/src/main/kotlin/modsman/packutil/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package modsman.packutil

import com.beust.jcommander.JCommander
import com.beust.jcommander.Parameter
import com.beust.jcommander.ParameterException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import modsman.BuildConfig
import modsman.Modsman
import java.nio.file.Files
import java.nio.file.Paths
import java.util.logging.Logger
import kotlin.system.exitProcess

object Args {
@Parameter(names = ["--minecraft-root", "-M"], required = true, order = 0)
lateinit var minecraftRoot: String

@Parameter(names = ["--invoke-in", "-i"], required = true, order = 1)
lateinit var targetDirs: List<String>

@Parameter(names = ["--force", "-f"], order = 2)
var force: Boolean = false

@Parameter(names = ["--version", "-v"], help = true, order = 3)
var version: Boolean = false
}

@FlowPreview
fun main(args: Array<String>) {
val jc = JCommander.newBuilder().addObject(Args).build()
jc.programName = "modsman-packutil"

try {
jc.parse(*args)
} catch (e: ParameterException) {
JCommander.getConsole().println(e.message)
exitProcess(1)
}

if (Args.version) {
JCommander.getConsole().println(BuildConfig.VERSION)
exitProcess(0)
}

System.setProperty(
"java.util.logging.SimpleFormatter.format",
"[%1\$tF %1\$tT] [%4\$s] %5\$s %n"
)
val log = Logger.getGlobal()

runBlocking {
val mcPath = Paths.get(Args.minecraftRoot)

for (target in Args.targetDirs) {
val targetPath = mcPath.resolve(target)
val markerPath = targetPath.resolve(".MODSMAN_FIRST_RUN_COMPLETE")

if (!Args.force && Files.exists(markerPath)) {
log.info("Skipping $targetPath ...")
continue
}

log.info("Invoking Modsman in $targetPath ...")
Modsman(targetPath, 10).use { modsman ->
val projectIds = modsman.modlist.mods.map { it.projectId }
modsman.reinstallMods(projectIds).collect { result ->
result
.onSuccess { log.info("Downloaded '${it.projectName}' as '${it.fileName}'") }
.onFailure { log.severe("${it::class.java.simpleName}: ${it.message}") }
}
}

log.info("Creating marker $markerPath ...")
withContext(Dispatchers.IO) {
try {
Files.createFile(markerPath)
} catch (ignored: java.nio.file.FileAlreadyExistsException) {
}
}
}
}

log.info("Done")
exitProcess(0)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ rootProject.name = "modsman"

include("modsman-core")
include("modsman-cli")
include("modsman-packutil")

0 comments on commit 45fc6e7

Please sign in to comment.