/** * The package were third-party libraries are shaded into * @return */ public static String getShadedPackageForThirdPartyLibraries(){ return getEvoSuitePackage() + "." +SHADED; }
/** {@inheritDoc} */ @Override public void onMethodExit(int opcode) { // TODO: Check for <clinit> if (opcode != Opcodes.ATHROW) { mv.visitLdcInsn(className); mv.visitLdcInsn(fullMethodName); mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcase.execution.ExecutionTracer.class), "leftMethod", "(Ljava/lang/String;Ljava/lang/String;)V", false); } super.onMethodExit(opcode); }
public static boolean isValidForInjection(Class<? extends Annotation> annotation, List<Class<? extends Annotation>> tagsToCheck){ Inputs.checkNull(annotation); String name = annotation.getName(); String shadedPrefix = PackageInfo.getShadedPackageForThirdPartyLibraries()+"."; for(Class<?> c : tagsToCheck){ String cn = c.getName(); if(name.equals(cn)){ return true; } if(cn.startsWith(shadedPrefix)){ if((shadedPrefix + name).equals(cn)){ return true; } } } return false; } }
private static void makeShadedCopy(){ String content = null; try { content = new Scanner(new File(resourceFolder + jdkFile)).useDelimiter("\\Z").next(); } catch (Exception e) { logger.error("Error when reading JDK file",e); return; } String shadedContent = content.replace(PackageInfo.getEvoSuitePackage(), PackageInfo.getShadedEvoSuitePackage()); File shadedFile = new File(resourceFolder+shadedJdkFile); if(shadedFile.exists()){ shadedFile.delete(); } try (PrintWriter out = new PrintWriter(shadedFile)) { out.write(shadedContent); } catch (Exception e){ logger.error("Error when making shaded copy"); } }
public static boolean isClassConsideredForInstrumentation(final String className) { // we exclude standard java and sun packages as well the Prototype package // TODO use regex for check // TODO use configuration for exclusion return! ( className.startsWith("sun") || className.startsWith("com/sun") || className.startsWith("java") || className.startsWith("java/lang") || className.startsWith("$Proxy") || // ignore all dynamic proxies (http://docs.oracle.com/javase/1.3/docs/guide/reflection/proxy.html) className.startsWith(PackageInfo.getEvoSuitePackageWithSlash()+"/testcarver") ); }
public static InheritanceTree readJDKData() { XStream xstream = new XStream(); XStream.setupDefaultSecurity(xstream); xstream.allowTypesByWildcard(new String[] {"org.evosuite.**", "org.jgrapht.**"}); String fileName; if(! PackageInfo.isCurrentlyShaded()) { fileName = "/" + jdkFile; } else { fileName = "/" + shadedJdkFile; } InputStream inheritance = InheritanceTreeGenerator.class.getResourceAsStream(fileName); if (inheritance != null) { return (InheritanceTree) xstream.fromXML(inheritance); } else { logger.warn("Found no JDK inheritance tree in the resource path: "+fileName); return null; } }
if(methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) { logger.debug("Replacing call "+methodInsnNode.name); methodInsnNode.owner = PackageInfo.getEvoSuitePackageWithSlash()+"/testcarver/wrapper/" + methodInsnNode.owner; newargs[i+1] = args[i]; methodInsnNode.desc = Type.getMethodDescriptor(returnType, newargs); methodInsnNode.owner = PackageInfo.getEvoSuitePackageWithSlash()+"/testcarver/wrapper/" + methodInsnNode.owner; } else { methodInsnNode.name += "_final"; if(wrapperClass.getName().equals(name)) { logger.debug("Replacing new "+name); typeInsnNode.desc = PackageInfo.getEvoSuitePackageWithSlash()+"/testcarver/wrapper/" + generatedType.getInternalName(); break;
private static String[] getEvoSuitePackages() { return new String[] { PackageInfo.getEvoSuitePackage(), "org.exsyst", "de.unisb.cs.st.testcarver", "de.unisb.cs.st.evosuite", "testing.generation.evosuite", "de.unisl.cs.st.bugex" }; }
/** {@inheritDoc} */ @Override public void visitLineNumber(int line, Label start) { super.visitLineNumber(line, start); currentLine = line; if (methodName.equals("<clinit>")) return; if (!hadInvokeSpecial) return; mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "checkTimeout", "()V", false); }
private static void handleShadingSpecialCases(){ String shadePrefix = PackageInfo.getShadedPackageForThirdPartyLibraries()+"."; if(! DocumentFactory.class.getName().startsWith(shadePrefix)){ //if not shaded (eg in system tests), then nothing to do return; } String defaultFactory = System.getProperty("org.dom4j.factory", "org.dom4j.DocumentFactory"); String defaultDomSingletonClass= System.getProperty( "org.dom4j.dom.DOMDocumentFactory.singleton.strategy", "org.dom4j.util.SimpleSingleton"); String defaultSingletonClass = System.getProperty( "org.dom4j.DocumentFactory.singleton.strategy", "org.dom4j.util.SimpleSingleton"); System.setProperty("org.dom4j.factory" , shadePrefix + defaultFactory); System.setProperty("org.dom4j.dom.DOMDocumentFactory.singleton.strategy" , shadePrefix + defaultDomSingletonClass); System.setProperty("org.dom4j.DocumentFactory.singleton.strategy" , shadePrefix + defaultSingletonClass); DocumentFactory.getInstance(); //force loading DOMDocumentFactory.getInstance(); //restore in case SUT uses its own dom4j System.setProperty("org.dom4j.factory" ,defaultFactory); System.setProperty("org.dom4j.dom.DOMDocumentFactory.singleton.strategy", defaultDomSingletonClass); System.setProperty("org.dom4j.DocumentFactory.singleton.strategy", defaultSingletonClass); }
@Test public void testGetEvoSuitePackageWithSlash() throws Exception { assertEquals("org/evosuite",PackageInfo.getEvoSuitePackageWithSlash()); }
/** * The package name of the shaded EvoSutie. Used only for when testing EvoSuite * @return */ public static String getShadedEvoSuitePackage(){ String shaded = SHADED + "."; String evo = getEvoSuitePackage(); if(evo.startsWith(shaded)){ return evo; } else { return shaded + evo; } }
@Override public String getDescriptor() { return "()L"+ PackageInfo.getNameWithSlash(retval.getVariableClass()) + ";"; }
@Test public void testGetShadedPackage() throws Exception { assertEquals("org.evosuite.shaded",PackageInfo.getShadedPackageForThirdPartyLibraries()); }
public static boolean isCurrentlyShaded(){ return getEvoSuitePackage().startsWith(SHADED); } }
/** {@inheritDoc} */ @Override public void onMethodEnter() { if (methodName.equals("<clinit>")) return; // FIXXME: Should we call super.onMethodEnter() here? mv.visitLdcInsn(className); mv.visitLdcInsn(fullMethodName); if ((access & Opcodes.ACC_STATIC) > 0) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.visitVarInsn(Opcodes.ALOAD, 0); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "enteredMethod", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V", false); super.onMethodEnter(); }
public static String getEvoSuitePackageWithSlash(){ return getEvoSuitePackage().replace('.', '/'); }
@SuppressWarnings("unchecked") private boolean isJUnitTest(ClassNode cn) throws IOException { // We do not consider abstract classes if ((cn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) return false; if (hasJUnitSuperclass(cn)) return true; List<MethodNode> methods = cn.methods; for (MethodNode mn : methods) { List<AnnotationNode> annotations = mn.visibleAnnotations; if (annotations != null) { for (AnnotationNode an : annotations) { if (an.desc.equals("Lorg/junit/Test;") || an.desc.equals("L"+PackageInfo.getNameWithSlash(EvoSuiteTest.class)+";")) return true; } } } return false; }
public static boolean isEvoSuiteClass(Class<?> c) { return c.getName().startsWith(PackageInfo.getEvoSuitePackage()); //|| c.getName().equals("java.lang.String"); // This is now handled in addDependencyClass }
/** {@inheritDoc} */ @Override public void visitInsn(int opcode) { if (opcode == Opcodes.ATHROW) { super.visitInsn(Opcodes.DUP); this.visitLdcInsn(className); this.visitLdcInsn(methodName); mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "exceptionThrown", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V", false); } super.visitInsn(opcode); } }