# HG changeset patch # User m-zytnicki # Date 1358517683 18000 # Node ID 86c78142123980a505eb2951eb466f427c6fd67a # Parent 769e306b7933da878bde0c4ddf9bfb5a116d3bc7 Deleted selected files diff -r 769e306b7933 -r 86c781421239 SMART/Java/File.java --- a/SMART/Java/File.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -public class File { - String name; - String formatType; - String format; - - - public File(String name, String type, String format) { - this.name = name; - this.formatType = type; - this.format = format; - } - - public String getName() { - return this.name; - } - - public String getFormatType() { - return this.formatType; - } - - public String getFormat() { - return this.format; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Files.java --- a/SMART/Java/Files.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class Files { - HashMap files; - - public Files () { - files = new HashMap < String, File> (); - } - - public void addFile(String fileName, String type, String format) { - this.addFile(new File(fileName, type, format)); - } - - public void addFile(File file) { - files.put(file.name, file); - } - - public void clear() { - files.clear(); - } - - public String getType(String fileName) { - if (fileName == null) { - System.out.println("Error! Looking for format of empty file name!"); - } - if (! files.containsKey(fileName)) { - System.out.println("Oops! Format type of file " + fileName + " is not found!"); - return null; - } - return files.get(fileName).formatType; - } - - public String getFormat(String fileName) { - if (fileName == null) { - System.out.println("Error! Looking for format of empty file name!"); - } - if (! files.containsKey(fileName)) { - System.out.println("Oops! Format of file " + fileName + " is not found!"); - return null; - } - return files.get(fileName).format; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/FormatType.java --- a/SMART/Java/FormatType.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class FormatType { - String type; - Vector < String > formats; - - public FormatType (String type) { - this.type = type; - this.formats = new Vector < String > (); - } - - public String getType () { - return this.type; - } - - public void addFormat (String format) { - formats.add(format); - } - - public boolean containsFormat (String format) { - for (int i = 0; i < formats.size(); i++) { - if (((String) formats.get(i)).compareToIgnoreCase(format) == 0) { - return true; - } - } - return false; - } - - public Vector < String > getFormats () { - return formats; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/FormatsContainer.java --- a/SMART/Java/FormatsContainer.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class FormatsContainer { - - HashMap < String, FormatType > formatTypes; - - - public FormatsContainer() { - this.formatTypes = new HashMap < String, FormatType > (); - } - - - public void addFormat(String type, String format) { - FormatType formatType; - if (formatTypes.containsKey(type)) { - formatType = this.formatTypes.get(type); - } - else { - formatType = new FormatType(type); - this.formatTypes.put(type, formatType); - } - formatType.addFormat(format); - } - - - public Vector < String > getFormatTypes () { - Vector < String > v = new Vector < String > (); - v.addAll(this.formatTypes.keySet()); - return v; - } - - - public FormatType getFormats (String type) { - if (! formatTypes.containsKey(type)) { - System.out.print("Format type " + type + " is unavailable. Got: "); - Iterator it = formatTypes.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry pairs = (Map.Entry) it.next(); - System.out.print(pairs.getKey() + " "); - } - System.out.println(); - } - return formatTypes.get(type); - } - - - public String getFormatType (String format) { - for (Iterator it = formatTypes.keySet().iterator(); it.hasNext(); ) { - Object type = it.next(); - Object formatType = formatTypes.get(type); - if (((FormatType) formatType).containsFormat(format)) { - return (String) type; - } - } - return null; - } -} - - diff -r 769e306b7933 -r 86c781421239 SMART/Java/FormatsReader.java --- a/SMART/Java/FormatsReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; - - -public class FormatsReader { - - String fileName; - Vector < FormatType > formatTypes; - Vector < String > typeNames; - - - public FormatsReader(String fileName) { - this.fileName = fileName; - this.formatTypes = new Vector < FormatType > (); - } - - - public boolean read() { - File file = new File(this.fileName); - - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = null; - String[] lineElements; - String[] formats; - String typeName; - - while ((line = reader.readLine()) != null) { - if (line.length() > 0) { - lineElements = line.split(":"); - typeName = lineElements[0].trim(); - formats = lineElements[1].split(","); - for (int i = 0; i < formats.length; i++) { - Global.formats.addFormat(typeName, formats[i].trim()); - } - } - } - - reader.close(); - } - catch (FileNotFoundException e) { - return false; - } - catch (IOException e) { - return false; - } - - return true; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Global.java --- a/SMART/Java/Global.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.Vector; -import java.util.HashMap; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JTextField; - -public class Global { - - public static int logAreaSize = 100; - - public static String smartConfFileName = "smart.conf"; - - public static String smartProgramsFileName = "programs.txt"; - - public static String smartFormatsFileName = "formats.txt"; - - public static String pythonPath = new String(); - - public static String pythonCommand = "python"; - - public static String mysqlCommand = "mysql"; - - public static String rCommand = "R"; - - public static Files files = new Files(); - - public static Vector < String > fileNames = new Vector < String >(); - - public static FormatsContainer formats = new FormatsContainer(); - - public static boolean programRunning = false; - - public static HashMap < JButton, JTextField > otherFilesChooser = new HashMap < JButton, JTextField >(); - - public static HashMap < JButton, JTextField > otherDirectoriesChooser = new HashMap < JButton, JTextField >(); - - public static HashMap < JButton, JTextField > otherFileConcatenationChooser = new HashMap < JButton, JTextField >(); - -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/Old/PasswordAsker.java --- a/SMART/Java/Installer/Old/PasswordAsker.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.concurrent.CountDownLatch; - -public class PasswordAsker { - - static String password; - static JFrame frame; - static CountDownLatch latch; - - - public PasswordAsker() { - password = null; - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - latch = new CountDownLatch(1); - } - - - private static void createAndShowGUI() { - //Create and set up the window. - frame = new JFrame("Password"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setContentPane(setMainPane()); - - //Display the window. - frame.pack(); - frame.setVisible(true); - } - - - private static JPanel setMainPane() { - JPanel rootPanel = new JPanel(false); - rootPanel.setLayout(new GridLayout(0, 1)); - - JPanel infoPanel = new JPanel(false); - JLabel infoLabel = new JLabel("Please write here the password that you entered for the mySQL root account.\r\nNo information is stored nor sent. I promise."); - infoPanel.add(infoLabel); - - JPanel passPanel = new JPanel(false); - passPanel.setLayout(new GridLayout(1, 0)); - JLabel passLabel = new JLabel("password"); - final JTextField passText = new JTextField(20); - passLabel.setLabelFor(passText); - passPanel.add(passLabel); - passPanel.add(passText); - - JPanel okPanel = new JPanel(false); - JButton okButton = new JButton("OK"); - okPanel.add(okButton); - - okButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - password = passText.getText(); - frame.setVisible(false); - frame.dispose(); - latch.countDown(); - } - }); - - rootPanel.add(infoPanel); - rootPanel.add(passPanel); - rootPanel.add(okPanel); - - return rootPanel; - } - - - public boolean waitForPassword() { - try { - latch.await(); - } - catch (InterruptedException e) { - return false; - } - return true; - } - - - public String getPassword() { - return password; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/Old/SmartInstaller.java --- a/SMART/Java/Installer/Old/SmartInstaller.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; -import java.net.*; - -public class SmartInstaller extends JPanel implements ActionListener { - int BUFFER = 1024; - - JFrame mainFrame; - JTextArea logArea; - - // configuration chooser buttons - String configurations[] = {"32 bits", "64 bits"}; - JRadioButton configurationButtons[]; - - // program chooser buttons - String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "MySQL", "MySQL account", "Python 2.6", "Python DB", "S-MART"}; - JCheckBox programChooserButtons[]; - - JButton goButton; - - // install directory - JButton installDirectoryChooserButton; - JTextField installDirectoryChooserTextField; - - - public SmartInstaller() { - super(); - - Box box = Box.createVerticalBox(); - - // Header - JPanel headerPanel = new JPanel(false); - JTextArea headerArea = new JTextArea("This is the S-MART installation tool.\r\nIt will download and install the needed softwares, as well as S-MART itself.\r\nYou can unselect the software that you already have installed.\r\nDuring the installation, accept all the default parameters.\r\nPlease remember the root password if you install MySQL!"); - TitledBorder headerBorder = BorderFactory.createTitledBorder("Wellcome to the S-MART installer!"); - headerArea.setEditable(false); - headerArea.setBackground(headerPanel.getBackground()); - headerPanel.add(headerArea); - headerPanel.setBorder(headerBorder); - - - // Configuration - JPanel configurationPanel = new JPanel(false); - configurationPanel.setLayout(new GridLayout(1, 0)); - configurationButtons = new JRadioButton[configurations.length]; - ButtonGroup configurationGroup = new ButtonGroup(); - for (int i = 0; i < configurations.length; i++) { - JRadioButton button = new JRadioButton(configurations[i]); - configurationPanel.add(button); - configurationButtons[i] = button; - configurationGroup.add(button); - } - configurationButtons[0].setSelected(true); - TitledBorder configurationBorder = BorderFactory.createTitledBorder("Configuration"); - configurationPanel.setBorder(configurationBorder); - - - // Program chooser panel - JPanel programPanel = new JPanel(false); - programPanel.setLayout(new GridLayout(0, 1)); - - JLabel programLabel = new JLabel("Choose which programs to install:"); - programPanel.add(programLabel); - programChooserButtons = new JCheckBox[programChoosers.length]; - for (int i = 0; i < programChoosers.length; i++) { - JCheckBox button = new JCheckBox(programChoosers[i]); - button.setSelected(true); - programPanel.add(button); - programChooserButtons[i] = button; - } - TitledBorder programBorder = BorderFactory.createTitledBorder("Programs"); - programPanel.setBorder(programBorder); - - // Install directory chooser - JPanel installDirectoryChooserPanel = new JPanel(false); - installDirectoryChooserPanel.setLayout(new GridLayout(1, 0)); - JLabel installDirectoryChooserLabel = new JLabel("Choose a directory to install S-MART: "); - installDirectoryChooserTextField = new JTextField(); - installDirectoryChooserButton = new JButton("Open..."); - installDirectoryChooserButton.addActionListener(this); - - installDirectoryChooserPanel.add(installDirectoryChooserLabel); - installDirectoryChooserPanel.add(installDirectoryChooserTextField); - installDirectoryChooserPanel.add(installDirectoryChooserButton); - TitledBorder installDirectoryChooserBorder = BorderFactory.createTitledBorder("Installation directory"); - installDirectoryChooserPanel.setBorder(installDirectoryChooserBorder); - - // GO! - JPanel goPanel = new JPanel(false); - goButton = new JButton("GO!"); - goButton.addActionListener(this); - goButton.setSelected(true); - goPanel.add(goButton); - TitledBorder goBorder = BorderFactory.createTitledBorder("Start install"); - goPanel.setBorder(goBorder); - - // Log - logArea = new JTextArea(10, 120); - logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize())); - JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - TitledBorder logBorder = BorderFactory.createTitledBorder("Log"); - logScroll.setBorder(logBorder); - - GridLayout horizontalLayout = new GridLayout(1, 0); - - box.add(headerPanel); - box.add(configurationPanel); - box.add(programPanel); - box.add(installDirectoryChooserPanel); - box.add(goPanel); - box.add(logScroll); - - add(box); - } - - - public void actionPerformed(ActionEvent e) { - - // Install directories chooser - if (e.getSource() == goButton) { - boolean[] selectedPrograms = new boolean[programChoosers.length]; - for (int i = 0; i < programChoosers.length; i++) { - selectedPrograms[i] = programChooserButtons[i].isSelected(); - } - SmartInstallerTask task = new SmartInstallerTask(logArea, selectedPrograms, installDirectoryChooserTextField.getText(), (configurationButtons[0].isSelected())? 0: 1); - task.execute(); - } - // Install directories chooser - else if (e.getSource() == installDirectoryChooserButton) { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - installDirectoryChooserTextField.setText(chooser.getSelectedFile().getPath()); - } - } - } - - private static void createAndShowGUI() { - // Create and set up the window. - JFrame mainFrame = new JFrame("S-Mart Installer"); - mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Create and set up the content pane. - JComponent newContentPane = new SmartInstaller(); - newContentPane.setOpaque(true); - mainFrame.setContentPane(newContentPane); - - // Display the window. - mainFrame.pack(); - mainFrame.setVisible(true); - } - - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/Old/SmartInstallerTask.java --- a/SMART/Java/Installer/Old/SmartInstallerTask.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,455 +0,0 @@ -import java.util.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; -import java.net.*; -import java.util.Stack; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class SmartInstallerTask extends SwingWorker { - - int BUFFER = 1024; - - int architecture = 0; - String installDirectoryName = null; - JTextArea logArea = null; - boolean[] selectedPrograms = null; - - // program chooser buttons - String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "MySQL", "MySQL account", "Python 2.6", "Python DB", "S-MART"}; - - // Web addresses for the tools - String packageAddresses[][] = { - {"http://cran.cict.fr/bin/windows/base/R-2.11.0-win32.exe", "http://cran.cict.fr/bin/windows64/base/R-2.11.0-win64.exe"}, - {"", ""}, - {"", ""}, - {"http://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-5.1/mysql-essential-5.1.47-win32.msi", "http://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-5.1/mysql-essential-5.1.47-winx64.msi"}, - {"", ""}, - {"http://www.python.org/ftp/python/2.6.5/python-2.6.5.msi", "http://www.python.org/ftp/python/2.6.5/python-2.6.5.amd64.msi"}, - {"http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe", "http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe"}, - {"http://urgi.versailles.inra.fr/download/s-mart/s-mart.zip", "http://urgi.versailles.inra.fr/download/s-mart/s-mart.zip"} - }; - - // Packages to install - String rPackages[] = {"RColorBrewer", "Hmisc"}; - - // Script lines - String scriptLines[][] = { - {"\"\\R-2.11.0-win32.exe\"", "\"\\R-2.11.0-win64.exe\""}, - {"\"\" CMD BATCH \"\\installRColorBrewer.R\"", "\"\" CMD BATCH \"\\installRColorBrewer.R\""}, - {"\"\" CMD BATCH \"\\installHmisc.R\"", "\"\" CMD BATCH \"\\installHmisc.R\""}, - {"msiexec /i \"\\mysql-essential-5.1.47-win32.msi\"", "msiexec /i \"\\mysql-essential-5.1.47-winx64.msi\""}, - {"", ""}, - {"msiexec /i \"\\python-2.6.5.msi\"", "msiexec /i \"\\python-2.6.5.amd64.msi\""}, - {"\\MySQL-python-1.2.2.win32-py2.6.exe", "\\MySQL-python-1.2.2.win32-py2.6.exe"}, - {"", ""} - }; - - // Files to uncompress - String compressedFiles[][] = { - {"", ""}, - {"", ""}, - {"", ""}, - {"", ""}, - {"", ""}, - {"", ""}, - {"", ""}, - {"\\s-mart.zip", "\\s-mart.zip"} - }; - - - public SmartInstallerTask(JTextArea ta, boolean[] b, String s, int a) { - logArea = ta; - selectedPrograms = b; - installDirectoryName = s; - architecture = a; - } - - - @Override - public Boolean doInBackground() { - boolean installOk; - publish("Starting install\n"); - writeFiles(); - for (int i = 0; i < selectedPrograms.length; i++) { - if (selectedPrograms[i]) { - if (! install(i)) { - return Boolean.FALSE; - } - } - } - removeFiles(); - setEnvironmentVariables(); - publish("Ending install\n"); - return Boolean.TRUE; - } - - - @Override - protected void process(List chunks) { - for (String chunk: chunks) { - logArea.append(chunk); - } - } - - - private boolean launch(String command) { - return realLaunch(new ProcessBuilder(command), command); - } - - private boolean launch(String[] command) { - return realLaunch(new ProcessBuilder(command), Arrays.toString(command)); - } - - private boolean realLaunch(ProcessBuilder pb, String command) { - BufferedReader outputReader; - pb = pb.redirectErrorStream(true); - Process process = null; - publish(" Starting command '" + command + "'\n"); - try { - process = pb.start(); - BufferedInputStream outputStream = new BufferedInputStream(process.getInputStream()); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - outputReader = new BufferedReader(isr); - } - catch (Exception exception) { - publish(" !Process cannot be started (command is '" + command + "')!\n"); - exception.printStackTrace(); - return false; - } - if (outputReader == null) { - publish(" !Problem in the output of the command!\n"); - return false; - } - else { - publish(" Output is:\n"); - try { - publish(" ---\n"); - String line; - while ((line = outputReader.readLine()) != null) { - publish(" " + line + "\r\n"); - } - publish(" ---\n"); - } - catch (IOException e) { - publish(" !Cannot get the output of the command!\n"); - return false; - } - } - int exitValue = process.exitValue(); - if (exitValue != 0) { - publish(" !Problem during the execution of the command '" + command + "'!\n"); - return false; - } - publish(" Ending command '" + command + "'\n"); - return true; - } - - - private File lookForFile(String fileName, String[] putativePlaces) { - publish(" Looking for file " + fileName + "\n"); - for (String place: putativePlaces) { - File file = new File(place, fileName); - publish(" Look at " + file.getAbsolutePath() + "\n"); - if (file.exists()) { - publish(" Found it in expected place " + file.getAbsolutePath() + "\n"); - return file; - } - } - Stack files = new Stack(); - files.push(new File("\\")); - while (! files.empty()) { - File file = files.pop(); - for (File childFile: file.listFiles()) { - if (childFile.isDirectory()) { - files.push(childFile); - } - else { - if (fileName.compareToIgnoreCase(childFile.getName()) == 0) { - publish(" Found it in unexpected place " + childFile.getAbsolutePath() + "\n"); - return childFile; - } - } - } - } - publish(" !Cannot file file '" + fileName + "'!\n"); - return null; - } - - - private boolean writeFile(String fileName, String content) { - try { - FileWriter fw = new FileWriter(fileName); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(content); - bw.close(); - fw.close(); - } - catch (Exception e) { - publish(" !Cannot write file '" + fileName + "'!\n"); - return false; - } - return true; - } - - - private boolean removeFile(String fileName) { - File file = new File(fileName); - if (file.exists()) { - if (! file.delete()) { - publish(" !Cannot delete file '" + file.getAbsolutePath() + "'!\n"); - return false; - } - } - return true; - } - - - private boolean writeFiles() { - for (String rPackage: rPackages) { - String fileName = installDirectoryName + File.separator + "install" + rPackage + ".R"; - String content = "install.packages(\"" + rPackage + "\", repos = \"http://cran.cict.fr\", dependencies = TRUE)\n"; - if (! writeFile(fileName, content)) { - publish(" !Cannot write file for R package '" + rPackage + "'!\n"); - return false; - } - } - String fileName = installDirectoryName + File.separator + "createUser.sql"; - String content = "CREATE USER 'smart'@'localhost';\nGRANT ALL PRIVILEGES ON *.* TO 'smart'@'localhost' WITH GRANT OPTION;\nCREATE DATABASE smart;\nGRANT ALL ON smart.* TO 'smart'@'localhost';\n"; - if (! writeFile(fileName, content)) { - publish(" !Cannot write mySQL configuration file!\n"); - return false; - } - return true; - } - - private boolean removeFiles() { - for (String rPackage: rPackages) { - File file = new File(installDirectoryName + File.separator + "install" + rPackage + ".R"); - if (! file.delete()) { - publish("!Cannot delete R install file for " + rPackage + "!\n"); - return false; - } - } - File file = new File(installDirectoryName + File.separator + "createUser.sql"); - if (! file.delete()) { - publish("!Cannot delete mySQL configuration file!\n"); - return false; - } - return true; - } - - private boolean install(int element) { - publish(" Starting install of " + programChoosers[element] + "\n"); - downloadPackage(element); - executeInstall(element); - uncompressPackage(element); - removePackage(element); - postProcess(element); - publish(" Ending install of " + programChoosers[element] + "\n"); - return true; - } - - - private String getLocalName(String remoteName) { - String localName = installDirectoryName + File.separator + (new File(remoteName)).getName(); - int position = localName.indexOf("?"); - if (position >= 0) { - localName = localName.substring(0, position); - } - return localName; - } - - - private boolean downloadPackage(int element) { - String fileName = packageAddresses[element][architecture]; - if (! "".equals(fileName)) { - publish(" Starting download of " + programChoosers[element] + "\n"); - try { - BufferedInputStream bis = new BufferedInputStream(new URL(fileName).openStream()); - FileOutputStream fos = new FileOutputStream(getLocalName(fileName)); - BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER); - byte[] data = new byte[BUFFER]; - int x = 0; - while((x = bis.read(data, 0, BUFFER)) >= 0) { - bos.write(data, 0, x); - } - bos.close(); - fos.close(); - bis.close(); - } - catch (IOException e) { - publish(" !Cannot download file '" + fileName + "'!\n"); - return false; - } - publish(" Ending download of " + programChoosers[element] + "\n"); - } - return true; - } - - - private String replaceSubstring(String line) { - if (line.contains("")) { - String protectedDirectory = installDirectoryName.replaceAll("\\\\", "\\\\\\\\"); - line = line.replaceAll("", protectedDirectory); - } - if (line.contains("")) { - String userName = System.getenv().get("USERNAME"); - String[] possibleRDirectories = {"C:\\Program Files\\R-2.11.0", "C:\\Documents and Settings\\" + userName + "\\Mes documents\\R\\R-2.11.0\\bin", "C:\\Documents and Settings\\" + userName + "\\My documents\\R\\R-2.11.0\\bin"}; - String rDirectory = lookForFile("'.exe", possibleRDirectories).getAbsolutePath(); - rDirectory = rDirectory.replaceAll("\\\\", "\\\\\\\\"); - line = line.replaceAll("", rDirectory); - } - if (line.contains("")) { - String userName = System.getenv().get("USERNAME"); - String[] possibleRDirectories = {"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin", "C:\\Documents and Settings\\" + userName + "\\Mes documents\\MySQL\\MySQL Server 5.1\\bin", "C:\\Documents and Settings\\" + userName + "\\My documents\\MySQL\\MySQL Server 5.1\\bin"}; - String rDirectory = lookForFile("mysql.exe", possibleRDirectories).getAbsolutePath(); - rDirectory = rDirectory.replaceAll("\\\\", "\\\\\\\\"); - line = line.replaceAll("", rDirectory); - } - return line; - } - - - private boolean executeInstall(int element) { - String commands = scriptLines[element][architecture]; - if (! "".equals(commands)) { - for (String command: commands.split(";")) { - command = replaceSubstring(command); - publish(" Starting command '" + command + "'\n"); - Process process = null; - try { - process = Runtime.getRuntime().exec(command); - } - catch (IOException e) { - publish(" !Cannot execute command '" + command + "'!\n"); - return false; - } - try { - process.waitFor(); - } - catch (InterruptedException e) { - publish(" !Cannot wait for the end of the command '" + command + "'!\n"); - return false; - } - int exitValue = process.exitValue(); - if (exitValue != 0) { - publish(" !Problem during the execution of the command '" + command + "'!\n"); - return false; - } - publish(" Ending command '" + command + "'\n"); - } - } - return true; - } - - - private boolean uncompressPackage(int element) { - String file = compressedFiles[element][architecture]; - if (! "".equals(file)) { - file = replaceSubstring(file); - publish(" Starting uncompressing file '" + file + "'\n"); - try { - FileInputStream fis = new FileInputStream(file); - BufferedInputStream bis = new BufferedInputStream(fis); - ZipInputStream zis = new ZipInputStream(bis); - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (! entry.isDirectory()) { - File newFile = new File(installDirectoryName + File.separator + entry.getName()); - // create parent directories - File upDirectory = newFile.getParentFile(); - while (upDirectory != null){ - if (! upDirectory.exists()) { - upDirectory.mkdir(); - publish(" Creating directory '" + upDirectory.getAbsolutePath() + "'\n"); - } - upDirectory = upDirectory.getParentFile(); - } - // write the files to the disk - publish(" Extracting '" + entry.getName() + "' to '" + newFile.getAbsolutePath() + "'\n"); - int count; - byte data[] = new byte[BUFFER]; - FileOutputStream fos = new FileOutputStream(newFile); - BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER); - while ((count = zis.read(data, 0, BUFFER)) != -1){ - bos.write(data, 0, count); - } - bos.flush(); - bos.close(); - fos.close(); - } - } - zis.close(); - bis.close(); - fis.close(); - } - catch(FileNotFoundException e) { - publish(" !Cannot find file '" + file + "'!\n"); - return false; - } - catch(Exception e){ - publish(" !Cannot uncompress file '" + file + "'!\n"); - return false; - } - publish(" Ending uncompressing file '" + file + "'\n"); - } - return true; - } - - - private boolean removePackage(int element) { - String packageName = packageAddresses[element][architecture]; - if ("".equals(packageName)) { - return true; - } - String fileName = getLocalName(packageAddresses[element][architecture]); - return removeFile(fileName); - } - - - private boolean postProcess(int element) { - switch (element) { - case 4: - // Create mySQL user - PasswordAsker pa = new PasswordAsker(); - if (! pa.waitForPassword()) { - publish("Problem in the password asker!\n"); - return false; - } - String command = "\"\" --user=root --password=" + pa.getPassword() + " -e \"source \\createUser.sql\""; - command = replaceSubstring(command); - if (! launch(command)) { - publish(" !Cannot create SQL accounts!\n"); - return false; - } - return true; - case 7: - // Move S-MART files to parent directory - File installDirectory = new File(installDirectoryName + File.separator + "S-Mart"); - for (File file: installDirectory.listFiles()) { - File destinationFile = new File(file.getParentFile().getParentFile(), file.getName()); - if (! file.renameTo(destinationFile)) { - publish(" !Cannot move '" + file.getAbsolutePath() + "' to '" + destinationFile.getAbsolutePath() + "'!\n"); - } - } - if (! installDirectory.delete()) { - publish(" !Cannot remove installation S-MART directory '" + installDirectory.getAbsolutePath() + "'!\n"); - } - } - return true; - } - - - private boolean setEnvironmentVariables() { - String[] command = {"REG", "ADD", "HKCU\\Environment", "/v", "PYTHONPATH", "/t", "REG_SZ", "/d", "\"" + installDirectoryName + "\\Python\"", "/f"}; - return launch(command); - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/PasswordAsker.java --- a/SMART/Java/Installer/PasswordAsker.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.concurrent.CountDownLatch; - -public class PasswordAsker { - - static String password; - static JFrame frame; - static CountDownLatch latch; - - - public PasswordAsker() { - password = null; - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - latch = new CountDownLatch(1); - } - - - private static void createAndShowGUI() { - //Create and set up the window. - frame = new JFrame("Password"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setContentPane(setMainPane()); - - //Display the window. - frame.pack(); - frame.setVisible(true); - } - - - private static JPanel setMainPane() { - JPanel rootPanel = new JPanel(false); - rootPanel.setLayout(new GridLayout(0, 1)); - - JPanel infoPanel = new JPanel(false); - JLabel infoLabel = new JLabel("Please write here the password that you entered for the mySQL root account.\r\nNo information is stored nor sent. I promise."); - infoPanel.add(infoLabel); - - JPanel passPanel = new JPanel(false); - passPanel.setLayout(new GridLayout(1, 0)); - JLabel passLabel = new JLabel("password"); - final JTextField passText = new JTextField(20); - passLabel.setLabelFor(passText); - passPanel.add(passLabel); - passPanel.add(passText); - - JPanel okPanel = new JPanel(false); - JButton okButton = new JButton("OK"); - okPanel.add(okButton); - - okButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - password = passText.getText(); - frame.setVisible(false); - frame.dispose(); - latch.countDown(); - } - }); - - rootPanel.add(infoPanel); - rootPanel.add(passPanel); - rootPanel.add(okPanel); - - return rootPanel; - } - - - public boolean waitForPassword() { - try { - latch.await(); - } - catch (InterruptedException e) { - return false; - } - return true; - } - - - public String getPassword() { - return password; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/SmartInstaller.jar Binary file SMART/Java/Installer/SmartInstaller.jar has changed diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/SmartInstaller.java --- a/SMART/Java/Installer/SmartInstaller.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; -import java.net.*; - -public class SmartInstaller extends JPanel implements ActionListener { - int BUFFER = 1024; - - JFrame mainFrame; - JTextArea logArea; - - // configuration chooser buttons - String configurations[] = {"32 bits", "64 bits"}; - JRadioButton configurationButtons[]; - - // program chooser buttons - String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "Python 2.6", "S-MART"}; - JCheckBox programChooserButtons[]; - - JButton goButton; - - // install directory - JButton installDirectoryChooserButton; - JTextField installDirectoryChooserTextField; - - - public SmartInstaller() { - super(); - - Box box = Box.createVerticalBox(); - - // Header - JPanel headerPanel = new JPanel(false); - JTextArea headerArea = new JTextArea("This is the S-MART installation tool.\r\nIt will download and install the needed softwares, as well as S-MART itself.\r\nYou can unselect the software that you already have installed.\r\nDuring the installation, accept all the default parameters."); - TitledBorder headerBorder = BorderFactory.createTitledBorder("Welcome to the S-MART installer!"); - headerArea.setEditable(false); - headerArea.setBackground(headerPanel.getBackground()); - headerPanel.add(headerArea); - headerPanel.setBorder(headerBorder); - - - // Configuration - JPanel configurationPanel = new JPanel(false); - configurationPanel.setLayout(new GridLayout(1, 0)); - configurationButtons = new JRadioButton[configurations.length]; - ButtonGroup configurationGroup = new ButtonGroup(); - for (int i = 0; i < configurations.length; i++) { - JRadioButton button = new JRadioButton(configurations[i]); - configurationPanel.add(button); - configurationButtons[i] = button; - configurationGroup.add(button); - } - configurationButtons[0].setSelected(true); - TitledBorder configurationBorder = BorderFactory.createTitledBorder("Configuration"); - configurationPanel.setBorder(configurationBorder); - - - // Program chooser panel - JPanel programPanel = new JPanel(false); - programPanel.setLayout(new GridLayout(0, 1)); - - JLabel programLabel = new JLabel("Choose which programs to install:"); - programPanel.add(programLabel); - programChooserButtons = new JCheckBox[programChoosers.length]; - for (int i = 0; i < programChoosers.length; i++) { - JCheckBox button = new JCheckBox(programChoosers[i]); - button.setSelected(true); - programPanel.add(button); - programChooserButtons[i] = button; - } - TitledBorder programBorder = BorderFactory.createTitledBorder("Programs"); - programPanel.setBorder(programBorder); - - // Install directory chooser - JPanel installDirectoryChooserPanel = new JPanel(false); - installDirectoryChooserPanel.setLayout(new GridLayout(1, 0)); - JLabel installDirectoryChooserLabel = new JLabel("Choose a directory to install S-MART: "); - installDirectoryChooserTextField = new JTextField(); - installDirectoryChooserButton = new JButton("Open..."); - installDirectoryChooserButton.addActionListener(this); - - installDirectoryChooserPanel.add(installDirectoryChooserLabel); - installDirectoryChooserPanel.add(installDirectoryChooserTextField); - installDirectoryChooserPanel.add(installDirectoryChooserButton); - TitledBorder installDirectoryChooserBorder = BorderFactory.createTitledBorder("Installation directory"); - installDirectoryChooserPanel.setBorder(installDirectoryChooserBorder); - - // GO! - JPanel goPanel = new JPanel(false); - goButton = new JButton("GO!"); - goButton.addActionListener(this); - goButton.setSelected(true); - goPanel.add(goButton); - TitledBorder goBorder = BorderFactory.createTitledBorder("Start install"); - goPanel.setBorder(goBorder); - - // Log - logArea = new JTextArea(10, 120); - logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize())); - JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - TitledBorder logBorder = BorderFactory.createTitledBorder("Log"); - logScroll.setBorder(logBorder); - - GridLayout horizontalLayout = new GridLayout(1, 0); - - box.add(headerPanel); - box.add(configurationPanel); - box.add(programPanel); - box.add(installDirectoryChooserPanel); - box.add(goPanel); - box.add(logScroll); - - add(box); - } - - - public void actionPerformed(ActionEvent e) { - - // Install directories chooser - if (e.getSource() == goButton) { - boolean[] selectedPrograms = new boolean[programChoosers.length]; - for (int i = 0; i < programChoosers.length; i++) { - selectedPrograms[i] = programChooserButtons[i].isSelected(); - } - SmartInstallerTask task = new SmartInstallerTask(logArea, selectedPrograms, installDirectoryChooserTextField.getText(), (configurationButtons[0].isSelected())? 0: 1); - task.execute(); - } - // Install directories chooser - else if (e.getSource() == installDirectoryChooserButton) { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - installDirectoryChooserTextField.setText(chooser.getSelectedFile().getPath()); - } - } - } - - private static void createAndShowGUI() { - // Create and set up the window. - JFrame mainFrame = new JFrame("S-Mart Installer"); - mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Create and set up the content pane. - JComponent newContentPane = new SmartInstaller(); - newContentPane.setOpaque(true); - mainFrame.setContentPane(newContentPane); - - // Display the window. - mainFrame.pack(); - mainFrame.setVisible(true); - } - - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/SmartInstallerTask.java --- a/SMART/Java/Installer/SmartInstallerTask.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,419 +0,0 @@ -import java.util.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; -import java.net.*; -import java.util.Stack; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class SmartInstallerTask extends SwingWorker { - - int BUFFER = 1024; - - int architecture = 0; - String installDirectoryName = null; - JTextArea logArea = null; - boolean[] selectedPrograms = null; - - // program chooser buttons - String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "Python 2.6", "S-MART"}; - - // Web addresses for the tools - String packageAddresses[][] = { - {"http://cran.cict.fr/bin/windows/base/R-2.11.0-win32.exe", "http://cran.cict.fr/bin/windows64/base/R-2.11.0-win64.exe"}, - {"", ""}, - {"", ""}, - {"http://www.python.org/ftp/python/2.6.5/python-2.6.5.msi", "http://www.python.org/ftp/python/2.6.5/python-2.6.5.amd64.msi"}, - {"http://urgi.versailles.inra.fr/content/download/1929/17848/file/s-mart-1.0.15.zip", "http://urgi.versailles.inra.fr/content/download/1929/17848/file/s-mart-1.0.15.zip"} - }; - - // Packages to install - String rPackages[] = {"RColorBrewer", "Hmisc"}; - - // Script lines - String scriptLines[][] = { - {"\"\\R-2.11.0-win32.exe\"", "\"\\R-2.11.0-win64.exe\""}, - {"\"\" CMD BATCH \"\\installRColorBrewer.R\"", "\"\" CMD BATCH \"\\installRColorBrewer.R\""}, - {"\"\" CMD BATCH \"\\installHmisc.R\"", "\"\" CMD BATCH \"\\installHmisc.R\""}, - {"msiexec /i \"\\python-2.6.5.msi\"", "msiexec /i \"\\python-2.6.5.amd64.msi\""}, - {"", ""} - }; - - // Files to uncompress - String compressedFiles[][] = { - {"", ""}, - {"", ""}, - {"", ""}, - {"", ""}, - {"\\s-mart-1.0.15.zip", "\\s-mart-1.0.15.zip"} - }; - - - public SmartInstallerTask(JTextArea ta, boolean[] b, String s, int a) { - logArea = ta; - selectedPrograms = b; - installDirectoryName = s; - architecture = a; - } - - - @Override - public Boolean doInBackground() { - boolean installOk; - publish("Starting install\n"); - writeFiles(); - for (int i = 0; i < selectedPrograms.length; i++) { - if (selectedPrograms[i]) { - if (! install(i)) { - return Boolean.FALSE; - } - } - } - removeFiles(); - setEnvironmentVariables(); - publish("Ending install\n"); - return Boolean.TRUE; - } - - - @Override - protected void process(List chunks) { - for (String chunk: chunks) { - logArea.append(chunk); - } - } - - - private boolean launch(String command) { - return realLaunch(new ProcessBuilder(command), command); - } - - private boolean launch(String[] command) { - return realLaunch(new ProcessBuilder(command), Arrays.toString(command)); - } - - private boolean realLaunch(ProcessBuilder pb, String command) { - BufferedReader outputReader; - pb = pb.redirectErrorStream(true); - Process process = null; - publish(" Starting command '" + command + "'\n"); - try { - process = pb.start(); - BufferedInputStream outputStream = new BufferedInputStream(process.getInputStream()); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - outputReader = new BufferedReader(isr); - } - catch (Exception exception) { - publish(" !Process cannot be started (command is '" + command + "')!\n"); - exception.printStackTrace(); - return false; - } - if (outputReader == null) { - publish(" !Problem in the output of the command!\n"); - return false; - } - else { - publish(" Output is:\n"); - try { - publish(" ---\n"); - String line; - while ((line = outputReader.readLine()) != null) { - publish(" " + line + "\r\n"); - } - publish(" ---\n"); - } - catch (IOException e) { - publish(" !Cannot get the output of the command!\n"); - return false; - } - } - int exitValue = process.exitValue(); - if (exitValue != 0) { - publish(" !Problem during the execution of the command '" + command + "'!\n"); - return false; - } - publish(" Ending command '" + command + "'\n"); - return true; - } - - - private File lookForFile(String fileName, String[] putativePlaces) { - publish(" Looking for file " + fileName + "\n"); - for (String place: putativePlaces) { - File file = new File(place, fileName); - publish(" Look at " + file.getAbsolutePath() + "\n"); - if (file.exists()) { - publish(" Found it in expected place " + file.getAbsolutePath() + "\n"); - return file; - } - } - Stack files = new Stack(); - files.push(new File("\\")); - while (! files.empty()) { - File file = files.pop(); - for (File childFile: file.listFiles()) { - if (childFile.isDirectory()) { - files.push(childFile); - } - else { - if (fileName.compareToIgnoreCase(childFile.getName()) == 0) { - publish(" Found it in unexpected place " + childFile.getAbsolutePath() + "\n"); - return childFile; - } - } - } - } - publish(" !Cannot file file '" + fileName + "'!\n"); - return null; - } - - - private boolean writeFile(String fileName, String content) { - try { - FileWriter fw = new FileWriter(fileName); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(content); - bw.close(); - fw.close(); - } - catch (Exception e) { - publish(" !Cannot write file '" + fileName + "'!\n"); - return false; - } - return true; - } - - - private boolean removeFile(String fileName) { - File file = new File(fileName); - if (file.exists()) { - if (! file.delete()) { - publish(" !Cannot delete file '" + file.getAbsolutePath() + "'!\n"); - return false; - } - } - return true; - } - - - private boolean writeFiles() { - for (String rPackage: rPackages) { - String fileName = installDirectoryName + File.separator + "install" + rPackage + ".R"; - String content = "install.packages(\"" + rPackage + "\", repos = \"http://cran.cict.fr\", dependencies = TRUE)\n"; - if (! writeFile(fileName, content)) { - publish(" !Cannot write file for R package '" + rPackage + "'!\n"); - return false; - } - } - return true; - } - - private boolean removeFiles() { - for (String rPackage: rPackages) { - File file = new File(installDirectoryName + File.separator + "install" + rPackage + ".R"); - if (! file.delete()) { - publish("!Cannot delete R install file for " + rPackage + "!\n"); - return false; - } - } - File file = new File(installDirectoryName + File.separator + "createUser.sql"); - if (! file.delete()) { - publish("!Cannot delete mySQL configuration file!\n"); - return false; - } - return true; - } - - private boolean install(int element) { - publish(" Starting install of " + programChoosers[element] + "\n"); - downloadPackage(element); - executeInstall(element); - uncompressPackage(element); - removePackage(element); - postProcess(element); - publish(" Ending install of " + programChoosers[element] + "\n"); - return true; - } - - - private String getLocalName(String remoteName) { - String localName = installDirectoryName + File.separator + (new File(remoteName)).getName(); - int position = localName.indexOf("?"); - if (position >= 0) { - localName = localName.substring(0, position); - } - return localName; - } - - - private boolean downloadPackage(int element) { - String fileName = packageAddresses[element][architecture]; - if (! "".equals(fileName)) { - publish(" Starting download of " + programChoosers[element] + "\n"); - try { - BufferedInputStream bis = new BufferedInputStream(new URL(fileName).openStream()); - FileOutputStream fos = new FileOutputStream(getLocalName(fileName)); - BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER); - byte[] data = new byte[BUFFER]; - int x = 0; - while((x = bis.read(data, 0, BUFFER)) >= 0) { - bos.write(data, 0, x); - } - bos.close(); - fos.close(); - bis.close(); - } - catch (IOException e) { - publish(" !Cannot download file '" + fileName + "'!\n"); - return false; - } - publish(" Ending download of " + programChoosers[element] + "\n"); - } - return true; - } - - - private String replaceSubstring(String line) { - if (line.contains("")) { - String protectedDirectory = installDirectoryName.replaceAll("\\\\", "\\\\\\\\"); - line = line.replaceAll("", protectedDirectory); - } - if (line.contains("")) { - String userName = System.getenv().get("USERNAME"); - String[] possibleRDirectories = {"C:\\Program Files\\R-2.11.0", "C:\\Documents and Settings\\" + userName + "\\Mes documents\\R\\R-2.11.0\\bin", "C:\\Documents and Settings\\" + userName + "\\My documents\\R\\R-2.11.0\\bin"}; - String rDirectory = lookForFile("'.exe", possibleRDirectories).getAbsolutePath(); - rDirectory = rDirectory.replaceAll("\\\\", "\\\\\\\\"); - line = line.replaceAll("", rDirectory); - } - return line; - } - - - private boolean executeInstall(int element) { - String commands = scriptLines[element][architecture]; - if (! "".equals(commands)) { - for (String command: commands.split(";")) { - command = replaceSubstring(command); - publish(" Starting command '" + command + "'\n"); - Process process = null; - try { - process = Runtime.getRuntime().exec(command); - } - catch (IOException e) { - publish(" !Cannot execute command '" + command + "'!\n"); - return false; - } - try { - process.waitFor(); - } - catch (InterruptedException e) { - publish(" !Cannot wait for the end of the command '" + command + "'!\n"); - return false; - } - int exitValue = process.exitValue(); - if (exitValue != 0) { - publish(" !Problem during the execution of the command '" + command + "'!\n"); - return false; - } - publish(" Ending command '" + command + "'\n"); - } - } - return true; - } - - - private boolean uncompressPackage(int element) { - String file = compressedFiles[element][architecture]; - if (! "".equals(file)) { - file = replaceSubstring(file); - publish(" Starting uncompressing file '" + file + "'\n"); - try { - FileInputStream fis = new FileInputStream(file); - BufferedInputStream bis = new BufferedInputStream(fis); - ZipInputStream zis = new ZipInputStream(bis); - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (! entry.isDirectory()) { - File newFile = new File(installDirectoryName + File.separator + entry.getName()); - // create parent directories - File upDirectory = newFile.getParentFile(); - while (upDirectory != null){ - if (! upDirectory.exists()) { - upDirectory.mkdir(); - publish(" Creating directory '" + upDirectory.getAbsolutePath() + "'\n"); - } - upDirectory = upDirectory.getParentFile(); - } - // write the files to the disk - publish(" Extracting '" + entry.getName() + "' to '" + newFile.getAbsolutePath() + "'\n"); - int count; - byte data[] = new byte[BUFFER]; - FileOutputStream fos = new FileOutputStream(newFile); - BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER); - while ((count = zis.read(data, 0, BUFFER)) != -1){ - bos.write(data, 0, count); - } - bos.flush(); - bos.close(); - fos.close(); - } - } - zis.close(); - bis.close(); - fis.close(); - } - catch(FileNotFoundException e) { - publish(" !Cannot find file '" + file + "'!\n"); - return false; - } - catch(Exception e){ - publish(" !Cannot uncompress file '" + file + "'!\n"); - return false; - } - publish(" Ending uncompressing file '" + file + "'\n"); - } - return true; - } - - - private boolean removePackage(int element) { - String packageName = packageAddresses[element][architecture]; - if ("".equals(packageName)) { - return true; - } - String fileName = getLocalName(packageAddresses[element][architecture]); - return removeFile(fileName); - } - - - private boolean postProcess(int element) { - switch (element) { - case 4: - // Move S-MART files to parent directory - File installDirectory = new File(installDirectoryName + File.separator + "S-Mart"); - for (File file: installDirectory.listFiles()) { - File destinationFile = new File(file.getParentFile().getParentFile(), file.getName()); - if (! file.renameTo(destinationFile)) { - publish(" !Cannot move '" + file.getAbsolutePath() + "' to '" + destinationFile.getAbsolutePath() + "'!\n"); - } - } - if (! installDirectory.delete()) { - publish(" !Cannot remove installation S-MART directory '" + installDirectory.getAbsolutePath() + "'!\n"); - } - } - return true; - } - - - private boolean setEnvironmentVariables() { - String[] command = {"REG", "ADD", "HKCU\\Environment", "/v", "PYTHONPATH", "/t", "REG_SZ", "/d", "\"" + installDirectoryName + "\\Python\"", "/f"}; - return launch(command); - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/build.sh --- a/SMART/Java/Installer/build.sh Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -#! /bin/sh - -rm -rf SmartInstaller.jar -javac *.java -jar cvfm SmartInstaller.jar manifest.txt *.class diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/manifest.txt --- a/SMART/Java/Installer/manifest.txt Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Created-By: Matthias Zytnicki -Main-Class: SmartInstaller diff -r 769e306b7933 -r 86c781421239 SMART/Java/Installer/s-mart.zip Binary file SMART/Java/Installer/s-mart.zip has changed diff -r 769e306b7933 -r 86c781421239 SMART/Java/Program.java --- a/SMART/Java/Program.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import javax.swing.*; - - -public class Program { - String shortName; - String name; - String section; - String description; - Vector options; - JPanel panel; - JButton button; - - - public Program() { - this.shortName = null; - this.name = null; - this.options = new Vector (); - } - - - public void setShortName(String shortName) { - this.shortName = shortName; - } - - - public void setName(String name) { - this.name = name; - } - - - public void setSection(String section) { - this.section = section; - } - - public void setDescription(String description) { - this.description = description; - } - - - public void addOption(ProgramOption option) { - options.add(option); - } - - - public String getShortName() { - return this.shortName; - } - - - public String getName() { - return this.name; - } - - - public String getSection() { - return this.section; - } - - public String getDescription() { - return this.description; - } - - - public String checkValues() { - for (int i = 0; i < options.size(); i++) { - String comment = options.get(i).checkValue(); - if (comment != null) { - return comment; - } - } - return null; - } - - - public LinkedList getCommand() { - LinkedList parameterList = new LinkedList(); - parameterList.add(Global.pythonCommand); - parameterList.add("Python" + java.io.File.separator + this.shortName); - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - parameterList.addAll(option.getCommand()); - } - return parameterList; - } - - - public JPanel getPanel() { - if (this.panel != null) { - return this.panel; - } - - this.panel = new JPanel(false); - this.panel.setLayout(new FlowLayout()); - Box box = Box.createVerticalBox(); - - JPanel descriptionPanel = new JPanel(false); - JLabel descriptionLabel = new JLabel(this.description); - descriptionPanel.add(descriptionLabel); - box.add(descriptionPanel); - - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - JPanel panel = option.getPanel(); - if (panel == null) { - System.out.println("Problem with Python program '" + this.shortName + "'."); - return null; - } - box.add(option.getPanel()); - } - - JPanel buttonPanel = new JPanel(false); - this.button = new JButton("GO!"); - - buttonPanel.add(button); - - box.add(buttonPanel); - - this.panel.add(box); - - return this.panel; - } - - - public JButton getButton() { - if (this.button == null) { - this.getPanel(); - } - return this.button; - } - - - public Vector < File > getOutputFiles() { - Vector < File > files = new Vector < File > (); - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - if (! option.isInput()) { - files.add(option.getOutputFile()); - } - } - return files; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/ProgramFileReader.java --- a/SMART/Java/ProgramFileReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; - - -public class ProgramFileReader { - String fileName; - Vector programs; - - - public ProgramFileReader(String fileName) { - this.fileName = fileName; - this.programs = new Vector (); - } - - - public boolean read() { -// File file = new File(this.fileName); -// Program program = null; -// int step = 0; -// TreeMap options = new TreeMap (); - -// try { -// BufferedReader reader = new BufferedReader(new FileReader(file)); -// String line = null; -// String section = null; - -// while ((line = reader.readLine()) != null) { - -// line = line.trim(); - -// if (line.length() == 0) { -// if (program != null) { -// programs.add(program); -// } -// program = null; -// step = 0; -// continue; -// } - -// if ((line.charAt(0) == '[') && (line.charAt(line.length() - 1) == ']')) { -// section = line.substring(1, line.length() - 1).trim(); -// continue; -// } -// switch (step) { -// case 0: -// program = new Program(); -// program.setName(line); -// if (section == null) { -// System.out.println("Error! Section of program '" + line + "' is not set!"); -// } -// program.setSection(section); -// step = 1; -// break; -// case 1: -// program.setShortName(line); -// step = 2; -// break; -// case 2: -// ProgramOption option = new ProgramOption(); - -// String[] elements = line.split(":"); -// boolean input = elements[0].trim().equalsIgnoreCase("input")? true: false; -// String[] subElements = elements[1].split(";"); -// String identifier = subElements[0].trim(); - -// option.setInput(input); - -// if (input) { - -// if (subElements.length < 4) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String type = subElements[1].trim(); -// String comment = subElements[2].trim(); -// boolean compulsory = subElements[3].trim().equalsIgnoreCase("0")? false: true; - -// option.setIdentifier(identifier); -// option.setType(type); -// option.setComment(comment); -// option.setCompulsory(compulsory); - -// if ("file".compareToIgnoreCase(type) == 0) { -// if (subElements.length < 5) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String formatIdentifier = subElements[4].trim(); -// option.setFormatIdentifier(formatIdentifier); -// } -// else if ("choice".compareToIgnoreCase(type) == 0) { -// if (subElements.length < 5) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String[] choices = subElements[4].trim().split(","); -// for (int i = 0; i < choices.length; i++) { -// choices[i] = choices[i].trim(); -// } -// option.setChoices(choices); -// } -// options.put(identifier, option); -// } -// else { -// String format = subElements[1].trim(); - -// option.setFormat(format); -// option.setAssociatedOption(options.get(identifier)); -// } - -// program.addOption(option); - -// break; -// default: -// return false; -// } -// } - -// reader.close(); -// } -// catch (FileNotFoundException e) { -// return false; -// } -// catch (IOException e) { -// return false; -// } - -// if (program != null) { -// programs.add(program); -// } - - return true; - } - - public int getNbPrograms() { - return programs.size(); - } - - public Program getProgram(int i) { - return programs.get(i); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/ProgramLauncher.java --- a/SMART/Java/ProgramLauncher.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,209 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.*; -import javax.swing.SwingUtilities; -import javax.swing.*; -import java.util.concurrent.CountDownLatch; - -public class ProgramLauncher extends SwingWorker { - - String[] command; - JTextArea logArea; - JLabel messageField; - JProgressBar progressBar; - JLabel etaField; - int exitValue; - CountDownLatch latch; - - - - public ProgramLauncher (LinkedList c, JTextArea la, JLabel mf, JProgressBar pb, JLabel ef) { - command = new String[c.size()]; - logArea = la; - messageField = mf; - progressBar = pb; - etaField = ef; - exitValue = -1; - c.toArray(command); - latch = new CountDownLatch(1); - } - - - public ProgramLauncher (String[] c, JTextArea la, JLabel mf, JProgressBar pb, JLabel ef) { - command = c; - logArea = la; - messageField = mf; - progressBar = pb; - etaField = ef; - exitValue = -1; - latch = new CountDownLatch(1); - } - - - @Override - public Boolean doInBackground() { - ProcessBuilder pb = new ProcessBuilder(command); - Process process = null; - BufferedReader outputReader = null; - pb = pb.redirectErrorStream(true); - Map env = pb.environment(); - env.put("PYTHONPATH", System.getProperty("user.dir")); - env.put("SMARTPATH", System.getProperty("user.dir") + java.io.File.separator + "SMART" + java.io.File.separator + "Java" + java.io.File.separator + "Python"); - env.put("SMARTMYSQLPATH", Global.mysqlCommand); - env.put("SMARTRPATH", Global.rCommand); - String commandJoined = Arrays.toString(command); - - try { - publish("=== Starting command '" + commandJoined.trim() + "' ===\n"); - process = pb.start(); - - BufferedInputStream outputStream = new BufferedInputStream(process.getInputStream()); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - outputReader = new BufferedReader(isr); - } - catch (Exception exception) { - publish("!Process cannot be started (command is '" + commandJoined + "')!\n"); - exception.printStackTrace(); - latch.countDown(); - return Boolean.FALSE; - } - if (outputReader == null) { - publish("!Problem in the output of the command!\n"); - latch.countDown(); - return Boolean.FALSE; - } - else { - try { - String line; - while ((line = outputReader.readLine()) != null) { - publish(line + "\n"); - } - } - catch (IOException e) { - e.printStackTrace(); - publish("!Cannot get the output of the command!\n"); - latch.countDown(); - return Boolean.FALSE; - } - } - try { - process.waitFor(); - } - catch (InterruptedException e) { - e.printStackTrace(); - publish("!Cannot wait for the end of the command!\n"); - latch.countDown(); - return Boolean.FALSE; - } - try { - exitValue = process.exitValue(); - } - catch (IllegalThreadStateException e) { - e.printStackTrace(); - publish("!Cannot get the exit value of the command!\n"); - latch.countDown(); - return Boolean.FALSE; - } - if (exitValue != 0) { - publish("!Problem during the execution of the command '" + commandJoined + "'!\n"); - latch.countDown(); - return Boolean.FALSE; - } - publish("=== Ending command '" + commandJoined.trim() + "' ===\n"); - latch.countDown(); - return Boolean.TRUE; - } - - - @Override - protected void process(List chunks) { - String message = ""; - String text = logArea.getText(); - for (String chunk: chunks) { - text += chunk; - } - for (String lineSeparatedByCarriageReturn: text.split("\n")) { - for (String line: lineSeparatedByCarriageReturn.split("\r")) { - boolean progressLine = false; - if (line.matches(".*\\[=*\\s*\\]\\s*\\d*/\\d*\\s*")) { - String[] ratioElements = line.split("\\]")[1].trim().split("/"); - int current = Integer.parseInt(ratioElements[0].trim()); - int aim = Integer.parseInt(ratioElements[1].trim()); - messageField.setText(line.split("\\[")[0].trim()); - progressBar.setValue(current * 100 / aim); - etaField.setText(""); - progressLine = true; - } - else if (line.matches(".*\\[=*\\s*\\]\\s*\\d*/\\d*\\s*ETA:\\s*.*")) { - String[] ratioElements = line.split("\\]")[1].split("E")[0].trim().split("/"); - int current = Integer.parseInt(ratioElements[0].trim()); - int aim = Integer.parseInt(ratioElements[1].trim()); - String eta = line.split("ETA:")[1].trim(); - messageField.setText(line.split("\\[")[0].trim()); - progressBar.setValue(current * 100 / aim); - etaField.setText("ETA: " + eta); - progressLine = true; - } - else if (line.matches(".*\\[=*\\s*\\]\\s*\\d*\\s*completed in.*")) { - String nbElements = line.split("\\]")[1].split("completed")[0].trim(); - String timeSpent = line.split("completed in")[1].trim(); - message += line.split("\\[")[0].trim() + ": " + nbElements + " elements completed in " + timeSpent + "\n"; - messageField.setText(line.split("\\[")[0].trim()); - progressLine = true; - } - if (! progressLine) { - message += line + "\n"; - } - } - } - String lines[] = message.split("\n"); - String toBeWritten = ""; - for (int i = Math.max(0, lines.length - Global.logAreaSize); i < lines.length; i++) { - toBeWritten += lines[i] + "\n"; - } - logArea.setText(toBeWritten); - } - - public int getExitValue() { - try { - latch.await(); - } - catch (InterruptedException e) { - logArea.append("Cannot wait for the end of the process!\n"); - e.printStackTrace(); - return -1; - } - return exitValue; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/ProgramOption.java --- a/SMART/Java/ProgramOption.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,358 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; - - -public class ProgramOption { - boolean input; - String identifier; - String type; - String comment; - boolean compulsory; - String[] format; - String formatIdentifier; - ProgramOption associatedOption; - String defaultValue; - String[] choices; - JComponent component; - JPanel panel; - - - public ProgramOption() { - this.input = true; - this.identifier = null; - this.type = null; - this.comment = null; - this.compulsory = false; - this.format = null; - this.formatIdentifier = null; - this.associatedOption = null; - this.defaultValue = ""; - this.choices = null; - this.component = null; - this.panel = null; - } - - - public void setInput(boolean input) { - this.input = input; - } - - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - - public void setType(String type) { - this.type = type; - } - - - public void setComment(String comment) { - this.comment = comment; - } - - - public void setCompulsory(boolean compulsory) { - this.compulsory = compulsory; - } - - - public void setFormat(String[] format) { - this.format = format; - } - - - public void setFormat(String format) { - this.format = new String[1]; - this.format[0] = format; - } - - - public void setFormatIdentifier(String formatIdentifier) { - this.formatIdentifier = formatIdentifier; - } - - - public void setAssociatedOption(ProgramOption option) { - this.associatedOption = option; - } - - - public void setChoices(String[] choices) { - this.choices = new String[choices.length+1]; - this.choices[0] = "---"; - for (int i = 0; i < choices.length; i++) { - this.choices[i+1] = choices[i]; - } - } - - - public void setDefault(String defaultValue) { - this.defaultValue = defaultValue; - } - - - public boolean isInput() { - return this.input; - } - - - public boolean checkSettings() { - if (this.identifier == null) { - return false; - } - if (this.type == null) { - return false; - } - if (this.comment == null) { - return false; - } - if (this.comment == null) { - return false; - } - if (("choice".compareToIgnoreCase(this.type) == 0) && (this.choices == null)) { - return false; - } - return true; - } - - - public JPanel getPanel() { - if (this.panel != null) { - return this.panel; - } - String comment = this.comment; - if (this.compulsory) { - comment += " [*]"; - } - - GridLayout horizontalLayout = new GridLayout(1, 0); - this.panel = new JPanel(false); - this.panel.setLayout(horizontalLayout); - JLabel label = new JLabel(comment); - - if (this.type == null) { - System.out.println("Error! Option '" + this.identifier + "' is not set!"); - } - - if (("int".compareToIgnoreCase(this.type) == 0) || ("float".compareToIgnoreCase(this.type) == 0) || ("string".compareToIgnoreCase(this.type) == 0) || (("file".compareToIgnoreCase(this.type) == 0) && (!this.input))) { - this.component = new JTextField(); - if (this.defaultValue != null) { - ((JTextField) this.component).setText(this.defaultValue); - } - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("file".compareToIgnoreCase(this.type) == 0) { - this.component = new JComboBox(Global.fileNames); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("boolean".compareToIgnoreCase(this.type) == 0) { - this.component = new JCheckBox(); - if ((this.defaultValue != null) && (this.defaultValue.compareToIgnoreCase("true") == 0)) { - ((JCheckBox) this.component).setSelected(true); - } - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("format".compareToIgnoreCase(this.type) == 0) { - Vector < String > formats = new Vector < String > (); - for (String format: this.format) { - if (Global.formats.getFormats(format) == null) { - System.out.println("Do not know how to handle format '" + format + "'."); - } - formats.addAll(Global.formats.getFormats(format).getFormats()); - } - this.component = new JComboBox(formats); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("files".compareToIgnoreCase(this.type) == 0) { - JButton button = new JButton("file..."); - this.component = new JTextField(); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - this.panel.add(button); - Global.otherFileConcatenationChooser.put(button, (JTextField) this.component); - } - else if ("directory".compareToIgnoreCase(this.type) == 0) { - JButton button = new JButton("directory..."); - this.component = new JTextField(); - label.setLabelFor(this.component); - this.panel.add(label); - JPanel rightPanel = new JPanel(false); - rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.LINE_AXIS)); - rightPanel.add(this.component); - rightPanel.add(button); - this.panel.add(rightPanel); - Global.otherDirectoriesChooser.put(button, (JTextField) this.component); - } - else if ("choice".compareToIgnoreCase(this.type) == 0) { - this.component = new JComboBox(this.choices); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else { - System.out.println("Do not know how to read type " + this.type); - } - - return this.panel; - } - - - public JComponent getComponent() { - if (component == null) { - this.getPanel(); - } - return this.component; - } - - - private String getValue() { - if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("directory".equals(this.type)) || ("files".equals(this.type))) { - String s = ((JTextField) this.component).getText(); - if ("None".equals(s)) { - return ""; - } - return s; - } - if ("file".equals(this.type)) { - return (String) ((JComboBox) this.component).getSelectedItem(); - } - if ("boolean".equals(this.type)) { - return ((JCheckBox) this.component).isSelected()? "true": "false"; - } - if ("format".equals(this.type)) { - return (String) ((JComboBox) this.component).getSelectedItem(); - } - if ("choice".equals(this.type)) { - String s = (String) ((JComboBox) this.component).getSelectedItem(); - if ("---".equals(s)) { - return ""; - } - return s; - } - System.out.println("Do not know how to get value of '" + this.type + "' (" + this.identifier + ")."); - return null; - } - - - public String checkValue() { - String value = this.getValue(); - if ((this.compulsory) && ((value == null) || ("".equals(value)))) { - return "Option '" + this.comment + "' has no value... Please specify it.\n"; - } - if ("int".equals(this.type)) { - if ((value != null) && (! "".equals(value)) && (! "None".equals(value))) { - try { - int i = Integer.parseInt(value); - } - catch (NumberFormatException e) { - return "Option '" + this.comment + "' should be an integer... Please correct it.\n"; - } - } - } - else if ("float".equals(this.type)) { - if ((value != null) && (! "".equals(value))) { - try { - float i = Float.parseFloat(value); - } - catch (NumberFormatException e) { - return "Option '" + this.comment + "' should be a float... Please correct it.\n"; - } - } - } - return null; - } - - - public LinkedList getCommand() { - LinkedList list = new LinkedList (); - - if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("format".equals(this.type)) || ("directory".equals(this.type)) || ("files".equals(this.type)) || ("choice".equals(this.type))) { - String value = this.getValue(); - if (value.length() == 0) { - return list; - } - list.add(this.identifier); - list.add(value); - return list; - } - if ("file".equals(this.type)) { - String fileName = (String) ((JComboBox) this.component).getSelectedItem(); - if (fileName == null) { - return list; - } - list.add(this.identifier); - list.add(this.getValue()); - return list; - } - if (("boolean".equals(this.type)) || ("bool".equals(this.type))) { - if ("true".equals(this.getValue())) { - list.add(this.identifier); - } - return list; - } - System.out.println("Cannot get type of option " + this.type + " (" + this.identifier + "): " + this.getValue()); - return null; - } - - - public File getOutputFile() { - if (this.input) return null; - String format = ""; - if (this.format != null) { - format = this.format[0]; - } - if (this.associatedOption != null) { - format = this.associatedOption.getValue(); - } - return new File(this.getValue(), Global.formats.getFormatType(format), format); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/PythonHelperReader.java --- a/SMART/Java/PythonHelperReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,336 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; -import java.util.regex.*; - -public class PythonHelperReader { - - String fileName; - Program program; - BufferedReader reader; - String message; - - public PythonHelperReader(String fileName) { - this.fileName = fileName; - this.reader = reader; - this.message = null; - } - - public void setReader(BufferedReader reader) { - this.reader = reader; - } - - public void run() { - this.program = new Program(); - boolean inBeginning = true; - boolean inUsage = false; - boolean afterUsage = false; - boolean inDescription = false; - boolean afterDescription = false; - boolean inOptions = false; - boolean inOptionBlank = false; - boolean inError = false; - String usage = null; - String description = null; - String option = null; - Vector options = new Vector < String > (); - String[] optionSplitted; - - // Parse file - try { - String line = null; - - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("Traceback")) { - this.message = "Problem with header of '" + this.fileName + "':\n" + line + "\n"; - inError = true; - inBeginning = false; - inUsage = false; - afterUsage = false; - inDescription = false; - afterDescription = false; - inOptions = false; - inOptionBlank = false; - } - else if (inError) { - this.message += line + "\n"; - } - else if (inBeginning) { - if (line.startsWith("Usage:")) { - inUsage = true; - inBeginning = false; - usage = line; - } - } - else if (inUsage) { - if ("".equals(line)) { - inUsage = false; - afterUsage = true; - } - else { - usage += " " + line; - } - } - else if (afterUsage) { - if (! "".equals(line)) { - description = line; - afterUsage = false; - inDescription = true; - } - } - else if (inDescription) { - if ("".equals(line)) { - inDescription = false; - afterDescription = true; - } - else { - description += " " + line; - } - } - else if (afterDescription) { - if (! "".equals(line)) { - afterDescription = false; - inOptions = true; - } - } - else if (inOptions) { - if ("".equals(line)) { - inOptions = false; - inOptionBlank = true; - } - else { - if (option == null) { - option = line; - } - else { - if (line.charAt(0) == '-') { - options.add(option); - option = line; - } - else { - option += " " + line; - } - } - } - } - else if (inOptionBlank) { - if (! "".equals(line)) { - inOptionBlank = false; - inOptions = true; - } - } - else { - this.message = "Something is wrong in the file '" + this.fileName + "'.\n"; - return; - } - } - - reader.close(); - } - catch (FileNotFoundException e) { - this.message = "File " + this.fileName + " not found.\n"; - return; - } - catch (IOException e) { - this.message = "IOException while reading file " + this.fileName; - return; - } - - if (inError) { - return; - } - - if (option != null) { - options.add(option); - } - - HashMap < String, ProgramOption > identifierToOptions = new HashMap < String, ProgramOption > (); - HashMap < ProgramOption, String > associatedOption = new HashMap < ProgramOption, String > (); - - if (usage == null) { - this.message = "Cannot read the usage of file " + this.fileName + ".\n"; - return; - } - program.setShortName(usage.split(" ")[1].trim()); - program.setName(description.split(":")[0].trim()); - - Pattern pattern = Pattern.compile("\\[Category: .*\\]"); - Matcher matcher = pattern.matcher(description); - if (matcher.find()) { - program.setSection(description.substring(matcher.start() + "[Category: ".length(), matcher.end() - 1)); - program.setDescription(description.substring(0, matcher.start() - 1).trim()); - } - else { - this.message = "Cannot find category in description '" + description + "' in file " + this.fileName + ".\n"; - return; - } - for (int i = 0; i < options.size(); i++) { - option = options.get(i).replace("\t", " "); - optionSplitted = option.split(" "); - option = ""; - for (int j = 3; j < optionSplitted.length; j++) { - option += optionSplitted[j] + " "; - } - - String identifier = optionSplitted[0].replace("-", "").replace(",", ""); - // Skip -h and -v options - if (("h".equals(identifier)) || ("v".equals(identifier))) - continue; - - ProgramOption programOption = new ProgramOption(); - programOption.setIdentifier("-" + identifier); - int commentEnd = option.indexOf("["); - if (commentEnd == -1) { - this.message = "Do not understand option line '" + option + "' in file " + this.fileName + ".\n"; - return; - } - programOption.setComment(option.substring(0, commentEnd).trim()); - identifierToOptions.put(identifier, programOption); - - pattern = Pattern.compile("\\[[^\\]]*\\]"); - matcher = pattern.matcher(option); - while (matcher.find()) { - String inner = option.substring(matcher.start()+1, matcher.end()-1); - if (inner.contains(":")) { - String type = inner.substring(0, inner.indexOf(":")).trim(); - String value = inner.substring(inner.indexOf(":")+1).trim(); - // Types of the options - if ("format".compareToIgnoreCase(type) == 0) { - String currentWord = ""; - String rest = ""; - if (value.contains(" ")) { - int pos = value.indexOf(" "); - currentWord = value.substring(0, pos); - rest = value.substring(pos+1); - } - else { - currentWord = value; - } - // Output file type - if ("output".compareToIgnoreCase(currentWord) == 0) { - programOption.setInput(false); - int pos = rest.indexOf(" "); - currentWord = rest.substring(0, pos).trim(); - rest = rest.substring(pos+1).trim(); - } - // File (input or output file) - if ("file".compareToIgnoreCase(currentWord) == 0) { - programOption.setType("file"); - // Format given by an associated option (to be found later) - if (rest.startsWith("in format given by ")) { - associatedOption.put(programOption, rest.substring(rest.indexOf("format given by ") + "format given by ".length() + 1).trim()); - } - else { - if (! rest.startsWith("in ")) { - this.message = "Descriptor " + option + " does not have a proper format.\n"; - return; - } - rest = rest.substring("in ".length()); - int pos = rest.indexOf(" format"); - if (pos == -1) { - this.message = "Descriptor " + option + " does not have a proper format.\n"; - return; - } - programOption.setFormat(rest.substring(0, pos).trim().toLowerCase().split(" or ")); - } - } - // Format type - else if (rest.endsWith("file format")) { - programOption.setFormat((currentWord + " " + rest.substring(0, rest.indexOf("file format"))).trim().toLowerCase().split(" or ")); - programOption.setType("format"); - } - // Choice type - else if ("choice".compareToIgnoreCase(currentWord) == 0) { - programOption.setChoices(rest.replace("(", "").replace(")", "").split(", ")); - programOption.setType("choice"); - } - // Boolean type - else if ("bool".compareToIgnoreCase(currentWord) == 0) { - programOption.setType("boolean"); - } - // Other type - else { - if (currentWord == null) { - this.message = "Program '" + this.fileName + "' has a problem concerning the type of option '" + identifier + "'.\n"; - return; - } - programOption.setType(currentWord); - } - } - // Default value - else if ("default".compareToIgnoreCase(type) == 0) { - programOption.setDefault(value); - } - else { - this.message = "Do not understand option descriptor '" + inner + "'.\n"; - return; - } - } - else { - // Compulsory option - if ("compulsory".compareToIgnoreCase(inner) == 0) { - programOption.setCompulsory(true); - } - else { - this.message = "Do not understand option descriptor '" + inner + "'.\n"; - return; - } - } - } - if (! programOption.checkSettings()) { - this.message = "Program '" + this.fileName + "' has a problem concerning option '" + identifier + "'.\n"; - return; - } - program.addOption(programOption); - } - - // Set associated option - Iterator it = associatedOption.keySet().iterator(); - while (it.hasNext()) { - ProgramOption programOption = (ProgramOption) it.next(); - programOption.setAssociatedOption(identifierToOptions.get(associatedOption.get(programOption))); - } - } - - public String getMessage () { - return this.message; - } - - public Program getProgram () { - return this.program; - } -} - - diff -r 769e306b7933 -r 86c781421239 SMART/Java/PythonProgramFinder.java --- a/SMART/Java/PythonProgramFinder.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.io.*; -import java.util.*; - -public class PythonProgramFinder { - - String dirName; - Vector < Program > programs; - - public PythonProgramFinder(String dirName) { - this.dirName = dirName; - } - - public String findPrograms() { - java.io.File directory = new java.io.File(this.dirName); - String[] files = directory.list(new FilenameFilter() {public boolean accept(java.io.File dir, String name) {return ((! name.startsWith(".")) && (! name.startsWith("test")) && ((new java.io.File(dir, name)).isFile()) && (name.endsWith(".py")) && (name.compareToIgnoreCase("__init__.py") != 0));}}); - this.programs = new Vector < Program > (); - - for (int i = 0; i < files.length; i++) { - String[] commandList = {Global.pythonCommand, "Python" + java.io.File.separator + files[i], "-h"}; - String command = ""; - for (int j = 0; j < commandList.length; j++) { - command += commandList[j] + " "; - } - ProcessBuilder pb = new ProcessBuilder(commandList); - pb = pb.redirectErrorStream(true); - Map env = pb.environment(); - env.put("PYTHONPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTMYSQLPATH", Global.mysqlCommand); - env.put("SMARTRPATH", Global.rCommand); - - PythonHelperReader helperReader = new PythonHelperReader(files[i]); - try { - final Process process = pb.start(); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - helperReader.setReader(br); - helperReader.run(); - } - catch (IOException e) { - final Writer result = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(result); - e.printStackTrace(printWriter); - return "Command '" + command + "' failed (I/O error)...\n" + result.toString(); - } - String comments = helperReader.getMessage(); - if (comments != null) return comments; - Program program = helperReader.getProgram(); - if (("Personnal".compareToIgnoreCase(program.getSection()) != 0) && ("Personal".compareToIgnoreCase(program.getSection()) != 0)) { - this.programs.add(program); - } - } - return null; - } - - public Vector getPrograms () { - return this.programs; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/File.java --- a/SMART/Java/Sav/File.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -public class File { - String name; - String formatType; - String format; - - - public File(String name, String type, String format) { - this.name = name; - this.formatType = type; - this.format = format; - } - - public String getName() { - return this.name; - } - - public String getFormatType() { - return this.formatType; - } - - public String getFormat() { - return this.format; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/Files.java --- a/SMART/Java/Sav/Files.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class Files { - HashMap files; - - public Files () { - files = new HashMap < String, File> (); - } - - public void addFile(String fileName, String type, String format) { - this.addFile(new File(fileName, type, format)); - } - - public void addFile(File file) { - files.put(file.name, file); - } - - public String getType(String fileName) { - if (fileName == null) { - System.out.println("Error! Looking for format of empty file name!"); - } - if (! files.containsKey(fileName)) { - System.out.println("Oops! Format type of file " + fileName + " is not found!"); - return null; - } - return files.get(fileName).formatType; - } - - public String getFormat(String fileName) { - if (fileName == null) { - System.out.println("Error! Looking for format of empty file name!"); - } - if (! files.containsKey(fileName)) { - System.out.println("Oops! Format of file " + fileName + " is not found!"); - return null; - } - return files.get(fileName).format; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/FormatType.java --- a/SMART/Java/Sav/FormatType.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class FormatType { - String type; - Vector < String > formats; - - public FormatType (String type) { - this.type = type; - this.formats = new Vector < String > (); - } - - public String getType () { - return this.type; - } - - public void addFormat (String format) { - formats.add(format); - } - - public boolean containsFormat (String format) { - for (int i = 0; i < formats.size(); i++) { - if (((String) formats.get(i)).compareToIgnoreCase(format) == 0) { - return true; - } - } - return false; - } - - public Vector < String > getFormats () { - return formats; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/FormatsContainer.java --- a/SMART/Java/Sav/FormatsContainer.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; - -public class FormatsContainer { - - HashMap < String, FormatType > formatTypes; - - - public FormatsContainer() { - this.formatTypes = new HashMap < String, FormatType > (); - } - - - public void addFormat(String type, String format) { - FormatType formatType; - if (formatTypes.containsKey(type)) { - formatType = this.formatTypes.get(type); - } - else { - formatType = new FormatType(type); - this.formatTypes.put(type, formatType); - } - formatType.addFormat(format); - } - - - public Vector < String > getFormatTypes () { - Vector < String > v = new Vector < String > (); - v.addAll(this.formatTypes.keySet()); - return v; - } - - - public FormatType getFormats (String type) { - return formatTypes.get(type); - } - - - public String getFormatType (String format) { - for (Iterator it = formatTypes.keySet().iterator(); it.hasNext(); ) { - Object type = it.next(); - Object formatType = formatTypes.get(type); - if (((FormatType) formatType).containsFormat(format)) { - return (String) type; - } - } - return null; - } -} - - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/FormatsReader.java --- a/SMART/Java/Sav/FormatsReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; - - -public class FormatsReader { - - String fileName; - Vector < FormatType > formatTypes; - Vector < String > typeNames; - - - public FormatsReader(String fileName) { - this.fileName = fileName; - this.formatTypes = new Vector < FormatType > (); - } - - - public boolean read() { - File file = new File(this.fileName); - - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = null; - String[] lineElements; - String[] formats; - String typeName; - - while ((line = reader.readLine()) != null) { - if (line.length() > 0) { - lineElements = line.split(":"); - typeName = lineElements[0].trim(); - formats = lineElements[1].split(","); - for (int i = 0; i < formats.length; i++) { - Global.formats.addFormat(typeName, formats[i].trim()); - } - } - } - - reader.close(); - } - catch (FileNotFoundException e) { - return false; - } - catch (IOException e) { - return false; - } - - return true; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/Global.java --- a/SMART/Java/Sav/Global.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.Vector; -import java.util.HashMap; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JTextField; - -public class Global { - - public static int logAreaSize = 100; - - public static String smartConfFileName = "smart.conf"; - - public static String smartProgramsFileName = "programs.txt"; - - public static String smartFormatsFileName = "formats.txt"; - - public static String pythonPath = new String(); - - public static String pythonCommand = "python"; - - public static String mysqlCommand = "mysql"; - - public static String rCommand = "R"; - - public static Files files = new Files(); - - public static DefaultListModel fileNames = new DefaultListModel(); - - public static FormatsContainer formats = new FormatsContainer(); - - public static boolean programRunning = false; - - public static HashMap < JButton, JTextField > otherFilesChooser = new HashMap < JButton, JTextField >(); - - public static HashMap < JButton, JTextField > otherDirectoriesChooser = new HashMap < JButton, JTextField >(); - - public static HashMap < JButton, JTextField > otherFileConcatenationChooser = new HashMap < JButton, JTextField >(); - -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/Program.java --- a/SMART/Java/Sav/Program.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import javax.swing.*; - - -public class Program { - String shortName; - String name; - String section; - String description; - Vector options; - JPanel panel; - JButton button; - - - public Program() { - this.shortName = null; - this.name = null; - this.options = new Vector (); - } - - - public void setShortName(String shortName) { - this.shortName = shortName; - } - - - public void setName(String name) { - this.name = name; - } - - - public void setSection(String section) { - this.section = section; - } - - public void setDescription(String description) { - this.description = description; - } - - - public void addOption(ProgramOption option) { - options.add(option); - } - - - public String getShortName() { - return this.shortName; - } - - - public String getName() { - return this.name; - } - - - public String getSection() { - return this.section; - } - - public String getDescription() { - return this.description; - } - - - public String checkValues() { - for (int i = 0; i < options.size(); i++) { - String comment = options.get(i).checkValue(); - if (comment != null) { - return comment; - } - } - return null; - } - - - public LinkedList getCommand() { - LinkedList parameterList = new LinkedList(); - parameterList.add(Global.pythonCommand); - parameterList.add("Python" + java.io.File.separator + this.shortName); - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - parameterList.addAll(option.getCommand()); - } - return parameterList; - } - - - public JPanel getPanel() { - if (this.panel != null) { - return this.panel; - } - - this.panel = new JPanel(false); - this.panel.setLayout(new FlowLayout()); - Box box = Box.createVerticalBox(); - - JPanel descriptionPanel = new JPanel(false); - JLabel descriptionLabel = new JLabel(this.description); - descriptionPanel.add(descriptionLabel); - box.add(descriptionPanel); - - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - JPanel panel = option.getPanel(); - if (panel == null) { - System.out.println("Problem with Python program '" + this.shortName + "'."); - return null; - } - box.add(option.getPanel()); - } - - JPanel buttonPanel = new JPanel(false); - this.button = new JButton("GO!"); - - buttonPanel.add(button); - - box.add(buttonPanel); - - this.panel.add(box); - - return this.panel; - } - - - public JButton getButton() { - if (this.button == null) { - this.getPanel(); - } - return this.button; - } - - - public Vector < File > getOutputFiles() { - Vector < File > files = new Vector < File > (); - for (int i = 0; i < options.size(); i++) { - ProgramOption option = options.get(i); - if (! option.isInput()) { - files.add(option.getOutputFile()); - } - } - return files; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/ProgramFileReader.java --- a/SMART/Java/Sav/ProgramFileReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; - - -public class ProgramFileReader { - String fileName; - Vector programs; - - - public ProgramFileReader(String fileName) { - this.fileName = fileName; - this.programs = new Vector (); - } - - - public boolean read() { -// File file = new File(this.fileName); -// Program program = null; -// int step = 0; -// TreeMap options = new TreeMap (); - -// try { -// BufferedReader reader = new BufferedReader(new FileReader(file)); -// String line = null; -// String section = null; - -// while ((line = reader.readLine()) != null) { - -// line = line.trim(); - -// if (line.length() == 0) { -// if (program != null) { -// programs.add(program); -// } -// program = null; -// step = 0; -// continue; -// } - -// if ((line.charAt(0) == '[') && (line.charAt(line.length() - 1) == ']')) { -// section = line.substring(1, line.length() - 1).trim(); -// continue; -// } -// switch (step) { -// case 0: -// program = new Program(); -// program.setName(line); -// if (section == null) { -// System.out.println("Error! Section of program '" + line + "' is not set!"); -// } -// program.setSection(section); -// step = 1; -// break; -// case 1: -// program.setShortName(line); -// step = 2; -// break; -// case 2: -// ProgramOption option = new ProgramOption(); - -// String[] elements = line.split(":"); -// boolean input = elements[0].trim().equalsIgnoreCase("input")? true: false; -// String[] subElements = elements[1].split(";"); -// String identifier = subElements[0].trim(); - -// option.setInput(input); - -// if (input) { - -// if (subElements.length < 4) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String type = subElements[1].trim(); -// String comment = subElements[2].trim(); -// boolean compulsory = subElements[3].trim().equalsIgnoreCase("0")? false: true; - -// option.setIdentifier(identifier); -// option.setType(type); -// option.setComment(comment); -// option.setCompulsory(compulsory); - -// if ("file".compareToIgnoreCase(type) == 0) { -// if (subElements.length < 5) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String formatIdentifier = subElements[4].trim(); -// option.setFormatIdentifier(formatIdentifier); -// } -// else if ("choice".compareToIgnoreCase(type) == 0) { -// if (subElements.length < 5) { -// System.out.println("Line '" + line + "' is weird..."); -// } - -// String[] choices = subElements[4].trim().split(","); -// for (int i = 0; i < choices.length; i++) { -// choices[i] = choices[i].trim(); -// } -// option.setChoices(choices); -// } -// options.put(identifier, option); -// } -// else { -// String format = subElements[1].trim(); - -// option.setFormat(format); -// option.setAssociatedOption(options.get(identifier)); -// } - -// program.addOption(option); - -// break; -// default: -// return false; -// } -// } - -// reader.close(); -// } -// catch (FileNotFoundException e) { -// return false; -// } -// catch (IOException e) { -// return false; -// } - -// if (program != null) { -// programs.add(program); -// } - - return true; - } - - public int getNbPrograms() { - return programs.size(); - } - - public Program getProgram(int i) { - return programs.get(i); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/ProgramLauncher.java --- a/SMART/Java/Sav/ProgramLauncher.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,191 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.*; -import javax.swing.SwingUtilities; -import javax.swing.*; -import java.util.concurrent.CountDownLatch; - -public class ProgramLauncher extends SwingWorker { - - String[] command; - JTextArea logArea; - JLabel messageField; - JProgressBar progressBar; - JLabel etaField; - int exitValue; - - - public ProgramLauncher (LinkedList c, JTextArea la, JLabel mf, JProgressBar pb, JLabel ef) { - command = new String[c.size()]; - logArea = la; - messageField = mf; - progressBar = pb; - etaField = ef; - exitValue = -1; - c.toArray(command); - } - - - public ProgramLauncher (String[] c, JTextArea la, JLabel mf, JProgressBar pb, JLabel ef) { - command = c; - logArea = la; - messageField = mf; - progressBar = pb; - etaField = ef; - exitValue = -1; - } - - - @Override - public Boolean doInBackground() { - ProcessBuilder pb = new ProcessBuilder(command); - Process process = null; - BufferedReader outputReader = null; - pb = pb.redirectErrorStream(true); - Map env = pb.environment(); - env.put("PYTHONPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTMYSQLPATH", Global.mysqlCommand); - env.put("SMARTRPATH", Global.rCommand); - String commandJoined = Arrays.toString(command); - - try { - publish("=== Starting command '" + commandJoined.trim() + "' ===\n"); - process = pb.start(); - - BufferedInputStream outputStream = new BufferedInputStream(process.getInputStream()); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - outputReader = new BufferedReader(isr); - } - catch (Exception exception) { - publish("!Process cannot be started (command is '" + commandJoined + "')!\n"); - exception.printStackTrace(); - return Boolean.FALSE; - } - if (outputReader == null) { - publish("!Problem in the output of the command!\n"); - return Boolean.FALSE; - } - else { - try { - String line; - while ((line = outputReader.readLine()) != null) { - publish(line + "\n"); - } - } - catch (IOException e) { - e.printStackTrace(); - publish("!Cannot get the output of the command!\n"); - return Boolean.FALSE; - } - } - try { - process.waitFor(); - } - catch (InterruptedException e) { - e.printStackTrace(); - publish("!Cannot wait for the end of the command!\n"); - return Boolean.FALSE; - } - try { - exitValue = process.exitValue(); - System.out.println(exitValue); - } - catch (IllegalThreadStateException e) { - e.printStackTrace(); - publish("!Cannot get the exit value of the command!\n"); - return Boolean.FALSE; - } - if (exitValue != 0) { - publish("!Problem during the execution of the command '" + commandJoined + "'!\n"); - return Boolean.FALSE; - } - publish("=== Ending command '" + commandJoined.trim() + "' ===\n"); - return Boolean.TRUE; - } - - - @Override - protected void process(List chunks) { - String message = ""; - String text = logArea.getText(); - for (String chunk: chunks) { - text += chunk; - } - for (String lineSeparatedByCarriageReturn: text.split("\n")) { - for (String line: lineSeparatedByCarriageReturn.split("\r")) { - boolean progressLine = false; - if (line.matches(".*\\[=*\\s*\\]\\s*\\d*/\\d*\\s*")) { - String[] ratioElements = line.split("\\]")[1].trim().split("/"); - int current = Integer.parseInt(ratioElements[0].trim()); - int aim = Integer.parseInt(ratioElements[1].trim()); - messageField.setText(line.split("\\[")[0].trim()); - progressBar.setValue(current * 100 / aim); - etaField.setText(""); - progressLine = true; - } - else if (line.matches(".*\\[=*\\s*\\]\\s*\\d*/\\d*\\s*ETA:\\s*.*")) { - String[] ratioElements = line.split("\\]")[1].split("E")[0].trim().split("/"); - int current = Integer.parseInt(ratioElements[0].trim()); - int aim = Integer.parseInt(ratioElements[1].trim()); - String eta = line.split("ETA:")[1].trim(); - messageField.setText(line.split("\\[")[0].trim()); - progressBar.setValue(current * 100 / aim); - etaField.setText("ETA: " + eta); - progressLine = true; - } - else if (line.matches(".*\\[=*\\s*\\]\\s*\\d*\\s*completed in.*")) { - String nbElements = line.split("\\]")[1].split("completed")[0].trim(); - String timeSpent = line.split("completed in")[1].trim(); - message += line.split("\\[")[0].trim() + ": " + nbElements + " elements completed in " + timeSpent + "\n"; - messageField.setText(line.split("\\[")[0].trim()); - progressLine = true; - } - if (! progressLine) { - message += line + "\n"; - } - } - } - String lines[] = message.split("\n"); - String toBeWritten = ""; - for (int i = Math.max(0, lines.length - Global.logAreaSize); i < lines.length; i++) { - toBeWritten += lines[i] + "\n"; - } - logArea.setText(toBeWritten); - } - - public int getExitValue() { - return exitValue; - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/ProgramOption.java --- a/SMART/Java/Sav/ProgramOption.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,329 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; - - -public class ProgramOption { - boolean input; - String identifier; - String type; - String comment; - boolean compulsory; - String[] format; - String formatIdentifier; - ProgramOption associatedOption; - String defaultValue; - String[] choices; - JComponent component; - JPanel panel; - - - public ProgramOption() { - this.input = true; - this.identifier = null; - this.type = null; - this.comment = null; - this.compulsory = false; - this.format = null; - this.formatIdentifier = null; - this.associatedOption = null; - this.defaultValue = ""; - this.choices = null; - this.component = null; - this.panel = null; - } - - - public void setInput(boolean input) { - this.input = input; - } - - - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - - public void setType(String type) { - this.type = type; - } - - - public void setComment(String comment) { - this.comment = comment; - } - - - public void setCompulsory(boolean compulsory) { - this.compulsory = compulsory; - } - - - public void setFormat(String[] format) { - this.format = format; - } - - - public void setFormat(String format) { - this.format = new String[1]; - this.format[0] = format; - } - - - public void setFormatIdentifier(String formatIdentifier) { - this.formatIdentifier = formatIdentifier; - } - - - public void setAssociatedOption(ProgramOption option) { - this.associatedOption = option; - } - - - public void setChoices(String[] choices) { - this.choices = choices; - } - - - public void setDefault(String defaultValue) { - this.defaultValue = defaultValue; - } - - - public boolean isInput() { - return this.input; - } - - - public JPanel getPanel() { - if (this.panel != null) { - return this.panel; - } - String comment = this.comment; - if (this.compulsory) { - comment += " [*]"; - } - - GridLayout horizontalLayout = new GridLayout(1, 0); - this.panel = new JPanel(false); - this.panel.setLayout(horizontalLayout); - JLabel label = new JLabel(comment); - - if (this.type == null) { - System.out.println("Error! Option '" + this.identifier + "' is not set!"); - } - - if (("int".compareToIgnoreCase(this.type) == 0) || ("float".compareToIgnoreCase(this.type) == 0) || ("string".compareToIgnoreCase(this.type) == 0) || (("file".compareToIgnoreCase(this.type) == 0) && (!this.input))) { - this.component = new JTextField(); - if (this.defaultValue != null) { - ((JTextField) this.component).setText(this.defaultValue); - } - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("file".compareToIgnoreCase(this.type) == 0) { - this.component = new JList(Global.fileNames); - ((JList) this.component).setVisibleRowCount(1); - JScrollPane scroll = new JScrollPane(this.component); - - Box box = Box.createHorizontalBox(); - box.add(Box.createRigidArea(new Dimension(0, 100))); - box.add(scroll); - - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(box); - } - else if ("boolean".compareToIgnoreCase(this.type) == 0) { - this.component = new JCheckBox(); - if ((this.defaultValue != null) && (this.defaultValue.compareToIgnoreCase("true") == 0)) { - ((JCheckBox) this.component).setSelected(true); - } - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("format".compareToIgnoreCase(this.type) == 0) { - Vector < String > formats = new Vector < String > (); - for (String format: this.format) { - formats.addAll(Global.formats.getFormats(format).getFormats()); - } - this.component = new JComboBox(formats); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else if ("files".compareToIgnoreCase(this.type) == 0) { - JButton button = new JButton("file..."); - this.component = new JTextField(); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - this.panel.add(button); - Global.otherFileConcatenationChooser.put(button, (JTextField) this.component); - } - else if ("directory".compareToIgnoreCase(this.type) == 0) { - JButton button = new JButton("directory..."); - this.component = new JTextField(); - label.setLabelFor(this.component); - this.panel.add(label); - JPanel rightPanel = new JPanel(false); - rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.LINE_AXIS)); - rightPanel.add(this.component); - rightPanel.add(button); - this.panel.add(rightPanel); - Global.otherDirectoriesChooser.put(button, (JTextField) this.component); - } - else if ("choice".compareToIgnoreCase(this.type) == 0) { - this.component = new JComboBox(this.choices); - label.setLabelFor(this.component); - this.panel.add(label); - this.panel.add(this.component); - } - else { - System.out.println("Do not know how to read type " + this.type); - } - - return this.panel; - } - - - public JComponent getComponent() { - if (component == null) { - this.getPanel(); - } - return this.component; - } - - - private String getValue() { - if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("directory".equals(this.type)) || ("files".equals(this.type))) { - String s = ((JTextField) this.component).getText(); - if ("None".equals(s)) { - return ""; - } - return s; - } - if ("file".equals(this.type)) { - return (String) ((JList) this.component).getSelectedValue(); - } - if ("boolean".equals(this.type)) { - return ((JCheckBox) this.component).isSelected()? "true": "false"; - } - if ("format".equals(this.type)) { - return (String) ((JComboBox) this.component).getSelectedItem(); - } - return null; - } - - - public String checkValue() { - String value = this.getValue(); - if ((this.compulsory) && ((value == null) || ("".equals(value)))) { - return "Option '" + this.comment + "' has no value... Please specify it.\n"; - } - if ("int".equals(this.type)) { - if ((value != null) && (! "".equals(value)) && (! "None".equals(value))) { - try { - int i = Integer.parseInt(value); - } - catch (NumberFormatException e) { - return "Option '" + this.comment + "' should be an integer... Please correct it.\n"; - } - } - } - else if ("float".equals(this.type)) { - if ((value != null) && (! "".equals(value))) { - try { - float i = Float.parseFloat(value); - } - catch (NumberFormatException e) { - return "Option '" + this.comment + "' should be a float... Please correct it.\n"; - } - } - } - return null; - } - - - public LinkedList getCommand() { - LinkedList list = new LinkedList (); - - if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("format".equals(this.type)) || ("directory".equals(this.type)) || ("files".equals(this.type))) { - String value = this.getValue(); - if (value.length() == 0) { - return list; - } - list.add(this.identifier); - list.add(value); - return list; - } - if ("file".equals(this.type)) { - String fileName = (String) ((JList) this.component).getSelectedValue(); - if (fileName == null) { - return list; - } - list.add(this.identifier); - list.add(this.getValue()); - return list; - } - if ("boolean".equals(this.type)) { - if ("true".equals(this.getValue())) { - list.add(this.identifier); - } - return list; - } - return null; - } - - - public File getOutputFile() { - if (this.input) return null; - String format = ""; - if (this.format != null) { - format = this.format[0]; - } - if (this.associatedOption != null) { - format = this.associatedOption.getValue(); - } - return new File(this.getValue() + "." + format, Global.formats.getFormatType(format), format); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/PythonHelperReader.java --- a/SMART/Java/Sav/PythonHelperReader.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,323 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.io.File; -import java.io.*; -import java.util.regex.*; - -public class PythonHelperReader { - - String fileName; - Program program; - BufferedReader reader; - String message; - - public PythonHelperReader(String fileName) { - this.fileName = fileName; - this.reader = reader; - this.message = null; - } - - public void setReader(BufferedReader reader) { - this.reader = reader; - } - - public void run() { - this.program = new Program(); - boolean inBeginning = true; - boolean inUsage = false; - boolean afterUsage = false; - boolean inDescription = false; - boolean afterDescription = false; - boolean inOptions = false; - boolean inOptionBlank = false; - boolean inError = false; - String usage = null; - String description = null; - String option = null; - Vector options = new Vector < String > (); - String[] optionSplitted; - - // Parse file - try { - String line = null; - - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("Traceback")) { - this.message = "Problem with header of '" + this.fileName + "':\n" + line + "\n"; - inError = true; - inBeginning = false; - inUsage = false; - afterUsage = false; - inDescription = false; - afterDescription = false; - inOptions = false; - inOptionBlank = false; - } - else if (inError) { - this.message += line + "\n"; - } - else if (inBeginning) { - if (line.startsWith("Usage:")) { - inUsage = true; - inBeginning = false; - usage = line; - } - } - else if (inUsage) { - if ("".equals(line)) { - inUsage = false; - afterUsage = true; - } - else { - usage += " " + line; - } - } - else if (afterUsage) { - if (! "".equals(line)) { - description = line; - afterUsage = false; - inDescription = true; - } - } - else if (inDescription) { - if ("".equals(line)) { - inDescription = false; - afterDescription = true; - } - else { - description += " " + line; - } - } - else if (afterDescription) { - if (! "".equals(line)) { - afterDescription = false; - inOptions = true; - } - } - else if (inOptions) { - if ("".equals(line)) { - inOptions = false; - inOptionBlank = true; - } - else { - if (option == null) { - option = line; - } - else { - if (line.charAt(0) == '-') { - options.add(option); - option = line; - } - else { - option += " " + line; - } - } - } - } - else if (inOptionBlank) { - if (! "".equals(line)) { - inOptionBlank = false; - inOptions = true; - } - } - else { - this.message = "Something is wrong in the file '" + this.fileName + "'."; - return; - } - } - - reader.close(); - } - catch (FileNotFoundException e) { - this.message = "File " + this.fileName + " not found"; - return; - } - catch (IOException e) { - this.message = "IOException while reading file " + this.fileName; - return; - } - - if (inError) { - return; - } - - if (option != null) { - options.add(option); - } - - HashMap < String, ProgramOption > identifierToOptions = new HashMap < String, ProgramOption > (); - HashMap < ProgramOption, String > associatedOption = new HashMap < ProgramOption, String > (); - - if (usage == null) { - this.message = "Cannot read the usage of file " + this.fileName; - return; - } - program.setShortName(usage.split(" ")[1].trim()); - program.setName(description.split(":")[0].trim()); - - Pattern pattern = Pattern.compile("\\[Category: .*\\]"); - Matcher matcher = pattern.matcher(description); - if (matcher.find()) { - program.setSection(description.substring(matcher.start() + "[Category: ".length(), matcher.end() - 1)); - program.setDescription(description.substring(0, matcher.start() - 1).trim()); - } - else { - this.message = "Cannot find category in description '" + description + "' in file " + this.fileName; - return; - } - for (int i = 0; i < options.size(); i++) { - option = options.get(i).replace("\t", " "); - optionSplitted = option.split(" "); - option = ""; - for (int j = 3; j < optionSplitted.length; j++) { - option += optionSplitted[j] + " "; - } - - String identifier = optionSplitted[0].replace("-", "").replace(",", ""); - // Skip -h and -v options - if (("h".equals(identifier)) || ("v".equals(identifier))) - continue; - - ProgramOption programOption = new ProgramOption(); - programOption.setIdentifier("-" + identifier); - programOption.setComment(option.substring(0, option.indexOf("[")).trim()); - identifierToOptions.put(identifier, programOption); - - pattern = Pattern.compile("\\[[^\\]]*\\]"); - matcher = pattern.matcher(option); - while (matcher.find()) { - String inner = option.substring(matcher.start()+1, matcher.end()-1); - if (inner.contains(":")) { - String type = inner.substring(0, inner.indexOf(":")).trim(); - String value = inner.substring(inner.indexOf(":")+1).trim(); - // Types of the options - if ("format".compareToIgnoreCase(type) == 0) { - String currentWord = ""; - String rest = ""; - if (value.contains(" ")) { - int pos = value.indexOf(" "); - currentWord = value.substring(0, pos); - rest = value.substring(pos+1); - } - else { - currentWord = value; - } - // Output file type - if ("output".compareToIgnoreCase(currentWord) == 0) { - programOption.setInput(false); - int pos = rest.indexOf(" "); - currentWord = rest.substring(0, pos).trim(); - rest = rest.substring(pos+1).trim(); - } - // File (input or output file) - if ("file".compareToIgnoreCase(currentWord) == 0) { - programOption.setType("file"); - // Format given by an associated option (to be found later) - if (rest.startsWith("in format given by ")) { - associatedOption.put(programOption, rest.substring(rest.indexOf("format given by ") + "format given by ".length() + 1).trim()); - } - else { - if (! rest.startsWith("in ")) { - this.message = "Descriptor " + option + " does not have a proper format."; - return; - } - rest = rest.substring("in ".length()); - int pos = rest.indexOf(" format"); - if (pos == -1) { - this.message = "Descriptor " + option + " does not have a proper format."; - return; - } - programOption.setFormat(rest.substring(0, pos).trim().toLowerCase().split(" or ")); - } - } - // Format type - else if (rest.endsWith("file format")) { - programOption.setFormat((currentWord + " " + rest.substring(0, rest.indexOf("file format"))).trim().toLowerCase().split(" or ")); - programOption.setType("format"); - } - // Choice type - else if ("choice".compareToIgnoreCase(currentWord) == 0) { - programOption.setChoices(rest.replace("(", "").replace(")", "").split(", ")); - programOption.setType("choice"); - } - // Boolean type - else if ("bool".compareToIgnoreCase(currentWord) == 0) { - programOption.setType("boolean"); - } - // Other type - else { - programOption.setType(currentWord); - } - } - // Default value - else if ("default".compareToIgnoreCase(type) == 0) { - programOption.setDefault(value); - } - else { - this.message = "Do not understand option descriptor '" + inner + "'."; - return; - } - } - else { - // Compulsory option - if ("compulsory".compareToIgnoreCase(inner) == 0) { - programOption.setCompulsory(true); - } - else { - this.message = "Do not understand option descriptor '" + inner + "'."; - return; - } - } - } - program.addOption(programOption); - } - - // Set associated option - Iterator it = associatedOption.keySet().iterator(); - while (it.hasNext()) { - ProgramOption programOption = (ProgramOption) it.next(); - programOption.setAssociatedOption(identifierToOptions.get(associatedOption.get(programOption))); - } - } - - public String getMessage () { - return this.message; - } - - public Program getProgram () { - return this.program; - } -} - - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/PythonProgramFinder.java --- a/SMART/Java/Sav/PythonProgramFinder.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.io.*; -import java.util.*; - -public class PythonProgramFinder { - - String dirName; - Vector < Program > programs; - - public PythonProgramFinder(String dirName) { - this.dirName = dirName; - } - - public String findPrograms() { - java.io.File directory = new java.io.File(this.dirName); - String[] files = directory.list(new FilenameFilter() {public boolean accept(java.io.File dir, String name) {return ((! name.startsWith(".")) && (! name.startsWith("test")) && ((new java.io.File(dir, name)).isFile()) && (name.endsWith(".py")));}}); - this.programs = new Vector < Program > (); - - for (int i = 0; i < files.length; i++) { - String[] commandList = {Global.pythonCommand, "Python" + java.io.File.separator + files[i], "-h"}; - String command = ""; - for (int j = 0; j < commandList.length; j++) { - command += commandList[j] + " "; - } - ProcessBuilder pb = new ProcessBuilder(commandList); - pb = pb.redirectErrorStream(true); - Map env = pb.environment(); - env.put("PYTHONPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTPATH", System.getProperty("user.dir") + java.io.File.separator + "Python"); - env.put("SMARTMYSQLPATH", Global.mysqlCommand); - env.put("SMARTRPATH", Global.rCommand); - - PythonHelperReader helperReader = new PythonHelperReader(files[i]); - try { - final Process process = pb.start(); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - helperReader.setReader(br); - helperReader.run(); - } - catch (IOException e) { - e.printStackTrace(); - return "Command '" + command + "' failed (I/O error)...\n"; - } - String comments = helperReader.getMessage(); - if (comments != null) return comments; - Program program = helperReader.getProgram(); - if ("Personnal".compareToIgnoreCase(program.getSection()) != 0) { - this.programs.add(program); - } - } - return null; - } - - public Vector getPrograms () { - return this.programs; - } -} - diff -r 769e306b7933 -r 86c781421239 SMART/Java/Sav/Smart.java --- a/SMART/Java/Sav/Smart.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,489 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; - - -public class Smart extends JPanel implements ActionListener { - - String version = "1.0.2"; - - JFrame mainFrame; - JButton openButton; - JButton comparisonGoButton; - - JComboBox formatTypes; - JComboBox fileFormats; - String[] emptyFormats = {"Choose a type first..."}; - - JFrame askFrame; - JButton pythonButton; - JButton mySqlButton; - JButton rButton; - - HashMap callingProgram; - - // comparison - JList comparisonFile1List; - JList comparisonFile2List; - JTextField comparisonOutputTextField; - JTextField comparisonFiveQueryExtensionTextField; - JCheckBox comparisonColinearCheckBox; - JCheckBox comparisonAntisenseCheckBox; - JCheckBox comparisonInvertCheckBox; - - JList fileList; - JTextArea logArea; - - // progress bar - JLabel messageField; - JProgressBar progressBar; - JLabel etaField; - - // process - Program currentProgram; - Process process; - javax.swing.Timer processTimer; - - - int previousStatus; - - public Smart() { - super(new BorderLayout()); - - callingProgram = new HashMap (); - - previousStatus = -1; - - processTimer = new javax.swing.Timer(1000, this); - processTimer.stop(); - - // Ask frame buttons - pythonButton = new JButton("find..."); - mySqlButton = new JButton("find..."); - rButton = new JButton("find..."); - - // Get available formats - FormatsReader formatReader = new FormatsReader(Global.smartFormatsFileName); - if (! formatReader.read()) { - System.out.println("Something was wrong while reading file format..."); - } - - // Get screen size - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - - // Log - logArea = new JTextArea(512, Global.logAreaSize); - logArea.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.22))); - logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize())); - JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - TitledBorder logBorder = BorderFactory.createTitledBorder("Log"); - logScroll.setBorder(logBorder); - logArea.append("Using S-MART " + version + "\n"); - - GridLayout horizontalLayout = new GridLayout(1, 0); - - // check configuration - this.readConfigurationFile(); - this.checkConfiguration(); - - // Tabs - JTabbedPane tabbedPane = new JTabbedPane(); - tabbedPane.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.75))); - - // File panel - JPanel filePanel = new JPanel(false); - filePanel.setLayout(new FlowLayout()); - tabbedPane.add("Files", filePanel); - - // Format sub-panel - JPanel formatComboPanel = new JPanel(false); - JPanel formatPanel = new JPanel(false); - Vector formatTypesString = Global.formats.getFormatTypes(); - formatPanel.setLayout(horizontalLayout); - formatTypesString.insertElementAt("Choose the format type", 0); - JLabel formatLabel = new JLabel("Format"); - formatTypes = new JComboBox(formatTypesString); - fileFormats = new JComboBox(emptyFormats); - formatLabel.setLabelFor(fileFormats); - formatTypes.addActionListener(this); - formatComboPanel.add(formatTypes); - formatComboPanel.add(fileFormats); - - formatPanel.add(formatLabel); - formatPanel.add(formatComboPanel); - - // File chooser sub-panel - JPanel fileChooserPanel = new JPanel(false); - fileChooserPanel.setLayout(horizontalLayout); - JLabel fileLabel = new JLabel("File"); - openButton = new JButton("Open a File..."); - openButton.addActionListener(this); - - fileChooserPanel.add(fileLabel); - fileChooserPanel.add(openButton); - - // File list sub-panel - JPanel existingFilesPanel = new JPanel(false); - existingFilesPanel.setLayout(horizontalLayout); - existingFilesPanel.setMinimumSize(new Dimension(10000, 10000)); - JLabel existingFilesLabel = new JLabel("Existing files"); - Box fileListBox = Box.createHorizontalBox(); - fileListBox.add(Box.createRigidArea(new Dimension(0, 100))); - JList fileList = new JList(Global.fileNames); - fileList.setLayoutOrientation(JList.HORIZONTAL_WRAP); - fileList.setVisibleRowCount(4); - JScrollPane listScroller = new JScrollPane(fileList); - fileListBox.add(listScroller); - - existingFilesPanel.add(existingFilesLabel); - existingFilesPanel.add(fileListBox); - - // File panel layout - Box box = Box.createVerticalBox(); - box.add(formatPanel); - box.add(fileChooserPanel); - box.add(existingFilesPanel); - filePanel.add(box); - - // Program panels - TreeMap < String, JTabbedPane > panels = new TreeMap < String, JTabbedPane >(); - PythonProgramFinder programFinder = new PythonProgramFinder("Python"); - String comments = programFinder.findPrograms(); - if (comments != null) { - logArea.append(comments); - } - for (int i = 0; i < programFinder.getPrograms().size(); i++) { - Program program = programFinder.getPrograms().get(i); - JPanel programPanel = program.getPanel(); - String section = program.getSection(); - JTabbedPane sectionPane = null; - if (panels.containsKey(section)) { - sectionPane = panels.get(section); - } - else { - sectionPane = new JTabbedPane(); - tabbedPane.addTab(section, sectionPane); - panels.put(section, sectionPane); - } - - JScrollPane programScroll = new JScrollPane(programPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - sectionPane.addTab(program.getName(), programScroll); - - JButton button = program.getButton(); - button.addActionListener(this); - callingProgram.put(button, program); - } - - // Progress bar - JPanel progressPanel = new JPanel(new GridLayout(1, 0), false); - progressPanel.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.02))); - messageField = new JLabel(); - progressBar = new JProgressBar(0, 100); - etaField = new JLabel(); - messageField.setHorizontalAlignment(JLabel.LEFT); - progressBar.setValue(0); - etaField.setHorizontalAlignment(JLabel.RIGHT); - progressBar.setStringPainted(true); - progressPanel.add(messageField); - progressPanel.add(progressBar); - progressPanel.add(etaField); - - add(tabbedPane, BorderLayout.PAGE_START); - add(logScroll, BorderLayout.CENTER); - add(progressPanel, BorderLayout.PAGE_END); - } - - - public boolean checkConfiguration() { - int status = this.testConfiguration(); - - if (status == previousStatus) { - logArea.append("S-MART does not seem to work properly... Tried to manage it by myself, unsuccessfully... Check documentation for further explanation...\n"); - return false; - } - - switch (status) { - case 0: - return true; - case 1: - logArea.append("S-MART does not seem to work properly... Check documentation for further explanation...\n"); - break; - case 3: - this.askWhereIsProgram("python"); - break; - case 4: - break; - case 5: - this.askWhereIsProgram("mySQL"); - break; - case 6: - this.askWhereIsProgram("R"); - break; - case 7: - logArea.append("Please install 'ColorBrewer' R package...\n"); - break; - default: - logArea.append("Weird configuration test status: " + status + "...\n"); - } - previousStatus = status; - return true; - } - - - public int testConfiguration() { - String[] command = {Global.pythonCommand, "Python" + java.io.File.separator + "testInstall.py"}; - ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField); - String line; - launcher.execute(); - (new Exception("hello")).printStackTrace(); - return launcher.getExitValue(); - } - - - public void readConfigurationFile() { - java.io.File file = new java.io.File(Global.smartConfFileName); - String line = null; - - if (! file.exists()) { - return; - } - - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("python:")) Global.pythonCommand = line.substring("python:".length()).trim(); - else if (line.startsWith("mysql:")) Global.mysqlCommand = line.substring("mysql:".length()).trim(); - else if (line.startsWith("r:")) Global.rCommand = line.substring("r:".length()).trim(); - } - reader.close(); - } - catch (FileNotFoundException e) { - logArea.append("Configuration file is empty: " + e.getMessage() + "!\n"); - return; - } - catch (IOException e) { - logArea.append("Weird with configuration file: " + e.getMessage() + "!\n"); - return; - } - } - - - public void askWhereIsProgram(String program) { - askFrame = new JFrame("Where is " + program + "?"); - askFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JLabel label = new JLabel("Where is your " + program + " (or " + program + ".exe) file?"); - JButton button = null; - if ("python".equals(program)) { - button = pythonButton; - } - else if ("mySQL".equals(program)) { - button = mySqlButton; - } - else if ("R".equals(program)) { - button = rButton; - } - else { - logArea.append("Problem with the button!\n"); - } - askFrame.getContentPane().add(label, BorderLayout.WEST); - askFrame.getContentPane().add(button, BorderLayout.EAST); - button.addActionListener(this); - askFrame.pack(); - askFrame.setVisible(true); - askFrame.setAlwaysOnTop(true); - } - - - public void actionPerformed(ActionEvent e) { - - // Python command chooser - if (e.getSource() == pythonButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.pythonCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("python: " + Global.pythonCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // MySQL command chooser - else if (e.getSource() == mySqlButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.mysqlCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("mysql: " + Global.mysqlCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // R command chooser - else if (e.getSource() == rButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.rCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("r: " + Global.rCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // Format type - else if (e.getSource() == formatTypes) { - fileFormats.removeAllItems(); - Vector < String > selectedFormats = Global.formats.getFormats((String) formatTypes.getSelectedItem()).getFormats(); - for (int i = 0; i < selectedFormats.size(); i++) { - fileFormats.addItem(selectedFormats.get(i)); - } - } - // Main file chooser - else if (e.getSource() == openButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - String fileName = chooser.getSelectedFile().getPath(); - Global.fileNames.addElement(fileName); - Global.files.addFile(fileName, (String) formatTypes.getSelectedItem(), (String) fileFormats.getSelectedItem()); - } - } - // Other file choosers - else if (Global.otherFilesChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherFilesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - textField.setText(chooser.getSelectedFile().getPath()); - } - } - // Other directories choosers - else if (Global.otherDirectoriesChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherDirectoriesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - textField.setText(chooser.getSelectedFile().getPath()); - } - } - else if (Global.otherFileConcatenationChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherDirectoriesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - String text = textField.getText(); - if ((text == null) || ("".equals(text))) { - textField.setText(chooser.getSelectedFile().getPath()); - } - else { - textField.setText(text + "," + chooser.getSelectedFile().getPath()); - } - } - } - // Programs - else { - currentProgram = callingProgram.get(e.getSource()); - String comment = currentProgram.checkValues(); - if (comment != null) { - logArea.append(comment); - return; - } - LinkedList command = currentProgram.getCommand(); - ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField); - launcher.execute(); - Vector < File > outputFiles = currentProgram.getOutputFiles(); - for (int i = 0; i < outputFiles.size(); i++) { - File file = outputFiles.get(i); - if (file.getFormatType().compareToIgnoreCase("other") != 0) { - Global.fileNames.addElement(file.getName()); - Global.files.addFile(file); - } - } - currentProgram = null; - } - } - - - private static void createAndShowGUI() { - // Create and set up the window. - JFrame mainFrame = new JFrame("S-Mart"); - mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Create and set up the content pane. - JComponent newContentPane = new Smart(); - newContentPane.setOpaque(true); - mainFrame.setContentPane(newContentPane); - - // Display the window. - mainFrame.pack(); - mainFrame.setVisible(true); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - mainFrame.setBounds(0, 0, screenSize.width, screenSize.height); - } - - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/Smart.jar Binary file SMART/Java/Smart.jar has changed diff -r 769e306b7933 -r 86c781421239 SMART/Java/Smart.java --- a/SMART/Java/Smart.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,668 +0,0 @@ -/** - * - * Copyright INRA-URGI 2009-2010 - * - * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, - * modify and/ or redistribute the software under the terms of the CeCILL - * license as circulated by CEA, CNRS and INRIA at the following URL - * "http://www.cecill.info". - * - * As a counterpart to the access to the source code and rights to copy, - * modify and redistribute granted by the license, users are provided only - * with a limited warranty and the software's author, the holder of the - * economic rights, and the successive licensors have only limited - * liability. - * - * In this respect, the user's attention is drawn to the risks associated - * with loading, using, modifying and/or developing or reproducing the - * software by the user in light of its specific status of free software, - * that may mean that it is complicated to manipulate, and that also - * therefore means that it is reserved for developers and experienced - * professionals having in-depth computer knowledge. Users are therefore - * encouraged to load and test the software's suitability as regards their - * requirements in conditions enabling the security of their systems and/or - * data to be ensured and, more generally, to use and operate it in the - * same conditions as regards security. - * - * The fact that you are presently reading this means that you have had - * knowledge of the CeCILL license and that you accept its terms. - * - */ -import java.util.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowAdapter; -import java.io.*; -import javax.swing.*; -import javax.swing.filechooser.*; -import javax.swing.border.*; -import javax.swing.SwingUtilities; -import java.util.prefs.BackingStoreException; - - -public class Smart extends JPanel implements ActionListener { - - String version = "1.1.0"; - - JFrame mainFrame; - JButton openButton; - JButton resetFileButton; - - JComboBox formatTypes; - JComboBox fileFormats; - String[] emptyFormats = {"Choose a type first..."}; - - JFrame askFrame; - JButton pythonButton; - JButton mySqlButton; - JButton rButton; - - HashMap callingProgram; - - static JList fileList; - static JTextArea logArea; - - // progress bar - static JLabel messageField; - static JProgressBar progressBar; - static JLabel etaField; - - // process - Program currentProgram; - Process process; - javax.swing.Timer processTimer; - - - int previousStatus; - - public Smart() { - super(new BorderLayout()); - - callingProgram = new HashMap (); - - previousStatus = -1; - - processTimer = new javax.swing.Timer(1000, this); - processTimer.stop(); - - // Ask frame buttons - pythonButton = new JButton("find..."); - mySqlButton = new JButton("find..."); - rButton = new JButton("find..."); - - // Get available formats - FormatsReader formatReader = new FormatsReader(Global.smartFormatsFileName); - if (! formatReader.read()) { - System.out.println("Something was wrong while reading file format..."); - } - - // Get screen size - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - - // Log - logArea = new JTextArea(512, Global.logAreaSize); - logArea.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.22))); - logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize())); - JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - TitledBorder logBorder = BorderFactory.createTitledBorder("Log"); - logScroll.setBorder(logBorder); - logArea.append("Using S-MART " + version + "\n"); - - GridLayout horizontalLayout = new GridLayout(1, 0); - - // check configuration - this.readConfigurationFile(); - if (System.getProperty("os.name").matches("(?i).*Windows.*")) { - if (! this.checkDefaultDir()) { - this.checkRegistries(); - } - } - this.checkConfiguration(); - - // Tabs - JTabbedPane tabbedPane = new JTabbedPane(); - tabbedPane.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.75))); - - // File panel - JPanel filePanel = new JPanel(false); - filePanel.setLayout(new FlowLayout()); - tabbedPane.add("Files", filePanel); - - // Format sub-panel - JPanel formatComboPanel = new JPanel(false); - JPanel formatPanel = new JPanel(false); - Vector formatTypesString = Global.formats.getFormatTypes(); - formatPanel.setLayout(horizontalLayout); - formatTypesString.insertElementAt("Choose the format type", 0); - JLabel formatLabel = new JLabel("Format"); - formatTypes = new JComboBox(formatTypesString); - fileFormats = new JComboBox(emptyFormats); - formatLabel.setLabelFor(fileFormats); - formatTypes.addActionListener(this); - formatComboPanel.add(formatTypes); - formatComboPanel.add(fileFormats); - - formatPanel.add(formatLabel); - formatPanel.add(formatComboPanel); - - // File chooser sub-panel - JPanel fileChooserPanel = new JPanel(false); - fileChooserPanel.setLayout(horizontalLayout); - JLabel fileLabel = new JLabel("File"); - openButton = new JButton("Open a File..."); - openButton.addActionListener(this); - - fileChooserPanel.add(fileLabel); - fileChooserPanel.add(openButton); - - // File list sub-panel - JPanel existingFilesPanel = new JPanel(false); - existingFilesPanel.setLayout(horizontalLayout); - existingFilesPanel.setMinimumSize(new Dimension(10000, 10000)); - JLabel existingFilesLabel = new JLabel("Existing files"); - Box fileListBox = Box.createHorizontalBox(); - fileListBox.add(Box.createRigidArea(new Dimension(0, 100))); - fileList = new JList(new DefaultListModel()); - fileList.setLayoutOrientation(JList.HORIZONTAL_WRAP); - fileList.setVisibleRowCount(4); - JScrollPane listScroller = new JScrollPane(fileList); - fileListBox.add(listScroller); - - existingFilesPanel.add(existingFilesLabel); - existingFilesPanel.add(fileListBox); - - // Reset sub-panel - JPanel resetFilePanel = new JPanel(false); - resetFileButton = new JButton("Reset"); - resetFileButton.addActionListener(this); - - // File panel layout - Box box = Box.createVerticalBox(); - box.add(formatPanel); - box.add(fileChooserPanel); - box.add(existingFilesPanel); - box.add(resetFileButton); - filePanel.add(box); - - // Program panels - TreeMap < String, JTabbedPane > panels = new TreeMap < String, JTabbedPane >(); - PythonProgramFinder programFinder = new PythonProgramFinder("Python"); - String comments = programFinder.findPrograms(); - if (comments != null) { - logArea.append(comments); - } - for (int i = 0; i < programFinder.getPrograms().size(); i++) { - Program program = programFinder.getPrograms().get(i); - JPanel programPanel = program.getPanel(); - String section = program.getSection(); - JTabbedPane sectionPane = null; - if (panels.containsKey(section)) { - sectionPane = panels.get(section); - } - else { - sectionPane = new JTabbedPane(); - tabbedPane.addTab(section, sectionPane); - panels.put(section, sectionPane); - } - - JScrollPane programScroll = new JScrollPane(programPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - sectionPane.addTab(program.getName(), programScroll); - - JButton button = program.getButton(); - button.addActionListener(this); - callingProgram.put(button, program); - } - - // Progress bar - JPanel progressPanel = new JPanel(new GridLayout(1, 0), false); - progressPanel.setPreferredSize(new Dimension(screenSize.width, (int) (screenSize.height * 0.02))); - messageField = new JLabel(); - progressBar = new JProgressBar(0, 100); - etaField = new JLabel(); - messageField.setHorizontalAlignment(JLabel.LEFT); - progressBar.setValue(0); - etaField.setHorizontalAlignment(JLabel.RIGHT); - progressBar.setStringPainted(true); - progressPanel.add(messageField); - progressPanel.add(progressBar); - progressPanel.add(etaField); - - add(tabbedPane, BorderLayout.PAGE_START); - add(logScroll, BorderLayout.CENTER); - add(progressPanel, BorderLayout.PAGE_END); - } - - - public String checkSubKey(int hkey, String key, String subKey, String trace) { - try { - for (String currentSubKey: WindowsRegistry.readStringSubKeys(hkey, key)) { - trace += "Looking at sub-key " + currentSubKey; - if (currentSubKey.matches(subKey)) { - trace += " OK"; - return subKey; - } - trace += "\n"; - } - } - catch (Exception e) { - final Writer writer = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(writer); - e.printStackTrace(printWriter); - trace += writer.toString(); - } - return null; - } - - public void debugRegistry(int hkey, String keys[], String valueName, String trace) { - String concatenatedKeys = ""; - String selectedKey = null; - for (String key: keys) { - selectedKey = checkSubKey(hkey, concatenatedKeys, key, trace); - if (selectedKey != null) { - concatenatedKeys += "\\" + selectedKey; - } - else { - return; - } - } - } - - - public String checkRegistry(int hkey, String key, String valueName, String trace) { - String result = null; - try { - result = WindowsRegistry.readString(hkey, key, valueName); - } - catch (Exception e) { - final Writer writer = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(writer); - e.printStackTrace(printWriter); - trace += result.toString(); - } - return result; - } - - - public boolean checkDefaultDir() { - String defaultPythonPath = System.getProperty("user.dir") + "\\Apps\\Python\\python.exe"; - java.io.File defaultPythonFile = new java.io.File(defaultPythonPath); - String defaultRPath = System.getProperty("user.dir") + "\\Apps\\R\\bin\\R.exe"; - java.io.File defaultRFile = new java.io.File(defaultRPath); - if (defaultPythonFile.exists()) { - Global.pythonCommand = defaultPythonPath; - logArea.append("Python found in default directory: " + defaultPythonPath + "\n"); - } - else { - logArea.append("Python not found in default directory: " + defaultPythonPath + "\n"); - return false; - } - if (defaultRFile.exists()) { - logArea.append("R found in default directory: " + defaultRPath + "\n"); - Global.rCommand = defaultRPath; - return true; - } - logArea.append("Python not found in default directory: " + defaultPythonPath + "\n"); - return false; - } - - - public boolean checkRegistries() { - String pythonDir = null; - String validValue = null; - String rDir; - String[] pythonFlavors = {"2.5", "2.6", "2.7"}; - String[] pythonDirectories = {"Python25", "Python26", "Python27"}; - String[] rDirectories = {"R-2.11.0", "R-2.11.0-x64"}; - String trace = ""; - for (String pythonFlavor: pythonFlavors) { - pythonDir = checkRegistry(WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Python\\PythonCore\\" + pythonFlavor + "\\InstallPath", "", trace); - if (pythonDir != null) { - break; - } - } - if (pythonDir == null) { - try { - logArea.append("Using OS: " + WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName") + "\n"); - } - catch (Exception e) { - logArea.append("Cannot do simple registry test. Strange...\n"); - } - String keys[] = {"SOFTWARE", "Python", "PythonCore", "2.[567]", "InstallPath"}; - debugRegistry(WindowsRegistry.HKEY_LOCAL_MACHINE, keys, "", trace); - logArea.append("S-MART cannot find Python installation directory using registry. Trying desperate move...\n"); - for (String currentDirectory: pythonDirectories) { - String fileName = "C:\\" + currentDirectory; - java.io.File file = new java.io.File(fileName); - if (file.exists()) { - pythonDir = fileName; - break; - } - } - if (pythonDir == null) { - logArea.append("S-MART cannot find Python installation directory despite all my efforts...\n" + trace); - return false; - } - } - rDir = checkRegistry(WindowsRegistry.HKEY_LOCAL_MACHINE, "SOFTWARE\\R-core\\R", "InstallPath", trace); - if (rDir == null) { - logArea.append("S-MART cannot find R installation directory using registry. Trying desperate move...\n"); - for (String currentDirectory: rDirectories) { - String fileName = "C:\\Program Files\\R\\" + currentDirectory; - java.io.File file = new java.io.File(fileName); - if (file.exists()) { - rDir = fileName; - break; - } - } - if (rDir == null) { - logArea.append("S-MART cannot find R installation directory despite all my efforts...\n" + trace); - return false; - } - } - Global.pythonCommand = pythonDir + "\\" + "python.exe"; - Global.rCommand = rDir + "\\" + "bin\\R.exe"; - return true; - } - - - public boolean checkConfiguration() { - int status = this.testConfiguration(); - - if (status == previousStatus) { - logArea.append("S-MART does not seem to work properly... Tried to manage it by myself, unsuccessfully... Check documentation for further explanation...\n"); - return false; - } - - switch (status) { - case 0: - return true; - case 1: - logArea.append("S-MART does not seem to work properly... Check documentation for further explanation...\n"); - break; - case 3: - this.askWhereIsProgram("python"); - break; - case 4: - break; - case 5: - this.askWhereIsProgram("mySQL"); - break; - case 6: - this.askWhereIsProgram("R"); - break; - case 7: - logArea.append("Please install 'ColorBrewer' R package...\n"); - break; - default: - logArea.append("Weird configuration test status: " + status + "...\n"); - } - previousStatus = status; - return true; - } - - - public int testConfiguration() { - String[] command = {Global.pythonCommand, "Python" + java.io.File.separator + "testInstall.py"}; - ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField); - String line; - launcher.execute(); - return launcher.getExitValue(); - } - - - public void readConfigurationFile() { - java.io.File file = new java.io.File(Global.smartConfFileName); - String line = null; - - if (! file.exists()) { - return; - } - - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("python:")) Global.pythonCommand = line.substring("python:".length()).trim(); - else if (line.startsWith("mysql:")) Global.mysqlCommand = line.substring("mysql:".length()).trim(); - else if (line.startsWith("r:")) Global.rCommand = line.substring("r:".length()).trim(); - } - reader.close(); - } - catch (FileNotFoundException e) { - logArea.append("Configuration file is empty: " + e.getMessage() + "!\n"); - return; - } - catch (IOException e) { - logArea.append("Weird with configuration file: " + e.getMessage() + "!\n"); - return; - } - } - - - public void askWhereIsProgram(String program) { - askFrame = new JFrame("Where is " + program + "?"); - askFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JLabel label = new JLabel("Where is your " + program + " (or " + program + ".exe) file?"); - JButton button = null; - if ("python".equals(program)) { - button = pythonButton; - } - else if ("mySQL".equals(program)) { - button = mySqlButton; - } - else if ("R".equals(program)) { - button = rButton; - } - else { - logArea.append("Problem with the button!\n"); - } - askFrame.getContentPane().add(label, BorderLayout.WEST); - askFrame.getContentPane().add(button, BorderLayout.EAST); - button.addActionListener(this); - askFrame.pack(); - askFrame.setVisible(true); - askFrame.setAlwaysOnTop(true); - } - - - public void actionPerformed(ActionEvent e) { - - // Python command chooser - if (e.getSource() == pythonButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.pythonCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("python: " + Global.pythonCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // MySQL command chooser - else if (e.getSource() == mySqlButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.mysqlCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("mysql: " + Global.mysqlCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // R command chooser - else if (e.getSource() == rButton) { - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - Global.rCommand = chooser.getSelectedFile().getPath(); - askFrame.setVisible(false); - askFrame.dispose(); - try { - BufferedWriter out = new BufferedWriter(new FileWriter(Global.smartConfFileName, true)); - out.write("r: " + Global.rCommand + "\n"); - out.close(); - } - catch (IOException exception) { - logArea.append("Cannot write configuration file!\n"); - } - } - this.checkConfiguration(); - } - // Format type - else if (e.getSource() == formatTypes) { - if (((String) formatTypes.getSelectedItem()).startsWith("Choose")) { - return; - } - fileFormats.removeAllItems(); - Vector < String > selectedFormats = Global.formats.getFormats((String) formatTypes.getSelectedItem()).getFormats(); - for (int i = 0; i < selectedFormats.size(); i++) { - fileFormats.addItem(selectedFormats.get(i)); - } - } - // Main file chooser - else if (e.getSource() == openButton) { - if (((String) formatTypes.getSelectedItem()).startsWith("Choose")) { - logArea.append("Please choose a type and format before selecting a file!\n"); - return; - } - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - String fileName = chooser.getSelectedFile().getPath(); - Global.fileNames.addElement(fileName); - Global.files.addFile(fileName, (String) formatTypes.getSelectedItem(), (String) fileFormats.getSelectedItem()); - DefaultListModel defaultListModel = (DefaultListModel) fileList.getModel(); - defaultListModel.addElement(fileName); - } - } - // Reset file chooser - else if (e.getSource() == resetFileButton) { - Global.files.clear(); - Global.fileNames.clear(); - DefaultListModel defaultListModel = (DefaultListModel) fileList.getModel(); - defaultListModel.clear(); - } - // Other file choosers - else if (Global.otherFilesChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherFilesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - textField.setText(chooser.getSelectedFile().getPath()); - } - } - // Other directories choosers - else if (Global.otherDirectoriesChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherDirectoriesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - textField.setText(chooser.getSelectedFile().getPath()); - } - } - else if (Global.otherFileConcatenationChooser.containsKey(e.getSource())) { - JTextField textField = Global.otherDirectoriesChooser.get(e.getSource()); - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) { - String text = textField.getText(); - if ((text == null) || ("".equals(text))) { - textField.setText(chooser.getSelectedFile().getPath()); - } - else { - textField.setText(text + "," + chooser.getSelectedFile().getPath()); - } - } - } - // Programs - else { - currentProgram = callingProgram.get(e.getSource()); - String comment = currentProgram.checkValues(); - if (comment != null) { - logArea.append(comment); - return; - } - LinkedList command = currentProgram.getCommand(); - ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField); - launcher.execute(); - Vector < File > outputFiles = currentProgram.getOutputFiles(); - for (int i = 0; i < outputFiles.size(); i++) { - File file = outputFiles.get(i); - if (file.getFormatType().compareToIgnoreCase("other") != 0) { - Global.fileNames.addElement(file.getName()); - Global.files.addFile(file); - } - } - currentProgram = null; - } - } - - - private static void removeTmpFiles() { - logArea.append("You want to quit already?\nRemoving temporary files..."); - String[] command = {Global.pythonCommand, "Python" + java.io.File.separator + "removeAllTmpTables.py"}; - ProgramLauncher launcher = new ProgramLauncher(command, logArea, messageField, progressBar, etaField); - launcher.execute(); - logArea.append(" done.\nNow quitting.\nBye!"); - } - - - private static void printJavaVersions() { - String[] pro = {"java.version", "java.vm.version", "java.runtime.version"}; - - Properties properties = System.getProperties(); - for (int i = 0; i < pro.length; i++) { - logArea.append(pro[i] + ": " + properties.getProperty(pro[i]) + "\n"); - } - } - - private static void createAndShowGUI() { - // Create and set up the window. - JFrame mainFrame = new JFrame("S-Mart"); - mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - //Create and set up the content pane. - JComponent newContentPane = new Smart(); - newContentPane.setOpaque(true); - mainFrame.setContentPane(newContentPane); - - // Display the window. - mainFrame.pack(); - mainFrame.setVisible(true); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - mainFrame.setBounds(0, 0, screenSize.width, screenSize.height); - printJavaVersions(); - - // Remove tmp file while quitting. - mainFrame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - removeTmpFiles(); - } - }); - } - - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - createAndShowGUI(); - } - }); - } -} diff -r 769e306b7933 -r 86c781421239 SMART/Java/SmartInstaller.jar Binary file SMART/Java/SmartInstaller.jar has changed diff -r 769e306b7933 -r 86c781421239 SMART/Java/WindowsRegistry.java --- a/SMART/Java/WindowsRegistry.java Fri Jan 18 04:54:14 2013 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,387 +0,0 @@ -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.ArrayList; -import java.util.List; -import java.util.prefs.Preferences; - -public class WindowsRegistry { - public static final int HKEY_CURRENT_USER = 0x80000001; - public static final int HKEY_LOCAL_MACHINE = 0x80000002; - public static final int REG_SUCCESS = 0; - public static final int REG_NOTFOUND = 2; - public static final int REG_ACCESSDENIED = 5; - - private static final int KEY_ALL_ACCESS = 0xf003f; - private static final int KEY_READ = 0x20019; - private static Preferences userRoot = Preferences.userRoot(); - private static Preferences systemRoot = Preferences.systemRoot(); - private static Class userClass = userRoot.getClass(); - private static Method regOpenKey = null; - private static Method regCloseKey = null; - private static Method regQueryValueEx = null; - private static Method regEnumValue = null; - private static Method regQueryInfoKey = null; - private static Method regEnumKeyEx = null; - private static Method regCreateKeyEx = null; - private static Method regSetValueEx = null; - private static Method regDeleteKey = null; - private static Method regDeleteValue = null; - - static { - try { - regOpenKey = userClass.getDeclaredMethod("WindowsRegOpenKey", - new Class[] { int.class, byte[].class, int.class }); - regOpenKey.setAccessible(true); - regCloseKey = userClass.getDeclaredMethod("WindowsRegCloseKey", - new Class[] { int.class }); - regCloseKey.setAccessible(true); - regQueryValueEx = userClass.getDeclaredMethod("WindowsRegQueryValueEx", - new Class[] { int.class, byte[].class }); - regQueryValueEx.setAccessible(true); - regEnumValue = userClass.getDeclaredMethod("WindowsRegEnumValue", - new Class[] { int.class, int.class, int.class }); - regEnumValue.setAccessible(true); - regQueryInfoKey = userClass.getDeclaredMethod("WindowsRegQueryInfoKey1", - new Class[] { int.class }); - regQueryInfoKey.setAccessible(true); - regEnumKeyEx = userClass.getDeclaredMethod( - "WindowsRegEnumKeyEx", new Class[] { int.class, int.class, - int.class }); - regEnumKeyEx.setAccessible(true); - regCreateKeyEx = userClass.getDeclaredMethod( - "WindowsRegCreateKeyEx", new Class[] { int.class, - byte[].class }); - regCreateKeyEx.setAccessible(true); - regSetValueEx = userClass.getDeclaredMethod( - "WindowsRegSetValueEx", new Class[] { int.class, - byte[].class, byte[].class }); - regSetValueEx.setAccessible(true); - regDeleteValue = userClass.getDeclaredMethod( - "WindowsRegDeleteValue", new Class[] { int.class, - byte[].class }); - regDeleteValue.setAccessible(true); - regDeleteKey = userClass.getDeclaredMethod( - "WindowsRegDeleteKey", new Class[] { int.class, - byte[].class }); - regDeleteKey.setAccessible(true); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private WindowsRegistry() { } - - /** - * Read a value from key and value name - * @param hkey HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE - * @param key - * @param valueName - * @return the value - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static String readString(int hkey, String key, String valueName) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - if (hkey == HKEY_LOCAL_MACHINE) { - return readString(systemRoot, hkey, key, valueName); - } - else if (hkey == HKEY_CURRENT_USER) { - return readString(userRoot, hkey, key, valueName); - } - else { - throw new IllegalArgumentException("hkey=" + hkey); - } - } - - /** - * Read value(s) and value name(s) form given key - * @param hkey HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE - * @param key - * @return the value name(s) plus the value(s) - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static Map readStringValues(int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - if (hkey == HKEY_LOCAL_MACHINE) { - return readStringValues(systemRoot, hkey, key); - } - else if (hkey == HKEY_CURRENT_USER) { - return readStringValues(userRoot, hkey, key); - } - else { - throw new IllegalArgumentException("hkey=" + hkey); - } - } - - /** - * Read the value name(s) from a given key - * @param hkey HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE - * @param key - * @return the value name(s) - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static List readStringSubKeys(int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - if (hkey == HKEY_LOCAL_MACHINE) { - return readStringSubKeys(systemRoot, hkey, key); - } - else if (hkey == HKEY_CURRENT_USER) { - return readStringSubKeys(userRoot, hkey, key); - } - else { - throw new IllegalArgumentException("hkey=" + hkey); - } - } - - /** - * Create a key - * @param hkey HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE - * @param key - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static void createKey(int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int [] ret; - if (hkey == HKEY_LOCAL_MACHINE) { - ret = createKey(systemRoot, hkey, key); - regCloseKey.invoke(systemRoot, new Object[] { new Integer(ret[0]) }); - } - else if (hkey == HKEY_CURRENT_USER) { - ret = createKey(userRoot, hkey, key); - regCloseKey.invoke(userRoot, new Object[] { new Integer(ret[0]) }); - } - else { - throw new IllegalArgumentException("hkey=" + hkey); - } - if (ret[1] != REG_SUCCESS) { - throw new IllegalArgumentException("rc=" + ret[1] + " key=" + key); - } - } - - /** - * Write a value in a given key/value name - * @param hkey - * @param key - * @param valueName - * @param value - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static void writeStringValue - (int hkey, String key, String valueName, String value) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - if (hkey == HKEY_LOCAL_MACHINE) { - writeStringValue(systemRoot, hkey, key, valueName, value); - } - else if (hkey == HKEY_CURRENT_USER) { - writeStringValue(userRoot, hkey, key, valueName, value); - } - else { - throw new IllegalArgumentException("hkey=" + hkey); - } - } - - /** - * Delete a given key - * @param hkey - * @param key - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static void deleteKey(int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int rc = -1; - if (hkey == HKEY_LOCAL_MACHINE) { - rc = deleteKey(systemRoot, hkey, key); - } - else if (hkey == HKEY_CURRENT_USER) { - rc = deleteKey(userRoot, hkey, key); - } - if (rc != REG_SUCCESS) { - throw new IllegalArgumentException("rc=" + rc + " key=" + key); - } - } - - /** - * delete a value from a given key/value name - * @param hkey - * @param key - * @param value - * @throws IllegalArgumentException - * @throws IllegalAccessException - * @throws InvocationTargetException - */ - public static void deleteValue(int hkey, String key, String value) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int rc = -1; - if (hkey == HKEY_LOCAL_MACHINE) { - rc = deleteValue(systemRoot, hkey, key, value); - } - else if (hkey == HKEY_CURRENT_USER) { - rc = deleteValue(userRoot, hkey, key, value); - } - if (rc != REG_SUCCESS) { - throw new IllegalArgumentException("rc=" + rc + " key=" + key + " value=" + value); - } - } - - // ===================== - - private static int deleteValue - (Preferences root, int hkey, String key, String value) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int[] handles = (int[]) regOpenKey.invoke(root, new Object[] { - new Integer(hkey), toCstr(key), new Integer(KEY_ALL_ACCESS) }); - if (handles[1] != REG_SUCCESS) { - return handles[1]; // can be REG_NOTFOUND, REG_ACCESSDENIED - } - int rc =((Integer) regDeleteValue.invoke(root, - new Object[] { - new Integer(handles[0]), toCstr(value) - })).intValue(); - regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) }); - return rc; - } - - private static int deleteKey(Preferences root, int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int rc =((Integer) regDeleteKey.invoke(root, - new Object[] { new Integer(hkey), toCstr(key) })).intValue(); - return rc; // can REG_NOTFOUND, REG_ACCESSDENIED, REG_SUCCESS - } - - private static String readString(Preferences root, int hkey, String key, String value) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - int[] handles = (int[]) regOpenKey.invoke(root, new Object[] { - new Integer(hkey), toCstr(key), new Integer(KEY_READ) }); - if (handles[1] != REG_SUCCESS) { - return null; - } - byte[] valb = (byte[]) regQueryValueEx.invoke(root, new Object[] { - new Integer(handles[0]), toCstr(value) }); - regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) }); - return (valb != null ? new String(valb).trim() : null); - } - - private static Map readStringValues - (Preferences root, int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - HashMap results = new HashMap(); - int[] handles = (int[]) regOpenKey.invoke(root, new Object[] { - new Integer(hkey), toCstr(key), new Integer(KEY_READ) }); - if (handles[1] != REG_SUCCESS) { - return null; - } - int[] info = (int[]) regQueryInfoKey.invoke(root, - new Object[] { new Integer(handles[0]) }); - - int count = info[2]; // count - int maxlen = info[3]; // value length max - for(int index=0; index readStringSubKeys - (Preferences root, int hkey, String key) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException - { - List results = new ArrayList(); - int[] handles = (int[]) regOpenKey.invoke(root, new Object[] { - new Integer(hkey), toCstr(key), new Integer(KEY_READ) - }); - if (handles[1] != REG_SUCCESS) { - return null; - } - int[] info = (int[]) regQueryInfoKey.invoke(root, - new Object[] { new Integer(handles[0]) }); - - int count = info[2]; // count - int maxlen = info[3]; // value length max - for(int index=0; index