Skip to content

Commit

Permalink
Merge pull request #1122 from jplag/feature/reafactorLangaugeModules
Browse files Browse the repository at this point in the history
Changed all language class names and added READMEs where they where missing
  • Loading branch information
tsaglam authored Jul 10, 2023
2 parents 8a6e8ac + 1d88ece commit e5aeec5
Show file tree
Hide file tree
Showing 48 changed files with 171 additions and 86 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[![Report Viewer](https://img.shields.io/badge/report%20viewer-online-b80025)](https://jplag.github.io/JPlag/)
[![Java Version](https://img.shields.io/badge/java-SE%2017-yellowgreen)](#download-and-installation)


JPlag is a system that finds similarities among multiple sets of source code files. This way it can detect software plagiarism and collusion in software development. JPlag currently supports various programming languages, EMF metamodels, and natural language text.

## Supported Languages
Expand Down Expand Up @@ -167,7 +168,7 @@ The new API makes it easy to integrate JPlag's plagiarism detection into externa
<!-- To assure that the code example is always correct, it must be kept in sync
with [`ReadmeCodeExampleTest#testReadmeCodeExample`](core/src/test/java/de/jplag/special/ReadmeCodeExampleTest.java). -->
```java
Language language = new de.jplag.java.Language();
JavaLanguage language = new JavaLanguage();
language.getOptions(); //Use the object returned by this to set language options(same as language specific arguments above).
Set<File> submissionDirectories = Set.of(new File("/path/to/rootDir"));
File baseCode = new File("/path/to/baseCode");
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/de/jplag/cli/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.jplag.clustering.ClusteringAlgorithm;
import de.jplag.clustering.ClusteringOptions;
import de.jplag.clustering.algorithm.InterClusterSimilarity;
import de.jplag.java.JavaLanguage;
import de.jplag.options.JPlagOptions;
import de.jplag.options.SimilarityMetric;

Expand All @@ -16,7 +17,7 @@

@CommandLine.Command(name = "jplag", description = "", usageHelpAutoWidth = true, abbreviateSynopsis = true)
public class CliOptions implements Runnable {
public static final Language defaultLanguage = new de.jplag.java.Language();
public static final Language defaultLanguage = new JavaLanguage();

@Parameters(paramLabel = "root-dirs", description = "Root-directory with submissions to check for plagiarism%n", split = ",")
public File[] rootDirectory = new File[0];
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/de/jplag/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.stream.Collectors;

import de.jplag.exceptions.ExitException;
import de.jplag.java.JavaLanguage;
import de.jplag.options.JPlagOptions;

/**
Expand Down Expand Up @@ -104,7 +105,7 @@ protected JPlagOptions getOptions(List<String> newPaths, Function<JPlagOptions,
protected JPlagOptions getOptions(List<String> newPaths, List<String> oldPaths, Function<JPlagOptions, JPlagOptions> customization) {
var newFiles = newPaths.stream().map(File::new).collect(Collectors.toSet());
var oldFiles = oldPaths.stream().map(File::new).collect(Collectors.toSet());
JPlagOptions options = new JPlagOptions(new de.jplag.java.Language(), newFiles, oldFiles);
JPlagOptions options = new JPlagOptions(new JavaLanguage(), newFiles, oldFiles);
return customization.apply(options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.jplag.JPlagResult;
import de.jplag.Language;
import de.jplag.exceptions.ExitException;
import de.jplag.java.JavaLanguage;
import de.jplag.options.JPlagOptions;
import de.jplag.reporting.reportobject.ReportObjectFactory;

Expand All @@ -25,7 +26,7 @@ class ReadmeCodeExampleTest {
*/
@Test
void testReadmeCodeExample() {
Language language = new de.jplag.java.Language();
Language language = new JavaLanguage();
Set<File> submissionDirectories = Set.of(new File("/path/to/rootDir"));
File baseCode = new File("/path/to/baseCode");
JPlagOptions options = new JPlagOptions(language, submissionDirectories, Set.of()).withBaseCodeSubmissionDirectory(baseCode);
Expand Down
2 changes: 1 addition & 1 deletion docs/1.-How-to-Use-JPlag.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ The new API makes it easy to integrate JPlag's plagiarism detection into externa
**Example:**

```java
Language language = new de.jplag.java.Language();
JavaLanguage language = new JavaLanguage();
language.getOptions(); //Use this to set language specific options, same as language specific arguments above.
Set<File> submissionDirectories = Set.of(new File("/path/to/rootDir"));
File baseCode = new File("/path/to/baseCode");
Expand Down
68 changes: 68 additions & 0 deletions languages/csharp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CSharp langauge module

Extracts token from CSharp source using the ANTRL Grammar from the official [ANTLR repository](https://github.com/antlr/grammars-v4/tree/master/csharp)

## Tokens

- INVOCATION
- OBJECT_CREATION
- ARRAY_CREATION
- ASSIGNMENT
- FIELD
- CONSTANT
- LOCAL_VARIABLE
- IF
- SWITCH_BEGIN
- SWITCH_END
- CASE
- DO
- WHILE
- FOR
- FOREACH
- BREAK
- CONTINUE
- GOTO
- RETURN
- THROW
- CHECKED
- UNCHECKED
- LOCK
- USING
- TRY
- CATCH
- FINALLY
- NAMESPACE_BEGIN
- NAMESPACE_END
- USING_DIRECTIVE
- CLASS_BEGIN
- CLASS_END
- METHOD
- PROPERTY
- EVENT
- INDEXER
- OPERATOR
- CONSTRUCTOR
- DESTRUCTOR
- STRUCT_BEGIN
- STRUCT_END
- INTERFACE_BEGIN
- INTERFACE_END
- ENUM
- DELEGATE
- ATTRIBUTE
- IF_END
- UNSAFE
- FIXED
- METHOD_BEGIN
- METHOD_END
- STRUCT
- IF_BEGIN
- CLASS
- INTERFACE
- ENUM_BEGIN
- ENUM_END
- ENUMERAL
- ACCESSORS_BEGIN
- ACCESSORS_END
- ACCESSOR_BEGIN
- ACCESSOR_END
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @author Timur Saglam
*/
@MetaInfServices(de.jplag.Language.class)
public class Language implements de.jplag.Language {
public class CSharpLanguage implements de.jplag.Language {
private static final String NAME = "C# 6 Parser";
private static final String IDENTIFIER = "csharp";
private static final String[] FILE_ENDINGS = new String[] {".cs", ".CS"};
private static final int DEFAULT_MIN_TOKEN_MATCH = 8;

private final CSharpParserAdapter parser;

public Language() {
public CSharpLanguage() {
parser = new CSharpParserAdapter();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MinimalCSharpTest {

@BeforeEach
public void setUp() {
language = new Language();
language = new CSharpLanguage();
baseDirectory = BASE_PATH.toFile();
assertTrue(baseDirectory.exists(), "Could not find base directory!");
}
Expand Down
2 changes: 1 addition & 1 deletion languages/emf-metamodel-dynamic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This module is based on the EMF dependencies available on maven central. These m
For the token extraction, we visit the containment tree of the metamodel and extract tokens for all metamodel elements based on their concrete metaclass. In this module, we thus extract tokens based on a dynamic token set.

### Usage
To use this module, add the `-l emf-metamodel-dynamic` flag in the CLI, or use a `JPlagOption` object with `new de.jplag.emf.dynamic.Language()` as `language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).
To use this module, add the `-l emf-metamodel-dynamic` flag in the CLI, or use a `JPlagOption` object with `new DynamicEmfLanguage()` as `language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).

### More Info
More information can be found in the paper [*"Token-based Plagiarism Detection for Metamodels" (MODELS-C'22)*](https://dl.acm.org/doi/10.1145/3550356.3556508).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.jplag.emf.dynamic;

import de.jplag.emf.EmfLanguage;
import de.jplag.emf.dynamic.parser.DynamicEcoreParser;
import de.jplag.emf.parser.EcoreParser;

Expand All @@ -8,7 +9,7 @@
* created token set instead of a hand-picked one.
* @author Timur Saglam
*/
public class Language extends de.jplag.emf.Language { // currently not included in the CLI
public class DynamicEmfLanguage extends EmfLanguage { // currently not included in the CLI
private static final String NAME = "EMF metamodels (dynamically created token set)";
private static final String IDENTIFIER = "emf-dynamic";

Expand All @@ -17,14 +18,14 @@ public class Language extends de.jplag.emf.Language { // currently not included
/**
* Creates an EMF language instance with a dynamic token parser.
*/
public Language() {
public DynamicEmfLanguage() {
super(new DynamicEcoreParser());
}

/**
* Creates an EMF language instance with a custom token parser.
*/
public Language(EcoreParser parser) {
public DynamicEmfLanguage(EcoreParser parser) {
super(parser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MinimalDynamicMetamodelTest {

@BeforeEach
public void setUp() {
language = new Language();
language = new DynamicEmfLanguage();
baseDirectory = BASE_PATH.toFile();
FileUtil.assertDirectory(baseDirectory, TEST_SUBJECTS);
}
Expand All @@ -48,8 +48,8 @@ void testBookstoreMetamodels() throws ParsingException {
List<File> testFiles = Arrays.stream(TEST_SUBJECTS).map(path -> new File(BASE_PATH.toFile(), path)).toList();
List<Token> result = language.parse(new HashSet<>(testFiles));
List<TokenType> tokenTypes = result.stream().map(Token::getType).toList();
logger.debug(TokenPrinter.printTokens(result, baseDirectory, Optional.of(Language.VIEW_FILE_SUFFIX)));
logger.info("parsed token types: " + tokenTypes.stream().map(TokenType::getDescription).toList().toString());
logger.debug(TokenPrinter.printTokens(result, baseDirectory, Optional.of(DynamicEmfLanguage.VIEW_FILE_SUFFIX)));
logger.info("parsed token types: " + tokenTypes.stream().map(TokenType::getDescription).toList());
assertEquals(94, tokenTypes.size());
assertEquals(7, new HashSet<>(tokenTypes.stream().filter(DynamicMetamodelTokenType.class::isInstance).toList()).size());

Expand All @@ -64,6 +64,6 @@ void testBookstoreMetamodels() throws ParsingException {

@AfterEach
public void tearDown() {
FileUtil.clearFiles(new File(BASE_PATH.toString()), Language.VIEW_FILE_SUFFIX);
FileUtil.clearFiles(new File(BASE_PATH.toString()), DynamicEmfLanguage.VIEW_FILE_SUFFIX);
}
}
2 changes: 1 addition & 1 deletion languages/emf-metamodel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This module is based on the EMF dependencies available on maven central. These m
For the token extraction, we visit the containment tree of the metamodel and extract tokens for certain metamodel elements based on their metaclass. In this module, we extract tokens based on a [handcrafted token set](https://github.com/jplag/JPlag/blob/master/languages/emf-metamodel/src/main/java/de/jplag/emf/MetamodelTokenType.java). Note that not for all concrete metaclasses tokens are extracted. `EFactory`, `EGenericType`, and `EObject` are ignored. Moreover, for some metaclasses, multiple token types are extracted. Finally, some references are also used for token extraction.

### Usage
To use this module, add the `-l emf-metamodel` flag in the CLI, or use a `JPlagOption` object with `new de.jplag.emf.Language()` as `language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).
To use this module, add the `-l emf-metamodel` flag in the CLI, or use a `JPlagOption` object with `new EmfLanguage()` as `language` in the Java API as described in the usage information in the [readme of the main project](https://github.com/jplag/JPlag#usage) and [in the wiki](https://github.com/jplag/JPlag/wiki/1.-How-to-Use-JPlag).

### More Info
More information can be found in the paper [*"Token-based Plagiarism Detection for Metamodels" (MODELS-C'22)*](https://dl.acm.org/doi/10.1145/3550356.3556508).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Timur Saglam
*/
@MetaInfServices(de.jplag.Language.class)
public class Language implements de.jplag.Language {
public class EmfLanguage implements de.jplag.Language {
public static final String VIEW_FILE_SUFFIX = ".emfatic";
public static final String FILE_ENDING = "." + EcorePackage.eNAME;

Expand All @@ -26,11 +26,11 @@ public class Language implements de.jplag.Language {

protected final EcoreParser parser;

public Language() {
public EmfLanguage() {
this(new EcoreParser());
}

protected Language(EcoreParser parser) {
protected EmfLanguage(EcoreParser parser) {
this.parser = parser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import de.jplag.ParsingException;
import de.jplag.Token;
import de.jplag.TokenType;
import de.jplag.emf.Language;
import de.jplag.emf.EmfLanguage;
import de.jplag.emf.MetamodelToken;
import de.jplag.emf.normalization.ModelSorter;
import de.jplag.emf.util.AbstractMetamodelVisitor;
Expand Down Expand Up @@ -74,7 +74,7 @@ protected void parseModelFile(File file) throws ParsingException {
* @return the correct view file suffix for the model view. Can be overriden in subclasses for alternative views.
*/
protected String getCorrespondingViewFileSuffix() {
return Language.VIEW_FILE_SUFFIX;
return EmfLanguage.VIEW_FILE_SUFFIX;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public abstract class AbstractEmfTest {

@BeforeEach
protected void setUp() {
language = new Language();
language = new EmfLanguage();
baseDirectory = BASE_PATH.toFile();
FileUtil.assertDirectory(baseDirectory, TEST_SUBJECTS);
}

@AfterEach
protected void tearDown() {
FileUtil.clearFiles(new File(BASE_PATH.toString()), Language.VIEW_FILE_SUFFIX);
FileUtil.clearFiles(new File(BASE_PATH.toString()), EmfLanguage.VIEW_FILE_SUFFIX);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void testBookstoreMetamodels() throws ParsingException {
List<File> testFiles = Arrays.stream(TEST_SUBJECTS).map(path -> new File(BASE_PATH.toFile(), path)).toList();
List<Token> result = language.parse(new HashSet<>(testFiles));

logger.debug(TokenPrinter.printTokens(result, baseDirectory, Optional.of(Language.VIEW_FILE_SUFFIX)));
logger.debug(TokenPrinter.printTokens(result, baseDirectory, Optional.of(EmfLanguage.VIEW_FILE_SUFFIX)));
List<TokenType> tokenTypes = result.stream().map(Token::getType).toList();
logger.info("Parsed token types: " + tokenTypes.stream().map(TokenType::getDescription).toList().toString());
logger.info("Parsed token types: " + tokenTypes.stream().map(TokenType::getDescription).toList());
assertEquals(80, tokenTypes.size());
assertEquals(12, new HashSet<>(tokenTypes).size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import de.jplag.ParsingException;
import de.jplag.emf.AbstractEmfTest;
import de.jplag.emf.Language;
import de.jplag.emf.EmfLanguage;

class EmfaticModelViewTest extends AbstractEmfTest {

Expand All @@ -31,9 +31,9 @@ void testEmfaticViewFiles(String modelName) throws ParsingException {

// Generate emfatic view:
EmfaticModelView view = new EmfaticModelView(modelFile, modelResource);
view.writeToFile(Language.VIEW_FILE_SUFFIX);
view.writeToFile(EmfLanguage.VIEW_FILE_SUFFIX);

// Compare expected vs. actual view file:
assertViewFilesMatch(modelFile, Language.VIEW_FILE_SUFFIX, EXPECTED_VIEW_FOLDER);
assertViewFilesMatch(modelFile, EmfLanguage.VIEW_FILE_SUFFIX, EXPECTED_VIEW_FOLDER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.kohsuke.MetaInfServices;

import de.jplag.emf.dynamic.DynamicEmfLanguage;
import de.jplag.emf.model.parser.DynamicModelParser;

/**
Expand All @@ -14,13 +15,13 @@
* @author Timur Saglam
*/
@MetaInfServices(de.jplag.Language.class)
public class Language extends de.jplag.emf.dynamic.Language {
public class EmfModelLanguage extends DynamicEmfLanguage {
private static final String NAME = "EMF models (dynamically created token set)";
private static final String IDENTIFIER = "emf-model";

public static final String VIEW_FILE_SUFFIX = ".treeview";

public Language() {
public EmfModelLanguage() {
super(new DynamicModelParser());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import org.eclipse.emf.ecore.resource.Resource;

import de.jplag.ParsingException;
import de.jplag.emf.EmfLanguage;
import de.jplag.emf.dynamic.parser.DynamicEcoreParser;
import de.jplag.emf.model.Language;
import de.jplag.emf.model.EmfModelLanguage;
import de.jplag.emf.util.AbstractModelView;
import de.jplag.emf.util.EMFUtil;
import de.jplag.emf.util.MetamodelTreeView;
Expand All @@ -37,9 +38,9 @@ public DynamicModelParser() {
@Override
protected void parseModelFile(File file) throws ParsingException {
// implicit assumption: Metamodel gets parsed first!
if (file.getName().endsWith(de.jplag.emf.Language.FILE_ENDING)) {
if (file.getName().endsWith(EmfLanguage.FILE_ENDING)) {
parseMetamodelFile(file);
} else if (file.getName().endsWith(Language.VIEW_FILE_SUFFIX)) {
} else if (file.getName().endsWith(EmfModelLanguage.VIEW_FILE_SUFFIX)) {
logger.warn(VIEW_FILE_WARNING, file.getName());
} else {
if (metapackages.isEmpty()) {
Expand All @@ -51,7 +52,7 @@ protected void parseModelFile(File file) throws ParsingException {

@Override
protected String getCorrespondingViewFileSuffix() {
return Language.VIEW_FILE_SUFFIX;
return EmfModelLanguage.VIEW_FILE_SUFFIX;
}

@Override
Expand Down
Loading

0 comments on commit e5aeec5

Please sign in to comment.