Revision 43126

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.main/src/main/java/org/gvsig/installer/main/execution/InstallPackageWizardFromDefaultDirectoryLauncher.java
55 55

  
56 56
		InstallPackageServiceFrame frame = new InstallPackageServiceFrame(
57 57
				getApplicationFolder(), getInstallFolder());
58
		frame.installFromDefaultDirectory();
58
//		frame.installFromDefaultDirectory();
59 59
		frame.setVisible(true);
60 60
	}
61 61
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.main/src/main/java/org/gvsig/installer/main/execution/InstallPackageServiceFrame.java
35 35
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
36 36
import org.gvsig.installer.main.utils.FrameWizardListener;
37 37
import org.gvsig.installer.swing.api.SwingInstallerLocator;
38
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard;
39 38
import org.gvsig.installer.swing.api.execution.InstallPackageWizardException;
39
import org.gvsig.installer.swing.api.execution.InstallWizardPanel;
40 40
import org.gvsig.tools.locator.LocatorException;
41 41

  
42 42
/**
......
45 45
public class InstallPackageServiceFrame extends JFrame {
46 46

  
47 47
	private static final long serialVersionUID = -5107758157530922356L;
48
	private AbstractInstallPackageWizard installerExecutionWizard;
48
        private final InstallWizardPanel installerExecutionWizard;
49 49

  
50 50
	public InstallPackageServiceFrame(File applicationFolder, File installFolder)
51 51
			throws LocatorException, InstallPackageWizardException {
52 52
		super();
53 53
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
54
		installerExecutionWizard = SwingInstallerLocator
54
		this.installerExecutionWizard = SwingInstallerLocator
55 55
				.getSwingInstallerManager().createInstallPackageWizard(
56 56
						applicationFolder, installFolder);
57 57
		installerExecutionWizard
58 58
				.setWizardActionListener(new FrameWizardListener(this));
59
		this.add(installerExecutionWizard);
59
		this.add(installerExecutionWizard.asJComponent());
60 60
		pack();
61 61
	}
62 62

  
63
	public void installFromDefaultDirectory()
64
			throws InstallPackageServiceException {
65
		installerExecutionWizard.installFromDefaultDirectory();
66
	}
63
//	public void installFromDefaultDirectory()
64
//			throws InstallPackageServiceException {
65
//		installerExecutionWizard.installFromDefaultDirectory();
66
//	}
67 67

  
68 68
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.main/src/main/java/org/gvsig/installer/main/creation/MakePluginPackageFrame.java
55 55
						applicationFolder, installFolder);
56 56
		installerCreationWizard
57 57
				.setWizardActionListener(new FrameWizardListener(this));
58
		this.add(installerCreationWizard);
58
		this.add(installerCreationWizard.asJComponent());
59 59
		pack();
60 60
	}
61 61

  
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/test/java/org/gvsig/installer/lib/impl/execution/InstallPackageServiceTest.java
60 60

  
61 61
		InstallPackageService installPackageService = InstallerLocator
62 62
				.getInstallerManager().getInstallPackageService();
63
		installPackageService.addBundlesFromDirectory(installersDirectory);
63
		installPackageService.addBundlesFromDirectory(installersDirectory, null);
64 64

  
65 65
		Assert.assertEquals(3, installPackageService.getPackageCount());
66 66

  
......
90 90

  
91 91
		InstallPackageService installerExecutionService = InstallerLocator
92 92
				.getInstallerManager().getInstallPackageService();
93
		installerExecutionService.addBundlesFromDirectory(installersDirectory);
93
		installerExecutionService.addBundlesFromDirectory(installersDirectory, null);
94 94

  
95 95
		PackageInfo packageInfo = installerExecutionService
96 96
				.getPackageInfo("org.gvsig.plugin1");
......
117 117

  
118 118
		InstallPackageService installerExecutionService = InstallerLocator
119 119
				.getInstallerManager().getInstallPackageService();
120
		installerExecutionService.addBundle(externalInstallationFile);
120
		installerExecutionService.addBundle(externalInstallationFile, null);
121 121

  
122 122
		PackageInfo packageInfo = installerExecutionService
123 123
				.getPackageInfo("org.gvsig.plugin1");
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/test/java/org/gvsig/installer/lib/impl/execution/InstallPackageServiceDumb.java
26 26
import java.io.File;
27 27
import java.net.URL;
28 28
import java.util.List;
29
import java.util.Properties;
29 30

  
30 31
import org.gvsig.installer.lib.api.PackageInfo;
31 32
import org.gvsig.installer.lib.api.execution.InstallPackageService;
......
35 36

  
36 37
public class InstallPackageServiceDumb implements InstallPackageService {
37 38

  
39
        @Override
38 40
	public Manager getManager() {
39 41
		return null;
40 42
	}
41 43

  
44
        @Override
42 45
	public void reset() {
43 46
	}
44 47

  
45
	public void addBundle(File bundleFile)
48
        @Override
49
	public void addBundle(File bundleFile, SimpleTaskStatus taskStatus)
46 50
			throws InstallPackageServiceException {
47 51
	}
48 52

  
49
	public void addBundle(URL bundleURL) throws InstallPackageServiceException {
53
        @Override
54
	public void addBundle(URL bundleURL, SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
50 55
	}
51 56

  
52
	public void addBundlesFromDirectory(File bundlesDirectory)
57
        @Override
58
	public void addBundlesFromDirectory(File bundlesDirectory, SimpleTaskStatus taskStatus)
53 59
			throws InstallPackageServiceException {
54 60
	}
55 61

  
62
        @Override
56 63
	public void installPackage(File applicationDirectory,
57 64
			PackageInfo packageInfo) throws InstallPackageServiceException {
58 65
	}
59 66

  
67
        @Override
60 68
	public void installPackage(File applicationDirectory, String packageCode)
61 69
			throws InstallPackageServiceException {
62 70
	}
63 71

  
72
        @Override
64 73
	public int getPackageCount() {
65 74
		return 0;
66 75
	}
67 76

  
77
        @Override
68 78
	public PackageInfo getPackageInfo(int index) {
69 79
		return null;
70 80
	}
71 81

  
82
        @Override
72 83
	public PackageInfo getPackageInfo(String packageCode) {
73 84
		return null;
74 85
	}
75 86

  
87
        @Override
76 88
	public void downloadPackage(PackageInfo packageInfo,
77 89
			SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
78 90
	}
79 91

  
92
        @Override
80 93
	public List<String> getDefaultSelectedPackagesIDs() {
81 94
		return null;
82 95
	}
83 96

  
97
        @Override
84 98
	public List<String> getCategories() {
85 99
		// TODO Auto-generated method stub
86 100
		return null;
87 101
	}
88 102

  
103
        @Override
89 104
	public List<String> getTypes() {
90 105
		// TODO Auto-generated method stub
91 106
		return null;
92 107
	}
93 108

  
109
    @Override
110
    public Properties getProperties() {
111
        return new Properties();
112
    }
113

  
114
    @Override
115
    public boolean needInstallPackageProviders() {
116
        return false;
117
    }
118

  
119
    @Override
120
    public void installPackageProviders(SimpleTaskStatus taskStatus) {
121
    }
122

  
123

  
94 124
}
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/test/java/org/gvsig/installer/lib/impl/creation/MakePluginPackageServiceTest.java
106 106
		InstallPackageService installPackageService = InstallerLocator
107 107
				.getInstallerManager().getInstallPackageService();
108 108

  
109
		installPackageService.addBundle(installerFile);
109
		installPackageService.addBundle(installerFile, null);
110 110
		assertEquals(1, installPackageService.getPackageCount());
111 111
		PackageInfo newInstallerInfo = makePluginPackageService
112 112
				.getPluginPackageInfo(0);
......
133 133
		// decompress the plugin and read the plugin information
134 134
		InstallPackageService installPackageService = InstallerLocator
135 135
				.getInstallerManager().getInstallPackageService();
136
		installPackageService.addBundle(installerFile);
136
		installPackageService.addBundle(installerFile, null);
137 137
		assertEquals(1, installPackageService.getPackageCount());
138 138
		PackageInfo newInstallerInfo = makePluginPackageService
139 139
				.getPluginPackageInfo(0);
......
162 162
		// decompress the plugin and read the plugin information
163 163
		InstallPackageService installPackageService = InstallerLocator
164 164
				.getInstallerManager().getInstallPackageService();
165
		installPackageService.addBundle(installerFile);
165
		installPackageService.addBundle(installerFile, null);
166 166
		assertEquals(1, installPackageService.getPackageCount());
167 167
		PackageInfo newInstallerInfo = makePluginPackageService
168 168
				.getPluginPackageInfo(0);
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
33 33
import java.io.OutputStream;
34 34
import java.util.List;
35 35
import java.util.Map;
36
import java.util.Properties;
36 37

  
37 38
import org.gvsig.installer.lib.api.PackageInfo;
38 39
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
......
45 46
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
46 47
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
47 48
import org.gvsig.tools.service.spi.AbstractProviderServices;
49
import org.gvsig.tools.task.SimpleTaskStatus;
48 50

  
49 51
/**
50 52
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
......
52 54
public class DefaultInstallerProviderServices extends AbstractProviderServices
53 55
		implements InstallPackageProviderServices {
54 56

  
55
	private List<String> defaultSelectedPacketsIDs = null;
57
    private List<String> defaultSelectedPacketsIDs = null;
58
    private Properties properties;
56 59

  
57 60
	// private static final Logger LOG = LoggerFactory
58 61
	// .getLogger(DefaultInstallerProviderServices.class);
......
156 159
		return decompress.searchPlugin(is, zipEntry);
157 160
	}
158 161

  
162
    @Override
159 163
	public void readPackageSetInfo(InputStream is,
160 164
			List<PackageInfo> installerInfos,
161
			Map<PackageInfo, String> zipEntriesMap)
165
			Map<PackageInfo, String> zipEntriesMap, SimpleTaskStatus taskStatus)
162 166
			throws InstallPackageServiceException {
163
		Decompress decompress = new Decompress();
164
		decompress
165
				.readPackageSetInstallInfos(is, installerInfos, zipEntriesMap);
167
		Decompress decompress = new Decompress(taskStatus);
168
		decompress.readPackageSetInstallInfos(is, installerInfos, zipEntriesMap);
166 169

  
167 170
		defaultSelectedPacketsIDs = decompress.getDefaultSelectedPackages();
171
                properties = decompress.getProperties();
168 172
	}
169 173

  
174
    @Override
170 175
	public void readPackageInfo(InputStream is,
171 176
			List<PackageInfo> installerInfos,
172
			Map<PackageInfo, String> zipEntriesMap, String name)
177
			Map<PackageInfo, String> zipEntriesMap, String name, SimpleTaskStatus taskStatus)
173 178
			throws InstallPackageServiceException {
174 179

  
175
		Decompress decompress = new Decompress();
180
		Decompress decompress = new Decompress(taskStatus);
176 181
		decompress.readPackageInstallInfo(is, installerInfos, zipEntriesMap,
177 182
				name);
178 183
	}
179 184

  
180
	public List<String> getDefaultSelectedPackagesIDs() {
181
		return defaultSelectedPacketsIDs;
182
	}
185
    @Override
186
    public List<String> getDefaultSelectedPackagesIDs() {
187
            return defaultSelectedPacketsIDs;
188
    }
189

  
190
    @Override
191
    public Properties getProperties() {
192
            return properties;
193
    }
183 194
}
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/execution/DefaultInstallPackageService.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10 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.
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15 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.
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
/*
25 24
 * AUTHORS (In addition to CIT):
26 25
 * 2010 {Prodevelop}   {Task}
27 26
 */
28

  
29 27
package org.gvsig.installer.lib.impl.execution;
30 28

  
31 29
import java.io.BufferedInputStream;
......
43 41
import java.util.HashSet;
44 42
import java.util.List;
45 43
import java.util.Map;
44
import java.util.Properties;
46 45
import java.util.Set;
46
import org.apache.commons.lang3.StringUtils;
47 47

  
48 48
import org.slf4j.Logger;
49 49
import org.slf4j.LoggerFactory;
......
68 68
/**
69 69
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
70 70
 */
71

  
72 71
public class DefaultInstallPackageService extends Thread implements
73
		InstallPackageService {
72
        InstallPackageService {
74 73

  
75
	private static final Logger LOG = LoggerFactory
76
			.getLogger(DefaultInstallPackageService.class);
77
	
78
	private static final String PACKAGE_FILE_NAME = "packages.gvspki";
74
    private static final Logger LOG = LoggerFactory
75
            .getLogger(DefaultInstallPackageService.class);
79 76

  
80
	private Map<PackageInfo, File> packageInfoFileMap = null;
81
	private Map<PackageInfo, String> zipEntriesMap = null;
82
	private List<PackageInfo> packageInfos = null;
83
	private InstallerManager manager;
84
	private InstallPackageProviderServices installerProviderServices = null;
77
    private static final String PACKAGE_FILE_NAME = "packages.gvspki";
85 78

  
86
	public DefaultInstallPackageService(DefaultInstallerManager manager) {
87
		super();
88
		this.manager = manager;
89
		this.reset();
90
	}
79
    private Map<PackageInfo, File> packageInfoFileMap = null;
80
    private Map<PackageInfo, String> zipEntriesMap = null;
81
    private List<PackageInfo> packageInfos = null;
82
    private InstallerManager manager;
83
    private InstallPackageProviderServices installerProviderServices = null;
91 84

  
92
	public void reset() {
93
		packageInfoFileMap = new HashMap<PackageInfo, File>();
94
		packageInfos = new ArrayList<PackageInfo>();
95
		zipEntriesMap = new HashMap<PackageInfo, String>();
96
		installerProviderServices = InstallerProviderLocator
97
				.getProviderManager().createInstallerProviderServices();
98
	}
85
    public DefaultInstallPackageService(DefaultInstallerManager manager) {
86
        super();
87
        this.manager = manager;
88
        this.reset();
89
    }
99 90

  
100
	public class InstallerApplicationDirectoryNotFoundException extends
101
			InstallPackageServiceException {
91
    public void reset() {
92
        packageInfoFileMap = new HashMap<PackageInfo, File>();
93
        packageInfos = new ArrayList<PackageInfo>();
94
        zipEntriesMap = new HashMap<PackageInfo, String>();
95
        installerProviderServices = InstallerProviderLocator
96
                .getProviderManager().createInstallerProviderServices();
97
    }
102 98

  
103
		private static final long serialVersionUID = -1130408094135962456L;
99
    public class InstallerApplicationDirectoryNotFoundException extends
100
            InstallPackageServiceException {
104 101

  
105
		private static final String message = "Aplication directory '%(directory)s' not found";
102
        private static final long serialVersionUID = -1130408094135962456L;
106 103

  
107
		private static final String KEY = "_aplication_directory_XdirectoryX_not_found";
104
        private static final String message = "Aplication directory '%(directory)s' not found";
108 105

  
109
		public InstallerApplicationDirectoryNotFoundException(File file) {
110
			super(message, KEY, serialVersionUID);
111
			setValue("directory", file.toString());
112
		}
106
        private static final String KEY = "_aplication_directory_XdirectoryX_not_found";
113 107

  
114
	}
108
        public InstallerApplicationDirectoryNotFoundException(File file) {
109
            super(message, KEY, serialVersionUID);
110
            setValue("directory", file.toString());
111
        }
115 112

  
116
	public class InstallerNoDirectoryException extends
117
			InstallPackageServiceException {
113
    }
118 114

  
119
		private static final long serialVersionUID = -8685263049644983769L;
115
    public class InstallerNoDirectoryException extends
116
            InstallPackageServiceException {
120 117

  
121
		private static final String message = "'%(directory)s' is not a directory";
118
        private static final long serialVersionUID = -8685263049644983769L;
122 119

  
123
		private static final String KEY = "_XdirectoryX_is_not_a_directory";
120
        private static final String message = "'%(directory)s' is not a directory";
124 121

  
125
		public InstallerNoDirectoryException(File file) {
126
			super(message, KEY, serialVersionUID);
127
			setValue("directory", file.toString());
128
		}
122
        private static final String KEY = "_XdirectoryX_is_not_a_directory";
129 123

  
130
	}
124
        public InstallerNoDirectoryException(File file) {
125
            super(message, KEY, serialVersionUID);
126
            setValue("directory", file.toString());
127
        }
131 128

  
132
	public class InstallerFileNotFoundException extends
133
			InstallPackageServiceException {
129
    }
134 130

  
135
		private static final long serialVersionUID = 556517830330132149L;
131
    public class InstallerFileNotFoundException extends
132
            InstallPackageServiceException {
136 133

  
137
		private static final String message = "File '%(file)s' not found";
134
        private static final long serialVersionUID = 556517830330132149L;
138 135

  
139
		private static final String KEY = "_file_XfileX_not_found";
136
        private static final String message = "File '%(file)s' not found";
140 137

  
141
		public InstallerFileNotFoundException(File file) {
142
			super(message, KEY, serialVersionUID);
143
			setValue("file", file.toString());
144
		}
138
        private static final String KEY = "_file_XfileX_not_found";
145 139

  
146
	}
140
        public InstallerFileNotFoundException(File file) {
141
            super(message, KEY, serialVersionUID);
142
            setValue("file", file.toString());
143
        }
147 144

  
148
	public class InstallerBundleNotFoundException extends
149
			InstallPackageServiceException {
145
    }
150 146

  
151
		private static final long serialVersionUID = 5065410511582625301L;
147
    public class InstallerBundleNotFoundException extends
148
            InstallPackageServiceException {
152 149

  
153
		private static final String message = "File '%(file)s' not found";
150
        private static final long serialVersionUID = 5065410511582625301L;
154 151

  
155
		private static final String KEY = "_file_XfileX_not_found";
152
        private static final String message = "File '%(file)s' not found";
156 153

  
157
		public InstallerBundleNotFoundException(File file,
158
				FileNotFoundException e) {
159
			super(message, e, KEY, serialVersionUID);
160
			setValue("file", file.toString());
161
		}
154
        private static final String KEY = "_file_XfileX_not_found";
162 155

  
163
	}
156
        public InstallerBundleNotFoundException(File file,
157
                FileNotFoundException e) {
158
            super(message, e, KEY, serialVersionUID);
159
            setValue("file", file.toString());
160
        }
164 161

  
165
	public class InstallerIOException extends InstallPackageServiceException {
162
    }
166 163

  
167
		private static final long serialVersionUID = 3153613550157712363L;
164
    public class InstallerIOException extends InstallPackageServiceException {
168 165

  
169
		private static final String message = "IO error installing the file '%(file)s'";
166
        private static final long serialVersionUID = 3153613550157712363L;
170 167

  
171
		private static final String KEY = "_IO_error installing_file_XfileX_";
168
        private static final String message = "IO error installing the file '%(file)s'";
172 169

  
173
		public InstallerIOException(File file, IOException e) {
174
			super(message, e, KEY, serialVersionUID);
175
			setValue("file", file.toString());
176
		}
170
        private static final String KEY = "_IO_error installing_file_XfileX_";
177 171

  
178
	}
172
        public InstallerIOException(File file, IOException e) {
173
            super(message, e, KEY, serialVersionUID);
174
            setValue("file", file.toString());
175
        }
179 176

  
180
	public class InstallerFileDownloadException extends
181
			InstallPackageServiceException {
177
    }
182 178

  
183
		private static final long serialVersionUID = 8640183295766490512L;
179
    public class InstallerFileDownloadException extends
180
            InstallPackageServiceException {
184 181

  
185
		private static final String message = "File '%(url)s' download error";
182
        private static final long serialVersionUID = 8640183295766490512L;
186 183

  
187
		private static final String KEY = "_File_XurlX_download_error";
184
        private static final String message = "File '%(url)s' download error";
188 185

  
189
		public InstallerFileDownloadException(URL url, IOException e) {
190
			super(message, e, KEY, serialVersionUID);
191
			setValue("url", url.toString());
192
		}
186
        private static final String KEY = "_File_XurlX_download_error";
193 187

  
194
	}
188
        public InstallerFileDownloadException(URL url, IOException e) {
189
            super(message, e, KEY, serialVersionUID);
190
            setValue("url", url.toString());
191
        }
195 192

  
196
	public class InstallerPackageNotFoundException extends
197
			InstallPackageServiceException {
193
    }
198 194

  
199
		private static final long serialVersionUID = 1726608498886963868L;
195
    public class InstallerPackageNotFoundException extends
196
            InstallPackageServiceException {
200 197

  
201
		private static final String message = "Package not found";
198
        private static final long serialVersionUID = 1726608498886963868L;
202 199

  
203
		private static final String KEY = "_package_not_found";
200
        private static final String message = "Package not found";
204 201

  
205
		public InstallerPackageNotFoundException() {
206
			super(message, KEY, serialVersionUID);
207
		}
202
        private static final String KEY = "_package_not_found";
208 203

  
209
	}
204
        public InstallerPackageNotFoundException() {
205
            super(message, KEY, serialVersionUID);
206
        }
210 207

  
211
	public class InstallerNoPackageException extends
212
			InstallPackageServiceException {
208
    }
213 209

  
214
		private static final long serialVersionUID = -2292735515704746966L;
210
    public class InstallerNoPackageException extends
211
            InstallPackageServiceException {
215 212

  
216
		private static final String message = "Package does not exist";
213
        private static final long serialVersionUID = -2292735515704746966L;
217 214

  
218
		private static final String KEY = "_package__does_not_exist";
215
        private static final String message = "Package does not exist";
219 216

  
220
		public InstallerNoPackageException() {
221
			super(message, KEY, serialVersionUID);
222
		}
217
        private static final String KEY = "_package__does_not_exist";
223 218

  
224
	}
219
        public InstallerNoPackageException() {
220
            super(message, KEY, serialVersionUID);
221
        }
225 222

  
226
	public class InstallerProviderCreationException extends
227
			InstallPackageServiceException {
223
    }
228 224

  
229
		private static final long serialVersionUID = -7985786807492393584L;
225
    public class InstallerProviderCreationException extends
226
            InstallPackageServiceException {
230 227

  
231
		private static final String message = "Error creating the provider";
228
        private static final long serialVersionUID = -7985786807492393584L;
232 229

  
233
		private static final String KEY = "_Error_creating_the_provider";
230
        private static final String message = "Error creating the provider";
234 231

  
235
		public InstallerProviderCreationException(ServiceException e) {
236
			super(message, e, KEY, serialVersionUID);
237
		}
232
        private static final String KEY = "_Error_creating_the_provider";
238 233

  
239
	}
234
        public InstallerProviderCreationException(ServiceException e) {
235
            super(message, e, KEY, serialVersionUID);
236
        }
240 237

  
241
	public void installPackage(File applicationDirectory,
242
			PackageInfo packageInfo) throws InstallPackageServiceException {
243
		if (!applicationDirectory.exists()) {
244
			LOG.warn("Can install package '"+packageInfo.getCode()+"', application folder '"+applicationDirectory.toString()+"' does not exits.");
245
			throw new InstallerApplicationDirectoryNotFoundException(
246
					applicationDirectory);
247
		}
248
		if (!packageInfoFileMap.containsKey(packageInfo)) {
249
			LOG.warn("Can install package '"+packageInfo.getCode()+"', package not found.");
250
			throw new InstallerPackageNotFoundException();
251
		}
238
    }
252 239

  
253
		InstallPackageProvider installerExecutionProvider = createProvider(packageInfo);
240
    public void installPackage(File applicationDirectory,
241
            PackageInfo packageInfo) throws InstallPackageServiceException {
242
        if (!applicationDirectory.exists()) {
243
            LOG.warn("Can install package '" + packageInfo.getCode() + "', application folder '" + applicationDirectory.toString() + "' does not exits.");
244
            throw new InstallerApplicationDirectoryNotFoundException(
245
                    applicationDirectory);
246
        }
247
        if (!packageInfoFileMap.containsKey(packageInfo)) {
248
            LOG.warn("Can install package '" + packageInfo.getCode() + "', package not found.");
249
            throw new InstallerPackageNotFoundException();
250
        }
254 251

  
255
		// Get the package or package set file
256
		File file = packageInfoFileMap.get(packageInfo);
257
		if (file == null) {
258
			if (packageInfo.getDownloadURL() == null) {
259
				throw new InstallerPackageNotFoundException();
260
			}
261
			this.downloadPackage(packageInfo);
262
			file = packageInfoFileMap.get(packageInfo);
263
		}
252
        InstallPackageProvider installerExecutionProvider = createProvider(packageInfo);
264 253

  
265
		// Open and install the package or package set file
266
		try {
254
        // Get the package or package set file
255
        File file = packageInfoFileMap.get(packageInfo);
256
        if (file == null) {
257
            if (packageInfo.getDownloadURL() == null) {
258
                throw new InstallerPackageNotFoundException();
259
            }
260
            this.downloadPackage(packageInfo);
261
            file = packageInfoFileMap.get(packageInfo);
262
        }
267 263

  
268
			InputStream packageStream;
269
			InputStream fis = new FileInputStream(file);
270
			InputStream bis = new BufferedInputStream(fis);
271
			if (isPackage(file)) {
272
				packageStream = bis;
273
			} else {
274
				if (!isPackageSet(file)) {
275
					LOG.info("Trying to install a package file ({0}) "
276
							+ "without a known file extension. Will try "
277
							+ "to install it as a package set", file);
278
				}
279
				packageStream = installerProviderServices.searchPackage(bis,
280
						zipEntriesMap.get(packageInfo));
281
			}
264
        // Open and install the package or package set file
265
        try {
282 266

  
283
			try {
284
				installerExecutionProvider.install(applicationDirectory,
285
						packageStream, packageInfo);
286
			} catch (InstallPackageServiceException e) {
267
            InputStream packageStream;
268
            InputStream fis = new FileInputStream(file);
269
            InputStream bis = new BufferedInputStream(fis);
270
            if (isPackage(file)) {
271
                packageStream = bis;
272
            } else {
273
                if (!isPackageSet(file)) {
274
                    LOG.info("Trying to install a package file ({0}) "
275
                            + "without a known file extension. Will try "
276
                            + "to install it as a package set", file);
277
                }
278
                packageStream = installerProviderServices.searchPackage(bis,
279
                        zipEntriesMap.get(packageInfo));
280
            }
287 281

  
288
				packageStream.close();
289
				if (bis != packageStream) {
290
					bis.close();
291
				}
292
				fis.close();
282
            try {
283
                installerExecutionProvider.install(applicationDirectory,
284
                        packageStream, packageInfo);
285
            } catch (InstallPackageServiceException e) {
293 286

  
294
				// if fails the installation, zip files need to be reopen
295
				// the package will be installed into the update folder for
296
				// installation after a gvSIG restart
287
                packageStream.close();
288
                if (bis != packageStream) {
289
                    bis.close();
290
                }
291
                fis.close();
297 292

  
298
				fis = new FileInputStream(file);
299
				bis = new BufferedInputStream(fis);
300
				if (isPackage(file)) {
301
					packageStream = bis;
302
				} else {
303
					if (!isPackageSet(file)) {
304
						LOG.info("Trying to install a package file ({0}) "
305
								+ "without a known file extension. Will try "
306
								+ "to install it as a package set", file);
307
					}
308
					packageStream = installerProviderServices.searchPackage(
309
							bis, zipEntriesMap.get(packageInfo));
310
				}
311
				installerExecutionProvider.installLater(applicationDirectory,
312
						packageStream, packageInfo);
313
			}
293
                // if fails the installation, zip files need to be reopen
294
                // the package will be installed into the update folder for
295
                // installation after a gvSIG restart
296
                fis = new FileInputStream(file);
297
                bis = new BufferedInputStream(fis);
298
                if (isPackage(file)) {
299
                    packageStream = bis;
300
                } else {
301
                    if (!isPackageSet(file)) {
302
                        LOG.info("Trying to install a package file ({0}) "
303
                                + "without a known file extension. Will try "
304
                                + "to install it as a package set", file);
305
                    }
306
                    packageStream = installerProviderServices.searchPackage(
307
                            bis, zipEntriesMap.get(packageInfo));
308
                }
309
                installerExecutionProvider.installLater(applicationDirectory,
310
                        packageStream, packageInfo);
311
            }
314 312

  
315
			packageStream.close();
316
			if (bis != packageStream) {
317
				bis.close();
318
			}
319
			fis.close();
313
            packageStream.close();
314
            if (bis != packageStream) {
315
                bis.close();
316
            }
317
            fis.close();
320 318

  
321
		} catch (FileNotFoundException e) {
322
			throw new InstallerFileNotFoundException(file);
323
		} catch (IOException e) {
324
			throw new InstallerIOException(file, e);
325
		}
319
        } catch (FileNotFoundException e) {
320
            throw new InstallerFileNotFoundException(file);
321
        } catch (IOException e) {
322
            throw new InstallerIOException(file, e);
323
        }
326 324

  
327
	}
325
    }
328 326

  
329
	public void installPackage(File applicationDirectory, String packageCode)
330
			throws InstallPackageServiceException {
331
		PackageInfo packageInfo = getPackageInfo(packageCode);
332
		if (packageInfo == null) {
333
			throw new InstallerNoPackageException();
334
		}
335
		installPackage(applicationDirectory, packageInfo);
336
	}
327
    public void installPackage(File applicationDirectory, String packageCode)
328
            throws InstallPackageServiceException {
329
        PackageInfo packageInfo = getPackageInfo(packageCode);
330
        if (packageInfo == null) {
331
            throw new InstallerNoPackageException();
332
        }
333
        installPackage(applicationDirectory, packageInfo);
334
    }
337 335

  
338
	private InstallPackageProvider createProvider(PackageInfo packageInfo)
339
			throws InstallPackageServiceException {
340
		InstallerProviderManager installerProviderManager = (InstallerProviderManager) ((DefaultInstallerManager) manager)
341
				.getProviderManager();
336
    private InstallPackageProvider createProvider(PackageInfo packageInfo)
337
            throws InstallPackageServiceException {
338
        InstallerProviderManager installerProviderManager = (InstallerProviderManager) ((DefaultInstallerManager) manager)
339
                .getProviderManager();
342 340

  
343
		try {
344
			return installerProviderManager.createExecutionProvider(packageInfo
345
					.getType());
346
		} catch (ServiceException e) {
347
			throw new InstallerProviderCreationException(e);
348
		}
349
	}
341
        try {
342
            return installerProviderManager.createExecutionProvider(packageInfo
343
                    .getType());
344
        } catch (ServiceException e) {
345
            throw new InstallerProviderCreationException(e);
346
        }
347
    }
350 348

  
351
	public PackageInfo getPackageInfo(int index) {
352
		if (index >= packageInfos.size()) {
353
			return null;
354
		}
355
		return packageInfos.get(index);
356
	}
349
    public PackageInfo getPackageInfo(int index) {
350
        if (index >= packageInfos.size()) {
351
            return null;
352
        }
353
        return packageInfos.get(index);
354
    }
357 355

  
358
	public PackageInfo getPackageInfo(String packageCode) {
359
		for (int i = 0; i < getPackageCount(); i++) {
360
			if (packageInfos.get(i).getCode().equals(packageCode)) {
361
				return packageInfos.get(i);
362
			}
363
		}
364
		return null;
365
	}
356
    public PackageInfo getPackageInfo(String packageCode) {
357
        for (int i = 0; i < getPackageCount(); i++) {
358
            if (packageInfos.get(i).getCode().equals(packageCode)) {
359
                return packageInfos.get(i);
360
            }
361
        }
362
        return null;
363
    }
366 364

  
367
	public void addBundle(File bundle) throws InstallPackageServiceException {
365
    @Override
366
    public void addBundle(File bundle, SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
368 367

  
369
		if (!bundle.exists()) {
370
			throw new InstallPackageServiceException();
371
		}
368
        if (!bundle.exists()) {
369
            throw new InstallPackageServiceException();
370
        }
372 371

  
373
		int packageInfoCount = packageInfos.size();
372
        int packageInfoCount = packageInfos.size();
374 373

  
375
		FileInputStream fis;
376
		try {
377
			fis = new FileInputStream(bundle);
378
		} catch (FileNotFoundException e) {
379
			throw new InstallerBundleNotFoundException(bundle, e);
380
		}
381
		BufferedInputStream bis = new BufferedInputStream(fis);
382
		if (isPackage(bundle)) {
383
			installerProviderServices.readPackageInfo(bis, packageInfos,
384
					zipEntriesMap, bundle.getName());
385
		} else {
386
			if (!isPackageSet(bundle)) {
387
				LOG
388
						.info(
389
								"Trying to add a package file ({0}) without a known "
390
										+ "file extension. Will try to add it as a package set",
391
								bundle);
392
			}
393
			installerProviderServices.readPackageSetInfo(fis, packageInfos,
394
					zipEntriesMap);
395
		}
396
		try {
397
			bis.close();
398
			fis.close();
399
		} catch (IOException e) {
400
			LOG.info("Error closing the input streams of the package file: "
401
					+ bundle, e);
402
		}
374
        FileInputStream fis;
375
        try {
376
            fis = new FileInputStream(bundle);
377
        } catch (FileNotFoundException e) {
378
            throw new InstallerBundleNotFoundException(bundle, e);
379
        }
380
        BufferedInputStream bis = new BufferedInputStream(fis);
381
        if (isPackage(bundle)) {
382
            installerProviderServices.readPackageInfo(bis, packageInfos,
383
                    zipEntriesMap, bundle.getName(), taskStatus);
384
        } else {
385
            if (!isPackageSet(bundle)) {
386
                LOG
387
                        .info(
388
                                "Trying to add a package file ({0}) without a known "
389
                                + "file extension. Will try to add it as a package set",
390
                                bundle);
391
            }
392
            installerProviderServices.readPackageSetInfo(fis, packageInfos,
393
                    zipEntriesMap, taskStatus);
394
        }
395
        try {
396
            bis.close();
397
            fis.close();
398
        } catch (IOException e) {
399
            LOG.info("Error closing the input streams of the package file: "
400
                    + bundle, e);
401
        }
403 402

  
404
		for (int i = packageInfoCount; i < packageInfos.size(); i++) {
405
			packageInfoFileMap.put(packageInfos.get(i), bundle);
406
		}
407
	}
403
        for (int i = packageInfoCount; i < packageInfos.size(); i++) {
404
            packageInfoFileMap.put(packageInfos.get(i), bundle);
405
        }
406
    }
408 407

  
409
	private boolean isPackageSet(File file) {
410
		return file.getName().endsWith(
411
				manager.getDefaultPackageSetFileExtension());
412
	}
408
    private boolean isPackageSet(File file) {
409
        return file.getName().endsWith(
410
                manager.getDefaultPackageSetFileExtension());
411
    }
413 412

  
414
	private boolean isPackage(File file) {
415
		return file.getName()
416
				.endsWith(manager.getDefaultPackageFileExtension());
417
	}
413
    private boolean isPackage(File file) {
414
        return file.getName()
415
                .endsWith(manager.getDefaultPackageFileExtension());
416
    }
418 417

  
419
	public void addBundle(URL bundleURL) throws InstallPackageServiceException {
420
		File bundle;
421
		String urlString = bundleURL.toString(); 
422
		if (urlString.endsWith(InstallerManager.PACKAGE_EXTENSION) || urlString.endsWith(InstallerManager.PACKAGE_INDEX_EXTENSION)) {
418
    @Override
419
    public void addBundle(URL bundleURL, SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
420
        File bundle;
421
        String urlString = bundleURL.toString();
422
        if (urlString.endsWith(InstallerManager.PACKAGE_EXTENSION) || urlString.endsWith(InstallerManager.PACKAGE_INDEX_EXTENSION)) {
423 423
            manager.setDownloadBaseURL(bundleURL);
424
			bundle = downloadFile(bundleURL, PACKAGE_FILE_NAME);
425
			addBundle(bundle);
426
		} else {
427
			if (!urlString.endsWith("/")) {
428
				urlString += "/";
429
			}
430
			
431
			Version version = manager.getVersionEx(); 
432
			urlString += ("dists/"
433
			+ version.getMayor() + "." + version.getMinor() + "."
434
			+ version.getRevision() + "/" + PACKAGE_FILE_NAME);
435
			
424
            bundle = downloadFile(bundleURL, PACKAGE_FILE_NAME);
425
            addBundle(bundle,taskStatus);
426
        } else {
427
            if (!urlString.endsWith("/")) {
428
                urlString += "/";
429
            }
436 430

  
437
			URL completeURL;
438
			try {
439
				completeURL = new URL(urlString);
440
			} catch (MalformedURLException e) {
441
				// TODO Auto-generated catch block
442
				e.printStackTrace();
443
				return;
444
			}
431
            Version version = manager.getVersionEx();
432
            urlString += ("dists/"
433
                    + version.getMayor() + "." + version.getMinor() + "."
434
                    + version.getRevision() + "/" + PACKAGE_FILE_NAME);
445 435

  
436
            URL completeURL;
437
            try {
438
                completeURL = new URL(urlString);
439
            } catch (MalformedURLException e) {
440
                // TODO Auto-generated catch block
441
                e.printStackTrace();
442
                return;
443
            }
444

  
446 445
            manager.setDownloadBaseURL(completeURL);
447
			bundle = downloadFile(completeURL, PACKAGE_FILE_NAME);
448
			addBundle(bundle);
449
		}
446
            bundle = downloadFile(completeURL, PACKAGE_FILE_NAME);
447
            addBundle(bundle,taskStatus);
448
        }
450 449

  
451
	}
450
    }
452 451

  
453
	private File downloadFile(URL bundleURL, String defaultFileName)
454
			throws InstallPackageServiceException {
455
		try {
456
			Download download = new Download();
457
			return download.downloadFile(bundleURL, defaultFileName);
458
		} catch (IOException e) {
459
			throw new InstallerFileDownloadException(bundleURL, e);
460
		}
461
	}
452
    private File downloadFile(URL bundleURL, String defaultFileName)
453
            throws InstallPackageServiceException {
454
        try {
455
            Download download = new Download();
456
            return download.downloadFile(bundleURL, defaultFileName);
457
        } catch (IOException e) {
458
            throw new InstallerFileDownloadException(bundleURL, e);
459
        }
460
    }
462 461

  
463
	public void addBundlesFromDirectory(File directory)
464
			throws InstallPackageServiceException {
465
		if (!directory.isDirectory()) {
466
			throw new InstallerNoDirectoryException(directory);
467
		}
468
		List<File> files = new ArrayList<File>();
462
    @Override
463
    public void addBundlesFromDirectory(File directory, SimpleTaskStatus taskStatus)
464
            throws InstallPackageServiceException {
465
        if (!directory.isDirectory()) {
466
            throw new InstallerNoDirectoryException(directory);
467
        }
468
        List<File> files = new ArrayList<File>();
469 469

  
470
		listRecursively(directory, new FileFilter() {
470
        listRecursively(directory, new FileFilter() {
471 471

  
472
			private String packageExt = manager
473
					.getDefaultPackageFileExtension();
474
			private String packageSetExt = manager
475
					.getDefaultPackageSetFileExtension();
472
            private String packageExt = manager
473
                    .getDefaultPackageFileExtension();
474
            private String packageSetExt = manager
475
                    .getDefaultPackageSetFileExtension();
476 476

  
477
			public boolean accept(File file) {
478
				String name = file.getName().toLowerCase();
479
				return file.isDirectory() || name.endsWith(packageExt)
480
						|| name.endsWith(packageSetExt);
481
			}
482
		}, files);
483
		for (int i = 0; i < files.size(); i++) {
484
			if (files.get(i).isFile()) {
485
				addBundle(files.get(i));
486
			}
487
		}
488
	}
477
            public boolean accept(File file) {
478
                String name = file.getName().toLowerCase();
479
                return file.isDirectory() || name.endsWith(packageExt)
480
                        || name.endsWith(packageSetExt);
481
            }
482
        }, files);
483
        for (int i = 0; i < files.size(); i++) {
484
            if (files.get(i).isFile()) {
485
                addBundle(files.get(i),taskStatus);
486
            }
487
        }
488
    }
489 489

  
490
	private void listRecursively(File fileOrDir, FileFilter filter,
491
			List<File> files) {
492
		files.add(fileOrDir);
490
    private void listRecursively(File fileOrDir, FileFilter filter,
491
            List<File> files) {
492
        files.add(fileOrDir);
493 493

  
494
		if (fileOrDir.isDirectory()) {
494
        if (fileOrDir.isDirectory()) {
495 495

  
496
			File[] dirContents = fileOrDir.listFiles(filter);
496
            File[] dirContents = fileOrDir.listFiles(filter);
497 497

  
498
			for (File f : dirContents) {
499
				listRecursively(f, filter, files); // Recursively list.
500
			}
501
		} else {
502
			files.add(fileOrDir);
503
		}
504
	}
498
            for (File f : dirContents) {
499
                listRecursively(f, filter, files); // Recursively list.
500
            }
501
        } else {
502
            files.add(fileOrDir);
503
        }
504
    }
505 505

  
506
	public int getPackageCount() {
507
		if (packageInfos == null) {
508
			return 0;
509
		}
510
		return packageInfos.size();
511
	}
506
    public int getPackageCount() {
507
        if (packageInfos == null) {
508
            return 0;
509
        }
510
        return packageInfos.size();
511
    }
512 512

  
513
	public Manager getManager() {
514
		return this.manager;
515
	}
513
    public Manager getManager() {
514
        return this.manager;
515
    }
516 516

  
517
	public void downloadPackage(PackageInfo packageInfo)
518
			throws InstallPackageServiceException {
519
		this.downloadPackage(packageInfo, null);
520
	}
517
    public void downloadPackage(PackageInfo packageInfo)
518
            throws InstallPackageServiceException {
519
        this.downloadPackage(packageInfo, null);
520
    }
521 521

  
522
	public void downloadPackage(PackageInfo packageInfo,
523
			SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
524
	    
525
		File file = null;
526
		
527
		try {
528
            file = packageInfo.downloadFile(taskStatus);
529
        } catch (BaseException e) {
530
            throw new InstallPackageServiceException(e);
522
    public void downloadPackage(PackageInfo packageInfo,
523
            SimpleTaskStatus taskStatus) throws InstallPackageServiceException {
524

  
525
        File file = packageInfoFileMap.get(packageInfo);
526
        if (file == null) {
527
            try {
528
                file = packageInfo.downloadFile(taskStatus);
529
            } catch (BaseException e) {
530
                throw new InstallPackageServiceException(e);
531
            }
532
            this.packageInfoFileMap.put(packageInfo, file);
531 533
        }
532
		this.packageInfoFileMap.put(packageInfo, file);
533
	}
534
    }
534 535

  
535
	public List<String> getDefaultSelectedPackagesIDs() {
536
		return installerProviderServices.getDefaultSelectedPackagesIDs();
537
	}
536
    public List<String> getDefaultSelectedPackagesIDs() {
537
        return installerProviderServices.getDefaultSelectedPackagesIDs();
538
    }
538 539

  
539
	public List<String> getCategories() {
540
		Set<String> categories = new HashSet<String>();
540
    @Override
541
    public Properties getProperties() {
542
        return installerProviderServices.getProperties();
543
    }
541 544

  
542
		for (int i = 0; i < packageInfos.size(); i++) {
543
			PackageInfo pkginfo = packageInfos.get(i);
544
			List<String> pkgcategories = pkginfo.getCategories();
545
			categories.addAll(pkgcategories);
546
		}
547
		try {
548
			PackageInfo[] pkgs = manager.getInstalledPackages();
549
			for (int i = 0; i < pkgs.length; i++) {
550
				PackageInfo pkginfo = pkgs[i];
551
				List<String> pkgcategories = pkginfo.getCategories();
552
				categories.addAll(pkgcategories);
553
			}
554
			
555
		} catch (MakePluginPackageServiceException e) {
556
			// Ignore exceptions
557
		}
558
		ArrayList<String> l = new ArrayList<String>(categories);
559
		Collections.sort(l);
560
		return l;
561
	}
545
    public List<String> getCategories() {
546
        Set<String> categories = new HashSet<String>();
562 547

  
563
	public List<String> getTypes() {
564
		Set<String> types = new HashSet<String>();
548
        for (int i = 0; i < packageInfos.size(); i++) {
549
            PackageInfo pkginfo = packageInfos.get(i);
550
            List<String> pkgcategories = pkginfo.getCategories();
551
            categories.addAll(pkgcategories);
552
        }
553
        try {
554
            PackageInfo[] pkgs = manager.getInstalledPackages();
555
            for (int i = 0; i < pkgs.length; i++) {
556
                PackageInfo pkginfo = pkgs[i];
557
                List<String> pkgcategories = pkginfo.getCategories();
558
                categories.addAll(pkgcategories);
559
            }
565 560

  
566
		for (int i = 0; i < packageInfos.size(); i++) {
567
			PackageInfo pkginfo = packageInfos.get(i);
568
			types.add(pkginfo.getType());
569
		}
570
		try {
571
			PackageInfo[] pkgs = manager.getInstalledPackages();
572
			for (int i = 0; i < pkgs.length; i++) {
573
				PackageInfo pkginfo = pkgs[i];
574
				types.add(pkginfo.getType());
575
			}
576
			
577
		} catch (MakePluginPackageServiceException e) {
578
			// Ignore exceptions
579
		}
580
		ArrayList<String> l = new ArrayList<String>(types);
581
		Collections.sort(l);
582
		return l;
583
	}
561
        } catch (MakePluginPackageServiceException e) {
562
            // Ignore exceptions
563
        }
564
        ArrayList<String> l = new ArrayList<String>(categories);
565
        Collections.sort(l);
566
        return l;
567
    }
584 568

  
569
    public List<String> getTypes() {
570
        Set<String> types = new HashSet<String>();
571

  
572
        for (int i = 0; i < packageInfos.size(); i++) {
573
            PackageInfo pkginfo = packageInfos.get(i);
574
            types.add(pkginfo.getType());
575
        }
576
        try {
577
            PackageInfo[] pkgs = manager.getInstalledPackages();
578
            for (int i = 0; i < pkgs.length; i++) {
579
                PackageInfo pkginfo = pkgs[i];
580
                types.add(pkginfo.getType());
581
            }
582

  
583
        } catch (MakePluginPackageServiceException e) {
584
            // Ignore exceptions
585
        }
586
        List<String> l = new ArrayList<>(types);
587
        Collections.sort(l);
588
        return l;
589
    }
590

  
591
    @Override
592
    public boolean needInstallPackageProviders() {
593
        boolean need = false;
594
        String ss = this.getProperties().getProperty("installers");
595
        if (ss != null) {
596
            String[] installerNames = StringUtils.split(ss);
597
            for (String installerName : installerNames) {
598
                InstallerProviderInstallers installer = new InstallerProviderInstallers(this, installerName);
599
                if( !installer.isAlreadyRegistered() ) {
600
                    need = true;
601
                    break;
602
                }
603
            }
604
        }
605
        return need;
606
    }
607

  
608
    @Override
609
    public void installPackageProviders(SimpleTaskStatus taskStatus) {
610
        Properties props = this.getProperties();
611
        String ss = props.getProperty("installers");
612
        if (ss == null) {
613
            return;
614
        }
615

  
616
        try {
617
            String[] installerNames = StringUtils.split(ss);
618
            taskStatus.setRangeOfValues(0, installerNames.length);
619
            int count=0;
620
            for (String installerName : installerNames) {
621
                taskStatus.message(installerName);
622
                taskStatus.setCurValue(count++);
623
                InstallerProviderInstallers installer = new InstallerProviderInstallers(this, installerName);
624
                installer.install();
625
            }
626
            taskStatus.setCurValue(count++);
627
        } finally {
628
            taskStatus.terminate();
629
        }
630
    }
631

  
585 632
}
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/utils/Decompress.java
37 37
import java.util.ArrayList;
38 38
import java.util.List;
39 39
import java.util.Map;
40
import java.util.Properties;
40 41
import java.util.zip.ZipEntry;
41 42
import java.util.zip.ZipException;
42 43
import java.util.zip.ZipInputStream;
......
45 46
import org.slf4j.LoggerFactory;
46 47
import org.apache.commons.io.FileUtils;
47 48
import org.apache.commons.io.FilenameUtils;
49
import org.apache.commons.io.IOUtils;
48 50
import org.gvsig.installer.lib.api.PackageInfo;
49 51
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
50 52
import org.gvsig.installer.lib.impl.DefaultPackageInfo;
51 53
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
52 54
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
53 55
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
54
import org.gvsig.tools.ToolsLocator;
55 56
import org.gvsig.tools.service.ServiceException;
56 57
import org.gvsig.tools.task.SimpleTaskStatus;
57
import org.gvsig.tools.task.TaskStatusManager;
58 58

  
59 59
/**
60 60
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
......
77 77
	private List<PackageInfo> selectedInstallerInfos = null;
78 78
	private Map<PackageInfo, String> zipEntriesMap = null;
79 79
	private List<String> defaultSelectedPackets = null;
80

  
80
        private Properties properties;
81
        private SimpleTaskStatus taskStatus = null;
82
        
81 83
	public Decompress() {
82

  
84
            this.properties = new Properties();
83 85
	}
84

  
86
        
87
	public Decompress(SimpleTaskStatus taskStatus) {
88
            this();
89
            this.taskStatus = taskStatus;
90
        }
91
        
85 92
	public void decompressPlugins(InputStream is, File outputDirectory)
86 93
			throws InstallPackageServiceException {
87 94
		option = OPTION_DECOMPRESS;
......
231 238

  
232 239
					defaultSelectedPackets = defaultPackagesList;
233 240
					out.flush();
234
				} else {
241
                                } else if (entry.getName().equals("packages.properties") ) {
242
                                    int count;
243
                                    byte data[] = new byte[BUFFER];
244
                                    ByteArrayOutputStream out = new ByteArrayOutputStream();
245

  
246
                                    while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
247
                                            out.write(data, 0, count);
248
                                    }
249
                                    InputStream in = new ByteArrayInputStream(out.toByteArray());
250
                                    properties.load(in);
251
                                    IOUtils.closeQuietly(in);
252
                                    IOUtils.closeQuietly(out);
253
                                } else {
235 254
//					logger.debug("Extracting all Plugins, plugin: " + name);
236 255
					if (option == OPTION_INSTALL) {
237 256

  
......
318 337
		byte data[] = new byte[BUFFER];
319 338
		int count = 0;
320 339

  
321
		TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
322
		SimpleTaskStatus taskStatus = manager
323
				.createDefaultSimpleTaskStatus("Uncompressing...");
324
		
325
		manager.add(taskStatus);
326 340
		int countRootFolders = 0;
327 341
		String entryName = "(header)";
328 342
		try {
329 343
			long readed = 0;
330
	
331
			// // First read all the contents size
332
			// zis = new ZipInputStream(inputStream);
333
			// while ((entry = zis.getNextEntry()) != null) {
334
			// count += entry.getSize();
335
			// }
336
			// // zis.close();
337
			// taskStatus.setRangeOfValues(0, count);
338
	
339
			// Return the stream to the initial position
344
                        if( taskStatus!=null ) {
345
                            taskStatus.push();
346
                        }
340 347
			zis = new ZipInputStream(inputStream);
341 348
			while ((entry = zis.getNextEntry()) != null) {
342 349
				entryName = FilenameUtils.separatorsToSystem(entry.getName());
343
				taskStatus.message(entryName);
350
                                if( taskStatus!=null ) {
351
                                    taskStatus.message(entryName);
352
                                }
344 353
	
345 354
				File file = new File(outputDirectory, entryName);
346 355
				if (file.exists()) {
......
365 374
					while ((count = zis.read(data, 0, BUFFER)) != -1) {
366 375
						fos.write(data, 0, count);
367 376
						readed += count;
368
						taskStatus.setCurValue(readed);
377
                                                if( taskStatus!=null ) {
378
                                                    taskStatus.setCurValue(readed);
379
                                                }
369 380
					}
370 381
					fos.flush();
371 382
					fos.close();
......
379 390
		} catch(RuntimeException ex) {
380 391
			logger.warn("Problems uncompresing plugin (last entry '"+entryName+"'.",ex);
381 392
			throw ex;
382
			
383
		} finally {
384
		    
385
		    taskStatus.remove();
386
		    
387
		}
388
		
389
        
393
                } finally {
394
                    if( taskStatus!=null ) {
395
                        taskStatus.pop();
396
                    }
397
                }
390 398
	}
391 399

  
392 400
	private void createParentFolder(File file) {
......
435 443
		InstallerInfoFileReader installerInfoFileReader = new InstallerInfoFileReader();
436 444
		installerInfoFileReader.read(installerInfo, new ByteArrayInputStream(
437 445
				out.toByteArray()));
438

  
446
                if( taskStatus!=null ) {                
447
                    taskStatus.message(installerInfo.getName());
448
                }
439 449
		return installerInfo;
440 450
	}
441 451

  
......
447 457
	public List<String> getDefaultSelectedPackages() {
448 458
		return defaultSelectedPackets;
449 459
	}
460
        
461
	public Properties getProperties() {
462
		return properties;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff