OSDN Git Service

update install process. add stigmata plugin check
authortama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Wed, 24 Dec 2008 08:39:38 +0000 (08:39 +0000)
committertama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Wed, 24 Dec 2008 08:39:38 +0000 (08:39 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/stigmata/trunk@364 acee48c3-7b26-0410-bdac-b3d0e5314bbc

src/main/java/jp/sourceforge/stigmata/command/InstallCommand.java
src/main/java/jp/sourceforge/stigmata/ui/swing/StigmataFrame.java
src/main/java/jp/sourceforge/stigmata/utils/Utility.java
src/main/resources/resources/messages.properties
src/main/resources/resources/messages_ja.source

index b1d04d4..a3092b1 100644 (file)
@@ -14,6 +14,7 @@ import java.io.OutputStream;
 import jp.sourceforge.stigmata.BirthmarkContext;
 import jp.sourceforge.stigmata.BirthmarkEnvironment;
 import jp.sourceforge.stigmata.Stigmata;
+import jp.sourceforge.stigmata.utils.Utility;
 
 /**
  * 
@@ -38,8 +39,8 @@ public class InstallCommand extends AbstractStigmataCommand{
             File pluginSource = new File(args[i]);
             File pluginDest = new File(pluginsDir, pluginSource.getName());
 
-            if(!pluginSource.getName().endsWith(".jar")){
-                throw new IllegalArgumentException("plugin is allowed only jar archive: " + args[i]);
+            if(!Utility.isStigmataPluginJarFile(pluginSource)){
+                throw new IllegalArgumentException(pluginSource + ": not stigmata plugin file.");
             }
             if(pluginDest.exists()){
                 String override = env.getProperty("override.exists.plugin");
index c8742b4..94cf325 100644 (file)
@@ -16,8 +16,10 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.swing.ButtonGroup;
@@ -447,25 +449,43 @@ public class StigmataFrame extends JFrame{
             new String[] { "jar", },
             messages.get("installplugin.fileopen.description")
         );
-        if(pluginFile != null && pluginFile.exists()){
-            StigmataCommandFactory factory = StigmataCommandFactory.getInstance();
-            StigmataCommand command = factory.getCommand("install");
+        List<String> messages = new ArrayList<String>();
+
+        if(Utility.isStigmataPluginJarFile(pluginFile, messages)){
+            StigmataCommand command = StigmataCommandFactory.getInstance().getCommand("install");
             String path = pluginFile.getPath();
             command.perform(getStigmata(), new String[] { path });
-        }
 
-        int flag = JOptionPane.showConfirmDialog(
-            this, getMessages().get("reload.after.installplugin"),
-            getMessages().get("reload.after.installplugin.title"),
-            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE
-        );
+            int flag = JOptionPane.showConfirmDialog(
+                this, getMessages().get("reload.after.installplugin"),
+                getMessages().get("reload.after.installplugin.title"),
+                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE
+            );
 
-        if(flag == JOptionPane.YES_OPTION){
-            reloadSettings(new String[] { "gui", });
+            if(flag == JOptionPane.YES_OPTION){
+                reloadSettings(new String[] { "gui", });
+            }
+            else{
+                JOptionPane.showMessageDialog(
+                    this, getMessages().get("reload.manually"),
+                    getMessages().get("reload.manually.title"),
+                    JOptionPane.INFORMATION_MESSAGE
+                );
+            }
         }
         else{
+            StringBuilder sb = new StringBuilder("<html><body>");
+            sb.append("<p>").append(getMessages().format("install.error", pluginFile.getPath())).append("</p>");
+            sb.append("<ul>");
+            for(String message: messages){
+                sb.append("<li>").append(getMessages().get(message)).append("</li>");
+            }
+            sb.append("</ul></body></html>");
+
             JOptionPane.showMessageDialog(
-                this, getMessages().get("reload.manually")
+                this, new String(sb),
+                getMessages().get("install.error.title"),
+                JOptionPane.ERROR_MESSAGE
             );
         }
     }
index 8fe8cef..fc1be95 100755 (executable)
@@ -1,6 +1,11 @@
 package jp.sourceforge.stigmata.utils;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
 public class Utility{
     /**
@@ -31,4 +36,39 @@ public class Utility{
         }
         return new String(builder);
     }
+
+    public static boolean isStigmataPluginJarFile(File pluginFile){
+        return isStigmataPluginJarFile(pluginFile, new ArrayList<String>());
+    }
+
+    public static boolean isStigmataPluginJarFile(File pluginFile, List<String> messages){
+        boolean flag = true;
+        if(pluginFile == null){
+            flag = false;
+        }
+        if(!pluginFile.getName().endsWith(".jar")){
+            messages.add("install.error.notjarfile");
+            flag = false;
+        }
+        if(!pluginFile.exists()){
+            messages.add("install.error.file.missing");
+            flag = false;
+        }
+
+        // check service descriptor.
+        if(flag){
+            try{
+                JarFile jarfile = new JarFile(pluginFile);
+                JarEntry entry = jarfile.getJarEntry("META-INF/services/jp.sourceforge.stigmata.spi.BirthmarkSpi");
+                if(entry == null){
+                    messages.add("install.error.servicedescriptor.missing");
+                    flag = false;
+                }
+                jarfile.close();
+            } catch(IOException e){
+                e.printStackTrace();
+            }
+        }
+        return flag;
+    }
 }
index 349ff96..ab7274a 100755 (executable)
@@ -48,10 +48,17 @@ installplugin.menuitem.label=Install Plugin...
 installplugin.menuitem.tooltip=Install stigmata plugin\r
 installplugin.menuitem.icon=cup_add.png\r
 installplugin.fileopen.description=Stigmata plugin jar file.\r
-reload.after.installplugin=Finish plugin installation.\r
-To use installed plugin, restart Stigmata for using installed plugin.\r
-reload.after.installplugin.title=Restart Stigmata NOW?\r
-reload.manually=Restart stigmata manualy.\r
+reload.after.installplugin=<html><body><p>Finish plugin installation.<br>\r
+To use installed plugin, restart Stigmata for using installed plugin.<br>\r
+reload.after.installplugin.title=Restart Stigmata NOW?</p></body></html>\r
+reload.manually.title=Restart\r
+reload.manually=Restart stigmata or select menu item named ``${refreshsetting.menuitem.label}'' in ``${fileMenu.menu.label}'' menu.\r
+install.error.title=Install Failed\r
+install.error={0}: Instalation is failed.\\r
+Causes is as follows.\r
+install.error.file.missing=File is not found\r
+install.error.servicedescriptor.missing=Service descriptor is missing.\r
+install.error.notjarfile=Not jar file.\r
 \r
 savesetting.menuitem.label=Save settings\r
 savesetting.menuitem.tooltip=Save current settings\r
index a6869ce..98e4e18 100755 (executable)
@@ -39,7 +39,15 @@ installplugin.menuitem.tooltip=Stigmata
 installplugin.fileopen.description=Stigmata\82Ì\83v\83\89\83O\83C\83\93jar\83t\83@\83C\83\8b\r
 reload.after.installplugin=<html><body><p>\83v\83\89\83O\83C\83\93\82Ì\83C\83\93\83X\83g\81[\83\8b\82Í\8fI\97¹\82µ\82Ü\82µ\82½\81D<br>\83C\83\93\83X\83g\81[\83\8b\82µ\82½\83v\83\89\83O\83C\83\93\82ð\8eg\82¤\82½\82ß\82É\82Í\81CStigmata\82ð\8dÄ\8bN\93®\82·\82é\95K\97v\82ª\82 \82è\82Ü\82·\81D<br>\8dÄ\8bN\93®\82µ\82Ü\82·\82©\81D</p></body></html>\r
 reload.after.installplugin.title=Stigmata\82Ì\8dÄ\8bN\93®\r
-reload.manually=\83C\83\93\83X\83g\81[\83\8b\82µ\82½\83v\83\89\83O\83C\83\93\82ÍStigmata\82Ì\8dÄ\8bN\93®\8cã\81C\8eg\82¦\82é\82æ\82¤\82É\82È\82è\82Ü\82·\81D\r
+reload.manually.title=\8dÄ\8bN\93®\r
+reload.manually=<html><body><p>\83C\83\93\83X\83g\81[\83\8b\82µ\82½\83v\83\89\83O\83C\83\93\82ð\8eg\82¤\82½\82ß\82É\81CStigmata\82ð\8dÄ\8bN\93®\81C<br>\82à\82µ\82­\82Í\81C\81u${fileMenu.menu.label}\81v\83\81\83j\83\85\81[\82©\82ç\81u${refreshsetting.menuitem.label}\81v\82ð\91I\91ð\82µ\82Ä\82­\82¾\82³\82¢\81D</p></body></html>\r
+\r
+install.error.title=\83C\83\93\83X\83g\81[\83\8b\8e¸\94s\r
+install.error={0}: \83C\83\93\83X\83g\81[\83\8b\82É\8e¸\94s\82µ\82Ü\82µ\82½\81D\\r
+\8c´\88ö\82Í\88È\89º\82Ì\92Ê\82è\82Å\82·\81D\r
+install.error.file.missing=\83t\83@\83C\83\8b\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ\81D\r
+install.error.servicedescriptor.missing=\83T\81[\83r\83X\8bL\8fq\8eq\82ªjar\83t\83@\83C\83\8b\93à\82É\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82¹\82ñ\81D\r
+install.error.notjarfile=jar\83t\83@\83C\83\8b\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81D\r
 \r
 savesetting.menuitem.label=\90Ý\92è\82ð\95Û\91\r
 savesetting.menuitem.tooltip=\8c»\8dÝ\82Ì\90Ý\92è\82ð\95Û\91\82µ\82Ü\82·\r