Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Java to compiled language to facilitate multi-file #644

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/java/15.0.2/compile
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into a run script - compile should only ever compile the files.

Copy link
Author

@JForden JForden Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HexF

Is there a way to conditionally trigger a run/compile depending on how many files a user submits?

This workaround is necessary for single-file submissions, as currently, for single-file submissions:

  1. In piston, if a user uploads a .java filename that does not correspond to the classname it still compiles and runs.
    • This function would no longer work if this logic was removed, javac requires filenames to match classnames.

Is there a reason why we could not remove the run script and switch it to a compiled language, using the above logic scheme to maintain functionality of single file submissions?

fi