import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
break;
case ROUND_ROBIN_XY:
crs = new RoundRobinComparisonResultSet(er, true);
+ break;
case GUESSED_PAIR:
crs = new CertainPairComparisonResultSet(er);
break;
}
}
- public BirthmarkContext prepare(String[] targetX, String[] targetY, BirthmarkContext context) throws MalformedURLException, IOException{
+ public synchronized BirthmarkContext prepare(String[] targetX, String[] targetY, BirthmarkContext context) throws MalformedURLException, IOException{
StigmataHookManager.getInstance().runHook(Phase.BEFORE_PREPROCESS, context);
Set<String> set = new HashSet<String>();
return context;
}
- private String[] mergeTarget(String[] t1, String[] t2){
+ private synchronized String[] mergeTarget(String[] t1, String[] t2){
List<String> list = new ArrayList<String>();
addToList(list, t1);
addToList(list, t2);
return list.toArray(new String[list.size()]);
}
- private void addToList(List<String> list, String[] target){
+ private synchronized void addToList(List<String> list, String[] target){
if(target != null){
for(String s: target){
list.add(s);
}
}
- private BirthmarkSet[] extractImpl(String[] target, ExtractionResultSet er, ExtractionTarget et) throws BirthmarkExtractionFailedException, IOException, BirthmarkStoreException{
+ private synchronized BirthmarkSet[] extractImpl(String[] target, ExtractionResultSet er, ExtractionTarget et) throws BirthmarkExtractionFailedException, IOException, BirthmarkStoreException{
ClassFileArchive[] archives = createArchives(target, environment);
BirthmarkContext context = er.getContext();
ExtractionUnit unit = context.getExtractionUnit();
return extractResult;
}
- private byte[] inputStreamToByteArray(InputStream in) throws IOException{
+ private synchronized byte[] inputStreamToByteArray(InputStream in) throws IOException{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int read;
byte[] dataBuffer = new byte[512];
return data;
}
- private void extractFromPackage(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException{
+ private synchronized void extractFromPackage(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException{
Map<String, BirthmarkSet> map = new HashMap<String, BirthmarkSet>();
BirthmarkContext context = er.getContext();
String packageName = parsePackageName(name);
BirthmarkSet bs = map.get(packageName);
if(bs == null){
- bs = new BirthmarkSet(packageName, archive.getLocation());
+ bs = new BirthmarkSet(packageName, archive.getLocation().toURI());
map.put(packageName, bs);
}
}
} catch(IOException e){
warnings.addMessage(e, archive.getName());
+ } catch(URISyntaxException e){
+ warnings.addMessage(e, archive.getLocation().toString());
}
}
}
}
}
- private String parsePackageName(String name){
+ private synchronized String parsePackageName(String name){
String n = name.replace('/', '.');
int index = n.lastIndexOf('.');
if(index > 0){
return n;
}
- private void extractFromClass(ClassFileArchive[] archives, ExtractionResultSet er,
+ private synchronized void extractFromClass(ClassFileArchive[] archives, ExtractionResultSet er,
ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
BirthmarkContext context = er.getContext();
for(ClassFileArchive archive: archives){
for(ClassFileEntry entry: archive){
try{
- BirthmarkSet birthmarkset = new BirthmarkSet(entry.getClassName(), entry.getLocation());
+ BirthmarkSet birthmarkset = new BirthmarkSet(entry.getClassName(), entry.getLocation().toURI());
byte[] data = inputStreamToByteArray(entry.getLocation().openStream());
for(String birthmarkType: context.getBirthmarkTypes()){
er.addBirthmarkSet(et, birthmarkset);
} catch(IOException e){
warnings.addMessage(e, entry.getClassName());
+ } catch(URISyntaxException e){
+ warnings.addMessage(e, entry.getLocation().toString());
}
}
}
}
- private void extractFromProduct(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
+ private synchronized void extractFromProduct(ClassFileArchive[] archives, ExtractionResultSet er, ExtractionTarget et) throws IOException, BirthmarkExtractionFailedException, BirthmarkStoreException{
BirthmarkContext context = er.getContext();
for(ClassFileArchive archive: archives){
- BirthmarkSet birthmarkset = new BirthmarkSet(archive.getName(), archive.getLocation());
+ BirthmarkSet birthmarkset = null;
+ try{
+ birthmarkset = new BirthmarkSet(archive.getName(), archive.getLocation().toURI());
+ } catch(URISyntaxException e){
+ warnings.addMessage(e, archive.getLocation().toString());
+ }
+ if(birthmarkset == null){
+ return;
+ }
for(ClassFileEntry entry: archive){
try{
}
}
- private ClassFileArchive[] createArchives(String[] files, BirthmarkEnvironment environment) throws IOException, MalformedURLException{
+ private synchronized ClassFileArchive[] createArchives(String[] files, BirthmarkEnvironment environment) throws IOException, MalformedURLException{
ClasspathContext bytecode = environment.getClasspathContext();
List<ClassFileArchive> archives = new ArrayList<ClassFileArchive>();
for(int i = 0; i < files.length; i++){
package jp.sourceforge.stigmata;
-import java.net.URL;
+import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* location of target is loaded from.
*/
- private URL location;
+ private URI location;
/**
* map for birthmarks.
/**
* constructor.
*/
- public BirthmarkSet(String name, URL location){
+ public BirthmarkSet(String name, URI location){
this.name = name;
this.location = location;
}
/**
* return the location.
*/
- public URL getLocation(){
+ public URI getLocation(){
return location;
}
package jp.sourceforge.stigmata;
+import java.io.Serializable;
import java.util.Comparator;
import jp.sourceforge.stigmata.spi.BirthmarkService;
/**
* @author Haruaki TAMADA
*/
-class BirthmarkSpiComparator implements Comparator<BirthmarkService>{
+class BirthmarkSpiComparator implements Comparator<BirthmarkService>, Serializable{
+ private static final long serialVersionUID = 8194452116506240274L;
+
/**
* default constructor
*/
private static final Map<String, BirthmarkStoreTarget> TARGETS = new HashMap<String, BirthmarkStoreTarget>();
- public static BirthmarkStoreTarget MEMORY = new BirthmarkStoreTarget(0, "MEMORY");
- public static BirthmarkStoreTarget XMLFILE = new BirthmarkStoreTarget(1, "XMLFILE");
- public static BirthmarkStoreTarget MEMORY_SINGLE = new BirthmarkStoreTarget(2, "MEMORY_SINGLE");
- public static BirthmarkStoreTarget RDB = new BirthmarkStoreTarget(3, "RDB");
+ public static final BirthmarkStoreTarget MEMORY = new BirthmarkStoreTarget(0, "MEMORY");
+ public static final BirthmarkStoreTarget XMLFILE = new BirthmarkStoreTarget(1, "XMLFILE");
+ public static final BirthmarkStoreTarget MEMORY_SINGLE = new BirthmarkStoreTarget(2, "MEMORY_SINGLE");
+ public static final BirthmarkStoreTarget RDB = new BirthmarkStoreTarget(3, "RDB");
private final String name;
private final int ordinal;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
BirthmarkEnvironment.resetSettings();
}
}
- initConfiguration(target);
+ try{
+ initConfiguration(target);
+ } finally{
+ if(target != null){
+ try{
+ target.close();
+ } catch(IOException e){
+ }
+ }
+ }
}
private void initConfiguration(InputStream in){
File file = new File(parent, fileName);
if(!file.exists()){
ConfigFileExporter exporter = new ConfigFileExporter(defaultEnvironment);
- exporter.export(new PrintWriter(new FileWriter(file)));
+ String encoding = defaultEnvironment.getProperty("encoding.config");
+ if(encoding == null){
+ encoding = defaultEnvironment.getProperty("encoding");
+ }
+ if(encoding == null){
+ encoding = "utf-8";
+ }
+ exporter.export(new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)));
}
} catch(IOException e){
e.printStackTrace();
@Override
public boolean equals(Object o){
- return o instanceof NullBirthmarkElement;
+ boolean flag = o != null && o.getClass().equals(getClass());
+ flag = flag && this == o;
+
+ return flag;
}
@Override
}
}
- private class CountPair{
+ private static final class CountPair{
private int c1 = 0;
private int c2 = 0;
public int get(boolean first){
+ int value = c2;
if(first){
- return c1;
- }
- else{
- return c2;
+ value = c1;
}
+ return value;
}
public void set(boolean first, int count){
@Override
public void visitIntInsn(int opcode, int operand){
if(opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH){
- constant = new Integer(operand);
+ constant = Integer.valueOf(operand);
}
super.visitIntInsn(opcode, operand);
}
@Override
public void visitInsn(int opcode){
- if(opcode == Opcodes.ICONST_M1) constant = new Integer(-1);
- else if(opcode == Opcodes.ICONST_0) constant = new Integer(0);
- else if(opcode == Opcodes.ICONST_1) constant = new Integer(1);
- else if(opcode == Opcodes.ICONST_2) constant = new Integer(2);
- else if(opcode == Opcodes.ICONST_3) constant = new Integer(3);
- else if(opcode == Opcodes.ICONST_4) constant = new Integer(4);
- else if(opcode == Opcodes.ICONST_5) constant = new Integer(5);
- else if(opcode == Opcodes.LCONST_0) constant = new Long(0L);
- else if(opcode == Opcodes.LCONST_1) constant = new Long(1L);
- else if(opcode == Opcodes.DCONST_0) constant = new Double(0D);
- else if(opcode == Opcodes.DCONST_1) constant = new Double(1D);
- else if(opcode == Opcodes.FCONST_0) constant = new Float(0F);
- else if(opcode == Opcodes.FCONST_1) constant = new Float(1F);
- else if(opcode == Opcodes.FCONST_2) constant = new Float(2F);
+ if(opcode == Opcodes.ICONST_M1) constant = Integer.valueOf(-1);
+ else if(opcode == Opcodes.ICONST_0) constant = Integer.valueOf(0);
+ else if(opcode == Opcodes.ICONST_1) constant = Integer.valueOf(1);
+ else if(opcode == Opcodes.ICONST_2) constant = Integer.valueOf(2);
+ else if(opcode == Opcodes.ICONST_3) constant = Integer.valueOf(3);
+ else if(opcode == Opcodes.ICONST_4) constant = Integer.valueOf(4);
+ else if(opcode == Opcodes.ICONST_5) constant = Integer.valueOf(5);
+ else if(opcode == Opcodes.LCONST_0) constant = Long.valueOf(0L);
+ else if(opcode == Opcodes.LCONST_1) constant = Long.valueOf(1L);
+ else if(opcode == Opcodes.DCONST_0) constant = Double.valueOf(0D);
+ else if(opcode == Opcodes.DCONST_1) constant = Double.valueOf(1D);
+ else if(opcode == Opcodes.FCONST_0) constant = Float.valueOf(0F);
+ else if(opcode == Opcodes.FCONST_1) constant = Float.valueOf(1F);
+ else if(opcode == Opcodes.FCONST_2) constant = Float.valueOf(2F);
super.visitInsn(opcode);
}
else elementValue = Boolean.FALSE;
break;
}
- case 'C': elementValue = new Character(subValue.charAt(0)); break;
- case 'D': elementValue = new Double(subValue); break;
- case 'F': elementValue = new Float(subValue); break;
- case 'S': elementValue = new Short(subValue); break;
- case 'B': elementValue = new Byte(subValue); break;
- case 'I': elementValue = new Integer(subValue); break;
- default: elementValue = value; break;
+ case 'C': elementValue = subValue.charAt(0); break;
+ case 'D': elementValue = subValue; break;
+ case 'F': elementValue = subValue; break;
+ case 'S': elementValue = subValue; break;
+ case 'B': elementValue = subValue; break;
+ case 'I': elementValue = subValue; break;
+ default: elementValue = value; break;
}
}
return new TypeAndValueBirthmarkElement(signature, elementValue);
if(signature.length() == 1 && value == null){
switch(signature.charAt(0)){
case 'Z': value = Boolean.FALSE; break;
- case 'D': value = new Double(0d); break;
- case 'F': value = new Float(0f); break;
+ case 'D': value = Double.valueOf(0d); break;
+ case 'F': value = Float.valueOf(0f); break;
case 'C':
case 'S':
case 'B':
case 'I':
- default: value = new Integer(0); break;
+ default: value = Integer.valueOf(0); break;
}
}
@Override
public boolean equals(Object o){
- if(o instanceof TypeAndValueBirthmarkElement){
- TypeAndValueBirthmarkElement tvbe = (TypeAndValueBirthmarkElement)o;
+ boolean flag = false;
+ if(o != null){
+ String className = o.getClass().getName();
+ if(className.equals(TypeAndValueBirthmarkElement.class.getName())){
+ TypeAndValueBirthmarkElement tvbe = (TypeAndValueBirthmarkElement)o;
- if(getSignature().equals(tvbe.getSignature())){
- if(getValue() == null && tvbe.getValue() == null){
- return true;
- }
- else if(getValue() != null && tvbe.getValue() != null){
- return getValue().equals(tvbe.getValue());
+ if(getSignature().equals(tvbe.getSignature())){
+ if(getValue() == null && tvbe.getValue() == null){
+ flag = true;
+ }
+ else if(getValue() != null && tvbe.getValue() != null){
+ flag = getValue().equals(tvbe.getValue());
+ }
}
}
}
- return false;
+ return flag;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
@Override
public boolean equals(Object o){
boolean flag = false;
- if(o instanceof MethodCallBirthmarkElement){
- MethodCallBirthmarkElement mcbe = (MethodCallBirthmarkElement)o;
+ if(o != null){
+ String className = o.getClass().getName();
+ if(className.equals(MethodCallBirthmarkElement.class.getName())){
+ MethodCallBirthmarkElement mcbe = (MethodCallBirthmarkElement)o;
- flag = getClassName().equals(mcbe.getClassName()) &&
- getMethodName().equals(mcbe.getMethodName()) &&
- getSignature().equals(mcbe.getSignature());
+ flag = getClassName().equals(mcbe.getClassName()) &&
+ getMethodName().equals(mcbe.getMethodName()) &&
+ getSignature().equals(mcbe.getSignature());
+ }
}
return flag;
import java.util.ArrayList;
import java.util.List;
+import jp.sourceforge.stigmata.BirthmarkContext;
import jp.sourceforge.stigmata.BirthmarkEnvironment;
import jp.sourceforge.stigmata.Stigmata;
import jp.sourceforge.stigmata.StigmataCommand;
public void tearDown(BirthmarkEnvironment env){
StigmataHookManager.getInstance().runHook(Phase.TEAR_DOWN, env);
}
+
+ public String getProperty(BirthmarkEnvironment env, String[] keys, String defaultValue){
+ String value = null;
+ for(String key: keys){
+ if(value != null){
+ break;
+ }
+ value = env.getProperty(key);
+ }
+ if(value == null){
+ value = defaultValue;
+ }
+ return value;
+ }
+
+ public String getProperty(BirthmarkContext context, String[] keys, String defaultValue){
+ String value = null;
+ for(String key: keys){
+ if(value != null){
+ break;
+ }
+ value = (String)context.getProperty(key);
+ }
+ value = getProperty(context.getEnvironment(), keys, defaultValue);
+
+ return value;
+ }
}
package jp.sourceforge.stigmata.command;
import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
import java.util.Iterator;
import jp.sourceforge.stigmata.BirthmarkContext;
ResultPrinterService spi = stigmata.getPrinterManager().getService(context.getFormat());
ComparisonResultSetPrinter formatter = spi.getComparisonResultSetPrinter();
- formatter.printResult(new PrintWriter(System.out), resultset);
+ String encoding = getProperty(context, new String[] { "encoding.output", "encoding" }, "utf-8");
+ formatter.printResult(new PrintWriter(new OutputStreamWriter(System.out, encoding)), resultset);
}catch(Exception e){
e.printStackTrace();
}
package jp.sourceforge.stigmata.command;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
import jp.sourceforge.stigmata.BirthmarkContext;
import jp.sourceforge.stigmata.Stigmata;
public boolean perform(Stigmata stigmata, BirthmarkContext context, String[] args){
PrintWriter out = null;
try{
+ String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
if(args == null || args.length == 0){
- out = new PrintWriter(System.out);
+ out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
}
else{
if(!args[0].endsWith(".xml")){
args[0] = args[0] + ".xml";
}
- out = new PrintWriter(new FileWriter(args[0]));
+ out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(args[0]), encoding));
}
new ConfigFileExporter(context.getEnvironment()).export(out);
package jp.sourceforge.stigmata.command;
import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
import java.util.Iterator;
import jp.sourceforge.stigmata.BirthmarkContext;
ResultPrinterService spi = stigmata.getPrinterManager().getService(context.getFormat());
ExtractionResultSetPrinter formatter = spi.getExtractionResultSetPrinter();
- formatter.printResult(new PrintWriter(System.out), ers);
+ String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
+ formatter.printResult(new PrintWriter(new OutputStreamWriter(System.out, encoding)), ers);
}catch(Exception ex){
ex.printStackTrace();
}
private void copyFile(File source, File dest){
byte[] data = new byte[256];
int read;
+ InputStream in = null;
+ OutputStream out = null;
try{
- InputStream in = new FileInputStream(source);
- OutputStream out = new FileOutputStream(dest);
+ in = new FileInputStream(source);
+ out = new FileOutputStream(dest);
while((read = in.read(data)) != -1){
out.write(data, 0, read);
in.close();
out.close();
} catch(IOException e){
+ } finally{
+ String message = null;
+ if(in != null){
+ try{
+ in.close();
+ } catch(IOException e){
+ message = e.getMessage();
+ }
+ }
+ if(out != null){
+ try{
+ out.close();
+ } catch(IOException e){
+ if(message != null){
+ message += ", " + e.getMessage();
+ }
+ else{
+ message = e.getMessage();
+ }
+ }
+ }
+ if(message != null){
+ throw new InternalError(message);
+ }
}
}
}
BufferedReader reader = null;
try{
InputStream in = getClass().getResourceAsStream("/META-INF/license.txt");
- reader = new BufferedReader(new InputStreamReader(in));
+ reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
String line;
while((line = reader.readLine()) != null){
try{
reader.close();
} catch(IOException e){
+ throw new InternalError(e.getMessage());
}
}
}
package jp.sourceforge.stigmata.command;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import jp.sourceforge.stigmata.BirthmarkContext;
try{
PrintWriter out;
+ String encoding = getProperty(context, new String[] { "encoding.output", "encoding", }, "utf-8");
if(args.length == 0){
- out = new PrintWriter(System.out);
+ out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
}
else{
String target = validateTarget(args[0], context.getFormat());
- out = new PrintWriter(new FileWriter(target));
+ out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(target), encoding));
}
formatter.printResult(out, spis);
}catch(IOException e){
package jp.sourceforge.stigmata.command;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
for(int i = 0; i < args.length; i++){
BirthmarkService service = env.getService(args[i]);
- if(service instanceof BirthmarkService){
- env.removeService(args[i]);
- removeServiceInConfigFile = true;
- }
- else{
- String fileName = getPluginFileNameOfService(context, service);
- if(fileName != null){
- File pluginFile = new File(pluginsDir, fileName);
- pluginFile.renameTo(new File(pluginFile.getParentFile(), pluginFile.getName() + ".back"));
- }
+ env.removeService(args[i]);
+ removeServiceInConfigFile = true;
+
+ String fileName = getPluginFileNameOfService(context, service);
+ if(fileName != null){
+ File pluginFile = new File(pluginsDir, fileName);
+ pluginFile.renameTo(new File(pluginFile.getParentFile(), pluginFile.getName() + ".back"));
}
}
if(removeServiceInConfigFile){
private void updateConfigFile(BirthmarkEnvironment env){
File configFile = new File(BirthmarkEnvironment.getStigmataHome(), "stigmata.xml");
try{
- new ConfigFileExporter(env).export(new PrintWriter(new FileWriter(configFile)));
+ String encoding = getProperty(env, new String[] { "encoding.output", "encoding", }, "utf-8");
+ new ConfigFileExporter(env).export(
+ new PrintWriter(new OutputStreamWriter(new FileOutputStream(configFile), encoding))
+ );
} catch(IOException e){
e.printStackTrace();
}
package jp.sourceforge.stigmata.event;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
*
* @author Haruaki Tamada
*/
-public class WarningMessages{
+public class WarningMessages implements Serializable{
+ private static final long serialVersionUID = -2305021456005540192L;
+
private OperationType type;
private Map<Exception, String> messages = new HashMap<Exception, String>();
package jp.sourceforge.stigmata.filter;
+import java.util.Arrays;
+
import jp.sourceforge.stigmata.ComparisonPairFilter;
import jp.sourceforge.stigmata.spi.ComparisonPairFilterService;
@Override
public void setCriterion(Criterion criterion){
if(!isAcceptable(criterion)){
- throw new IllegalArgumentException("illegal criterion: "
- + criterion + ": accepts only " + getAcceptableCriteria());
+ throw new IllegalArgumentException(
+ "illegal criterion: " + criterion +
+ ": accepts only " + Arrays.toString(getAcceptableCriteria())
+ );
}
this.criterion = criterion;
}
switch(getTarget()){
case TARGET_1: sb.append("target1"); break;
case TARGET_2: sb.append("target2"); break;
- case BOTH_TARGETS: sb.append("(target1&target2)"); break;
- case ONE_OF_TARGETS: sb.append("(target1|target2)");
+ case BOTH_TARGETS: sb.append("(target1&target2)"); break;
+ case ONE_OF_TARGETS: sb.append("(target1|target2)"); break;
+ default:
}
sb.append(".").append(birthmarkType);
sb.append(".size");
case LESS_THAN: sb.append(" < "); break;
case EQUALS_AS: sb.append(" == "); break;
case NOT_EQUALS_AS: sb.append(" != "); break;
+ default:
}
sb.append(Integer.toString(getThreshold()));
case LESS_THAN: sb.append(" < "); break;
case EQUALS_AS: sb.append(" == "); break;
case NOT_EQUALS_AS: sb.append(" != "); break;
+ default:
}
sb.append(getThreshold());
return new String(sb);
case TARGET_1: sb.append("target1.name"); break;
case TARGET_2: sb.append("target2.name"); break;
case BOTH_TARGETS: sb.append("(target1&target2).name"); break;
- case ONE_OF_TARGETS: sb.append("(target1|target2).name"); break;
+ case ONE_OF_TARGETS: sb.append("(target1|target2).name"); break;
+ default:
}
switch(getCriterion()){
case STARTS_WITH: sb.append(" starts with "); break;
case NOT_ENDS_WITH: sb.append(" not ends with "); break;
case EQUALS_AS: sb.append(" equals as "); break;
case NOT_EQUALS_AS: sb.append(" not equals as "); break;
+ default:
}
sb.append(getValue());
case TARGET_2: sb.append("target2"); break;
case BOTH_TARGETS: sb.append("(target1&target2)"); break;
case ONE_OF_TARGETS: sb.append("(target1|target2)"); break;
+ default:
}
sb.append(".element");
switch(getCriterion()){
case LESS_THAN: sb.append(" < "); break;
case EQUALS_AS: sb.append(" == "); break;
case NOT_EQUALS_AS: sb.append(" != "); break;
+ default:
}
sb.append(Integer.toString(getThreshold()));
package jp.sourceforge.stigmata.result;
-import java.net.URL;
+import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
}
private Collection<BirthmarkSet> createSources(){
- Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+ Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
for(Iterator<ComparisonPair> i = iterator(); i.hasNext(); ){
ComparisonPair pair = i.next();
addToMap(map, pair.getTarget1());
return map.values();
}
- private void addToMap(Map<URL, BirthmarkSet> map, BirthmarkSet set){
+ private void addToMap(Map<URI, BirthmarkSet> map, BirthmarkSet set){
map.put(set.getLocation(), set);
}
package jp.sourceforge.stigmata.result;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@Override
public Object handle(ResultSet rs) throws SQLException{
- Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+ Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
while(rs.next()){
try{
String name = rs.getString("NAME");
String location = rs.getString("LOCATION");
- URL url = new URL(location);
- BirthmarkSet bs = map.get(url);
+ URI uri = new URI(location);
+ BirthmarkSet bs = map.get(uri);
if(bs == null){
- bs = new BirthmarkSet(name, url);
- map.put(url, bs);
+ bs = new BirthmarkSet(name, uri);
+ map.put(uri, bs);
}
String type = rs.getString("TYPE");
}
String element = rs.getString("ELEMENT");
birthmark.addElement(env.getService(type).getExtractor().buildElement(element));
-
- } catch(MalformedURLException e){
+ } catch(URISyntaxException e){
}
}
return map.values().toArray(new BirthmarkSet[map.size()]);
package jp.sourceforge.stigmata.result;
-import java.net.URL;
+import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@Override
public Iterator<BirthmarkSet> pairSources(){
- Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+ Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
if(extraction.isTableType()){
for(Iterator<BirthmarkSet> i = extraction.birthmarkSets(ExtractionTarget.TARGET_X); i.hasNext(); ){
BirthmarkSet bs = i.next();
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
private static class BirthmarkSetStAXIterator implements Iterator<BirthmarkSet>{
private XMLEventReader reader = null;
private BirthmarkSet nextObject;
- private List<URL> validItems;
+ private List<URI> validItems;
private BirthmarkEnvironment env;
private BirthmarkContext context;
- public BirthmarkSetStAXIterator(File file, List<URL> validItems, BirthmarkContext context){
+ public BirthmarkSetStAXIterator(File file, List<URI> validItems, BirthmarkContext context){
try{
XMLInputFactory factory = XMLInputFactory.newInstance();
- BufferedReader in = new BufferedReader(new FileReader(file));
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
reader = factory.createXMLEventReader(in);
} catch(FileNotFoundException e){
+ } catch(UnsupportedEncodingException e){
} catch(XMLStreamException e){
}
this.validItems = validItems;
throw new XMLStreamException("incompatible with definition");
}
try{
- URL url = new URL(location);
- bs = new BirthmarkSet(className, url);
- } catch(MalformedURLException e){
+ URI uri = new URI(location);
+ bs = new BirthmarkSet(className, uri);
+ } catch(URISyntaxException e){
e.printStackTrace();
}
}
private static class XmlFile{
private ExtractionResultSetXmlPrinter formatter;
private BirthmarkContext context;
- private List<URL> addList = new ArrayList<URL>();
+ private List<URI> addList = new ArrayList<URI>();
private int size;
private File file;
private PrintWriter out;
public void addBirthmarkSet(BirthmarkSet bs) throws BirthmarkStoreException{
if(formatter == null){
try{
- out = new PrintWriter(new FileWriter(file));
+ out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
formatter = new ExtractionResultSetXmlPrinter();
formatter.printHeader(out);
out.printf(" <unit>%s</unit>%n", context.getExtractionUnit());
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
private void addValuesFromSystemFile(Set<String> values){
File file = new File(BirthmarkEnvironment.getStigmataHome(), "storelocations.txt");
if(file.exists()){
+ BufferedReader in = null;
try{
- BufferedReader in = new BufferedReader(new FileReader(file));
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
String line;
while((line = in.readLine()) != null){
values.add(line);
}
} catch(IOException e){
+ } finally{
+ try{
+ if(in != null){
+ in.close();
+ }
+ } catch(IOException e){
+ throw new InternalError(e.getMessage());
+ }
}
}
}
* @author Haruaki TAMADA
*/
public abstract class BirthmarkSelectablePane extends JPanel implements BirthmarkServiceListener{
- private static final long serialVersionUID = 7057130952947891635L;
+ private static final long serialVersionUID = 7057130952947891635L;
- private StigmataFrame stigmata;
+ private StigmataFrame stigmata;
private Set<String> selectedServices = new HashSet<String>();
private Map<String, BirthmarkSelection> services;
private List<DataChangeListener> listeners = new ArrayList<DataChangeListener>();
@Override
public void serviceRemoved(BirthmarkService service){
- BirthmarkSelection elem = services.get(service);
+ BirthmarkSelection elem = services.get(service.getType());
if(elem != null){
- selectedServices.remove(service);
- services.remove(service);
+ selectedServices.remove(service.getType());
+ services.remove(service.getType());
}
fireEvent();
}
package jp.sourceforge.stigmata.ui.swing;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
public void outputNameMappings(File file) throws IOException{
PrintWriter out = null;
try{
- out = new PrintWriter(new FileWriter(file));
+ out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
for(String oldName: nameMapping.keySet()){
String newName = nameMapping.get(oldName);
out.print(oldName);
public BirthmarkSet obfuscateClassName(BirthmarkSet orig){
String newName = nameMapping.get(orig.getName());
if(newName == null){
- newName = String.format("C%04d", new Object[] { new Integer(nameMapping.size() + 1), });
+ newName = String.format("C%04d", new Object[] { nameMapping.size() + 1, });
nameMapping.put(orig.getName(), newName);
}
right.setText(String.valueOf(item.getRight()));
}
- if(item.getIcon() != null){
+ if(item != null && item.getIcon() != null){
left.setIcon(item.getIcon());
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
BirthmarkEnvironment environment = generateEnvironment();
ConfigFileExporter bce = new ConfigFileExporter(environment);
try{
- PrintWriter out = new PrintWriter(new FileWriter(file));
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
bce.export(out);
out.close();
} catch(IOException e){
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
-import java.net.URL;
+import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
}
private void mdsButtonActionPerformed(ActionEvent e){
- Map<URL, BirthmarkSet> map = new HashMap<URL, BirthmarkSet>();
+ Map<URI, BirthmarkSet> map = new HashMap<URI, BirthmarkSet>();
for(Iterator<BirthmarkSet> i = extraction.birthmarkSets(ExtractionTarget.TARGET_X); i.hasNext(); ){
BirthmarkSet bs = i.next();
map.put(bs.getLocation(), bs);
}
int index = 0;
BirthmarkSet[] set = new BirthmarkSet[map.size()];
- for(Map.Entry<URL, BirthmarkSet> entry: map.entrySet()){
+ for(Map.Entry<URI, BirthmarkSet> entry: map.entrySet()){
set[index] = entry.getValue();
index++;
}
for(int j = 1; j < table.getColumnCount(); j++){
Double d = (Double)table.getValueAt(i, j);
int similarity = (int)Math.round(d.doubleValue() * 100);
- Integer dist = values.get(new Integer(similarity));
+ Integer dist = values.get(similarity);
if(dist == null){
- dist = new Integer(0);
+ dist = 0;
}
- dist = new Integer(dist.intValue() + 1);
- values.put(new Integer(similarity), dist);
+ dist = dist.intValue() + 1;
+ values.put(similarity, dist);
}
}
stigmata.showSimilarityDistributionGraph(values);
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.swing.ButtonGroup;
int compareDetail = getNextCount("compare_detail");
GUIUtility.addNewTab(getMessages(), "comparedetail", tabPane, detail,
- new Object[] { new Integer(compareDetail), },
+ new Object[] { Integer.valueOf(compareDetail), },
new Object[] {
Utility.array2String(target1.getBirthmarkTypes()),
target1.getName(),
int compareCount = getNextCount("compare");
GUIUtility.addNewTab(
getMessages(), "compare", tabPane, compare,
- new Object[] { new Integer(compareCount), },
+ new Object[] { Integer.valueOf(compareCount), },
new Object[] {
Utility.array2String(context.getBirthmarkTypes()),
Utility.array2String(targetX),
int compareCount = getNextCount("compare");
GUIUtility.addNewTab(
getMessages(), "compare", tabPane, new PairComparisonResultSetPane(this, resultset),
- new Object[] { new Integer(compareCount), },
+ new Object[] { Integer.valueOf(compareCount), },
new Object[] {
Utility.array2String(context.getBirthmarkTypes()),
Utility.array2String(targetX),
GUIUtility.addNewTab(
getMessages(), "comparepair", tabPane,
new PairComparisonResultSetPane(this, resultset),
- new Object[] { new Integer(comparePair), },
+ new Object[] { Integer.valueOf(comparePair), },
new Object[] {
Utility.array2String(context.getBirthmarkTypes()),
Utility.array2String(targetX),
GUIUtility.addNewTab(
getMessages(), "comparepair", tabPane,
new PairComparisonResultSetPane(this, crs),
- new Object[] { new Integer(comparePair), },
+ new Object[] { Integer.valueOf(comparePair), },
new Object[] {
Utility.array2String(context.getBirthmarkTypes()),
Utility.array2String(targetX),
GUIUtility.addNewTab(
getMessages(), "comparisonresultset", tabPane,
new PairComparisonResultSetPane(this, resultset),
- new Object[] { new Integer(comparePair), }, null, true
+ new Object[] { Integer.valueOf(comparePair), }, null, true
);
}
int mappingGraphCount = getNextCount("mds_graph");
GUIUtility.addNewTab(
getMessages(), "mappinggraph", tabPane, panel,
- new Object[] { new Integer(mappingGraphCount), }, null, true
+ new Object[] { Integer.valueOf(mappingGraphCount), }, null, true
);
} catch(Exception e){
showExceptionMessage(e);
int similarityGraphCount = getNextCount("similarity_graph");
GUIUtility.addNewTab(
getMessages(), "similaritygraph", tabPane, graph,
- new Object[] { new Integer(similarityGraphCount), }, null, true
+ new Object[] { Integer.valueOf(similarityGraphCount), }, null, true
);
}
int compareCount = getNextCount("compare");
GUIUtility.addNewTab(
getMessages(), "compare", tabPane, compare,
- new Object[] { new Integer(compareCount), },
+ new Object[] { Integer.valueOf(compareCount), },
new Object[] {
Utility.array2String(ers.getBirthmarkTypes()),
Utility.array2String(new String[0]),
BirthmarkExtractionResultPane viewer = new BirthmarkExtractionResultPane(this, ers);
GUIUtility.addNewTab(
getMessages(), "extract", tabPane, viewer,
- new Object[] { new Integer(extractCount), },
+ new Object[] { Integer.valueOf(extractCount), },
new Object[] { Utility.array2String(ers.getBirthmarkTypes()), }, true
);
}
Map<String, String> mapping = new HashMap<String, String>();
BufferedReader in = null;
try{
- in = new BufferedReader(new FileReader(file));
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
String line;
while((line = in.readLine()) != null){
String[] tokens = line.split(", *");
private int getNextCount(String label){
Integer i = countmap.get(label);
if(i == null){
- i = new Integer(0);
+ i = 0;
}
i = i + 1;
countmap.put(label, i);
exts[i], MessageFormat.format(getSelectDescription(), exts[i])
);
}
- ;
}
- return filters;
+ FileFilter[] newFilters = new FileFilter[filters.length];
+ System.arraycopy(filters, 0, newFilters, 0, filters.length);
+
+ return newFilters;
}
public String getSelectDescription(){
}
public void setFileFilters(FileFilter[] filters){
- this.filters = filters;
+ this.filters = new FileFilter[filters.length];
+ System.arraycopy(filters, 0, this.filters, 0, filters.length);
}
public void setMultipleSelectable(boolean flag){
}
};
- private class TargetTransferable implements Transferable{
+ private static class TargetTransferable implements Transferable{
private String[] strings;
public TargetTransferable(String[] strings){
StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);
- BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
+ BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
String line;
while((line = in.readLine()) != null){
writer.println(line);
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.swing.AbstractAction;
}
public void setExtensions(String[] extensions){
- this.extensions = extensions;
+ this.extensions = new String[extensions.length];
+ System.arraycopy(extensions, 0, this.extensions, 0, extensions.length);
}
public void setDescrpition(String description){
PrintWriter writer = null;
try{
if(asciiWritable != null){
- writer = new PrintWriter(new FileWriter(file));
+ writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
asciiWritable.writeAsciiData(writer, format);
}
else{
double w = (d.width / 100d);
Integer v1 = distributions.get(0);
- if(v1 == null) v1 = new Integer(0);
+ if(v1 == null) v1 = 0;
double x = 20;
for(int i = 0; i <= 100; i++){
Integer v2 = distributions.get(i);
- if(v2 == null) new Integer(0);
+ if(v2 == null) v2 = 0;
double hh1 = v1 * ((double)height / totalCount);
double hh2 = v2 * ((double)height / totalCount);
private void initializeData(){
maxFrequency = 0;
for(int i = 0; i <= 100; i++){
- Integer frequency = distributions.get(new Integer(i));
+ Integer frequency = distributions.get(i);
if(frequency == null){
- frequency = new Integer(0);
- distributions.put(new Integer(i), frequency);
+ frequency = 0;
+ distributions.put(i, frequency);
}
if(maxFrequency < frequency.intValue()){
maxFrequency = frequency.intValue();
}
public int getGroupId(String groupLabel){
- Integer i = new Integer(0);
+ Integer i = 0;
if(isGroupEnabled()){
i = gids.get(groupLabel);
if(i == null){
- i = new Integer(0);
+ i = 0;
}
}
return i;
for(Map.Entry<String, String> entry: groups.entrySet()){
Integer i = map.get(entry.getValue());
if(i == null){
- i = new Integer(0);
+ i = 0;
}
map.put(entry.getValue(), i + 1);
}
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
-import java.net.URL;
+import java.net.URI;
import java.util.HashMap;
import java.util.Map;
private ZoomInAction zoomin;
private ZoomOutAction zoomout;
- public MdsViewerPane(StigmataFrame stigmata, BirthmarkSet[] set, BirthmarkContext context){
+ public MdsViewerPane(StigmataFrame stigmata, BirthmarkSet[] bset, BirthmarkContext context){
this.stigmata = stigmata;
this.context = context;
- this.set = set;
+ this.set = new BirthmarkSet[bset.length];
+ System.arraycopy(bset, 0, set, 0, bset.length);
try{
initLayouts();
return table;
}
- private String getGroupName(URL location){
+ private String getGroupName(URI location){
String url = location.toString();
if(url.startsWith("jar:")){
url = url.substring("jar:".length(), url.lastIndexOf('!'));
import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
+import java.io.Serializable;
import javax.swing.JTextField;
* @author Haruaki Tamada
* @author Terai Atsuhiro
*/
-class EditableTabbedPaneFocusTraversalPolicy extends FocusTraversalPolicy{
+class EditableTabbedPaneFocusTraversalPolicy extends FocusTraversalPolicy implements Serializable{
+ private static final long serialVersionUID = 7521938828453530777L;
+
private JTextField editor;
public EditableTabbedPaneFocusTraversalPolicy(JTextField editor){
package jp.sourceforge.stigmata.utils;
+import java.util.Arrays;
import java.util.Iterator;
+import java.util.NoSuchElementException;
/**
*
private int currentIndex = 0;
public ArrayIterator(T[] values){
- this.values = values;
if(values != null){
+ this.values = Arrays.copyOf(values, values.length);
length = values.length;
}
else{
@Override
public T next(){
+ if(currentIndex < 0 || currentIndex >= values.length){
+ throw new NoSuchElementException();
+ }
T value = values[currentIndex];
currentIndex++;
return value;
private void exportServices(PrintWriter out) throws IOException{
out.println(" <birthmark-services>");
for(BirthmarkService service: environment.getServices()){
- if(service.isExperimental() && service instanceof BirthmarkService){
+ if(service.isExperimental()){
out.println(" <birthmark-service>");
out.printf(" <type>%s</type>%n", service.getType());
if(service instanceof ReflectedBirthmarkService){
public void updateContext(BirthmarkEnvironment env) throws IOException{
String path = env.getProperty("location.hermes.config");
OutputStream out = null;
- if(path != null && path.startsWith("file:")){
- out = new URL(path).openConnection().getOutputStream();
- }
- else{
- File file = new File(BirthmarkEnvironment.getStigmataHome(), "plugins/hermes.xml");
- out = new FileOutputStream(file);
- }
- HermesContextExporter exporter = new HermesContextExporter();
- exporter.export(out, context);
- if(out != null){
- out.close();
+ try{
+ if(path != null && path.startsWith("file:")){
+ out = new URL(path).openConnection().getOutputStream();
+ }
+ else{
+ File file = new File(BirthmarkEnvironment.getStigmataHome(), "plugins/hermes.xml");
+ out = new FileOutputStream(file);
+ }
+ HermesContextExporter exporter = new HermesContextExporter();
+ exporter.export(out, context);
+ } finally{
+ if(out != null){
+ out.close();
+ }
}
}
if(updateTargets == null){
updateTargets = hermes.getUpdateTarget();
}
- return updateTargets;
+ Artifact[] artifacts = new Artifact[updateTargets.length];
+ System.arraycopy(updateTargets, 0, artifacts, 0, artifacts.length);
+ return artifacts;
}
public void update() throws IOException, HermesException{
}
} finally{
if(in != null){
- in.close();
+ try{
+ in.close();
+ } catch(IOException e){
+ }
}
if(out != null){
- out.close();
+ try{
+ out.close();
+ } catch(IOException e){
+ }
}
}
}
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
if(pluginFile == null){
flag = false;
}
- if(!pluginFile.getName().endsWith(".jar")){
+ if(flag && !pluginFile.getName().endsWith(".jar")){
messages.add("install.error.notjarfile");
flag = false;
}
- if(!pluginFile.exists()){
+ if(flag && !pluginFile.exists()){
messages.add("install.error.file.missing");
flag = false;
}