public final MetaClass getMetaClass(Class theClass) { return ClassInfo.getClassInfo(theClass).getMetaClass(); }
public MetaClass getMetaClass(Object obj) { return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj); }
public ClassMetaClassGetPropertySite(CallSite parent, Class aClass) { super(parent); this.aClass = aClass; classInfo = ClassInfo.getClassInfo(aClass); version = classInfo.getVersion(); metaClass = classInfo.getMetaClass(); }
/** * Returns a string detailing possible solutions to a missing field or property * if no good solutions can be found a empty string is returned. * * @param fieldName the missing field * @param type the class on which the field is sought * @return a string with probable solutions to the exception */ public static String getPropertySuggestionString(String fieldName, Class type){ ClassInfo ci = ClassInfo.getClassInfo(type); List<MetaProperty> fi = ci.getMetaClass().getProperties(); List<RankableField> rf = new ArrayList<RankableField>(fi.size()); StringBuilder sb = new StringBuilder(); sb.append("\nPossible solutions: "); for(MetaProperty mp : fi) rf.add(new RankableField(fieldName, mp)); Collections.sort(rf); int i = 0; for (RankableField f : rf) { if (i > MAX_RECOMENDATIONS) break; if (f.score > MAX_FIELD_SCORE) break; if(i > 0) sb.append(", "); sb.append(f.f.getName()); i++; } return i > 0? sb.toString(): ""; }
ClassInfo ci = ClassInfo.getClassInfo(type); List<MetaMethod> methods = new ArrayList<MetaMethod>(ci.getMetaClass().getMethods()); methods.addAll(ci.getMetaClass().getMetaMethods()); List<MetaMethod> sugg = rankMethods(methodName,arguments,methods); StringBuilder sb = new StringBuilder();
public final MetaClass getMetaClass(Class theClass) { return ClassInfo.getClassInfo(theClass).getMetaClass(); }
public final MetaClass getMetaClass(Class theClass) { return ClassInfo.getClassInfo(theClass).getMetaClass(); }
public final MetaClass getMetaClass(Class theClass) { return ClassInfo.getClassInfo(theClass).getMetaClass(); }
public MetaClass getMetaClass(Object obj) { return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj); }
public MetaClass getMetaClass(Object obj) { return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj); }
public MetaClass getMetaClass(Object obj) { return ClassInfo.getClassInfo(obj.getClass()).getMetaClass(obj); }
public ClassMetaClassGetPropertySite(CallSite parent, Class aClass) { super(parent); this.aClass = aClass; classInfo = ClassInfo.getClassInfo(aClass); version = classInfo.getVersion(); metaClass = classInfo.getMetaClass(); }
public ClassMetaClassGetPropertySite(CallSite parent, Class aClass) { super(parent); this.aClass = aClass; classInfo = ClassInfo.getClassInfo(aClass); version = classInfo.getVersion(); metaClass = classInfo.getMetaClass(); }
public ClassMetaClassGetPropertySite(CallSite parent, Class aClass) { super(parent); this.aClass = aClass; classInfo = ClassInfo.getClassInfo(aClass); version = classInfo.getVersion(); metaClass = classInfo.getMetaClass(); }
/** * Returns a string detailing possible solutions to a missing field or property * if no good solutions can be found a empty string is returned. * * @param fieldName the missing field * @param type the class on which the field is sought * @return a string with probable solutions to the exception */ public static String getPropertySuggestionString(String fieldName, Class type){ ClassInfo ci = ClassInfo.getClassInfo(type); List<MetaProperty> fi = ci.getMetaClass().getProperties(); List<RankableField> rf = new ArrayList<RankableField>(fi.size()); StringBuffer sb = new StringBuffer(); sb.append("\nPossible solutions: "); for(MetaProperty mp : fi) rf.add(new RankableField(fieldName, mp)); Collections.sort(rf); int i = 0; for (RankableField f : rf) { if (i > MAX_RECOMENDATIONS) break; if (f.score > MAX_FIELD_SCORE) break; if(i > 0) sb.append(", "); sb.append(f.f.getName()); i++; } return i > 0? sb.toString(): ""; }
ClassInfo ci = ClassInfo.getClassInfo(type); List<MetaMethod> methods = new ArrayList<MetaMethod>(ci.getMetaClass().getMethods()); methods.addAll(ci.getMetaClass().getMetaMethods()); List<MetaMethod> sugg = rankMethods(methodName,arguments,methods); StringBuffer sb = new StringBuffer();
ClassPropertyFetcher(final Class clazz) { this.clazz = clazz; this.classInfo = ClassInfo.getClassInfo(clazz); this.theMetaClass = classInfo.getMetaClass(); List<MetaProperty> properties = theMetaClass.getProperties(); this.metaProperties = new ArrayList<>(properties.size());
@Ignore("creates classes such as script1493642504440203321963 in a new GroovyClassLoader.InnerLoader delegating to CleanGroovyClassLoader which are invisible to cleanUpHeap") @Test public void doNotUseConfigSlurper() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition(CpsFlowExecutionMemoryTest.class.getName() + ".register(this); echo(/parsed ${new ConfigSlurper().parse('foo.bar.baz = 99')}/)", false)); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertFalse(LOADERS.isEmpty()); try { // as above Field f = ASTTransformationVisitor.class.getDeclaredField("compUnit"); f.setAccessible(true); f.set(null, null); } catch (NoSuchFieldException e) {} { // TODO as above MetaClass metaClass = ClassInfo.getClassInfo(CpsFlowExecutionMemoryTest.class).getMetaClass(); Method clearInvocationCaches = metaClass.getClass().getDeclaredMethod("clearInvocationCaches"); clearInvocationCaches.setAccessible(true); clearInvocationCaches.invoke(metaClass); } for (WeakReference<ClassLoader> loaderRef : LOADERS) { MemoryAssert.assertGC(loaderRef, true); } }
@Test public void loaderReleased() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); r.jenkins.getWorkspaceFor(p).child("lib.groovy").write(CpsFlowExecutionMemoryTest.class.getName() + ".register(this)", null); p.setDefinition(new CpsFlowDefinition(CpsFlowExecutionMemoryTest.class.getName() + ".register(this); node {load 'lib.groovy'; evaluate(readFile('lib.groovy'))}", false)); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertFalse(((CpsFlowExecution) b.getExecution()).getProgramDataFile().exists()); assertFalse(LOADERS.isEmpty()); { // TODO it seems that the call to CpsFlowExecutionMemoryTest.register(Object) on a Script1 parameter creates a MetaMethodIndex.Entry.cachedStaticMethod. // In other words any call to a foundational API might leak classes. Why does Groovy need to do this? // Unclear whether this is a problem in a realistic environment; for the moment, suppressing it so the test can run with no SoftReference. MetaClass metaClass = ClassInfo.getClassInfo(CpsFlowExecutionMemoryTest.class).getMetaClass(); Method clearInvocationCaches = metaClass.getClass().getDeclaredMethod("clearInvocationCaches"); clearInvocationCaches.setAccessible(true); clearInvocationCaches.invoke(metaClass); } for (WeakReference<ClassLoader> loaderRef : LOADERS) { MemoryAssert.assertGC(loaderRef, false); } }