Skip to content

Commit 50fedf6

Browse files
committed
updated maven and improved the caching logic
1 parent a6bbfda commit 50fedf6

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

plugins/java/src/maven_plugin.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use tmc_langs_framework::{
1717
};
1818
use tmc_langs_util::file_util;
1919

20-
const MVN_ARCHIVE: &[u8] = include_bytes!("../deps/apache-maven-3.6.3-bin.tar.gz");
20+
const MVN_ARCHIVE: &[u8] = include_bytes!("../deps/apache-maven-3.8.1-bin.tar.gz");
21+
const MVN_PATH_IN_ARCHIVE: &str = "apache-maven-3.8.1"; // the name of the base directory in the maven archive
22+
const MVN_VERSION: &str = "3.8.1";
2123

2224
pub struct MavenPlugin {
2325
jvm: Jvm,
@@ -52,17 +54,40 @@ impl MavenPlugin {
5254
#[cfg(not(windows))]
5355
let mvn_exec = "mvn";
5456

55-
let mvn_exec_path = tmc_path
56-
.join("apache-maven-3.6.3")
57-
.join("bin")
58-
.join(mvn_exec);
59-
if !mvn_exec_path.exists() {
57+
let mvn_path = tmc_path.join("apache-maven");
58+
let mvn_version_path = mvn_path.join("VERSION");
59+
60+
let needs_update = if mvn_version_path.exists() {
61+
let version_contents = file_util::read_file_to_string(&mvn_version_path)?;
62+
MVN_VERSION != version_contents
63+
} else {
64+
true
65+
};
66+
67+
if needs_update {
68+
if mvn_path.exists() {
69+
file_util::remove_dir_all(&mvn_path)?;
70+
}
71+
// TODO: remove this bit eventually, this is just to clean up the old maven cachce that had the version in the name
72+
let old_path = tmc_path.join("apache-maven-3.6.3");
73+
if old_path.exists() {
74+
file_util::remove_dir_all(old_path)?;
75+
}
76+
6077
log::debug!("extracting bundled tar");
6178
let tar = GzDecoder::new(Cursor::new(MVN_ARCHIVE));
6279
let mut tar = Archive::new(tar);
6380
tar.unpack(&tmc_path)
64-
.map_err(|e| JavaError::JarWrite(tmc_path, e))?;
81+
.map_err(|e| JavaError::JarWrite(tmc_path.clone(), e))?;
82+
83+
log::debug!("renaming extracted archive to apache-maven");
84+
file_util::rename(tmc_path.join(MVN_PATH_IN_ARCHIVE), &mvn_path)?;
85+
86+
log::debug!("writing bundle version data");
87+
file_util::write_to_file(MVN_VERSION.as_bytes(), &mvn_version_path)?;
6588
}
89+
90+
let mvn_exec_path = mvn_path.join("bin").join(mvn_exec);
6691
Ok(mvn_exec_path.as_os_str().to_os_string())
6792
}
6893
}
@@ -324,7 +349,7 @@ mod test {
324349
std::env::set_var("PATH", "");
325350
let cmd = MavenPlugin::get_mvn_command().unwrap();
326351
let expected = format!(
327-
"tmc{0}apache-maven-3.6.3{0}bin{0}mvn",
352+
"tmc{0}apache-maven-3.8.1{0}bin{0}mvn",
328353
std::path::MAIN_SEPARATOR
329354
);
330355
assert!(cmd.to_string_lossy().ends_with(&expected))

0 commit comments

Comments
 (0)