Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for DefaultGrailsPlugin: set delegation strategy before … #12892

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 the original author or authors.
* Copyright 2004-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -540,6 +540,8 @@ public void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
if(c != null) {
BeanBuilder bb = new BeanBuilder(getParentCtx(),springConfig, grailsApplication.getClassLoader());
bb.setBinding(b);
c.setDelegate(bb);
c.setResolveStrategy(Closure.DELEGATE_FIRST);
bb.invokeMethod("beans", new Object[]{c});
}
}
Expand All @@ -557,6 +559,7 @@ public void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
BeanBuilder bb = new BeanBuilder(getParentCtx(),springConfig, grailsApplication.getClassLoader());
bb.setBinding(b);
c.setDelegate(bb);
c.setResolveStrategy(Closure.DELEGATE_FIRST);
bb.invokeMethod("beans", new Object[]{c});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 the original author or authors.
* Copyright 2004-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,8 @@
public class DefaultGrailsPluginTests extends AbstractGrailsMockTests {

private Class<?> versioned;
private Class<?> versioned2;
private Class<?> versioned3;
private Class<?> notVersion;
private Class<?> notPluginClass;
private Class<?> disabled;
Expand All @@ -54,6 +56,21 @@ protected void onSetUp() {
"assert event != null" +
"}" +
"}");
versioned2 = gcl.parseClass("class MyTwoGrailsPlugin extends grails.plugins.Plugin {\n" +
"def version = 1.1;" +
"Closure doWithSpring() { {->" +
"classEditor(org.springframework.beans.propertyeditors.ClassEditor,application.classLoader)" +
"}}\n" +
"}");
versioned3 = gcl.parseClass("class MyThreeGrailsPlugin extends grails.plugins.Plugin {\n" +
"def version = 1.1;" +
"Object invokeMethod(String name, Object args) {" +
"true" +
"}\n" +
"Closure doWithSpring() { {->" +
"classEditor(org.springframework.beans.propertyeditors.ClassEditor,application.classLoader)" +
"}}\n" +
"}");
notVersion = gcl.parseClass("class AnotherGrailsPlugin {\n" +
"}");
notPluginClass = gcl.parseClass("class SomeOtherPlugin {\n" +
Expand Down Expand Up @@ -135,6 +152,26 @@ public void testDoWithRuntimeConfiguration() {
ApplicationContext ctx = springConfig.getApplicationContext();

assertTrue(ctx.containsBean("classEditor"));

// Version 2
GrailsPlugin versionPlugin2 = new DefaultGrailsPlugin(versioned2, ga);

RuntimeSpringConfiguration springConfig2 = new DefaultRuntimeSpringConfiguration();
versionPlugin2.doWithRuntimeConfiguration(springConfig2);

ApplicationContext ctx2 = springConfig2.getApplicationContext();

assertTrue(ctx2.containsBean("classEditor"));

// Version 3
GrailsPlugin versionPlugin3 = new DefaultGrailsPlugin(versioned3, ga);

RuntimeSpringConfiguration springConfig3 = new DefaultRuntimeSpringConfiguration();
versionPlugin3.doWithRuntimeConfiguration(springConfig3);

ApplicationContext ctx3 = springConfig3.getApplicationContext();

assertTrue(ctx3.containsBean("classEditor"));
}

public void testGetName() {
Expand Down