Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ before_install:
- export PATH=$PATH:$PWD/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
- mkdir -p $HOME/bin && ln -s $(which python3.4) $HOME/bin/python3 && export PATH="$HOME/bin:$PATH"
- export PATH="$HOME/bin:$PATH"
- mvn install -Dmaven.test.skip=true
script:
- mvn clean test -pl tmc-langs-r
Expand Down
16 changes: 16 additions & 0 deletions tmc-langs-cli/src/main/java/fi/helsinki/cs/tmc/langs/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
Expand Down Expand Up @@ -54,6 +55,7 @@ public final class Main {
+ " Commands:\n"
+ " checkstyle --exercisePath --outputPath --locale"
+ " Run checkstyle or similar plugin to project if applicable.\n"
+ " compress-project --exercisePath --outputPath\n"
+ " help"
+ " Display help information.\n"
+ " prepare-solutions --exercisePath --outputPath"
Expand Down Expand Up @@ -118,6 +120,9 @@ private static void run(String command) {
case "checkstyle":
runCheckCodeStyle();
break;
case "compress-project":
runCompressProject();
break;
case "scan-exercise":
runScanExercise();
break;
Expand Down Expand Up @@ -166,6 +171,17 @@ private static Path getOutputPathFromArgs() {
throw new IllegalStateException("No " + OUTPUT_PATH + " provided");
}

private static void runCompressProject() {
Path exercisePath = getExercisePathFromArgs();
Path outputPath = getOutputPathFromArgs();
try {
byte[] compressed = executor.compressProject(exercisePath);
Files.write(outputPath, compressed);
} catch (IOException | NoLanguagePluginFoundException e) {
e.printStackTrace();
}
}

private static void runCheckCodeStyle() {
ValidationResult validationResult = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Stack;

Expand Down Expand Up @@ -147,9 +149,17 @@ private ImmutableList<Path> searchForExercises(
}

@Override
public ExercisePackagingConfiguration getExercisePackagingConfiguration() {
return new ExercisePackagingConfiguration(
ImmutableList.of("src"), ImmutableList.of("test"));
public ExercisePackagingConfiguration getExercisePackagingConfiguration(Path path) {
Configuration configuration = getConfiguration(path);
List<Path> extraStudentFiles = configuration.getExtraStudentFiles();
List<String> extraStudentStrings = new ArrayList<>();
for (Path p : extraStudentFiles) {
extraStudentStrings.add(p.toString());
}
ImmutableList<String> studentFiles =
ImmutableList.<String>builder().add("src").addAll(extraStudentStrings).build();
ImmutableList<String> src = ImmutableList.of("src");
return new ExercisePackagingConfiguration(studentFiles, ImmutableList.of("test"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ ValidationResult checkCodeStyle(Path path, Locale messageLocale)
* Returns configuration which is used to package submission on tmc-server.
*/
@Beta
public ExercisePackagingConfiguration getExercisePackagingConfiguration();
public ExercisePackagingConfiguration getExercisePackagingConfiguration(Path path);

/**
* Runs clean command e.g {@code make clean} for make or {@code mvn clean} for maven.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@

import fi.helsinki.cs.tmc.langs.utils.TmcProjectYmlParser;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class Configuration {

private final TmcProjectYmlParser tmcProjectYmlParser;
private final Path path;
private Map<String, ValueObject> options;
public static final Path TMC_PROJECT_YML = Paths.get(".tmcproject.yml");

@VisibleForTesting
public Configuration() {
tmcProjectYmlParser = new TmcProjectYmlParser();
options = new HashMap<>();
path = null;
}

public Configuration(Path path) {
this.path = path;
tmcProjectYmlParser = new TmcProjectYmlParser();
parseOptions(path);
}

Expand All @@ -40,19 +49,23 @@ public ValueObject get(String key) {
return null;
}

public List<Path> getExtraStudentFiles() {
return tmcProjectYmlParser.parseExtraStudentFiles(path.resolve(TMC_PROJECT_YML));
}

/**
* Parse options from the path.
*
* @param path Absolute path to configuration, e.g. .tmcproject.yml -file.
*/
public void parseOptions(Path path) {
void parseOptions(Path path) {
this.options = parseTmcProjectYmlOptions(path);
}

private Map<String, ValueObject> parseTmcProjectYmlOptions(Path path) {
Path configFile = path.resolve(TMC_PROJECT_YML);
if (Files.exists(path)) {
return new TmcProjectYmlParser().parseOptions(configFile);
return tmcProjectYmlParser.parseOptions(configFile);
}
return Maps.newHashMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ public boolean isStudentFile(Path path, Path projectRootPath) {
projectRootPath);
}

/**
* Determines whether a file is an <tt>ExtraStudentFile</tt>.
*/
/** Determines whether a file is an <tt>ExtraStudentFile</tt>. */
private boolean isExtraStudentFile(Path path) {
if (extraStudentFiles == null) {
loadExtraStudentFileList();
}

for (Path extraStudentFile : extraStudentFiles) {
if (extraStudentFile.toAbsolutePath().equals(path.toAbsolutePath())) {
Path extraStudentPath = rootPath.resolve(extraStudentFile).toAbsolutePath();
Path userSuppliedPath = path.toAbsolutePath();
if (extraStudentPath.equals(userSuppliedPath)
|| (userSuppliedPath.startsWith((extraStudentPath))
&& Files.isDirectory(extraStudentPath))) {
return true;
}
}
Expand All @@ -96,7 +98,7 @@ private void loadExtraStudentFileList() {

if (Files.exists(configFile)) {
TmcProjectYmlParser parser = new TmcProjectYmlParser();
extraStudentFiles = parser.parseExtraStudentFiles(configFile, rootPath);
extraStudentFiles = parser.parseExtraStudentFiles(configFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -20,18 +21,15 @@
public final class TmcProjectYmlParser implements ConfigurationParser {

private static final Logger log = LoggerFactory.getLogger(TmcProjectYmlParser.class);

private Path rootPath;
private List<Path> extraStudentFiles;

/**
* Parses a list of extra student files from a <tt>.tmcproject.yml</tt> file.
*/
public List<Path> parseExtraStudentFiles(Path configFilePath, Path projectRootPath) {
public List<Path> parseExtraStudentFiles(Path configFilePath) {

log.debug("Parsing extra student files from {}", configFilePath);

rootPath = projectRootPath;
extraStudentFiles = new ArrayList<>();

Object yamlSpecifications = getYamlSpecs(configFilePath.toAbsolutePath());
Expand Down Expand Up @@ -109,12 +107,21 @@ private void addAllIfList(Object files) {

private void addIfString(Object value) {
if (value instanceof String) {
Path path = this.rootPath.resolve((String) value);
String[] pathParts = ((String) value).split("/");
Path path = constructPathfromArray(pathParts);
extraStudentFiles.add(path);
log.trace("Added {} as extra student file", path);
}
}

private Path constructPathfromArray(String[] parts) {
Path path = Paths.get(parts[0]);
for (int i = 1; i < parts.length; i++) {
path = path.resolve(parts[i]);
}
return path;
}

private String initFileContents(File file) {
try {
log.trace("Reading config file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ protected TestRunFileAndLogs createRunResultFile(Path path)
result.getStdErr());
}

// TODO: ADD extra student file support to here too
@Override
public ExercisePackagingConfiguration getExercisePackagingConfiguration() {
public ExercisePackagingConfiguration getExercisePackagingConfiguration(Path path) {
return new ExercisePackagingConfiguration(
ImmutableList.of("src/main"), ImmutableList.of("src/test"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ public void clean(Path path) {
// no op
}

// TODO: Add extra student files to here too
@Override
public ExercisePackagingConfiguration getExercisePackagingConfiguration() {
public ExercisePackagingConfiguration getExercisePackagingConfiguration(Path path) {
return new ExercisePackagingConfiguration(
ImmutableList.of("src"), ImmutableList.of("test", "tmc"));
}
Expand Down
4 changes: 4 additions & 0 deletions tmc-langs-r/getAvailablePoints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
#Currently this script needs to be run at project root!

Rscript -e "library(tmcRtestrunner);get_available_points(\"$PWD\")"
3 changes: 3 additions & 0 deletions tmc-langs-r/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
#Currently this script needs to be run at project root!
/usr/bin/Rscript -e "library(tmcRtestrunner);runTestsWithDefault(TRUE)"
27 changes: 19 additions & 8 deletions tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/RPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public String getPluginName() {

@Override
public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
ProcessRunner runner = new ProcessRunner(getAvailablePointsCommand(), path);
ProcessRunner runner = new ProcessRunner(this.getAvailablePointsCommand(), path);
try {
runner.call();
} catch (Exception e) {
Expand Down Expand Up @@ -143,21 +143,32 @@ public ValidationResult checkCodeStyle(Path path, Locale messageLocale) {
return null;
}

private String[] getTestCommand() {
String[] rscr = new String[] {"Rscript", "-e"};
public String[] getTestCommand() {

String[] rscr;
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
rscr = new String[] {"Rscript", "-e"};
command = new String[] {"\"library('tmcRtestrunner');runTestsWithDefault(TRUE)\""};
} else {
command = new String[] {"\"library(tmcRtestrunner);runTests(\"$PWD\", print=TRUE)\""};
rscr = new String[] {"bash"};
command = new String[] {Paths.get("").toAbsolutePath().toString() + "/runTests.sh"};
}
return ArrayUtils.addAll(rscr, command);
}

private String[] getAvailablePointsCommand() {
String[] rscr = new String[] {"Rscript", "-e"};
String[] command = new String[] {"\"library(tmcRtestrunner);"
+ "getAvailablePoints(\"$PWD\")\""};
public String[] getAvailablePointsCommand() {
String[] rscr;
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
rscr = new String[] {"Rscript", "-e"};
command = new String[] {"\"library(tmcRtestrunner);"
+ "get_available_points(\"$PWD\")\""};
} else {
rscr = new String[] {"bash"};
command = new String[] {Paths.get("").toAbsolutePath().toString()
+ "/getAvailablePoints.sh"};
}
return ArrayUtils.addAll(rscr, command);
}

Expand Down
43 changes: 5 additions & 38 deletions tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.domain.TestResult;
import fi.helsinki.cs.tmc.langs.utils.ProcessRunner;
import fi.helsinki.cs.tmc.langs.utils.TestUtils;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -23,11 +16,12 @@ public class TestMain {
public static void main(String[] args) {
//For now, add the path you want to test here fully,
//for example: pathToGithubFolder/tmc-r/example_projects/example_project1
String exampleProjectLocation = "/example_projects/example_project1";
/**String exampleProjectLocation = "/path/to/r-project"
+ "/example_projects/example_project1";
Path path = Paths.get(exampleProjectLocation);
RunResult runRes = runTests(path);
printTestResult(runRes);
RunResult rr;
RPlugin rplugin = new RPlugin();
RunResult runRes = rplugin.runTests(path);
printTestResult(runRes);**/
}

public static void printTestResult(RunResult rr) {
Expand All @@ -37,31 +31,4 @@ public static void printTestResult(RunResult rr) {
}


public static RunResult runTests(Path path) {

ProcessRunner runner = new ProcessRunner(getTestCommand(), path);
try {
runner.call();
} catch (Exception e) {
System.out.println("Something wrong: " + e.getMessage());
}

try {
return new RTestResultParser(path).parse();
} catch (IOException e) {
System.out.println("Something wrong: " + e.getMessage());
}
return null;
}

private static String[] getTestCommand() {
String[] rscr = new String[]{"Rscript", "-e"};
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
command = new String[] {"\"library('tmcRtestrunner');runTestsWithDefault(TRUE)\""};
} else {
command = new String[] {"\"library(tmcRtestrunner);runTests(\"$PWD\", print=TRUE)\""};
}
return ArrayUtils.addAll(rscr, command);
}
}
Loading