Revision 32285 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/creation/DefaultInstallerCreationService.java
DefaultInstallerCreationService.java | ||
---|---|---|
1 | 1 |
/* gvSIG. Geographic Information System of the Valencian Government |
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
2 |
*
|
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
|
4 |
* of the Valencian Government (CIT)
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or
|
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 2
|
|
9 |
* of the License, or (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
19 |
* MA 02110-1301, USA.
|
|
20 |
*
|
|
21 |
*/
|
|
22 | 22 |
|
23 | 23 |
/* |
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2010 {Prodevelop} {Task} |
|
26 |
*/ |
|
27 |
|
|
24 |
* AUTHORS (In addition to CIT):
|
|
25 |
* 2010 {Prodevelop} {Task}
|
|
26 |
*/
|
|
27 |
|
|
28 | 28 |
package org.gvsig.installer.lib.impl.creation; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.io.FileInputStream; |
|
31 | 32 |
import java.io.OutputStream; |
32 | 33 |
|
33 | 34 |
import org.gvsig.installer.lib.api.InstallerInfo; |
34 | 35 |
import org.gvsig.installer.lib.api.creation.InstallerCreationService; |
35 | 36 |
import org.gvsig.installer.lib.api.creation.InstallerCreationServiceException; |
36 | 37 |
import org.gvsig.installer.lib.impl.DefaultInstallerInfo; |
38 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileException; |
|
39 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader; |
|
37 | 40 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter; |
38 | 41 |
|
39 | 42 |
/** |
40 | 43 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
41 | 44 |
*/ |
42 | 45 |
public class DefaultInstallerCreationService extends DefaultInstallerInfo implements InstallerCreationService { |
46 |
private static final String INSTALLINFO_FILE_NAME = "install.info"; |
|
43 | 47 |
private File pluginDirectory; |
44 | 48 |
|
45 |
|
|
49 |
|
|
46 | 50 |
public void createInstaller(OutputStream installerStream) |
47 |
throws InstallerCreationServiceException {
|
|
51 |
throws InstallerCreationServiceException { |
|
48 | 52 |
if (pluginDirectory == null){ |
49 | 53 |
throw new InstallerCreationServiceException("The plugin directory has to be set"); |
50 | 54 |
} |
51 |
InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter(); |
|
52 |
installerInfoFileWriter.write(this, new File(getInstallInfoFileName(pluginDirectory.getAbsolutePath())));
|
|
53 |
|
|
55 |
|
|
56 |
writeInstallInfo();
|
|
57 |
|
|
54 | 58 |
Compress compress = new Compress(); |
55 | 59 |
compress.compressPlugin(pluginDirectory, installerStream); |
56 | 60 |
} |
57 |
|
|
61 |
|
|
58 | 62 |
public void setPluginDirectory(File pluginDirectory) throws InstallerCreationServiceException { |
59 | 63 |
if (!pluginDirectory.isDirectory()){ |
60 | 64 |
throw new InstallerCreationServiceException("The plugin directory has to be a directory"); |
61 | 65 |
} |
62 | 66 |
this.pluginDirectory = pluginDirectory; |
67 |
|
|
68 |
//If the install.info file exists |
|
69 |
File file = new File(getInstallerInfoFileName()); |
|
70 |
if (file.exists()){ |
|
71 |
readInstallInfo(); |
|
72 |
}else{ |
|
73 |
setCode(pluginDirectory.getName()); |
|
74 |
setName(pluginDirectory.getName()); |
|
75 |
} |
|
63 | 76 |
} |
64 | 77 |
|
65 |
private String getInstallInfoFileName(String pluginDirectory){ |
|
66 |
return pluginDirectory + File.separator + "install.info"; |
|
78 |
private void readInstallInfo() throws InstallerInfoFileException{ |
|
79 |
InstallerInfoFileReader installerInfoFileReader = new InstallerInfoFileReader(); |
|
80 |
installerInfoFileReader.read(this, getInstallerInfoFileName()); |
|
81 |
} |
|
82 |
|
|
83 |
private void writeInstallInfo() throws InstallerInfoFileException{ |
|
84 |
InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter(); |
|
85 |
installerInfoFileWriter.write(this, new File(getInstallerInfoFileName())); |
|
67 | 86 |
} |
68 | 87 |
|
88 |
private String getInstallerInfoFileName(){ |
|
89 |
return pluginDirectory + File.separator + INSTALLINFO_FILE_NAME; |
|
90 |
} |
|
91 |
|
|
69 | 92 |
public InstallerInfo getInstallerInfo() { |
70 | 93 |
return this; |
71 | 94 |
} |
Also available in: Unified diff