OSDN Git Service

add preprocessor of birthmarking
authortama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Tue, 9 Dec 2008 07:46:10 +0000 (07:46 +0000)
committertama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Tue, 9 Dec 2008 07:46:10 +0000 (07:46 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/stigmata/trunk@345 acee48c3-7b26-0410-bdac-b3d0e5314bbc

pom.xml
src/main/java/jp/sourceforge/stigmata/BirthmarkEngine.java
src/main/java/jp/sourceforge/stigmata/BirthmarkExtractor.java
src/main/java/jp/sourceforge/stigmata/BirthmarkPreprocessor.java [new file with mode: 0644]
src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmark.java
src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmarkExtractor.java
src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmarkPreprocessor.java [new file with mode: 0644]
src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmarkService.java
src/main/java/jp/sourceforge/stigmata/hook/Phase.java
src/main/java/jp/sourceforge/stigmata/spi/BirthmarkSpi.java
src/main/java/jp/sourceforge/stigmata/ui/swing/mds/OpenItemsAction.java

diff --git a/pom.xml b/pom.xml
index 73e5e8d..b4e35e5 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
@@ -61,7 +61,7 @@
     <dependency>
       <groupId>jp.sourceforge.talisman</groupId>
       <artifactId>mds</artifactId>
-      <version>1.0.1-SNAPSHOT</version>
+      <version>1.0.0</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
     <dependency>
       <groupId>jp.sourceforge.talisman</groupId>
       <artifactId>i18n</artifactId>
-      <version>1.0.1-SNAPSHOT</version>
+      <version>1.0.1</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>jp.sourceforge.stigmata</groupId>
       <artifactId>digger</artifactId>
-      <version>1.0.0-SNAPSHOT</version>
+      <version>1.0.0</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
index a3301e2..5ee7305 100755 (executable)
@@ -12,8 +12,10 @@ import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.Stack;
 
 import jp.sourceforge.stigmata.birthmarks.extractors.BirthmarkExtractorFactory;
@@ -34,6 +36,7 @@ import jp.sourceforge.stigmata.hook.Phase;
 import jp.sourceforge.stigmata.hook.StigmataHookManager;
 import jp.sourceforge.stigmata.result.CertainPairComparisonResultSet;
 import jp.sourceforge.stigmata.result.RoundRobinComparisonResultSet;
+import jp.sourceforge.stigmata.spi.BirthmarkSpi;
 
 /**
  * core engine for extracting/comparing/filtering birthmarks.
@@ -233,6 +236,8 @@ public class BirthmarkEngine{
         ExtractionResultSet er = context.getEnvironment().getHistoryManager().createDefaultResultSet(context);
 
         try{
+            prepare(targetX, targetY, context);
+
             StigmataHookManager.getInstance().runHook(Phase.BEFORE_EXTRACTION, context);
 
             switch(context.getComparisonMethod()){
@@ -263,6 +268,30 @@ public class BirthmarkEngine{
         }
     }
 
+    public BirthmarkContext prepare(String[] targetX, String[] targetY, BirthmarkContext context) throws MalformedURLException, IOException{
+        StigmataHookManager.getInstance().runHook(Phase.BEFORE_PREPROCESS, context);
+
+        Set<String> set = new HashSet<String>();
+        if(targetX != null){
+            for(String t: targetX) set.add(t);
+        }
+        if(targetY != null){
+            for(String t: targetY) set.add(t);
+        }
+        String[] target = set.toArray(new String[set.size()]);
+        ClassFileArchive[] archives = createArchives(target, environment);
+        for(String type: context.getBirthmarkTypes()){
+            BirthmarkSpi service = context.getEnvironment().getService(type);
+            if(service != null && service.getPreprocessor() != null){
+                BirthmarkPreprocessor preprocessor = service.getPreprocessor();
+                preprocessor.preprocess(archives, context);
+            }
+        }
+        StigmataHookManager.getInstance().runHook(Phase.AFTER_PREPROCESS, context);
+
+        return context;
+    }
+
     private String[] mergeTarget(String[] t1, String[] t2){
         List<String> list = new ArrayList<String>();
         addToList(list, t1);
index e07fe59..27d032a 100644 (file)
@@ -36,16 +36,6 @@ public interface BirthmarkExtractor{
     public ExtractionUnit[] getAcceptableUnits();
 
     /**
-     * extract birthmark from given stream.
-     */
-    public Birthmark extract(InputStream in) throws BirthmarkExtractionFailedException;
-
-    /**
-     * extract birthmark from given byte array.
-     */
-    public Birthmark extract(byte[] bytecode) throws BirthmarkExtractionFailedException;
-
-    /**
      * extract birthmark from given stream with given environment.
      */
     public Birthmark extract(InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException;
@@ -56,16 +46,6 @@ public interface BirthmarkExtractor{
     public Birthmark extract(byte[] bytecode, BirthmarkContext context) throws BirthmarkExtractionFailedException;
 
     /**
-     * extract birthmark from given stream and add element to given birthmark object.
-     */
-    public Birthmark extract(Birthmark birthmark, InputStream in) throws BirthmarkExtractionFailedException;
-
-    /**
-     * extract birthmark from given byte array and add element to given birthmark object.
-     */
-    public Birthmark extract(Birthmark birthmark, byte[] bytecode) throws BirthmarkExtractionFailedException;
-
-    /**
      * extract birthmark from given stream with given environment and add element to given birthmark object.
      */
     public Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException;
diff --git a/src/main/java/jp/sourceforge/stigmata/BirthmarkPreprocessor.java b/src/main/java/jp/sourceforge/stigmata/BirthmarkPreprocessor.java
new file mode 100644 (file)
index 0000000..aff06ad
--- /dev/null
@@ -0,0 +1,7 @@
+package jp.sourceforge.stigmata;
+
+import jp.sourceforge.stigmata.digger.ClassFileArchive;
+
+public interface BirthmarkPreprocessor{
+    public void preprocess(ClassFileArchive[] targets, BirthmarkContext context);
+}
index 9796a27..5cda916 100644 (file)
@@ -30,6 +30,9 @@ public abstract class AbstractBirthmark implements Birthmark, Serializable{
         elements.add(element);
     }
 
+    /**
+     * returns the number of elements.
+     */
     public int getElementCount(){
         int numberOfElement = 0;
         BirthmarkElement[] elements = getElements();
@@ -40,18 +43,28 @@ public abstract class AbstractBirthmark implements Birthmark, Serializable{
     }
 
     /**
+     * returns elements.
      * @return  elements
      */
     public BirthmarkElement[] getElements(){
         return elements.toArray(new BirthmarkElement[elements.size()]);
     }
 
+    /**
+     * returns elements.
+     */
     public Iterator<BirthmarkElement> iterator(){
         return elements.iterator();
     }
 
+    /**
+     * returns the type of this birthmark.
+     */
     public abstract String getType();
 
+    /**
+     * Is given birthmark the same type.
+     */
     public boolean isSameType(Birthmark b){
         return getType().equals(b.getType());
     }
index c616e84..c826d5c 100644 (file)
@@ -9,7 +9,6 @@ import java.io.InputStream;
 
 import jp.sourceforge.stigmata.Birthmark;
 import jp.sourceforge.stigmata.BirthmarkContext;
-import jp.sourceforge.stigmata.BirthmarkEnvironment;
 import jp.sourceforge.stigmata.BirthmarkExtractionFailedException;
 import jp.sourceforge.stigmata.BirthmarkExtractor;
 import jp.sourceforge.stigmata.ExtractionUnit;
@@ -49,58 +48,30 @@ public abstract class AbstractBirthmarkExtractor implements BirthmarkExtractor{
     }
 
     /**
-     * extract birthmark given stream.
-     */
-    public final Birthmark extract(InputStream in) throws BirthmarkExtractionFailedException{
-        return extract(in, new BirthmarkContext(BirthmarkEnvironment.getDefaultEnvironment()));
-    }
-
-    /**
-     * extract birthmark given byte array.
-     */
-    public final Birthmark extract(byte[] bytecode) throws BirthmarkExtractionFailedException{
-        return extract(bytecode, new BirthmarkContext(BirthmarkEnvironment.getDefaultEnvironment()));
-    }
-
-    /**
-     * extract birthmark given stream.
-     */
-    public final Birthmark extract(Birthmark birthmark, InputStream in) throws BirthmarkExtractionFailedException{
-        return extract(birthmark, in, new BirthmarkContext(BirthmarkEnvironment.getDefaultEnvironment()));
-    }
-
-    /**
-     * extract birthmark given byte array.
-     */
-    public final Birthmark extract(Birthmark birthmark, byte[] bytecode) throws BirthmarkExtractionFailedException{
-        return extract(birthmark, bytecode, new BirthmarkContext(BirthmarkEnvironment.getDefaultEnvironment()));
-    }
-
-    /**
      * extract birthmark given stream with given environment.
      */
-    public final Birthmark extract(InputStream in, BirthmarkContext environment) throws BirthmarkExtractionFailedException{
-        return extract(createBirthmark(), in, environment);
+    public final Birthmark extract(InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException{
+        return extract(createBirthmark(), in, context);
     }
 
     /**
      * extract birthmark given byte array with given environment.
      */
-    public final Birthmark extract(Birthmark birthmark, byte[] bytecode, BirthmarkContext environment) throws BirthmarkExtractionFailedException{
-        return extract(birthmark, new ByteArrayInputStream(bytecode), environment);
+    public final Birthmark extract(Birthmark birthmark, byte[] bytecode, BirthmarkContext context) throws BirthmarkExtractionFailedException{
+        return extract(birthmark, new ByteArrayInputStream(bytecode), context);
     }
 
     /**
      * extract birthmark given byte array with given environment.
      */
-    public final Birthmark extract(byte[] bytecode, BirthmarkContext environment) throws BirthmarkExtractionFailedException{
-        return extract(createBirthmark(), new ByteArrayInputStream(bytecode), environment);
+    public final Birthmark extract(byte[] bytecode, BirthmarkContext context) throws BirthmarkExtractionFailedException{
+        return extract(createBirthmark(), new ByteArrayInputStream(bytecode), context);
     }
 
     /**
      * extract birthmark given stream with given environment.
      */
-    public abstract Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext environment) throws BirthmarkExtractionFailedException;
+    public abstract Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException;
 
     /**
      * create birthmark.
diff --git a/src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmarkPreprocessor.java b/src/main/java/jp/sourceforge/stigmata/birthmarks/AbstractBirthmarkPreprocessor.java
new file mode 100644 (file)
index 0000000..623492c
--- /dev/null
@@ -0,0 +1,27 @@
+package jp.sourceforge.stigmata.birthmarks;
+
+import jp.sourceforge.stigmata.BirthmarkContext;
+import jp.sourceforge.stigmata.BirthmarkPreprocessor;
+import jp.sourceforge.stigmata.digger.ClassFileArchive;
+import jp.sourceforge.stigmata.spi.BirthmarkSpi;
+
+public abstract class AbstractBirthmarkPreprocessor implements BirthmarkPreprocessor{
+    private BirthmarkSpi service;
+
+    /**
+     * default constructor.
+     */
+    @Deprecated
+    public AbstractBirthmarkPreprocessor(){
+    }
+
+    public AbstractBirthmarkPreprocessor(BirthmarkSpi service){
+        this.service = service;
+    }
+
+    public BirthmarkSpi getProvider(){
+        return service;
+    }
+
+    public abstract void preprocess(ClassFileArchive[] targets, BirthmarkContext context);
+}
index 512d44f..40a9bf8 100644 (file)
@@ -7,7 +7,10 @@ package jp.sourceforge.stigmata.birthmarks;
 import java.util.Locale;
 
 import jp.sourceforge.stigmata.Birthmark;
+import jp.sourceforge.stigmata.BirthmarkComparator;
 import jp.sourceforge.stigmata.BirthmarkElement;
+import jp.sourceforge.stigmata.BirthmarkExtractor;
+import jp.sourceforge.stigmata.BirthmarkPreprocessor;
 import jp.sourceforge.stigmata.spi.BirthmarkSpi;
 import jp.sourceforge.stigmata.utils.LocalizedDescriptionManager;
 
@@ -44,14 +47,31 @@ public abstract class AbstractBirthmarkService implements BirthmarkSpi{
         return description;
     }
 
+    public abstract BirthmarkComparator getComparator();
+
     public String getComparatorClassName(){
         return getComparator().getClass().getName();
     }
 
+    public abstract BirthmarkExtractor getExtractor();
+
     public String getExtractorClassName(){
         return getExtractor().getClass().getName();
     }
 
+    public BirthmarkPreprocessor getPreprocessor(){
+        return null;
+    }
+
+    public String getPreprocessorClassName(){
+        BirthmarkPreprocessor preprocessor = getPreprocessor();
+        String name = null;
+        if(preprocessor != null){
+            name = preprocessor.getClass().getName();
+        }
+        return name;
+    }
+
     public abstract String getType();
 
     public abstract String getDefaultDescription();
index 0dda80a..04629f7 100755 (executable)
@@ -12,6 +12,8 @@ package jp.sourceforge.stigmata.hook;
 public enum Phase{
     SETUP,
     TEAR_DOWN,
+    BEFORE_PREPROCESS,
+    AFTER_PREPROCESS,
     BEFORE_EXTRACTION,
     AFTER_EXTRACTION,
     BEFORE_COMPARISON,
index ca33814..5e6fdf7 100644 (file)
@@ -10,6 +10,7 @@ import jp.sourceforge.stigmata.Birthmark;
 import jp.sourceforge.stigmata.BirthmarkComparator;
 import jp.sourceforge.stigmata.BirthmarkElement;
 import jp.sourceforge.stigmata.BirthmarkExtractor;
+import jp.sourceforge.stigmata.BirthmarkPreprocessor;
 
 /**
  * Birthmark service provider interface.
@@ -54,6 +55,10 @@ public interface BirthmarkSpi extends ServiceProvider{
 
     public BirthmarkElement buildBirthmarkElement(String elementValue);
 
+    public BirthmarkPreprocessor getPreprocessor();
+
+    public String getPreprocessorClassName();
+
     /**
      * returns a extractor for the birthmark of this service.
      */
index 8aa1486..32635fe 100644 (file)
@@ -61,7 +61,6 @@ public class OpenItemsAction extends AbstractAction{
         });
     }
 
-    @Override
     public void actionPerformed(ActionEvent e){
         Item[] items;
         if(selectedItemFlag){