root / 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 / info / InstallerInfoFileWriter.java @ 34005
History | View | Annotate | Download (4.71 KB)
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.lib.impl.info; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileNotFoundException; |
32 |
import java.io.FileOutputStream; |
33 |
import java.io.IOException; |
34 |
import java.io.OutputStream; |
35 |
import java.net.URL; |
36 |
import java.util.Properties; |
37 |
|
38 |
import org.gvsig.installer.lib.api.PackageInfo; |
39 |
import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
40 |
|
41 |
/**
|
42 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
43 |
*/
|
44 |
public class InstallerInfoFileWriter { |
45 |
|
46 |
/**
|
47 |
* Writes the install.info file
|
48 |
*
|
49 |
* @param fileName
|
50 |
* The file name to write the installation information
|
51 |
* @param installInfo
|
52 |
* The installation information
|
53 |
* @throws InstallerInfoFileException
|
54 |
*/
|
55 |
public void write(PackageInfo installInfo, String fileName) |
56 |
throws InstallerInfoFileException {
|
57 |
write(installInfo, new File(fileName)); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Writes the install.info file
|
62 |
*
|
63 |
* @param file
|
64 |
* The file to write the installation information
|
65 |
* @param installInfo
|
66 |
* The installation information
|
67 |
* @throws InstallerInfoFileException
|
68 |
*/
|
69 |
public void write(PackageInfo installInfo, File file) |
70 |
throws InstallerInfoFileException {
|
71 |
try {
|
72 |
write(installInfo, new FileOutputStream(file)); |
73 |
} catch (FileNotFoundException e) { |
74 |
throw new InstallerInfoFileException("install_infofile_not_found", |
75 |
e); |
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* Writes the install.info file
|
81 |
*
|
82 |
* @param os
|
83 |
* The file to write the installation information
|
84 |
* @param installInfo
|
85 |
* The installation information
|
86 |
* @throws InstallerInfoFileException
|
87 |
*/
|
88 |
public void write(PackageInfo installInfo, OutputStream os) |
89 |
throws InstallerInfoFileException {
|
90 |
try {
|
91 |
// Fill the properties
|
92 |
Properties properties = new Properties(); |
93 |
properties.setProperty(InstallerInfoTags.CODE, |
94 |
installInfo.getCode()); |
95 |
properties.setProperty(InstallerInfoTags.NAME, |
96 |
installInfo.getName()); |
97 |
properties.setProperty(InstallerInfoTags.DESCRIPTION, |
98 |
installInfo.getDescription()); |
99 |
properties.setProperty(InstallerInfoTags.VERSION, |
100 |
installInfo.getVersion()); |
101 |
properties.setProperty(InstallerInfoTags.BUILD, |
102 |
Integer.toString(installInfo.getBuild()));
|
103 |
properties.setProperty(InstallerInfoTags.STATE, |
104 |
installInfo.getState()); |
105 |
properties.setProperty(InstallerInfoTags.OFFICIAL, |
106 |
Boolean.toString(installInfo.isOfficial()));
|
107 |
properties.setProperty(InstallerInfoTags.TYPE, |
108 |
installInfo.getType()); |
109 |
properties.setProperty(InstallerInfoTags.OS, |
110 |
installInfo.getOperatingSystem()); |
111 |
properties.setProperty(InstallerInfoTags.ARCHITECTURE, |
112 |
installInfo.getArchitecture()); |
113 |
properties.setProperty(InstallerInfoTags.JVM, |
114 |
installInfo.getJavaVM()); |
115 |
properties.setProperty(InstallerInfoTags.GVSIG_VERSION, |
116 |
installInfo.getGvSIGVersion()); |
117 |
URL downloadURL = installInfo.getDownloadURL();
|
118 |
if (downloadURL != null) { |
119 |
properties.setProperty(InstallerInfoTags.DOWNLOAD_URL, |
120 |
downloadURL.toString()); |
121 |
} |
122 |
properties.setProperty(InstallerInfoTags.MODEL_VERSION, |
123 |
installInfo.getModelVersion()); |
124 |
properties.store(os, "");
|
125 |
os.close(); |
126 |
} catch (IOException e) { |
127 |
throw new InstallerInfoFileException( |
128 |
"install_infofile_writing_error", e);
|
129 |
} |
130 |
|
131 |
} |
132 |
} |