Skip to content

Commit b96958f

Browse files
committed
Plugins - use a source level annotation to provide compiler hint. Fixes #9910
Currently an interface is used to provide a compiler hint that the application belongs to a plugin. This creates problems because the plugin then cannot be used in an earlier version of Grails. This fixes that by using a source level annotation instead.
1 parent 582b527 commit b96958f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.plugins.metadata;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* Source level annotation that indicates that a given source file is part of a plugin
25+
*
26+
* @author Graeme Rocher
27+
* @since 3.1.7
28+
*/
29+
@Retention(RetentionPolicy.SOURCE)
30+
@Target({ElementType.TYPE})
31+
public @interface PluginSource {
32+
}

grails-web-boot/src/main/groovy/org/grails/compiler/boot/BootInitializerClassInjector.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import grails.boot.GrailsPluginApplication
44
import grails.boot.config.GrailsAutoConfiguration
55
import grails.compiler.ast.AstTransformer
66
import grails.compiler.ast.GlobalClassInjectorAdapter
7+
import grails.plugins.metadata.PluginSource
78
import grails.util.BuildSettings
89
import groovy.transform.CompileStatic
910
import org.codehaus.groovy.ast.ClassHelper
@@ -51,12 +52,18 @@ import java.lang.reflect.Modifier
5152
class BootInitializerClassInjector extends GlobalClassInjectorAdapter {
5253

5354
public static final ClassNode GRAILS_CONFIGURATION_CLASS_NODE = ClassHelper.make(GrailsAutoConfiguration)
55+
public static final ClassNode PLUGIN_SOURCE_ANNOTATION = ClassHelper.make(PluginSource)
5456

5557
@Override
5658
void performInjectionInternal(SourceUnit source, ClassNode classNode) {
59+
// if this is a plugin source, then exit
60+
if( classNode.getAnnotations(PLUGIN_SOURCE_ANNOTATION) ) {
61+
return
62+
}
5763
// don't generate for plugins
5864
if( classNode.getNodeMetaData('isPlugin') ) return
5965

66+
6067
if(GrailsASTUtils.isAssignableFrom(GRAILS_CONFIGURATION_CLASS_NODE, classNode) && !GrailsASTUtils.isSubclassOfOrImplementsInterface(classNode, GrailsPluginApplication.name)) {
6168
def methods = classNode.getMethods("main")
6269
for(MethodNode mn in methods) {

0 commit comments

Comments
 (0)