svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / info / InstallerInfoFileReader.java @ 40539
History | View | Annotate | Download (8.67 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 |
|
113 |
String codealias1 = properties.getProperty(InstallerInfoTags.CODEALIAS);
|
114 |
if( codealias1 != null ) { |
115 |
String[] s = codealias1.split(","); |
116 |
for( int i=0; i<s.length; i++) { |
117 |
s[i] = s[i].trim(); |
118 |
if(! "".equals(s[i]) ) { |
119 |
installerInfoResource.getAllCodes().add(s[i]); |
120 |
} |
121 |
} |
122 |
} |
123 |
|
124 |
String name = properties.getProperty(InstallerInfoTags.NAME);
|
125 |
installerInfoResource.setName(name); |
126 |
installerInfoResource.setDescription(properties |
127 |
.getProperty(InstallerInfoTags.DESCRIPTION)); |
128 |
String version = properties.getProperty(InstallerInfoTags.VERSION);
|
129 |
if (version == null) { |
130 |
LOG |
131 |
.warn( |
132 |
"Got a null version string for the {} plugin "
|
133 |
+ "Ignoring it and leaving the default version value",
|
134 |
name); |
135 |
} else {
|
136 |
installerInfoResource.setVersion(version); |
137 |
} |
138 |
installerInfoResource.setType(properties |
139 |
.getProperty(InstallerInfoTags.TYPE)); |
140 |
String build = properties.getProperty(InstallerInfoTags.BUILD);
|
141 |
if (build != null && installerInfoResource.getVersion().getBuild() == 0) { |
142 |
try {
|
143 |
installerInfoResource.setBuild(Integer.parseInt(build));
|
144 |
} catch (Exception e) { |
145 |
installerInfoResource.setBuild(0);
|
146 |
LOG.info( |
147 |
"Error while converting to int the "
|
148 |
+ InstallerInfoTags.BUILD + " property value: "
|
149 |
+ build, e); |
150 |
} |
151 |
} |
152 |
|
153 |
// Look for the old build tag just in case (the new one is buildNumber).
|
154 |
if (installerInfoResource.getBuild() <= 0) { |
155 |
String oldBuild = properties
|
156 |
.getProperty(InstallerInfoTags.BUILD_OLD); |
157 |
if (oldBuild != null) { |
158 |
try {
|
159 |
installerInfoResource.setBuild(Integer.parseInt(oldBuild));
|
160 |
} catch (Exception e) { |
161 |
installerInfoResource.setBuild(0);
|
162 |
LOG.info("Error while converting to int the "
|
163 |
+ InstallerInfoTags.BUILD_OLD + " property value: "
|
164 |
+ oldBuild, e); |
165 |
} |
166 |
} |
167 |
} |
168 |
installerInfoResource.setState(properties |
169 |
.getProperty(InstallerInfoTags.STATE)); |
170 |
try {
|
171 |
installerInfoResource.setOfficial(Boolean.parseBoolean(properties
|
172 |
.getProperty(InstallerInfoTags.OFFICIAL))); |
173 |
} catch (Exception e) { |
174 |
installerInfoResource.setOfficial(false);
|
175 |
LOG.info("Error while converting to boolean the "
|
176 |
+ InstallerInfoTags.OFFICIAL + " property value: "
|
177 |
+ properties.getProperty(InstallerInfoTags.OFFICIAL), e); |
178 |
} |
179 |
|
180 |
String os = properties.getProperty(InstallerInfoTags.OS);
|
181 |
if (os != null) { |
182 |
installerInfoResource.setOperatingSystem(os); |
183 |
} |
184 |
|
185 |
String arch = properties.getProperty(InstallerInfoTags.ARCHITECTURE);
|
186 |
if (arch != null) { |
187 |
installerInfoResource.setArchitecture(arch); |
188 |
} |
189 |
|
190 |
String jvm = properties.getProperty(InstallerInfoTags.JVM);
|
191 |
if (jvm != null) { |
192 |
installerInfoResource.setJavaVM(jvm); |
193 |
} |
194 |
|
195 |
installerInfoResource.setGvSIGVersion(properties |
196 |
.getProperty(InstallerInfoTags.GVSIG_VERSION)); |
197 |
|
198 |
String urlStr = properties.getProperty(InstallerInfoTags.DOWNLOAD_URL);
|
199 |
if (urlStr != null) { |
200 |
installerInfoResource.setDownloadURL(urlStr); |
201 |
} |
202 |
|
203 |
String modelVersion = properties
|
204 |
.getProperty(InstallerInfoTags.MODEL_VERSION); |
205 |
if (modelVersion != null) { |
206 |
installerInfoResource.setModelVersion(modelVersion); |
207 |
} |
208 |
|
209 |
String owner = properties.getProperty(InstallerInfoTags.OWNER);
|
210 |
if (owner != null) { |
211 |
installerInfoResource.setOwner(owner); |
212 |
} |
213 |
|
214 |
String dependencies = properties
|
215 |
.getProperty(InstallerInfoTags.DEPENDENCIES); |
216 |
if (dependencies != null) { |
217 |
installerInfoResource.setDependencies(dependencies); |
218 |
} |
219 |
|
220 |
String sourcesUrlStr = properties
|
221 |
.getProperty(InstallerInfoTags.SOURCES_URL); |
222 |
if (sourcesUrlStr != null && !sourcesUrlStr.equals("")) { |
223 |
URL sourcesURL;
|
224 |
try {
|
225 |
if( sourcesUrlStr.toLowerCase().startsWith("scm:svn:http") ) { |
226 |
sourcesUrlStr = sourcesUrlStr.substring(8);
|
227 |
} |
228 |
sourcesURL = new URL(sourcesUrlStr); |
229 |
} catch (MalformedURLException e) { |
230 |
throw new InstallerInfoFileException( |
231 |
"Error getting the value of the sources url property as URL: "
|
232 |
+ sourcesUrlStr, e); |
233 |
} |
234 |
installerInfoResource.setSourcesURL(sourcesURL); |
235 |
} else {
|
236 |
installerInfoResource.setSourcesURL(null);
|
237 |
} |
238 |
|
239 |
String webUrlStr = properties.getProperty(InstallerInfoTags.WEB_URL);
|
240 |
if (webUrlStr != null && !webUrlStr.equals("")) { |
241 |
URL webUrl;
|
242 |
try {
|
243 |
webUrl = new URL(webUrlStr); |
244 |
} catch (MalformedURLException e) { |
245 |
throw new InstallerInfoFileException( |
246 |
"Error getting the value of the web url property as URL: "
|
247 |
+ webUrlStr, e); |
248 |
} |
249 |
installerInfoResource.setWebURL(webUrl); |
250 |
} else {
|
251 |
installerInfoResource.setWebURL(null);
|
252 |
} |
253 |
|
254 |
String ownerURLStr = properties
|
255 |
.getProperty(InstallerInfoTags.OWNER_URL); |
256 |
if (ownerURLStr != null && !ownerURLStr.equals("")) { |
257 |
URL ownerUrl;
|
258 |
try {
|
259 |
ownerUrl = new URL(ownerURLStr); |
260 |
} catch (MalformedURLException e) { |
261 |
throw new InstallerInfoFileException( |
262 |
"Error getting the value of the owner url property as URL: "
|
263 |
+ ownerURLStr, e); |
264 |
} |
265 |
installerInfoResource.setOwnerURL(ownerUrl); |
266 |
} else {
|
267 |
installerInfoResource.setOwnerURL(null);
|
268 |
} |
269 |
|
270 |
String categories = properties
|
271 |
.getProperty(InstallerInfoTags.CATEGORIES); |
272 |
if (categories != null && !categories.equals("")) { |
273 |
installerInfoResource.addCategoriesAsString(categories); |
274 |
} |
275 |
|
276 |
} |
277 |
|
278 |
} |