annotate SMART/Java/Installer/SmartInstallerTask.java @ 20:c265f13066d8

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:24:43 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 import java.util.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 import java.awt.event.ActionEvent;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import java.awt.event.ActionListener;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import java.io.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 import javax.swing.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 import javax.swing.filechooser.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 import javax.swing.border.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 import javax.swing.SwingUtilities;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 import java.net.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 import java.util.Stack;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 import java.util.zip.ZipEntry;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 import java.util.zip.ZipInputStream;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 public class SmartInstallerTask extends SwingWorker<Boolean, String> {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 int BUFFER = 1024;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 int architecture = 0;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 String installDirectoryName = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 JTextArea logArea = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 boolean[] selectedPrograms = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 // program chooser buttons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "Python 2.6", "S-MART"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 // Web addresses for the tools
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 String packageAddresses[][] = {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 {"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"},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 {"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"},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 {"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"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 };
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 // Packages to install
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 String rPackages[] = {"RColorBrewer", "Hmisc"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 // Script lines
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 String scriptLines[][] = {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 {"\"<INSTALLDIR>\\R-2.11.0-win32.exe\"", "\"<INSTALLDIR>\\R-2.11.0-win64.exe\""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 {"\"<RFILE>\" CMD BATCH \"<INSTALLDIR>\\installRColorBrewer.R\"", "\"<RFILE>\" CMD BATCH \"<INSTALLDIR>\\installRColorBrewer.R\""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 {"\"<RFILE>\" CMD BATCH \"<INSTALLDIR>\\installHmisc.R\"", "\"<RFILE>\" CMD BATCH \"<INSTALLDIR>\\installHmisc.R\""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 {"msiexec /i \"<INSTALLDIR>\\python-2.6.5.msi\"", "msiexec /i \"<INSTALLDIR>\\python-2.6.5.amd64.msi\""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 {"", ""}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 };
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 // Files to uncompress
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 String compressedFiles[][] = {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 {"", ""},
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 {"<INSTALLDIR>\\s-mart-1.0.15.zip", "<INSTALLDIR>\\s-mart-1.0.15.zip"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 };
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 public SmartInstallerTask(JTextArea ta, boolean[] b, String s, int a) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 logArea = ta;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 selectedPrograms = b;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 installDirectoryName = s;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 architecture = a;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 @Override
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 public Boolean doInBackground() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 boolean installOk;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 publish("Starting install\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 writeFiles();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 for (int i = 0; i < selectedPrograms.length; i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 if (selectedPrograms[i]) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 if (! install(i)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 return Boolean.FALSE;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 removeFiles();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 setEnvironmentVariables();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 publish("Ending install\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 return Boolean.TRUE;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 @Override
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 protected void process(List<String> chunks) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 for (String chunk: chunks) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 logArea.append(chunk);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 private boolean launch(String command) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 return realLaunch(new ProcessBuilder(command), command);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 private boolean launch(String[] command) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 return realLaunch(new ProcessBuilder(command), Arrays.toString(command));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 private boolean realLaunch(ProcessBuilder pb, String command) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 BufferedReader outputReader;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 pb = pb.redirectErrorStream(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 Process process = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 publish(" Starting command '" + command + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 process = pb.start();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 BufferedInputStream outputStream = new BufferedInputStream(process.getInputStream());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 InputStream is = process.getInputStream();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 InputStreamReader isr = new InputStreamReader(is);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 outputReader = new BufferedReader(isr);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 catch (Exception exception) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 publish(" !Process cannot be started (command is '" + command + "')!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 exception.printStackTrace();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 if (outputReader == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 publish(" !Problem in the output of the command!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 publish(" Output is:\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 publish(" ---\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 String line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 while ((line = outputReader.readLine()) != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 publish(" " + line + "\r\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 publish(" ---\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 catch (IOException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 publish(" !Cannot get the output of the command!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 int exitValue = process.exitValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 if (exitValue != 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 publish(" !Problem during the execution of the command '" + command + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 publish(" Ending command '" + command + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 private File lookForFile(String fileName, String[] putativePlaces) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 publish(" Looking for file " + fileName + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 for (String place: putativePlaces) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 File file = new File(place, fileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 publish(" Look at " + file.getAbsolutePath() + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 if (file.exists()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 publish(" Found it in expected place " + file.getAbsolutePath() + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 return file;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 Stack<File> files = new Stack<File>();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 files.push(new File("\\"));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 while (! files.empty()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 File file = files.pop();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 for (File childFile: file.listFiles()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 if (childFile.isDirectory()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 files.push(childFile);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 if (fileName.compareToIgnoreCase(childFile.getName()) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 publish(" Found it in unexpected place " + childFile.getAbsolutePath() + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 return childFile;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 publish(" !Cannot file file '" + fileName + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 return null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 private boolean writeFile(String fileName, String content) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 FileWriter fw = new FileWriter(fileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 BufferedWriter bw = new BufferedWriter(fw);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 bw.write(content);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 bw.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 fw.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 catch (Exception e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 publish(" !Cannot write file '" + fileName + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 private boolean removeFile(String fileName) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 File file = new File(fileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 if (file.exists()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 if (! file.delete()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 publish(" !Cannot delete file '" + file.getAbsolutePath() + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 private boolean writeFiles() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 for (String rPackage: rPackages) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 String fileName = installDirectoryName + File.separator + "install" + rPackage + ".R";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 String content = "install.packages(\"" + rPackage + "\", repos = \"http://cran.cict.fr\", dependencies = TRUE)\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 if (! writeFile(fileName, content)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 publish(" !Cannot write file for R package '" + rPackage + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 private boolean removeFiles() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 for (String rPackage: rPackages) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 File file = new File(installDirectoryName + File.separator + "install" + rPackage + ".R");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 if (! file.delete()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 publish("!Cannot delete R install file for " + rPackage + "!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 File file = new File(installDirectoryName + File.separator + "createUser.sql");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 if (! file.delete()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 publish("!Cannot delete mySQL configuration file!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 private boolean install(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 publish(" Starting install of " + programChoosers[element] + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 downloadPackage(element);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 executeInstall(element);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 uncompressPackage(element);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 removePackage(element);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 postProcess(element);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 publish(" Ending install of " + programChoosers[element] + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 private String getLocalName(String remoteName) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 String localName = installDirectoryName + File.separator + (new File(remoteName)).getName();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 int position = localName.indexOf("?");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 if (position >= 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 localName = localName.substring(0, position);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 return localName;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 private boolean downloadPackage(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 String fileName = packageAddresses[element][architecture];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 if (! "".equals(fileName)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 publish(" Starting download of " + programChoosers[element] + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 BufferedInputStream bis = new BufferedInputStream(new URL(fileName).openStream());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 FileOutputStream fos = new FileOutputStream(getLocalName(fileName));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 byte[] data = new byte[BUFFER];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 int x = 0;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 while((x = bis.read(data, 0, BUFFER)) >= 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 bos.write(data, 0, x);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 bos.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 fos.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 bis.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 catch (IOException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 publish(" !Cannot download file '" + fileName + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 publish(" Ending download of " + programChoosers[element] + "\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 private String replaceSubstring(String line) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 if (line.contains("<INSTALLDIR>")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 String protectedDirectory = installDirectoryName.replaceAll("\\\\", "\\\\\\\\");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 line = line.replaceAll("<INSTALLDIR>", protectedDirectory);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 if (line.contains("<RFILE>")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 String userName = System.getenv().get("USERNAME");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 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"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 String rDirectory = lookForFile("'.exe", possibleRDirectories).getAbsolutePath();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 rDirectory = rDirectory.replaceAll("\\\\", "\\\\\\\\");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 line = line.replaceAll("<RFILE>", rDirectory);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 return line;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 private boolean executeInstall(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 String commands = scriptLines[element][architecture];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 if (! "".equals(commands)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 for (String command: commands.split(";")) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 command = replaceSubstring(command);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 publish(" Starting command '" + command + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 Process process = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 process = Runtime.getRuntime().exec(command);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 catch (IOException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 publish(" !Cannot execute command '" + command + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 process.waitFor();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 catch (InterruptedException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 publish(" !Cannot wait for the end of the command '" + command + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 int exitValue = process.exitValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 if (exitValue != 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 publish(" !Problem during the execution of the command '" + command + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 publish(" Ending command '" + command + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 private boolean uncompressPackage(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 String file = compressedFiles[element][architecture];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 if (! "".equals(file)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 file = replaceSubstring(file);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 publish(" Starting uncompressing file '" + file + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 FileInputStream fis = new FileInputStream(file);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 BufferedInputStream bis = new BufferedInputStream(fis);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 ZipInputStream zis = new ZipInputStream(bis);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 ZipEntry entry;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341 while ((entry = zis.getNextEntry()) != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 if (! entry.isDirectory()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 File newFile = new File(installDirectoryName + File.separator + entry.getName());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 // create parent directories
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345 File upDirectory = newFile.getParentFile();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 while (upDirectory != null){
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 if (! upDirectory.exists()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 upDirectory.mkdir();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 publish(" Creating directory '" + upDirectory.getAbsolutePath() + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 upDirectory = upDirectory.getParentFile();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 // write the files to the disk
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 publish(" Extracting '" + entry.getName() + "' to '" + newFile.getAbsolutePath() + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 int count;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 byte data[] = new byte[BUFFER];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 FileOutputStream fos = new FileOutputStream(newFile);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359 while ((count = zis.read(data, 0, BUFFER)) != -1){
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 bos.write(data, 0, count);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362 bos.flush();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 bos.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 fos.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 zis.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 bis.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 fis.close();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371 catch(FileNotFoundException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372 publish(" !Cannot find file '" + file + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 catch(Exception e){
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376 publish(" !Cannot uncompress file '" + file + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 publish(" Ending uncompressing file '" + file + "'\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385 private boolean removePackage(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386 String packageName = packageAddresses[element][architecture];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387 if ("".equals(packageName)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390 String fileName = getLocalName(packageAddresses[element][architecture]);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 return removeFile(fileName);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395 private boolean postProcess(int element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396 switch (element) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397 case 4:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398 // Move S-MART files to parent directory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399 File installDirectory = new File(installDirectoryName + File.separator + "S-Mart");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400 for (File file: installDirectory.listFiles()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 File destinationFile = new File(file.getParentFile().getParentFile(), file.getName());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 if (! file.renameTo(destinationFile)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403 publish(" !Cannot move '" + file.getAbsolutePath() + "' to '" + destinationFile.getAbsolutePath() + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 if (! installDirectory.delete()) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 publish(" !Cannot remove installation S-MART directory '" + installDirectory.getAbsolutePath() + "'!\n");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 private boolean setEnvironmentVariables() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 String[] command = {"REG", "ADD", "HKCU\\Environment", "/v", "PYTHONPATH", "/t", "REG_SZ", "/d", "\"" + installDirectoryName + "\\Python\"", "/f"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416 return launch(command);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419