1 package jp.sourceforge.stigmata.command;
8 import java.io.FileInputStream;
9 import java.io.FileOutputStream;
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.io.OutputStream;
14 import jp.sourceforge.stigmata.BirthmarkContext;
15 import jp.sourceforge.stigmata.BirthmarkEnvironment;
16 import jp.sourceforge.stigmata.Stigmata;
20 * @author Haruaki Tamada
23 public class InstallCommand extends AbstractStigmataCommand{
24 public boolean isAvailableArguments(String[] args){
25 return args.length > 0;
29 public String getCommandString(){
33 public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
34 File pluginsDir = new File(BirthmarkEnvironment.getStigmataHome(), "plugins");
35 BirthmarkEnvironment env = context.getEnvironment();
37 for(int i = 0; i < args.length; i++){
38 File pluginSource = new File(args[i]);
39 File pluginDest = new File(pluginsDir, pluginSource.getName());
41 if(!pluginSource.getName().endsWith(".jar")){
42 throw new IllegalArgumentException("plugin is allowed only jar archive: " + args[i]);
44 if(pluginDest.exists()){
45 String override = env.getProperty("override.exists.plugin");
46 if(override != null && (override.equalsIgnoreCase("true") || override.equalsIgnoreCase("yes"))){
50 File backupFile = new File(pluginDest.getParent(), pluginDest.getName() + ".back");
51 if(backupFile.exists()) backupFile.delete();
52 pluginDest.renameTo(backupFile);
56 byte[] data = new byte[256];
60 InputStream in = new FileInputStream(pluginSource);
61 OutputStream out = new FileOutputStream(pluginDest);
63 while((read = in.read(data)) != -1){
64 out.write(data, 0, read);
68 } catch(IOException e){