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 @ 37822
History | View | Annotate | Download (5.4 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.api.PackageInfoWriter; |
40 |
import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
41 |
|
42 |
/**
|
43 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
44 |
*/
|
45 |
public class InstallerInfoFileWriter implements PackageInfoWriter { |
46 |
|
47 |
/**
|
48 |
* Writes the install.info file
|
49 |
*
|
50 |
* @param fileName
|
51 |
* The file name to write the installation information
|
52 |
* @param installInfo
|
53 |
* The installation information
|
54 |
* @throws InstallerInfoFileException
|
55 |
*/
|
56 |
public void write(PackageInfo installInfo, String fileName) |
57 |
throws InstallerInfoFileException {
|
58 |
write(installInfo, new File(fileName)); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Writes the install.info file
|
63 |
*
|
64 |
* @param file
|
65 |
* The file to write the installation information
|
66 |
* @param installInfo
|
67 |
* The installation information
|
68 |
* @throws InstallerInfoFileException
|
69 |
*/
|
70 |
public void write(PackageInfo installInfo, File file) |
71 |
throws InstallerInfoFileException {
|
72 |
try {
|
73 |
write(installInfo, new FileOutputStream(file)); |
74 |
} catch (FileNotFoundException e) { |
75 |
throw new InstallerInfoFileException("install_infofile_not_found", |
76 |
e); |
77 |
} |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Writes the install.info file
|
82 |
*
|
83 |
* @param os
|
84 |
* The file to write the installation information
|
85 |
* @param installInfo
|
86 |
* The installation information
|
87 |
* @throws InstallerInfoFileException
|
88 |
*/
|
89 |
public void write(PackageInfo installInfo, OutputStream os) |
90 |
throws InstallerInfoFileException {
|
91 |
try {
|
92 |
// Fill the properties
|
93 |
Properties properties = new Properties(); |
94 |
properties.setProperty(InstallerInfoTags.CODE, installInfo |
95 |
.getCode()); |
96 |
properties.setProperty(InstallerInfoTags.NAME, installInfo |
97 |
.getName()); |
98 |
properties.setProperty(InstallerInfoTags.DESCRIPTION, installInfo |
99 |
.getDescription()); |
100 |
properties.setProperty(InstallerInfoTags.VERSION, installInfo |
101 |
.getVersion().toString()); |
102 |
properties.setProperty(InstallerInfoTags.BUILD, Integer
|
103 |
.toString(installInfo.getBuild())); |
104 |
properties.setProperty(InstallerInfoTags.STATE, installInfo |
105 |
.getState()); |
106 |
properties.setProperty(InstallerInfoTags.OFFICIAL, Boolean
|
107 |
.toString(installInfo.isOfficial())); |
108 |
properties.setProperty(InstallerInfoTags.TYPE, installInfo |
109 |
.getType()); |
110 |
properties.setProperty(InstallerInfoTags.OS, installInfo |
111 |
.getOperatingSystem()); |
112 |
properties.setProperty(InstallerInfoTags.ARCHITECTURE, installInfo |
113 |
.getArchitecture()); |
114 |
properties.setProperty(InstallerInfoTags.JVM, installInfo |
115 |
.getJavaVM()); |
116 |
properties.setProperty(InstallerInfoTags.GVSIG_VERSION, installInfo |
117 |
.getGvSIGVersion()); |
118 |
String owner = installInfo.getOwner();
|
119 |
properties.setProperty(InstallerInfoTags.OWNER, owner == null ? "" |
120 |
: owner); |
121 |
String categories = installInfo.getCategoriesAsString();
|
122 |
properties.setProperty(InstallerInfoTags.CATEGORIES, |
123 |
categories == null ? "" : categories); |
124 |
if (installInfo.getDependencies() == null) { |
125 |
properties.setProperty(InstallerInfoTags.DEPENDENCIES, "");
|
126 |
} else {
|
127 |
properties.setProperty(InstallerInfoTags.DEPENDENCIES, |
128 |
installInfo.getDependencies().toString()); |
129 |
} |
130 |
|
131 |
URL sourcesURL = installInfo.getSourcesURL();
|
132 |
if (sourcesURL != null) { |
133 |
properties.setProperty(InstallerInfoTags.SOURCES_URL, |
134 |
sourcesURL.toString()); |
135 |
} else {
|
136 |
properties.setProperty(InstallerInfoTags.SOURCES_URL, "");
|
137 |
} |
138 |
|
139 |
URL webURL = installInfo.getWebURL();
|
140 |
if (webURL != null) { |
141 |
properties.setProperty(InstallerInfoTags.WEB_URL, webURL |
142 |
.toString()); |
143 |
} else {
|
144 |
properties.setProperty(InstallerInfoTags.WEB_URL, "");
|
145 |
} |
146 |
|
147 |
URL downloadURL = installInfo.getDownloadURL();
|
148 |
if (downloadURL != null) { |
149 |
properties.setProperty(InstallerInfoTags.DOWNLOAD_URL, |
150 |
downloadURL.toString()); |
151 |
} |
152 |
URL ownerURL = installInfo.getOwnerURL();
|
153 |
if (ownerURL != null) { |
154 |
properties.setProperty(InstallerInfoTags.OWNER_URL, ownerURL |
155 |
.toString()); |
156 |
} |
157 |
properties.setProperty(InstallerInfoTags.MODEL_VERSION, installInfo |
158 |
.getModelVersion()); |
159 |
properties.store(os, "");
|
160 |
os.close(); |
161 |
} catch (IOException e) { |
162 |
throw new InstallerInfoFileException( |
163 |
"install_infofile_writing_error", e);
|
164 |
} |
165 |
} |
166 |
} |