1 package com.atlassian.plugin.repositories;
2
3 import com.atlassian.plugin.PluginInstaller;
4 import com.atlassian.plugin.PluginJar;
5
6 import org.apache.commons.io.IOUtils;
7
8 import java.io.File;
9 import java.io.FileOutputStream;
10 import java.io.IOException;
11 import java.io.OutputStream;
12
13
14
15
16
17
18
19 public class FilePluginInstaller implements PluginInstaller
20 {
21 private File directory;
22
23
24
25
26 public FilePluginInstaller(File directory)
27 {
28 this.directory = directory;
29 }
30
31
32
33
34
35
36 public void installPlugin(String key, PluginJar pluginJar)
37 {
38 File newPluginFile = new File(directory, pluginJar.getFileName());
39 if (newPluginFile.exists())
40 newPluginFile.delete();
41
42 OutputStream os = null;
43 try
44 {
45 os= new FileOutputStream(newPluginFile);
46 IOUtils.copy(pluginJar.getInputStream(), os);
47 }
48 catch (IOException e)
49 {
50 throw new RuntimeException("Could not install plugin: " + pluginJar, e);
51 }
52 finally
53 {
54 IOUtils.closeQuietly(os);
55 }
56 }
57 }