71 |
71 |
private List<InstallerInfo> installerInfos = null;
|
72 |
72 |
private Map<InstallerInfo, String> directories = null;
|
73 |
73 |
private int pluginToInstallIndex = -1;
|
|
74 |
protected List<File> selectedFiles = null;
|
|
75 |
protected String antScript = null;
|
74 |
76 |
|
75 |
77 |
public DefaultInstallerCreationService(Manager manager) {
|
76 |
78 |
super();
|
77 |
79 |
this.manager = manager;
|
78 |
80 |
installerInfos = new ArrayList<InstallerInfo>();
|
79 |
81 |
directories = new HashMap<InstallerInfo, String>();
|
|
82 |
selectedFiles = new ArrayList<File>();
|
80 |
83 |
}
|
81 |
84 |
|
82 |
85 |
public void createInstaller(OutputStream installerStream)
|
... | ... | |
93 |
96 |
if (antScript != null){
|
94 |
97 |
writeAntFile(antScript);
|
95 |
98 |
}
|
96 |
|
|
|
99 |
|
97 |
100 |
//Copy the selected files
|
98 |
101 |
writeSelectedFiles();
|
99 |
102 |
|
... | ... | |
114 |
117 |
//Deleting the previous files folder
|
115 |
118 |
File copiedFilesDirectoryfile = new File(copiedFilesDirectory);
|
116 |
119 |
deleteDirectory(copiedFilesDirectoryfile);
|
117 |
|
for (int i=0 ; i<getSelectedInstallerInfo().getFileToCopySize() ; i++){
|
118 |
|
String destFile = getSelectedInstallerInfo().getFileToCopyAt(i).getAbsolutePath();
|
119 |
|
|
|
120 |
for (int i=0 ; i<getFileToCopySize() ; i++){
|
|
121 |
String destFile = getFileToCopyAt(i).getAbsolutePath();
|
|
122 |
|
120 |
123 |
String sourceFile = applicationDirectory + File.separator + destFile;
|
121 |
|
|
|
124 |
|
122 |
125 |
//Create the final path
|
123 |
126 |
destFile = pluginsDirectory + File.separator + copiedFilesDirectory + File.separator + destFile;
|
124 |
|
|
125 |
127 |
|
|
128 |
|
126 |
129 |
//Copy the files
|
127 |
130 |
copy(new File(sourceFile), new File(destFile));
|
128 |
131 |
}
|
... | ... | |
134 |
137 |
private void writeAntFile(String content) throws InstallerCreationServiceException {
|
135 |
138 |
try{
|
136 |
139 |
ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes());
|
137 |
|
OutputStream out = new FileOutputStream(getAntFileName());
|
|
140 |
OutputStream out = new FileOutputStream(getAbsoluteAntFile());
|
138 |
141 |
|
139 |
142 |
// Copy the bits from instream to outstream
|
140 |
143 |
byte[] buf = new byte[1024];
|
... | ... | |
214 |
217 |
String pluginDirectoryName = plugins[i];
|
215 |
218 |
File pluginDirectory = getAbsolutePluginFile(pluginDirectoryName);
|
216 |
219 |
DefaultInstallerInfo installerInfo = new DefaultInstallerInfo();
|
|
220 |
//Check if the install info file exists
|
217 |
221 |
File installInfoFile = new File(getInstallerInfoFileName(pluginDirectory.getAbsolutePath()));
|
218 |
222 |
if (installInfoFile.exists()){
|
219 |
223 |
reader.read(installerInfo, installInfoFile);
|
... | ... | |
221 |
225 |
installerInfo.setCode(pluginDirectoryName);
|
222 |
226 |
installerInfo.setName(pluginDirectoryName);
|
223 |
227 |
}
|
|
228 |
//Checks if the ant file exists
|
|
229 |
File antFile = new File(getAntFileName(pluginDirectory.getAbsolutePath()));
|
|
230 |
if (antFile.exists()){
|
|
231 |
try {
|
|
232 |
installerInfo.setAnScript(readFileAsString(antFile.getAbsolutePath()));
|
|
233 |
} catch (IOException e) {
|
|
234 |
logger.error("Not possible to read the ant file");
|
|
235 |
}
|
|
236 |
}
|
224 |
237 |
installerInfos.add(installerInfo);
|
225 |
238 |
directories.put(installerInfo, pluginDirectoryName);
|
226 |
239 |
}
|
... | ... | |
237 |
250 |
private File getAbsoluteSelectePluginFile() throws InstallerCreationServiceException{
|
238 |
251 |
return getAbsolutePluginFile(directories.get(getSelectedInstallerInfo()));
|
239 |
252 |
}
|
240 |
|
|
|
253 |
|
241 |
254 |
private File getAbsolutePluginFile(String selectePluginName) throws InstallerCreationServiceException{
|
242 |
255 |
return new File(pluginsDirectory.getAbsolutePath() + File.separator + selectePluginName);
|
243 |
256 |
}
|
244 |
|
|
|
257 |
|
245 |
258 |
private String getPluginToInstallDirectory() throws InstallerCreationServiceException{
|
246 |
259 |
return directories.get(getSelectedInstallerInfo());
|
247 |
260 |
}
|
|
261 |
|
|
262 |
private File getAbsoluteAntFile() throws InstallerCreationServiceException{
|
|
263 |
return new File(pluginsDirectory.getAbsolutePath() + File.separator + ANT_FILE_NAME);
|
|
264 |
}
|
248 |
265 |
|
249 |
266 |
private String getCopiedFilesDirectoryName() throws InstallerCreationServiceException{
|
250 |
267 |
return getCopiedFilesDirectoryName(getPluginToInstallDirectory());
|
... | ... | |
267 |
284 |
}
|
268 |
285 |
|
269 |
286 |
private String getAntFileName(String pluginDirectory) throws InstallerCreationServiceException{
|
270 |
|
return getAbsoluteSelectePluginFile().getAbsolutePath() + File.separator + ANT_FILE_NAME;
|
|
287 |
return pluginDirectory + File.separator + ANT_FILE_NAME;
|
271 |
288 |
}
|
272 |
289 |
|
273 |
290 |
|
... | ... | |
355 |
372 |
throw new InstallerCreationServiceException("Impossible to read the default ant file", e);
|
356 |
373 |
}
|
357 |
374 |
}
|
358 |
|
|
359 |
|
private String readFileAsString(String filePath)
|
360 |
|
throws java.io.IOException{
|
361 |
|
StringBuffer fileData = new StringBuffer(1000);
|
362 |
|
BufferedReader reader = new BufferedReader(
|
363 |
|
new FileReader(filePath));
|
364 |
|
char[] buf = new char[1024];
|
365 |
|
int numRead=0;
|
366 |
|
while((numRead=reader.read(buf)) != -1){
|
367 |
|
String readData = String.valueOf(buf, 0, numRead);
|
368 |
|
fileData.append(readData);
|
369 |
|
buf = new char[1024];
|
370 |
|
}
|
371 |
|
reader.close();
|
372 |
|
return fileData.toString();
|
373 |
|
}
|
374 |
375 |
|
|
376 |
private String readFileAsString(String filePath)
|
|
377 |
throws java.io.IOException{
|
|
378 |
StringBuffer fileData = new StringBuffer(1000);
|
|
379 |
BufferedReader reader = new BufferedReader(
|
|
380 |
new FileReader(filePath));
|
|
381 |
char[] buf = new char[1024];
|
|
382 |
int numRead=0;
|
|
383 |
while((numRead=reader.read(buf)) != -1){
|
|
384 |
String readData = String.valueOf(buf, 0, numRead);
|
|
385 |
fileData.append(readData);
|
|
386 |
buf = new char[1024];
|
|
387 |
}
|
|
388 |
reader.close();
|
|
389 |
return fileData.toString();
|
|
390 |
}
|
|
391 |
|
|
392 |
public void addFileToCopy(File file) {
|
|
393 |
selectedFiles.add(file);
|
|
394 |
}
|
|
395 |
|
|
396 |
public File getFileToCopyAt(int index) {
|
|
397 |
return selectedFiles.get(index);
|
|
398 |
}
|
|
399 |
|
|
400 |
public int getFileToCopySize() {
|
|
401 |
return selectedFiles.size();
|
|
402 |
}
|
|
403 |
|
|
404 |
public void removeFileToCopy(int index) {
|
|
405 |
selectedFiles.remove(index);
|
|
406 |
}
|
|
407 |
|
|
408 |
public String getAntScript() {
|
|
409 |
return antScript;
|
|
410 |
}
|
|
411 |
|
|
412 |
public void setAnScript(String antScript) {
|
|
413 |
this.antScript = antScript;
|
|
414 |
}
|
|
415 |
|
375 |
416 |
}
|
376 |
417 |
|