Skip to content

1. How to Use JPlag

tsaglam edited this page Feb 21, 2024 · 24 revisions

JPlag can be used via the Command Line Interface (CLI) or programmatically via the Java API.

Using JPlag via the CLI

JPlag can be used via the Command Line Interface by executing the JAR file.

Example: java -jar jplag.jar path/to/the/submissions

The language can either be set with the -l parameter or as a subcommand. If both a subcommand and the -l option are specified, the subcommand will take priority. When using the subcommand language specific arguments can be set. A list of language specific options can be obtained by requesting the help page of a subcommand (e.g. "jplag java -h").

The following arguments can be used to control JPlag:

Parameter descriptions: 
      [root-dirs[,root-dirs...]...]
                        Root-directory with submissions to check for plagiarism.
      -bc, --bc, --base-code=<baseCode>
                        Path to the base code directory (common framework used in all submissions).
  -l, --language=<language>
                        Select the language of the submissions (default: java). See subcommands below.
  -M, --mode=<{RUN, VIEW, RUN_AND_VIEW}>
                        The mode of JPlag: either only run analysis, only open the viewer, or do both (default: null)
  -n, --shown-comparisons=<shownComparisons>
                        The maximum number of comparisons that will be shown in the generated report, if set to -1 all comparisons will be shown (default: 500)
      -new, --new=<newDirectories>[,<newDirectories>...]
                        Root-directories with submissions to check for plagiarism (same as root).
      --normalize       Activate the normalization of tokens. Supported for languages: Java, C++.
      -old, --old=<oldDirectories>[,<oldDirectories>...]
                        Root-directories with prior submissions to compare against.
  -r, --result-file=<resultFile>
                        Name of the file in which the comparison results will be stored (default: results). Missing .zip endings will be automatically added.
  -t, --min-tokens=<minTokenMatch>
                        Tunes the comparison sensitivity by adjusting the minimum token required to be counted as a matching section. A smaller value increases the sensitivity but might lead to more
                          false-positives.

Advanced
      --csv-export      Export pairwise similarity values as a CSV file.
  -d, --debug           Store on-parsable files in error folder.
  -m, --similarity-threshold=<similarityThreshold>
                        Comparison similarity threshold [0.0-1.0]: All comparisons above this threshold will be saved (default: 0.0).
  -p, --suffixes=<suffixes>[,<suffixes>...]
                        comma-separated list of all filename suffixes that are included.
  -P, --port=<port>     The port used for the internal report viewer (default: 1996).
  -s, --subdirectory=<subdirectory>
                        Look in directories <root-dir>/*/<dir> for programs.
  -x, --exclusion-file=<exclusionFileName>
                        All files named in this file will be ignored in the comparison (line-separated list).

Clustering
      --cluster-alg, --cluster-algorithm=<{AGGLOMERATIVE, SPECTRAL}>
                        Specifies the clustering algorithm (default: spectral).
      --cluster-metric=<{AVG, MIN, MAX, INTERSECTION}>
                        The similarity metric used for clustering (default: average similarity).
      --cluster-skip    Skips the cluster calculation.

Subsequence Match Merging
      --gap-size=<maximumGapSize>
                        Maximal gap between neighboring matches to be merged (between 1 and minTokenMatch, default: 6).
      --match-merging   Enables merging of neighboring matches to counteract obfuscation attempts.
      --neighbor-length=<minimumNeighborLength>
                        Minimal length of neighboring matches to be merged (between 1 and minTokenMatch, default: 2).

Subcommands (supported languages):
  c
  cpp
  csharp
  emf
  emf-model
  go
  java
  javascript
  kotlin
  llvmir
  python3
  rlang
  rust
  scala
  scheme
  scxml
  swift
  text
  typescript

Note that the legacy CLI is varying slightly.

Using JPlag programmatically

The new API makes it easy to integrate JPlag's plagiarism detection into external Java projects.

Example:

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");
JPlagOptions options = new JPlagOptions(language, submissionDirectories, Set.of()).withBaseCodeSubmissionDirectory(baseCode);

try {
    JPlagResult result = JPlag.run(options);
     
    // Optional
    ReportObjectFactory reportObjectFactory = new ReportObjectFactory(new File("/path/to/output"));
    reportObjectFactory.createAndSaveReport(result, "/path/to/output");
} catch (ExitException e) {
    // error handling here
}

Report File Generation

After a JPlag run a zipped result report is automatically created. The target location of the report can be specified with the -r flag.

If the -r is not specified, the location defaults result.zip. Specifying the -r flag with a path /path/to/desiredFolder results in the report being created as /path/to/desiredFolder.zip.

Unless there is an error during the zipping process, the report will always be zipped. If the zipping process fails, the report will be available as unzipped under the specified location.

Viewing Reports

The newest version of the report viewer is always accessible at https://jplag.github.io/JPlag/. Simply drop your result.zip folder on the page to start inspecting the results of your JPlag run. Your submissions will neither be uploaded to a server nor stored permanently. They are saved in the application as long as you view them. Once you refresh the page, all information will be erased.

Basic Concepts

This section explains some fundamental concepts about JPlag that make it easier to understand and use.

  • Root directory: This is the directory in which JPlag will scan for submissions.
  • Submissions: Submissions contain the source code that JPlag will parse and compare. They have to be direct children of the root directory and can either be single files or directories.

Single-file submissions

/path/to/root-directory
├── Submission-1.java
├── ...
└── Submission-n.java

Directory submissions

JPlag will read submission directories recursively, so they can contain multiple (nested) source code files.

/path/to/root-directory
├── Submission-1
│   ├── Main.java
│   └── util
│       └── Utils.java
├── ...
└── Submission-n
    ├── Main.java
    └── util
        └── Utils.java

If you want JPlag to scan only one specific subdirectory of the submissions for source code files (e.g. src), can configure that with the argument -S:

/path/to/root-directory
├── Submission-1
│   ├── src                 
│   │   ├── Main.java       # Included
│   │   └── util            
│   │       └── Utils.java  # Included
│   ├── lib                 
│   │   └── Library.java    # Ignored
│   └── Other.java          # Ignored
└── ...

Base Code

The base code is a special kind of submission. It is the template that all other submissions are based on. JPlag will ignore all matches between two submissions, where the matches are also part of the base code. Like any other submission, the base code has to be a single file or directory in the root directory.

/path/to/root-directory
├── BaseCode
│   └── Solution.java
├── Submission-1
│   └── Solution.java
├── ...
└── Submission-n
    └── Solution.java

In this example, students have to solve a given problem by implementing the run method in the template below. Because they are not supposed to modify the main function, it will be identical for each student.

// BaseCode/Solution.java
public class Solution {

    // DO NOT MODIFY
    public static void main(String[] args) {
        Solution solution = new Solution();  
        solution.run();
    }
    
    public void run() {
        // TODO: Implement your solution here.
    }
}

To prevent JPlag from detecting similarities in the main function (and other parts of the template), we can instruct JPlag to ignore matches with the given base code by providing the --bc=<base-code-name> option. The <base-code-name> in the example above is BaseCode.

Multiple Root Directories

  • You can run JPlag with multiple root directories, JPlag compares submissions from all of them
  • JPlag distinguishes between old and new root directories ** Submissions in new root directories are checked amongst themselves and against submissions from other root directories ** Submissions in old root directories are only checked against submissions from other new root directories
  • You need at least one new root directory to run JPlag

This allows you to check submissions against those of previous years:

/path/to/root-new
└── ...
/path/to/root-old1
└── ...
/path/to/root-old2
└── ...

Details

The following diagram shows all the relations between root directories, submissions, and files:

classDiagram
    direction LR

    Input -->"1..*" RootDirectory : consists of
    RootDirectory
    RootDirectory <|-- NewDirectory: is a
    RootDirectory <|-- OldDirectory : is a
    
    
    RootDirectory --> "1..*" Submission : contains
    Directory --> "1..*" File : contains
    Submission <|-- File : is a
    Submission <|-- Directory : is a