Skip to content

Commit 5e201c7

Browse files
authored
Merge pull request #2439 from jplag/feature/suffix-extension-conflict
Enforce consistent terminology regarding file extensions
2 parents 2a44d4e + 1d1f86c commit 5e201c7

File tree

50 files changed

+148
-127
lines changed

Some content is hidden

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

50 files changed

+148
-127
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ Parameter descriptions:
113113
against.
114114
-r, --result-file=<resultFile>
115115
Name of the file in which the comparison results will
116-
be stored (default: results). Missing .jplag endings
117-
will be automatically added.
116+
be stored (default: results). Missing .jplag
117+
extension will be automatically added.
118118
-t, --min-tokens=<minTokenMatch>
119119
Tunes the comparison sensitivity by adjusting the
120120
minimum token required to be counted as a matching

cli/src/main/java/de/jplag/cli/CLI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class CLI {
3131
private static final String DEFAULT_FILE_EXTENSION = ".jplag";
3232
private static final int NAME_COLLISION_ATTEMPTS = 4;
3333

34-
private static final String OUTPUT_FILE_EXISTS = "The output file (also with suffixes e.g. results(1).jplag) already exists. You can use --overwrite to overwrite the file.";
34+
private static final String OUTPUT_FILE_EXISTS = "The output file already exists. You can use --overwrite to overwrite the file.";
3535
private static final String OUTPUT_FILE_NOT_WRITABLE = "The output file (%s) cannot be written to.";
3636

3737
private static final String ZIP_FILE_EXTENSION = ".zip";

cli/src/main/java/de/jplag/cli/options/CliOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class CliOptions implements Runnable {
5050
public int shownComparisons = JPlagOptions.DEFAULT_SHOWN_COMPARISONS;
5151

5252
@Option(names = {"-r",
53-
"--result-file"}, description = "Name of the file in which the comparison results will be stored (default: ${DEFAULT-VALUE}). Missing .jplag endings will be automatically added.")
53+
"--result-file"}, description = "Name of the file in which the comparison results will be stored (default: ${DEFAULT-VALUE}). Missing .jplag extension will be automatically added.")
5454
public String resultFile = "results";
5555

5656
@Option(names = {"-M",

cli/src/main/java/de/jplag/cli/server/ContentType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public String getValue() {
2626
}
2727

2828
/**
29-
* Guesses the type from the given path using the suffix after the last '.'.
29+
* Guesses the type from the given path using the extension after the last dot.
3030
* @param path The path to guess from
3131
* @return The guessed type
3232
*/
3333
public static ContentType fromPath(String path) {
34-
String suffix = path.substring(path.lastIndexOf('.'));
34+
String extension = path.substring(path.lastIndexOf('.'));
3535
for (ContentType value : ContentType.values()) {
36-
if (suffix.equals(value.nameSuffix)) {
36+
if (extension.equals(value.nameSuffix)) {
3737
return value;
3838
}
3939
}

cli/src/test/java/de/jplag/cli/FileExtensionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
55

66
import java.io.IOException;
7-
import java.util.Arrays;
87
import java.util.List;
98

109
import org.junit.jupiter.api.Test;
@@ -22,7 +21,7 @@ class FileExtensionTest extends CliTest {
2221
void testDefaultExtensions() throws IOException, ExitException {
2322
JPlagOptions options = runCliForOptions();
2423

25-
List<String> expectedExtensions = Arrays.asList(new JavaLanguage().suffixes());
24+
List<String> expectedExtensions = new JavaLanguage().fileExtensions();
2625
assertIterableEquals(expectedExtensions, options.fileSuffixes());
2726
}
2827

cli/src/test/java/de/jplag/cli/LanguageTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

55
import java.io.IOException;
6-
import java.util.Arrays;
76
import java.util.Collection;
87
import java.util.List;
98

@@ -49,7 +48,7 @@ void testValidLanguages(Language language) throws ExitException, IOException {
4948
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.LANGUAGE, language.getIdentifier()));
5049

5150
assertEquals(language.getIdentifier(), options.language().getIdentifier());
52-
assertEquals(Arrays.asList(language.suffixes()), options.fileSuffixes());
51+
assertEquals(language.fileExtensions(), options.fileSuffixes());
5352
}
5453

5554
@Test

core/src/main/java/de/jplag/SubmissionSetBuilder.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private Optional<Submission> loadBaseCode() throws ExitException {
167167
throw new BasecodeException("Exclude submission: " + baseCodeSubmissionDirectory.getName());
168168
}
169169
if (baseCodeSubmissionDirectory.isFile() && !hasValidSuffix(baseCodeSubmissionDirectory)) {
170-
throw new BasecodeException("Ignore submission with invalid suffix: " + baseCodeSubmissionDirectory.getName());
170+
throw new BasecodeException("Ignore submission with invalid extension or suffix: " + baseCodeSubmissionDirectory.getName());
171171
}
172172

173173
Submission baseCodeSubmission = processSubmission(baseCodeSubmissionDirectory.getName(), baseCodeSubmissionDirectory, false);
@@ -233,7 +233,7 @@ private void processSubmissionFile(SubmissionFileData file, boolean multipleRoot
233233
if (isFileExcluded(file.submissionFile())) {
234234
logger.error("Exclude submission: {}", file.submissionFile().getName());
235235
} else if (file.submissionFile().isFile() && !hasValidSuffix(file.submissionFile())) {
236-
logger.error("Ignore submission with invalid suffix: {}", file.submissionFile().getName());
236+
logger.error("Ignore submission with invalid extension or suffix: {}", file.submissionFile().getName());
237237
} else {
238238
String rootDirectoryPrefix = multipleRoots ? file.rootDirectory().getName() + File.separator : "";
239239
String submissionName = rootDirectoryPrefix + file.submissionFile().getName();
@@ -243,9 +243,9 @@ private void processSubmissionFile(SubmissionFileData file, boolean multipleRoot
243243
}
244244

245245
/**
246-
* Checks if a file has a valid suffix for the current language.
246+
* Checks if a file has a valid file extension for the current language or ends in a specified suffix.
247247
* @param file is the file to check.
248-
* @return true if the file suffix matches the language.
248+
* @return true if the file matches the file extension or suffix.
249249
*/
250250
private boolean hasValidSuffix(File file) {
251251
List<String> validSuffixes = options.fileSuffixes();
@@ -265,7 +265,8 @@ private boolean isFileExcluded(File file) {
265265
}
266266

267267
/**
268-
* Recursively scan the given directory for nested files. Excluded files and files with an invalid suffix are ignored.
268+
* Recursively scan the given directory for nested files. Excluded files and files with an invalid extension or suffix
269+
* are ignored.
269270
* <p>
270271
* If the given file is not a directory, the input will be returned as a singleton list.
271272
* @param file - File to start the scan from.

core/src/main/java/de/jplag/options/JPlagOptions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.BufferedReader;
44
import java.io.File;
55
import java.io.IOException;
6-
import java.util.Arrays;
76
import java.util.Collections;
87
import java.util.List;
98
import java.util.Optional;
@@ -35,7 +34,7 @@
3534
* @param baseCodeSubmissionDirectory Directory containing the base code.
3635
* @param subdirectoryName Example: If the subdirectoryName is 'src', only the code inside submissionDir/src of each
3736
* submission will be used for comparison.
38-
* @param fileSuffixes List of file suffixes that should be included.
37+
* @param fileSuffixes List of file extensions or custom suffixes that should be included.
3938
* @param exclusionFileName Name of the file that contains the names of files to exclude from comparison.
4039
* @param similarityMetric The similarity metric determines how the minimum similarity threshold required for a
4140
* comparison (of two submissions) is calculated. This affects which comparisons are stored and thus make it into the
@@ -113,7 +112,7 @@ public Set<String> excludedFiles() {
113112
public List<String> fileSuffixes() {
114113
var language = language();
115114
if ((fileSuffixes == null || fileSuffixes.isEmpty()) && language != null) {
116-
return Arrays.stream(language.suffixes()).toList();
115+
return language.fileExtensions();
117116
}
118117
return fileSuffixes == null ? null : Collections.unmodifiableList(fileSuffixes);
119118
}

core/src/main/java/de/jplag/reporting/reportobject/ReportObjectFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void copySubmissionFilesToReport(JPlagResult result) {
133133
}
134134

135135
private File getFileToCopy(Language language, File file) {
136-
return language.useViewFiles() ? new File(file.getPath() + language.viewFileSuffix()) : file;
136+
return language.useViewFiles() ? new File(file.getPath() + language.viewFileExtension()) : file;
137137
}
138138

139139
private void writeComparisons(JPlagResult result) {

docs/1.-How-to-Use-JPlag.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Parameter descriptions:
4848
against.
4949
-r, --result-file=<resultFile>
5050
Name of the file in which the comparison results will
51-
be stored (default: results). Missing .jplag endings
52-
will be automatically added.
51+
be stored (default: results). Missing .jplag
52+
extension will be automatically added.
5353
-t, --min-tokens=<minTokenMatch>
5454
Tunes the comparison sensitivity by adjusting the
5555
minimum token required to be counted as a matching

0 commit comments

Comments
 (0)