Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file encoding issue #177

Merged
merged 2 commits into from
Sep 7, 2021
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ Usage: JPlag [ options ] [<root-dir>]

named arguments:
-h, --help show this help message and exit
-l {java1,java2,java5,java5dm,java7,java9,python3,cpp,csharp,char,text,scheme}
Select the language to parse the submissions (Standard: java9)
-l {java1,java2,java5,java5dm,java7,java9,python3,cpp,csharp,char,text,scheme} Select the language to parse the submissions (Standard: java9)
-bc BC Name of the directory which contains the base code (common framework used in all submissions)
-v {parser,quiet,long,details}
Verbosity (Standard: quiet)
-v {quiet,long} Verbosity of the logging (Standard: quiet)
-d (Debug) parser. Non-parsable files will be stored (Standard: false)
-S S Look in directories <root-dir>/*/<dir> for programs
-p P comma-separated list of all filename suffixes that are included
Expand Down
4 changes: 2 additions & 2 deletions jplag.frontend.chars/src/main/java/jplag/chars/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.FileReader;
import java.nio.charset.StandardCharsets;

import jplag.TokenList;

Expand All @@ -18,7 +19,6 @@ public jplag.TokenList parse(File dir, String files[]) {
errors++;
struct.addToken(new CharToken(FILE_END, files[i], this));
}
//System.err.println(struct.toString());
if (errors == 0)
program.print(null, "OK");
else
Expand All @@ -35,7 +35,7 @@ private boolean parseFile(File dir, String file) {
int offset = 0;

try {
FileReader fis = new FileReader(new File(dir, file));
FileReader fis = new FileReader(new File(dir, file), StandardCharsets.UTF_8);

do {
length = fis.read(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public jplag.TokenList parse(File dir, String files[]) {
errors++;
struct.addToken(new JavaToken(FILE_END, actFile, 0));
}
// System.err.println(struct.toString());
if (errors == 0)
program.print(null, "OK\n");
else
Expand All @@ -30,10 +29,6 @@ public jplag.TokenList parse(File dir, String files[]) {

public void add(int type, Token token) {
struct.addToken(new JavaToken(type, actFile, token.beginLine));
/*
* System.out.println(token.beginLine+"\t"+ (new
* JavaToken(0,null,0)).type2string(type)+"\t"+ token.image);
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void print(String normalMsg, String longMsg) {
} else if (normalMsg != null) {
System.out.println(normalMsg);
} else {
System.out.println("Someboy messed up - no message given");
System.out.println("Somebody messed up - no message given");
}
}
}
27 changes: 7 additions & 20 deletions jplag/src/main/java/jplag/JPlag.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jplag;

import static jplag.options.Verbosity.LONG;
import static jplag.options.Verbosity.PARSER;
import static jplag.options.Verbosity.QUIET;

import java.io.BufferedReader;
Expand All @@ -10,6 +9,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -18,6 +18,7 @@

import jplag.options.JPlagOptions;
import jplag.options.LanguageOption;
import jplag.options.Verbosity;
import jplag.strategy.ComparisonStrategy;
import jplag.strategy.NormalComparisonStrategy;
import jplag.strategy.ParallelComparisonStrategy;
Expand Down Expand Up @@ -134,28 +135,14 @@ public boolean isFileExcluded(File file) {

@Override
public void print(String message, String longMessage) {
if (options.getVerbosity() == PARSER) {
if (longMessage != null) {
System.out.println(longMessage);
} else if (message != null) {
System.out.println(message);
}
}
if (options.getVerbosity() == QUIET) {
return;
}
try {
Verbosity verbosity = options.getVerbosity();
if (verbosity != QUIET) {
if (message != null) {
System.out.print(message);
}

if (longMessage != null) {
if (options.getVerbosity() == LONG) {
System.out.print(longMessage);
}
if (longMessage != null && verbosity == LONG) {
System.out.print(longMessage);
}
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}

Expand Down Expand Up @@ -444,7 +431,7 @@ private void readExclusionFile() {
excludedFileNames = new HashSet<>();

try {
BufferedReader reader = new BufferedReader(new FileReader(options.getExclusionFileName()));
BufferedReader reader = new BufferedReader(new FileReader(options.getExclusionFileName(), StandardCharsets.UTF_8));
String line;

while ((line = reader.readLine()) != null) {
Expand Down
12 changes: 4 additions & 8 deletions jplag/src/main/java/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.List;
import java.util.Vector;

import jplag.options.Verbosity;

/**
* Represents a single submission. A submission can contain multiple files.
*/
Expand Down Expand Up @@ -123,11 +121,9 @@ private String[] getRelativeFilePaths(File baseFile, List<File> files) {

/* parse all the files... */
public boolean parse() {
if (program.getOptions().getVerbosity() != Verbosity.PARSER) {
if (files == null || files.size() == 0) {
program.print("ERROR: nothing to parse for submission \"" + name + "\"\n", null);
return false;
}
if (files == null || files.size() == 0) {
program.print("ERROR: nothing to parse for submission \"" + name + "\"\n", null);
return false;
}

String[] relativeFilePaths = getRelativeFilePaths(submissionFile, files);
Expand Down Expand Up @@ -209,7 +205,7 @@ public char[][] readFilesChar(String[] files) throws jplag.ExitException {
int size = (int) file.length();
char[] buffer = new char[size];

FileReader reader = new FileReader(file);
FileReader reader = new FileReader(file, StandardCharsets.UTF_8);

if (size != reader.read(buffer)) {
System.out.println("Not right size read from the file, " + "but I will still continue...");
Expand Down
5 changes: 1 addition & 4 deletions jplag/src/main/java/jplag/options/Verbosity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package jplag.options;

public enum Verbosity { // TODO TS: These levels are not used consistently.
PARSER,
public enum Verbosity {
QUIET,
LONG;

public static Verbosity fromOption(String optionName) {
switch (optionName) {
case "parser":
return PARSER;
case "quiet":
return QUIET;
case "long":
Expand Down
3 changes: 2 additions & 1 deletion jplag/src/main/java/jplag/reporting/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -651,7 +652,7 @@ private void writeMatchesCSV(String fileName) {

try {
csvFile.createNewFile();
writer = new FileWriter(csvFile);
writer = new FileWriter(csvFile, StandardCharsets.UTF_8);

for (JPlagComparison comparison : comparisons) {
String submissionNameA = comparison.getFirstSubmission().name;
Expand Down
3 changes: 2 additions & 1 deletion jplag/src/test/java/jplag/VolumeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void volumeComparisonTest() throws ExitException, IOException {
}

private Map<String, Float> readCSVResults(String filePathAndName) throws IOException {
List<String> lines = Files.readAllLines(Path.of(filePathAndName));
List<String> lines = Files.readAllLines(Path.of(filePathAndName), StandardCharsets.UTF_8);
var results = new HashMap<String, Float>();

lines.forEach(line -> {
Expand Down