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 / DefaultInstallerProviderServices.java @ 40560
History | View | Annotate | Download (6.19 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; |
30 |
|
31 |
import java.io.File; |
32 |
import java.io.InputStream; |
33 |
import java.io.OutputStream; |
34 |
import java.util.List; |
35 |
import java.util.Map; |
36 |
|
37 |
import org.gvsig.installer.lib.api.PackageInfo; |
38 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException; |
39 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
40 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader; |
41 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter; |
42 |
import org.gvsig.installer.lib.impl.utils.Compress; |
43 |
import org.gvsig.installer.lib.impl.utils.Decompress; |
44 |
import org.gvsig.installer.lib.spi.InstallPackageProviderServices; |
45 |
import org.gvsig.installer.lib.spi.InstallerInfoFileException; |
46 |
import org.gvsig.installer.lib.spi.InstallerProviderLocator; |
47 |
import org.gvsig.tools.service.spi.AbstractProviderServices; |
48 |
|
49 |
/**
|
50 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
51 |
*/
|
52 |
public class DefaultInstallerProviderServices extends AbstractProviderServices |
53 |
implements InstallPackageProviderServices {
|
54 |
|
55 |
private List<String> defaultSelectedPacketsIDs = null; |
56 |
|
57 |
// private static final Logger LOG = LoggerFactory
|
58 |
// .getLogger(DefaultInstallerProviderServices.class);
|
59 |
|
60 |
public void decompress(InputStream is, File outputDirectory) |
61 |
throws InstallPackageServiceException {
|
62 |
Decompress decompress = new Decompress();
|
63 |
decompress.decompressPlugin(is, outputDirectory); |
64 |
} |
65 |
|
66 |
public class ReadPackageException extends InstallPackageServiceException { |
67 |
|
68 |
private static final long serialVersionUID = 1989187468965303199L; |
69 |
|
70 |
private static final String message = "Exception reading a compressed file"; |
71 |
|
72 |
private static final String KEY = "Exception_reading_a_compressed_file"; |
73 |
|
74 |
public ReadPackageException(InstallerInfoFileException e) {
|
75 |
super(message, e, KEY, serialVersionUID);
|
76 |
} |
77 |
|
78 |
} |
79 |
|
80 |
public PackageInfo readCompressedPackageInfo(InputStream is) |
81 |
throws InstallPackageServiceException {
|
82 |
Decompress decompress = new Decompress();
|
83 |
try {
|
84 |
return decompress.readInstallerInfo(is);
|
85 |
} catch (InstallerInfoFileException e) {
|
86 |
throw new ReadPackageException(e); |
87 |
} |
88 |
} |
89 |
|
90 |
public void compressPackageSet(File folder, String fileName, OutputStream os) |
91 |
throws MakePluginPackageServiceException {
|
92 |
Compress compress = new Compress();
|
93 |
compress.compressPluginAsPackageSet(folder, fileName, os); |
94 |
} |
95 |
|
96 |
public void compressPackage(File folder, OutputStream os) |
97 |
throws MakePluginPackageServiceException {
|
98 |
Compress compress = new Compress();
|
99 |
compress.compressPluginAsPackage(folder, os); |
100 |
} |
101 |
|
102 |
public void compressPackageIndex(File folder, OutputStream os) |
103 |
throws MakePluginPackageServiceException {
|
104 |
Compress compress = new Compress();
|
105 |
compress.compressPluginAsPackageIndex(folder, os); |
106 |
} |
107 |
|
108 |
public void readPackageInfo(File directory, PackageInfo installerInfo) |
109 |
throws InstallerInfoFileException {
|
110 |
File installInfoFile = new File(directory + File.separator |
111 |
+ getPackageInfoFileName()); |
112 |
if (installInfoFile.exists()) {
|
113 |
InstallerInfoFileReader reader = new InstallerInfoFileReader();
|
114 |
reader.read(installerInfo, installInfoFile.getAbsolutePath()); |
115 |
} |
116 |
|
117 |
if (installerInfo.getCode() == null) { |
118 |
installerInfo.setCode(directory.getName()); |
119 |
} |
120 |
if (installerInfo.getName() == null) { |
121 |
installerInfo.setName(directory.getName()); |
122 |
} |
123 |
} |
124 |
|
125 |
private String getPackageInfoFileName() { |
126 |
return InstallerProviderLocator.getProviderManager()
|
127 |
.getPackageInfoFileName(); |
128 |
} |
129 |
|
130 |
public void writePackageInfo(File directory, PackageInfo packageInfo) |
131 |
throws InstallerInfoFileException {
|
132 |
writePackageInfoFile(directory, getPackageInfoFileName(), packageInfo); |
133 |
} |
134 |
|
135 |
public void writePackageInfoForIndex(File directory, PackageInfo packageInfo) |
136 |
throws InstallerInfoFileException {
|
137 |
writePackageInfoFile(directory, getPackageInfoFileName() + ".index",
|
138 |
packageInfo); |
139 |
} |
140 |
|
141 |
private void writePackageInfoFile(File directory, String fileName, |
142 |
PackageInfo installerInfo) throws InstallerInfoFileException {
|
143 |
if (!directory.exists()) {
|
144 |
// throw new
|
145 |
// InstallerInfoFileException("The directory doesn't exist");
|
146 |
directory.mkdir(); |
147 |
} |
148 |
InstallerInfoFileWriter installerInfoFileWriter = new InstallerInfoFileWriter();
|
149 |
installerInfoFileWriter.write(installerInfo, directory + File.separator
|
150 |
+ fileName); |
151 |
} |
152 |
|
153 |
public InputStream searchPackage(InputStream is, String zipEntry) |
154 |
throws InstallPackageServiceException {
|
155 |
Decompress decompress = new Decompress();
|
156 |
return decompress.searchPlugin(is, zipEntry);
|
157 |
} |
158 |
|
159 |
public void readPackageSetInfo(InputStream is, |
160 |
List<PackageInfo> installerInfos,
|
161 |
Map<PackageInfo, String> zipEntriesMap) |
162 |
throws InstallPackageServiceException {
|
163 |
Decompress decompress = new Decompress();
|
164 |
decompress |
165 |
.readPackageSetInstallInfos(is, installerInfos, zipEntriesMap); |
166 |
|
167 |
defaultSelectedPacketsIDs = decompress.getDefaultSelectedPackages(); |
168 |
} |
169 |
|
170 |
public void readPackageInfo(InputStream is, |
171 |
List<PackageInfo> installerInfos,
|
172 |
Map<PackageInfo, String> zipEntriesMap, String name) |
173 |
throws InstallPackageServiceException {
|
174 |
|
175 |
Decompress decompress = new Decompress();
|
176 |
decompress.readPackageInstallInfo(is, installerInfos, zipEntriesMap, |
177 |
name); |
178 |
} |
179 |
|
180 |
public List<String> getDefaultSelectedPackagesIDs() { |
181 |
return defaultSelectedPacketsIDs;
|
182 |
} |
183 |
} |