Skip to content

Commit 7f483a5

Browse files
committed
handle updated jar files properly
1 parent bb751ed commit 7f483a5

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

plugins/java/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ fn get_junit_runner_path() -> Result<PathBuf, JavaError> {
3737
let jar_dir = tmc_dir()?;
3838

3939
let junit_path = jar_dir.join("tmc-junit-runner.jar");
40-
if !junit_path.exists() {
40+
if let Ok(bytes) = file_util::read_file(&junit_path) {
41+
if TMC_CHECKSTYLE_RUNNER_BYTES != bytes.as_slice() {
42+
log::debug!("updating tmc junit runner jar");
43+
file_util::write_to_file(&mut TMC_JUNIT_RUNNER_BYTES, &junit_path)?;
44+
}
45+
} else {
46+
log::debug!("failed to read tmc junit runner jar, writing");
4147
file_util::write_to_file(&mut TMC_JUNIT_RUNNER_BYTES, &junit_path)?;
4248
}
4349
Ok(junit_path)
@@ -48,7 +54,13 @@ fn get_checkstyle_runner_path() -> Result<PathBuf, JavaError> {
4854
let jar_dir = tmc_dir()?;
4955

5056
let checkstyle_path = jar_dir.join("tmc-checkstyle-runner.jar");
51-
if !checkstyle_path.exists() {
57+
if let Ok(bytes) = file_util::read_file(&checkstyle_path) {
58+
if TMC_CHECKSTYLE_RUNNER_BYTES != bytes.as_slice() {
59+
log::debug!("updating checkstyle runner jar");
60+
file_util::write_to_file(&mut TMC_CHECKSTYLE_RUNNER_BYTES, &checkstyle_path)?;
61+
}
62+
} else {
63+
log::debug!("failed to read checkstyle runner jar, writing");
5264
file_util::write_to_file(&mut TMC_CHECKSTYLE_RUNNER_BYTES, &checkstyle_path)?;
5365
}
5466
Ok(checkstyle_path)
@@ -60,7 +72,14 @@ fn initialize_jassets() -> Result<PathBuf, JavaError> {
6072
let jassets_dir = jar_dir.join("jassets");
6173

6274
let j4rs_path = jassets_dir.join("j4rs.jar");
63-
if !j4rs_path.exists() {
75+
76+
if let Ok(bytes) = file_util::read_file(&j4rs_path) {
77+
if J4RS_BYTES != bytes.as_slice() {
78+
log::debug!("updating j4rs jar");
79+
file_util::write_to_file(&mut J4RS_BYTES, &j4rs_path)?;
80+
}
81+
} else {
82+
log::debug!("failed to read j4rs jar, writing");
6483
file_util::write_to_file(&mut J4RS_BYTES, &j4rs_path)?;
6584
}
6685
Ok(j4rs_path)

plugins/java/src/plugin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ pub(crate) trait JavaPlugin: LanguagePlugin {
226226
locale: &Language,
227227
path: &Path,
228228
) -> Result<ValidationResult, JavaError> {
229-
let file = self.jvm().create_instance(
230-
"java.io.File",
231-
&[InvocationArg::try_from(&*path.to_string_lossy())?],
232-
)?;
229+
let path = path.to_string_lossy();
230+
let file = self
231+
.jvm()
232+
.create_instance("java.io.File", &[InvocationArg::try_from(path.as_ref())?])?;
233233
let locale_code = locale.to_639_1().unwrap_or_else(|| locale.to_639_3()); // Java requires 639-1 if one exists
234234
let locale = self
235235
.jvm()

0 commit comments

Comments
 (0)