codeconsole commented on code in PR #16780:
URL: https://github.com/apache/grails-core/pull/16780#discussion_r4416096038


##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/FactoriesCompileInput.groovy:
##########
@@ -0,0 +1,76 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.gradle.plugin.core
+
+import groovy.transform.CompileStatic
+
+import org.gradle.api.Project
+import org.gradle.api.tasks.PathSensitivity
+import org.gradle.api.tasks.compile.GroovyCompile
+
+/**
+ * Declares the hand-authored factories files the Grails compiler merges into 
the ones it generates as
+ * inputs of a Groovy compilation. A resource does not invalidate a 
compilation on its own, so a change
+ * to one of these files left the generated file as it was until a source 
changed as well. As an input
+ * that is not a source, a change to one recompiles in full, which writes the 
generated file again.
+ *
+ * @since 9.0

Review Comment:
   This targets 8.0.x, and `PruneGeneratedFactories` (and its functional spec) 
say `@since 8.0.1`. Should this be `8.0.1` too? The same applies to 
`FactoriesCompileInputFunctionalSpec`.



##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -242,10 +242,19 @@ class GrailsGradlePlugin implements Plugin<Project> {
     private void configureGroovyCompiler(Project project) {
         project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c 
->
             if (c.name == 'compileGroovy') {
-                // Resource-only changes do not ordinarily invalidate 
compilation. This file changes
-                // whether the compiler owns the generated imports resource, 
so adding or deleting it
-                // must run the transform even when no Groovy source changed.
+                // Resource-only changes do not ordinarily invalidate 
compilation. These files change
+                // what the compiler generates: whether it owns the imports 
resource, and what it
+                // merges into the factories files, so adding, editing or 
deleting one must run the
+                // transforms even when no Groovy source changed.
                 AutoConfigurationImportsCompileInput.register(project, c)
+                FactoriesCompileInput.registerGrailsFactories(project, c)
+                FactoriesCompileInput.registerCliFactories(project, c)
+                // A deleted class that nothing depends on compiles nothing, 
so the factories files the

Review Comment:
   This only happens with incremental Groovy compilation, which is opt-in 
(`options.incremental = true`; the `factories-prune` fixture sets it). With the 
default, deleting a source runs a full recompile that cleans the destination 
directory first, so the prune finds nothing to do. Could the comment (and the 
`PruneGeneratedFactories` Javadoc) say so? Otherwise a reader may think every 
build depends on this action.



##########
grails-gradle/plugins/src/test/resources/test-projects/factories-prune/src/main/groovy/example/Plain.groovy:
##########
@@ -0,0 +1,22 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package example
+
+class Plain {

Review Comment:
   No feature asserts anything about `Plain`. It is never registered, and 
`handlers()` reads only `example.Handler`. Either assert that it stays out of 
the file (and that the prune leaves it alone), or drop the fixture.



##########
grails-core/src/main/groovy/org/grails/compiler/injection/GlobalGrailsClassInjectorTransformation.groovy:
##########
@@ -564,9 +564,13 @@ class GlobalGrailsClassInjectorTransformation implements 
ASTTransformation, Comp
     }
 
     private static boolean updateGrailsFactoriesWithTypes(ClassNode classNode, 
Collection<ClassNode> superTypes, File compilationTargetDirectory) {
-        superTypes.any {
-            updateGrailsFactoriesWithType(classNode, it, 
compilationTargetDirectory)
+        // every type is visited rather than stopping at the first that 
registers the class: one it
+        // is no longer a subtype of has to drop it
+        boolean registered = false
+        for (ClassNode superType : superTypes) {

Review Comment:
   Side effect of replacing `any`: a class that is both an `ArtefactHandler` 
and a `TraitInjector` used to be registered only as the handler, because `any` 
stopped at the first match. Now it is registered under both types, so it is 
also loaded as a trait injector. I think the new behavior is the right one. It 
is still an observable change in a patch release, though, so it may be worth a 
line in the commit message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to