diff --git a/plugins/csharp/src/cs_test_result.rs b/plugins/csharp/src/cs_test_result.rs index 917d7533e5b..8c9cc31af83 100644 --- a/plugins/csharp/src/cs_test_result.rs +++ b/plugins/csharp/src/cs_test_result.rs @@ -7,6 +7,7 @@ use tmc_langs_framework::TestResult; /// Test result from the C# test runner. #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] +#[allow(clippy::upper_case_acronyms)] pub struct CSTestResult { pub name: String, pub passed: bool, diff --git a/plugins/csharp/src/error.rs b/plugins/csharp/src/error.rs index d37af985f6f..ad44716a196 100644 --- a/plugins/csharp/src/error.rs +++ b/plugins/csharp/src/error.rs @@ -32,8 +32,8 @@ impl From for TmcError { } // conversion from plugin error to a tmc result -impl Into> for CSharpError { - fn into(self) -> Result { - Err(TmcError::Plugin(Box::new(self))) +impl From for Result { + fn from(from: CSharpError) -> Self { + Err(TmcError::Plugin(Box::new(from))) } } diff --git a/plugins/csharp/src/plugin.rs b/plugins/csharp/src/plugin.rs index 818ebd9aae9..ea3e1de90dc 100644 --- a/plugins/csharp/src/plugin.rs +++ b/plugins/csharp/src/plugin.rs @@ -18,6 +18,7 @@ use walkdir::WalkDir; use zip::ZipArchive; const TMC_CSHARP_RUNNER: &[u8] = include_bytes!("../deps/tmc-csharp-runner-1.1.1.zip"); +const TMC_CSHARP_RUNNER_VERSION: &str = "1.1.1"; #[derive(Default)] pub struct CSharpPlugin {} @@ -27,40 +28,6 @@ impl CSharpPlugin { Self {} } - /// Verifies that the runner directory matches the contents of the zip. - /// Note: does not check for extra files not in the zip. - fn runner_needs_to_be_extracted(target: &Path) -> Result { - log::debug!("verifying C# runner integrity at {}", target.display()); - - // no need to check the zip contents if the directory doesn't even exist - if !target.exists() { - return Ok(true); - } - - let mut zip = ZipArchive::new(Cursor::new(TMC_CSHARP_RUNNER))?; - for i in 0..zip.len() { - let file = zip.by_index(i)?; - if file.is_file() { - let target_file_path = target.join(Path::new(file.name())); - if !target_file_path.exists() { - return Ok(true); // new file in zip, need to extract - } - - let target_bytes = file_util::read_file(target_file_path)?; - let zip_file_path = PathBuf::from(file.name()); - let zip_bytes: Vec = file - .bytes() - .collect::, _>>() - .map_err(|e| FileError::FileRead(zip_file_path, e))?; - - if target_bytes != zip_bytes { - return Ok(true); // bytes changed, need to extract - } - } - } - Ok(false) - } - /// Extracts the bundled tmc-csharp-runner to the given path. fn extract_runner_to_dir(target: &Path) -> Result<(), CSharpError> { log::debug!("extracting C# runner to {}", target.display()); @@ -94,12 +61,23 @@ impl CSharpPlugin { match dirs::cache_dir() { Some(cache_dir) => { let runner_dir = cache_dir.join("tmc").join("tmc-csharp-runner"); - if Self::runner_needs_to_be_extracted(&runner_dir)? { + let version_path = runner_dir.join("VERSION"); + + let needs_update = if version_path.exists() { + let version = file_util::read_file_to_string(&version_path)?; + version != TMC_CSHARP_RUNNER_VERSION + } else { + true + }; + + if needs_update { + log::debug!("updating the cached C# runner"); if runner_dir.exists() { // clear the directory if it exists file_util::remove_dir_all(&runner_dir)?; } Self::extract_runner_to_dir(&runner_dir)?; + file_util::write_to_file(TMC_CSHARP_RUNNER_VERSION.as_bytes(), version_path)?; } Ok(runner_dir) } @@ -444,41 +422,6 @@ mod test { temp } - #[test] - fn runner_needs_to_be_extracted() { - init(); - - // replace a file's content with garbage - let temp = tempfile::TempDir::new().unwrap(); - CSharpPlugin::extract_runner_to_dir(temp.path()).unwrap(); - std::fs::write( - temp.path().join("TestMyCode.CSharp.Bootstrap.exe"), - b"garbage", - ) - .unwrap(); - assert!(CSharpPlugin::runner_needs_to_be_extracted(&temp.path()).unwrap()); - - // remove a file - let temp = tempfile::TempDir::new().unwrap(); - CSharpPlugin::extract_runner_to_dir(temp.path()).unwrap(); - std::fs::remove_file(temp.path().join("TestMyCode.CSharp.Bootstrap.exe")).unwrap(); - assert!(CSharpPlugin::runner_needs_to_be_extracted(&temp.path()).unwrap()); - } - - #[test] - fn runner_does_not_need_to_be_extracted() { - init(); - - // no changes - let temp = tempfile::TempDir::new().unwrap(); - CSharpPlugin::extract_runner_to_dir(temp.path()).unwrap(); - assert!(!CSharpPlugin::runner_needs_to_be_extracted(&temp.path()).unwrap()); - - // new file added - file_to(&temp, "new_file", "stuff"); - assert!(!CSharpPlugin::runner_needs_to_be_extracted(&temp.path()).unwrap()); - } - #[test] fn extracts_runner_to_dir() { init(); diff --git a/plugins/java/deps/apache-maven-3.6.3-bin.tar.gz b/plugins/java/deps/apache-maven-3.8.1-bin.tar.gz similarity index 54% rename from plugins/java/deps/apache-maven-3.6.3-bin.tar.gz rename to plugins/java/deps/apache-maven-3.8.1-bin.tar.gz index 66fdd6d4c4e..3425a4298a6 100644 Binary files a/plugins/java/deps/apache-maven-3.6.3-bin.tar.gz and b/plugins/java/deps/apache-maven-3.8.1-bin.tar.gz differ diff --git a/plugins/java/src/error.rs b/plugins/java/src/error.rs index 45f6da03462..7922db49db5 100644 --- a/plugins/java/src/error.rs +++ b/plugins/java/src/error.rs @@ -47,8 +47,8 @@ impl From for TmcError { } // conversion from plugin error to a tmc result -impl Into> for JavaError { - fn into(self) -> Result { - Err(TmcError::Plugin(Box::new(self))) +impl From for Result { + fn from(from: JavaError) -> Self { + Err(TmcError::Plugin(Box::new(from))) } } diff --git a/plugins/java/src/java_plugin.rs b/plugins/java/src/java_plugin.rs index 85119911fc8..a06a432e8d9 100644 --- a/plugins/java/src/java_plugin.rs +++ b/plugins/java/src/java_plugin.rs @@ -47,7 +47,7 @@ pub(crate) trait JavaPlugin: LanguagePlugin { self.create_run_result_file(project_root_path, timeout, compile_result)?; let result = self.parse_test_result(&test_result); file_util::remove_file(&test_result.test_results)?; - Ok(result?) + result } /// Parses test results. diff --git a/plugins/java/src/maven_plugin.rs b/plugins/java/src/maven_plugin.rs index 671976c8dfc..1cdac536f40 100644 --- a/plugins/java/src/maven_plugin.rs +++ b/plugins/java/src/maven_plugin.rs @@ -17,7 +17,9 @@ use tmc_langs_framework::{ }; use tmc_langs_util::file_util; -const MVN_ARCHIVE: &[u8] = include_bytes!("../deps/apache-maven-3.6.3-bin.tar.gz"); +const MVN_ARCHIVE: &[u8] = include_bytes!("../deps/apache-maven-3.8.1-bin.tar.gz"); +const MVN_PATH_IN_ARCHIVE: &str = "apache-maven-3.8.1"; // the name of the base directory in the maven archive +const MVN_VERSION: &str = "3.8.1"; pub struct MavenPlugin { jvm: Jvm, @@ -52,17 +54,40 @@ impl MavenPlugin { #[cfg(not(windows))] let mvn_exec = "mvn"; - let mvn_exec_path = tmc_path - .join("apache-maven-3.6.3") - .join("bin") - .join(mvn_exec); - if !mvn_exec_path.exists() { + let mvn_path = tmc_path.join("apache-maven"); + let mvn_version_path = mvn_path.join("VERSION"); + + let needs_update = if mvn_version_path.exists() { + let version_contents = file_util::read_file_to_string(&mvn_version_path)?; + MVN_VERSION != version_contents + } else { + true + }; + + if needs_update { + if mvn_path.exists() { + file_util::remove_dir_all(&mvn_path)?; + } + // TODO: remove this bit eventually, this is just to clean up the old maven cachce that had the version in the name + let old_path = tmc_path.join("apache-maven-3.6.3"); + if old_path.exists() { + file_util::remove_dir_all(old_path)?; + } + log::debug!("extracting bundled tar"); let tar = GzDecoder::new(Cursor::new(MVN_ARCHIVE)); let mut tar = Archive::new(tar); tar.unpack(&tmc_path) - .map_err(|e| JavaError::JarWrite(tmc_path, e))?; + .map_err(|e| JavaError::JarWrite(tmc_path.clone(), e))?; + + log::debug!("renaming extracted archive to apache-maven"); + file_util::rename(tmc_path.join(MVN_PATH_IN_ARCHIVE), &mvn_path)?; + + log::debug!("writing bundle version data"); + file_util::write_to_file(MVN_VERSION.as_bytes(), &mvn_version_path)?; } + + let mvn_exec_path = mvn_path.join("bin").join(mvn_exec); Ok(mvn_exec_path.as_os_str().to_os_string()) } } @@ -324,7 +349,7 @@ mod test { std::env::set_var("PATH", ""); let cmd = MavenPlugin::get_mvn_command().unwrap(); let expected = format!( - "tmc{0}apache-maven-3.6.3{0}bin{0}mvn", + "tmc{0}apache-maven-3.8.1{0}bin{0}mvn", std::path::MAIN_SEPARATOR ); assert!(cmd.to_string_lossy().ends_with(&expected)) diff --git a/plugins/make/src/error.rs b/plugins/make/src/error.rs index fca902b6b93..1f97771ef5e 100644 --- a/plugins/make/src/error.rs +++ b/plugins/make/src/error.rs @@ -38,8 +38,8 @@ impl From for TmcError { } // conversion from plugin error to a tmc result -impl Into> for MakeError { - fn into(self) -> Result { - Err(TmcError::Plugin(Box::new(self))) +impl From for Result { + fn from(from: MakeError) -> Self { + Err(TmcError::Plugin(Box::new(from))) } } diff --git a/plugins/python3/src/error.rs b/plugins/python3/src/error.rs index eb12a4a6ced..b9e8a824e05 100644 --- a/plugins/python3/src/error.rs +++ b/plugins/python3/src/error.rs @@ -39,8 +39,8 @@ impl From for TmcError { } // conversion from plugin error to a tmc result -impl Into> for PythonError { - fn into(self) -> Result { - Err(TmcError::Plugin(Box::new(self))) +impl From for Result { + fn from(from: PythonError) -> Self { + Err(TmcError::Plugin(Box::new(from))) } } diff --git a/plugins/r/src/error.rs b/plugins/r/src/error.rs index 7c62f291291..6190a56c781 100644 --- a/plugins/r/src/error.rs +++ b/plugins/r/src/error.rs @@ -24,8 +24,8 @@ impl From for TmcError { } // conversion from plugin error to a tmc result -impl Into> for RError { - fn into(self) -> Result { - Err(TmcError::Plugin(Box::new(self))) +impl From for Result { + fn from(from: RError) -> Self { + Err(TmcError::Plugin(Box::new(from))) } } diff --git a/tmc-langs-util/src/file_util.rs b/tmc-langs-util/src/file_util.rs index bd2ff149673..9e91a75313f 100644 --- a/tmc-langs-util/src/file_util.rs +++ b/tmc-langs-util/src/file_util.rs @@ -150,7 +150,7 @@ pub fn write_to_writer, W: Write>( ) -> Result<(), FileError> { target .write_all(source.as_ref()) - .map_err(|e| FileError::WriteError(e))?; + .map_err(FileError::WriteError)?; Ok(()) } diff --git a/tmc-langs/Cargo.toml b/tmc-langs/Cargo.toml index e608c6d8d16..58e5441b34f 100644 --- a/tmc-langs/Cargo.toml +++ b/tmc-langs/Cargo.toml @@ -37,7 +37,7 @@ toml = "0.5" url = "2" walkdir = "2" zip = "0.5" -zstd = "0.6" +zstd = "0.7" [target.'cfg(unix)'.dependencies] nix = "0.20"