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

View file

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

View file

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

View file

@ -19,12 +19,6 @@ public class StatementText {
throw new IndexOutOfBoundsException("" + index);
}
statementText.vars[index - 1] = value;
} else {
if (statementText!=null){
System.out.println(statementText);
} else {
System.out.println("null");
}
}
}

View file

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

View file

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