Skip to content

Commit 5e72d73

Browse files
authored
Merge pull request #121 from rage/restructuring
Restructuring
2 parents 534f69c + 9e6de1d commit 5e72d73

File tree

194 files changed

+3562
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+3562
-604
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[workspace]
22
members =[
33
"tmc-client",
4+
"tmc-langs",
45
"tmc-langs-cli",
56
"tmc-langs-framework",
7+
"tmc-langs-plugins",
68
"tmc-langs-util",
79

810
"plugins/csharp",

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ Documentation and binaries for the supported targets are built and the binaries
6868

6969
### tmc-langs-cli
7070

71-
A binary CLI interface for TMC-langs for IDEs.
71+
A "frontend" for tmc-langs. A binary CLI client for TMC-langs for IDEs. Intended to be used programmatically, for a CLI meant for manual use see [tmc-cli-rust](https://github.com/rage/tmc-cli-rust).
72+
73+
### tmc-langs
74+
75+
The "backend". A library that provides a convenient API for implementing different frontends. A frontend (such as a CLI) should only depend on this and optionally the util library.
7276

7377
### tmc-client
7478

@@ -78,9 +82,13 @@ A library for communicating with the TMC server.
7882

7983
A library for creating language plugins.
8084

85+
### tmc-langs-plugins
86+
87+
A library that provides a convenient API for using all the different plugins.
88+
8189
### tmc-langs-util
8290

83-
A library that provides a convenient interface abstracting over all available language plugins.
91+
A utility library that contains various kinds of useful functionality for other projects.
8492

8593
### plugins/csharp
8694

plugins/csharp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ license = "MIT OR Apache-2.0"
77

88
[dependencies]
99
tmc-langs-framework = { path = "../../tmc-langs-framework" }
10+
tmc-langs-util = { path = "../../tmc-langs-util" }
1011

1112
dirs = "3"
1213
log = "0.4"
1314
serde = { version = "1", features = ["derive"] }
1415
serde_json = "1"
1516
thiserror = "1"
1617
walkdir = "2"
18+
zip = "0.5"
1719

1820
[dev-dependencies]
1921
simple_logger = "1"
2022
tempfile = "3"
21-
zip = "0.5"

plugins/csharp/src/cs_test_result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use serde::Deserialize;
44
use std::collections::HashSet;
5-
use tmc_langs_framework::domain::TestResult;
5+
use tmc_langs_framework::TestResult;
66

77
/// Test result from the C# test runner.
88
#[derive(Debug, Deserialize)]

plugins/csharp/src/error.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
33
use std::path::PathBuf;
44
use thiserror::Error;
5-
use tmc_langs_framework::{
6-
error::{CommandError, FileIo},
7-
zip, TmcError,
8-
};
5+
use tmc_langs_framework::TmcError;
6+
use tmc_langs_util::FileError;
97

108
#[derive(Debug, Error)]
119
pub enum CSharpError {
@@ -20,12 +18,8 @@ pub enum CSharpError {
2018
MissingBootstrapDll(PathBuf),
2119

2220
// Wrapping other error types.
23-
#[error("Command not found")]
24-
Command(#[from] CommandError),
2521
#[error("File IO error")]
26-
FileIo(#[from] FileIo),
27-
#[error("TMC error")]
28-
Tmc(#[from] TmcError),
22+
FileError(#[from] FileError),
2923
#[error("Zip error")]
3024
Zip(#[from] zip::result::ZipError),
3125
}
@@ -36,3 +30,10 @@ impl From<CSharpError> for TmcError {
3630
Self::Plugin(Box::new(err))
3731
}
3832
}
33+
34+
// conversion from plugin error to a tmc result
35+
impl<T> Into<Result<T, TmcError>> for CSharpError {
36+
fn into(self) -> Result<T, TmcError> {
37+
Err(TmcError::Plugin(Box::new(self)))
38+
}
39+
}

plugins/csharp/src/plugin.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ use std::io::{BufReader, Cursor, Read, Seek};
99
use std::path::{Path, PathBuf};
1010
use std::time::Duration;
1111
use tmc_langs_framework::{
12-
command::TmcCommand,
13-
domain::{
14-
ExerciseDesc, RunResult, RunStatus, StyleValidationResult, StyleValidationStrategy,
15-
TestDesc, TestResult,
16-
},
17-
error::{CommandError, FileIo},
18-
file_util,
1912
nom::{bytes, character, combinator, error::VerboseError, sequence, IResult},
20-
plugin::Language,
21-
zip::ZipArchive,
22-
LanguagePlugin, TmcError,
13+
CommandError, ExerciseDesc, Language, LanguagePlugin, RunResult, RunStatus,
14+
StyleValidationResult, StyleValidationStrategy, TestDesc, TestResult, TmcCommand, TmcError,
2315
};
16+
use tmc_langs_util::{file_util, FileError};
2417
use walkdir::WalkDir;
18+
use zip::ZipArchive;
2519

2620
const TMC_CSHARP_RUNNER: &[u8] = include_bytes!("../deps/tmc-csharp-runner-1.1.1.zip");
2721

@@ -57,7 +51,7 @@ impl CSharpPlugin {
5751
let zip_bytes: Vec<u8> = file
5852
.bytes()
5953
.collect::<Result<Vec<_>, _>>()
60-
.map_err(|e| FileIo::FileRead(zip_file_path, e))?;
54+
.map_err(|e| FileError::FileRead(zip_file_path, e))?;
6155

6256
if target_bytes != zip_bytes {
6357
return Ok(true); // bytes changed, need to extract
@@ -84,7 +78,7 @@ impl CSharpPlugin {
8478
let bytes: Vec<u8> = file
8579
.bytes()
8680
.collect::<Result<Vec<_>, _>>()
87-
.map_err(|e| FileIo::FileRead(file_path, e))?;
81+
.map_err(|e| FileError::FileRead(file_path, e))?;
8882
file_util::write_to_file(&mut bytes.as_slice(), target_file_path)?;
8983
}
9084
}

plugins/java/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT OR Apache-2.0"
77

88
[dependencies]
99
tmc-langs-framework = { path = "../../tmc-langs-framework" }
10+
tmc-langs-util = { path = "../../tmc-langs-util" }
1011

1112
dirs = "3"
1213
flate2 = "1"

plugins/java/src/ant_plugin.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ use std::ffi::OsStr;
1010
use std::path::{Path, PathBuf};
1111
use std::time::Duration;
1212
use tmc_langs_framework::{
13-
command::TmcCommand,
14-
domain::{ExerciseDesc, RunResult, StyleValidationResult},
15-
file_util,
1613
nom::{error::VerboseError, IResult},
17-
plugin::{Language, LanguagePlugin},
18-
TmcError,
14+
ExerciseDesc, Language, LanguagePlugin, RunResult, StyleValidationResult, TmcCommand, TmcError,
1915
};
16+
use tmc_langs_util::file_util;
2017
use walkdir::WalkDir;
2118

2219
pub struct AntPlugin {
@@ -274,8 +271,8 @@ impl JavaPlugin for AntPlugin {
274271
mod test {
275272
use super::*;
276273
use std::fs;
277-
use tmc_langs_framework::domain::StyleValidationStrategy;
278-
use tmc_langs_framework::zip::ZipArchive;
274+
use tmc_langs_framework::StyleValidationStrategy;
275+
use zip::ZipArchive;
279276

280277
fn init() {
281278
use log::*;
@@ -534,7 +531,7 @@ mod test {
534531
log::debug!("{:?}", test_result);
535532
assert_eq!(
536533
test_result.status,
537-
tmc_langs_framework::domain::RunStatus::TestsFailed
534+
tmc_langs_framework::RunStatus::TestsFailed
538535
);
539536
}
540537

@@ -554,13 +551,8 @@ mod test {
554551
let mut source = test_result_err.source();
555552
while let Some(inner) = source {
556553
source = inner.source();
557-
if let Some(cmd_error) =
558-
inner.downcast_ref::<tmc_langs_framework::error::CommandError>()
559-
{
560-
if matches!(
561-
cmd_error,
562-
tmc_langs_framework::error::CommandError::TimeOut { .. }
563-
) {
554+
if let Some(cmd_error) = inner.downcast_ref::<tmc_langs_framework::CommandError>() {
555+
if matches!(cmd_error, tmc_langs_framework::CommandError::TimeOut { .. }) {
564556
return;
565557
}
566558
}

plugins/java/src/ant_policy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Ant student file policy
22
33
use std::path::Path;
4-
use tmc_langs_framework::{policy::StudentFilePolicy, TmcProjectYml};
4+
use tmc_langs_framework::{StudentFilePolicy, TmcProjectYml};
55

66
pub struct AntStudentFilePolicy {
77
project_config: TmcProjectYml,

plugins/java/src/error.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
use std::io;
44
use std::path::PathBuf;
55
use thiserror::Error;
6-
use tmc_langs_framework::{
7-
error::{CommandError, FileIo},
8-
TmcError,
9-
};
6+
use tmc_langs_framework::TmcError;
7+
use tmc_langs_util::FileError;
108

119
#[derive(Error, Debug)]
1210
pub enum JavaError {
@@ -35,24 +33,20 @@ pub enum JavaError {
3533
WalkDir(#[from] walkdir::Error),
3634
#[error("JSON error")]
3735
Json(#[from] serde_json::Error),
38-
#[error("Failed to run command")]
39-
Command(#[from] CommandError),
36+
#[error("File IO error")]
37+
FileError(#[from] FileError),
4038
#[error("Error")]
4139
Tmc(#[from] TmcError),
4240
}
4341

42+
// conversion from plugin error to TmcError::Plugin
4443
impl From<JavaError> for TmcError {
4544
fn from(err: JavaError) -> TmcError {
4645
TmcError::Plugin(Box::new(err))
4746
}
4847
}
4948

50-
impl From<FileIo> for JavaError {
51-
fn from(err: FileIo) -> JavaError {
52-
JavaError::Tmc(TmcError::FileIo(err))
53-
}
54-
}
55-
49+
// conversion from plugin error to a tmc result
5650
impl<T> Into<Result<T, TmcError>> for JavaError {
5751
fn into(self) -> Result<T, TmcError> {
5852
Err(TmcError::Plugin(Box::new(self)))

0 commit comments

Comments
 (0)