Skip to content

Commit

Permalink
Travis support (#25)
Browse files Browse the repository at this point in the history
* Add travis file
* Solve travis issues
  • Loading branch information
Benedikt Schneider authored May 23, 2019
1 parent 13bf076 commit b1b166d
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 57 deletions.
113 changes: 113 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This is the language of our project.
language: php

# If using Behat, then this should be true due to an issue with Travis CI.
# If not using Behat, recommended to use `sudo: false` as it is faster.
sudo: true

# Installs the required version of Firefox for Behat, an updated version
# of PostgreSQL and extra APT packages. Java 8 is only required
# for Mustache command.
addons:
firefox: "47.0.1"
postgresql: "9.4"
apt:
packages:
- openjdk-8-jre-headless

# Cache NPM's and Composer's caches to speed up build times.
cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm

# Determines which versions of PHP to test our project against. Each version
# listed here will create a separate build and run the tests against that
# version of PHP.
php:
- 7.1
- 7.2
- 7.3

# This section sets up the environment variables for the build.
env:
global:
# This line determines which version of Moodle to test against.
- MOODLE_BRANCH=MOODLE_36_STABLE
- MOODLE_BRANCH=MOODLE_37_STABLE
# This matrix is used for testing against multiple databases. So for
# each version of PHP being tested, one build will be created for each
# database listed here.
matrix:
- DB=pgsql
- DB=mysqli

# This lists steps that are run before the installation step.
before_install:
# This disables XDebug which should speed up the build.
- phpenv config-rm xdebug.ini
# This installs NodeJS which is used by Grunt, etc.
- nvm install 8.9
- nvm use 8.9
# Currently we are inside of the clone of your repository. We move up two
# directories to build the project.
- cd ../..
# Install this project into a directory called "ci".
- composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2
# Update the $PATH so scripts from this project can be called easily.
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"

# This lists steps that are run for installation and setup.
install:
# Run the default install. The overview of what this does:
# - Clone the Moodle project into a directory called moodle.
# - Create a data directory called moodledata.
# - Create Moodle config.php, database, etc.
# - Copy your plugin(s) into Moodle.
# - Run Composer install within Moodle.
# - Run NPM install in Moodle and in your plugin if it has a "package.json".
# - Run "grunt ignorefiles" within Moodle to update ignore file lists.
# - If your plugin has Behat features, then Behat will be setup.
# - If your plugin has unit tests, then PHPUnit will be setup.
- moodle-plugin-ci install

# This lists steps that are run for the purposes of testing. Any of
# these steps can be re-ordered or removed to your liking. And of
# course, you can add any of your own custom steps.
script:
# This step lints your PHP files to check for syntax errors.
- moodle-plugin-ci phplint
# This step runs the PHP Copy/Paste Detector on your plugin.
# This helps to find code duplication.
- moodle-plugin-ci phpcpd
# This step runs the PHP Mess Detector on your plugin. This helps to find
# potential problems with your code which can result in
# refactoring opportunities.
- moodle-plugin-ci phpmd
# This step runs the Moodle Code Checker to make sure that your plugin
# conforms to the Moodle coding standards. It is highly recommended
# that you keep this step.
- moodle-plugin-ci codechecker
# This step runs some light validation on the plugin file structure
# and code. Validation can be plugin specific.
- moodle-plugin-ci validate
# This step validates your plugin's upgrade steps.
- moodle-plugin-ci savepoints
# This step validates the HTML and Javascript in your Mustache templates.
- moodle-plugin-ci mustache
# This step runs Grunt tasks on the plugin. By default, it tries to run
# tasks relevant to your plugin and Moodle version, but you can run
# specific tasks by passing them as options,
# EG: moodle-plugin-ci grunt -t task1 -t task2
- moodle-plugin-ci grunt -t eslint:amd -t uglify:amd
# This step runs the PHPUnit tests of your plugin. If your plugin has
# PHPUnit tests, then it is highly recommended that you keep this step.
- moodle-plugin-ci phpunit
# This step runs the Behat tests of your plugin. If your plugin has
# Behat tests, then it is highly recommended that you keep this step.
# There are two important options that you may want to use:
# - The auto rerun option allows you to rerun failures X number of times,
# default is 2, EG usage: --auto-rerun 3
# - The dump option allows you to print the failure HTML to the console,
# handy for debugging, EG usage: --dump
- moodle-plugin-ci behat
5 changes: 0 additions & 5 deletions coursesetting/course_selection_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use Leafo\ScssPhp\Node\Number;

defined('MOODLE_INTERNAL') || die('Access to internal script forbidden');

require_once($CFG->dirroot.'/lib/formslib.php');
Expand Down Expand Up @@ -73,8 +71,6 @@ public function __construct($page=1, $category=0, $name='') {
* @see moodleform::definition()
*/
protected function definition() {
global $DB;

$courses = $this->course_search($totalnum);
$mform = $this->_form;

Expand All @@ -98,7 +94,6 @@ protected function definition() {

$nextlink = '';
$islastpage = ($this->page * PAGE_SIZE) >= $totalnum;
$page = $this->page;
if (!$islastpage) {
$nextlink = html_writer::link('', get_string('next'), array('class' => 'changepagelink', 'page' => $this->page + 1));
}
Expand Down
4 changes: 2 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function xmldb_plagiarism_programming_upgrade($oldversion = 0) {
$dbman->rename_field($table, $field, 'cmid');
}

// No need to call upgrade at this point since the next if will surely run.
upgrade_plugin_savepoint(true, 2012062001, 'plagiarism', 'programming');
}

if ($oldversion < 2012062900) {
Expand Down Expand Up @@ -227,7 +227,7 @@ function xmldb_plagiarism_programming_upgrade($oldversion = 0) {
}

// Programming savepoint reached.
upgrade_plugin_savepoint(true, 2012062001, 'plagiarism', 'programming');
upgrade_plugin_savepoint(true, 2012062900, 'plagiarism', 'programming');
}

if ($oldversion < 2012120700) {
Expand Down
16 changes: 3 additions & 13 deletions jplag/jplag_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* @copyright 2015 thanhtri, 2019 Benedikt Schneider (@Nullmann)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use Leafo\ScssPhp\Node\Number;
defined('MOODLE_INTERNAL') || die('Access to internal script forbidden');

require_once(__DIR__ . '/../utils.php');
Expand Down Expand Up @@ -62,8 +61,6 @@ public function __construct($cmid) {
* Parses the input to the jplag format, I guess.
*/
public function parse() {
global $DB;

$directory = dirname($this->filename);

$dom = new DOMDocument();
Expand Down Expand Up @@ -132,14 +129,6 @@ public function get_similar_parts() {

$this->parse_similar_parts($pair->student1_id, $pair->student2_id, $file0, $similarityarray, $filearray);
$this->parse_similar_parts($pair->student2_id, $pair->student1_id, $file1, $similarityarray, $filearray);

/* Only used for debugging.
if (!debugging()) {
unlink($file);
unlink($file0);
unlink($file1);
}
*/
}
$this->save_code($filearray, $similarityarray, $path);
}
Expand Down Expand Up @@ -309,11 +298,12 @@ private function mark_similarity(&$content, $similarities) {
// Mark in the reverse order so that it does not affect the char count if two marks are on the same line.
foreach ($similarities as $position) {
$anchor = implode(',', $position['anchor']);
$studentid = implode(',', $position['student']);
$studid = implode(',', $position['student']);
$color = implode(',', $position['color']);
$type = $position['type'];
$line = $lines[$position['line'] - 1];
$line = substr($line, 0, $position['char'] - 1)."<span sid='$studentid' anchor='$anchor' type='$type' color='$color'></span>".substr($line, $position['char'] - 1);
$line = substr($line, 0, $position['char'] - 1)
."<span sid='$studid' anchor='$anchor' type='$type' color='$color'></span>".substr($line, $position['char'] - 1);
$lines[$position['line'] - 1] = $line;
}
$content = implode("\n", $lines);
Expand Down
4 changes: 3 additions & 1 deletion jplag/jplag_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class jplag_stub{
* @param String $proxyuser
* @param String $proxypass
*/
public function __construct($username = null, $password = null, $proxyhost = null, $proxyport = null, $proxyuser = null, $proxypass = null) {
public function __construct($username = null, $password = null, $proxyhost = null,
$proxyport = null, $proxyuser = null, $proxypass = null) {

$proxyparam = array();
if (!empty($proxyhost) && !empty($proxyport)) {
$proxyparam['proxy_host'] = $proxyhost;
Expand Down
11 changes: 6 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct() {
* @param object $context - current context
* @param string $modulename - Name of the module
*/
public function get_form_elements_module($mform, $context, $modulename='') {
public function get_form_elements_module($mform, $context, $modulename = '') {
global $DB, $PAGE;

// When updating an assignment, cmid of the assignment is passed by "update" param.
Expand Down Expand Up @@ -257,7 +257,7 @@ public function save_form_elements($data) {
}

// Either save in *_jplag or *_moss table.
foreach ($detectiontools as $toolname => $info) {
foreach ($detectiontools as $toolname) {
if ($setting->$toolname && !$DB->get_record('plagiarism_programming_'.$toolname,
array('settingid' => $setting->id))) {

Expand Down Expand Up @@ -460,7 +460,8 @@ public function update_status($course, $cm) {
}

// Add link to MOSS / stanford.
$content .= '<a target="_blank" href='.$scanninginfo->resultlink.'>'.get_string('stanford_link', 'plagiarism_programming').'</a> <br>';
$content .= '<a target="_blank" href='.$scanninginfo->resultlink.'>'
.get_string('stanford_link', 'plagiarism_programming').'</a> <br>';

// Get user's preferred language to transform time string.
setlocale(LC_TIME, $USER->lang);
Expand Down Expand Up @@ -548,8 +549,8 @@ public function is_plugin_enabled($cmid, $courseid=null) {
return false;
}

$plagiarismprogrammingsetting = (array) get_config('plagiarism_programming');
if ($plagiarismprogrammingsetting['level_enabled'] == 'global') { // Globally enabled.
$programmingsettings = (array) get_config('plagiarism_programming');
if ($programmingsettings['level_enabled'] == 'global') { // Globally enabled.
return true;
}

Expand Down
9 changes: 0 additions & 9 deletions moss/moss_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public function __construct($cmid) {
* Parses the index file of the report and populate the record in plagiarism_programming_reslt table.
*/
public function parse() {
global $DB;

$content = file_get_contents($this->filename);
// This pattern extract the link.
$pattern = '/<A HREF=\"(match[0-9]*\.html)\">([^\/]*)\/\s\(([0-9]*)%\)<\/A>/';
Expand Down Expand Up @@ -118,13 +116,6 @@ public function get_similar_parts() {

$this->parse_similar_parts($pair->student1_id, $pair->student2_id, $file0, $similarityarray);
$this->parse_similar_parts($pair->student2_id, $pair->student1_id, $file1, $similarityarray);

/* Only used for debugging.
if (!debugging()) {
unlink($file0);
unlink($file1);
}
*/
}
$this->save_similarity($similarityarray);
}
Expand Down
2 changes: 1 addition & 1 deletion moss/moss_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function download_result($url, $downloaddir, $handler = null) {
*/
private function calculate_total_size(&$filelist) {
$totalsize = 0;
foreach ($filelist as $path => $file) {
foreach ($filelist as $path) {
$totalsize += filesize($path);
}
return $totalsize;
Expand Down
3 changes: 1 addition & 2 deletions plagiarism_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ protected function definition() {
$mform->addElement('html', html_writer::tag('div', get_string('account_instruction', 'plagiarism_programming')));
*/

/*
Jplag is currently not supported!
/* Jplag is currently not supported!
$mform->addElement('header', 'jplag_config', get_string('jplag', 'plagiarism_programming'));
$jplag_link = html_writer::link('https://www.ipd.uni-karlsruhe.de/jplag/', ' https://www.ipd.uni-karlsruhe.de/jplag/');
Expand Down
2 changes: 1 addition & 1 deletion programming_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}

if (! scanning_in_progress($assignmentconfig)) { // Reset the scanning.
foreach ($detectiontools as $toolname => $toolinfo) {
foreach ($detectiontools as $toolname) {
if ($assignmentconfig->$toolname) {
$toolstatus = $DB->get_record('plagiarism_programming_' . $toolname, array(
'settingid' => $assignmentconfig->id
Expand Down
17 changes: 12 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ Copyright: 2019 Benedikt Schneider (@Nullmann), 2014 Tri (@thantri)

License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

# Revived and reworked version
This plugin was forked from @thantri and last updated 5 years ago.
In the meantime, the jplag-service was discontinued.
As such, there will be legacy code left behind.
# Moodle-Plagiarism_Programming [![Build Status](https://travis-ci.org/Nullmann/moodle-plagiarism_programming.svg?branch=travis_support)](https://travis-ci.org/Nullmann/moodle-plagiarism_programming)

The second big change is that there is no course selection in the settings anymore. It is replaced by plugin-specific capabilities.
## Revived and reworked version
This plugin was forked from @thantri who last updated it 5 years ago. There are two major changes made to the plugin:

1) The jplag-service was discontinued. As such, this feature was dropped and only moss is supported. The jplag-code is still there, but commented out.

2) There is no course selection in the settings anymore. It is replaced by plugin-specific capabilities.

## 1. Registering a MOSS account
The plugin relies on MOSS engine in the background to carry out the scanning for similarity.
Expand Down Expand Up @@ -48,6 +50,11 @@ Go to Site Administrator → Plugin → Plagiarism Prevention → Programming As
* Enable this plugin globally or for specific courses.
* MOSS Userid: the userid emailed to you when registered for MOSS. If you find it difficult to locate the userid in that email. Just copy the entire email to the textbox below (you need either find the user id or copy the email. You don't need to do both)

### 5.2.1 Capabilites
There are 3 new capabilites for this plugins: Change settings (in submission settings), trigger manual scan and mark pair (as suspicious or normal).

The standard settings are pretty conservative, only allowing teachers and managers to have alle rights. You probably want to give non-editing teachers the mark pairs-capability.

## 6. Assignment settings
Once the plugin is enabled, users will see the 'Source code plagiarism detection' block when creating or editing an assignment.

Expand Down
4 changes: 2 additions & 2 deletions reportlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function plagiarism_programming_create_chart($reportid, $similaritytype) {
* @param Number $courseid
*/
function plagiarism_programming_create_student_lookup_table(&$resulttable, $isteacher, &$studentnames, $courseid) {
global $USER, $DB;
global $USER;

$studentnames = array();
if ($isteacher) {
Expand Down Expand Up @@ -346,7 +346,7 @@ function plagiarism_programming_get_students_similarity_info($cmid, $studid = nu
));
// Get the latest report version.
$reports = array();
foreach ($detectiontools as $toolname => $toolinfo) {
foreach ($detectiontools as $toolname) {
if ($setting->$toolname) {
$report = plagiarism_programming_get_latest_report($cmid, $toolname);
if ($report) {
Expand Down
2 changes: 1 addition & 1 deletion scan_after_extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
require_once(__DIR__.'/../../config.php');
require_once(__DIR__.'/scan_assignment.php');
require_once(__DIR__.'/detection_tools.php');
global $DB, $CFG;
global $DB;

/*
* This global is used to store the assignment currently processed
Expand Down
Loading

0 comments on commit b1b166d

Please sign in to comment.