Skip to content

Commit bfe1637

Browse files
authored
Merge pull request #131 from rage/compress-project-without-java
added plugintype so compress-project doesn't need to construct a plugin
2 parents 6b1b375 + 637d1dc commit bfe1637

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

tmc-langs-plugins/src/lib.rs

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,32 @@ pub fn extract_project_overwrite(
5454
/// See `LanguagePlugin::compress_project`.
5555
// TODO: clean up
5656
pub fn compress_project(path: &Path) -> Result<Vec<u8>, PluginError> {
57-
let plugin = get_language_plugin(path)?;
58-
match plugin {
59-
Plugin::CSharp(_) => Ok(tmc_zip::zip(
57+
match get_language_plugin_type(path)? {
58+
PluginType::CSharp => Ok(tmc_zip::zip(
6059
<CSharpPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
6160
path,
6261
)?),
63-
Plugin::Make(_) => Ok(tmc_zip::zip(
62+
PluginType::Make => Ok(tmc_zip::zip(
6463
<MakePlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
6564
path,
6665
)?),
67-
Plugin::Maven(_) => Ok(tmc_zip::zip(
66+
PluginType::Maven => Ok(tmc_zip::zip(
6867
<MavenPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
6968
path,
7069
)?),
71-
Plugin::NoTests(_) => Ok(tmc_zip::zip(
70+
PluginType::NoTests => Ok(tmc_zip::zip(
7271
<NoTestsPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
7372
path,
7473
)?),
75-
Plugin::Python3(_) => Ok(tmc_zip::zip(
74+
PluginType::Python3 => Ok(tmc_zip::zip(
7675
<Python3Plugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
7776
path,
7877
)?),
79-
Plugin::R(_) => Ok(tmc_zip::zip(
78+
PluginType::R => Ok(tmc_zip::zip(
8079
<RPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
8180
path,
8281
)?),
83-
Plugin::Ant(_) => Ok(tmc_zip::zip(
82+
PluginType::Ant => Ok(tmc_zip::zip(
8483
<AntPlugin as LanguagePlugin>::StudentFilePolicy::new(path)?,
8584
path,
8685
)?),
@@ -108,61 +107,83 @@ pub enum Plugin {
108107
Ant(AntPlugin),
109108
}
110109

111-
// Get language plugin for the given path.
112-
pub fn get_language_plugin(path: &Path) -> Result<Plugin, PluginError> {
113-
if NoTestsPlugin::is_exercise_type_correct(path) {
110+
pub enum PluginType {
111+
CSharp,
112+
Make,
113+
Maven,
114+
NoTests,
115+
Python3,
116+
R,
117+
Ant,
118+
}
119+
120+
pub fn get_language_plugin_type(path: &Path) -> Result<PluginType, PluginError> {
121+
let plugin_type = if NoTestsPlugin::is_exercise_type_correct(path) {
114122
log::info!(
115123
"Detected project at {} as {}",
116124
path.display(),
117125
NoTestsPlugin::PLUGIN_NAME
118126
);
119-
Ok(Plugin::NoTests(NoTestsPlugin::new()))
127+
PluginType::NoTests
120128
} else if CSharpPlugin::is_exercise_type_correct(path) {
121-
let csharp = CSharpPlugin::new();
122129
log::info!(
123130
"Detected project at {} as {}",
124131
path.display(),
125132
CSharpPlugin::PLUGIN_NAME
126133
);
127-
Ok(Plugin::CSharp(csharp))
134+
PluginType::CSharp
128135
} else if MakePlugin::is_exercise_type_correct(path) {
129-
let make = MakePlugin::new();
130136
log::info!(
131137
"Detected project at {} as {}",
132138
path.display(),
133139
MakePlugin::PLUGIN_NAME
134140
);
135-
Ok(Plugin::Make(make))
141+
PluginType::Make
136142
} else if Python3Plugin::is_exercise_type_correct(path) {
137143
log::info!(
138144
"Detected project at {} as {}",
139145
path.display(),
140146
Python3Plugin::PLUGIN_NAME
141147
);
142-
Ok(Plugin::Python3(Python3Plugin::new()))
148+
PluginType::Python3
143149
} else if RPlugin::is_exercise_type_correct(path) {
144150
log::info!(
145151
"Detected project at {} as {}",
146152
path.display(),
147153
RPlugin::PLUGIN_NAME
148154
);
149-
Ok(Plugin::R(RPlugin::new()))
155+
PluginType::R
150156
} else if MavenPlugin::is_exercise_type_correct(path) {
151157
log::info!(
152158
"Detected project at {} as {}",
153159
path.display(),
154160
MavenPlugin::PLUGIN_NAME
155161
);
156-
Ok(Plugin::Maven(MavenPlugin::new()?))
162+
PluginType::Maven
157163
} else if AntPlugin::is_exercise_type_correct(path) {
158164
// TODO: currently, ant needs to be last because any project with src and test are recognized as ant
159165
log::info!(
160166
"Detected project at {} as {}",
161167
path.display(),
162168
AntPlugin::PLUGIN_NAME
163169
);
164-
Ok(Plugin::Ant(AntPlugin::new()?))
170+
PluginType::Ant
165171
} else {
166-
Err(PluginError::PluginNotFound(path.to_path_buf()))
167-
}
172+
return Err(PluginError::PluginNotFound(path.to_path_buf()));
173+
};
174+
Ok(plugin_type)
175+
}
176+
177+
// Get language plugin for the given path.
178+
pub fn get_language_plugin(path: &Path) -> Result<Plugin, PluginError> {
179+
let plugin = match get_language_plugin_type(path)? {
180+
PluginType::NoTests => Plugin::NoTests(NoTestsPlugin::new()),
181+
PluginType::CSharp => Plugin::CSharp(CSharpPlugin::new()),
182+
PluginType::Make => Plugin::Make(MakePlugin::new()),
183+
PluginType::Python3 => Plugin::Python3(Python3Plugin::new()),
184+
PluginType::R => Plugin::R(RPlugin::new()),
185+
PluginType::Maven => Plugin::Maven(MavenPlugin::new()?),
186+
PluginType::Ant => Plugin::Ant(AntPlugin::new()?),
187+
};
188+
Ok(plugin)
168189
}

tmc-langs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::{
4949
};
5050
use std::{collections::HashMap, ffi::OsStr};
5151
use tmc_langs_framework::{NothingIsStudentFilePolicy, StudentFilePolicy, TmcError, TmcProjectYml};
52-
use tmc_langs_plugins::{get_language_plugin, tmc_zip, AntPlugin, Plugin};
52+
use tmc_langs_plugins::{get_language_plugin, tmc_zip, AntPlugin, PluginType};
5353
use tmc_langs_util::progress_reporter;
5454
use toml::{map::Map as TomlMap, Value as TomlValue};
5555
use url::Url;
@@ -754,7 +754,7 @@ pub fn prepare_stub(exercise_path: &Path, dest_path: &Path) -> Result<(), LangsE
754754
submission_processing::prepare_stub(&exercise_path, dest_path)?;
755755

756756
// The Ant plugin needs some additional files to be copied over.
757-
if let Plugin::Ant(_) = tmc_langs_plugins::get_language_plugin(exercise_path)? {
757+
if let PluginType::Ant = tmc_langs_plugins::get_language_plugin_type(exercise_path)? {
758758
AntPlugin::copy_tmc_junit_runner(dest_path).map_err(|e| TmcError::Plugin(Box::new(e)))?;
759759
}
760760
Ok(())

0 commit comments

Comments
 (0)