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 @ 41284
History | View | Annotate | Download (5.44 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.util.Properties; |
37 |
import org.apache.commons.lang3.StringUtils; |
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, toStr(installInfo.getCode())); |
101 |
properties.setProperty(InstallerInfoTags.NAME, toStr(installInfo.getName())); |
102 |
properties.setProperty(InstallerInfoTags.DESCRIPTION, toStr(installInfo.getDescription())); |
103 |
properties.setProperty(InstallerInfoTags.VERSION, installInfo.getVersion().toString()); |
104 |
properties.setProperty(InstallerInfoTags.BUILD, Integer.toString(installInfo.getBuild()));
|
105 |
properties.setProperty(InstallerInfoTags.STATE, toStr(installInfo.getState())); |
106 |
properties.setProperty(InstallerInfoTags.OFFICIAL, Boolean.toString(installInfo.isOfficial()));
|
107 |
properties.setProperty(InstallerInfoTags.TYPE, toStr(installInfo.getType())); |
108 |
properties.setProperty(InstallerInfoTags.OS, toStr(installInfo.getOperatingSystem())); |
109 |
properties.setProperty(InstallerInfoTags.ARCHITECTURE, toStr(installInfo.getArchitecture())); |
110 |
properties.setProperty(InstallerInfoTags.JVM, toStr(installInfo.getJavaVM())); |
111 |
properties.setProperty(InstallerInfoTags.GVSIG_VERSION, toStr(installInfo.getGvSIGVersion())); |
112 |
properties.setProperty(InstallerInfoTags.OWNER, toStr(installInfo.getOwner())); |
113 |
properties.setProperty(InstallerInfoTags.CATEGORIES, toStr(installInfo.getCategoriesAsString())); |
114 |
properties.setProperty(InstallerInfoTags.DEPENDENCIES, toStr(installInfo.getDependencies())); |
115 |
properties.setProperty(InstallerInfoTags.SOURCES_URL, toStr(installInfo.getSourcesURL())); |
116 |
properties.setProperty(InstallerInfoTags.WEB_URL, toStr(installInfo.getWebURL())); |
117 |
properties.setProperty(InstallerInfoTags.OWNER_URL, toStr(installInfo.getOwnerURL())); |
118 |
properties.setProperty(InstallerInfoTags.MODEL_VERSION, toStr(installInfo.getModelVersion())); |
119 |
if( !StringUtils.isBlank(installInfo.getDownloadURLAsString()) ) {
|
120 |
properties.setProperty(InstallerInfoTags.DOWNLOAD_URL, toStr(installInfo.getDownloadURLAsString())); |
121 |
} |
122 |
|
123 |
properties.store(os, "");
|
124 |
os.close(); |
125 |
} catch (IOException e) { |
126 |
throw new InstallerInfoFileException( |
127 |
"install_infofile_writing_error", e);
|
128 |
} |
129 |
} |
130 |
|
131 |
private String toStr(Object s) { |
132 |
return s == null ? "" : s.toString(); |
133 |
} |
134 |
} |