<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>
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;
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.
ExtractionResultSet er = context.getEnvironment().getHistoryManager().createDefaultResultSet(context);
try{
+ prepare(targetX, targetY, context);
+
StigmataHookManager.getInstance().runHook(Phase.BEFORE_EXTRACTION, context);
switch(context.getComparisonMethod()){
}
}
+ 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);
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;
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;
--- /dev/null
+package jp.sourceforge.stigmata;
+
+import jp.sourceforge.stigmata.digger.ClassFileArchive;
+
+public interface BirthmarkPreprocessor{
+ public void preprocess(ClassFileArchive[] targets, BirthmarkContext context);
+}
elements.add(element);
}
+ /**
+ * returns the number of elements.
+ */
public int getElementCount(){
int numberOfElement = 0;
BirthmarkElement[] elements = getElements();
}
/**
+ * 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());
}
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;
}
/**
- * 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.
--- /dev/null
+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);
+}
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;
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();
public enum Phase{
SETUP,
TEAR_DOWN,
+ BEFORE_PREPROCESS,
+ AFTER_PREPROCESS,
BEFORE_EXTRACTION,
AFTER_EXTRACTION,
BEFORE_COMPARISON,
import jp.sourceforge.stigmata.BirthmarkComparator;
import jp.sourceforge.stigmata.BirthmarkElement;
import jp.sourceforge.stigmata.BirthmarkExtractor;
+import jp.sourceforge.stigmata.BirthmarkPreprocessor;
/**
* Birthmark service provider interface.
public BirthmarkElement buildBirthmarkElement(String elementValue);
+ public BirthmarkPreprocessor getPreprocessor();
+
+ public String getPreprocessorClassName();
+
/**
* returns a extractor for the birthmark of this service.
*/
});
}
- @Override
public void actionPerformed(ActionEvent e){
Item[] items;
if(selectedItemFlag){