Skip to content

Commit

Permalink
maven, forge and neoforge
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Aug 6, 2023
1 parent 7f594a2 commit 78690ec
Show file tree
Hide file tree
Showing 22 changed files with 774 additions and 173 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
name = "mcman"
version = "0.3.0"
edition = "2021"
authors = ["ParadigmMC"]
repository = "https://github.com/ParadigmMC/mcman"
homepage = "https://paradigmmc.github.io/mcman/"
authors = ["ParadigmMC"]
license = "gpl"
description = "Powerful Minecraft Server Manager CLI"
documentation = "https://paradigmmc.github.io/mcman/"
keywords = [
"minecraft", "server"
]
categories = ["command-line-utilities", "config", ""]

[profile.release]
debug = false
Expand Down Expand Up @@ -37,3 +45,4 @@ sha2 = "0.10"
notify = { version = "6.0.1", default-features = false }
glob-match = "0.2"
async-trait = "0.1.72"
roxmltree = "0.18"
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ Submit a PR or open an issue if you have a mcman-server repository that we can a

## Changelog

### `0.3.0` (unreleased)
whats a semver? /s

### `0.3.1` (unreleased)

- Added [neoforge](https://neoforged.net/) server type
- Added [Forge](https://forums.minecraftforge.net/) server type
- Added Downloadable type **Maven**
- Improved building process
- Fixed a bug on `mcman run` which messed up the output when server crashes

### `0.3.0`

- Added [CurseRinth](https://curserinth.kuylar.dev/) support
- Added **packwiz importing**
Expand Down
10 changes: 6 additions & 4 deletions src/core/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl BuildContext {
let (tx_stop, rx_stop) = oneshot::channel();

// stdout
tokio::spawn(async move {
let stdout_process = tokio::spawn(async move {
let mut tx = Some(tx_stop);
for buf in BufReader::new(stdout).lines() {
let buf = buf.unwrap();
Expand All @@ -75,13 +75,14 @@ impl BuildContext {

if test_mode
&& !test_passed_clone.load(std::sync::atomic::Ordering::Relaxed)
&& line.contains("INFO]: Done")
&& line.contains("]: Done")
&& line.ends_with("For help, type \"help\"")
&& tx.is_some()
{
println!(
"{} Server started successfully, stopping in 5s...",
style("<TE>").yellow().bold()
"{} {}",
style("<TE>").yellow().bold(),
style("Server started successfully, stopping in 5s...").yellow()
);
test_passed_clone.store(true, std::sync::atomic::Ordering::Relaxed);
tx.take()
Expand Down Expand Up @@ -109,6 +110,7 @@ impl BuildContext {
}

let exit_status = child.wait()?;
stdout_process.await.context("Awaiting stdout proxy printing thread")?;

if !exit_status.success() {
println!();
Expand Down
20 changes: 15 additions & 5 deletions src/core/serverjar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl BuildContext {
let serverjar_name = match self
.server
.jar
.get_install_method(&self.http_client)
.get_install_method(&self.http_client, &self.server.mc_version)
.await?
{
InstallMethod::Installer {
Expand All @@ -35,7 +35,7 @@ impl BuildContext {
.downloadable(&self.server.jar, None, |state, filename| match state {
ReportBackState::Skipped => {
println!(
" {name} present ({})",
" {name} is present ({})",
style(filename.clone()).dim()
);
}
Expand All @@ -49,15 +49,25 @@ impl BuildContext {
})
.await?;

let jar_name = jar_name.replace("${mcver}", &self.server.mc_version);

if !self.force && self.output_dir.join(&jar_name).exists() {
println!(
" Skipping server jar ({})",
style(jar_name.clone()).dim()
style(if rename_from.is_some() {
jar_name.clone()
} else {
"<in libraries>".to_owned()
}).dim()
);
} else {
println!(
" Installing server jar... ({})",
style(jar_name.clone()).dim()
style(if rename_from.is_some() {
jar_name.clone()
} else {
"<in libraries>".to_owned()
}).dim()
);

let mut cmd_args = vec!["-jar", &installer_jar];
Expand Down Expand Up @@ -105,7 +115,7 @@ impl BuildContext {
}
}?;

self.startup_method = self.server.jar.get_startup_method(&serverjar_name);
self.startup_method = self.server.jar.get_startup_method(&self.http_client, &serverjar_name, &self.server.mc_version).await?;

Ok(())
}
Expand Down
20 changes: 19 additions & 1 deletion src/model/downloadable/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ impl Downloadable {
let link = url.clone() + &str_process_job(job);
format!("[{job}]({link})")
}
Self::Maven { url, group, .. } => {
format!("[{g}]({url}/{g})", g = group.replace('.', "/"))
}
Self::Spigot { id } => {
format!("[{id}](https://www.spigotmc.org/resources/{id})")
}
Expand Down Expand Up @@ -104,6 +107,11 @@ impl Downloadable {
map.insert("Version".to_owned(), format!("{build} / `{artifact}`"));
}

Self::Maven { version, .. } => {
map.insert("Name".to_owned(), self.get_md_link());
map.insert("Version".to_owned(), version.to_owned());

Check warning on line 112 in src/model/downloadable/markdown.rs

View workflow job for this annotation

GitHub Actions / clippy

implicitly cloning a `String` by calling `to_owned` on its dereferenced type

warning: implicitly cloning a `String` by calling `to_owned` on its dereferenced type --> src/model/downloadable/markdown.rs:112:50 | 112 | map.insert("Version".to_owned(), version.to_owned()); | ^^^^^^^^^^^^^^^^^^ help: consider using: `version.clone()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone note: the lint level is defined here --> src/main.rs:2:9 | 2 | #![warn(clippy::pedantic)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(clippy::implicit_clone)]` implied by `#[warn(clippy::pedantic)]`
}

Self::Url {
url,
filename,
Expand Down Expand Up @@ -132,11 +140,12 @@ impl Downloadable {
pub fn get_type_name(&self) -> String {
match self {
Self::Url { .. } => "URL",
Self::GithubRelease { .. } => "GithubRelease",
Self::GithubRelease { .. } => "GithubRel",
Self::Jenkins { .. } => "Jenkins",
Self::Modrinth { .. } => "Modrinth",
Self::CurseRinth { .. } => "CurseRinth",
Self::Spigot { .. } => "Spigot",
Self::Maven { .. } => "Maven",
}
.to_owned()
}
Expand Down Expand Up @@ -180,6 +189,12 @@ impl Downloadable {
map.insert("Version/Release".to_owned(), build.clone());
map.insert("Asset/File".to_owned(), artifact.clone());
}

Self::Maven { url, group, artifact, version, filename } => {
map.insert("Project/URL".to_owned(), format!("{group}.{artifact} - ({url})"));
map.insert("Version/Release".to_owned(), version.clone());
map.insert("Asset/File".to_owned(), filename.clone());
}
}

map
Expand All @@ -199,6 +214,9 @@ impl Downloadable {
"URL".to_string()
}
}
Self::Maven { group, artifact, .. } => {
format!("Maven/{group}.{artifact}")
}
}
}
}
Expand Down
84 changes: 59 additions & 25 deletions src/model/downloadable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use anyhow::Result;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

use crate::sources::maven::{get_maven_url, self};
use crate::{model::Server, Source};

use crate::sources::{
curserinth::{download_curserinth, fetch_curserinth_filename, get_curserinth_url},
curserinth::{ fetch_curserinth_filename, get_curserinth_url},
github::{download_github_release, fetch_github_release_filename, get_github_release_url},
jenkins::{download_jenkins, get_jenkins_download_url, get_jenkins_filename},
modrinth::{download_modrinth, fetch_modrinth_filename, get_modrinth_url},
spigot::{download_spigot_resource, fetch_spigot_resource_latest_ver, get_spigot_url},
jenkins::{ get_jenkins_download_url, get_jenkins_filename},
modrinth::{ fetch_modrinth_filename, get_modrinth_url},
spigot::{fetch_spigot_resource_latest_ver, get_spigot_url},
};
mod import_url;
mod markdown;
Expand Down Expand Up @@ -56,6 +57,17 @@ pub enum Downloadable {
#[serde(default = "first")]
artifact: String,
},

Maven {
url: String,
group: String,
#[serde(default = "first")]
artifact: String,
#[serde(default = "latest")]
version: String,
#[serde(default = "artifact")]
filename: String,
},
}

pub fn latest() -> String {
Expand All @@ -66,13 +78,19 @@ pub fn first() -> String {
"first".to_owned()
}

pub fn artifact() -> String {
"artifact".to_owned()
}

impl Downloadable {
/// only for exporting uses, every downloadable is supported* hehe :3 -dennis
pub async fn get_url(
&self,
client: &reqwest::Client,
server: &Server,
filename_hint: Option<&str>,
) -> Result<String> {
let mcver = &server.mc_version;

match self {
Self::Url { url, .. } => Ok(url.clone()),

Expand All @@ -84,7 +102,7 @@ impl Downloadable {
}
Self::Spigot { id } => Ok(get_spigot_url(id)),
Self::GithubRelease { repo, tag, asset } => {
Ok(get_github_release_url(repo, tag, asset, client, filename_hint).await?)
Ok(get_github_release_url(repo, tag, asset, mcver, client, filename_hint).await?)
}

Self::Jenkins {
Expand All @@ -93,6 +111,10 @@ impl Downloadable {
build,
artifact,
} => Ok(get_jenkins_download_url(client, url, job, build, artifact).await?),

Self::Maven { url, group, artifact, version, filename } => {
Ok(get_maven_url(client, url, group, artifact, version, filename, mcver).await?)
}
}
}
}
Expand All @@ -101,34 +123,27 @@ impl Downloadable {
impl Source for Downloadable {
async fn download(
&self,
_server: &Server,
server: &Server,
client: &reqwest::Client,
filename_hint: Option<&str>,
) -> Result<reqwest::Response> {
match self {
Self::Url { url, .. } => Ok(client.get(url).send().await?.error_for_status()?),

Self::Modrinth { id, version } => {
Ok(download_modrinth(id, version, client, None).await?)
}
Self::CurseRinth { id, version } => {
Ok(download_curserinth(id, version, client, None).await?)
}
Self::Spigot { id } => Ok(download_spigot_resource(id, client).await?),
Self::GithubRelease { repo, tag, asset } => {
Ok(download_github_release(repo, tag, asset, client, filename_hint).await?)
Ok(download_github_release(repo, tag, asset, &server.mc_version, client, filename_hint).await?)
}

Self::Jenkins {
url,
job,
build,
artifact,
} => Ok(download_jenkins(client, url, job, build, artifact).await?),
dl => {
Ok(client.get(dl.get_url(client, server, filename_hint).await?)
.send()
.await?
.error_for_status()?)
}
}
}

async fn get_filename(&self, _server: &Server, client: &reqwest::Client) -> Result<String> {
async fn get_filename(&self, server: &Server, client: &reqwest::Client) -> Result<String> {
let mcver = &server.mc_version;

match self {
Self::Url { url, filename, .. } => {
if let Some(filename) = filename {
Expand Down Expand Up @@ -156,7 +171,7 @@ impl Source for Downloadable {

// problematic stuff part 2345
Self::GithubRelease { repo, tag, asset } => {
Ok(fetch_github_release_filename(repo, tag, asset, client).await?)
Ok(fetch_github_release_filename(repo, tag, asset, mcver, client).await?)
}

Self::Jenkins {
Expand All @@ -167,6 +182,10 @@ impl Source for Downloadable {
} => Ok(get_jenkins_filename(client, url, job, build, artifact)
.await?
.1),

Self::Maven { url, group, artifact, version, filename } => {
Ok(maven::get_maven_filename(client, url, group, artifact, version, filename, mcver).await?)
}
}
}
}
Expand Down Expand Up @@ -209,6 +228,21 @@ impl std::fmt::Display for Downloadable {
.field("Build ID", build)
.field("Artifact", artifact)
.finish(),

Self::Maven {
url,
group,
artifact,
version,
filename,
} => f
.debug_struct("Maven")
.field("Instance URL", url)
.field("Group", group)
.field("Artifact", artifact)
.field("Version", version)
.field("Filename", filename)
.finish(),
}
}
}
Loading

0 comments on commit 78690ec

Please sign in to comment.