Stigmataのメインプログラムのためのリポジトリ.
Revision | 3b3e402e47ced2281afb78629c258f57eb63879c (tree) |
---|---|
Time | 2012-09-01 17:13:36 |
Author | Haruaki Tamada <tamada@cc.k...> |
Commiter | Haruaki Tamada |
delete default birthmarks, which move to basic project.
Update survey.
@@ -8,12 +8,12 @@ | ||
8 | 8 | <parent> |
9 | 9 | <groupId>jp.sourceforge</groupId> |
10 | 10 | <artifactId>stigmata</artifactId> |
11 | - <version>4.0-SNAPSHOT</version> | |
11 | + <version>4.0</version> | |
12 | 12 | </parent> |
13 | 13 | |
14 | 14 | <groupId>jp.sourceforge.stigmata</groupId> |
15 | 15 | <artifactId>stigmata-core</artifactId> |
16 | - <version>4.0-SNAPSHOT</version> | |
16 | + <version>4.0</version> | |
17 | 17 | <packaging>jar</packaging> |
18 | 18 | |
19 | 19 | <name>Stigmata: Java Birthmark Toolkit Core Library</name> |
@@ -21,6 +21,14 @@ | ||
21 | 21 | <url>http://stigmata.sourceforge.jp/</url> |
22 | 22 | <inceptionYear>2008</inceptionYear> |
23 | 23 | |
24 | + <repositories> | |
25 | + <repository> | |
26 | + <id>stigmata.sourceforge.jp</id> | |
27 | + <name>Stigmata Maven2 Repository in sourceforge.jp</name> | |
28 | + <url>http://stigmata.sourceforge.jp/maven2</url> | |
29 | + </repository> | |
30 | + </repositories> | |
31 | + | |
24 | 32 | <scm> |
25 | 33 | <connection>scm:git:git://git.sourceforge.jp/gitroot/stigmata/stigmata-core.git</connection> |
26 | 34 | <developerConnection>scm:git:ssh://tama3@git.sourceforge.jp:/gitroot/stigmata/stigmata-core.git</developerConnection> |
@@ -1,161 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import java.util.LinkedHashMap; | |
4 | -import java.util.Map; | |
5 | - | |
6 | -import jp.sourceforge.stigmata.Birthmark; | |
7 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | - | |
10 | -import org.objectweb.asm.ClassVisitor; | |
11 | -import org.objectweb.asm.FieldVisitor; | |
12 | -import org.objectweb.asm.MethodVisitor; | |
13 | -import org.objectweb.asm.Opcodes; | |
14 | -import org.objectweb.asm.Type; | |
15 | - | |
16 | -/** | |
17 | - * | |
18 | - * | |
19 | - * | |
20 | - * @author Haruaki TAMADA | |
21 | - */ | |
22 | -public class ConstantValueOfFieldVariableBirthmarkExtractVisitor extends BirthmarkExtractVisitor{ | |
23 | - private Map<String, TypeAndValueBirthmarkElement> elements = new LinkedHashMap<String, TypeAndValueBirthmarkElement>(); | |
24 | - private String className; | |
25 | - | |
26 | - public ConstantValueOfFieldVariableBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkContext context){ | |
27 | - super(visitor, birthmark, context); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public void visitEnd(){ | |
32 | - for(String key: elements.keySet()){ | |
33 | - addElement(elements.get(key)); | |
34 | - } | |
35 | - super.visitEnd(); | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public void visit(int version, int access, String name, String signature, | |
40 | - String superName, String[] interfaces){ | |
41 | - this.className = name; | |
42 | - | |
43 | - super.visit(version, access, name, signature, superName, interfaces); | |
44 | - } | |
45 | - | |
46 | - @Override | |
47 | - public FieldVisitor visitField(int access, String name, String desc, | |
48 | - String signature, Object value){ | |
49 | - | |
50 | - FieldVisitor visitor = super.visitField(access, name, desc, signature, value); | |
51 | - | |
52 | - TypeAndValueBirthmarkElement e = elements.get(name); | |
53 | - if(e == null){ | |
54 | - e = new TypeAndValueBirthmarkElement(desc, value); | |
55 | - } | |
56 | - else{ | |
57 | - if(value != null){ | |
58 | - e.setValue(value); | |
59 | - } | |
60 | - } | |
61 | - elements.put(name, e); | |
62 | - | |
63 | - return visitor; | |
64 | - } | |
65 | - | |
66 | - @Override | |
67 | - public MethodVisitor visitMethod(int access, String name, String desc, String signature, | |
68 | - String[] exceptions){ | |
69 | - MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions); | |
70 | - | |
71 | - if(name.equals("<init>") || name.equals("<clinit>")){ | |
72 | - visitor = new MethodVisitor(Opcodes.ASM4, visitor){ | |
73 | - private Object constant = null; | |
74 | - | |
75 | - @Override | |
76 | - public void visitIntInsn(int opcode, int operand){ | |
77 | - if(opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH){ | |
78 | - constant = new Integer(operand); | |
79 | - } | |
80 | - super.visitIntInsn(opcode, operand); | |
81 | - } | |
82 | - | |
83 | - @Override | |
84 | - public void visitMethodInsn(int opcode, String owner, String name, String desc){ | |
85 | - Type type = Type.getReturnType(desc); | |
86 | - if(!type.equals(Type.VOID_TYPE)){ | |
87 | - constant = null; | |
88 | - } | |
89 | - super.visitMethodInsn(opcode, owner, name, desc); | |
90 | - } | |
91 | - | |
92 | - @Override | |
93 | - public void visitInsn(int opcode){ | |
94 | - if(opcode == Opcodes.ICONST_M1) constant = new Integer(-1); | |
95 | - else if(opcode == Opcodes.ICONST_0) constant = new Integer(0); | |
96 | - else if(opcode == Opcodes.ICONST_1) constant = new Integer(1); | |
97 | - else if(opcode == Opcodes.ICONST_2) constant = new Integer(2); | |
98 | - else if(opcode == Opcodes.ICONST_3) constant = new Integer(3); | |
99 | - else if(opcode == Opcodes.ICONST_4) constant = new Integer(4); | |
100 | - else if(opcode == Opcodes.ICONST_5) constant = new Integer(5); | |
101 | - else if(opcode == Opcodes.LCONST_0) constant = new Long(0L); | |
102 | - else if(opcode == Opcodes.LCONST_1) constant = new Long(1L); | |
103 | - else if(opcode == Opcodes.DCONST_0) constant = new Double(0D); | |
104 | - else if(opcode == Opcodes.DCONST_1) constant = new Double(1D); | |
105 | - else if(opcode == Opcodes.FCONST_0) constant = new Float(0F); | |
106 | - else if(opcode == Opcodes.FCONST_1) constant = new Float(1F); | |
107 | - else if(opcode == Opcodes.FCONST_2) constant = new Float(2F); | |
108 | - | |
109 | - super.visitInsn(opcode); | |
110 | - } | |
111 | - | |
112 | - @Override | |
113 | - public void visitLdcInsn(Object object){ | |
114 | - constant = object; | |
115 | - super.visitLdcInsn(object); | |
116 | - } | |
117 | - | |
118 | - @Override | |
119 | - public void visitFieldInsn(int opcode, String owner, String name, String desc){ | |
120 | - if(className.equals(owner) && opcode == Opcodes.PUTFIELD){ | |
121 | - TypeAndValueBirthmarkElement e = elements.get(name); | |
122 | - if(e == null){ | |
123 | - e = new TypeAndValueBirthmarkElement(desc, constant); | |
124 | - } | |
125 | - | |
126 | - if(e.getValue() == null && constant != null){ | |
127 | - if(!checkCast(desc, constant)){ | |
128 | - constant = null; | |
129 | - } | |
130 | - e.setValue(constant); | |
131 | - } | |
132 | - } | |
133 | - super.visitFieldInsn(opcode, owner, name, desc); | |
134 | - } | |
135 | - }; | |
136 | - } | |
137 | - | |
138 | - return visitor; | |
139 | - } | |
140 | - | |
141 | - private boolean checkCast(String desc, Object constant){ | |
142 | - if(constant instanceof Integer){ | |
143 | - return desc.equals("Ljava/lang/Integer;") || | |
144 | - desc.equals("I") || desc.equals("S") || desc.equals("Z") || | |
145 | - desc.equals("C") || desc.equals("B"); | |
146 | - } | |
147 | - else if(constant instanceof Float){ | |
148 | - return desc.equals("Ljava/lang/Float;") || desc.equals("F"); | |
149 | - } | |
150 | - else if(constant instanceof Double){ | |
151 | - return desc.equals("Ljava/lang/Double;") || desc.equals("D"); | |
152 | - } | |
153 | - else if(constant instanceof Long){ | |
154 | - return desc.equals("Ljava/lang/Long;") || desc.equals("J"); | |
155 | - } | |
156 | - else if(constant instanceof String){ | |
157 | - return desc.equals("Ljava/lang/String;"); | |
158 | - } | |
159 | - return false; | |
160 | - } | |
161 | -} |
@@ -1,65 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
7 | -import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
10 | - | |
11 | -import org.objectweb.asm.ClassWriter; | |
12 | - | |
13 | -/** | |
14 | - * | |
15 | - * @author Haruaki TAMADA | |
16 | - */ | |
17 | -public class ConstantValueOfFieldVariableBirthmarkExtractor extends ASMBirthmarkExtractor{ | |
18 | - public ConstantValueOfFieldVariableBirthmarkExtractor(BirthmarkService spi){ | |
19 | - super(spi); | |
20 | - } | |
21 | - | |
22 | - public ConstantValueOfFieldVariableBirthmarkExtractor(){ | |
23 | - super(); | |
24 | - } | |
25 | - | |
26 | - @Override | |
27 | - public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context) { | |
28 | - return new ConstantValueOfFieldVariableBirthmarkExtractVisitor(writer, birthmark, context); | |
29 | - } | |
30 | - | |
31 | - @Override | |
32 | - public ExtractionUnit[] getAcceptableUnits(){ | |
33 | - return new ExtractionUnit[] { | |
34 | - ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE, | |
35 | - }; | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public BirthmarkElement buildElement(String value) { | |
40 | - String signature = value.substring(0, value.indexOf('=')); | |
41 | - String subValue = value.substring(value.indexOf('=') + 1); | |
42 | - Object elementValue = subValue; | |
43 | - | |
44 | - if(subValue.equals("null")){ | |
45 | - elementValue = null; | |
46 | - } | |
47 | - else{ | |
48 | - switch(signature.charAt(0)){ | |
49 | - case 'Z':{ | |
50 | - if(value.equals("true")) elementValue = Boolean.TRUE; | |
51 | - else elementValue = Boolean.FALSE; | |
52 | - break; | |
53 | - } | |
54 | - case 'C': elementValue = new Character(subValue.charAt(0)); break; | |
55 | - case 'D': elementValue = new Double(subValue); break; | |
56 | - case 'F': elementValue = new Float(subValue); break; | |
57 | - case 'S': elementValue = new Short(subValue); break; | |
58 | - case 'B': elementValue = new Byte(subValue); break; | |
59 | - case 'I': elementValue = new Integer(subValue); break; | |
60 | - default: elementValue = value; break; | |
61 | - } | |
62 | - } | |
63 | - return new TypeAndValueBirthmarkElement(signature, elementValue); | |
64 | - } | |
65 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class ConstantValueOfFieldVariableBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "cvfv"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new ConstantValueOfFieldVariableBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Constant Value and Field Variable birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class ConstantValueOfFieldVariableBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new PlainBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new ConstantValueOfFieldVariableBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "cvfv"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public String getDescription(){ | |
26 | - return "Field type and its initial value."; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractor getExtractor(){ | |
31 | - return extractor; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public BirthmarkComparator getComparator(){ | |
36 | - return comparator; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isExperimental(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public boolean isUserDefined(){ | |
46 | - return false; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,91 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import java.io.IOException; | |
4 | -import java.io.ObjectInputStream; | |
5 | -import java.io.Serializable; | |
6 | - | |
7 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * @author Haruaki TAMADA | |
12 | - */ | |
13 | -public class TypeAndValueBirthmarkElement extends BirthmarkElement implements Serializable{ | |
14 | - private static final long serialVersionUID = 237098465735321L; | |
15 | - | |
16 | - private String signature; | |
17 | - private Serializable serialValue; | |
18 | - private transient Object value; | |
19 | - | |
20 | - /** | |
21 | - * @param value | |
22 | - */ | |
23 | - public TypeAndValueBirthmarkElement(String signature, Object value){ | |
24 | - super(signature + "=" + value); | |
25 | - this.signature = signature; | |
26 | - setValue(value); | |
27 | - } | |
28 | - | |
29 | - public String getSignature(){ | |
30 | - return signature; | |
31 | - } | |
32 | - | |
33 | - public void setValue(Object value){ | |
34 | - this.value = value; | |
35 | - if(signature.length() == 1 && value == null){ | |
36 | - switch(signature.charAt(0)){ | |
37 | - case 'Z': value = Boolean.FALSE; break; | |
38 | - case 'D': value = new Double(0d); break; | |
39 | - case 'F': value = new Float(0f); break; | |
40 | - case 'C': | |
41 | - case 'S': | |
42 | - case 'B': | |
43 | - case 'I': | |
44 | - default: value = new Integer(0); break; | |
45 | - } | |
46 | - } | |
47 | - | |
48 | - if(value != null && value instanceof Serializable){ | |
49 | - serialValue = (Serializable)value; | |
50 | - } | |
51 | - } | |
52 | - | |
53 | - @Override | |
54 | - public Object getValue(){ | |
55 | - return value; | |
56 | - } | |
57 | - | |
58 | - @Override | |
59 | - public String toString(){ | |
60 | - return signature + "=" + value; | |
61 | - } | |
62 | - | |
63 | - @Override | |
64 | - public int hashCode(){ | |
65 | - return signature.hashCode() + value.hashCode(); | |
66 | - } | |
67 | - | |
68 | - @Override | |
69 | - public boolean equals(Object o){ | |
70 | - if(o instanceof TypeAndValueBirthmarkElement){ | |
71 | - TypeAndValueBirthmarkElement tvbe = (TypeAndValueBirthmarkElement)o; | |
72 | - | |
73 | - if(getSignature().equals(tvbe.getSignature())){ | |
74 | - if(getValue() == null && tvbe.getValue() == null){ | |
75 | - return true; | |
76 | - } | |
77 | - else if(getValue() != null && tvbe.getValue() != null){ | |
78 | - return getValue().equals(tvbe.getValue()); | |
79 | - } | |
80 | - } | |
81 | - } | |
82 | - return false; | |
83 | - } | |
84 | - | |
85 | - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{ | |
86 | - in.defaultReadObject(); | |
87 | - if(serialValue != null){ | |
88 | - value = serialValue; | |
89 | - } | |
90 | - } | |
91 | -} |
@@ -1,55 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fmc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
7 | -import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | -import jp.sourceforge.stigmata.birthmarks.FrequencyBirthmark; | |
10 | -import jp.sourceforge.stigmata.birthmarks.FrequencyBirthmarkElement; | |
11 | -import jp.sourceforge.stigmata.birthmarks.smc.SequentialMethodCallBirthmarkExtractVisitor; | |
12 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
13 | - | |
14 | -import org.objectweb.asm.ClassWriter; | |
15 | - | |
16 | -/** | |
17 | - * @author Haruaki TAMADA | |
18 | - */ | |
19 | -public class FrequencyMethodCallBirthmarkExtractor extends ASMBirthmarkExtractor{ | |
20 | - public FrequencyMethodCallBirthmarkExtractor(BirthmarkService spi){ | |
21 | - super(spi); | |
22 | - } | |
23 | - | |
24 | - public FrequencyMethodCallBirthmarkExtractor(){ | |
25 | - super(); | |
26 | - } | |
27 | - | |
28 | - @Override | |
29 | - public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){ | |
30 | - return new SequentialMethodCallBirthmarkExtractVisitor(writer, birthmark, context){ | |
31 | - @Override | |
32 | - protected void addElement(String className, String methodName, String description){ | |
33 | - addElement(new FrequencyBirthmarkElement(className + "#" + methodName + description)); | |
34 | - } | |
35 | - }; | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public ExtractionUnit[] getAcceptableUnits(){ | |
40 | - return new ExtractionUnit[] { | |
41 | - ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE, | |
42 | - }; | |
43 | - } | |
44 | - | |
45 | - @Override | |
46 | - public Birthmark createBirthmark(){ | |
47 | - return new FrequencyBirthmark(getProvider().getType()); | |
48 | - } | |
49 | - | |
50 | - | |
51 | - @Override | |
52 | - public BirthmarkElement buildElement(String value) { | |
53 | - return new FrequencyBirthmarkElement(value); | |
54 | - } | |
55 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fmc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class FrequencyMethodCallBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "fmc"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new FrequencyMethodCallBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Frequency of Method Calls birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fmc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.CosineSimilarityBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class FrequencyMethodCallBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new CosineSimilarityBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new FrequencyMethodCallBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "fmc"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public BirthmarkExtractor getExtractor(){ | |
26 | - return extractor; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkComparator getComparator(){ | |
31 | - return comparator; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public boolean isExperimental(){ | |
36 | - return false; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isUserDefined(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public String getDescription(){ | |
46 | - return "Frequency of Method Calls"; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,49 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fuc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
7 | -import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | -import jp.sourceforge.stigmata.birthmarks.FrequencyBirthmark; | |
10 | -import jp.sourceforge.stigmata.birthmarks.FrequencyBirthmarkElement; | |
11 | -import jp.sourceforge.stigmata.birthmarks.uc.UsedClassesBirthmarkExtractVisitor; | |
12 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
13 | - | |
14 | -import org.objectweb.asm.ClassWriter; | |
15 | - | |
16 | -/** | |
17 | - * | |
18 | - * @author Haruaki TAMADA | |
19 | - */ | |
20 | -public class FrequencyUsedClassesBirthmarkExtractor extends ASMBirthmarkExtractor{ | |
21 | - public FrequencyUsedClassesBirthmarkExtractor(BirthmarkService spi){ | |
22 | - super(spi); | |
23 | - } | |
24 | - | |
25 | - public FrequencyUsedClassesBirthmarkExtractor(){ | |
26 | - super(); | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){ | |
31 | - return new UsedClassesBirthmarkExtractVisitor(writer, birthmark, context); | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public ExtractionUnit[] getAcceptableUnits(){ | |
36 | - return new ExtractionUnit[] { | |
37 | - ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE, | |
38 | - }; | |
39 | - } | |
40 | - | |
41 | - @Override | |
42 | - public Birthmark createBirthmark(){ | |
43 | - return new FrequencyBirthmark(getProvider().getType()); | |
44 | - } | |
45 | - | |
46 | - public BirthmarkElement buildElement(String value){ | |
47 | - return new FrequencyBirthmarkElement(value); | |
48 | - } | |
49 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fuc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class FrequencyUsedClassesBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "fuc"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new FrequencyUsedClassesBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Frequency of Used Classes birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.fuc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.CosineSimilarityBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class FrequencyUsedClassesBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new CosineSimilarityBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new FrequencyUsedClassesBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "fuc"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public String getDescription(){ | |
26 | - return "Frequency of used classes in target class."; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractor getExtractor(){ | |
31 | - return extractor; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public BirthmarkComparator getComparator(){ | |
36 | - return comparator; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isExperimental(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public boolean isUserDefined(){ | |
46 | - return false; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,85 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.is; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
7 | -import jp.sourceforge.stigmata.birthmarks.NullBirthmarkElement; | |
8 | -import jp.sourceforge.stigmata.digger.ClassFileEntry; | |
9 | -import jp.sourceforge.stigmata.digger.ClasspathContext; | |
10 | -import jp.sourceforge.stigmata.utils.WellknownClassManager; | |
11 | - | |
12 | -import org.objectweb.asm.ClassVisitor; | |
13 | -import org.objectweb.asm.Opcodes; | |
14 | - | |
15 | - | |
16 | -/** | |
17 | - * | |
18 | - * | |
19 | - * | |
20 | - * @author Haruaki TAMADA | |
21 | - */ | |
22 | -public class InheritanceStructureBirthmarkExtractVisitor extends BirthmarkExtractVisitor{ | |
23 | - public InheritanceStructureBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkContext context){ | |
24 | - super(visitor, birthmark, context); | |
25 | - } | |
26 | - | |
27 | - @Override | |
28 | - public void visit(int version, int access, String name, String signature, | |
29 | - String superName, String[] interfaces){ | |
30 | - if((access & Opcodes.ACC_INTERFACE) != Opcodes.ACC_INTERFACE){ | |
31 | - ClasspathContext context = getEnvironment().getClasspathContext(); | |
32 | - name = name.replace('/', '.'); | |
33 | - ClassFileEntry entry = context.findEntry(name); | |
34 | - if(entry == null){ | |
35 | - superName = superName.replace('/', '.'); | |
36 | - ClassFileEntry parent = context.findEntry(superName); | |
37 | - if(parent != null){ | |
38 | - addIsBirthmark(name); | |
39 | - addIsBirthmark(superName); | |
40 | - } | |
41 | - else{ | |
42 | - addFailur(new ClassNotFoundException(superName)); | |
43 | - } | |
44 | - } | |
45 | - else{ | |
46 | - try{ | |
47 | - Class<?> clazz = context.findClass(name); | |
48 | - addISBirthmark(clazz); | |
49 | - } catch(ClassNotFoundException e){ | |
50 | - addFailur(e); | |
51 | - } | |
52 | - } | |
53 | - } | |
54 | - } | |
55 | - | |
56 | - private void addIsBirthmark(String className){ | |
57 | - WellknownClassManager wcm = getEnvironment().getWellknownClassManager(); | |
58 | - BirthmarkElement element; | |
59 | - if(wcm.isWellKnownClass(className)){ | |
60 | - element = new BirthmarkElement(className); | |
61 | - } | |
62 | - else{ | |
63 | - element = NullBirthmarkElement.getInstance(); | |
64 | - } | |
65 | - addElement(element); | |
66 | - } | |
67 | - | |
68 | - private void addISBirthmark(Class<?> c){ | |
69 | - WellknownClassManager wcm = getEnvironment().getWellknownClassManager(); | |
70 | - do{ | |
71 | - String className = c.getName(); | |
72 | - BirthmarkElement element = null; | |
73 | - if(wcm.isWellKnownClass(className)){ | |
74 | - element = new BirthmarkElement(className); | |
75 | - } | |
76 | - else{ | |
77 | - element = NullBirthmarkElement.getInstance(); | |
78 | - } | |
79 | - | |
80 | - addElement(element); | |
81 | - c = c.getSuperclass(); | |
82 | - } while(!c.getName().equals("java.lang.Object")); | |
83 | - addElement(new BirthmarkElement("java.lang.Object")); | |
84 | - } | |
85 | -} |
@@ -1,74 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.is; | |
2 | - | |
3 | -import java.io.IOException; | |
4 | -import java.io.InputStream; | |
5 | - | |
6 | -import jp.sourceforge.stigmata.Birthmark; | |
7 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
8 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
9 | -import jp.sourceforge.stigmata.BirthmarkElementClassNotFoundException; | |
10 | -import jp.sourceforge.stigmata.BirthmarkExtractionFailedException; | |
11 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
12 | -import jp.sourceforge.stigmata.birthmarks.AbstractBirthmarkExtractor; | |
13 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
14 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
15 | - | |
16 | -import org.objectweb.asm.ClassReader; | |
17 | -import org.objectweb.asm.ClassWriter; | |
18 | - | |
19 | - | |
20 | -/** | |
21 | - * | |
22 | - * @author Haruaki TAMADA | |
23 | - */ | |
24 | -public class InheritanceStructureBirthmarkExtractor extends AbstractBirthmarkExtractor{ | |
25 | - public InheritanceStructureBirthmarkExtractor(BirthmarkService spi){ | |
26 | - super(spi); | |
27 | - } | |
28 | - | |
29 | - @SuppressWarnings("deprecation") | |
30 | - public InheritanceStructureBirthmarkExtractor(){ | |
31 | - super(); | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException{ | |
36 | - BirthmarkElementClassNotFoundException e = new BirthmarkElementClassNotFoundException(); | |
37 | - | |
38 | - try{ | |
39 | - ClassReader reader = new ClassReader(in); | |
40 | - ClassWriter writer = new ClassWriter(0); | |
41 | - BirthmarkExtractVisitor visitor = new InheritanceStructureBirthmarkExtractVisitor(writer, birthmark, context); | |
42 | - reader.accept(visitor, 0); | |
43 | - | |
44 | - if(!visitor.isSuccess()){ | |
45 | - for(Throwable t: visitor.getCauses()){ | |
46 | - if(t instanceof ClassNotFoundException){ | |
47 | - e.addClassName(t.getMessage()); | |
48 | - } | |
49 | - else{ | |
50 | - e.addCause(t); | |
51 | - } | |
52 | - } | |
53 | - } | |
54 | - } catch(IOException ee){ | |
55 | - e.addCause(ee); | |
56 | - } finally{ | |
57 | - if(e.isFailed()){ | |
58 | - System.out.printf("fail: %s%n", e.getMessage()); | |
59 | - throw e; | |
60 | - } | |
61 | - } | |
62 | - return birthmark; | |
63 | - } | |
64 | - | |
65 | - @Override | |
66 | - public ExtractionUnit[] getAcceptableUnits(){ | |
67 | - return new ExtractionUnit[] { ExtractionUnit.CLASS, }; | |
68 | - } | |
69 | - | |
70 | - @Override | |
71 | - public BirthmarkElement buildElement(String value){ | |
72 | - return new BirthmarkElement(value); | |
73 | - } | |
74 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.is; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class InheritanceStructureBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "is"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new InheritanceStructureBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Inheritance Structure birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.is; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class InheritanceStructureBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new PlainBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new InheritanceStructureBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "is"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public String getDescription(){ | |
26 | - return "Inheritance sequence to root class and user classes is replaced to <null>."; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractor getExtractor(){ | |
31 | - return extractor; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public BirthmarkComparator getComparator(){ | |
36 | - return comparator; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isExperimental(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public boolean isUserDefined(){ | |
46 | - return false; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,61 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import java.io.Serializable; | |
4 | - | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | - | |
7 | -/** | |
8 | - * | |
9 | - * @author Haruaki TAMADA | |
10 | - */ | |
11 | -public class MethodCallBirthmarkElement extends BirthmarkElement implements Serializable { | |
12 | - private static final long serialVersionUID = -3178451461780859954L; | |
13 | - | |
14 | - private String className; | |
15 | - private String methodName; | |
16 | - private String signature; | |
17 | - | |
18 | - public MethodCallBirthmarkElement(String className, String methodName, String signature) { | |
19 | - super(className + "#" + methodName); | |
20 | - | |
21 | - this.className = className; | |
22 | - this.methodName = methodName; | |
23 | - this.signature = signature; | |
24 | - } | |
25 | - | |
26 | - public String getClassName(){ | |
27 | - return className; | |
28 | - } | |
29 | - | |
30 | - public String getMethodName(){ | |
31 | - return methodName; | |
32 | - } | |
33 | - | |
34 | - public String getSignature(){ | |
35 | - return signature; | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public Object getValue(){ | |
40 | - return getClassName() + "#" + getMethodName() + "!" + getSignature(); | |
41 | - } | |
42 | - | |
43 | - @Override | |
44 | - public int hashCode(){ | |
45 | - return System.identityHashCode(this); | |
46 | - } | |
47 | - | |
48 | - @Override | |
49 | - public boolean equals(Object o){ | |
50 | - boolean flag = false; | |
51 | - if(o instanceof MethodCallBirthmarkElement){ | |
52 | - MethodCallBirthmarkElement mcbe = (MethodCallBirthmarkElement)o; | |
53 | - | |
54 | - flag = getClassName().equals(mcbe.getClassName()) && | |
55 | - getMethodName().equals(mcbe.getMethodName()) && | |
56 | - getSignature().equals(mcbe.getSignature()); | |
57 | - } | |
58 | - | |
59 | - return flag; | |
60 | - } | |
61 | -} |
@@ -1,42 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
6 | -import org.objectweb.asm.ClassVisitor; | |
7 | -import org.objectweb.asm.MethodVisitor; | |
8 | -import org.objectweb.asm.Opcodes; | |
9 | - | |
10 | -/** | |
11 | - * | |
12 | - * | |
13 | - * | |
14 | - * @author Haruaki TAMADA | |
15 | - */ | |
16 | -public class SequentialMethodCallBirthmarkExtractVisitor extends BirthmarkExtractVisitor{ | |
17 | - public SequentialMethodCallBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkContext context){ | |
18 | - super(visitor, birthmark, context); | |
19 | - } | |
20 | - | |
21 | - @Override | |
22 | - public MethodVisitor visitMethod(int access, String name, String desc, | |
23 | - String signature, String[] exceptions){ | |
24 | - | |
25 | - MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions); | |
26 | - | |
27 | - return new MethodVisitor(Opcodes.ASM4, visitor){ | |
28 | - @Override | |
29 | - public void visitMethodInsn(int opcode, String owner, String name, String desc){ | |
30 | - String className = owner.replace('/', '.'); | |
31 | - if(getEnvironment().getWellknownClassManager().isWellKnownClass(className)){ | |
32 | - addElement(className, name, desc); | |
33 | - } | |
34 | - super.visitMethodInsn(opcode, owner, name, desc); | |
35 | - } | |
36 | - }; | |
37 | - } | |
38 | - | |
39 | - protected void addElement(String className, String methodName, String description){ | |
40 | - addElement(new MethodCallBirthmarkElement(className, methodName, description)); | |
41 | - } | |
42 | -} |
@@ -1,43 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
7 | -import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
10 | - | |
11 | -import org.objectweb.asm.ClassWriter; | |
12 | - | |
13 | -/** | |
14 | - * @author Haruaki TAMADA | |
15 | - */ | |
16 | -public class SequentialMethodCallBirthmarkExtractor extends ASMBirthmarkExtractor{ | |
17 | - public SequentialMethodCallBirthmarkExtractor(BirthmarkService spi){ | |
18 | - super(spi); | |
19 | - } | |
20 | - | |
21 | - public SequentialMethodCallBirthmarkExtractor(){ | |
22 | - super(); | |
23 | - } | |
24 | - | |
25 | - @Override | |
26 | - public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){ | |
27 | - return new SequentialMethodCallBirthmarkExtractVisitor(writer, birthmark, context); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public ExtractionUnit[] getAcceptableUnits(){ | |
32 | - return new ExtractionUnit[] { ExtractionUnit.CLASS, ExtractionUnit.ARCHIVE, ExtractionUnit.PACKAGE, }; | |
33 | - } | |
34 | - | |
35 | - @Override | |
36 | - public BirthmarkElement buildElement(String value) { | |
37 | - String className = value.substring(0, value.indexOf('#')); | |
38 | - String methodName = value.substring(value.indexOf('#') + 1, value.lastIndexOf('!')); | |
39 | - String signature = value.substring(value.lastIndexOf('!') + 1); | |
40 | - | |
41 | - return new MethodCallBirthmarkElement(className, methodName, signature); | |
42 | - } | |
43 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class SequentialMethodCallBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "smc"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new SequentialMethodCallBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Sequence of Method Calls birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class SequentialMethodCallBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new PlainBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new SequentialMethodCallBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "smc"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public String getDescription(){ | |
26 | - return "Sequence of method call which order is appeared in method definition."; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractor getExtractor(){ | |
31 | - return extractor; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public BirthmarkComparator getComparator(){ | |
36 | - return comparator; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isExperimental(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public boolean isUserDefined(){ | |
46 | - return false; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,42 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
4 | -import jp.sourceforge.stigmata.birthmarks.PlainBirthmark; | |
5 | - | |
6 | -/** | |
7 | - * | |
8 | - * @author Haruaki Tamada | |
9 | - */ | |
10 | -class UsedClassesBirthmark extends PlainBirthmark{ | |
11 | - private static final long serialVersionUID = -1043130948373105655L; | |
12 | - | |
13 | - public UsedClassesBirthmark(String type){ | |
14 | - super(type); | |
15 | - } | |
16 | - | |
17 | - @Override | |
18 | - public synchronized void addElement(BirthmarkElement element){ | |
19 | - int c = getElementCount(); | |
20 | - String s = (String)element.getValue(); | |
21 | - boolean addFlag = false; | |
22 | - for(int i = 0; i < c; i++){ | |
23 | - BirthmarkElement e = getElement(i); | |
24 | - String v = (String)e.getValue(); | |
25 | - if(s.equals(v)){ | |
26 | - addFlag = true; | |
27 | - break; | |
28 | - } | |
29 | - } | |
30 | - if(!addFlag){ | |
31 | - for(int i = 0; i < c; i++){ | |
32 | - if(s.compareTo((String)getElement(i).getValue()) < 0){ | |
33 | - super.addElement(i, element); | |
34 | - break; | |
35 | - } | |
36 | - } | |
37 | - } | |
38 | - if(!addFlag && c == getElementCount()){ | |
39 | - super.addElement(element); | |
40 | - } | |
41 | - } | |
42 | -} |
@@ -1,194 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
7 | - | |
8 | -import org.objectweb.asm.ClassVisitor; | |
9 | -import org.objectweb.asm.FieldVisitor; | |
10 | -import org.objectweb.asm.Label; | |
11 | -import org.objectweb.asm.MethodVisitor; | |
12 | -import org.objectweb.asm.Opcodes; | |
13 | -import org.objectweb.asm.Type; | |
14 | -import org.objectweb.asm.signature.SignatureReader; | |
15 | -import org.objectweb.asm.signature.SignatureWriter; | |
16 | - | |
17 | -/** | |
18 | - * | |
19 | - * @author Haruaki TAMADA | |
20 | - */ | |
21 | -public class UsedClassesBirthmarkExtractVisitor extends BirthmarkExtractVisitor{ | |
22 | - public UsedClassesBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark, | |
23 | - BirthmarkContext context){ | |
24 | - super(visitor, birthmark, context); | |
25 | - } | |
26 | - | |
27 | - @Override | |
28 | - public void visit(int version, int access, String name, String signature, | |
29 | - String superName, String[] interfaces){ | |
30 | - addSignatureClass(signature); | |
31 | - | |
32 | - addUCElement(superName); | |
33 | - for(String i: interfaces){ | |
34 | - addUCElement(i); | |
35 | - } | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public FieldVisitor visitField(int access, String name, String desc, | |
40 | - String signature, Object value){ | |
41 | - FieldVisitor visitor = super.visitField(access, name, desc, signature, value); | |
42 | - | |
43 | - addDescriptor(desc); | |
44 | - addSignatureClass(signature); | |
45 | - | |
46 | - return visitor; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public MethodVisitor visitMethod(int access, String name, String desc, | |
51 | - String signature, String[] exceptions){ | |
52 | - if(exceptions != null){ | |
53 | - for(String exception: exceptions){ | |
54 | - addUCElement(exception); | |
55 | - } | |
56 | - } | |
57 | - addMethodDescriptor(desc); | |
58 | - addSignatureClass(signature); | |
59 | - | |
60 | - MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions); | |
61 | - | |
62 | - return new MethodVisitor(Opcodes.ASM4, visitor){ | |
63 | - @Override | |
64 | - public void visitTypeInsn(int opcode, String desc){ | |
65 | - Type type = Type.getType("L" + desc + ";"); | |
66 | - if(checkType(type)){ | |
67 | - addUCElement(desc); | |
68 | - } | |
69 | - super.visitTypeInsn(opcode, desc); | |
70 | - } | |
71 | - | |
72 | - @Override | |
73 | - public void visitTryCatchBlock(Label start, Label end, Label handle, String desc){ | |
74 | - Type type = Type.getType("L" + desc + ";"); | |
75 | - if(checkType(type)){ | |
76 | - addUCElement(getType(type)); | |
77 | - } | |
78 | - super.visitTryCatchBlock(start, end, handle, desc); | |
79 | - } | |
80 | - | |
81 | - @Override | |
82 | - public void visitMultiANewArrayInsn(String desc, int dims){ | |
83 | - Type type = Type.getType(desc); | |
84 | - if(checkType(type)){ | |
85 | - addUCElement(getType(type)); | |
86 | - } | |
87 | - super.visitMultiANewArrayInsn(desc, dims); | |
88 | - } | |
89 | - | |
90 | - @Override | |
91 | - public void visitLocalVariable(String name, String desc, String signature, | |
92 | - Label start, Label end, int index){ | |
93 | - if(checkType(Type.getType(desc))){ | |
94 | - addUCElement(desc); | |
95 | - } | |
96 | - addSignatureClass(signature); | |
97 | - | |
98 | - super.visitLocalVariable(name, desc, signature, start, end, index); | |
99 | - } | |
100 | - | |
101 | - @Override | |
102 | - public void visitFieldInsn(int opcode, String owner, String name, String desc){ | |
103 | - addUCElement(owner); | |
104 | - addDescriptor(desc); | |
105 | - super.visitFieldInsn(opcode, owner, name, desc); | |
106 | - } | |
107 | - @Override | |
108 | - public void visitMethodInsn(int opcode, String owner, String name, String desc){ | |
109 | - String className = normalize(owner); | |
110 | - addUCElement(className); | |
111 | - addMethodDescriptor(desc); | |
112 | - super.visitMethodInsn(opcode, owner, name, desc); | |
113 | - } | |
114 | - }; | |
115 | - } | |
116 | - | |
117 | - private void addSignatureClass(String signature){ | |
118 | - if(signature != null){ | |
119 | - SignatureReader in = new SignatureReader(signature); | |
120 | - SignatureWriter writer = new SignatureWriter(){ | |
121 | - @Override | |
122 | - public void visitClassType(String classType){ | |
123 | - addUCElement(classType); | |
124 | - } | |
125 | - }; | |
126 | - in.accept(writer); | |
127 | - } | |
128 | - } | |
129 | - | |
130 | - private void addMethodDescriptor(String desc){ | |
131 | - Type returnType = Type.getReturnType(desc); | |
132 | - Type[] args = Type.getArgumentTypes(desc); | |
133 | - if(checkType(returnType)){ | |
134 | - addUCElement(getType(returnType)); | |
135 | - } | |
136 | - for(Type arg: args){ | |
137 | - if(checkType(arg)){ | |
138 | - addUCElement(getType(arg)); | |
139 | - } | |
140 | - } | |
141 | - } | |
142 | - | |
143 | - private void addDescriptor(String desc){ | |
144 | - Type type = Type.getType(desc); | |
145 | - if(checkType(type)){ | |
146 | - addUCElement(desc); | |
147 | - } | |
148 | - } | |
149 | - | |
150 | - private String getType(Type type){ | |
151 | - if(type.getSort() == Type.ARRAY){ | |
152 | - while(type.getSort() != Type.ARRAY){ | |
153 | - type = type.getElementType(); | |
154 | - } | |
155 | - } | |
156 | - | |
157 | - if(type.getSort() == Type.OBJECT){ | |
158 | - return normalize(type.getClassName()); | |
159 | - } | |
160 | - | |
161 | - return null; | |
162 | - } | |
163 | - | |
164 | - private boolean checkType(Type type){ | |
165 | - if(type.getSort() == Type.ARRAY){ | |
166 | - while(type.getSort() != Type.ARRAY){ | |
167 | - type = type.getElementType(); | |
168 | - } | |
169 | - } | |
170 | - | |
171 | - if(type.getSort() == Type.OBJECT){ | |
172 | - String className = type.getClassName(); | |
173 | - if(getEnvironment().getWellknownClassManager().isWellKnownClass(className)){ | |
174 | - return true; | |
175 | - } | |
176 | - } | |
177 | - return false; | |
178 | - } | |
179 | - | |
180 | - private String normalize(String name){ | |
181 | - if(name.startsWith("L") && name.endsWith(";")){ | |
182 | - name = name.substring(1, name.length() - 1); | |
183 | - } | |
184 | - name = name.replace('/', '.'); | |
185 | - | |
186 | - return name; | |
187 | - } | |
188 | - | |
189 | - private void addUCElement(String name){ | |
190 | - if(getEnvironment().getWellknownClassManager().isWellKnownClass(name)){ | |
191 | - addElement(new BirthmarkElement(normalize(name))); | |
192 | - } | |
193 | - } | |
194 | -} |
@@ -1,47 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.Birthmark; | |
4 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
5 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
6 | -import jp.sourceforge.stigmata.ExtractionUnit; | |
7 | -import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor; | |
8 | -import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor; | |
9 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
10 | - | |
11 | -import org.objectweb.asm.ClassWriter; | |
12 | - | |
13 | -/** | |
14 | - * | |
15 | - * @author Haruaki TAMADA | |
16 | - */ | |
17 | -public class UsedClassesBirthmarkExtractor extends ASMBirthmarkExtractor{ | |
18 | - public UsedClassesBirthmarkExtractor(BirthmarkService spi){ | |
19 | - super(spi); | |
20 | - } | |
21 | - | |
22 | - public UsedClassesBirthmarkExtractor(){ | |
23 | - super(); | |
24 | - } | |
25 | - | |
26 | - @Override | |
27 | - public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){ | |
28 | - return new UsedClassesBirthmarkExtractVisitor(writer, birthmark, context); | |
29 | - } | |
30 | - | |
31 | - @Override | |
32 | - public ExtractionUnit[] getAcceptableUnits(){ | |
33 | - return new ExtractionUnit[] { | |
34 | - ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE, | |
35 | - }; | |
36 | - } | |
37 | - | |
38 | - @Override | |
39 | - public Birthmark createBirthmark(){ | |
40 | - return new UsedClassesBirthmark(getProvider().getType()); | |
41 | - } | |
42 | - | |
43 | - @Override | |
44 | - public BirthmarkElement buildElement(String value){ | |
45 | - return new BirthmarkElement(value); | |
46 | - } | |
47 | -} |
@@ -1,34 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
4 | -import jp.sourceforge.stigmata.spi.BirthmarkExtractorService; | |
5 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
6 | - | |
7 | -/** | |
8 | - * Birthmark Service Provider Interface. | |
9 | - * | |
10 | - * @author Haruaki TAMADA | |
11 | - */ | |
12 | -public class UsedClassesBirthmarkExtractorService implements BirthmarkExtractorService{ | |
13 | - | |
14 | - /** | |
15 | - * returns a type of the birthmark this service provides. | |
16 | - */ | |
17 | - @Override | |
18 | - public String getType(){ | |
19 | - return "uc"; | |
20 | - } | |
21 | - | |
22 | - /** | |
23 | - * returns a extractor for the birthmark of this service. | |
24 | - */ | |
25 | - @Override | |
26 | - public BirthmarkExtractor getExtractor(BirthmarkService service){ | |
27 | - return new UsedClassesBirthmarkExtractor(service); | |
28 | - } | |
29 | - | |
30 | - @Override | |
31 | - public String getDescription(){ | |
32 | - return "Used classes birthmark"; | |
33 | - } | |
34 | -} | |
\ No newline at end of file |
@@ -1,53 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkComparator; | |
4 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
5 | -import jp.sourceforge.stigmata.BirthmarkPreprocessor; | |
6 | -import jp.sourceforge.stigmata.birthmarks.comparators.LogicalAndBirthmarkComparator; | |
7 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
8 | - | |
9 | -/** | |
10 | - * | |
11 | - * | |
12 | - * | |
13 | - * @author Haruaki TAMADA | |
14 | - */ | |
15 | -public class UsedClassesBirthmarkService implements BirthmarkService{ | |
16 | - private BirthmarkComparator comparator = new LogicalAndBirthmarkComparator(this); | |
17 | - private BirthmarkExtractor extractor = new UsedClassesBirthmarkExtractor(this); | |
18 | - | |
19 | - @Override | |
20 | - public String getType(){ | |
21 | - return "uc"; | |
22 | - } | |
23 | - | |
24 | - @Override | |
25 | - public String getDescription(){ | |
26 | - return "Used classes birthmark"; | |
27 | - } | |
28 | - | |
29 | - @Override | |
30 | - public BirthmarkExtractor getExtractor(){ | |
31 | - return extractor; | |
32 | - } | |
33 | - | |
34 | - @Override | |
35 | - public BirthmarkComparator getComparator(){ | |
36 | - return comparator; | |
37 | - } | |
38 | - | |
39 | - @Override | |
40 | - public boolean isExperimental(){ | |
41 | - return false; | |
42 | - } | |
43 | - | |
44 | - @Override | |
45 | - public boolean isUserDefined(){ | |
46 | - return false; | |
47 | - } | |
48 | - | |
49 | - @Override | |
50 | - public BirthmarkPreprocessor getPreprocessor(){ | |
51 | - return null; | |
52 | - } | |
53 | -} |
@@ -1,6 +0,0 @@ | ||
1 | -jp.sourceforge.stigmata.birthmarks.cvfv.ConstantValueOfFieldVariableBirthmarkExtractorService | |
2 | -jp.sourceforge.stigmata.birthmarks.is.InheritanceStructureBirthmarkExtractorService | |
3 | -jp.sourceforge.stigmata.birthmarks.smc.SequentialMethodCallBirthmarkExtractorService | |
4 | -jp.sourceforge.stigmata.birthmarks.uc.UsedClassesBirthmarkExtractorService | |
5 | -jp.sourceforge.stigmata.birthmarks.fmc.FrequencyMethodCallBirthmarkExtractorService | |
6 | -jp.sourceforge.stigmata.birthmarks.fuc.FrequencyUsedClassesBirthmarkExtractorService |
@@ -1,6 +0,0 @@ | ||
1 | -jp.sourceforge.stigmata.birthmarks.smc.SequentialMethodCallBirthmarkService | |
2 | -jp.sourceforge.stigmata.birthmarks.cvfv.ConstantValueOfFieldVariableBirthmarkService | |
3 | -jp.sourceforge.stigmata.birthmarks.is.InheritanceStructureBirthmarkService | |
4 | -jp.sourceforge.stigmata.birthmarks.uc.UsedClassesBirthmarkService | |
5 | -jp.sourceforge.stigmata.birthmarks.fmc.FrequencyMethodCallBirthmarkService | |
6 | -jp.sourceforge.stigmata.birthmarks.fuc.FrequencyUsedClassesBirthmarkService |
@@ -91,6 +91,22 @@ Related Publications | ||
91 | 91 | |
92 | 92 | *Dynamic Birthmark |
93 | 93 | |
94 | + * Patrick P.F. Chan, Lucas C.K. Hui, and S.M. Yiu, ``Dynamic software | |
95 | + birthmark for Java based on heap memory analysis,'' In Proc. 12th | |
96 | + IFIP TC 6/TC 11 International conference on Communications and | |
97 | + multimedia security, ser. CMS'11, pp.94--106, Springer-Verlag, 2011 | |
98 | + (Berlin, Heidelberg). | |
99 | + | |
100 | + * Patrick P.F. Chan, Lucas C.K. Hui, and S.M. Yiu, ``Jsbirth: Dynamic | |
101 | + javascript birthmark based on the run-time heap,'' In | |
102 | + Proc. Computer Software and Applications Conference (COMPSAC), 2011 | |
103 | + IEEE 35th Annual, pp.407--412, July 2011. | |
104 | + | |
105 | + * X. Wang, Y.C. Jhi, S. Zhu, and P. Liu, ``Behavior based software | |
106 | + theft detection,'' In Proc. the 16th ACM conference on Computer and | |
107 | + communications security, ser. CCS '09. pp.280--290, 2009. (New | |
108 | + York, NY, USA). | |
109 | + | |
94 | 110 | * David Schuler, Valentin Dallmeier, and Christian Lindig, ``A |
95 | 111 | Dynamic Birthmark for Java,'' In Proc. the 22nd IEEE/ACM |
96 | 112 | International Conference on Automated Software Engineering, |
@@ -133,6 +149,7 @@ Related Publications | ||
133 | 149 | Whole Program Path Birthmarks,'' In Proc. Information Security |
134 | 150 | Conference, September 27-29, 2004. |
135 | 151 | |
152 | + | |
136 | 153 | *Other Birthmark |
137 | 154 | |
138 | 155 | * Xiaoming Zhou, Xingming Sun, Guang Sun and Ying Yang, ``A Combined |
@@ -1,37 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata; | |
2 | - | |
3 | -import static org.junit.Assert.assertNotNull; | |
4 | - | |
5 | -import org.junit.Before; | |
6 | -import org.junit.Test; | |
7 | - | |
8 | -/** | |
9 | - * @author Haruaki Tamada | |
10 | - */ | |
11 | -public class ServiceListTest{ | |
12 | - private BirthmarkEnvironment env; | |
13 | - | |
14 | - @Before | |
15 | - public void setup() throws Exception{ | |
16 | - env = Stigmata.getInstance().createEnvironment(); | |
17 | - } | |
18 | - | |
19 | - @Test | |
20 | - public void testServiceList(){ | |
21 | - assertNotNull(env.getService("cvfv")); | |
22 | - assertNotNull(env.getService("fmc")); | |
23 | - assertNotNull(env.getService("fuc")); | |
24 | - assertNotNull(env.getService("is")); | |
25 | - assertNotNull(env.getService("smc")); | |
26 | - assertNotNull(env.getService("uc")); | |
27 | - assertNotNull(env.getService("cvfv_dp")); | |
28 | - assertNotNull(env.getService("cvfv_ed")); | |
29 | - assertNotNull(env.getService("is_dp")); | |
30 | - assertNotNull(env.getService("is_ed")); | |
31 | - assertNotNull(env.getService("smc_dp")); | |
32 | - assertNotNull(env.getService("smc_ed")); | |
33 | - assertNotNull(env.getService("uc_dp")); | |
34 | - assertNotNull(env.getService("uc_ed")); | |
35 | - assertNotNull(env.getService("uc_seq")); | |
36 | - } | |
37 | -} |
@@ -1,95 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.spi.BirthmarkService; | |
4 | - | |
5 | -import org.junit.Assert; | |
6 | -import org.junit.Before; | |
7 | -import org.junit.Test; | |
8 | - | |
9 | -/** | |
10 | - * test case. | |
11 | - * @author Haruaki TAMADA | |
12 | - */ | |
13 | -public class StigmataTest{ | |
14 | - private BirthmarkContext context; | |
15 | - private BirthmarkEnvironment environment; | |
16 | - | |
17 | - @Before | |
18 | - public void prepare(){ | |
19 | - Stigmata stigmata = Stigmata.getInstance(); | |
20 | - context = stigmata.createContext(); | |
21 | - environment = context.getEnvironment(); | |
22 | - } | |
23 | - | |
24 | - @Test | |
25 | - public void checkAvailableServices() throws Exception{ | |
26 | - Assert.assertNotNull(environment.getService("smc")); | |
27 | - Assert.assertNotNull(environment.getService("cvfv")); | |
28 | - Assert.assertNotNull(environment.getService("is")); | |
29 | - Assert.assertNotNull(environment.getService("uc")); | |
30 | - } | |
31 | - | |
32 | - @Test | |
33 | - public void checkSmcBirthmarkService() throws Exception{ | |
34 | - BirthmarkService service = environment.getService("smc"); | |
35 | - | |
36 | - Assert.assertNotNull(service.getComparator()); | |
37 | - Assert.assertNotNull(service.getExtractor()); | |
38 | - Assert.assertEquals( | |
39 | - "jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator", | |
40 | - service.getComparator().getClass().getName() | |
41 | - ); | |
42 | - Assert.assertEquals( | |
43 | - "jp.sourceforge.stigmata.birthmarks.smc.SequentialMethodCallBirthmarkExtractor", | |
44 | - service.getExtractor().getClass().getName() | |
45 | - ); | |
46 | - } | |
47 | - | |
48 | - @Test | |
49 | - public void checkCvfvBirthmarkService() throws Exception{ | |
50 | - BirthmarkService service = environment.getService("cvfv"); | |
51 | - | |
52 | - Assert.assertNotNull(service.getComparator()); | |
53 | - Assert.assertNotNull(service.getExtractor()); | |
54 | - Assert.assertEquals( | |
55 | - "jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator", | |
56 | - service.getComparator().getClass().getName() | |
57 | - ); | |
58 | - Assert.assertEquals( | |
59 | - "jp.sourceforge.stigmata.birthmarks.cvfv.ConstantValueOfFieldVariableBirthmarkExtractor", | |
60 | - service.getExtractor().getClass().getName() | |
61 | - ); | |
62 | - } | |
63 | - | |
64 | - @Test | |
65 | - public void checkIsBirthmarkService() throws Exception{ | |
66 | - BirthmarkService service = environment.getService("is"); | |
67 | - | |
68 | - Assert.assertNotNull(service.getComparator()); | |
69 | - Assert.assertNotNull(service.getExtractor()); | |
70 | - Assert.assertEquals( | |
71 | - "jp.sourceforge.stigmata.birthmarks.comparators.PlainBirthmarkComparator", | |
72 | - service.getComparator().getClass().getName() | |
73 | - ); | |
74 | - Assert.assertEquals( | |
75 | - "jp.sourceforge.stigmata.birthmarks.is.InheritanceStructureBirthmarkExtractor", | |
76 | - service.getExtractor().getClass().getName() | |
77 | - ); | |
78 | - } | |
79 | - | |
80 | - @Test | |
81 | - public void checkUcBirthmarkService() throws Exception{ | |
82 | - BirthmarkService service = environment.getService("uc"); | |
83 | - | |
84 | - Assert.assertNotNull(service.getComparator()); | |
85 | - Assert.assertNotNull(service.getExtractor()); | |
86 | - Assert.assertEquals( | |
87 | - "jp.sourceforge.stigmata.birthmarks.comparators.LogicalAndBirthmarkComparator", | |
88 | - service.getComparator().getClass().getName() | |
89 | - ); | |
90 | - Assert.assertEquals( | |
91 | - "jp.sourceforge.stigmata.birthmarks.uc.UsedClassesBirthmarkExtractor", | |
92 | - service.getExtractor().getClass().getName() | |
93 | - ); | |
94 | - } | |
95 | -} |
@@ -1,48 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.BirthmarkContext; | |
4 | -import jp.sourceforge.stigmata.BirthmarkEngine; | |
5 | -import jp.sourceforge.stigmata.BirthmarkSet; | |
6 | -import jp.sourceforge.stigmata.ExtractionResultSet; | |
7 | -import jp.sourceforge.stigmata.ExtractionTarget; | |
8 | -import jp.sourceforge.stigmata.Stigmata; | |
9 | - | |
10 | -import org.junit.Assert; | |
11 | -import org.junit.Before; | |
12 | -import org.junit.Test; | |
13 | - | |
14 | -/** | |
15 | - * | |
16 | - * @author Haruaki Tamada | |
17 | - */ | |
18 | -public class BirthmarkCompareTest{ | |
19 | - private BirthmarkContext context; | |
20 | - private BirthmarkSet[] birthmarks; | |
21 | - private BirthmarkEngine engine; | |
22 | - | |
23 | - @Before | |
24 | - public void readBirthmarks() throws Exception{ | |
25 | - context = Stigmata.getInstance().createContext(); | |
26 | - context.setBirthmarkTypes(new String[] { "cvfv", "smc", "uc", "is", }); | |
27 | - engine = new BirthmarkEngine(context.getEnvironment()); | |
28 | - | |
29 | - ExtractionResultSet ers = engine.extract( | |
30 | - new String[] { | |
31 | - "target/classes/jp/sourceforge/stigmata/Stigmata.class", | |
32 | - "target/classes/jp/sourceforge/stigmata/Main.class", | |
33 | - "target/classes/jp/sourceforge/stigmata/BirthmarkEnvironment.class", | |
34 | - }, context | |
35 | - ); | |
36 | - birthmarks = ers.getBirthmarkSets(ExtractionTarget.TARGET_BOTH); | |
37 | - } | |
38 | - | |
39 | - @Test | |
40 | - public void equalsTest() throws Exception{ | |
41 | - Assert.assertEquals(3, birthmarks.length); | |
42 | - BirthmarkEngine engine = Stigmata.getInstance().createEngine(); | |
43 | - | |
44 | - Assert.assertEquals(1d, engine.compareDetails(birthmarks[0], birthmarks[0], context).calculateSimilarity(), 1E-6); | |
45 | - Assert.assertEquals(1d, engine.compareDetails(birthmarks[1], birthmarks[1], context).calculateSimilarity(), 1E-6); | |
46 | - Assert.assertEquals(1d, engine.compareDetails(birthmarks[2], birthmarks[2], context).calculateSimilarity(), 1E-6); | |
47 | - } | |
48 | -} |
@@ -1,52 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.cvfv; | |
2 | - | |
3 | -import java.io.FileInputStream; | |
4 | - | |
5 | -import jp.sourceforge.stigmata.Birthmark; | |
6 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
7 | -import jp.sourceforge.stigmata.BirthmarkEnvironment; | |
8 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
9 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule; | |
10 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchPartType; | |
11 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchType; | |
12 | -import jp.sourceforge.stigmata.utils.WellknownClassManager; | |
13 | - | |
14 | -import org.junit.Assert; | |
15 | -import org.junit.Before; | |
16 | -import org.junit.Test; | |
17 | - | |
18 | -/** | |
19 | - * | |
20 | - * @author Haruaki TAMADA | |
21 | - */ | |
22 | -public class CVFVBirthmarkExtractorTest{ | |
23 | - private BirthmarkExtractor extractor; | |
24 | - | |
25 | - @Before | |
26 | - public void setup(){ | |
27 | - extractor = new ConstantValueOfFieldVariableBirthmarkService().getExtractor(); | |
28 | - BirthmarkEnvironment env = BirthmarkEnvironment.getDefaultEnvironment(); | |
29 | - WellknownClassManager manager = env.getWellknownClassManager(); | |
30 | - manager.add(new WellknownClassJudgeRule("java.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
31 | - manager.add(new WellknownClassJudgeRule("javax.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
32 | - } | |
33 | - | |
34 | - | |
35 | - @Test | |
36 | - public void checkBirthmark() throws Exception{ | |
37 | - Birthmark birthmark = extractor.extract(new FileInputStream("target/test-classes/resources/HelloWorldFrame.class")); | |
38 | - Assert.assertEquals("cvfv", birthmark.getType()); | |
39 | - | |
40 | - BirthmarkElement[] elements = birthmark.getElements(); | |
41 | - Assert.assertEquals(2, elements.length); | |
42 | - | |
43 | - Assert.assertTrue(elements[0] instanceof TypeAndValueBirthmarkElement); | |
44 | - Assert.assertTrue(elements[1] instanceof TypeAndValueBirthmarkElement); | |
45 | - | |
46 | - Assert.assertEquals("Ljava/lang/String;", ((TypeAndValueBirthmarkElement)elements[0]).getSignature()); | |
47 | - Assert.assertEquals("Ljava/lang/String;", ((TypeAndValueBirthmarkElement)elements[1]).getSignature()); | |
48 | - | |
49 | - Assert.assertEquals("Hello World", elements[0].getValue()); | |
50 | - Assert.assertEquals("Lucida Regular", elements[1].getValue()); | |
51 | - } | |
52 | -} |
@@ -1,46 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.is; | |
2 | - | |
3 | -import java.io.FileInputStream; | |
4 | - | |
5 | -import jp.sourceforge.stigmata.Birthmark; | |
6 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
7 | -import jp.sourceforge.stigmata.BirthmarkEnvironment; | |
8 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
9 | -import jp.sourceforge.stigmata.birthmarks.NullBirthmarkElement; | |
10 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule; | |
11 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchPartType; | |
12 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchType; | |
13 | -import jp.sourceforge.stigmata.utils.WellknownClassManager; | |
14 | - | |
15 | -import org.junit.Assert; | |
16 | -import org.junit.Before; | |
17 | -import org.junit.Test; | |
18 | - | |
19 | -/** | |
20 | - * | |
21 | - * @author Haruaki TAMADA | |
22 | - */ | |
23 | -public class InheritanceStructureBirthmarkExtractorTest{ | |
24 | - private BirthmarkExtractor extractor; | |
25 | - | |
26 | - @Before | |
27 | - public void setup(){ | |
28 | - extractor = new InheritanceStructureBirthmarkService().getExtractor(); | |
29 | - BirthmarkEnvironment env = BirthmarkEnvironment.getDefaultEnvironment(); | |
30 | - WellknownClassManager manager = env.getWellknownClassManager(); | |
31 | - manager.add(new WellknownClassJudgeRule("java.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
32 | - manager.add(new WellknownClassJudgeRule("javax.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
33 | - } | |
34 | - | |
35 | - @Test | |
36 | - public void checkBirthmark() throws Exception{ | |
37 | - Birthmark birthmark = extractor.extract(new FileInputStream("target/test-classes/resources/HelloWorldFrame.class")); | |
38 | - Assert.assertEquals("is", birthmark.getType()); | |
39 | - | |
40 | - BirthmarkElement[] elements = birthmark.getElements(); | |
41 | - Assert.assertEquals(2, elements.length); | |
42 | - | |
43 | - Assert.assertTrue(elements[0] instanceof NullBirthmarkElement); | |
44 | - Assert.assertEquals("java.lang.Object", elements[1].getValue()); | |
45 | - } | |
46 | -} |
@@ -1,56 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.smc; | |
2 | - | |
3 | -import java.io.FileInputStream; | |
4 | - | |
5 | -import jp.sourceforge.stigmata.Birthmark; | |
6 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
7 | -import jp.sourceforge.stigmata.BirthmarkEnvironment; | |
8 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
9 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule; | |
10 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchPartType; | |
11 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchType; | |
12 | -import jp.sourceforge.stigmata.utils.WellknownClassManager; | |
13 | - | |
14 | -import org.junit.Assert; | |
15 | -import org.junit.Before; | |
16 | -import org.junit.Test; | |
17 | - | |
18 | -/** | |
19 | - * | |
20 | - * @author Haruaki TAMADA | |
21 | - */ | |
22 | -public class SequentialMethodCallBirthmarkExtractorTest{ | |
23 | - private BirthmarkExtractor extractor; | |
24 | - | |
25 | - @Before | |
26 | - public void setup(){ | |
27 | - extractor = new SequentialMethodCallBirthmarkService().getExtractor(); | |
28 | - BirthmarkEnvironment env = BirthmarkEnvironment.getDefaultEnvironment(); | |
29 | - WellknownClassManager manager = env.getWellknownClassManager(); | |
30 | - manager.add(new WellknownClassJudgeRule("java.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
31 | - manager.add(new WellknownClassJudgeRule("javax.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
32 | - } | |
33 | - | |
34 | - | |
35 | - @Test | |
36 | - public void checkBirthmark() throws Exception{ | |
37 | - Birthmark birthmark = extractor.extract(new FileInputStream("target/test-classes/resources/HelloWorldFrame.class")); | |
38 | - Assert.assertEquals("smc", birthmark.getType()); | |
39 | - | |
40 | - BirthmarkElement[] elements = birthmark.getElements(); | |
41 | - Assert.assertEquals(10, elements.length); | |
42 | - | |
43 | - Assert.assertEquals("java.lang.Object#<init>!()V", elements[0].getValue()); | |
44 | - Assert.assertEquals("javax.swing.JFrame#<init>!()V", elements[1].getValue()); | |
45 | - Assert.assertEquals("javax.swing.JLabel#<init>!(Ljava/lang/String;)V", elements[2].getValue()); | |
46 | - Assert.assertEquals("java.awt.Font#<init>!(Ljava/lang/String;II)V", elements[3].getValue()); | |
47 | - Assert.assertEquals("javax.swing.JLabel#setFont!(Ljava/awt/Font;)V", elements[4].getValue()); | |
48 | - Assert.assertEquals("javax.swing.JFrame#setDefaultCloseOperation!(I)V", elements[5].getValue()); | |
49 | - Assert.assertEquals("javax.swing.JFrame#getContentPane!()Ljava/awt/Container;", | |
50 | - elements[6].getValue()); | |
51 | - Assert.assertEquals("java.awt.Container#add!(Ljava/awt/Component;Ljava/lang/Object;)V", | |
52 | - elements[7].getValue()); | |
53 | - Assert.assertEquals("javax.swing.JFrame#pack!()V", elements[8].getValue()); | |
54 | - Assert.assertEquals("javax.swing.JFrame#setVisible!(Z)V", elements[9].getValue()); | |
55 | - } | |
56 | -} |
@@ -1,50 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import java.io.FileInputStream; | |
4 | - | |
5 | -import jp.sourceforge.stigmata.Birthmark; | |
6 | -import jp.sourceforge.stigmata.BirthmarkElement; | |
7 | -import jp.sourceforge.stigmata.BirthmarkEnvironment; | |
8 | -import jp.sourceforge.stigmata.BirthmarkExtractor; | |
9 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule; | |
10 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchPartType; | |
11 | -import jp.sourceforge.stigmata.utils.WellknownClassJudgeRule.MatchType; | |
12 | -import jp.sourceforge.stigmata.utils.WellknownClassManager; | |
13 | - | |
14 | -import org.junit.Assert; | |
15 | -import org.junit.Before; | |
16 | -import org.junit.Test; | |
17 | - | |
18 | -/** | |
19 | - * | |
20 | - * @author Haruaki TAMADA | |
21 | - */ | |
22 | -public class UsedClassesBirthmarkExtractorTest{ | |
23 | - private BirthmarkExtractor extractor; | |
24 | - | |
25 | - @Before | |
26 | - public void setup(){ | |
27 | - extractor = new UsedClassesBirthmarkService().getExtractor(); | |
28 | - BirthmarkEnvironment env = BirthmarkEnvironment.getDefaultEnvironment(); | |
29 | - WellknownClassManager manager = env.getWellknownClassManager(); | |
30 | - manager.add(new WellknownClassJudgeRule("java.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
31 | - manager.add(new WellknownClassJudgeRule("javax.", MatchType.PREFIX, MatchPartType.FULLY_NAME)); | |
32 | - } | |
33 | - | |
34 | - @Test | |
35 | - public void checkBirthmark() throws Exception{ | |
36 | - Birthmark birthmark = extractor.extract(new FileInputStream("target/test-classes/resources/HelloWorldFrame.class")); | |
37 | - | |
38 | - Assert.assertEquals("uc", birthmark.getType()); | |
39 | - Assert.assertEquals(7, birthmark.getElementCount()); | |
40 | - | |
41 | - BirthmarkElement[] elements = birthmark.getElements(); | |
42 | - Assert.assertEquals("java.awt.Component", elements[0].getValue()); | |
43 | - Assert.assertEquals("java.awt.Container", elements[1].getValue()); | |
44 | - Assert.assertEquals("java.awt.Font", elements[2].getValue()); | |
45 | - Assert.assertEquals("java.lang.Object", elements[3].getValue()); | |
46 | - Assert.assertEquals("java.lang.String", elements[4].getValue()); | |
47 | - Assert.assertEquals("javax.swing.JFrame", elements[5].getValue()); | |
48 | - Assert.assertEquals("javax.swing.JLabel", elements[6].getValue()); | |
49 | - } | |
50 | -} |
@@ -1,27 +0,0 @@ | ||
1 | -package jp.sourceforge.stigmata.birthmarks.uc; | |
2 | - | |
3 | -import jp.sourceforge.stigmata.birthmarks.comparators.LogicalAndBirthmarkComparator; | |
4 | -import junit.framework.Assert; | |
5 | - | |
6 | -import org.junit.Before; | |
7 | -import org.junit.Test; | |
8 | - | |
9 | -public class UsedClassesBirthmarkServiceTest{ | |
10 | - private UsedClassesBirthmarkService service; | |
11 | - | |
12 | - @Before | |
13 | - public void setUp(){ | |
14 | - service = new UsedClassesBirthmarkService(); | |
15 | - } | |
16 | - | |
17 | - @Test | |
18 | - public void testBasic(){ | |
19 | - Assert.assertEquals("uc", service.getType()); | |
20 | - Assert.assertEquals("Used classes birthmark", service.getDescription()); | |
21 | - Assert.assertFalse(service.isExperimental()); | |
22 | - Assert.assertFalse(service.isUserDefined()); | |
23 | - Assert.assertEquals(UsedClassesBirthmarkExtractor.class, service.getExtractor().getClass()); | |
24 | - Assert.assertEquals(LogicalAndBirthmarkComparator.class, service.getComparator().getClass()); | |
25 | - Assert.assertNull(service.getPreprocessor()); | |
26 | - } | |
27 | -} |
@@ -1,25 +0,0 @@ | ||
1 | -import java.awt.BorderLayout; | |
2 | -import java.awt.Font; | |
3 | - | |
4 | -import javax.swing.JFrame; | |
5 | -import javax.swing.JLabel; | |
6 | - | |
7 | - | |
8 | -public class HelloWorldFrame{ | |
9 | - private String message = "Hello World"; | |
10 | - private String fontName = "Lucida Regular"; | |
11 | - | |
12 | - public HelloWorldFrame(){ | |
13 | - JFrame frame = new JFrame(); | |
14 | - JLabel label = new JLabel(message); | |
15 | - label.setFont(new Font(fontName, Font.BOLD, 72)); | |
16 | - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
17 | - frame.getContentPane().add(label, BorderLayout.CENTER); | |
18 | - frame.pack(); | |
19 | - frame.setVisible(true); | |
20 | - } | |
21 | - | |
22 | - public static void main(String[] args){ | |
23 | - new HelloWorldFrame(); | |
24 | - } | |
25 | -} | |
\ No newline at end of file |