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 @ 40560
History | View | Annotate | Download (8.71 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2010 {Prodevelop} {Task}
|
||
27 | */
|
||
28 | |||
29 | package org.gvsig.installer.lib.impl.info; |
||
30 | |||
31 | import java.io.File; |
||
32 | import java.io.FileInputStream; |
||
33 | import java.io.FileNotFoundException; |
||
34 | import java.io.IOException; |
||
35 | import java.io.InputStream; |
||
36 | import java.net.MalformedURLException; |
||
37 | import java.net.URL; |
||
38 | import java.util.Properties; |
||
39 | |||
40 | import org.slf4j.Logger; |
||
41 | import org.slf4j.LoggerFactory; |
||
42 | |||
43 | import org.gvsig.installer.lib.api.PackageInfo; |
||
44 | import org.gvsig.installer.lib.api.PackageInfoReader; |
||
45 | import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
||
46 | |||
47 | /**
|
||
48 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
49 | */
|
||
50 | public class InstallerInfoFileReader implements PackageInfoReader { |
||
51 | |||
52 | private static final Logger LOG = LoggerFactory |
||
53 | .getLogger(InstallerInfoFileReader.class); |
||
54 | |||
55 | /**
|
||
56 | * Reads and parses the install.info file and creates one object that
|
||
57 | * contains the information.
|
||
58 | *
|
||
59 | * @param fileName
|
||
60 | * The file name that contains the install.info information.
|
||
61 | * @return An object with the information about the installation
|
||
62 | * @throws InstallerInfoFileException
|
||
63 | */
|
||
64 | public void read(PackageInfo installerInfoResource, String fileName) |
||
65 | throws InstallerInfoFileException {
|
||
66 | read(installerInfoResource, new File(fileName)); |
||
67 | } |
||
68 | |||
69 | /**
|
||
70 | * Reads and parses the install.info file and creates one object that
|
||
71 | * contains the information.
|
||
72 | *
|
||
73 | * @param file
|
||
74 | * The file that contains the install.info information.
|
||
75 | * @return An object with the information about the installation
|
||
76 | * @throws InstallerInfoFileException
|
||
77 | */
|
||
78 | public void read(PackageInfo installerInfoResource, File file) |
||
79 | throws InstallerInfoFileException {
|
||
80 | if (!file.exists()) {
|
||
81 | throw new InstallerInfoFileException("install_infofile_not_found"); |
||
82 | } |
||
83 | try {
|
||
84 | read(installerInfoResource, new FileInputStream(file)); |
||
85 | } catch (FileNotFoundException e) { |
||
86 | throw new InstallerInfoFileException("install_infofile_not_found", |
||
87 | e); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * Reads and parses the install.info file and creates one object that
|
||
93 | * contains the information.
|
||
94 | *
|
||
95 | * @param is
|
||
96 | * The input stream that contains the install.info information.
|
||
97 | * @return An object with the information about the installation
|
||
98 | * @throws InstallerInfoFileException
|
||
99 | */
|
||
100 | public void read(PackageInfo installerInfoResource, InputStream is) |
||
101 | throws InstallerInfoFileException {
|
||
102 | Properties properties = new Properties(); |
||
103 | try {
|
||
104 | properties.load(is); |
||
105 | is.close(); |
||
106 | } catch (IOException e) { |
||
107 | throw new InstallerInfoFileException( |
||
108 | "install_infofile_reading_error", e);
|
||
109 | } |
||
110 | |||
111 | installerInfoResource.setCode(properties |
||
112 | .getProperty(InstallerInfoTags.CODE)); |
||
113 | 40487 | jjdelcerro | |
114 | String codealias1 = properties.getProperty(InstallerInfoTags.CODEALIAS);
|
||
115 | if( codealias1 != null ) { |
||
116 | String[] s = codealias1.split(","); |
||
117 | for( int i=0; i<s.length; i++) { |
||
118 | s[i] = s[i].trim(); |
||
119 | if(! "".equals(s[i]) ) { |
||
120 | installerInfoResource.getAllCodes().add(s[i]); |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | 40435 | jjdelcerro | String name = properties.getProperty(InstallerInfoTags.NAME);
|
126 | installerInfoResource.setName(name); |
||
127 | installerInfoResource.setDescription(properties |
||
128 | .getProperty(InstallerInfoTags.DESCRIPTION)); |
||
129 | String version = properties.getProperty(InstallerInfoTags.VERSION);
|
||
130 | if (version == null) { |
||
131 | LOG |
||
132 | .warn( |
||
133 | "Got a null version string for the {} plugin "
|
||
134 | + "Ignoring it and leaving the default version value",
|
||
135 | name); |
||
136 | } else {
|
||
137 | installerInfoResource.setVersion(version); |
||
138 | } |
||
139 | installerInfoResource.setType(properties |
||
140 | .getProperty(InstallerInfoTags.TYPE)); |
||
141 | String build = properties.getProperty(InstallerInfoTags.BUILD);
|
||
142 | if (build != null && installerInfoResource.getVersion().getBuild() == 0) { |
||
143 | try {
|
||
144 | installerInfoResource.setBuild(Integer.parseInt(build));
|
||
145 | } catch (Exception e) { |
||
146 | installerInfoResource.setBuild(0);
|
||
147 | LOG.info( |
||
148 | "Error while converting to int the "
|
||
149 | + InstallerInfoTags.BUILD + " property value: "
|
||
150 | + build, e); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | // Look for the old build tag just in case (the new one is buildNumber).
|
||
155 | if (installerInfoResource.getBuild() <= 0) { |
||
156 | String oldBuild = properties
|
||
157 | .getProperty(InstallerInfoTags.BUILD_OLD); |
||
158 | if (oldBuild != null) { |
||
159 | try {
|
||
160 | installerInfoResource.setBuild(Integer.parseInt(oldBuild));
|
||
161 | } catch (Exception e) { |
||
162 | installerInfoResource.setBuild(0);
|
||
163 | LOG.info("Error while converting to int the "
|
||
164 | + InstallerInfoTags.BUILD_OLD + " property value: "
|
||
165 | + oldBuild, e); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | installerInfoResource.setState(properties |
||
170 | .getProperty(InstallerInfoTags.STATE)); |
||
171 | try {
|
||
172 | installerInfoResource.setOfficial(Boolean.parseBoolean(properties
|
||
173 | .getProperty(InstallerInfoTags.OFFICIAL))); |
||
174 | } catch (Exception e) { |
||
175 | installerInfoResource.setOfficial(false);
|
||
176 | LOG.info("Error while converting to boolean the "
|
||
177 | + InstallerInfoTags.OFFICIAL + " property value: "
|
||
178 | + properties.getProperty(InstallerInfoTags.OFFICIAL), e); |
||
179 | } |
||
180 | |||
181 | String os = properties.getProperty(InstallerInfoTags.OS);
|
||
182 | if (os != null) { |
||
183 | installerInfoResource.setOperatingSystem(os); |
||
184 | } |
||
185 | |||
186 | String arch = properties.getProperty(InstallerInfoTags.ARCHITECTURE);
|
||
187 | if (arch != null) { |
||
188 | installerInfoResource.setArchitecture(arch); |
||
189 | } |
||
190 | |||
191 | String jvm = properties.getProperty(InstallerInfoTags.JVM);
|
||
192 | if (jvm != null) { |
||
193 | installerInfoResource.setJavaVM(jvm); |
||
194 | } |
||
195 | |||
196 | installerInfoResource.setGvSIGVersion(properties |
||
197 | .getProperty(InstallerInfoTags.GVSIG_VERSION)); |
||
198 | |||
199 | String urlStr = properties.getProperty(InstallerInfoTags.DOWNLOAD_URL);
|
||
200 | if (urlStr != null) { |
||
201 | installerInfoResource.setDownloadURL(urlStr); |
||
202 | } |
||
203 | |||
204 | String modelVersion = properties
|
||
205 | .getProperty(InstallerInfoTags.MODEL_VERSION); |
||
206 | if (modelVersion != null) { |
||
207 | installerInfoResource.setModelVersion(modelVersion); |
||
208 | } |
||
209 | |||
210 | String owner = properties.getProperty(InstallerInfoTags.OWNER);
|
||
211 | if (owner != null) { |
||
212 | installerInfoResource.setOwner(owner); |
||
213 | } |
||
214 | |||
215 | String dependencies = properties
|
||
216 | .getProperty(InstallerInfoTags.DEPENDENCIES); |
||
217 | if (dependencies != null) { |
||
218 | installerInfoResource.setDependencies(dependencies); |
||
219 | } |
||
220 | |||
221 | String sourcesUrlStr = properties
|
||
222 | .getProperty(InstallerInfoTags.SOURCES_URL); |
||
223 | if (sourcesUrlStr != null && !sourcesUrlStr.equals("")) { |
||
224 | URL sourcesURL;
|
||
225 | try {
|
||
226 | 40539 | jjdelcerro | if( sourcesUrlStr.toLowerCase().startsWith("scm:svn:http") ) { |
227 | sourcesUrlStr = sourcesUrlStr.substring(8);
|
||
228 | } |
||
229 | 40435 | jjdelcerro | sourcesURL = new URL(sourcesUrlStr); |
230 | } catch (MalformedURLException e) { |
||
231 | throw new InstallerInfoFileException( |
||
232 | "Error getting the value of the sources url property as URL: "
|
||
233 | + sourcesUrlStr, e); |
||
234 | } |
||
235 | installerInfoResource.setSourcesURL(sourcesURL); |
||
236 | } else {
|
||
237 | installerInfoResource.setSourcesURL(null);
|
||
238 | } |
||
239 | |||
240 | String webUrlStr = properties.getProperty(InstallerInfoTags.WEB_URL);
|
||
241 | if (webUrlStr != null && !webUrlStr.equals("")) { |
||
242 | URL webUrl;
|
||
243 | try {
|
||
244 | webUrl = new URL(webUrlStr); |
||
245 | } catch (MalformedURLException e) { |
||
246 | throw new InstallerInfoFileException( |
||
247 | "Error getting the value of the web url property as URL: "
|
||
248 | + webUrlStr, e); |
||
249 | } |
||
250 | installerInfoResource.setWebURL(webUrl); |
||
251 | } else {
|
||
252 | installerInfoResource.setWebURL(null);
|
||
253 | } |
||
254 | |||
255 | String ownerURLStr = properties
|
||
256 | .getProperty(InstallerInfoTags.OWNER_URL); |
||
257 | if (ownerURLStr != null && !ownerURLStr.equals("")) { |
||
258 | URL ownerUrl;
|
||
259 | try {
|
||
260 | ownerUrl = new URL(ownerURLStr); |
||
261 | } catch (MalformedURLException e) { |
||
262 | throw new InstallerInfoFileException( |
||
263 | "Error getting the value of the owner url property as URL: "
|
||
264 | + ownerURLStr, e); |
||
265 | } |
||
266 | installerInfoResource.setOwnerURL(ownerUrl); |
||
267 | } else {
|
||
268 | installerInfoResource.setOwnerURL(null);
|
||
269 | } |
||
270 | |||
271 | String categories = properties
|
||
272 | .getProperty(InstallerInfoTags.CATEGORIES); |
||
273 | if (categories != null && !categories.equals("")) { |
||
274 | installerInfoResource.addCategoriesAsString(categories); |
||
275 | } |
||
276 | |||
277 | } |
||
278 | |||
279 | } |