diff -r 125c427b7a42 netx/net/sourceforge/jnlp/config/Defaults.java --- a/netx/net/sourceforge/jnlp/config/Defaults.java Thu Feb 14 15:48:21 2013 -0500 +++ b/netx/net/sourceforge/jnlp/config/Defaults.java Fri Feb 22 09:45:06 2013 +0100 @@ -384,6 +384,12 @@ DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS, null, null + }, + //JVM executable for itw + { + DeploymentConfiguration.KEY_JRE_DIR, + null, + null } }; diff -r 125c427b7a42 netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java --- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Thu Feb 14 15:48:21 2013 -0500 +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java Fri Feb 22 09:45:06 2013 +0100 @@ -162,6 +162,7 @@ * JVM arguments for plugin */ public static final String KEY_PLUGIN_JVM_ARGUMENTS= "deployment.plugin.jvm.arguments"; + public static final String KEY_JRE_DIR= "deployment.jre.dir"; public enum ConfigType { System, User @@ -174,6 +175,10 @@ private File systemPropertiesFile = null; /** The user's deployment.config file */ private File userPropertiesFile = null; + + /*default user file*/ + public static final File USER_FILE = new File(System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR + + File.separator + DEPLOYMENT_PROPERTIES); /** the current deployment properties */ private Map> currentConfiguration; @@ -206,8 +211,7 @@ */ public void load(boolean fixIssues) throws ConfigurationException { // make sure no state leaks if security check fails later on - File userFile = new File(System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR - + File.separator + DEPLOYMENT_PROPERTIES); + File userFile = new File(USER_FILE.getAbsolutePath()); SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -400,8 +404,25 @@ return etcFile; } - File jreFile = new File(System.getProperty("java.home") + File.separator + "lib" - + File.separator + DEPLOYMENT_CONFIG); + String jrePath = null; + try { + Map> tmpProperties = parsePropertiesFile(USER_FILE); + Setting jreSetting = tmpProperties.get(KEY_JRE_DIR); + if (jreSetting != null) { + jrePath = jreSetting.getValue(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + + File jreFile; + if (jrePath != null) { + jreFile = new File(jrePath + File.separator + "lib" + + File.separator + DEPLOYMENT_CONFIG); + } else { + jreFile = new File(System.getProperty("java.home") + File.separator + "lib" + + File.separator + DEPLOYMENT_CONFIG); + } if (jreFile.isFile()) { return jreFile; } diff -r 125c427b7a42 netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java --- a/netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java Thu Feb 14 15:48:21 2013 -0500 +++ b/netx/net/sourceforge/jnlp/controlpanel/JVMPanel.java Fri Feb 22 09:45:06 2013 +0100 @@ -40,8 +40,18 @@ import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JTextField; @@ -50,31 +60,99 @@ @SuppressWarnings("serial") public class JVMPanel extends NamedBorderPanel { - private DeploymentConfiguration config; + + private DeploymentConfiguration config; + private File lastPath = new File("/usr/lib/jvm/java/jre/"); + private final JVMPanel self; JVMPanel(DeploymentConfiguration config) { super(Translator.R("CPHeadJVMSettings"), new GridBagLayout()); this.config = config; addComponents(); + self=this; } private void addComponents() { - JLabel description = new JLabel("" + Translator.R("CPJVMPluginArguments") + "
"); - JTextField testFieldArguments = new JTextField(25); + final JLabel description = new JLabel("" + Translator.R("CPJVMPluginArguments") + "
"); + final JTextField testFieldArguments = new JTextField(25); testFieldArguments.getDocument().addDocumentListener(new DocumentAdapter(config, DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS)); testFieldArguments.setText(config.getProperty(DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS)); + + + final JLabel descriptionExec = new JLabel("" + Translator.R("CPJVMPluginExec") + "
"); + final JTextField testFieldArgumentsExec = new JTextField(25); + + testFieldArgumentsExec.getDocument().addDocumentListener(new DocumentAdapter(config, DeploymentConfiguration.KEY_JRE_DIR)); + testFieldArgumentsExec.setText(config.getProperty(DeploymentConfiguration.KEY_JRE_DIR)); + + final JButton selectJvm = new JButton( Translator.R("CPJVMPluginSelectExec")); + final JLabel validationResult = new JLabel(resetValidationResult(testFieldArgumentsExec.getText(),"","CPJVMnone")); + selectJvm.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser jfch; + if (lastPath != null && lastPath.exists()){ + jfch = new JFileChooser(lastPath); + } else { + jfch = new JFileChooser(); + } + jfch.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int i = jfch.showOpenDialog(self); + if (i == JFileChooser.APPROVE_OPTION && jfch.getSelectedFile()!=null){ + lastPath=jfch.getSelectedFile().getParentFile(); + String nws = jfch.getSelectedFile().getAbsolutePath(); + String olds = testFieldArgumentsExec.getText(); + if (!nws.equals(olds)){ + validationResult.setText(resetValidationResult(testFieldArgumentsExec.getText(),"","CPJVMnone")); + } + testFieldArgumentsExec.setText(nws); + } + + } + + }); + final JButton validateJvm = new JButton( Translator.R("CPJVMPluginExecValidation") ); + validateJvm.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + String s = validateJvm(testFieldArgumentsExec.getText()); + validationResult.setText(resetValidationResult(testFieldArgumentsExec.getText(),s,"CPJVMvalidated")); + + } + + }); // Filler to pack the bottom of the panel. GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1; + c.gridwidth = 2; c.gridx = 0; c.gridy = 0; + c.insets = new Insets(2, 2, 4, 4); this.add(description, c); c.gridy++; this.add(testFieldArguments, c); + c.gridy++; + this.add(descriptionExec, c); + c.gridy++; + this.add(testFieldArgumentsExec, c); + c.gridy++; + GridBagConstraints cb1 = (GridBagConstraints) c.clone(); + cb1.fill = GridBagConstraints.NONE; + cb1.gridwidth = 1; + this.add(selectJvm, cb1); + GridBagConstraints cb2 = (GridBagConstraints) c.clone(); + cb2.fill = GridBagConstraints.NONE; + cb2.gridx = 1; + cb2.gridwidth = 1; + this.add(validateJvm, cb2); + c.gridy++; + this.add(validationResult, c); // This is to keep it from expanding vertically if resized. Component filler = Box.createRigidArea(new Dimension(1, 1)); @@ -82,4 +160,88 @@ c.weighty++; this.add(filler, c); } + + private static String validateJvm(String cmd) { + if (cmd == null || cmd.trim().equals("")){ + return ""+Translator.R("CPJVMvalueNotSet")+""; + } + String procesString=""; + File jreDirFile = new File (cmd); + if (jreDirFile.isDirectory()) { + procesString+=""+Translator.R("CPJVMisDir")+"
"; + }else{ + procesString+=""+Translator.R("CPJVMnotDir")+"
"; + } + File javaFile = new File (cmd+File.separator+"bin"+File.separator+"java"); + if (javaFile.isFile()) { + procesString+=""+Translator.R("CPJVMjava")+"
"; + }else{ + procesString+=""+Translator.R("CPJVMnoJava")+"
"; + } + File rtFile = new File (cmd+File.separator+"lib"+File.separator+"rt.jar"); + if (javaFile.isFile()) { + procesString+=""+Translator.R("CPJVMrtJar")+"
"; + }else{ + procesString+=""+Translator.R("CPJVMnoRtJar")+"
"; + } + ProcessBuilder sb = new ProcessBuilder(javaFile.getAbsolutePath(), "-version"); + Process p = null; + String s1 =""; + String s2 = ""; + Integer r = null; + try { + p = sb.start(); + p.waitFor(); + s1 = inputToHtmlString(p.getErrorStream()); + s2 = inputToHtmlString(p.getInputStream()); + r = p.exitValue(); + System.err.println(s1); + System.out.println(s2); + s1=s1.toLowerCase(); + s2=s2.toLowerCase(); + } catch (Exception ex) {; + ex.printStackTrace(); + + } + if (r == null){ + return procesString+""+Translator.R("CPJVMnotLaunched")+""; + } + if (r.intValue()!=0){ + return procesString+""+Translator.R("CPJVMnoSuccess")+""; + } + if (s1.contains("openjdk") || s2.contains("openjdk")){ + return procesString+""+Translator.R("CPJVMopenJdkFound")+"" ; + } + if (s1.contains("oracle") || s2.contains("oracle")){ + return procesString+""+Translator.R("CPJVMoracleFound")+"" ; + } + if (s1.contains("ibm") || s2.contains("ibm")){ + return procesString+""+Translator.R("CPJVMibmFound")+""; + } + if (s1.contains("gij") || s2.contains("gij")){ + return procesString+""+Translator.R("CPJVMgijFound")+""; + } + return procesString+""+Translator.R("CPJVMstrangeProcess")+""; + + } + + private static String inputToHtmlString(InputStream stream) throws IOException { + InputStreamReader is = new InputStreamReader(stream); + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(is); + while (true) { + String read = br.readLine(); + if (read == null) { + break; + } + sb.append(read); + + } + + return sb.toString(); + } + + private String resetValidationResult(final String value, String result, String headerKey) { + return "" + Translator.R(headerKey) + ":
"+value+"
"+result+"
"; + } } diff -r 125c427b7a42 netx/net/sourceforge/jnlp/resources/Messages.properties --- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Feb 14 15:48:21 2013 -0500 +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Fri Feb 22 09:45:06 2013 +0100 @@ -301,6 +301,25 @@ CPDebuggingDescription=Enable options here to help with debugging CPDesktopIntegrationDescription=Set whether or not to allow creation of desktop shortcut. CPJVMPluginArguments=Set JVM arguments for plugin. +CPJVMPluginExec=Set JVM for icedtea-web +CPJVMPluginExecValidation=Validate JVM for icedtea-web +CPJVMPluginSelectExec=Select JVM for icedtea-web +CPJVMnone=None validation result for +CPJVMvalidated=Validation result for +CPJVMvalueNotSet=Value is not set. Hardcoded JVM will be used +CPJVMnotLaunched=Error, process was not launched, see console outputs for more info +CPJVMnoSuccess=Error, process have not ended successfully, see output for details, but your java is not set correctly +CPJVMopenJdkFound=Excellent, OpenJDK detected +CPJVMoracleFound=Great, Oracle java detected +CPJVMibmFound=Good, IBM java detected +CPJVMgijFound=Warning, gij detected +CPJVMstrangeProcess=Your path is executable process, but was not recognized. Ensure yourself in console output +CPJVMnotDir=You must set directory +CPJVMisDir=Is directory +CPJVMnoJava=Must contains bin/java +CPJVMjava=Contains bin/java +CPJVMnoRtJar=Do not contains lib/rt.jar +CPJVMrtJar=Do contains lib/rt.jar # Control Panel - Buttons CPButAbout=About...