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