Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 1c0be3b

Browse files
committed
Merge branch 'master' into courseinfoupdating-matike
2 parents 66a5a55 + d2aa5b3 commit 1c0be3b

10 files changed

Lines changed: 253 additions & 46 deletions

File tree

HACKING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ public class ExampleCommand extends AbstractCommand {
3131

3232
## Architecture
3333
...
34+
35+
## Debugging
36+
### Logging

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Now that you've installed tmc-cli, you can view all available commands by runnin
4646
Once installation is complete, you can log in using `tmc login`. This saves your TMC login information to a configuration file in ~/.config/tmc-cli/ (or %LOCALAPPDATA% on Windows) - you will only have to log in once.
4747
```
4848
~ $ tmc login
49-
username: my-username
50-
password:
5149
server address:
50+
username:
51+
password:
5252
Login successful.
5353
```
5454

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>fi.helsinki.cs.tmc.cli</groupId>
55
<artifactId>tmc-cli</artifactId>
6-
<version>0.5.2</version>
6+
<version>0.6.0</version>
77
<packaging>jar</packaging>
88
<properties>
99
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/fi/helsinki/cs/tmc/cli/command/LoginCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public void getOptions(Options options) {
3636
@Override
3737
public void run(CommandLine args, Io io) {
3838
this.io = io;
39+
String serverAddress = getLoginInfo(args, "s", "server address: ");
3940
String username = getLoginInfo(args, "u", "username: ");
4041
String password = getLoginInfo(args, "p", "password: ");
41-
String serverAddress = getLoginInfo(args, "s", "server address: ");
42-
42+
4343
Settings settings = new Settings(serverAddress, username, password);
4444
if (loginPossible(settings) && saveLoginSettings(settings)) {
4545
io.println("Login successful.");

src/main/java/fi/helsinki/cs/tmc/cli/command/RunTestsCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ public void run(CommandLine args, Io io) {
107107
passed += ResultPrinter.passedTests(runResult.testResults);
108108
exercise.setAttempted(true);
109109
if (runResult.status == PASSED && !exercise.isCompleted()) {
110+
// add exercise to locally tested exercises
110111
if (!info.getLocalCompletedExercises().contains(exercise.getName())) {
111112
info.getLocalCompletedExercises().add(exercise.getName());
112113
}
114+
} else {
115+
if (info.getLocalCompletedExercises().contains(exercise.getName())) {
116+
info.getLocalCompletedExercises().remove(exercise.getName());
117+
}
113118
}
114119
}
115120
CourseInfoIo.save(info, workDir.getConfigFile());

src/main/java/fi/helsinki/cs/tmc/cli/command/SubmitCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class SubmitCommand extends AbstractCommand {
4040
public void getOptions(Options options) {
4141
options.addOption("a", "all", false, "Show all test results");
4242
options.addOption("d", "details", false, "Show detailed error message");
43-
options.addOption("c", "completed", false, "Only exercises that have passed all tests");
43+
options.addOption("c", "completed", false,
44+
"Filter out exercises that haven't been locally tested");
4445
}
4546

4647
@Override
@@ -68,6 +69,7 @@ public void run(CommandLine args, Io io) {
6869

6970
List<String> exerciseNames;
7071
if (args.hasOption("c")) {
72+
workDir.addPath(workDir.getCourseDirectory());
7173
exerciseNames = workDir.getExerciseNames(true, true, false);
7274
} else {
7375
exerciseNames = workDir.getExerciseNames();

src/main/java/fi/helsinki/cs/tmc/cli/command/core/CommandAnnotationProcessor.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,32 @@ public class CommandAnnotationProcessor extends AbstractProcessor {
3030
private static final Logger logger = LoggerFactory.getLogger(CommandAnnotationProcessor.class);
3131

3232
private static final String CLASS_NAME = "CommandList";
33-
private static final String PACKAGE_NAME = "fi.helsinki.cs.tmc.cli.command";
33+
private static final String PACKAGE_NAME = "fi.helsinki.cs.tmc.cli.command.core";
3434
private static final String TAB = " ";
3535

36-
private ProcessingEnvironment processingEnv;
37-
38-
@Override
39-
public void init(ProcessingEnvironment processingEnv) {
40-
this.processingEnv = processingEnv;
41-
}
42-
4336
private void generateSourceFile(Map<String, String> map) throws IOException {
4437
JavaFileObject jfo = processingEnv.getFiler().createSourceFile(
45-
PACKAGE_NAME + ".core." + CLASS_NAME);
38+
PACKAGE_NAME + "." + CLASS_NAME);
4639

4740
try (Writer writer = jfo.openWriter()) {
4841
BufferedWriter bwriter = new BufferedWriter(writer);
49-
bwriter.append("package ");
50-
bwriter.append(PACKAGE_NAME);
51-
bwriter.append(".core;\n\n");
42+
bwriter.append("package " + PACKAGE_NAME + ";\n\n");
43+
44+
// import the command classes
5245
bwriter.append("//CHECKSTYLE:OFF\n");
53-
bwriter.append("import " + PACKAGE_NAME + ".core.CommandFactory;\n\n");
5446
for (Entry<String, String> entry : map.entrySet()) {
5547
bwriter.append("import " + entry.getValue() + ";\n");
5648
}
5749
bwriter.append("//CHECKSTYLE:ON\n");
50+
5851
bwriter.append("\npublic class " + CLASS_NAME + " {\n");
5952
bwriter.append(TAB + "static {\n");
6053
for (Entry<String, String> entry : map.entrySet()) {
6154
String[] parts = entry.getValue().split("\\.");
6255
if (parts.length == 0) {
6356
continue;
6457
}
58+
// print out the lines that add the commands to the command factory.
6559
String className = parts[parts.length - 1];
6660
bwriter.append(TAB + TAB + "CommandFactory.addCommand(\""
6761
+ entry.getKey() + "\", "
@@ -76,15 +70,15 @@ private void generateSourceFile(Map<String, String> map) throws IOException {
7670
@Override
7771
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
7872
Map<String, String> map = new HashMap<>();
79-
Messager messager = processingEnv.getMessager();
8073

8174
for (Element elem : roundEnv.getElementsAnnotatedWith(Command.class)) {
8275
if (elem.getKind() != ElementKind.CLASS) {
83-
continue;
76+
logger.warn("Element with command annotation is not class: " + elem.toString());
77+
return false;
8478
}
8579
Command command = elem.getAnnotation(Command.class);
86-
messager.printMessage(Diagnostic.Kind.NOTE, elem.toString());
87-
messager.printMessage(Diagnostic.Kind.NOTE, elem.getClass().getCanonicalName());
80+
logger.info("element with annotation: " + elem.toString());
81+
logger.info("element name with annotation: " + elem.getClass().getCanonicalName());
8882

8983
TypeElement classElement = (TypeElement) elem;
9084
map.put(command.name(), processingEnv.getElementUtils()
@@ -94,7 +88,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
9488
try {
9589
generateSourceFile(map);
9690
} catch (IOException ex) {
97-
messager.printMessage(Diagnostic.Kind.NOTE, "Failed to create source file." + ex);
91+
logger.warn("Failed to create source file." + ex);
9892
}
9993
return true;
10094
}

src/main/java/fi/helsinki/cs/tmc/cli/io/ResultPrinter.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import fi.helsinki.cs.tmc.langs.domain.SpecialLogs;
66
import fi.helsinki.cs.tmc.langs.domain.TestResult;
77

8+
import java.util.Arrays;
89
import java.util.List;
910

1011
public class ResultPrinter {
1112

1213
private static final String COMPILE_ERROR_MESSAGE
1314
= Color.colorString("Failed to compile project", Color.AnsiColor.ANSI_PURPLE);
14-
private static final String FAIL = Color.colorString("Failed: ", Color.AnsiColor.ANSI_RED);
15-
private static final String PASS = Color.colorString("Passed: ", Color.AnsiColor.ANSI_GREEN);
16-
private static final String TAB = " ";
17-
private static final char LF = '\n';
15+
private static final String FAIL_MESSAGE = "Failed: ";
16+
private static final String PASS_MESSAGE = "Passed: ";
17+
private final String tab;
1818

1919
private final Io io;
2020

@@ -27,6 +27,8 @@ public ResultPrinter(Io io, boolean showDetails, boolean showPassed) {
2727
this.io = io;
2828
this.showDetails = showDetails;
2929
this.showPassed = showPassed;
30+
31+
this.tab = createPaddingString(PASS_MESSAGE.length());
3032
}
3133

3234
public boolean isShowDetails() {
@@ -155,9 +157,9 @@ public static int passedTests(List<TestResult> testResults) {
155157
private void printTestResults(List<TestResult> testResults) {
156158
for (TestResult testResult : testResults) {
157159
if (!testResult.isSuccessful()) {
158-
io.println(createFailMessage(testResult));
160+
printFailMessage(testResult);
159161
} else if (showPassed) {
160-
io.println(createPassMessage(testResult));
162+
printPassMessage(testResult);
161163
}
162164
}
163165
io.println("Test results: "
@@ -166,37 +168,45 @@ private void printTestResults(List<TestResult> testResults) {
166168

167169
}
168170

169-
private String createFailMessage(TestResult testResult) {
170-
StringBuilder sb = new StringBuilder();
171-
sb.append(FAIL).append(testResult.getName()).append(LF);
172-
sb.append(TAB).append(testResult.getMessage()).append(LF);
171+
private void printFailMessage(TestResult testResult) {
172+
io.print(Color.colorString(FAIL_MESSAGE, Color.AnsiColor.ANSI_RED));
173+
io.println(testResult.getName());
174+
io.println(this.tab + testResult.getMessage());
173175

174176
if (showDetails) {
175-
String details = listToString(testResult.getDetailedMessage(), LF);
177+
String details = listToString(testResult.getDetailedMessage());
176178
if (details != null) {
177-
sb.append(LF).append("Detailed message:").append(LF).append(details);
179+
io.println("\nDetailed message:");
180+
io.println(details);
178181
}
179-
String exception = listToString(testResult.getException(), LF);
182+
183+
String exception = listToString(testResult.getException());
180184
if (exception != null) {
181-
sb.append(LF).append("Exception:").append(LF).append(exception);
185+
io.println("\nException:");
186+
io.println(exception);
182187
}
183188
}
184-
return sb.toString();
185189
}
186190

187-
private String createPassMessage(TestResult testResult) {
188-
return PASS + testResult.getName() + LF;
191+
private void printPassMessage(TestResult testResult) {
192+
io.print(Color.colorString(PASS_MESSAGE, Color.AnsiColor.ANSI_GREEN));
193+
io.println(testResult.getName());
189194
}
190195

191-
private String listToString(List<String> strings, char separator) {
196+
private String listToString(List<String> strings) {
192197
if (strings == null || strings.isEmpty()) {
193198
return null;
194199
}
195200
StringBuilder sb = new StringBuilder();
196201
for (String string : strings) {
197-
sb.append(string).append(separator);
202+
sb.append(string).append("\n");
198203
}
199204
return sb.toString();
200205
}
201206

202-
}
207+
private String createPaddingString(int size) {
208+
char[] charArray = new char[size];
209+
Arrays.fill(charArray, ' ');
210+
return new String(charArray);
211+
}
212+
}

src/test/java/fi/helsinki/cs/tmc/cli/command/RunTestsCommandTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.Assert.assertFalse;
44
import static org.junit.Assert.assertNotNull;
55
import static org.junit.Assert.assertTrue;
6-
76
import static org.mockito.Matchers.anyObject;
87
import static org.mockito.Mockito.doReturn;
98
import static org.mockito.Mockito.mock;
@@ -133,5 +132,4 @@ public void worksInCourseDirectoryIfExerciseIsGiven() {
133132
app.run(args);
134133
assertTrue(io.out().contains("Testing: " + EXERCISE1_NAME));
135134
}
136-
137135
}

0 commit comments

Comments
 (0)