@@ -54,33 +54,32 @@ pub fn extract_project_overwrite(
5454/// See `LanguagePlugin::compress_project`.
5555// TODO: clean up
5656pub 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}
0 commit comments