removed printing of errors on commandline. Fixed bug for bean class hierarchies

This commit is contained in:
Sander Hautvast 2020-12-29 18:56:10 +01:00
parent 480b13b935
commit 118871eeaa
7 changed files with 21 additions and 57 deletions

View file

@ -1,22 +0,0 @@
package perfix;
public class MutableBoolean {
private boolean value;
public MutableBoolean(boolean value) {
this.value = value;
}
public void set(boolean value) {
this.value = value;
}
public boolean get() {
return value;
}
@Override
public String toString() {
return Boolean.toString(value);
}
}

View file

@ -4,7 +4,6 @@ import javassist.CannotCompileException;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
import javassist.NotFoundException; import javassist.NotFoundException;
import perfix.MutableBoolean;
import java.io.IOException; import java.io.IOException;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
@ -94,14 +93,8 @@ public class ClassInstrumentor extends Instrumentor {
return getCtClass(resource.replaceAll("/", ".")); return getCtClass(resource.replaceAll("/", "."));
} }
private boolean shouldInclude(String resource, List<String> excludes) { private boolean shouldInclude(String resource, List<String> includes) {
MutableBoolean included = new MutableBoolean(false); return includes.stream().anyMatch(resource::startsWith);
excludes.forEach(include -> {
if (resource.startsWith(include)) {
included.set(true);
}
});
return included.get();
} }
private boolean isInnerClass(String resource) { private boolean isInnerClass(String resource) {

View file

@ -5,8 +5,10 @@ import javassist.*;
import java.io.IOException; import java.io.IOException;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
public abstract class Instrumentor { public abstract class Instrumentor {
private static final Logger log = Logger.getLogger("perfix");
static final String JAVA_STRING = "java.lang.String"; static final String JAVA_STRING = "java.lang.String";
static final String JAVA_HASHMAP = "java.util.HashMap"; static final String JAVA_HASHMAP = "java.util.HashMap";
static final String PERFIX_METHODINVOCATION_CLASS = "perfix.MethodInvocation"; static final String PERFIX_METHODINVOCATION_CLASS = "perfix.MethodInvocation";
@ -29,8 +31,7 @@ public abstract class Instrumentor {
hashMapClass = classPool.get(JAVA_HASHMAP); hashMapClass = classPool.get(JAVA_HASHMAP);
} catch (NotFoundException e) { } catch (NotFoundException e) {
e.printStackTrace(); log.severe(e.toString());
//suppress TODO implement trace
} }
} }

View file

@ -6,11 +6,13 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Stream; import java.util.stream.Stream;
import static java.util.Arrays.stream; import static java.util.Arrays.stream;
public class JdbcInstrumentor extends Instrumentor { public class JdbcInstrumentor extends Instrumentor {
private static final Logger log = Logger.getLogger("perfix");
private static CtClass statementTextClass = null; private static CtClass statementTextClass = null;
@ -41,7 +43,7 @@ public class JdbcInstrumentor extends Instrumentor {
try { try {
return bytecode(preparedStatementInterface); return bytecode(preparedStatementInterface);
} catch (CannotCompileException | IOException e) { } catch (CannotCompileException | IOException e) {
e.printStackTrace(); log.severe(e.toString());
return uninstrumentedByteCode; return uninstrumentedByteCode;
} }
} }
@ -69,8 +71,7 @@ public class JdbcInstrumentor extends Instrumentor {
method.insertAfter("$_.setSqlForPerfix($1);"); //$_ is result instance, $1 is first argument method.insertAfter("$_.setSqlForPerfix($1);"); //$_ is result instance, $1 is first argument
} catch (CannotCompileException | NotFoundException e) { } catch (CannotCompileException | NotFoundException e) {
// suppress log.severe(e.toString());
e.printStackTrace();
} }
} }
); );
@ -134,7 +135,7 @@ public class JdbcInstrumentor extends Instrumentor {
methods.addAll(Arrays.asList(preparedStatementClass.getDeclaredMethods(methodname))); methods.addAll(Arrays.asList(preparedStatementClass.getDeclaredMethods(methodname)));
} catch (NotFoundException e) { } catch (NotFoundException e) {
e.printStackTrace(); log.severe(e.toString());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View file

@ -19,12 +19,6 @@ public class StatementText {
throw new IndexOutOfBoundsException("" + index); throw new IndexOutOfBoundsException("" + index);
} }
statementText.vars[index - 1] = value; statementText.vars[index - 1] = value;
} else {
if (statementText!=null){
System.out.println(statementText);
} else {
System.out.println("null");
}
} }
} }
@ -59,7 +53,7 @@ public class StatementText {
@Override @Override
public String toString() { public String toString() {
StringBuilder output=new StringBuilder(sql); StringBuilder output = new StringBuilder(sql);
int found = 0; int found = 0;
for (int i = 0; i < sql.length(); i++) { for (int i = 0; i < sql.length(); i++) {
if (output.charAt(i) == BOUNDVAR_MARK) { if (output.charAt(i) == BOUNDVAR_MARK) {

View file

@ -28,7 +28,7 @@ public class HTTPServer implements HttpHandler {
try { try {
HttpServer server = HttpServer.create(new InetSocketAddress("localhost", port), 0); HttpServer server = HttpServer.create(new InetSocketAddress("localhost", port), 0);
server.createContext("/", this); server.createContext("/", this);
server.setExecutor(Executors.newFixedThreadPool(2)); server.setExecutor(Executors.newFixedThreadPool(3));
server.start(); server.start();
System.out.println(" --- Perfix http server running. Point your browser to http://localhost:" + port + "/"); System.out.println(" --- Perfix http server running. Point your browser to http://localhost:" + port + "/");
} catch (IOException ioe) { } catch (IOException ioe) {

View file

@ -5,11 +5,14 @@ import javassist.*;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.logging.Logger;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet; import static java.util.Collections.unmodifiableSet;
public class SynthSerializerFactory implements SerializerFactory { public class SynthSerializerFactory implements SerializerFactory {
private static final Logger log = Logger.getLogger("perfix");
private static final String STRING = "java.lang.String"; private static final String STRING = "java.lang.String";
private static final String BOOLEAN = "java.lang.Boolean"; private static final String BOOLEAN = "java.lang.Boolean";
private static final String CHARACTER = "java.lang.Character"; private static final String CHARACTER = "java.lang.Character";
@ -64,7 +67,7 @@ public class SynthSerializerFactory implements SerializerFactory {
return createSerializerInstance(serializerClass); return createSerializerInstance(serializerClass);
} catch (NotFoundException | CannotCompileException | ReflectiveOperationException e) { } catch (NotFoundException | CannotCompileException | ReflectiveOperationException e) {
e.printStackTrace(); log.severe(e.toString());
throw new SerializerCreationException(e); throw new SerializerCreationException(e);
} }
}); });
@ -270,24 +273,18 @@ public class SynthSerializerFactory implements SerializerFactory {
private List<CtField> getAllFields(CtClass beanClass) { private List<CtField> getAllFields(CtClass beanClass) {
try { try {
List<CtField> allfields = new ArrayList<>(); List<CtField> allfields = new ArrayList<>();
for (CtField field : beanClass.getDeclaredFields()) { return getAllFields(beanClass, allfields);
allfields.add(field);
}
if (beanClass.getSuperclass() != null) {
return getAllFields(beanClass.getSuperclass(), allfields);
}
return allfields;
} catch (NotFoundException e) { } catch (NotFoundException e) {
throw new SerializerCreationException(e); throw new SerializerCreationException(e);
} }
} }
private List<CtField> getAllFields(CtClass beanClass, List<CtField> allfields) { private List<CtField> getAllFields(CtClass beanClass, List<CtField> allfields) throws NotFoundException {
for (CtField field : beanClass.getDeclaredFields()) { allfields.addAll(asList(beanClass.getDeclaredFields()));
allfields.add(field); if (beanClass.getSuperclass() != null) {
return getAllFields(beanClass.getSuperclass(), allfields);
} }
return allfields; return allfields;
} }