svn-gvsig-desktop / tags / v2_0_0_Build_2051 / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / info / InstallerInfoFileReader.java @ 38753
History | View | Annotate | Download (8.25 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.FileInputStream; |
32 |
import java.io.FileNotFoundException; |
33 |
import java.io.IOException; |
34 |
import java.io.InputStream; |
35 |
import java.net.MalformedURLException; |
36 |
import java.net.URL; |
37 |
import java.util.Properties; |
38 |
|
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.installer.lib.api.PackageInfo; |
43 |
import org.gvsig.installer.lib.api.PackageInfoReader; |
44 |
import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
45 |
|
46 |
/**
|
47 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
48 |
*/
|
49 |
public class InstallerInfoFileReader implements PackageInfoReader { |
50 |
|
51 |
private static final Logger LOG = LoggerFactory |
52 |
.getLogger(InstallerInfoFileReader.class); |
53 |
|
54 |
/**
|
55 |
* Reads and parses the install.info file and creates one object that
|
56 |
* contains the information.
|
57 |
*
|
58 |
* @param fileName
|
59 |
* The file name that contains the install.info information.
|
60 |
* @return An object with the information about the installation
|
61 |
* @throws InstallerInfoFileException
|
62 |
*/
|
63 |
public void read(PackageInfo installerInfoResource, String fileName) |
64 |
throws InstallerInfoFileException {
|
65 |
read(installerInfoResource, new File(fileName)); |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Reads and parses the install.info file and creates one object that
|
70 |
* contains the information.
|
71 |
*
|
72 |
* @param file
|
73 |
* The file that contains the install.info information.
|
74 |
* @return An object with the information about the installation
|
75 |
* @throws InstallerInfoFileException
|
76 |
*/
|
77 |
public void read(PackageInfo installerInfoResource, File file) |
78 |
throws InstallerInfoFileException {
|
79 |
if (!file.exists()) {
|
80 |
throw new InstallerInfoFileException("install_infofile_not_found"); |
81 |
} |
82 |
try {
|
83 |
read(installerInfoResource, new FileInputStream(file)); |
84 |
} catch (FileNotFoundException e) { |
85 |
throw new InstallerInfoFileException("install_infofile_not_found", |
86 |
e); |
87 |
} |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Reads and parses the install.info file and creates one object that
|
92 |
* contains the information.
|
93 |
*
|
94 |
* @param is
|
95 |
* The input stream that contains the install.info information.
|
96 |
* @return An object with the information about the installation
|
97 |
* @throws InstallerInfoFileException
|
98 |
*/
|
99 |
public void read(PackageInfo installerInfoResource, InputStream is) |
100 |
throws InstallerInfoFileException {
|
101 |
Properties properties = new Properties(); |
102 |
try {
|
103 |
properties.load(is); |
104 |
is.close(); |
105 |
} catch (IOException e) { |
106 |
throw new InstallerInfoFileException( |
107 |
"install_infofile_reading_error", e);
|
108 |
} |
109 |
|
110 |
installerInfoResource.setCode(properties |
111 |
.getProperty(InstallerInfoTags.CODE)); |
112 |
String name = properties.getProperty(InstallerInfoTags.NAME);
|
113 |
installerInfoResource.setName(name); |
114 |
installerInfoResource.setDescription(properties |
115 |
.getProperty(InstallerInfoTags.DESCRIPTION)); |
116 |
String version = properties.getProperty(InstallerInfoTags.VERSION);
|
117 |
if (version == null) { |
118 |
LOG |
119 |
.warn( |
120 |
"Got a null version string for the {} plugin "
|
121 |
+ "Ignoring it and leaving the default version value",
|
122 |
name); |
123 |
} else {
|
124 |
installerInfoResource.setVersion(version); |
125 |
} |
126 |
installerInfoResource.setType(properties |
127 |
.getProperty(InstallerInfoTags.TYPE)); |
128 |
String build = properties.getProperty(InstallerInfoTags.BUILD);
|
129 |
if (build != null && installerInfoResource.getVersion().getBuild() == 0) { |
130 |
try {
|
131 |
installerInfoResource.setBuild(Integer.parseInt(build));
|
132 |
} catch (Exception e) { |
133 |
installerInfoResource.setBuild(0);
|
134 |
LOG.info( |
135 |
"Error while converting to int the "
|
136 |
+ InstallerInfoTags.BUILD + " property value: "
|
137 |
+ build, e); |
138 |
} |
139 |
} |
140 |
|
141 |
// Look for the old build tag just in case (the new one is buildNumber).
|
142 |
if (installerInfoResource.getBuild() <= 0) { |
143 |
String oldBuild = properties
|
144 |
.getProperty(InstallerInfoTags.BUILD_OLD); |
145 |
if (oldBuild != null) { |
146 |
try {
|
147 |
installerInfoResource.setBuild(Integer.parseInt(oldBuild));
|
148 |
} catch (Exception e) { |
149 |
installerInfoResource.setBuild(0);
|
150 |
LOG.info("Error while converting to int the "
|
151 |
+ InstallerInfoTags.BUILD_OLD + " property value: "
|
152 |
+ oldBuild, e); |
153 |
} |
154 |
} |
155 |
} |
156 |
installerInfoResource.setState(properties |
157 |
.getProperty(InstallerInfoTags.STATE)); |
158 |
try {
|
159 |
installerInfoResource.setOfficial(Boolean.parseBoolean(properties
|
160 |
.getProperty(InstallerInfoTags.OFFICIAL))); |
161 |
} catch (Exception e) { |
162 |
installerInfoResource.setOfficial(false);
|
163 |
LOG.info("Error while converting to boolean the "
|
164 |
+ InstallerInfoTags.OFFICIAL + " property value: "
|
165 |
+ properties.getProperty(InstallerInfoTags.OFFICIAL), e); |
166 |
} |
167 |
|
168 |
String os = properties.getProperty(InstallerInfoTags.OS);
|
169 |
if (os != null) { |
170 |
installerInfoResource.setOperatingSystem(os); |
171 |
} |
172 |
|
173 |
String arch = properties.getProperty(InstallerInfoTags.ARCHITECTURE);
|
174 |
if (arch != null) { |
175 |
installerInfoResource.setArchitecture(arch); |
176 |
} |
177 |
|
178 |
String jvm = properties.getProperty(InstallerInfoTags.JVM);
|
179 |
if (jvm != null) { |
180 |
installerInfoResource.setJavaVM(jvm); |
181 |
} |
182 |
|
183 |
installerInfoResource.setGvSIGVersion(properties |
184 |
.getProperty(InstallerInfoTags.GVSIG_VERSION)); |
185 |
|
186 |
String urlStr = properties.getProperty(InstallerInfoTags.DOWNLOAD_URL);
|
187 |
if (urlStr != null) { |
188 |
installerInfoResource.setDownloadURL(urlStr); |
189 |
} |
190 |
|
191 |
String modelVersion = properties
|
192 |
.getProperty(InstallerInfoTags.MODEL_VERSION); |
193 |
if (modelVersion != null) { |
194 |
installerInfoResource.setModelVersion(modelVersion); |
195 |
} |
196 |
|
197 |
String owner = properties.getProperty(InstallerInfoTags.OWNER);
|
198 |
if (owner != null) { |
199 |
installerInfoResource.setOwner(owner); |
200 |
} |
201 |
|
202 |
String dependencies = properties
|
203 |
.getProperty(InstallerInfoTags.DEPENDENCIES); |
204 |
if (dependencies != null) { |
205 |
installerInfoResource.setDependencies(dependencies); |
206 |
} |
207 |
|
208 |
String sourcesUrlStr = properties
|
209 |
.getProperty(InstallerInfoTags.SOURCES_URL); |
210 |
if (sourcesUrlStr != null && !sourcesUrlStr.equals("")) { |
211 |
URL sourcesURL;
|
212 |
try {
|
213 |
sourcesURL = new URL(sourcesUrlStr); |
214 |
} catch (MalformedURLException e) { |
215 |
throw new InstallerInfoFileException( |
216 |
"Error getting the value of the sources url property as URL: "
|
217 |
+ sourcesUrlStr, e); |
218 |
} |
219 |
installerInfoResource.setSourcesURL(sourcesURL); |
220 |
} else {
|
221 |
installerInfoResource.setSourcesURL(null);
|
222 |
} |
223 |
|
224 |
String webUrlStr = properties.getProperty(InstallerInfoTags.WEB_URL);
|
225 |
if (webUrlStr != null && !webUrlStr.equals("")) { |
226 |
URL webUrl;
|
227 |
try {
|
228 |
webUrl = new URL(webUrlStr); |
229 |
} catch (MalformedURLException e) { |
230 |
throw new InstallerInfoFileException( |
231 |
"Error getting the value of the web url property as URL: "
|
232 |
+ webUrlStr, e); |
233 |
} |
234 |
installerInfoResource.setWebURL(webUrl); |
235 |
} else {
|
236 |
installerInfoResource.setWebURL(null);
|
237 |
} |
238 |
|
239 |
String ownerURLStr = properties
|
240 |
.getProperty(InstallerInfoTags.OWNER_URL); |
241 |
if (ownerURLStr != null && !ownerURLStr.equals("")) { |
242 |
URL ownerUrl;
|
243 |
try {
|
244 |
ownerUrl = new URL(ownerURLStr); |
245 |
} catch (MalformedURLException e) { |
246 |
throw new InstallerInfoFileException( |
247 |
"Error getting the value of the owner url property as URL: "
|
248 |
+ ownerURLStr, e); |
249 |
} |
250 |
installerInfoResource.setOwnerURL(ownerUrl); |
251 |
} else {
|
252 |
installerInfoResource.setOwnerURL(null);
|
253 |
} |
254 |
|
255 |
String categories = properties
|
256 |
.getProperty(InstallerInfoTags.CATEGORIES); |
257 |
if (categories != null && !categories.equals("")) { |
258 |
installerInfoResource.addCategoriesAsString(categories); |
259 |
} |
260 |
|
261 |
} |
262 |
|
263 |
} |