From 2a9de4d7b2f053f55efea8f58f236850ae1bac28 Mon Sep 17 00:00:00 2001 From: Jack Forden <60225273+JForden@users.noreply.github.com> Date: Wed, 28 Feb 2024 17:17:58 -0600 Subject: [PATCH] Change Java to compiled language to facilitate multi-file Currently, Piston does not support multi-file Java submissions This change turns Java into a compiled language, while still maintaining the flexibility of single file submissions. --- packages/java/15.0.2/compile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/java/15.0.2/compile diff --git a/packages/java/15.0.2/compile b/packages/java/15.0.2/compile new file mode 100644 index 0000000..9e3a8db --- /dev/null +++ b/packages/java/15.0.2/compile @@ -0,0 +1,34 @@ +#!/bin/bash + +# Check if exactly one argument is provided +if [ $# -eq 1 ]; then + mv $1 $1.java + filename=$1.java + shift + java $filename "$@" +else + # Initialize an empty array to hold the filenames + declare -a javaFiles + + # Loop through each argument + for file in "$@"; do + # Check if the file already ends with .java + if [[ "$file" == *.java ]]; then + # If it does, add it directly to the array + javaFiles+=("$file") + else + # If it doesn't, add .java extension then add to the array + javaFiles+=("${file}.java") + fi + done + + # Compile all Java files at once + javac "${javaFiles[@]}" + + # Run the compiled Java classes + # Assuming the first argument is the main class file to run + # Remove .java extension from the main class name if present + mainClass="${1%.java}" + # Execute the main class + java "$mainClass" +fi