From 6d1215702642518fcc3001eebd8cd9fa6c742912 Mon Sep 17 00:00:00 2001 From: Jakub Tarnawski Date: Wed, 30 Jul 2014 01:51:11 +0200 Subject: [PATCH] Made it possible to run programs in Java by adding (1) option to skip checking existence of executable file and (2) instructions on Java configuration. --- Hightail/src/org/hightail/Config.java | 9 ++++ .../src/org/hightail/ui/ConfigJDialog.form | 46 +++++++++------- .../src/org/hightail/ui/ConfigJDialog.java | 53 +++++++++++-------- .../src/org/hightail/ui/ProblemJPanel.form | 12 +++-- .../src/org/hightail/ui/ProblemJPanel.java | 43 ++++++++------- 5 files changed, 98 insertions(+), 65 deletions(-) diff --git a/Hightail/src/org/hightail/Config.java b/Hightail/src/org/hightail/Config.java index 28b724e..8375c00 100644 --- a/Hightail/src/org/hightail/Config.java +++ b/Hightail/src/org/hightail/Config.java @@ -33,6 +33,7 @@ static protected void fillInUnsetValuesWithDefaults() { setIfUnset("pathFromWorkingDirToExec", "%P.exe"); // TODO: if under Unix, this better be "%L" setIfUnset("prependingCommand", ""); + setIfUnset("checkExistence", "1"); } static public boolean load() { @@ -57,4 +58,12 @@ static public void save() throws IOException { static public boolean isPrependingCommandNonempty() { return !Config.get("prependingCommand").trim().isEmpty(); } + + public static boolean getBoolean(String key) { + return !get(key).equals("0"); + } + + public static void setBoolean(String key, boolean value) { + set(key, value ? "1" : "0"); + } } diff --git a/Hightail/src/org/hightail/ui/ConfigJDialog.form b/Hightail/src/org/hightail/ui/ConfigJDialog.form index dbd16f4..340bc57 100644 --- a/Hightail/src/org/hightail/ui/ConfigJDialog.form +++ b/Hightail/src/org/hightail/ui/ConfigJDialog.form @@ -1,13 +1,12 @@ -
+ - @@ -45,8 +44,8 @@ - - + + @@ -85,20 +84,20 @@ - - - - - - - + + + + + + + @@ -115,24 +114,24 @@ - - - + - - - + + + + + @@ -181,14 +180,21 @@ - + - + + + + + - + + + + diff --git a/Hightail/src/org/hightail/ui/ConfigJDialog.java b/Hightail/src/org/hightail/ui/ConfigJDialog.java index adc8dc4..342e712 100644 --- a/Hightail/src/org/hightail/ui/ConfigJDialog.java +++ b/Hightail/src/org/hightail/ui/ConfigJDialog.java @@ -39,6 +39,8 @@ public ConfigJDialog(JFrame parent) { pathFromWorkingDirToExecTextField.setText(Config.get("pathFromWorkingDirToExec")); prependingCommandTextField.setText(Config.get("prependingCommand")); + + checkExistenceCheckBox.setSelected(Config.getBoolean("checkExistence")); } /** This method is called from within the constructor to @@ -61,8 +63,8 @@ private void initComponents() { jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); prependingCommandTextField = new javax.swing.JTextField(); - jSeparator2 = new javax.swing.JSeparator(); - jSeparator1 = new javax.swing.JSeparator(); + checkExistenceCheckBox = new javax.swing.JCheckBox(); + jLabel4 = new javax.swing.JLabel(); saveButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); @@ -94,7 +96,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLabel2.setText("Command to prepend the executable with:"); - jLabel3.setText("Leave it empty for C++ (i.e. if the executable is standalone). Nonempty examples: \"java\", \"python\""); + jLabel3.setText("Leave it empty for C++ (i.e. if the executable is standalone). Nonempty example: \"python\""); + + checkExistenceCheckBox.setSelected(true); + checkExistenceCheckBox.setText("Check whether executable file exists before execution"); + + jLabel4.setText("Setup tips for Java: let's say you keep the main class of your compiled solution to problem B at \"d:\\algo\\taskB\\Main.class\". In this case you want to execute \"java -classpath d:\\algo\\taskB Main\", so you should set the working directory to \"d:\\algo\", path from working directory to executable to \"task%P Main\" and the prepending command to \"java -classpath\". If you had just \"d:\\algo\\Main.class\", you would need to set the path from working directory to executable to \" Main\" (note the space at the beginning).
You must also uncheck \"check whether executable file exists\"."); javax.swing.GroupLayout pathsAndDirectoriesPanelLayout = new javax.swing.GroupLayout(pathsAndDirectoriesPanel); pathsAndDirectoriesPanel.setLayout(pathsAndDirectoriesPanelLayout); @@ -114,17 +121,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(pathFromWorkingDirToExecLabel) .addGap(10, 10, 10) .addComponent(pathFromWorkingDirToExecTextField)) - .addComponent(jSeparator2) - .addComponent(jSeparator1) - .addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup() - .addComponent(jLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(prependingCommandTextField)) + .addComponent(checkExistenceCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup() .addGroup(pathsAndDirectoriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) - .addComponent(jLabel3)) - .addGap(0, 0, Short.MAX_VALUE))) + .addComponent(jLabel3) + .addGroup(pathsAndDirectoriesPanelLayout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(prependingCommandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addContainerGap()) ); pathsAndDirectoriesPanelLayout.setVerticalGroup( @@ -137,22 +144,22 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(workingDirectoryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(workingDirectoryBrowseButton) .addComponent(workingDirectoryLabel)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(1, 1, 1) + .addGap(18, 18, 18) .addGroup(pathsAndDirectoriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(pathFromWorkingDirToExecLabel) .addComponent(pathFromWorkingDirToExecTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pathFromWorkingDirToExecLabel2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGap(18, 18, 18) .addGroup(pathsAndDirectoriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(prependingCommandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) + .addGap(18, 18, 18) + .addComponent(checkExistenceCheckBox) + .addGap(18, 18, 18) + .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -188,8 +195,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() - .addComponent(pathsAndDirectoriesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(pathsAndDirectoriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(saveButton) .addComponent(cancelButton)) @@ -228,6 +235,9 @@ private boolean unsavedChanges() { if (!Config.get("prependingCommand").equals(prependingCommandTextField.getText())) { return true; } + if (Config.getBoolean("checkExistence") != checkExistenceCheckBox.isSelected()) { + return true; + } return false; } @@ -262,6 +272,7 @@ private void save() { Config.set("workingDirectory", workingDirectoryTextField.getText()); Config.set("pathFromWorkingDirToExec", pathFromWorkingDirToExecTextField.getText()); Config.set("prependingCommand", prependingCommandTextField.getText()); + Config.setBoolean("checkExistence", checkExistenceCheckBox.isSelected()); try { Config.save(); JOptionPane.showMessageDialog(this, "The configuration file has been saved."); @@ -288,11 +299,11 @@ private void workingDirectoryBrowseButtonActionPerformed(java.awt.event.ActionEv // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; + private javax.swing.JCheckBox checkExistenceCheckBox; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; - private javax.swing.JSeparator jSeparator1; - private javax.swing.JSeparator jSeparator2; + private javax.swing.JLabel jLabel4; private javax.swing.JLabel pathFromWorkingDirToExecLabel; private javax.swing.JLabel pathFromWorkingDirToExecLabel2; private javax.swing.JTextField pathFromWorkingDirToExecTextField; diff --git a/Hightail/src/org/hightail/ui/ProblemJPanel.form b/Hightail/src/org/hightail/ui/ProblemJPanel.form index a093eaf..e8b362f 100644 --- a/Hightail/src/org/hightail/ui/ProblemJPanel.form +++ b/Hightail/src/org/hightail/ui/ProblemJPanel.form @@ -68,12 +68,12 @@ - + - + @@ -91,8 +91,10 @@ - - + + + + @@ -152,7 +154,7 @@ - + diff --git a/Hightail/src/org/hightail/ui/ProblemJPanel.java b/Hightail/src/org/hightail/ui/ProblemJPanel.java index c17ec11..b133c41 100644 --- a/Hightail/src/org/hightail/ui/ProblemJPanel.java +++ b/Hightail/src/org/hightail/ui/ProblemJPanel.java @@ -114,7 +114,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - deleteTestcaseButton.setText("
Delete
test case
"); + deleteTestcaseButton.setText("
Delete
"); deleteTestcaseButton.setEnabled(false); deleteTestcaseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -170,12 +170,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(editTestcaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(deleteTestcaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(deleteTestcaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(copyInputButton, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(saveTestsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 196, Short.MAX_VALUE) .addComponent(runTestsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(abortCurrentTestButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -191,8 +191,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(testcasePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(saveTestsButton) - .addComponent(copyInputButton) + .addGroup(testcasePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(saveTestsButton) + .addComponent(copyInputButton)) .addComponent(deleteTestcaseButton) .addComponent(editTestcaseButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(newTestcaseButton) @@ -406,21 +407,25 @@ protected void runTests() { } final String pathToExecFile = sourceFile.getText(); File execFile = new File(pathToExecFile); - if (!execFile.exists()) { - // executable file does not exist - JOptionPane.showMessageDialog(this, "Executable file does not exist.", "Wrong file", JOptionPane.ERROR_MESSAGE); - return; - } - if (execFile.isDirectory()) { - // file path points to a directory, not a file - JOptionPane.showMessageDialog(this, "Selected path to executable is a directory.", "Wrong file", JOptionPane.ERROR_MESSAGE); - return; + + if (Config.getBoolean("checkExistence")) { + if (!execFile.exists()) { + // executable file does not exist + JOptionPane.showMessageDialog(this, "Executable file does not exist.", "Wrong file", JOptionPane.ERROR_MESSAGE); + return; + } + if (execFile.isDirectory()) { + // file path points to a directory, not a file + JOptionPane.showMessageDialog(this, "Selected path to executable is a directory.", "Wrong file", JOptionPane.ERROR_MESSAGE); + return; + } + if (!Config.isPrependingCommandNonempty() && !execFile.canExecute()) { + // application cannot execute this file + JOptionPane.showMessageDialog(this, "Executable file cannot be executed.", "Wrong file", JOptionPane.ERROR_MESSAGE); + return; + } // TODO: if Config.isPrependingCommandNonempty(), then do this check for the prepending command itself } - if (!Config.isPrependingCommandNonempty() && !execFile.canExecute()) { - // application cannot execute this file - JOptionPane.showMessageDialog(this, "Executable file cannot be executed.", "Wrong file", JOptionPane.ERROR_MESSAGE); - return; - } // TODO: if Config.isPrependingCommandNonempty(), then do this check for the prepending command itself + if (problem.getTestcaseSet().isEmpty()) { // no tests JOptionPane.showMessageDialog(this, "No tests to run.", "No tests", JOptionPane.ERROR_MESSAGE);