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

Conversation

JForden
Copy link

@JForden JForden commented Feb 28, 2024

Pull Request: Enhance Java Support for Multi-File Submissions

Overview

This pull request aims to extend the functionality of our Java execution environment to support multi-file Java programs. Historically, our system has only supported single-file submissions, limiting the complexity and scope of projects that users can run. This update is a significant step towards accommodating more advanced Java applications and improving the versatility of our execution platform.

Goals

  • Primary Objective: Introduce multi-file support for Java submissions without impacting the existing support for single-file Java programs.
  • Maintain Compatibility: Ensure that single-file submissions continue to function as they have, even when the submitted .java file's name does not match the public class name.

Changes

1. Multi-File Support Implementation

  • New Compile File: Added a compile file to the Java package. This script leverages the existing Piston infrastructure to compile and execute multi-file Java programs. It automatically detects and compiles all .java files present in the request

2. Single File Submissions

  • No Changes for Single File: The process for single file submissions remains unchanged. Users can submit a .java file where the file name does not necessarily match the public class name, and it will continue to be supported seamlessly.

3. Multi-File Java Program Support

  • Main File Requirement: For multi-file submissions to be executed correctly, the "main" file containing the public static void main(String[] args) method must be the first file passed into the API. This ensures the correct entry point is identified and executed.

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.
@JForden
Copy link
Author

JForden commented Feb 28, 2024

Hi!

I talked about this pull request awhile ago with Hex who asked me to push it upstream. I'm only about a year late in actually getting to this, so it may not be something that is wanted/needed anymore.

@gouseferoz
Copy link

Hi!

I talked about this pull request awhile ago with Hex who asked me to push it upstream. I'm only about a year late in actually getting to this, so it may not be something that is wanted/needed anymore.

I think this feature is required. I am having a similar request in these lines, where i can be able to have a multi class single java file to execute. Currently it is not supported with piston.

@JForden
Copy link
Author

JForden commented Apr 12, 2024

Just a note!

I identified a minor bug with file passing, aka if you want to pass in a .txt file that a .java file should read from. I have resolved this issue and will commit changes soon.

# 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?

@sahar2339
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants