Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,20 @@ class JmxMetaMapBuilder {
* **************************************/
/**
* Returns a meta map of operations from given object.
* <p>
* Every public method reachable on the object is exported, inherited ones included, less
* the names in {@code OPS_EXCEPTION_LIST}. To export a narrower set, name the wanted
* operations explicitly in a descriptor rather than relying on this default.
*
* @param object to profile
* @return The meta map generated.
*/
static Map buildOperationMapFrom(def object) {
def methods = object.metaClass.methods
def ops = [:]

def declaredMethods = object.class.declaredMethods*.name

methods.each { method ->
// avoid picking up extra methods from parents
if ((declaredMethods.contains(method.name) && !OPS_EXCEPTION_LIST.contains(method.name)) || (!OPS_EXCEPTION_LIST.contains(method.name))) {
if (!OPS_EXCEPTION_LIST.contains(method.name)) {
String mName = method.name
MetaProperty prop =
(mName.length() > 3 && (mName.startsWith("get") || mName.startsWith("set")) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,31 @@ class JmxMetaMapBuilderTest {
assert map."set".name == "set"
}

@Test
void testMetaClassAccessorsAreNotExportedAsOperations() {
// Not exported because getMetaClass/setMetaClass resolve to the metaClass MetaProperty
// and are dropped by the getter/setter filter, not because they are named in
// OPS_EXCEPTION_LIST. Pinned so that a change to that filter cannot quietly publish
// them as remotely invokable operations.
[new MockManagedObject(), new MockManagedGroovyObject()].each { object ->
def map = JmxMetaMapBuilder.buildOperationMapFrom(object)
assert !map."getMetaClass"
assert !map."setMetaClass"
}
}

@Test
void testInheritedOperationsRemainExported() {
// The default export deliberately spans the whole inheritance chain: JmxBuilder's own
// embedded-descriptor fixtures declare their operations on a base class, and
// 'operations: "*"' routes here and must mean all of them.
def map = JmxMetaMapBuilder.buildOperationMapFrom(new EmbeddedAllOps())

assert map."doNothing"
assert map."doTwoThings"
assert map."doThreeThings"
}

@Test
void testBuildOperationFromDescriptorMap() {
def object = new MockManagedObject()
Expand Down
Loading