Coder Social home page Coder Social logo

egbakou / marathon-compilers Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 3.0 100 KB

Compilation library for programming competitions. This library can be used to configure online compilers or to set up a platform for compiling and running programs during programming competitions.

License: Apache License 2.0

Shell 1.40% Java 98.60%
compilers interpreter marathon java-library timing maven-plugin shell-extension shell

marathon-compilers's Introduction

Marathon Compilers

Continuous Integration

Build Status

Quick Overview

This project was created to meet the need for compilation and execution of files during the programming contest we organized in our university, a competition in which there was a web application with several compilers compiling and running the files of participants. This project was based on the zt-exec project which allows to run external processes from Java. It provides several classes like JavaCompiler, PythonCompiler, GccCompiler, ... It is designed to be powerful but still easy to use.

Installation

Maven Central

The project artifacts are available in Maven Central Repository.

To include it in your maven project then you have to specify the dependency.

<dependency>
    <groupId>com.github.egbakou</groupId>
    <artifactId>marathon-compilers</artifactId>
    <version>1.1</version>
</dependency>

Motivation

There are many approaches to take when running external processes from Java. There are the JRE options such as the Runtime.exec() and ProcessBuilder. Also there is the Apache Commons Exec.

Some of the reasons for this library

  • Represent each compiler of the programming languages used by a class.
  • Return result after executing the uploded file
  • Reading/writing to streams
  • Redirecting stderr to stdout
  • Improved handling of timeouts
  • Improved checking of exit codes
  • Improved API
  • One liners for quite complex usecases
  • One liners to get process output into a String
  • Improved logging with SLF4J API
  • Support for multiple processes

Extension

This library can be used to configure online compilers or to set up a platform for compiling and running programs during programming competitions.

Download

You can download it by Git:

git clone https://github.com/egbakou/marathon-compilers.git

or download the archive.

Requirements

To use this library, you must install:

## =>Java
sudo apt-get install openjdk-8-jre openjdk-8-jdk
## configure JAVA_HOME
## Test installation: Main.java example
javac Main.java && java Main 
--------------------------------------------------
## =>Python
sudo apt-get install python3.6
## Test installation: problem1.py example
python problem1.py
--------------------------------------------------
## =>PHP CLI
sudo apt-get install php5-cli
## Test installation: file.php example
php file.php
--------------------------------------------------
## =>Free Pascal
sudo apt-get install fp-compiler-3.0.2
## Test installation: file.pass example
fpc file.pass
--------------------------------------------------
## =>C & C++ compiler
sudo apt-get install build-essential
gcc --version
sudo apt-get install manpages-dev man-db manpages-posix-dev
make -v
## Test installation: file.cpp example
g++ file.cpp -o file
--------------------------------------------------
## =>Javascript(nodejs)
sudo apt-get  install nodejs
## Test installation: file.js example
node file.js
--------------------------------------------------
## =>C# compiler
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt install mono-devel
## Test installation: hello.cs example
csc hello.cs
--------------------------------------------------
## =>Kotlin
curl -s https://get.sdkman.io | bash
sdk install kotlin
## Test installation: Problem1.kt example
kotlinc Problem1.kt -include-runtime -d hello.jar
java -jar Problem1.jar

This library also works on the Windows OS. For use on the Windows OS, install the equivalent compilers but provide the same compilation and execution commands as those in the example above. ๐Ÿ˜Š

You can also install the compilers and interpreters that you need only.

Example

Java compiler

  • Compile and Run java file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new JavaCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileAndRunInTiming("Main.java",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Compile java file without timing constraints (Runis not recommanded in competition contest; Read method documentation for details)
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new JavaCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileWithoutTiming("Main.java");

        System.out.println(out);

    }

Python interpreter

  • Run PYTHON file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

	String out = new PythonCompiler()
                .directory(new File("/home/laurent/Documents"))
                .runInTiming("p001.py",TimeUnit.SECONDS,3L);
                
	System.out.println(out);

    }
  • Method runWithoutTiming is also avialable for PythonCompiler class.

PHP interpreter

  • Run PHP file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

	String out = new PhpCompiler()
                .directory(new File("/home/laurent/Documents"))
                .runInTiming("euler1.php",TimeUnit.SECONDS,3L);

	System.out.println(out);

    }
  • Method runWithoutTiming is also avialable for PhpCompiler class.

JavaScript interpreter

  • Run Js file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new JsCompiler()
                .directory(new File("/home/laurent/Documents"))
                .runInTiming("index.js",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Method runWithoutTiming is also avialable for JsCompiler class.

C an C++ compiler

  • Compile and Run C or C++ file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new GccCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileAndRunInTiming("problem1.c",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Method compileAndRunWithoutTiming is also avialable for GccCompiler class.

Pascal compiler

  • Compile and Run file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new PascalCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileAndRunInTiming("euler1.pas",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Method compileAndRunWithoutTiming is also avialable for PascalCompiler class.

C# compiler

  • Compile and Run C# file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new CSharpCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileAndRunInTiming("euler1.cs",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Method compileAndRunWithoutTiming is also avialable for CSharpCompiler class.

Kotlin compiler

  • Compile and Run Kotlin file with timing constraints
  • Running with a timeout of 3 seconds
public static void main(String[] args) throws 
InterruptedException, IOException, TimeoutException {

        String out = new KotlinCompiler()
                .directory(new File("/home/laurent/Documents"))
                .compileAndRunInTiming("Problem001.kt",TimeUnit.SECONDS,3L);

        System.out.println(out);

    }
  • Method compileAndRunWithoutTiming is also avialable for KotlinCompiler class.

marathon-compilers's People

Contributors

egbakou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

marathon-compilers's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.