This is an automated email from the ASF dual-hosted git repository. jdaugherty pushed a commit to branch wrapper-rewrite in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 114eb01540b6c302a0144730b0d62ebff7e9e096 Author: James Daugherty <jdaughe...@jdresources.net> AuthorDate: Tue May 13 23:50:21 2025 -0400 Remove old reloading code (Support.groovy) --- .../src/main/groovy/grails/dev/Support.groovy | 107 --------------------- .../injection/ApplicationClassInjector.groovy | 46 ++++----- 2 files changed, 21 insertions(+), 132 deletions(-) diff --git a/grails-core/src/main/groovy/grails/dev/Support.groovy b/grails-core/src/main/groovy/grails/dev/Support.groovy deleted file mode 100644 index d261e86dd9..0000000000 --- a/grails-core/src/main/groovy/grails/dev/Support.groovy +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 grails.dev - -import grails.util.BuildSettings -import grails.util.Environment -import groovy.transform.CompileDynamic -import groovy.transform.CompileStatic -import groovy.util.logging.Commons -import org.springframework.util.ClassUtils - -import java.lang.management.ManagementFactory - -/** - * Methods to support the development environment - * - * @author Graeme Rocher - * @since 3.0 - */ -@CompileStatic -@Commons -class Support { - - - public static final String PROPERTY_RELOAD_AGENT_PATH = "reload.agent.path" - public static final String ENV_RELOAD_AGENT_PATH = "RELOAD_AGENT_PATH" - - /** - * Enables the reloading agent at runtime if it isn't present - */ - static void enableAgentIfNotPresent(Class mainClass = null) { - if(mainClass) { - System.setProperty(BuildSettings.MAIN_CLASS_NAME, mainClass.getName()) - } - - def environment = Environment.current - if(environment.isReloadEnabled() && - (!ClassUtils.isPresent("org.springsource.loaded.SpringLoaded", System.classLoader) || - !ClassUtils.isPresent("org.springsource.loaded.TypeRegistry", System.classLoader))) { - def grailsHome = System.getenv(Environment.ENV_GRAILS_HOME) - - if(grailsHome) { - def agentPath = System.getProperty(PROPERTY_RELOAD_AGENT_PATH) - if(!agentPath) { - agentPath = System.getenv(ENV_RELOAD_AGENT_PATH) - } - def file = findAgentJar(agentPath, grailsHome) - if(file?.exists()) { - def runtimeMxBean = ManagementFactory.runtimeMXBean - def arguments = runtimeMxBean.inputArguments - if(!arguments.contains('-Xverify:none') && !arguments.contains('-noverify')) { - log.warn("Reloading is disabled. Development time reloading requires disabling the Java verifier. Please pass the argument '-Xverify:none' to the JVM") - } - else { - def vmName = runtimeMxBean.name - int i = vmName.indexOf('@') - String pid = vmName.subSequence(0, i) - if(ClassUtils.isPresent('com.sun.tools.attach.VirtualMachine', System.classLoader)) { - def vmClass = Support.classLoader.loadClass('com.sun.tools.attach.VirtualMachine') - attachAgentClassToProcess(vmClass, pid, file) - } - - } - } - } - } - } - - protected static File findAgentJar(String agentPath, String grailsHome) { - if(agentPath) { - return new File(agentPath) - } - else if(grailsHome) { - def parentDir = new File(grailsHome, "lib/org.springframework/springloaded/jars") - if(parentDir.exists()) { - return parentDir.listFiles()?.find() { File f -> f.name.endsWith('.RELEASE.jar')} - } - } - } - - @CompileDynamic - private static void attachAgentClassToProcess(Class<?> vmClass, String pid, File file) { - try { - def vm = vmClass.attach(pid) - vm.loadAgent(file.absolutePath, "") - vm.detach() - } catch (e) { - System.err.println("WARNING: Could not attach reloading agent. Reloading disabled. Message: $e.message") - } - } -} diff --git a/grails-core/src/main/groovy/org/grails/compiler/injection/ApplicationClassInjector.groovy b/grails-core/src/main/groovy/org/grails/compiler/injection/ApplicationClassInjector.groovy index 51d69384ee..33bbae3495 100644 --- a/grails-core/src/main/groovy/org/grails/compiler/injection/ApplicationClassInjector.groovy +++ b/grails-core/src/main/groovy/org/grails/compiler/injection/ApplicationClassInjector.groovy @@ -1,26 +1,23 @@ /* - * 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 + * 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 + * 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. + * 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.compiler.injection import grails.compiler.ast.AstTransformer import grails.compiler.ast.GrailsArtefactClassInjector -import grails.dev.Support import grails.io.ResourceUtils import grails.util.BuildSettings import groovy.transform.CompileDynamic @@ -29,11 +26,8 @@ import org.apache.groovy.ast.tools.AnnotatedNodeUtils import org.codehaus.groovy.ast.AnnotationNode import org.codehaus.groovy.ast.ClassHelper import org.codehaus.groovy.ast.ClassNode -import org.codehaus.groovy.ast.expr.ArgumentListExpression -import org.codehaus.groovy.ast.expr.ClassExpression import org.codehaus.groovy.ast.expr.ConstantExpression import org.codehaus.groovy.ast.expr.ListExpression -import org.codehaus.groovy.ast.expr.MethodCallExpression import org.codehaus.groovy.ast.stmt.BlockStatement import org.codehaus.groovy.ast.stmt.ExpressionStatement import org.codehaus.groovy.ast.stmt.ReturnStatement @@ -44,9 +38,16 @@ import org.grails.core.artefact.ApplicationArtefactHandler import org.grails.io.support.GrailsResourceUtils import org.grails.io.support.UrlResource import org.springframework.util.ClassUtils -import static org.codehaus.groovy.ast.tools.GeneralUtils.* + import java.lang.reflect.Modifier +import static org.codehaus.groovy.ast.tools.GeneralUtils.args +import static org.codehaus.groovy.ast.tools.GeneralUtils.callX +import static org.codehaus.groovy.ast.tools.GeneralUtils.classX +import static org.codehaus.groovy.ast.tools.GeneralUtils.constX +import static org.codehaus.groovy.ast.tools.GeneralUtils.propX +import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt + /** * Injector for the 'Application' class * @@ -91,13 +92,8 @@ class ApplicationClassInjector implements GrailsArtefactClassInjector { if(!transformedInstances.contains(objectId)) { transformedInstances << objectId - def arguments = new ArgumentListExpression(new ClassExpression(classNode)) - def enableAgentMethodCall = new MethodCallExpression(new ClassExpression(ClassHelper.make(Support)), "enableAgentIfNotPresent", arguments) - def methodCallStatement = new ExpressionStatement(enableAgentMethodCall) - List<Statement> statements = [ - stmt( callX(classX(System), "setProperty", args( propX( classX(BuildSettings), "MAIN_CLASS_NAME"), constX(classNode.name) )) ), - methodCallStatement + stmt(callX(classX(System), "setProperty", args(propX(classX(BuildSettings), "MAIN_CLASS_NAME"), constX(classNode.name)))) ] classNode.addStaticInitializerStatements(statements, true)