OSDN Git Service

fixed findbugs warnings. fix_findbugs
authorHaruaki Tamada <tamada@cc.kyoto-su.ac.jp>
Sat, 3 Dec 2011 08:35:15 +0000 (17:35 +0900)
committerHaruaki Tamada <tamada@cc.kyoto-su.ac.jp>
Sat, 3 Dec 2011 08:35:15 +0000 (17:35 +0900)
47 files changed:
src/main/java/jp/sourceforge/stigmata/BirthmarkEngine.java
src/main/java/jp/sourceforge/stigmata/BirthmarkSet.java
src/main/java/jp/sourceforge/stigmata/BirthmarkSpiComparator.java
src/main/java/jp/sourceforge/stigmata/BirthmarkStoreTarget.java
src/main/java/jp/sourceforge/stigmata/Stigmata.java
src/main/java/jp/sourceforge/stigmata/birthmarks/NullBirthmarkElement.java
src/main/java/jp/sourceforge/stigmata/birthmarks/comparators/CosineSimilarityBirthmarkComparator.java
src/main/java/jp/sourceforge/stigmata/birthmarks/cvfv/ConstantValueOfFieldVariableBirthmarkExtractVisitor.java
src/main/java/jp/sourceforge/stigmata/birthmarks/cvfv/ConstantValueOfFieldVariableBirthmarkExtractor.java
src/main/java/jp/sourceforge/stigmata/birthmarks/cvfv/TypeAndValueBirthmarkElement.java
src/main/java/jp/sourceforge/stigmata/birthmarks/smc/MethodCallBirthmarkElement.java
src/main/java/jp/sourceforge/stigmata/command/AbstractStigmataCommand.java
src/main/java/jp/sourceforge/stigmata/command/CompareCommand.java
src/main/java/jp/sourceforge/stigmata/command/ExportConfigCommand.java
src/main/java/jp/sourceforge/stigmata/command/ExtractCommand.java
src/main/java/jp/sourceforge/stigmata/command/InstallCommand.java
src/main/java/jp/sourceforge/stigmata/command/LicenseCommand.java
src/main/java/jp/sourceforge/stigmata/command/ListBirthmarksCommand.java
src/main/java/jp/sourceforge/stigmata/command/UninstallCommand.java
src/main/java/jp/sourceforge/stigmata/event/WarningMessages.java
src/main/java/jp/sourceforge/stigmata/filter/AbstractComparisonPairFilter.java
src/main/java/jp/sourceforge/stigmata/filter/BirthmarkElementCountComparisonPairFilter.java
src/main/java/jp/sourceforge/stigmata/filter/SimilarityComparisonPairFilter.java
src/main/java/jp/sourceforge/stigmata/filter/TargetNameComparisonPairFilter.java
src/main/java/jp/sourceforge/stigmata/filter/TotalElementCountComparisonPairFilter.java
src/main/java/jp/sourceforge/stigmata/result/CertainPairComparisonResultSet.java
src/main/java/jp/sourceforge/stigmata/result/RDBExtractionResultSet.java
src/main/java/jp/sourceforge/stigmata/result/RoundRobinComparisonResultSet.java
src/main/java/jp/sourceforge/stigmata/result/XmlFileExtractionResultSet.java
src/main/java/jp/sourceforge/stigmata/result/history/ExtractedBirthmarkServiceManager.java
src/main/java/jp/sourceforge/stigmata/ui/swing/BirthmarkSelectablePane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/ClassNameObfuscator.java
src/main/java/jp/sourceforge/stigmata/ui/swing/ClippedLRListCellRenderer.java
src/main/java/jp/sourceforge/stigmata/ui/swing/ControlPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/RoundRobinComparisonResultPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/StigmataFrame.java
src/main/java/jp/sourceforge/stigmata/ui/swing/TargetSelectionPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/UpdatePluginsPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/actions/SaveAction.java
src/main/java/jp/sourceforge/stigmata/ui/swing/graph/SimilarityDistributionGraphPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/mds/LabelMap.java
src/main/java/jp/sourceforge/stigmata/ui/swing/mds/MdsViewerPane.java
src/main/java/jp/sourceforge/stigmata/ui/swing/tab/EditableTabbedPaneFocusTraversalPolicy.java
src/main/java/jp/sourceforge/stigmata/utils/ArrayIterator.java
src/main/java/jp/sourceforge/stigmata/utils/ConfigFileExporter.java
src/main/java/jp/sourceforge/stigmata/utils/HermesUtility.java
src/main/java/jp/sourceforge/stigmata/utils/Utility.java

index 2e01d89..e2d06c1 100644 (file)
@@ -6,6 +6,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -202,6 +203,7 @@ public class BirthmarkEngine{
             break;
         case ROUND_ROBIN_XY:
             crs = new RoundRobinComparisonResultSet(er, true);
+            break;
         case GUESSED_PAIR:
             crs = new CertainPairComparisonResultSet(er);
             break;
@@ -260,7 +262,7 @@ public class BirthmarkEngine{
         }
     }
 
-    public BirthmarkContext prepare(String[] targetX, String[] targetY, BirthmarkContext context) throws MalformedURLException, IOException{
+    public synchronized BirthmarkContext prepare(String[] targetX, String[] targetY, BirthmarkContext context) throws MalformedURLException, IOException{
         StigmataHookManager.getInstance().runHook(Phase.BEFORE_PREPROCESS, context);
 
         Set<String> set = new HashSet<String>();
@@ -284,7 +286,7 @@ public class BirthmarkEngine{
         return context;
     }
 
-    private String[] mergeTarget(String[] t1, String[] t2){
+    private synchronized String[] mergeTarget(String[] t1, String[] t2){
         List<String> list = new ArrayList<String>();
         addToList(list, t1);
         addToList(list, t2);
@@ -292,7 +294,7 @@ public class BirthmarkEngine{
         return list.toArray(new String[list.size()]);
     }
 
-    private void addToList(List<String> list, String[] target){
+    private synchronized void addToList(List<String> list, String[] target){
         if(target != null){
             for(String s: target){
                 list.add(s);
@@ -300,7 +302,7 @@ public class BirthmarkEngine{
         }
     }
 
-    private BirthmarkSet[] extractImpl(String[] target, ExtractionResultSet er, ExtractionTarget et) throws BirthmarkExtractionFailedException, IOException, BirthmarkStoreException{
+    private synchronized BirthmarkSet[] extractImpl(String[] target, ExtractionResultSet er, ExtractionTarget et) throws BirthmarkExtractionFailedException, IOException, BirthmarkStoreException{
         ClassFileArchive[] archives = createArchives(target, environment);
         BirthmarkContext context = er.getContext();
         ExtractionUnit unit = context.getExtractionUnit();
@@ -319,7 +321,7 @@ public class BirthmarkEngine{
         return extractResult;
     }
 
-    private byte[] inputStreamToByteArray(InputStream in) throws IOException{
+    private synchronized byte[] inputStreamToByteArray(InputStream in) throws IOException{
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
         int read;
         byte[] dataBuffer = new byte[512];
@@ -332,7 +334,7 @@ public class BirthmarkEngine{
         return data;
     }
 
-    private void extractFromPackage(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException{
+    private synchronized void extractFromPackage(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException{
         Map<String, BirthmarkSet> map = new HashMap<String, BirthmarkSet>();
         BirthmarkContext context = er.getContext();
 
@@ -343,7 +345,7 @@ public class BirthmarkEngine{
                     String packageName = parsePackageName(name);
                     BirthmarkSet bs = map.get(packageName);
                     if(bs == null){
-                        bs = new BirthmarkSet(packageName, archive.getLocation());
+                        bs = new BirthmarkSet(packageName, archive.getLocation().toURI());
                         map.put(packageName, bs);
                     }
 
@@ -362,6 +364,8 @@ public class BirthmarkEngine{
                     }
                 } catch(IOException e){
                     warnings.addMessage(e, archive.getName());
+                } catch(URISyntaxException e){
+                    warnings.addMessage(e, archive.getLocation().toString());
                 }
             }
         }
@@ -373,7 +377,7 @@ public class BirthmarkEngine{
         }
     }
 
-    private String parsePackageName(String name){
+    private synchronized String parsePackageName(String name){
         String n = name.replace('/', '.');
         int index = n.lastIndexOf('.');
         if(index > 0){
@@ -383,14 +387,14 @@ public class BirthmarkEngine{
         return n;
     }
 
-    private void extractFromClass(ClassFileArchive[] archives, ExtractionResultSet er,
+    private synchronized void extractFromClass(ClassFileArchive[] archives, ExtractionResultSet er,
             ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
         BirthmarkContext context = er.getContext();
 
         for(ClassFileArchive archive: archives){
             for(ClassFileEntry entry: archive){
                 try{
-                    BirthmarkSet birthmarkset = new BirthmarkSet(entry.getClassName(), entry.getLocation());
+                    BirthmarkSet birthmarkset = new BirthmarkSet(entry.getClassName(), entry.getLocation().toURI());
                     byte[] data = inputStreamToByteArray(entry.getLocation().openStream());
 
                     for(String birthmarkType: context.getBirthmarkTypes()){
@@ -404,16 +408,26 @@ public class BirthmarkEngine{
                     er.addBirthmarkSet(et, birthmarkset);
                 } catch(IOException e){
                     warnings.addMessage(e, entry.getClassName());
+                } catch(URISyntaxException e){
+                    warnings.addMessage(e, entry.getLocation().toString());
                 }
             }
         }
     }
 
-    private void extractFromProduct(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
+    private synchronized void extractFromProduct(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
         BirthmarkContext context = er.getContext();
 
         for(ClassFileArchive archive: archives){
-            BirthmarkSet birthmarkset = new BirthmarkSet(archive.getName(), archive.getLocation());
+            BirthmarkSet birthmarkset = null;
+            try{
+                birthmarkset = new BirthmarkSet(archive.getName(), archive.getLocation().toURI());
+            } catch(URISyntaxException e){
+                warnings.addMessage(e, archive.getLocation().toString());
+            }
+            if(birthmarkset == null){
+                return;
+            }
 
             for(ClassFileEntry entry: archive){
                 try{
@@ -440,7 +454,7 @@ public class BirthmarkEngine{
         }
     }
 
-    private ClassFileArchive[] createArchives(String[] files, BirthmarkEnvironment environment) throws IOException, MalformedURLException{
+    private synchronized ClassFileArchive[] createArchives(String[] files, BirthmarkEnvironment environment) throws IOException, MalformedURLException{
         ClasspathContext bytecode = environment.getClasspathContext();
         List<ClassFileArchive> archives = new ArrayList<ClassFileArchive>();
         for(int i = 0; i < files.length; i++){
index b036094..9904e15 100644 (file)
@@ -1,6 +1,6 @@
 package jp.sourceforge.stigmata;
 
-import java.net.URL;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -19,7 +19,7 @@ public class BirthmarkSet implements Iterable<Birthmark>{
     /**
      * location of target is loaded from.
      */
-    private URL location;
+    private URI location;
 
     /**
      * map for birthmarks.
@@ -29,7 +29,7 @@ public class BirthmarkSet implements Iterable<Birthmark>{
     /**
      * constructor.
      */
-    public BirthmarkSet(String name, URL location){
+    public BirthmarkSet(String name, URI location){
         this.name = name;
         this.location = location;
     }
@@ -63,7 +63,7 @@ public class BirthmarkSet implements Iterable<Birthmark>{
     /**
      * return the location.
      */
-    public URL getLocation(){
+    public URI getLocation(){
         return location;
     }
 
index 8898218..0cefb42 100644 (file)
@@ -1,5 +1,6 @@
 package jp.sourceforge.stigmata;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import jp.sourceforge.stigmata.spi.BirthmarkService;
@@ -7,7 +8,9 @@ import jp.sourceforge.stigmata.spi.BirthmarkService;
 /**
  * @author Haruaki TAMADA
  */
-class BirthmarkSpiComparator implements Comparator<BirthmarkService>{
+class BirthmarkSpiComparator implements Comparator<BirthmarkService>, Serializable{
+    private static final long serialVersionUID = 8194452116506240274L;
+
     /**
      * default constructor
      */
index f8051d8..2872b95 100644 (file)
@@ -15,10 +15,10 @@ public class BirthmarkStoreTarget implements Serializable, Comparable<BirthmarkS
 
     private static final Map<String, BirthmarkStoreTarget> TARGETS = new HashMap<String, BirthmarkStoreTarget>();
 
-    public static BirthmarkStoreTarget MEMORY = new BirthmarkStoreTarget(0, "MEMORY");
-    public static BirthmarkStoreTarget XMLFILE = new BirthmarkStoreTarget(1, "XMLFILE");
-    public static BirthmarkStoreTarget MEMORY_SINGLE = new BirthmarkStoreTarget(2, "MEMORY_SINGLE");
-    public static BirthmarkStoreTarget RDB = new BirthmarkStoreTarget(3, "RDB");
+    public static final BirthmarkStoreTarget MEMORY = new BirthmarkStoreTarget(0, "MEMORY");
+    public static final BirthmarkStoreTarget XMLFILE = new BirthmarkStoreTarget(1, "XMLFILE");
+    public static final BirthmarkStoreTarget MEMORY_SINGLE = new BirthmarkStoreTarget(2, "MEMORY_SINGLE");
+    public static final BirthmarkStoreTarget RDB = new BirthmarkStoreTarget(3, "RDB");
 
     private final String name;
     private final int ordinal;
index e2447ff..eaf28e0 100644 (file)
@@ -3,9 +3,10 @@ package jp.sourceforge.stigmata;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -137,7 +138,16 @@ public class Stigmata{
                 BirthmarkEnvironment.resetSettings();
             }
         }
-        initConfiguration(target);
+        try{
+            initConfiguration(target);
+        } finally{
+            if(target != null){
+                try{
+                    target.close();
+                } catch(IOException e){
+                }
+            }
+        }
     }
 
     private void initConfiguration(InputStream in){
@@ -181,7 +191,14 @@ public class Stigmata{
             File file = new File(parent, fileName);
             if(!file.exists()){
                 ConfigFileExporter exporter = new ConfigFileExporter(defaultEnvironment);
-                exporter.export(new PrintWriter(new FileWriter(file)));
+                String encoding = defaultEnvironment.getProperty("encoding.config");
+                if(encoding == null){
+                    encoding = defaultEnvironment.getProperty("encoding");
+                }
+                if(encoding == null){
+                    encoding = "utf-8";
+                }
+                exporter.export(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)));
             }
         } catch(IOException e){
             e.printStackTrace();
index 15a00e7..a0e8329 100644 (file)
@@ -27,7 +27,10 @@ public class NullBirthmarkElement extends BirthmarkElement{
 
     @Override
     public boolean equals(Object o){
-        return o instanceof NullBirthmarkElement;
+        boolean flag = o != null && o.getClass().equals(getClass());
+        flag = flag && this == o;
+
+        return flag;
     }
 
     @Override
index 3655778..55584da 100644 (file)
@@ -81,17 +81,16 @@ public class CosineSimilarityBirthmarkComparator extends
         }
     }
 
-    private class CountPair{
+    private static final class CountPair{
         private int c1 = 0;
         private int c2 = 0;
 
         public int get(boolean first){
+            int value = c2;
             if(first){
-                return c1;
-            }
-            else{
-                return c2;
+                value = c1;
             }
+            return value;
         }
 
         public void set(boolean first, int count){
index b7b6155..bc7601a 100644 (file)
@@ -76,7 +76,7 @@ public class ConstantValueOfFieldVariableBirthmarkExtractVisitor extends Birthma
                 @Override
                 public void visitIntInsn(int opcode, int operand){
                     if(opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH){
-                        constant = new Integer(operand);
+                        constant = Integer.valueOf(operand);
                     }
                     super.visitIntInsn(opcode, operand);
                 }
@@ -92,20 +92,20 @@ public class ConstantValueOfFieldVariableBirthmarkExtractVisitor extends Birthma
 
                 @Override
                 public void visitInsn(int opcode){
-                    if(opcode == Opcodes.ICONST_M1)     constant = new Integer(-1);
-                    else if(opcode == Opcodes.ICONST_0) constant = new Integer(0);
-                    else if(opcode == Opcodes.ICONST_1) constant = new Integer(1);
-                    else if(opcode == Opcodes.ICONST_2) constant = new Integer(2);
-                    else if(opcode == Opcodes.ICONST_3) constant = new Integer(3);
-                    else if(opcode == Opcodes.ICONST_4) constant = new Integer(4);
-                    else if(opcode == Opcodes.ICONST_5) constant = new Integer(5);
-                    else if(opcode == Opcodes.LCONST_0) constant = new Long(0L);
-                    else if(opcode == Opcodes.LCONST_1) constant = new Long(1L);
-                    else if(opcode == Opcodes.DCONST_0) constant = new Double(0D);
-                    else if(opcode == Opcodes.DCONST_1) constant = new Double(1D);
-                    else if(opcode == Opcodes.FCONST_0) constant = new Float(0F);
-                    else if(opcode == Opcodes.FCONST_1) constant = new Float(1F);
-                    else if(opcode == Opcodes.FCONST_2) constant = new Float(2F);
+                    if(opcode == Opcodes.ICONST_M1)     constant = Integer.valueOf(-1);
+                    else if(opcode == Opcodes.ICONST_0) constant = Integer.valueOf(0);
+                    else if(opcode == Opcodes.ICONST_1) constant = Integer.valueOf(1);
+                    else if(opcode == Opcodes.ICONST_2) constant = Integer.valueOf(2);
+                    else if(opcode == Opcodes.ICONST_3) constant = Integer.valueOf(3);
+                    else if(opcode == Opcodes.ICONST_4) constant = Integer.valueOf(4);
+                    else if(opcode == Opcodes.ICONST_5) constant = Integer.valueOf(5);
+                    else if(opcode == Opcodes.LCONST_0) constant = Long.valueOf(0L);
+                    else if(opcode == Opcodes.LCONST_1) constant = Long.valueOf(1L);
+                    else if(opcode == Opcodes.DCONST_0) constant = Double.valueOf(0D);
+                    else if(opcode == Opcodes.DCONST_1) constant = Double.valueOf(1D);
+                    else if(opcode == Opcodes.FCONST_0) constant = Float.valueOf(0F);
+                    else if(opcode == Opcodes.FCONST_1) constant = Float.valueOf(1F);
+                    else if(opcode == Opcodes.FCONST_2) constant = Float.valueOf(2F);
 
                     super.visitInsn(opcode);
                 }
index f48cd40..42c4169 100644 (file)
@@ -51,13 +51,13 @@ public class ConstantValueOfFieldVariableBirthmarkExtractor extends ASMBirthmark
                 else                     elementValue = Boolean.FALSE;
                 break;
             }
-            case 'C': elementValue = new Character(subValue.charAt(0)); break;
-            case 'D': elementValue = new Double(subValue);  break;
-            case 'F': elementValue = new Float(subValue);   break;
-            case 'S': elementValue = new Short(subValue);   break;
-            case 'B': elementValue = new Byte(subValue);    break;
-            case 'I': elementValue = new Integer(subValue); break;
-            default:  elementValue = value; break;
+            case 'C': elementValue = subValue.charAt(0); break;
+            case 'D': elementValue = subValue;           break;
+            case 'F': elementValue = subValue;           break;
+            case 'S': elementValue = subValue;           break;
+            case 'B': elementValue = subValue;           break;
+            case 'I': elementValue = subValue;           break;
+            default:  elementValue = value;              break;
             }
        }
        return new TypeAndValueBirthmarkElement(signature, elementValue);
index c3c5117..c0df3d8 100644 (file)
@@ -35,13 +35,13 @@ public class TypeAndValueBirthmarkElement extends BirthmarkElement implements Se
         if(signature.length() == 1 && value == null){
             switch(signature.charAt(0)){
             case 'Z': value = Boolean.FALSE;  break;
-            case 'D': value = new Double(0d); break;
-            case 'F': value = new Float(0f);  break;
+            case 'D': value = Double.valueOf(0d); break;
+            case 'F': value = Float.valueOf(0f);  break;
             case 'C':
             case 'S':
             case 'B':
             case 'I':
-            default:  value = new Integer(0); break;
+            default:  value = Integer.valueOf(0); break;
             }
         }
 
@@ -67,19 +67,23 @@ public class TypeAndValueBirthmarkElement extends BirthmarkElement implements Se
 
     @Override
     public boolean equals(Object o){
-        if(o instanceof TypeAndValueBirthmarkElement){
-            TypeAndValueBirthmarkElement tvbe = (TypeAndValueBirthmarkElement)o;
+        boolean flag = false;
+        if(o != null){
+            String className = o.getClass().getName();
+            if(className.equals(TypeAndValueBirthmarkElement.class.getName())){
+                TypeAndValueBirthmarkElement tvbe = (TypeAndValueBirthmarkElement)o;
 
-            if(getSignature().equals(tvbe.getSignature())){
-                if(getValue() == null && tvbe.getValue() == null){
-                    return true;
-                }
-                else if(getValue() != null && tvbe.getValue() != null){
-                    return getValue().equals(tvbe.getValue());
+                if(getSignature().equals(tvbe.getSignature())){
+                    if(getValue() == null && tvbe.getValue() == null){
+                        flag = true;
+                    }
+                    else if(getValue() != null && tvbe.getValue() != null){
+                        flag = getValue().equals(tvbe.getValue());
+                    }
                 }
             }
         }
-        return false;
+        return flag;
     }
 
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
index 77dbda2..06cc0f5 100644 (file)
@@ -48,12 +48,15 @@ public class MethodCallBirthmarkElement extends BirthmarkElement implements Seri
     @Override
     public boolean equals(Object o){
         boolean flag = false;
-        if(o instanceof MethodCallBirthmarkElement){
-            MethodCallBirthmarkElement mcbe = (MethodCallBirthmarkElement)o;
+        if(o != null){
+            String className = o.getClass().getName();
+            if(className.equals(MethodCallBirthmarkElement.class.getName())){
+                MethodCallBirthmarkElement mcbe = (MethodCallBirthmarkElement)o;
 
-            flag = getClassName().equals(mcbe.getClassName()) &&
-                getMethodName().equals(mcbe.getMethodName())  &&
-                getSignature().equals(mcbe.getSignature());
+                flag = getClassName().equals(mcbe.getClassName()) &&
+                    getMethodName().equals(mcbe.getMethodName())  &&
+                    getSignature().equals(mcbe.getSignature());
+            }
         }
 
         return flag;
index e65e3fd..25c5a64 100644 (file)
@@ -3,6 +3,7 @@ package jp.sourceforge.stigmata.command;
 import java.util.ArrayList;
 import java.util.List;
 
+import jp.sourceforge.stigmata.BirthmarkContext;
 import jp.sourceforge.stigmata.BirthmarkEnvironment;
 import jp.sourceforge.stigmata.Stigmata;
 import jp.sourceforge.stigmata.StigmataCommand;
@@ -56,4 +57,31 @@ public abstract class AbstractStigmataCommand implements StigmataCommand{
     public void tearDown(BirthmarkEnvironment env){
         StigmataHookManager.getInstance().runHook(Phase.TEAR_DOWN, env);
     }
+
+    public String getProperty(BirthmarkEnvironment env, String[] keys, String defaultValue){
+        String value = null;
+        for(String key: keys){
+            if(value != null){
+                break;
+            }
+            value = env.getProperty(key);
+        }
+        if(value == null){
+            value = defaultValue;
+        }
+        return value;
+    }
+
+    public String getProperty(BirthmarkContext context, String[] keys, String defaultValue){
+        String value = null;
+        for(String key: keys){
+            if(value != null){
+                break;
+            }
+            value = (String)context.getProperty(key);
+        }
+        value = getProperty(context.getEnvironment(), keys, defaultValue);
+
+        return value;
+    }
 }
index 0b5c440..768b9a8 100644 (file)
@@ -1,6 +1,7 @@
 package jp.sourceforge.stigmata.command;
 
 import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
 import java.util.Iterator;
 
 import jp.sourceforge.stigmata.BirthmarkContext;
@@ -53,7 +54,8 @@ public class CompareCommand extends AbstractStigmataCommand{
 
             ResultPrinterService spi = stigmata.getPrinterManager().getService(context.getFormat());
             ComparisonResultSetPrinter formatter = spi.getComparisonResultSetPrinter();
-            formatter.printResult(new PrintWriter(System.out), resultset);
+            String encoding = getProperty(context, new String[] { "encoding.output", "encoding" }, "utf-8");
+            formatter.printResult(new PrintWriter(new OutputStreamWriter(System.out, encoding)), resultset);
         }catch(Exception e){
             e.printStackTrace();
         }
index f572ad7..06dc1fd 100644 (file)
@@ -1,8 +1,9 @@
 package jp.sourceforge.stigmata.command;
 
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
 
 import jp.sourceforge.stigmata.BirthmarkContext;
 import jp.sourceforge.stigmata.Stigmata;
@@ -23,14 +24,15 @@ public class ExportConfigCommand extends AbstractStigmataCommand{
     public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
         PrintWriter out = null;
         try{
+            String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
             if(args == null || args.length == 0){
-                out = new PrintWriter(System.out);
+                out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
             }
             else{
                 if(!args[0].endsWith(".xml")){
                     args[0] = args[0] + ".xml";
                 }
-                out = new PrintWriter(new FileWriter(args[0]));
+                out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(args[0]), encoding));
             }
 
             new ConfigFileExporter(context.getEnvironment()).export(out);
index 00dbcc2..dd1a77f 100644 (file)
@@ -1,6 +1,7 @@
 package jp.sourceforge.stigmata.command;
 
 import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
 import java.util.Iterator;
 
 import jp.sourceforge.stigmata.BirthmarkContext;
@@ -48,7 +49,8 @@ public class ExtractCommand extends AbstractStigmataCommand{
 
             ResultPrinterService spi = stigmata.getPrinterManager().getService(context.getFormat());
             ExtractionResultSetPrinter formatter = spi.getExtractionResultSetPrinter();
-            formatter.printResult(new PrintWriter(System.out), ers);
+            String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
+            formatter.printResult(new PrintWriter(new OutputStreamWriter(System.out, encoding)), ers);
         }catch(Exception ex){
             ex.printStackTrace();
         }
index 548d16b..59ae0bf 100644 (file)
@@ -107,10 +107,12 @@ public class InstallCommand extends AbstractStigmataCommand{
     private void copyFile(File source, File dest){
         byte[] data = new byte[256];
         int read;
+        InputStream in = null;
+        OutputStream out = null;
         
         try{
-            InputStream in = new FileInputStream(source);
-            OutputStream out = new FileOutputStream(dest);
+            in = new FileInputStream(source);
+            out = new FileOutputStream(dest);
 
             while((read = in.read(data)) != -1){
                 out.write(data, 0, read);
@@ -118,6 +120,30 @@ public class InstallCommand extends AbstractStigmataCommand{
             in.close();
             out.close();
         } catch(IOException e){
+        } finally{
+            String message = null;
+            if(in != null){
+                try{
+                    in.close();
+                } catch(IOException e){
+                    message = e.getMessage();
+                }
+            }
+            if(out != null){
+                try{
+                    out.close();
+                } catch(IOException e){
+                    if(message != null){
+                        message += ", " + e.getMessage();
+                    }
+                    else{
+                        message = e.getMessage();
+                    }
+                }
+            }
+            if(message != null){
+                throw new InternalError(message);
+            }
         }
     }
 }
index d819669..9c8d53b 100644 (file)
@@ -23,7 +23,7 @@ public class LicenseCommand extends AbstractStigmataCommand{
         BufferedReader reader = null;
         try{
             InputStream in = getClass().getResourceAsStream("/META-INF/license.txt");
-            reader = new BufferedReader(new InputStreamReader(in));
+            reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
             String line;
 
             while((line = reader.readLine()) != null){
@@ -38,6 +38,7 @@ public class LicenseCommand extends AbstractStigmataCommand{
                 try{
                     reader.close();
                 } catch(IOException e){
+                    throw new InternalError(e.getMessage());
                 }
             }
         }
index 7c45c1a..e3b4134 100644 (file)
@@ -1,7 +1,8 @@
 package jp.sourceforge.stigmata.command;
 
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
 import jp.sourceforge.stigmata.BirthmarkContext;
@@ -28,12 +29,13 @@ public class ListBirthmarksCommand extends AbstractStigmataCommand{
 
         try{
             PrintWriter out;
+            String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
             if(args.length == 0){
-                out = new PrintWriter(System.out);
+                out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
             }
             else{
                 String target = validateTarget(args[0], context.getFormat());
-                out = new PrintWriter(new FileWriter(target));
+                out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(target), encoding));
             }
             formatter.printResult(out, spis);
         }catch(IOException e){
index aa59451..2df78f3 100644 (file)
@@ -1,8 +1,9 @@
 package jp.sourceforge.stigmata.command;
 
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -40,16 +41,13 @@ public class UninstallCommand extends AbstractStigmataCommand{
 
         for(int i = 0; i < args.length; i++){
             BirthmarkService service = env.getService(args[i]);
-            if(service instanceof BirthmarkService){
-                env.removeService(args[i]);
-                removeServiceInConfigFile = true;
-            }
-            else{
-                String fileName = getPluginFileNameOfService(context, service);
-                if(fileName != null){
-                    File pluginFile = new File(pluginsDir, fileName);
-                    pluginFile.renameTo(new File(pluginFile.getParentFile(), pluginFile.getName() + ".back"));
-                }
+            env.removeService(args[i]);
+            removeServiceInConfigFile = true;
+
+            String fileName = getPluginFileNameOfService(context, service);
+            if(fileName != null){
+                File pluginFile = new File(pluginsDir, fileName);
+                pluginFile.renameTo(new File(pluginFile.getParentFile(), pluginFile.getName() + ".back"));
             }
         }
         if(removeServiceInConfigFile){
@@ -61,7 +59,10 @@ public class UninstallCommand extends AbstractStigmataCommand{
     private void updateConfigFile(BirthmarkEnvironment env){
         File configFile = new File(BirthmarkEnvironment.getStigmataHome(), "stigmata.xml");
         try{
-            new ConfigFileExporter(env).export(new PrintWriter(new FileWriter(configFile)));
+            String encoding = getProperty(env, new String[] { "encoding.output", "encoding", }, "utf-8");
+            new ConfigFileExporter(env).export(
+                new PrintWriter(new OutputStreamWriter(new FileOutputStream(configFile), encoding))
+            );
         } catch(IOException e){
             e.printStackTrace();
         }
index 69219b7..fe9d846 100644 (file)
@@ -1,5 +1,6 @@
 package jp.sourceforge.stigmata.event;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -8,7 +9,9 @@ import java.util.Map;
  * 
  * @author Haruaki Tamada
  */
-public class WarningMessages{
+public class WarningMessages implements Serializable{
+    private static final long serialVersionUID = -2305021456005540192L;
+
     private OperationType type;
     private Map<Exception, String> messages = new HashMap<Exception, String>();
 
index ab6b045..42bbb87 100644 (file)
@@ -1,5 +1,7 @@
 package jp.sourceforge.stigmata.filter;
 
+import java.util.Arrays;
+
 import jp.sourceforge.stigmata.ComparisonPairFilter;
 import jp.sourceforge.stigmata.spi.ComparisonPairFilterService;
 
@@ -28,8 +30,10 @@ public abstract class AbstractComparisonPairFilter implements ComparisonPairFilt
     @Override
     public void setCriterion(Criterion criterion){
         if(!isAcceptable(criterion)){
-            throw new IllegalArgumentException("illegal criterion: "
-                    + criterion + ": accepts only " + getAcceptableCriteria());
+            throw new IllegalArgumentException(
+                "illegal criterion: " + criterion +
+                ": accepts only " + Arrays.toString(getAcceptableCriteria())
+            );
         }
         this.criterion = criterion;
     }
index c7a22f2..fdf7509 100644 (file)
@@ -156,8 +156,9 @@ public class BirthmarkElementCountComparisonPairFilter extends AbstractCompariso
         switch(getTarget()){
         case TARGET_1:       sb.append("target1"); break;
         case TARGET_2:       sb.append("target2"); break;
-        case BOTH_TARGETS:   sb.append("(target1&target2)");    break;
-        case ONE_OF_TARGETS: sb.append("(target1|target2)");
+        case BOTH_TARGETS:   sb.append("(target1&target2)"); break;
+        case ONE_OF_TARGETS: sb.append("(target1|target2)"); break;
+        default:
         }
         sb.append(".").append(birthmarkType);
         sb.append(".size");
@@ -168,6 +169,7 @@ public class BirthmarkElementCountComparisonPairFilter extends AbstractCompariso
         case LESS_THAN:      sb.append(" <  "); break;
         case EQUALS_AS:      sb.append(" == "); break;
         case NOT_EQUALS_AS:  sb.append(" != "); break;
+        default:
         }
         sb.append(Integer.toString(getThreshold()));
 
index 5729992..cf3d791 100644 (file)
@@ -91,6 +91,7 @@ public class SimilarityComparisonPairFilter extends AbstractComparisonPairFilter
         case LESS_THAN:      sb.append(" <  "); break;
         case EQUALS_AS:      sb.append(" == "); break;
         case NOT_EQUALS_AS:  sb.append(" != "); break;
+        default:
         }
         sb.append(getThreshold());
         return new String(sb);
index 293c738..e5a8958 100644 (file)
@@ -150,7 +150,8 @@ public class TargetNameComparisonPairFilter extends AbstractComparisonPairFilter
         case TARGET_1:       sb.append("target1.name");           break;
         case TARGET_2:       sb.append("target2.name");           break;
         case BOTH_TARGETS:   sb.append("(target1&target2).name"); break;
-        case ONE_OF_TARGETS: sb.append("(target1|target2).name"); break; 
+        case ONE_OF_TARGETS: sb.append("(target1|target2).name"); break;
+        default:
         }
         switch(getCriterion()){
         case STARTS_WITH:     sb.append(" starts with ");     break;
@@ -159,6 +160,7 @@ public class TargetNameComparisonPairFilter extends AbstractComparisonPairFilter
         case NOT_ENDS_WITH:   sb.append(" not ends with ");   break;
         case EQUALS_AS:       sb.append(" equals as ");       break;
         case NOT_EQUALS_AS:   sb.append(" not equals as ");   break;
+        default:
         }
         sb.append(getValue());
 
index a62a3d5..844b3f2 100644 (file)
@@ -147,6 +147,7 @@ public class TotalElementCountComparisonPairFilter extends AbstractComparisonPai
         case TARGET_2:       sb.append("target2"); break;
         case BOTH_TARGETS:   sb.append("(target1&target2)"); break;
         case ONE_OF_TARGETS: sb.append("(target1|target2)"); break;
+        default:
         }
         sb.append(".element");
         switch(getCriterion()){
@@ -156,6 +157,7 @@ public class TotalElementCountComparisonPairFilter extends AbstractComparisonPai
         case LESS_THAN:      sb.append(" <  "); break;
         case EQUALS_AS:      sb.append(" == "); break;
         case NOT_EQUALS_AS:  sb.append(" != "); break;
+        default:
         }
         sb.append(Integer.toString(getThreshold()));
 
index 2329201..28b56f7 100644 (file)
@@ -1,6 +1,6 @@
 package jp.sourceforge.stigmata.result;
 
-import java.net.URL;
+import java.net.URI;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -116,7 +116,7 @@ public class CertainPairComparisonResultSet extends AbstractComparisonResultSet{
     }
 
     private Collection<BirthmarkSet> createSources(){
-        Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+        Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
         for(Iterator<ComparisonPair> i = iterator(); i.hasNext(); ){
             ComparisonPair pair = i.next();
             addToMap(map, pair.getTarget1());
@@ -125,7 +125,7 @@ public class CertainPairComparisonResultSet extends AbstractComparisonResultSet{
         return map.values();
     }
 
-    private void addToMap(Map<URL, BirthmarkSet> map, BirthmarkSet set){
+    private void addToMap(Map<URI, BirthmarkSet> map, BirthmarkSet set){
         map.put(set.getLocation(), set);
     }
 
index c5dc9c0..6e27e06 100644 (file)
@@ -1,7 +1,7 @@
 package jp.sourceforge.stigmata.result;
 
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -200,18 +200,18 @@ public class RDBExtractionResultSet extends AbstractExtractionResultSet{
 
         @Override
         public Object handle(ResultSet rs) throws SQLException{
-            Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+            Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
 
             while(rs.next()){
                 try{
                     String name = rs.getString("NAME");
                     String location = rs.getString("LOCATION");
 
-                    URL url = new URL(location);
-                    BirthmarkSet bs = map.get(url);
+                    URI uri = new URI(location);
+                    BirthmarkSet bs = map.get(uri);
                     if(bs == null){
-                        bs = new BirthmarkSet(name, url);
-                        map.put(url, bs);
+                        bs = new BirthmarkSet(name, uri);
+                        map.put(uri, bs);
                     }
                     String type = rs.getString("TYPE");
 
@@ -222,8 +222,7 @@ public class RDBExtractionResultSet extends AbstractExtractionResultSet{
                     }
                     String element = rs.getString("ELEMENT");
                     birthmark.addElement(env.getService(type).getExtractor().buildElement(element));
-
-                } catch(MalformedURLException e){
+                } catch(URISyntaxException e){
                 }
             }
             return map.values().toArray(new BirthmarkSet[map.size()]);
index 2b21985..11ed14c 100644 (file)
@@ -1,6 +1,6 @@
 package jp.sourceforge.stigmata.result;
 
-import java.net.URL;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -120,7 +120,7 @@ public class RoundRobinComparisonResultSet extends AbstractComparisonResultSet{
 
     @Override
     public Iterator<BirthmarkSet> pairSources(){
-        Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+        Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
         if(extraction.isTableType()){
             for(Iterator<BirthmarkSet> i = extraction.birthmarkSets(ExtractionTarget.TARGET_X); i.hasNext(); ){
                 BirthmarkSet bs = i.next();
index 35d7f32..c5b775e 100644 (file)
@@ -2,13 +2,16 @@ package jp.sourceforge.stigmata.result;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -216,16 +219,18 @@ public class XmlFileExtractionResultSet extends AbstractExtractionResultSet{
     private static class BirthmarkSetStAXIterator implements Iterator<BirthmarkSet>{
         private XMLEventReader reader = null;
         private BirthmarkSet nextObject;
-        private List<URL> validItems;
+        private List<URI> validItems;
         private BirthmarkEnvironment env;
         private BirthmarkContext context;
 
-        public BirthmarkSetStAXIterator(File file, List<URL> validItems, BirthmarkContext context){
+        public BirthmarkSetStAXIterator(File file, List<URI> validItems, BirthmarkContext context){
             try{
                 XMLInputFactory factory = XMLInputFactory.newInstance();
-                BufferedReader in = new BufferedReader(new FileReader(file));
+
+                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
                 reader = factory.createXMLEventReader(in);
             } catch(FileNotFoundException e){
+            } catch(UnsupportedEncodingException e){
             } catch(XMLStreamException e){
             }
             this.validItems = validItems;
@@ -307,9 +312,9 @@ public class XmlFileExtractionResultSet extends AbstractExtractionResultSet{
                             throw new XMLStreamException("incompatible with definition");
                         }
                         try{
-                            URL url = new URL(location);
-                            bs = new BirthmarkSet(className, url);
-                        } catch(MalformedURLException e){
+                            URI uri = new URI(location);
+                            bs = new BirthmarkSet(className, uri);
+                        } catch(URISyntaxException e){
                             e.printStackTrace();
                         }
                     }
@@ -352,7 +357,7 @@ public class XmlFileExtractionResultSet extends AbstractExtractionResultSet{
     private static class XmlFile{
         private ExtractionResultSetXmlPrinter formatter;
         private BirthmarkContext context;
-        private List<URL> addList = new ArrayList<URL>();
+        private List<URI> addList = new ArrayList<URI>();
         private int size;
         private File file;
         private PrintWriter out;
@@ -373,7 +378,7 @@ public class XmlFileExtractionResultSet extends AbstractExtractionResultSet{
         public void addBirthmarkSet(BirthmarkSet bs) throws BirthmarkStoreException{
             if(formatter == null){
                 try{
-                    out = new PrintWriter(new FileWriter(file));
+                    out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
                     formatter = new ExtractionResultSetXmlPrinter();
                     formatter.printHeader(out);
                     out.printf("    <unit>%s</unit>%n", context.getExtractionUnit());
index 694f1da..7962903 100644 (file)
@@ -2,8 +2,9 @@ package jp.sourceforge.stigmata.result.history;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -110,13 +111,22 @@ public class ExtractedBirthmarkServiceManager{
     private void addValuesFromSystemFile(Set<String> values){
         File file = new File(BirthmarkEnvironment.getStigmataHome(), "storelocations.txt");
         if(file.exists()){
+            BufferedReader in = null;
             try{
-                BufferedReader in = new BufferedReader(new FileReader(file));
+                in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
                 String line;
                 while((line = in.readLine()) != null){
                     values.add(line);
                 }
             } catch(IOException e){
+            } finally{
+                try{
+                    if(in != null){
+                        in.close();
+                    }
+                } catch(IOException e){
+                    throw new InternalError(e.getMessage());
+                }
             }
         }
     }
index 746e283..4dea497 100644 (file)
@@ -18,9 +18,9 @@ import jp.sourceforge.talisman.i18n.Messages;
  * @author Haruaki TAMADA
  */
 public abstract class BirthmarkSelectablePane extends JPanel implements BirthmarkServiceListener{
-       private static final long serialVersionUID = 7057130952947891635L;
+    private static final long serialVersionUID = 7057130952947891635L;
 
-       private StigmataFrame stigmata;
+    private StigmataFrame stigmata;
     private Set<String> selectedServices = new HashSet<String>();
     private Map<String, BirthmarkSelection> services;
     private List<DataChangeListener> listeners = new ArrayList<DataChangeListener>();
@@ -115,10 +115,10 @@ public abstract class BirthmarkSelectablePane extends JPanel implements Birthmar
 
     @Override
     public void serviceRemoved(BirthmarkService service){
-        BirthmarkSelection elem = services.get(service);
+        BirthmarkSelection elem = services.get(service.getType());
         if(elem != null){
-            selectedServices.remove(service);
-            services.remove(service);
+            selectedServices.remove(service.getType());
+            services.remove(service.getType());
         }
         fireEvent();
     }
index e85684c..92fb173 100644 (file)
@@ -1,8 +1,9 @@
 package jp.sourceforge.stigmata.ui.swing;
 
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;
@@ -20,7 +21,7 @@ public class ClassNameObfuscator{
     public void outputNameMappings(File file) throws IOException{
         PrintWriter out = null;
         try{
-            out = new PrintWriter(new FileWriter(file));
+            out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
             for(String oldName: nameMapping.keySet()){
                 String newName = nameMapping.get(oldName);
                 out.print(oldName);
@@ -38,7 +39,7 @@ public class ClassNameObfuscator{
     public BirthmarkSet obfuscateClassName(BirthmarkSet orig){
         String newName = nameMapping.get(orig.getName());
         if(newName == null){
-            newName = String.format("C%04d", new Object[] { new Integer(nameMapping.size() + 1), });
+            newName = String.format("C%04d", new Object[] { nameMapping.size() + 1, });
             nameMapping.put(orig.getName(), newName);
         }
 
index 3c10897..1caa045 100644 (file)
@@ -47,7 +47,7 @@ public class ClippedLRListCellRenderer extends JPanel implements ListCellRendere
             right.setText(String.valueOf(item.getRight()));
         }
 
-        if(item.getIcon() != null){
+        if(item != null && item.getIcon() != null){
             left.setIcon(item.getIcon());
         }
 
index 19fc8a3..181fbd3 100644 (file)
@@ -6,8 +6,9 @@ import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;
@@ -119,7 +120,7 @@ public class ControlPane extends JPanel{
         BirthmarkEnvironment environment = generateEnvironment();
         ConfigFileExporter bce = new ConfigFileExporter(environment);
         try{
-            PrintWriter out = new PrintWriter(new FileWriter(file));
+            PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
             bce.export(out);
             out.close();
         } catch(IOException e){
index cb530c4..cfb8fa5 100644 (file)
@@ -10,7 +10,7 @@ import java.awt.event.MouseEvent;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.net.URL;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -204,7 +204,7 @@ public class RoundRobinComparisonResultPane extends JPanel{
     }
 
     private void mdsButtonActionPerformed(ActionEvent e){
-        Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+        Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
         for(Iterator<BirthmarkSet> i = extraction.birthmarkSets(ExtractionTarget.TARGET_X); i.hasNext(); ){
             BirthmarkSet bs = i.next();
             map.put(bs.getLocation(), bs);
@@ -215,7 +215,7 @@ public class RoundRobinComparisonResultPane extends JPanel{
         }
         int index = 0;
         BirthmarkSet[] set = new BirthmarkSet[map.size()];
-        for(Map.Entry<URL, BirthmarkSet> entry: map.entrySet()){
+        for(Map.Entry<URI, BirthmarkSet> entry: map.entrySet()){
             set[index] = entry.getValue();
             index++;
         }
@@ -229,12 +229,12 @@ public class RoundRobinComparisonResultPane extends JPanel{
             for(int j = 1; j < table.getColumnCount(); j++){
                 Double d = (Double)table.getValueAt(i, j);
                 int similarity = (int)Math.round(d.doubleValue() * 100);
-                Integer dist = values.get(new Integer(similarity));
+                Integer dist = values.get(similarity);
                 if(dist == null){
-                    dist = new Integer(0);
+                    dist = 0;
                 }
-                dist = new Integer(dist.intValue() + 1);
-                values.put(new Integer(similarity), dist);
+                dist = dist.intValue() + 1;
+                values.put(similarity, dist);
             }
         }
         stigmata.showSimilarityDistributionGraph(values);
index 33acbd8..0df88a9 100644 (file)
@@ -8,14 +8,13 @@ import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 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;
@@ -191,7 +190,7 @@ public class StigmataFrame extends JFrame{
         int compareDetail = getNextCount("compare_detail");
 
         GUIUtility.addNewTab(getMessages(), "comparedetail", tabPane, detail,
-            new Object[] { new Integer(compareDetail), },
+            new Object[] { Integer.valueOf(compareDetail), },
             new Object[] {
                 Utility.array2String(target1.getBirthmarkTypes()),
                 target1.getName(),
@@ -210,7 +209,7 @@ public class StigmataFrame extends JFrame{
             int compareCount = getNextCount("compare");
             GUIUtility.addNewTab(
                 getMessages(), "compare", tabPane, compare,
-                new Object[] { new Integer(compareCount), },
+                new Object[] { Integer.valueOf(compareCount), },
                 new Object[] {
                     Utility.array2String(context.getBirthmarkTypes()),
                     Utility.array2String(targetX),
@@ -235,7 +234,7 @@ public class StigmataFrame extends JFrame{
             int compareCount = getNextCount("compare");
             GUIUtility.addNewTab(
                 getMessages(), "compare", tabPane, new PairComparisonResultSetPane(this, resultset),
-                new Object[] { new Integer(compareCount), },
+                new Object[] { Integer.valueOf(compareCount), },
                 new Object[] {
                     Utility.array2String(context.getBirthmarkTypes()),
                     Utility.array2String(targetX),
@@ -257,7 +256,7 @@ public class StigmataFrame extends JFrame{
             GUIUtility.addNewTab(
                 getMessages(), "comparepair", tabPane,
                 new PairComparisonResultSetPane(this, resultset),
-                new Object[] { new Integer(comparePair), },
+                new Object[] { Integer.valueOf(comparePair), },
                 new Object[] {
                     Utility.array2String(context.getBirthmarkTypes()),
                     Utility.array2String(targetX),
@@ -288,7 +287,7 @@ public class StigmataFrame extends JFrame{
                 GUIUtility.addNewTab(
                     getMessages(), "comparepair", tabPane,
                     new PairComparisonResultSetPane(this, crs),
-                    new Object[] { new Integer(comparePair), },
+                    new Object[] { Integer.valueOf(comparePair), },
                     new Object[] {
                         Utility.array2String(context.getBirthmarkTypes()),
                         Utility.array2String(targetX),
@@ -306,7 +305,7 @@ public class StigmataFrame extends JFrame{
         GUIUtility.addNewTab(
             getMessages(), "comparisonresultset", tabPane,
             new PairComparisonResultSetPane(this, resultset),
-            new Object[] { new Integer(comparePair), }, null, true
+            new Object[] { Integer.valueOf(comparePair), }, null, true
         );
     }
 
@@ -316,7 +315,7 @@ public class StigmataFrame extends JFrame{
             int mappingGraphCount = getNextCount("mds_graph");
             GUIUtility.addNewTab(
                 getMessages(), "mappinggraph", tabPane, panel,
-                new Object[] { new Integer(mappingGraphCount), }, null, true
+                new Object[] { Integer.valueOf(mappingGraphCount), }, null, true
             );
         } catch(Exception e){
             showExceptionMessage(e);
@@ -329,7 +328,7 @@ public class StigmataFrame extends JFrame{
         int similarityGraphCount = getNextCount("similarity_graph");
         GUIUtility.addNewTab(
             getMessages(), "similaritygraph", tabPane, graph,
-            new Object[] { new Integer(similarityGraphCount), }, null, true
+            new Object[] { Integer.valueOf(similarityGraphCount), }, null, true
         );
     }
 
@@ -338,7 +337,7 @@ public class StigmataFrame extends JFrame{
         int compareCount = getNextCount("compare");
         GUIUtility.addNewTab(
             getMessages(), "compare", tabPane, compare,
-            new Object[] { new Integer(compareCount), },
+            new Object[] { Integer.valueOf(compareCount), },
             new Object[] {
                 Utility.array2String(ers.getBirthmarkTypes()),
                 Utility.array2String(new String[0]),
@@ -352,7 +351,7 @@ public class StigmataFrame extends JFrame{
         BirthmarkExtractionResultPane viewer = new BirthmarkExtractionResultPane(this, ers);
         GUIUtility.addNewTab(
             getMessages(), "extract", tabPane, viewer,
-            new Object[] { new Integer(extractCount), },
+            new Object[] { Integer.valueOf(extractCount), },
             new Object[] { Utility.array2String(ers.getBirthmarkTypes()), }, true
         );
     }
@@ -374,7 +373,7 @@ public class StigmataFrame extends JFrame{
         Map<String, String> mapping = new HashMap<String, String>();
         BufferedReader in = null;
         try{
-            in = new BufferedReader(new FileReader(file));
+            in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
             String line;
             while((line = in.readLine()) != null){
                 String[] tokens = line.split(", *");
@@ -791,7 +790,7 @@ public class StigmataFrame extends JFrame{
     private int getNextCount(String label){
         Integer i = countmap.get(label);
         if(i == null){
-            i = new Integer(0);
+            i = 0;
         }
         i = i + 1;
         countmap.put(label, i);
index 62a79ce..99b17e6 100644 (file)
@@ -121,9 +121,11 @@ public class TargetSelectionPane extends JPanel{
                     exts[i], MessageFormat.format(getSelectDescription(), exts[i])
                 );
             }
-            ;
         }
-        return filters;
+        FileFilter[] newFilters = new FileFilter[filters.length];
+        System.arraycopy(filters, 0, newFilters, 0, filters.length);
+
+        return newFilters;
     }
 
     public String getSelectDescription(){
@@ -181,7 +183,8 @@ public class TargetSelectionPane extends JPanel{
     }
 
     public void setFileFilters(FileFilter[] filters){
-        this.filters = filters;
+        this.filters = new FileFilter[filters.length];
+        System.arraycopy(filters, 0, this.filters, 0, filters.length);
     }
 
     public void setMultipleSelectable(boolean flag){
@@ -394,7 +397,7 @@ public class TargetSelectionPane extends JPanel{
         }
     };
 
-    private class TargetTransferable implements Transferable{
+    private static class TargetTransferable implements Transferable{
         private String[] strings;
 
         public TargetTransferable(String[] strings){
index 10bb109..20ad72e 100644 (file)
@@ -297,7 +297,7 @@ public class UpdatePluginsPane extends JPanel{
             StringWriter out = new StringWriter();
             PrintWriter writer = new PrintWriter(out);
 
-            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
+            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
             String line;
             while((line = in.readLine()) != null){
                 writer.println(line);
index 2753a4f..8edd2a4 100644 (file)
@@ -4,9 +4,9 @@ import java.awt.event.ActionEvent;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
 import javax.swing.AbstractAction;
@@ -41,7 +41,8 @@ public class SaveAction extends AbstractAction{
     }
 
     public void setExtensions(String[] extensions){
-        this.extensions = extensions;
+        this.extensions = new String[extensions.length];
+        System.arraycopy(extensions, 0, this.extensions, 0, extensions.length);
     }
 
     public void setDescrpition(String description){
@@ -63,7 +64,7 @@ public class SaveAction extends AbstractAction{
             PrintWriter writer = null;
             try{
                 if(asciiWritable != null){
-                    writer = new PrintWriter(new FileWriter(file));
+                    writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
                     asciiWritable.writeAsciiData(writer, format);
                 }
                 else{
index 0a31118..55662b3 100644 (file)
@@ -79,11 +79,11 @@ public class SimilarityDistributionGraphPane extends JPanel{
         double w = (d.width / 100d);
 
         Integer v1 = distributions.get(0);
-        if(v1 == null) v1 = new Integer(0);
+        if(v1 == null) v1 = 0;
         double x = 20;
         for(int i = 0; i <= 100; i++){
             Integer v2 = distributions.get(i);
-            if(v2 == null) new Integer(0);
+            if(v2 == null) v2 = 0;
 
             double hh1 = v1 * ((double)height / totalCount);
             double hh2 = v2 * ((double)height / totalCount);
@@ -124,10 +124,10 @@ public class SimilarityDistributionGraphPane extends JPanel{
     private void initializeData(){
         maxFrequency = 0;
         for(int i = 0; i <= 100; i++){
-            Integer frequency = distributions.get(new Integer(i));
+            Integer frequency = distributions.get(i);
             if(frequency == null){
-                frequency = new Integer(0);
-                distributions.put(new Integer(i), frequency);
+                frequency = 0;
+                distributions.put(i, frequency);
             }
             if(maxFrequency < frequency.intValue()){
                 maxFrequency = frequency.intValue();
index 283123c..00f8ed8 100644 (file)
@@ -68,11 +68,11 @@ class LabelMap{
     }
 
     public int getGroupId(String groupLabel){
-        Integer i = new Integer(0);
+        Integer i = 0;
         if(isGroupEnabled()){
             i = gids.get(groupLabel);
             if(i == null){
-                i = new Integer(0);
+                i = 0;
             }
         }
         return i;
@@ -99,7 +99,7 @@ class LabelMap{
         for(Map.Entry<String, String> entry: groups.entrySet()){
             Integer i = map.get(entry.getValue());
             if(i == null){
-                i = new Integer(0);
+                i = 0;
             }
             map.put(entry.getValue(), i + 1);
         }
index a89f02a..99a3022 100644 (file)
@@ -8,7 +8,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
-import java.net.URL;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -73,10 +73,11 @@ public class MdsViewerPane extends JPanel implements ZoomEnabler, MessageManager
     private ZoomInAction zoomin;
     private ZoomOutAction zoomout;
 
-    public MdsViewerPane(StigmataFrame stigmata, BirthmarkSet[] set, BirthmarkContext context){
+    public MdsViewerPane(StigmataFrame stigmata, BirthmarkSet[] bset, BirthmarkContext context){
         this.stigmata = stigmata;
         this.context = context;
-        this.set = set;
+        this.set = new BirthmarkSet[bset.length];
+        System.arraycopy(bset, 0, set, 0, bset.length);
 
         try{
             initLayouts();
@@ -140,7 +141,7 @@ public class MdsViewerPane extends JPanel implements ZoomEnabler, MessageManager
         return table;
     }
 
-    private String getGroupName(URL location){
+    private String getGroupName(URI location){
         String url = location.toString();
         if(url.startsWith("jar:")){
             url = url.substring("jar:".length(), url.lastIndexOf('!'));
index a29722b..a2bb3af 100644 (file)
@@ -3,6 +3,7 @@ package jp.sourceforge.stigmata.ui.swing.tab;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.FocusTraversalPolicy;
+import java.io.Serializable;
 
 import javax.swing.JTextField;
 
@@ -13,7 +14,9 @@ import javax.swing.JTextField;
  * @author Haruaki Tamada
  * @author Terai Atsuhiro
  */
-class EditableTabbedPaneFocusTraversalPolicy extends FocusTraversalPolicy{
+class EditableTabbedPaneFocusTraversalPolicy extends FocusTraversalPolicy implements Serializable{
+    private static final long serialVersionUID = 7521938828453530777L;
+
     private JTextField editor;
 
     public EditableTabbedPaneFocusTraversalPolicy(JTextField editor){
index a0b1099..d64c40f 100644 (file)
@@ -1,6 +1,8 @@
 package jp.sourceforge.stigmata.utils;
 
+import java.util.Arrays;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 /**
  * 
@@ -12,8 +14,8 @@ public class ArrayIterator<T> implements Iterator<T>{
     private int currentIndex = 0;
 
     public ArrayIterator(T[] values){
-        this.values = values;
         if(values != null){
+            this.values = Arrays.copyOf(values, values.length);
             length = values.length;
         }
         else{
@@ -28,6 +30,9 @@ public class ArrayIterator<T> implements Iterator<T>{
 
     @Override
     public T next(){
+        if(currentIndex < 0 || currentIndex >= values.length){
+            throw new NoSuchElementException();
+        }
         T value = values[currentIndex];
         currentIndex++;
         return value;
index 1f7fab1..1a97ab6 100644 (file)
@@ -161,7 +161,7 @@ public class ConfigFileExporter{
     private void exportServices(PrintWriter out) throws IOException{
         out.println("  <birthmark-services>");
         for(BirthmarkService service: environment.getServices()){
-            if(service.isExperimental() && service instanceof BirthmarkService){
+            if(service.isExperimental()){
                 out.println("    <birthmark-service>");
                 out.printf("      <type>%s</type>%n", service.getType());
                 if(service instanceof ReflectedBirthmarkService){
index 5491805..f00f344 100644 (file)
@@ -37,17 +37,20 @@ public class HermesUtility{
     public void updateContext(BirthmarkEnvironment env) throws IOException{
         String path = env.getProperty("location.hermes.config");
         OutputStream out = null;
-        if(path != null && path.startsWith("file:")){
-            out = new URL(path).openConnection().getOutputStream();
-        }
-        else{
-            File file = new File(BirthmarkEnvironment.getStigmataHome(), "plugins/hermes.xml");
-            out = new FileOutputStream(file);
-        }
-        HermesContextExporter exporter = new HermesContextExporter();
-        exporter.export(out, context);
-        if(out != null){
-            out.close();
+        try{
+            if(path != null && path.startsWith("file:")){
+                out = new URL(path).openConnection().getOutputStream();
+            }
+            else{
+                File file = new File(BirthmarkEnvironment.getStigmataHome(), "plugins/hermes.xml");
+                out = new FileOutputStream(file);
+            }
+            HermesContextExporter exporter = new HermesContextExporter();
+            exporter.export(out, context);
+        } finally{
+            if(out != null){
+                out.close();
+            }
         }
     }
 
@@ -83,7 +86,9 @@ public class HermesUtility{
         if(updateTargets == null){
             updateTargets = hermes.getUpdateTarget();
         }
-        return updateTargets;
+        Artifact[] artifacts = new Artifact[updateTargets.length];
+        System.arraycopy(updateTargets, 0, artifacts, 0, artifacts.length);
+        return artifacts;
     }
 
     public void update() throws IOException, HermesException{
@@ -132,10 +137,16 @@ public class HermesUtility{
             }
         } finally{
             if(in != null){
-                in.close();
+                try{
+                    in.close();
+                } catch(IOException e){
+                }
             }
             if(out != null){
-                out.close();
+                try{
+                    out.close();
+                } catch(IOException e){
+                }
             }
         }
     }
index df05013..9fc2505 100644 (file)
@@ -2,7 +2,6 @@ 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;
@@ -64,11 +63,11 @@ public class Utility{
         if(pluginFile == null){
             flag = false;
         }
-        if(!pluginFile.getName().endsWith(".jar")){
+        if(flag && !pluginFile.getName().endsWith(".jar")){
             messages.add("install.error.notjarfile");
             flag = false;
         }
-        if(!pluginFile.exists()){
+        if(flag && !pluginFile.exists()){
             messages.add("install.error.file.missing");
             flag = false;
         }