Skip to content

Commit

Permalink
Revert "Revert "feat(core): Remove/Replace deprecated Groovy classes …
Browse files Browse the repository at this point in the history
…to prepare upgrade to Groovy 4 (grails#13386)""

This reverts commit a7f00c7.
  • Loading branch information
jdaugherty committed Oct 2, 2024
1 parent e43ceee commit 6a26d4b
Show file tree
Hide file tree
Showing 72 changed files with 566 additions and 478 deletions.
2 changes: 2 additions & 0 deletions gradle/idea.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import groovy.xml.XmlParser

idea {
project {
jdkName "1.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package grails.codegen.model

import grails.util.GrailsNameUtils
import groovy.transform.CompileStatic
import org.codehaus.groovy.runtime.MetaClassHelper
import org.apache.groovy.util.BeanUtils
import org.grails.io.support.FileSystemResource
import org.grails.io.support.GrailsResourceUtils
import org.grails.io.support.Resource
Expand Down Expand Up @@ -89,7 +89,7 @@ trait ModelBuilder {
final String packagePath

ModelImpl(String className) {
this.className = MetaClassHelper.capitalize(GrailsNameUtils.getShortName(className))
this.className = BeanUtils.capitalize(GrailsNameUtils.getShortName(className))
this.fullName = className
this.propertyName = GrailsNameUtils.getPropertyName(className)
this.packageName = GrailsNameUtils.getPackageName(className)
Expand All @@ -111,7 +111,14 @@ trait ModelBuilder {

@Override
Map<String, Object> asMap() {
(Map<String,Object>) [ className: className, fullName: fullName, propertyName: propertyName, modelName: propertyName, packageName: packageName, packagePath: packagePath, simpleName: simpleName, lowerCaseName: lowerCaseName]
[className: className,
fullName: fullName,
propertyName: propertyName,
modelName: propertyName,
packageName: packageName,
packagePath: packagePath,
simpleName: simpleName,
lowerCaseName: lowerCaseName] as Map<String, Object>
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.grails.io.support;

import groovy.util.XmlSlurper;
import groovy.xml.XmlSlurper;
import groovy.xml.FactorySupport;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
package grails.ui.shell.support

import grails.core.GrailsApplication
import grails.ui.support.DevelopmentWebApplicationContext
import org.codehaus.groovy.tools.shell.Groovysh
import org.apache.groovy.groovysh.Groovysh
import org.codehaus.groovy.tools.shell.IO
import org.springframework.context.support.GenericApplicationContext


/**
* @author Graeme Rocher
* @since 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import grails.core.GrailsApplication
import grails.ui.support.DevelopmentWebApplicationContext
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors
import org.codehaus.groovy.tools.shell.Groovysh
import org.apache.groovy.groovysh.Groovysh
import org.codehaus.groovy.tools.shell.IO


/**
* @author Graeme Rocher
* @since 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package grails.util;

import grails.util.GrailsStringUtils;
import groovy.lang.GroovyObjectSupport;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.util.HashCodeHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class GrailsStringUtils extends StringUtils{
* Same as {@link StringUtils#isEmpty(java.lang.Object)} but trims the string for surrounding whitespace
*/
static boolean isBlank(String str) {
isEmpty(str?.trim())
!hasText(str?.trim())
}

/**
Expand All @@ -179,7 +179,7 @@ abstract class GrailsStringUtils extends StringUtils{
* Opposite of {@link GrailsStringUtils#isEmpty(java.lang.Object)}
*/
static boolean isNotEmpty(String str) {
!isEmpty(str)
hasText(str)
}

/**
Expand Down
15 changes: 0 additions & 15 deletions grails-core/src/main/groovy/grails/util/GrailsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,12 @@
*/
package grails.util;

import grails.io.IOUtils;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Writable;
import groovy.util.slurpersupport.GPathResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.grails.core.io.CachingPathMatchingResourcePatternResolver;
import org.grails.exceptions.reporting.DefaultStackTraceFilterer;
import org.grails.exceptions.reporting.StackTraceFilterer;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
* Grails utility methods for command line and GUI applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import grails.util.GrailsNameUtils
import groovy.transform.CompilationUnitAware
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import groovy.util.slurpersupport.GPathResult
import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlSlurper
import groovy.xml.slurpersupport.GPathResult
import org.codehaus.groovy.ast.*
import org.codehaus.groovy.ast.expr.ConstantExpression
import org.codehaus.groovy.control.CompilationUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class GrailsFactoriesLoader extends FactoriesLoaderSupport {
boolean hasArguments = !(arguments != null && arguments.length==0)
List<T> results = new ArrayList<T>()
for(Class<? extends T> clazz : loadFactoryClasses(factoryClass, classLoader)) {
results.add(hasArguments ? clazz.newInstance(arguments) : clazz.newInstance())
results.add(hasArguments ? clazz.newInstance(arguments) : clazz.getDeclaredConstructor().newInstance())
}
OrderComparator.sort((List<?>) results)
results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.grails.plugins;

import groovy.util.slurpersupport.GPathResult;
import groovy.xml.slurpersupport.GPathResult;
import org.grails.core.exceptions.GrailsConfigurationException;
import org.grails.io.support.SpringIOUtils;
import org.springframework.core.io.Resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EnhancesSpec extends Specification{
void "Test that the enhances trait transform works as expected"() {

when:"The generated transformer is loaded"
def traitInjector = getClass().classLoader.loadClass("grails.artefact.FooTraitInjector").newInstance()
def traitInjector = getClass().classLoader.loadClass("grails.artefact.FooTraitInjector").getDeclaredConstructor().newInstance()

then:"It is a valid trait injector"
traitInjector instanceof TraitInjector
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.compiler.injection

import groovy.xml.MarkupBuilder
import groovy.xml.XmlSlurper
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.classgen.GeneratorContext
import org.codehaus.groovy.control.CompilationFailedException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.grails.core.io

import grails.core.DefaultGrailsApplication
import org.grails.plugins.BinaryGrailsPlugin
import org.grails.plugins.BinaryGrailsPluginDescriptor
import org.grails.plugins.MockBinaryPluginResource
import org.grails.plugins.MockGrailsPluginManager
import org.grails.plugins.TestBinaryGrailsPlugin
import groovy.xml.XmlSlurper
import org.grails.plugins.*
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.ResourceLoader

import spock.lang.Specification

class ResourceLocatorSpec extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FooController {
filterer.setCutOffPackage("org.spockframework.util")
Throwable exception
try {
cls.newInstance().show()
cls.getDeclaredConstructor().newInstance().show()
} catch (e) {
filterer.filter(e)
exception = e
Expand Down Expand Up @@ -77,7 +77,7 @@ class FooService {
filterer.setCutOffPackage("org.spockframework.util")
Throwable exception
try {
cls.newInstance().show()
cls.getDeclaredConstructor().newInstance().show()
} catch (e) {
filterer.filter(e, true)
println getExceptionContents(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class StackTracePrinterSpec extends Specification {
void "Test pretty print simple stack trace"() {
given: "a controller that throws an exception"
final gcl = new GroovyClassLoader()
gcl.parseClass(getServiceResource().inputStream, serviceResource.filename)
def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance()
gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename)
def controller = gcl.parseClass(new BufferedReader(new InputStreamReader(getControllerResource().inputStream)), getControllerResource().filename).getDeclaredConstructor().newInstance()
when:"An exception is pretty printed"
def printer = new DefaultErrorsPrinter()
def result = null
Expand All @@ -36,8 +36,8 @@ class StackTracePrinterSpec extends Specification {
void "Test pretty print nested stack trace"() {
given: "a controller that throws an exception"
final gcl = new GroovyClassLoader()
gcl.parseClass(getServiceResource().inputStream, serviceResource.filename)
def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance()
gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename)
def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance()
when:"An exception is pretty printed"
def printer = new DefaultErrorsPrinter()
def result = null
Expand All @@ -58,8 +58,8 @@ class StackTracePrinterSpec extends Specification {
void "Test pretty print nested stack trace for JDK 11"() {
given: "a controller that throws an exception"
final gcl = new GroovyClassLoader()
gcl.parseClass(getServiceResource().inputStream, serviceResource.filename)
def controller = gcl.parseClass(getControllerResource().inputStream, controllerResource.filename).newInstance()
gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename)
def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance()
when:"An exception is pretty printed"
def printer = new DefaultErrorsPrinter()
def result = null
Expand All @@ -79,8 +79,8 @@ class StackTracePrinterSpec extends Specification {
void "Test pretty print code snippet"() {
given: "a controller that throws an exception"
final gcl = new GroovyClassLoader()
gcl.parseClass(getServiceResource().inputStream, serviceResource.filename)
def controller = gcl.parseClass(getControllerResource().inputStream, getControllerResource().filename).newInstance()
gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename)
def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance()

when: "A code snippet is pretty printed"
final locator = new StaticResourceLocator()
Expand Down Expand Up @@ -118,8 +118,8 @@ Around line 5 of FooController.groovy
void "Test pretty print nested exception code snippet"() {
given:"a service that throws an exception that is caught and rethrown"
final gcl = new GroovyClassLoader()
gcl.parseClass(getServiceResource().inputStream, serviceResource.filename)
def controller = gcl.parseClass(controllerResource.inputStream, controllerResource.filename).newInstance()
gcl.parseClass(toBufferedReader(getServiceResource().inputStream), serviceResource.filename)
def controller = gcl.parseClass(toBufferedReader(getControllerResource().inputStream), getControllerResource().filename).getDeclaredConstructor().newInstance()
final locator = new StaticResourceLocator()
locator.addClassResource("test.FooController", controllerResource)
locator.addClassResource("test.FooService", serviceResource)
Expand Down Expand Up @@ -198,4 +198,8 @@ class FooService {
}
}
}

private BufferedReader toBufferedReader(InputStream inputStream) {
new BufferedReader(new InputStreamReader(inputStream))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package grails.databinding;

import grails.databinding.events.DataBindingListener;
import groovy.util.slurpersupport.GPathResult;
import groovy.xml.slurpersupport.GPathResult;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import grails.databinding.events.DataBindingListener
import grails.databinding.initializers.ValueInitializer
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import groovy.util.slurpersupport.GPathResult
import groovy.xml.slurpersupport.GPathResult
import org.codehaus.groovy.reflection.CachedMethod
import org.grails.databinding.ClosureValueConverter
import org.grails.databinding.ClosureValueInitializer
Expand Down Expand Up @@ -344,11 +344,11 @@ class SimpleDataBinder implements DataBinder {
} else if (isBasicType(genericType)) {
addElementToCollectionAt obj, propName, collectionInstance, index, convert(genericType, val)
} else if (val instanceof Map){
indexedInstance = genericType.newInstance()
indexedInstance = genericType.getDeclaredConstructor().newInstance()
bind indexedInstance, new SimpleMapDataBindingSource(val), listener
addElementToCollectionAt obj, propName, collectionInstance, index, indexedInstance
} else if (val instanceof DataBindingSource) {
indexedInstance = genericType.newInstance()
indexedInstance = genericType.getDeclaredConstructor().newInstance()
bind indexedInstance, val, listener
addElementToCollectionAt obj, propName, collectionInstance, index, indexedInstance
} else if(genericType.isEnum() && val instanceof CharSequence) {
Expand Down Expand Up @@ -752,7 +752,7 @@ class SimpleDataBinder implements DataBinder {
obj[propName] = initializer.initialize()
}
else{
obj[propName] = propertyType.newInstance()
obj[propName] = propertyType.getDeclaredConstructor().newInstance()
}
}

Expand Down Expand Up @@ -815,7 +815,7 @@ class SimpleDataBinder implements DataBinder {
} else if (typeToConvertTo.isPrimitive() || typeToConvertTo.isArray()) {
return value
} else if (value instanceof Map) {
def obj = typeToConvertTo.newInstance()
def obj = typeToConvertTo.getDeclaredConstructor().newInstance()
bind obj, new SimpleMapDataBindingSource(value)
return obj
} else if (Enum.isAssignableFrom(typeToConvertTo) && value instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import grails.databinding.CollectionDataBindingSource;
import grails.databinding.DataBindingSource;
import grails.databinding.SimpleMapDataBindingSource;
import groovy.transform.CompileStatic
import groovy.util.slurpersupport.GPathResult
import groovy.xml.slurpersupport.GPathResult

@CompileStatic
class GPathResultCollectionDataBindingSource implements CollectionDataBindingSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package org.grails.databinding.xml

import groovy.util.slurpersupport.GPathResult
import groovy.util.slurpersupport.Node
import groovy.util.slurpersupport.NodeChild
import groovy.xml.slurpersupport.GPathResult
import groovy.xml.slurpersupport.Node
import groovy.xml.slurpersupport.NodeChild

/**
* @author Jeff Brown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
*/
package grails.databinding

import grails.databinding.SimpleDataBinder;

import groovy.xml.XmlSlurper
import spock.lang.Specification

class XMLBindingSpec extends Specification {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.databinding.xml

import grails.databinding.DataBindingSource;
import grails.databinding.DataBindingSource
import groovy.xml.XmlSlurper
import spock.lang.Specification

class GPathCollectionDataBindingSourceSpec extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.grails.databinding.xml

import groovy.xml.XmlSlurper
import spock.lang.Specification

class GPathResultMapSpec extends Specification {
Expand Down
2 changes: 1 addition & 1 deletion grails-docs/src/main/groovy/grails/doc/DocEngine.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class DocEngine extends BaseRenderEngine implements WikiRenderEngine {
EscapeFilter]

for (f in filters) {
RegexFilter filter = f.newInstance()
RegexFilter filter = f.getDeclaredConstructor().newInstance()
fp.addFilter(filter)

if (filter instanceof MacroFilter) {
Expand Down
Loading

0 comments on commit 6a26d4b

Please sign in to comment.