|
27 | 27 | import org.elasticsearch.common.component.LifecycleComponent;
|
28 | 28 | import org.elasticsearch.common.inject.Inject;
|
29 | 29 | import org.elasticsearch.common.inject.Module;
|
30 |
| -import org.elasticsearch.common.io.Streams; |
31 | 30 | import org.elasticsearch.common.settings.Settings;
|
32 | 31 | import org.elasticsearch.env.Environment;
|
33 | 32 | import org.elasticsearch.index.CloseableIndexComponent;
|
34 | 33 |
|
35 |
| -import java.io.*; |
| 34 | +import java.io.File; |
| 35 | +import java.io.IOException; |
| 36 | +import java.io.InputStream; |
36 | 37 | import java.lang.reflect.Method;
|
37 | 38 | import java.net.URL;
|
38 | 39 | import java.util.*;
|
39 |
| -import java.util.zip.ZipEntry; |
40 |
| -import java.util.zip.ZipFile; |
41 | 40 |
|
42 | 41 | import static org.elasticsearch.common.collect.Maps.*;
|
43 |
| -import static org.elasticsearch.common.io.FileSystemUtils.*; |
44 | 42 |
|
45 | 43 | /**
|
46 | 44 | * @author kimchy (shay.banon)
|
@@ -163,115 +161,21 @@ private void loadPluginsIntoClassLoader() {
|
163 | 161 |
|
164 | 162 | File[] pluginsFiles = pluginsFile.listFiles();
|
165 | 163 | for (File pluginFile : pluginsFiles) {
|
166 |
| - if (!pluginFile.getName().endsWith(".zip")) { |
167 |
| - if (pluginFile.isDirectory()) { |
168 |
| - logger.trace("--- adding expanded plugin [" + pluginFile.getAbsolutePath() + "]"); |
169 |
| - try { |
170 |
| - // add the root |
171 |
| - addURL.invoke(classLoader, pluginFile.toURI().toURL()); |
172 |
| - // if there are jars in it, add it as well |
173 |
| - for (File jarToAdd : pluginFile.listFiles()) { |
174 |
| - if (!(jarToAdd.getName().endsWith(".jar") || jarToAdd.getName().endsWith(".zip"))) { |
175 |
| - continue; |
176 |
| - } |
177 |
| - addURL.invoke(classLoader, jarToAdd.toURI().toURL()); |
178 |
| - } |
179 |
| - } catch (Exception e) { |
180 |
| - logger.warn("failed to add plugin [" + pluginFile + "]", e); |
181 |
| - } |
182 |
| - } |
183 |
| - |
184 |
| - continue; |
185 |
| - } |
186 |
| - if (logger.isTraceEnabled()) { |
187 |
| - logger.trace("processing [{}]", pluginFile); |
188 |
| - } |
189 |
| - |
190 |
| - String pluginNameNoExtension = pluginFile.getName().substring(0, pluginFile.getName().lastIndexOf('.')); |
191 |
| - File extractedPluginDir = new File(new File(environment.workFile(), "plugins"), pluginNameNoExtension); |
192 |
| - extractedPluginDir.mkdirs(); |
193 |
| - |
194 |
| - File stampsDir = new File(new File(environment.workFile(), "plugins"), "_stamps"); |
195 |
| - stampsDir.mkdirs(); |
196 |
| - |
197 |
| - boolean extractPlugin = true; |
198 |
| - File stampFile = new File(stampsDir, pluginNameNoExtension + ".stamp"); |
199 |
| - if (stampFile.exists()) { |
200 |
| - // read it, and check if its the same size as the pluginFile |
201 |
| - RandomAccessFile raf = null; |
202 |
| - try { |
203 |
| - raf = new RandomAccessFile(stampFile, "r"); |
204 |
| - long size = raf.readLong(); |
205 |
| - if (size == pluginFile.length()) { |
206 |
| - extractPlugin = false; |
207 |
| - if (logger.isTraceEnabled()) { |
208 |
| - logger.trace("--- no need to extract plugin, same size [" + size + "]"); |
209 |
| - } |
210 |
| - } |
211 |
| - } catch (Exception e) { |
212 |
| - // ignore and extract the plugin |
213 |
| - } finally { |
214 |
| - if (raf != null) { |
215 |
| - try { |
216 |
| - raf.close(); |
217 |
| - } catch (IOException e) { |
218 |
| - // ignore |
219 |
| - } |
220 |
| - } |
221 |
| - } |
222 |
| - } |
223 |
| - |
224 |
| - if (extractPlugin) { |
225 |
| - if (logger.isTraceEnabled()) { |
226 |
| - logger.trace("--- extracting plugin to [" + extractedPluginDir + "]"); |
227 |
| - } |
228 |
| - deleteRecursively(extractedPluginDir, false); |
229 |
| - |
230 |
| - ZipFile zipFile = null; |
| 164 | + if (pluginFile.isDirectory()) { |
| 165 | + logger.trace("--- adding plugin [" + pluginFile.getAbsolutePath() + "]"); |
231 | 166 | try {
|
232 |
| - zipFile = new ZipFile(pluginFile); |
233 |
| - Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); |
234 |
| - while (zipEntries.hasMoreElements()) { |
235 |
| - ZipEntry zipEntry = zipEntries.nextElement(); |
236 |
| - if (!(zipEntry.getName().endsWith(".jar") || zipEntry.getName().endsWith(".zip"))) { |
| 167 | + // add the root |
| 168 | + addURL.invoke(classLoader, pluginFile.toURI().toURL()); |
| 169 | + // if there are jars in it, add it as well |
| 170 | + for (File jarToAdd : pluginFile.listFiles()) { |
| 171 | + if (!(jarToAdd.getName().endsWith(".jar") || jarToAdd.getName().endsWith(".zip"))) { |
237 | 172 | continue;
|
238 | 173 | }
|
239 |
| - String name = zipEntry.getName().replace('\\', '/'); |
240 |
| - File target = new File(extractedPluginDir, name); |
241 |
| - Streams.copy(zipFile.getInputStream(zipEntry), new FileOutputStream(target)); |
| 174 | + addURL.invoke(classLoader, jarToAdd.toURI().toURL()); |
242 | 175 | }
|
243 | 176 | } catch (Exception e) {
|
244 |
| - logger.warn("failed to extract plugin [" + pluginFile + "], ignoring...", e); |
245 |
| - continue; |
246 |
| - } finally { |
247 |
| - if (zipFile != null) { |
248 |
| - try { |
249 |
| - zipFile.close(); |
250 |
| - } catch (IOException e) { |
251 |
| - // ignore |
252 |
| - } |
253 |
| - } |
| 177 | + logger.warn("failed to add plugin [" + pluginFile + "]", e); |
254 | 178 | }
|
255 |
| - |
256 |
| - try { |
257 |
| - RandomAccessFile raf = new RandomAccessFile(stampFile, "rw"); |
258 |
| - raf.writeLong(pluginFile.length()); |
259 |
| - raf.close(); |
260 |
| - } catch (Exception e) { |
261 |
| - // ignore |
262 |
| - } |
263 |
| - |
264 |
| - } |
265 |
| - |
266 |
| - try { |
267 |
| - for (File jarToAdd : extractedPluginDir.listFiles()) { |
268 |
| - if (!(jarToAdd.getName().endsWith(".jar") || jarToAdd.getName().endsWith(".zip"))) { |
269 |
| - continue; |
270 |
| - } |
271 |
| - addURL.invoke(classLoader, jarToAdd.toURI().toURL()); |
272 |
| - } |
273 |
| - } catch (Exception e) { |
274 |
| - logger.warn("failed to add plugin [" + pluginFile + "]", e); |
275 | 179 | }
|
276 | 180 | }
|
277 | 181 | }
|
|
0 commit comments