Skip to content

Commit

Permalink
Hello rat
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikb committed Jul 16, 2023
1 parent 7008b94 commit e726f4c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022, macOS-11, macOS-12 ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version" ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat" ]

runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -297,7 +297,7 @@ jobs:
strategy:
matrix:
os: [ windows-2019, windows-2022 ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version" ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat" ]

runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -341,7 +341,7 @@ jobs:
strategy:
matrix:
container: [ ubuntu, debian, alpine, archlinux, 'ubuntu:14.04', 'ubuntu:18.04' ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version" ]
cmd: [ "node@14 -v", "node@14 -e 'console.log(1)'", "npm@14 -v", "npx@14 -v", "java -version", "java@11 -version", "java@+lts -version", "gradle@7 -version", "gradle -version", "maven -v", "openapi version", "rat" ]

runs-on: ubuntu-latest
container: ${{ matrix.container }}
Expand Down
23 changes: 13 additions & 10 deletions src/stage4/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use semver::{Version, VersionReq};
use crate::{download_unpack_and_all_that_stuff, Gradle, Java, NoClap, Node};
use crate::maven::Maven;
use crate::openapigenerator::OpenAPIGenerator;
use crate::rat::Rat;
use crate::target::{Arch, Os, Target, Variant};

#[derive(PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -84,6 +85,7 @@ impl dyn Executor {
"java" => Some(Box::new(Java { executor_cmd })),
"maven" | "mvn" => Some(Box::new(Maven { executor_cmd })),
"openapi" => Some(Box::new(OpenAPIGenerator { executor_cmd })),
"rat" | "ra" => Some(Box::new(Rat { executor_cmd })),
_ => None
}
}
Expand Down Expand Up @@ -211,16 +213,17 @@ pub async fn prep(executor: &dyn Executor, input: &AppInput, pb: &ProgressBar) -
return false;
}

if let Some(os) = u.os {
if os != Os::Any && !(match input.target.os {
Os::Windows => u.download_url.ends_with(".zip"),
Os::Linux => u.download_url.ends_with(".tar.gz"),
Os::Mac => u.download_url.ends_with(".tar.gz"),
Os::Any => u.download_url.ends_with(".tar.gz")
}) {
return false;
}
}
// SKIP?!
// if let Some(os) = u.os {
// if os != Os::Any && !(match input.target.os {
// Os::Windows => u.download_url.ends_with(".zip"),
// Os::Linux => u.download_url.ends_with(".tar.gz"),
// Os::Mac => u.download_url.ends_with(".tar.gz"),
// Os::Any => u.download_url.ends_with(".tar.gz")
// }) {
// return false;
// }
// }

let cmd = executor.get_executor_cmd();
for tag in &cmd.include_tags {
Expand Down
2 changes: 2 additions & 0 deletions src/stage4/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod executor;
mod no_clap;
mod custom_command;
mod bloody_maven;
mod rat;

fn print_help(ver: &str) {
println!(r"gg.cmd
Expand Down Expand Up @@ -59,6 +60,7 @@ Supported systems:
java
maven
openapi
rat (ra)
");
}

Expand Down
89 changes: 89 additions & 0 deletions src/stage4/src/rat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use std::collections::HashSet;
use std::fs;
use std::fs::{Permissions, read_dir, rename};
use std::future::Future;
use std::os::unix::fs::PermissionsExt;
use std::pin::Pin;

use log::info;
use package_json::PackageJsonManager;
use regex::Regex;
use semver::{Version, VersionReq};
use serde::Deserialize;
use serde::Serialize;

use crate::executor::{AppInput, Download, Executor, ExecutorCmd};
use crate::target::{Arch, Os, Target, Variant};

pub struct Rat {
pub executor_cmd: ExecutorCmd,
}

impl Executor for Rat {
fn get_executor_cmd(&self) -> &ExecutorCmd {
&self.executor_cmd
}

fn get_download_urls<'a>(&'a self, input: &'a AppInput) -> Pin<Box<dyn Future<Output=Vec<Download>> + 'a>> {
Box::pin(async move {
let versions: Vec<String> = reqwest::get("https://ratbinsa.z1.web.core.windows.net/list.json").await.unwrap().json().await.unwrap();
versions.into_iter().map(|name| {
let url = format!("https://ratbinsa.z1.web.core.windows.net/{}", name);
let name = name.clone();
let parts = name.split("-");
let version = parts.clone().nth(1).unwrap_or("NA");
let os = match parts.clone().nth(2) {
Some("windows") => Some(Os::Windows),
Some("linux") => Some(Os::Linux),
Some("macos") => Some(Os::Mac),
_ => None
};
Download {
version: Version::parse(version).ok(),
tags: Default::default(),
download_url: url,
arch: Some(Arch::X86_64),
os,
variant: Some(Variant::Any),
}
}).collect()
})
}


fn get_bin(&self, input: &AppInput) -> Vec<&str> {
vec!(match &input.target.os {
Os::Windows => "rat.exe",
_ => "rat.bin"
})
}

fn get_name(&self) -> &str {
"rat"
}

fn post_prep(&self, cache_path: &str) {
let entries = read_dir(&cache_path);
if let Ok(entries) = entries {
entries.for_each(|entry| {
if let Ok(entry) = entry {
if let Some(path_str) = entry.path().to_str() {
let to_path = if path_str.ends_with(".bin") {
Some(cache_path.to_string() + "/rat.bin")
} else if path_str.ends_with(".exe") {
Some(cache_path.to_string() + "/rat.exe")
} else {
None
};
if let Some(to_path) = to_path {
rename(entry.path(), &to_path).unwrap();
let mut perms = fs::metadata(&to_path).unwrap().permissions();
perms.set_mode(0o755);
fs::set_permissions(to_path, perms).unwrap();
}
}
}
});
}
}
}

0 comments on commit e726f4c

Please sign in to comment.