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