Skip to content

Commit b7aa868

Browse files
committed
Disable Java plugin on musl
1 parent 614d7c7 commit b7aa868

File tree

7 files changed

+150
-32
lines changed

7 files changed

+150
-32
lines changed

crates/plugins/java/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The `./deps` directory contains some Java dependencies, such as a bundled Maven
1515
- https://maven.mooc.fi/snapshots/fi/helsinki/cs/tmc/tmc-junit-runner/{VERSION}/maven-metadata.xml (Find the `snapshotVersion.value`)
1616
- https://maven.mooc.fi/snapshots/fi/helsinki/cs/tmc/tmc-junit-runner/{VERSION}/tmc-junit-runner-{SNAPSHOT_VERSION}.jar
1717

18+
Note that this plugin is not supported on musl due to dynamic loading not being supported on the platform.
19+
1820
## Maven
1921

2022
### Student file policy

crates/plugins/java/src/error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ stderr: {}
4242
},
4343
#[error("J4rs panicked: {0}")]
4444
J4rsPanic(String),
45-
#[error("This program does not support Java on this platform due to dynamic loading not being supported on musl. As a result, J4rs panicked: {0}")]
46-
UnsupportedPlatformMusl(String),
4745

4846
#[error(transparent)]
4947
WalkDir(#[from] walkdir::Error),

crates/plugins/java/src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
//! Java plugins for ant and maven
44
5+
#[cfg(target_env = "musl")]
6+
compile_error!("The Java plugin does not work on musl");
7+
58
mod ant_plugin;
69
mod ant_policy;
710
mod error;
@@ -165,15 +168,7 @@ fn instantiate_jvm() -> Result<JvmWrapper, JavaError> {
165168
"J4rs panicked without an error message".to_string()
166169
};
167170

168-
// it's expected that we end up here when running on musl as libjvm is dynamically linked
169-
// (and statically linking it seems challenging)
170-
// we could fail early and error as soon as we recognise a Java project on musl,
171-
// but this is a very niche issue and this is a foolproof place to detect it
172-
if cfg!(target_env = "musl") {
173-
return Err(JavaError::UnsupportedPlatformMusl(error_message));
174-
} else {
175-
return Err(JavaError::J4rsPanic(error_message));
176-
}
171+
return Err(JavaError::J4rsPanic(error_message));
177172
}
178173
};
179174

crates/tmc-langs-plugins/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ tmc-langs-framework.workspace = true
1111
tmc-langs-util.workspace = true
1212

1313
tmc-langs-csharp.workspace = true
14-
tmc-langs-java.workspace = true
1514
tmc-langs-make.workspace = true
1615
tmc-langs-notests.workspace = true
1716
tmc-langs-python3.workspace = true
@@ -25,6 +24,10 @@ walkdir = "2.3.2"
2524
zip = "2.2.0"
2625
zstd = "0.13.0"
2726

27+
# The Java plugin causes compilation to fail on musl
28+
[target.'cfg(not(target_env = "musl"))'.dependencies]
29+
tmc-langs-java.workspace = true
30+
2831
[dev-dependencies]
2932
simple_logger = "5.0.0"
3033
tempfile = "3.3.0"

crates/tmc-langs-plugins/src/error.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
//! Contains the PluginError type.
22
33
use std::path::PathBuf;
4+
// the Java plugin is disabled on musl
5+
#[cfg(not(target_env = "musl"))]
46
use tmc_langs_java::JavaError;
57

68
#[derive(thiserror::Error, Debug)]
79
pub enum PluginError {
10+
// on musl, warn the user about the Java plugin being nonfunctional
11+
#[cfg(not(target_env = "musl"))]
812
#[error("No matching plugin found for {0}")]
913
PluginNotFound(PathBuf),
10-
#[error("No matching plugin found in archive")]
14+
#[cfg(target_env = "musl")]
15+
#[error("No matching plugin found for {0}. Note that Java support is disabled on musl.")]
16+
PluginNotFound(PathBuf),
17+
#[error("No matching plugin found in archive.")]
1118
PluginNotFoundInArchive,
1219
#[error(transparent)]
1320
Tmc(#[from] tmc_langs_framework::TmcError),
1421
#[error(transparent)]
1522
Walkdir(#[from] walkdir::Error),
1623
}
1724

25+
// the Java plugin is disabled on musl
26+
#[cfg(not(target_env = "musl"))]
1827
impl From<JavaError> for PluginError {
1928
fn from(e: JavaError) -> Self {
2029
Self::Tmc(e.into())

crates/tmc-langs-plugins/src/lib.rs

Lines changed: 116 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub use tmc_langs_framework::{
1818
NothingIsStudentFilePolicy, RunResult, StudentFilePolicy, StyleValidationResult,
1919
StyleValidationStrategy,
2020
};
21+
// the Java plugin is disabled on musl
22+
#[cfg(not(target_env = "musl"))]
2123
pub use tmc_langs_java::{AntPlugin, MavenPlugin};
2224
pub use tmc_langs_make::MakePlugin;
2325
pub use tmc_langs_notests::NoTestsPlugin;
@@ -62,19 +64,17 @@ pub fn compress_project(
6264
}
6365

6466
/// Enum containing variants for each language plugin.
65-
#[impl_enum::with_methods(
66-
pub fn clean(&self, path: &Path) -> Result<(), TmcError>
67-
pub fn scan_exercise(&self, path: &Path, exercise_name: String) -> Result<ExerciseDesc, TmcError>
68-
pub fn run_tests(&self, path: &Path) -> Result<RunResult, TmcError>
69-
pub fn check_code_style(&self, path: &Path, locale: Language) -> Result<Option<StyleValidationResult>, TmcError>
70-
)]
7167
pub enum Plugin {
7268
CSharp(CSharpPlugin),
7369
Make(MakePlugin),
70+
// the Java plugin is disabled on musl
71+
#[cfg(not(target_env = "musl"))]
7472
Maven(MavenPlugin),
7573
NoTests(NoTestsPlugin),
7674
Python3(Python3Plugin),
7775
R(RPlugin),
76+
// the Java plugin is disabled on musl
77+
#[cfg(not(target_env = "musl"))]
7878
Ant(AntPlugin),
7979
}
8080

@@ -87,22 +87,102 @@ impl Plugin {
8787
PluginType::Make => Plugin::Make(MakePlugin::new()),
8888
PluginType::Python3 => Plugin::Python3(Python3Plugin::new()),
8989
PluginType::R => Plugin::R(RPlugin::new()),
90+
// the Java plugin is disabled on musl
91+
#[cfg(not(target_env = "musl"))]
9092
PluginType::Maven => Plugin::Maven(MavenPlugin::new()?),
93+
// the Java plugin is disabled on musl
94+
#[cfg(not(target_env = "musl"))]
9195
PluginType::Ant => Plugin::Ant(AntPlugin::new()?),
9296
};
9397
Ok(plugin)
9498
}
99+
100+
pub fn clean(&self, path: &Path) -> Result<(), TmcError> {
101+
match self {
102+
Plugin::CSharp(plugin) => plugin.clean(path),
103+
Plugin::Make(plugin) => plugin.clean(path),
104+
// the Java plugin is disabled on musl
105+
#[cfg(not(target_env = "musl"))]
106+
Plugin::Maven(plugin) => plugin.clean(path),
107+
Plugin::NoTests(plugin) => plugin.clean(path),
108+
Plugin::Python3(plugin) => plugin.clean(path),
109+
Plugin::R(plugin) => plugin.clean(path),
110+
// the Java plugin is disabled on musl
111+
#[cfg(not(target_env = "musl"))]
112+
Plugin::Ant(plugin) => plugin.clean(path),
113+
}
114+
}
115+
116+
pub fn scan_exercise(
117+
&self,
118+
path: &Path,
119+
exercise_name: String,
120+
) -> Result<ExerciseDesc, TmcError> {
121+
match self {
122+
Plugin::CSharp(plugin) => plugin.scan_exercise(path, exercise_name),
123+
Plugin::Make(plugin) => plugin.scan_exercise(path, exercise_name),
124+
// the Java plugin is disabled on musl
125+
#[cfg(not(target_env = "musl"))]
126+
Plugin::Maven(plugin) => plugin.scan_exercise(path, exercise_name),
127+
Plugin::NoTests(plugin) => plugin.scan_exercise(path, exercise_name),
128+
Plugin::Python3(plugin) => plugin.scan_exercise(path, exercise_name),
129+
Plugin::R(plugin) => plugin.scan_exercise(path, exercise_name),
130+
// the Java plugin is disabled on musl
131+
#[cfg(not(target_env = "musl"))]
132+
Plugin::Ant(plugin) => plugin.scan_exercise(path, exercise_name),
133+
}
134+
}
135+
136+
pub fn run_tests(&self, path: &Path) -> Result<RunResult, TmcError> {
137+
match self {
138+
Plugin::CSharp(plugin) => plugin.run_tests(path),
139+
Plugin::Make(plugin) => plugin.run_tests(path),
140+
// the Java plugin is disabled on musl
141+
#[cfg(not(target_env = "musl"))]
142+
Plugin::Maven(plugin) => plugin.run_tests(path),
143+
Plugin::NoTests(plugin) => plugin.run_tests(path),
144+
Plugin::Python3(plugin) => plugin.run_tests(path),
145+
Plugin::R(plugin) => plugin.run_tests(path),
146+
// the Java plugin is disabled on musl
147+
#[cfg(not(target_env = "musl"))]
148+
Plugin::Ant(plugin) => plugin.run_tests(path),
149+
}
150+
}
151+
152+
pub fn check_code_style(
153+
&self,
154+
path: &Path,
155+
locale: Language,
156+
) -> Result<Option<StyleValidationResult>, TmcError> {
157+
match self {
158+
Plugin::CSharp(plugin) => plugin.check_code_style(path, locale),
159+
Plugin::Make(plugin) => plugin.check_code_style(path, locale),
160+
// the Java plugin is disabled on musl
161+
#[cfg(not(target_env = "musl"))]
162+
Plugin::Maven(plugin) => plugin.check_code_style(path, locale),
163+
Plugin::NoTests(plugin) => plugin.check_code_style(path, locale),
164+
Plugin::Python3(plugin) => plugin.check_code_style(path, locale),
165+
Plugin::R(plugin) => plugin.check_code_style(path, locale),
166+
// the Java plugin is disabled on musl
167+
#[cfg(not(target_env = "musl"))]
168+
Plugin::Ant(plugin) => plugin.check_code_style(path, locale),
169+
}
170+
}
95171
}
96172

97173
/// Allows calling LanguagePlugin functions without constructing the plugin.
98174
#[derive(Clone, Copy)]
99175
pub enum PluginType {
100176
CSharp,
101177
Make,
178+
// the Java plugin is disabled on musl
179+
#[cfg(not(target_env = "musl"))]
102180
Maven,
103181
NoTests,
104182
Python3,
105183
R,
184+
// the Java plugin is disabled on musl
185+
#[cfg(not(target_env = "musl"))]
106186
Ant,
107187
}
108188

@@ -111,10 +191,14 @@ macro_rules! delegate_plugin_type {
111191
match $self {
112192
Self::CSharp => CSharpPlugin::$($args)*,
113193
Self::Make => MakePlugin::$($args)*,
194+
// the Java plugin is disabled on musl
195+
#[cfg(not(target_env = "musl"))]
114196
Self::Maven => MavenPlugin::$($args)*,
115197
Self::NoTests => NoTestsPlugin::$($args)*,
116198
Self::Python3 => Python3Plugin::$($args)*,
117199
Self::R => RPlugin::$($args)*,
200+
// the Java plugin is disabled on musl
201+
#[cfg(not(target_env = "musl"))]
118202
Self::Ant => AntPlugin::$($args)*,
119203
}
120204
};
@@ -132,12 +216,18 @@ impl PluginType {
132216
(Python3Plugin::PLUGIN_NAME, PluginType::Python3)
133217
} else if RPlugin::is_exercise_type_correct(path) {
134218
(RPlugin::PLUGIN_NAME, PluginType::R)
135-
} else if MavenPlugin::is_exercise_type_correct(path) {
136-
(MavenPlugin::PLUGIN_NAME, PluginType::Maven)
137-
} else if AntPlugin::is_exercise_type_correct(path) {
138-
// TODO: currently, ant needs to be last because any project with src and test are recognized as ant
139-
(AntPlugin::PLUGIN_NAME, PluginType::Ant)
140219
} else {
220+
// the Java plugin is disabled on musl
221+
#[cfg(not(target_env = "musl"))]
222+
if MavenPlugin::is_exercise_type_correct(path) {
223+
(MavenPlugin::PLUGIN_NAME, PluginType::Maven)
224+
} else if AntPlugin::is_exercise_type_correct(path) {
225+
// TODO: currently, ant needs to be last because any project with src and test are recognized as ant
226+
(AntPlugin::PLUGIN_NAME, PluginType::Ant)
227+
} else {
228+
return Err(PluginError::PluginNotFound(path.to_path_buf()));
229+
}
230+
#[cfg(target_env = "musl")]
141231
return Err(PluginError::PluginNotFound(path.to_path_buf()));
142232
};
143233
log::info!("Detected project at {} as {}", path.display(), plugin_name);
@@ -155,12 +245,18 @@ impl PluginType {
155245
(Python3Plugin::PLUGIN_NAME, PluginType::Python3)
156246
} else if RPlugin::is_archive_type_correct(archive) {
157247
(RPlugin::PLUGIN_NAME, PluginType::R)
158-
} else if MavenPlugin::is_archive_type_correct(archive) {
159-
(MavenPlugin::PLUGIN_NAME, PluginType::Maven)
160-
} else if AntPlugin::is_archive_type_correct(archive) {
161-
// TODO: currently, ant needs to be last because any project with src and test are recognized as ant
162-
(AntPlugin::PLUGIN_NAME, PluginType::Ant)
163248
} else {
249+
// the Java plugin is disabled on musl
250+
#[cfg(not(target_env = "musl"))]
251+
if MavenPlugin::is_archive_type_correct(archive) {
252+
(MavenPlugin::PLUGIN_NAME, PluginType::Maven)
253+
} else if AntPlugin::is_archive_type_correct(archive) {
254+
// TODO: currently, ant needs to be last because any project with src and test are recognized as ant
255+
(AntPlugin::PLUGIN_NAME, PluginType::Ant)
256+
} else {
257+
return Err(PluginError::PluginNotFoundInArchive);
258+
}
259+
#[cfg(target_env = "musl")]
164260
return Err(PluginError::PluginNotFoundInArchive);
165261
};
166262
log::info!("Detected project in archive as {}", plugin_name);
@@ -222,9 +318,13 @@ pub fn get_student_file_policy(path: &Path) -> Result<Box<dyn StudentFilePolicy>
222318
path,
223319
)?),
224320
PluginType::R => Box::new(<RPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?),
321+
// the Java plugin is disabled on musl
322+
#[cfg(not(target_env = "musl"))]
225323
PluginType::Maven => Box::new(<MavenPlugin as LanguagePlugin>::StudentFilePolicy::new(
226324
path,
227325
)?),
326+
// the Java plugin is disabled on musl
327+
#[cfg(not(target_env = "musl"))]
228328
PluginType::Ant => Box::new(<AntPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?),
229329
};
230330
Ok(policy)

crates/tmc-langs/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ use std::{
4141
path::{Path, PathBuf},
4242
sync::{Arc, Mutex},
4343
};
44-
use tmc_langs_framework::{Archive, TmcError};
44+
use tmc_langs_framework::Archive;
4545
pub use tmc_langs_framework::{
4646
CommandError, Compression, ExerciseDesc, ExercisePackagingConfiguration, Language,
4747
LanguagePlugin, PythonVer, RunResult, RunStatus, StyleValidationError, StyleValidationResult,
4848
StyleValidationStrategy, TestDesc, TestResult, TmcProjectYml,
4949
};
5050
use tmc_langs_plugins::{
51-
AntPlugin, CSharpPlugin, MakePlugin, MavenPlugin, NoTestsPlugin, Plugin, PluginType,
52-
Python3Plugin, RPlugin,
51+
CSharpPlugin, MakePlugin, NoTestsPlugin, Plugin, PluginType, Python3Plugin, RPlugin,
5352
};
53+
// the Java plugin is disabled on musl
5454
pub use tmc_langs_util::{
5555
file_util::{self, FileLockGuard},
5656
notification_reporter, progress_reporter,
@@ -60,6 +60,11 @@ pub use tmc_testmycode_client as tmc;
6060
use toml::Value as TomlValue;
6161
use url::Url;
6262
use walkdir::WalkDir;
63+
#[cfg(not(target_env = "musl"))]
64+
use {
65+
tmc_langs_framework::TmcError,
66+
tmc_langs_plugins::{AntPlugin, MavenPlugin},
67+
};
6368

6469
const TMC_LANGS_CONFIG_DIR_VAR: &str = "TMC_LANGS_CONFIG_DIR";
6570

@@ -920,6 +925,8 @@ pub fn prepare_stub(exercise_path: &Path, dest_path: &Path) -> Result<(), LangsE
920925
submission_processing::prepare_stub(exercise_path, dest_path)?;
921926

922927
// The Ant plugin needs some additional files to be copied over.
928+
// the Java plugin is disabled on musl
929+
#[cfg(not(target_env = "musl"))]
923930
if let Ok(PluginType::Ant) = PluginType::from_exercise(exercise_path) {
924931
AntPlugin::copy_tmc_junit_runner(dest_path).map_err(|e| TmcError::Plugin(Box::new(e)))?;
925932
}
@@ -1076,7 +1083,11 @@ fn get_default_sandbox_image(path: &Path) -> Result<&'static str, LangsError> {
10761083
let img = match PluginType::from_exercise(path)? {
10771084
PluginType::CSharp => CSharpPlugin::DEFAULT_SANDBOX_IMAGE,
10781085
PluginType::Make => MakePlugin::DEFAULT_SANDBOX_IMAGE,
1086+
// the Java plugin is disabled on musl
1087+
#[cfg(not(target_env = "musl"))]
10791088
PluginType::Maven => MavenPlugin::DEFAULT_SANDBOX_IMAGE,
1089+
// the Java plugin is disabled on musl
1090+
#[cfg(not(target_env = "musl"))]
10801091
PluginType::Ant => AntPlugin::DEFAULT_SANDBOX_IMAGE,
10811092
PluginType::NoTests => NoTestsPlugin::DEFAULT_SANDBOX_IMAGE,
10821093
PluginType::Python3 => Python3Plugin::DEFAULT_SANDBOX_IMAGE,

0 commit comments

Comments
 (0)