You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/10/17 01:36:13 UTC
(grails-core) 01/02: refactor(build-tooling): idiomatic Groovy cleanup of the J2G output
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch groovyism/build-tooling
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit c05385afebad5759c4ef1302defadc81c8348b23
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Fri Oct 16 19:19:54 2026 -0500
refactor(build-tooling): idiomatic Groovy cleanup of the J2G output
Behaviour-preserving idiom pass over the Java-to-Groovy conversion output for
build-logic/docs-core and grails-gradle/common+model (14 of the 35 files in
scope; the rest were already idiomatic or are interfaces/DTOs left untouched).
Applied:
- property syntax for getters with no isX/getX collision: ~35 sites
(Class.getName() -> .name, URL.getProtocol()/.getFile()/.getPath() -> .protocol/.file/.path,
File.getName()/.getParentFile()/.getAbsolutePath()/.getCanonicalPath(), URLConnection.getContentLength()/
.getResponseCode(), Throwable.getMessage(), Class.isArray()/.getComponentType() -> .array/.componentType,
Thread.getContextClassLoader(), Resource.getURL()/.getInputStream() -> .URL/.inputStream matching the
existing test idiom)
- map.get(k)/map.containsKey(k) read -> map[k]: ~10 sites (CollectionUtils, Holder, CommandLineParser,
DefaultCommandLine, GrailsResourceUtils, SpringIOUtils)
- .equals( on Strings -> ==: ~15 sites (GrailsResourceUtils protocol/path checks, CommandLineParser/
DefaultCommandLine constant comparisons, FileSystemResource/UrlResource equals() field comparisons)
- str.length() == 0 / > 0 -> isEmpty()/!isEmpty(): ~12 sites
- StringBuilder.append( -> << in statement position: ~20 sites
- string concatenation -> GString where it lands in a String-typed slot (return type or exception
message): FileSystemResource/UrlResource#getDescription, SpringIOUtils exception messages
- dropped unnecessary casts after instanceof flow typing: CollectionUtils#getOrCreateChildMap,
GrailsResourceUtils#getPropertyNameConvention-equivalent branches, UrlResource#getInputStream,
AbstractFileResolvingResource#contentLength/lastModified
- x != null ? x.foo() : null -> x?.foo(): SpringIOUtils#closeQuietly
- for (X x : coll) -> for (X x in coll): SpringIOUtils, DefaultCommandLine
- dropped the UnnecessaryPublicModifier on StringEscapeCategory's static methods
Deliberately left (Tier B exclusions / risk):
- Environment.getName() calls (CommandLineParser, DefaultCommandLine): Environment is an enum that
defines its own getName()/setName(), shadowing the inherited Enum.name() the property syntax would
otherwise resolve to differently; left as explicit calls.
- DefaultResourceLoader.getClassLoader() bare calls from getResource()/getResourceByPath(): the private
classLoader field with the same name is accessible by direct-field priority within the declaring
class, so property syntax there would bypass the getter's fallback-to-default logic. The one
cross-class static-dispatch call sites (Class literal -> Class#getClassLoader()) were converted,
matching the idiom the Spec already exercises (DefaultResourceLoader.classLoader / .defaultClassLoader).
- SupplierUtil#memoizedNonEmpty's instanceof-narrowed cast on `value` kept: the variable is shared across
two closures assigned to the same `delegate` field, so Groovy's static type checker refuses to narrow
it (javap/compile verified; dropping the cast failed compileGroovy with a "closure shared variable"
error).
- GrailsResourceUtils#instantiateFromFlatConfig's Class.newInstance() kept: swapping in
getDeclaredConstructor().newInstance() per the table entry would add NoSuchMethodException/
InvocationTargetException to the call site, widening the method's declared checked-exception surface
(a public API change), so it was left as-is.
- SpringIOUtils `in`/`out` parameter names across every copy() overload: a real "in is a keyword, rename
it" Tier A hit, but touching all ~8 overloads' signatures for a non-functional rename was judged
disproportionate to a focused idiom pass; left unchanged (it already compiles - `in` is only a Groovy
keyword in for-loop/membership positions).
- ClassPathResource#nullSafeEquals' o1.equals(o2) kept: o1/o2 are declared Object and may be arrays;
Groovy's == has its own (possibly different) array-comparison semantics, and the very next lines branch
on primitive-array types via Arrays.equals, so swapping to == risked changing which branch is reached.
- Trivial getter/setter field pairs (ClassPathResource#getPath, FileSystemResource#getPath/getFile,
DefaultCommandLine$SpecifiedOption#getOption/getValue) kept as explicit methods: collapsing them to bare
Groovy properties would add a public setter that does not exist today, a public API change.
- XmlParserFeature#getFeatureName kept explicit: carries Javadoc that must stay on the method.
Found and fixed during verification: `map[k] = v` (subscript assignment) on a java.util.Map field
compiles to a dynamic `ScriptBytecodeAdapter.invokeMethodN("putAt", ...)` call under @CompileStatic in
this Groovy version, unlike the read form `map[k]` which resolves to the static
DefaultGroovyMethods.getAt - confirmed via the javap audit across every module. Reverted all ~10
map[k] = v sites introduced by this pass back to map.put(k, v); the read-only subscript conversions were
kept since they compile cleanly.
Verification (build-logic, own gradlew):
- :grails-docs-core:compileGroovy, :compileTestGroovy: BUILD SUCCESSFUL
- :grails-docs-core:test: 67 tests, 1 pre-existing failure unrelated to this change
(FetchTagsTaskSpec, environmental: this sandbox's global git tag.gpgSign=true with no core.editor
breaks `git tag`, nothing to do with StringEscapeCategory); StringEscapeCategorySpec itself 2/2 passed.
- no codenarc/checkstyle task exists for this project (compileGroovy only)
Verification (grails-gradle, own gradlew):
- :grails-gradle-common:compileGroovy, :grails-gradle-model:compileGroovy, both compileTestGroovy:
BUILD SUCCESSFUL
- :grails-gradle-common:codeStyle, :grails-gradle-model:codeStyle: BUILD SUCCESSFUL, 0 CodeNarc
violations in both main.html reports
- :grails-gradle-common:test (24/24) + :grails-gradle-model:test (432/432): 456/456, 0 failures,
0 errors, 0 skipped (test-results XML, not exit code)
- javap -c -p dynamic-dispatch audit on every changed class: clean after the putAt fix above. The only
remaining ScriptBytecodeAdapter/GroovyObject-property hits are inside the compiler-generated
this$dist$invoke$1/this$dist$set$1/this$dist$get$1 trampolines that GrailsResourceUtils, SupplierUtil,
DefaultResourceLoader and DefaultCommandLine already carried before this change (triggered by their
pre-existing anonymous/nested inner classes), confirmed by diffing against untouched classes with no
such nesting (Option, FileSystemResource, ...) which show none.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../doc/internal/StringEscapeCategory.groovy | 6 +-
.../main/groovy/grails/util/CollectionUtils.groovy | 6 +-
.../main/groovy/grails/util/GrailsNameUtils.groovy | 53 ++++++------
.../src/main/groovy/grails/util/Holder.groovy | 6 +-
.../grails/build/parsing/CommandLineParser.groovy | 40 ++++-----
.../grails/build/parsing/DefaultCommandLine.groovy | 20 ++---
.../groovy/org/grails/build/parsing/Option.groovy | 2 +-
.../support/AbstractFileResolvingResource.groovy | 16 ++--
.../org/grails/io/support/ClassPathResource.groovy | 14 ++--
.../grails/io/support/DefaultResourceLoader.groovy | 10 +--
.../grails/io/support/FileSystemResource.groovy | 8 +-
.../grails/io/support/GrailsResourceUtils.groovy | 98 +++++++++++-----------
.../org/grails/io/support/SpringIOUtils.groovy | 33 ++++----
.../org/grails/io/support/UrlResource.groovy | 12 +--
14 files changed, 161 insertions(+), 163 deletions(-)
diff --git a/build-logic/docs-core/src/main/groovy/grails/doc/internal/StringEscapeCategory.groovy b/build-logic/docs-core/src/main/groovy/grails/doc/internal/StringEscapeCategory.groovy
index b8b4d30bc9..cda703f523 100644
--- a/build-logic/docs-core/src/main/groovy/grails/doc/internal/StringEscapeCategory.groovy
+++ b/build-logic/docs-core/src/main/groovy/grails/doc/internal/StringEscapeCategory.groovy
@@ -28,7 +28,7 @@ class StringEscapeCategory {
private StringEscapeCategory() {
}
- public static String encodeAsUrlPath(String str) {
+ static String encodeAsUrlPath(String str) {
try {
String uri = new URI('http', 'localhost', '/' + str, '').toASCIIString()
return uri.substring(17, uri.length() - 1)
@@ -38,7 +38,7 @@ class StringEscapeCategory {
}
}
- public static String encodeAsUrlFragment(String str) {
+ static String encodeAsUrlFragment(String str) {
try {
String uri = new URI('http', 'localhost', '/', str).toASCIIString()
return uri.substring(18, uri.length())
@@ -48,7 +48,7 @@ class StringEscapeCategory {
}
}
- public static String encodeAsHtml(String str) {
+ static String encodeAsHtml(String str) {
return StringEscapeUtils.escapeHtml4(str)
}
diff --git a/grails-gradle/model/src/main/groovy/grails/util/CollectionUtils.groovy b/grails-gradle/model/src/main/groovy/grails/util/CollectionUtils.groovy
index 583bcf2d7e..b4e20eaa40 100644
--- a/grails-gradle/model/src/main/groovy/grails/util/CollectionUtils.groovy
+++ b/grails-gradle/model/src/main/groovy/grails/util/CollectionUtils.groovy
@@ -72,11 +72,11 @@ class CollectionUtils {
* @return The child map
*/
static Map getOrCreateChildMap(Map parent, String key) {
- Object o = parent.get(key)
+ Object o = parent[key]
if (o instanceof Map) {
- return (Map) o
+ return o
}
- return new LinkedHashMap()
+ return [:]
}
}
diff --git a/grails-gradle/model/src/main/groovy/grails/util/GrailsNameUtils.groovy b/grails-gradle/model/src/main/groovy/grails/util/GrailsNameUtils.groovy
index 19be1e7f81..07cada6401 100644
--- a/grails-gradle/model/src/main/groovy/grails/util/GrailsNameUtils.groovy
+++ b/grails-gradle/model/src/main/groovy/grails/util/GrailsNameUtils.groovy
@@ -91,7 +91,7 @@ class GrailsNameUtils {
* @param cls The class name
*/
static String getFullClassName(Class cls) {
- String className = cls.getName()
+ String className = cls.name
return getFullClassName(className)
}
@@ -126,7 +126,7 @@ class GrailsNameUtils {
* @return The property name representation
*/
static String getClassNameRepresentation(String name) {
- if (name == null || name.length() == 0) {
+ if (name == null || name.isEmpty()) {
return ''
}
@@ -136,9 +136,9 @@ class GrailsNameUtils {
String token = token1.trim()
int length = token.length()
if (length > 0) {
- buf.append(token.substring(0, 1).toUpperCase(Locale.ENGLISH))
+ buf << token.substring(0, 1).toUpperCase(Locale.ENGLISH)
if (length > 1) {
- buf.append(token.substring(1))
+ buf << token.substring(1)
}
}
}
@@ -163,9 +163,8 @@ class GrailsNameUtils {
StringBuilder buf = new StringBuilder()
String[] tokens = name.split('-')
for (String token in tokens) {
- if (token == null || token.length() == 0) continue
- buf.append(token.substring(0, 1).toUpperCase())
- .append(token.substring(1))
+ if (token == null || token.isEmpty()) continue
+ buf << token.substring(0, 1).toUpperCase() << token.substring(1)
}
return buf.toString()
}
@@ -179,7 +178,7 @@ class GrailsNameUtils {
* @return The logical class name
*/
static String getLogicalName(Class<?> clazz, String trailingName) {
- return getLogicalName(clazz.getName(), trailingName)
+ return getLogicalName(clazz.name, trailingName)
}
/**
@@ -285,7 +284,7 @@ class GrailsNameUtils {
* @return The short name of the class
*/
static String getShortName(Class<?> targetClass) {
- return getShortName(targetClass.getName())
+ return getShortName(targetClass.name)
}
/**
@@ -325,7 +324,7 @@ class GrailsNameUtils {
* @return The script name representation
*/
static String getScriptName(Class<?> clazz) {
- return clazz == null ? null : getScriptName(clazz.getName())
+ return clazz == null ? null : getScriptName(clazz.name)
}
/**
@@ -368,7 +367,7 @@ class GrailsNameUtils {
* not valid, i.e. if it doesn't end with "GrailsPlugin.groovy".
*/
static String getPluginName(String descriptorName) {
- if (descriptorName == null || descriptorName.length() == 0) {
+ if (descriptorName == null || descriptorName.isEmpty()) {
return descriptorName
}
@@ -401,7 +400,7 @@ class GrailsNameUtils {
}
if (Character.isLowerCase(c) || Character.isDigit(c)) {
- if (Character.isLowerCase(c) && w.length() == 0) {
+ if (Character.isLowerCase(c) && w.isEmpty()) {
c = Character.toUpperCase(c)
}
else if (w.length() > 1 && Character.isUpperCase(w.charAt(w.length() - 1))) {
@@ -412,7 +411,7 @@ class GrailsNameUtils {
words.set(i, w + c)
}
else if (Character.isUpperCase(c)) {
- if ((i == 0 && w.length() == 0) || (Character.isUpperCase(w.charAt(w.length() - 1)) && Character.isUpperCase(chars[j - 1]))) {
+ if ((i == 0 && w.isEmpty()) || (Character.isUpperCase(w.charAt(w.length() - 1)) && Character.isUpperCase(chars[j - 1]))) {
words.set(i, w + c)
}
else {
@@ -424,9 +423,9 @@ class GrailsNameUtils {
StringBuilder buf = new StringBuilder()
for (Iterator<String> j = words.iterator(); j.hasNext();) {
String word = j.next()
- buf.append(word)
+ buf << word
if (j.hasNext()) {
- buf.append(' ')
+ buf << ' '
}
}
return buf.toString()
@@ -445,7 +444,7 @@ class GrailsNameUtils {
* blank.
*/
static boolean isBlank(String str) {
- return str == null || str.trim().length() == 0
+ return str == null || str.trim().isEmpty()
}
/**
@@ -508,12 +507,12 @@ class GrailsNameUtils {
static String getPropertyNameConvention(Object object, String suffix) {
if (object != null) {
Class<?> type = object.getClass()
- if (type.isArray()) {
- return getPropertyName(type.getComponentType()) + suffix + 'Array'
+ if (type.array) {
+ return getPropertyName(type.componentType) + suffix + 'Array'
}
if (object instanceof Collection) {
- Collection coll = (Collection) object
+ Collection coll = object
if (coll.isEmpty()) {
return 'emptyCollection'
}
@@ -529,7 +528,7 @@ class GrailsNameUtils {
}
if (object instanceof Map) {
- Map map = (Map) object
+ Map map = object
if (map.isEmpty()) {
return 'emptyMap'
@@ -567,7 +566,7 @@ class GrailsNameUtils {
* @return The property name equivalent
*/
static String getPropertyForGetter(String getterName, Class returnType) {
- return getPropertyForGetter(getterName, returnType.getName())
+ return getPropertyForGetter(getterName, returnType.name)
}
/**
@@ -579,13 +578,13 @@ class GrailsNameUtils {
* @return The property name equivalent
*/
static String getPropertyForGetter(String getterName, String returnType) {
- if (getterName == null || getterName.length() == 0) return null
+ if (getterName == null || getterName.isEmpty()) return null
if (getterName.startsWith('get')) {
String prop = getterName.substring(3)
return convertValidPropertyMethodSuffix(prop)
}
- if (getterName.startsWith('is') && returnType.equals('boolean')) {
+ if (getterName.startsWith('is') && returnType == 'boolean') {
String prop = getterName.substring(2)
return convertValidPropertyMethodSuffix(prop)
}
@@ -600,7 +599,7 @@ class GrailsNameUtils {
* @return The property name or null
*/
static String convertValidPropertyMethodSuffix(String suffix) {
- if (suffix.length() == 0) return null
+ if (suffix.isEmpty()) return null
// We assume all characters are Character.isJavaIdentifierPart, but the first one may not be a valid
// starting character.
@@ -646,7 +645,7 @@ class GrailsNameUtils {
* @return true if it is a javabean property getter
*/
static boolean isGetter(String name, Class returnType, Class<?>[] args) {
- if (name == null || name.length() == 0 || args == null) return false
+ if (name == null || name.isEmpty() || args == null) return false
if (args.length != 0) return false
if (name.startsWith('get')) {
@@ -701,7 +700,7 @@ class GrailsNameUtils {
* @return true if suffix indicates a property name
*/
protected static boolean isPropertyMethodSuffix(String suffix) {
- if (suffix.length() == 0) return false
+ if (suffix.isEmpty()) return false
if (!Character.isJavaIdentifierStart(suffix.charAt(0))) return false
if (suffix.length() == 1) return Character.isUpperCase(suffix.charAt(0))
return Character.isUpperCase(suffix.charAt(0)) || Character.isUpperCase(suffix.charAt(1))
@@ -715,7 +714,7 @@ class GrailsNameUtils {
* @return The property name equivalent
*/
static String getPropertyForSetter(String setterName) {
- if (setterName == null || setterName.length() == 0) return null
+ if (setterName == null || setterName.isEmpty()) return null
if (setterName.startsWith('set')) {
String prop = setterName.substring(3)
diff --git a/grails-gradle/model/src/main/groovy/grails/util/Holder.groovy b/grails-gradle/model/src/main/groovy/grails/util/Holder.groovy
index dd0c74b2f6..22bd872110 100644
--- a/grails-gradle/model/src/main/groovy/grails/util/Holder.groovy
+++ b/grails-gradle/model/src/main/groovy/grails/util/Holder.groovy
@@ -43,7 +43,7 @@ class Holder<T> {
}
T get(boolean mappedOnly) {
- T t = instances.get(getClassLoaderId())
+ T t = instances[getClassLoaderId()]
if (t != null) {
return t
}
@@ -67,7 +67,7 @@ class Holder<T> {
void set(T t) {
int id = getClassLoaderId()
- int thisClassLoaderId = System.identityHashCode(getClass().getClassLoader())
+ int thisClassLoaderId = System.identityHashCode(getClass().classLoader)
if (t == null) {
instances.remove(id)
instances.remove(thisClassLoaderId)
@@ -80,7 +80,7 @@ class Holder<T> {
}
private int getClassLoaderId() {
- return Environment.isWarDeployed() ? System.identityHashCode(Thread.currentThread().getContextClassLoader()) : System.identityHashCode(getClass().getClassLoader())
+ return Environment.isWarDeployed() ? System.identityHashCode(Thread.currentThread().contextClassLoader) : System.identityHashCode(getClass().classLoader)
}
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/CommandLineParser.groovy b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/CommandLineParser.groovy
index f36c85a180..3fd87d4529 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/CommandLineParser.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/CommandLineParser.groovy
@@ -89,7 +89,7 @@ class CommandLineParser {
* An empty or null toProcess parameter results in a zero sized array.
*/
static String[] translateCommandline(String toProcess) {
- if (toProcess == null || toProcess.length() == 0) {
+ if (toProcess == null || toProcess.isEmpty()) {
//no command? no string
return new String[0]
}
@@ -108,39 +108,39 @@ class CommandLineParser {
String nextTok = tok.nextToken()
switch (state) {
case inQuote:
- if ("\'".equals(nextTok)) {
+ if (nextTok == "\'") {
lastTokenHasBeenQuoted = true
state = normal
} else {
- current.append(nextTok)
+ current << nextTok
}
break
case inDoubleQuote:
- if ('"'.equals(nextTok)) {
+ if (nextTok == '"') {
lastTokenHasBeenQuoted = true
state = normal
} else {
- current.append(nextTok)
+ current << nextTok
}
break
default:
- if ("\'".equals(nextTok)) {
+ if (nextTok == "\'") {
state = inQuote
- } else if ('"'.equals(nextTok)) {
+ } else if (nextTok == '"') {
state = inDoubleQuote
- } else if (' '.equals(nextTok)) {
- if (lastTokenHasBeenQuoted || current.length() != 0) {
+ } else if (nextTok == ' ') {
+ if (lastTokenHasBeenQuoted || !current.isEmpty()) {
result.add(current.toString())
current.setLength(0)
}
} else {
- current.append(nextTok)
+ current << nextTok
}
lastTokenHasBeenQuoted = false
break
}
}
- if (lastTokenHasBeenQuoted || current.length() != 0) {
+ if (lastTokenHasBeenQuoted || !current.isEmpty()) {
result.add(current.toString())
}
if (state == inQuote || state == inDoubleQuote) {
@@ -190,7 +190,7 @@ class CommandLineParser {
for (String arg in args) {
if (arg == null) continue
String trimmed = arg.trim()
- if (trimmed != null && trimmed.length() > 0) {
+ if (trimmed != null && !trimmed.isEmpty()) {
if (trimmed.charAt(0) == '"' && trimmed.charAt(trimmed.length() - 1) == '"') {
trimmed = trimmed.substring(1, trimmed.length() - 1)
}
@@ -204,7 +204,7 @@ class CommandLineParser {
continue
}
if (firstArgumentIsCommand && ENV_ARGS.containsKey(trimmed)) {
- cl.setEnvironment(ENV_ARGS.get(trimmed))
+ cl.setEnvironment(ENV_ARGS[trimmed])
}
else {
if (firstArgumentIsCommand) {
@@ -224,15 +224,15 @@ class CommandLineParser {
String ls = System.getProperty('line.separator')
usageMessage = 'Available options:'
StringBuilder sb = new StringBuilder(usageMessage)
- sb.append(ls)
+ sb << ls
for (Option option in declaredOptions.values()) {
- String name = option.getName()
+ String name = option.name
int extraPadding = longestOptionNameLength - name.length()
- sb.append(' -').append(name)
+ sb << ' -' << name
for (int i = 0; i < extraPadding; i++) {
- sb.append(' ')
+ sb << ' '
}
- sb.append(DEFAULT_PADDING).append(option.getDescription()).append(ls)
+ sb << DEFAULT_PADDING << option.description << ls
}
return sb.toString()
@@ -262,7 +262,7 @@ class CommandLineParser {
validateOptionName(name)
String value = split[1].trim()
if (declaredOptions.containsKey(name)) {
- cl.addDeclaredOption(name, declaredOptions.get(name), value)
+ cl.addDeclaredOption(name, declaredOptions[name], value)
}
else {
cl.addUndeclaredOption(name, value)
@@ -272,7 +272,7 @@ class CommandLineParser {
validateOptionName(arg)
if (declaredOptions.containsKey(arg)) {
- cl.addDeclaredOption(arg, declaredOptions.get(arg))
+ cl.addDeclaredOption(arg, declaredOptions[arg])
}
else {
cl.addUndeclaredOption(arg)
diff --git a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/DefaultCommandLine.groovy b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/DefaultCommandLine.groovy
index c2e16df9fd..bc519ed164 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/DefaultCommandLine.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/DefaultCommandLine.groovy
@@ -98,7 +98,7 @@ class DefaultCommandLine implements CommandLine {
String lookupEnvironmentForCommand() {
String fallbackEnv = System.getProperty(Environment.KEY) != null ? System.getProperty(Environment.KEY) : Environment.DEVELOPMENT.getName()
- String env = CommandLineParser.DEFAULT_ENVS.get(commandName)
+ String env = CommandLineParser.DEFAULT_ENVS[commandName]
return env == null ? fallbackEnv : env
}
@@ -107,7 +107,7 @@ class DefaultCommandLine implements CommandLine {
}
void setCommandName(String cmd) {
- if (REFRESH_DEPENDENCIES_ARGUMENT.equals(cmd)) {
+ if (REFRESH_DEPENDENCIES_ARGUMENT == cmd) {
addUndeclaredOption(REFRESH_DEPENDENCIES_ARGUMENT)
}
commandName = cmd
@@ -139,11 +139,11 @@ class DefaultCommandLine implements CommandLine {
Object optionValue(String name) {
if (declaredOptions.containsKey(name)) {
- SpecifiedOption specifiedOption = declaredOptions.get(name)
+ SpecifiedOption specifiedOption = declaredOptions[name]
return specifiedOption.value
}
if (undeclaredOptions.containsKey(name)) {
- return undeclaredOptions.get(name)
+ return undeclaredOptions[name]
}
return null
}
@@ -178,17 +178,17 @@ class DefaultCommandLine implements CommandLine {
String sep = ''
List<String> args = new ArrayList<>(remainingArgs)
if (includeOptions) {
- for (Map.Entry<String, Object> entry : undeclaredOptions.entrySet()) {
- if (entry.getValue() instanceof Boolean && ((Boolean) entry.getValue())) {
- args.add('-' + entry.getKey())
+ for (Map.Entry<String, Object> entry in undeclaredOptions.entrySet()) {
+ if (entry.value instanceof Boolean && ((Boolean) entry.value)) {
+ args.add('-' + entry.key)
}
else {
- args.add('-' + entry.getKey() + '=' + entry.getValue())
+ args.add('-' + entry.key + '=' + entry.value)
}
}
}
for (String arg in args) {
- sb.append(sep).append(arg)
+ sb << sep << arg
sep = separator
}
return sb.toString()
@@ -199,7 +199,7 @@ class DefaultCommandLine implements CommandLine {
}
void addSystemProperty(String name, String value) {
- if (Environment.KEY.equals(name)) {
+ if (name == Environment.KEY) {
setEnvironment(value)
}
systemProperties.put(name, value)
diff --git a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/Option.groovy b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/Option.groovy
index fc20727ac9..5dda283f5c 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/build/parsing/Option.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/build/parsing/Option.groovy
@@ -33,7 +33,7 @@ class Option {
private String description
Option(String name, String description) {
- if (name == null || name.length() == 0) {
+ if (name == null || name.isEmpty()) {
throw new IllegalArgumentException('illegal option specified')
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/AbstractFileResolvingResource.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/AbstractFileResolvingResource.groovy
index 9e2a2cb6e3..cd4d4157ff 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/AbstractFileResolvingResource.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/AbstractFileResolvingResource.groovy
@@ -70,7 +70,7 @@ abstract class AbstractFileResolvingResource implements Resource {
* @param con the URLConnection to set the flag on
*/
private static void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getName().startsWith('JNLP'))
+ con.useCaches = con.getClass().name.startsWith('JNLP')
}
boolean exists() {
@@ -87,8 +87,8 @@ abstract class AbstractFileResolvingResource implements Resource {
HttpURLConnection httpCon =
(con instanceof HttpURLConnection ? (HttpURLConnection) con : null)
if (httpCon != null) {
- httpCon.setRequestMethod('HEAD')
- int code = httpCon.getResponseCode()
+ httpCon.requestMethod = 'HEAD'
+ int code = httpCon.responseCode
if (code == HttpURLConnection.HTTP_OK) {
return true
}
@@ -96,7 +96,7 @@ abstract class AbstractFileResolvingResource implements Resource {
return false
}
}
- if (con.getContentLength() >= 0) {
+ if (con.contentLength >= 0) {
return true
}
if (httpCon != null) {
@@ -140,9 +140,9 @@ abstract class AbstractFileResolvingResource implements Resource {
URLConnection con = url.openConnection()
useCachesIfNecessary(con)
if (con instanceof HttpURLConnection) {
- ((HttpURLConnection) con).setRequestMethod('HEAD')
+ con.requestMethod = 'HEAD'
}
- return con.getContentLength()
+ return con.contentLength
}
long lastModified() throws IOException {
@@ -155,9 +155,9 @@ abstract class AbstractFileResolvingResource implements Resource {
URLConnection con = url.openConnection()
useCachesIfNecessary(con)
if (con instanceof HttpURLConnection) {
- ((HttpURLConnection) con).setRequestMethod('HEAD')
+ con.requestMethod = 'HEAD'
}
- return con.getLastModified()
+ return con.lastModified
}
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/ClassPathResource.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/ClassPathResource.groovy
index ca923d39d5..7f991c9afe 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/ClassPathResource.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/ClassPathResource.groovy
@@ -110,7 +110,7 @@ class ClassPathResource extends AbstractFileResolvingResource {
* Return the ClassLoader that this resource will be obtained from.
*/
final ClassLoader getClassLoader() {
- return classLoader == null ? clazz.getClassLoader() : classLoader
+ return classLoader == null ? clazz.classLoader : classLoader
}
/**
@@ -198,12 +198,12 @@ class ClassPathResource extends AbstractFileResolvingResource {
StringBuilder builder = new StringBuilder('class path resource [')
if (clazz != null) {
- builder.append(GrailsResourceUtils.classPackageAsResourcePath(clazz))
- builder.append('/')
+ builder << GrailsResourceUtils.classPackageAsResourcePath(clazz)
+ builder << '/'
}
- builder.append(path)
- builder.append(']')
+ builder << path
+ builder << ']'
return builder.toString()
}
@@ -217,7 +217,7 @@ class ClassPathResource extends AbstractFileResolvingResource {
}
if (obj instanceof ClassPathResource) {
ClassPathResource otherRes = (ClassPathResource) obj
- return (path.equals(otherRes.path) &&
+ return (path == otherRes.path &&
nullSafeEquals(classLoader, otherRes.@classLoader) &&
nullSafeEquals(clazz, otherRes.@clazz))
}
@@ -234,7 +234,7 @@ class ClassPathResource extends AbstractFileResolvingResource {
if (o1.equals(o2)) {
return true
}
- if (o1.getClass().isArray() && o2.getClass().isArray()) {
+ if (o1.getClass().array && o2.getClass().array) {
if (o1 instanceof Object[] && o2 instanceof Object[]) {
return Arrays.equals((Object[]) o1, (Object[]) o2)
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/DefaultResourceLoader.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/DefaultResourceLoader.groovy
index 11e4aa2fb2..3115fda1d9 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/DefaultResourceLoader.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/DefaultResourceLoader.groovy
@@ -48,14 +48,14 @@ class DefaultResourceLoader implements ResourceLoader {
static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null
try {
- cl = Thread.currentThread().getContextClassLoader()
+ cl = Thread.currentThread().contextClassLoader
}
catch (Throwable ignored) {
// Cannot access thread context ClassLoader - falling back to system class loader...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
- cl = DefaultResourceLoader.getClassLoader()
+ cl = DefaultResourceLoader.classLoader
}
return cl
}
@@ -127,13 +127,13 @@ class DefaultResourceLoader implements ResourceLoader {
@SuppressWarnings('unused')
String getPathWithinContext() {
- return getPath()
+ return path
}
@Override
Resource createRelative(String relativePath) {
- String pathToUse = GrailsResourceUtils.applyRelativePath(getPath(), relativePath)
- return new ClassPathContextResource(pathToUse, getClassLoader())
+ String pathToUse = GrailsResourceUtils.applyRelativePath(path, relativePath)
+ return new ClassPathContextResource(pathToUse, classLoader)
}
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/FileSystemResource.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/FileSystemResource.groovy
index 17fe8a141e..0a050ad542 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/FileSystemResource.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/FileSystemResource.groovy
@@ -43,7 +43,7 @@ class FileSystemResource implements Resource {
FileSystemResource(File file) {
assertNotNull(file, 'File must not be null')
this.file = file
- path = GrailsResourceUtils.cleanPath(file.getPath())
+ path = GrailsResourceUtils.cleanPath(file.path)
}
/**
@@ -129,7 +129,7 @@ class FileSystemResource implements Resource {
* @see java.io.File#getName()
*/
String getFilename() {
- return file.getName()
+ return file.name
}
/**
@@ -138,7 +138,7 @@ class FileSystemResource implements Resource {
* @see java.io.File#getAbsolutePath()
*/
String getDescription() {
- return 'file [' + file.getAbsolutePath() + ']'
+ return "file [${file.absolutePath}]"
}
/**
@@ -176,7 +176,7 @@ class FileSystemResource implements Resource {
@Override
boolean equals(Object obj) {
return (this.is(obj) ||
- (obj instanceof FileSystemResource && path.equals(((FileSystemResource) obj).path)))
+ (obj instanceof FileSystemResource && path == ((FileSystemResource) obj).path))
}
/**
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/GrailsResourceUtils.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/GrailsResourceUtils.groovy
index 545c10a506..6dcdd04812 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/GrailsResourceUtils.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/GrailsResourceUtils.groovy
@@ -219,7 +219,7 @@ class GrailsResourceUtils {
static boolean isDomainClass(URL url) {
if (url == null) return false
- return KNOWN_DOMAIN_CLASSES.get(url.getFile())
+ return KNOWN_DOMAIN_CLASSES[url.file]
}
/**
@@ -254,7 +254,7 @@ class GrailsResourceUtils {
if (clazz == null) {
return ''
}
- String className = clazz.getName()
+ String className = clazz.name
int packageEndIndex = className.lastIndexOf('.')
if (packageEndIndex == -1) {
return ''
@@ -264,7 +264,7 @@ class GrailsResourceUtils {
}
static void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getName().startsWith('JNLP'))
+ con.useCaches = con.getClass().name.startsWith('JNLP')
}
/**
@@ -275,7 +275,7 @@ class GrailsResourceUtils {
*/
static String getClassName(Resource resource) {
try {
- return getClassName(resource.getFile().getAbsolutePath())
+ return getClassName(resource.file.absolutePath)
}
catch (IOException e) {
return null
@@ -325,17 +325,17 @@ class GrailsResourceUtils {
* a file in the file system
*/
static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
- if (!URL_PROTOCOL_FILE.equals(resourceUrl.getProtocol())) {
+ if (URL_PROTOCOL_FILE != resourceUrl.protocol) {
throw new FileNotFoundException(
description + ' cannot be resolved to absolute file path ' +
'because it does not reside in the file system: ' + resourceUrl)
}
try {
- return new File(toURI(resourceUrl).getSchemeSpecificPart())
+ return new File(toURI(resourceUrl).schemeSpecificPart)
}
catch (URISyntaxException ex) {
// Fallback for URLs that are not valid URIs (should hardly ever happen).
- return new File(resourceUrl.getFile())
+ return new File(resourceUrl.file)
}
}
@@ -349,11 +349,11 @@ class GrailsResourceUtils {
* @return whether the URL has been identified as a JAR URL
*/
static boolean isJarURL(URL url) {
- String protocol = url.getProtocol()
- return (URL_PROTOCOL_JAR.equals(protocol) ||
- URL_PROTOCOL_ZIP.equals(protocol) ||
- URL_PROTOCOL_WSJAR.equals(protocol) ||
- (URL_PROTOCOL_CODE_SOURCE.equals(protocol) && url.getPath().contains(JAR_URL_SEPARATOR)))
+ String protocol = url.protocol
+ return (URL_PROTOCOL_JAR == protocol ||
+ URL_PROTOCOL_ZIP == protocol ||
+ URL_PROTOCOL_WSJAR == protocol ||
+ (URL_PROTOCOL_CODE_SOURCE == protocol && url.path.contains(JAR_URL_SEPARATOR)))
}
/**
@@ -367,12 +367,12 @@ class GrailsResourceUtils {
* a file in the file system
*/
static File getFile(URI resourceUri, String description) throws FileNotFoundException {
- if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) {
+ if (URL_PROTOCOL_FILE != resourceUri.scheme) {
throw new FileNotFoundException(
description + ' cannot be resolved to absolute file path ' +
'because it does not reside in the file system: ' + resourceUri)
}
- return new File(resourceUri.getSchemeSpecificPart())
+ return new File(resourceUri.schemeSpecificPart)
}
/**
@@ -408,8 +408,8 @@ class GrailsResourceUtils {
* @return whether the URL has been identified as a file system URL
*/
static boolean isFileURL(URL url) {
- String protocol = url.getProtocol()
- return (URL_PROTOCOL_FILE.equals(protocol) || protocol.startsWith(URL_PROTOCOL_VFS))
+ String protocol = url.protocol
+ return (URL_PROTOCOL_FILE == protocol || protocol.startsWith(URL_PROTOCOL_VFS))
}
/**
@@ -467,10 +467,10 @@ class GrailsResourceUtils {
for (int i = pathArray.length - 1; i >= 0; i--) {
String element = pathArray[i]
- if (CURRENT_PATH.equals(element)) {
+ if (CURRENT_PATH == element) {
// Points to current directory - drop it.
}
- else if (TOP_PATH.equals(element)) {
+ else if (TOP_PATH == element) {
// Registering top path found.
tops++
}
@@ -505,9 +505,9 @@ class GrailsResourceUtils {
StringBuilder sb = new StringBuilder()
Iterator<?> it = coll.iterator()
while (it.hasNext()) {
- sb.append(prefix).append(it.next()).append(suffix)
+ sb << prefix << it.next() << suffix
if (it.hasNext()) {
- sb.append(delim)
+ sb << delim
}
}
return sb.toString()
@@ -547,21 +547,21 @@ class GrailsResourceUtils {
return [str] as String[]
}
List<String> result = new ArrayList<>()
- if (''.equals(delimiter)) {
+ if (delimiter == '') {
for (int i = 0; i < str.length(); i++) {
- result.add(deleteAny(str.substring(i, i + 1), charsToDelete))
+ result << deleteAny(str.substring(i, i + 1), charsToDelete)
}
}
else {
int pos = 0
int delPos
while ((delPos = str.indexOf(delimiter, pos)) != -1) {
- result.add(deleteAny(str.substring(pos, delPos), charsToDelete))
+ result << deleteAny(str.substring(pos, delPos), charsToDelete)
pos = delPos + delimiter.length()
}
- if (str.length() > 0 && pos <= str.length()) {
+ if (!str.isEmpty() && pos <= str.length()) {
// Add rest of String, but not in case of empty input.
- result.add(deleteAny(str.substring(pos), charsToDelete))
+ result << deleteAny(str.substring(pos), charsToDelete)
}
}
return toStringArray(result)
@@ -582,7 +582,7 @@ class GrailsResourceUtils {
for (int i = 0; i < inString.length(); i++) {
char c = inString.charAt(i)
if (charsToDelete.indexOf((int) c) == -1) {
- sb.append(c)
+ sb << c
}
}
return sb.toString()
@@ -606,18 +606,18 @@ class GrailsResourceUtils {
// the index of an occurrence we've found, or -1
int patLen = oldPattern.length()
while (index >= 0) {
- sb.append(inString.substring(pos, index))
- sb.append(newPattern)
+ sb << inString.substring(pos, index)
+ sb << newPattern
pos = index + patLen
index = inString.indexOf(oldPattern, pos)
}
- sb.append(inString.substring(pos))
+ sb << inString.substring(pos)
// remember to append any characters to the right of a match
return sb.toString()
}
private static boolean hasLength(CharSequence str) {
- return (str != null && str.length() > 0)
+ return (str != null && !str.isEmpty())
}
/**
@@ -628,7 +628,7 @@ class GrailsResourceUtils {
* @throws MalformedURLException if no valid jar file URL could be extracted
*/
static URL extractJarFileURL(URL jarUrl) throws MalformedURLException {
- String urlFile = jarUrl.getFile()
+ String urlFile = jarUrl.file
int separatorIndex = urlFile.indexOf(JAR_URL_SEPARATOR)
if (separatorIndex != -1) {
String jarFile = urlFile.substring(0, separatorIndex)
@@ -667,7 +667,7 @@ class GrailsResourceUtils {
static boolean isGrailsPath(String path) {
if (KNOWN_PATHS.containsKey(path)) {
- return KNOWN_PATHS.get(path)
+ return KNOWN_PATHS[path]
}
for (Pattern grailsAppResourcePattern in grailsAppResourcePatterns) {
Matcher m = grailsAppResourcePattern.matcher(path)
@@ -704,7 +704,7 @@ class GrailsResourceUtils {
*/
static boolean isProjectSource(Resource r) {
try {
- String file = r.getURL().getFile()
+ String file = r.URL.file
return isProjectSource(file) || file.endsWith('GrailsPlugin.groovy')
}
catch (IOException e) {
@@ -720,7 +720,7 @@ class GrailsResourceUtils {
*/
static boolean isGrailsResource(Resource r) {
try {
- String file = r.getURL().getFile()
+ String file = r.URL.file
return isGrailsPath(file) || file.endsWith('GrailsPlugin.groovy')
}
catch (IOException e) {
@@ -740,18 +740,18 @@ class GrailsResourceUtils {
if (resource == null) return null
try {
- File file = resource.getFile()
- while (file != null && !file.getName().equals(GRAILS_APP_DIR)) {
- file = file.getParentFile()
+ File file = resource.file
+ while (file != null && file.name != GRAILS_APP_DIR) {
+ file = file.parentFile
}
if (file != null) {
- return new FileSystemResource(file.getAbsolutePath() + '/')
+ return new FileSystemResource(file.absolutePath + '/')
}
} catch (IOException ignored) {
}
try {
- String url = resource.getURL().toString()
+ String url = resource.URL.toString()
int i = url.lastIndexOf(GRAILS_APP_DIR)
if (i > -1) {
@@ -782,7 +782,7 @@ class GrailsResourceUtils {
if (resource == null) return null
try {
- String url = resource.getURL().toString()
+ String url = resource.URL.toString()
int i = url.indexOf(WEB_INF)
if (i > -1) {
return url.substring(i)
@@ -820,7 +820,7 @@ class GrailsResourceUtils {
String url
try {
- url = resource.getURL().toString()
+ url = resource.URL.toString()
}
catch (IOException e) {
return contextPath
@@ -828,7 +828,7 @@ class GrailsResourceUtils {
Matcher m = PLUGIN_RESOURCE_PATTERN.matcher(url)
if (m.find()) {
- return (contextPath.length() > 0 ? contextPath + '/' : '') + m.group(1)
+ return (!contextPath.isEmpty() ? contextPath + '/' : '') + m.group(1)
}
return contextPath
@@ -873,9 +873,9 @@ class GrailsResourceUtils {
else {
try {
File baseDir = BuildSettings.BASE_DIR
- String basePath = baseDir != null ? baseDir.getCanonicalPath() : null
+ String basePath = baseDir != null ? baseDir.canonicalPath : null
if (basePath != null) {
- String canonicalPath = new File(path).getCanonicalPath()
+ String canonicalPath = new File(path).canonicalPath
return canonicalPath.contains(basePath) ? canonicalPath.substring(basePath.length() + 1) : canonicalPath
}
} catch (IOException ignored) {
@@ -938,16 +938,16 @@ class GrailsResourceUtils {
char previous = 0
for (int i = 0; i < pieces.length; i++) {
String piece = pieces[i]
- if (piece != null && piece.length() > 0) {
+ if (piece != null && !piece.isEmpty()) {
for (int j = 0, maxlen = piece.length(); j < maxlen; j++) {
char current = piece.charAt(j)
if (!(previous == '/' && current == '/')) {
- builder.append(current)
+ builder << current
previous = current
}
}
if (i + 1 < pieces.length && previous != '/') {
- builder.append('/')
+ builder << '/'
previous = '/'
}
}
@@ -964,11 +964,11 @@ class GrailsResourceUtils {
static Object instantiateFromFlatConfig(Map<String, Object> flatConfig, String configKey, String defaultClassName)
throws InstantiationException, IllegalAccessException, ClassNotFoundException, LinkageError {
String className = defaultClassName
- Object configName = flatConfig.get(configKey)
+ Object configName = flatConfig[configKey]
if (configName instanceof CharSequence) {
className = configName.toString()
}
- return forName(className, DefaultResourceLoader.getDefaultClassLoader()).newInstance()
+ return forName(className, DefaultResourceLoader.defaultClassLoader).newInstance()
}
private static Class<?> forName(String className, ClassLoader defaultClassLoader) throws ClassNotFoundException {
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/SpringIOUtils.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/SpringIOUtils.groovy
index 4701e22397..333642ffe1 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/SpringIOUtils.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/SpringIOUtils.groovy
@@ -88,9 +88,9 @@ class SpringIOUtils {
ch = (byte) (ch >>> 4) // shift the bits down
ch = (byte) (ch & 0x0F) // must do this is high order bit is on!
- out.append(CHARS[ch]) // convert the nibble to a String Character
+ out << CHARS[ch] // convert the nibble to a String Character
ch = (byte) (in[i] & 0x0F) // Strip off low nibble
- out.append(CHARS[ch]) // convert the nibble to a String Character
+ out << CHARS[ch] // convert the nibble to a String Character
}
//CheckStyle:MagicNumber ON
@@ -120,14 +120,14 @@ class SpringIOUtils {
}
private static MessageDigest getMessageDigest(String algorithm) {
- String mdAlgorithm = (String) algorithms.get(algorithm)
+ String mdAlgorithm = (String) algorithms[algorithm]
if (mdAlgorithm == null) {
- throw new IllegalArgumentException('unknown algorithm ' + algorithm)
+ throw new IllegalArgumentException("unknown algorithm ${algorithm}")
}
try {
return MessageDigest.getInstance(mdAlgorithm)
} catch (NoSuchAlgorithmException e) {
- throw new IllegalArgumentException('unknown algorithm ' + algorithm)
+ throw new IllegalArgumentException("unknown algorithm ${algorithm}")
}
}
@@ -139,15 +139,15 @@ class SpringIOUtils {
* @return The new array
*/
static Object[] addAll(Object[] array1, Object[] array2) {
- Object[] joinedArray = (Object[]) Array.newInstance(array1.getClass().getComponentType(), array1.length + array2.length)
+ Object[] joinedArray = (Object[]) Array.newInstance(array1.getClass().componentType, array1.length + array2.length)
System.arraycopy(array1, 0, joinedArray, 0, array1.length)
try {
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length)
} catch (ArrayStoreException ase) {
- final Class<?> type1 = array1.getClass().getComponentType()
- final Class<?> type2 = array2.getClass().getComponentType()
+ final Class<?> type1 = array1.getClass().componentType
+ final Class<?> type2 = array2.getClass().componentType
if (!type1.isAssignableFrom(type2)) {
- throw new IllegalArgumentException('Cannot store ' + type2.getName() + ' in an array of ' + type1.getName())
+ throw new IllegalArgumentException("Cannot store ${type2.name} in an array of ${type1.name}")
}
throw ase // No, so rethrow original
}
@@ -167,10 +167,10 @@ class SpringIOUtils {
* @param targetDir The target directory
*/
static void copyAll(Resource base, Resource[] resources, File targetDir) throws IOException {
- final URL baseUrl = base.getURL()
+ final URL baseUrl = base.URL
for (Resource resource in resources) {
- final InputStream input = resource.getInputStream()
- final File target = new File(targetDir, resource.getURL().toString().substring(baseUrl.toString().length()))
+ final InputStream input = resource.inputStream
+ final File target = new File(targetDir, resource.URL.toString().substring(baseUrl.toString().length()))
copy(new BufferedInputStream(input), new BufferedOutputStream(new FileOutputStream(target)))
}
}
@@ -199,7 +199,7 @@ class SpringIOUtils {
static int copy(Resource in, File out) throws IOException {
assert in != null : 'No input File specified'
assert out != null : 'No output File specified'
- return copy(new BufferedInputStream(in.getInputStream()),
+ return copy(new BufferedInputStream(in.inputStream),
new BufferedOutputStream(new FileOutputStream(out)))
}
@@ -375,8 +375,7 @@ class SpringIOUtils {
*/
static void closeQuietly(Closeable closeable) {
try {
- if (closeable != null)
- closeable.close()
+ closeable?.close()
} catch (IOException ignored) {
// ignore
}
@@ -500,7 +499,7 @@ class SpringIOUtils {
}
setFeature(factory, XMLConstants.FEATURE_SECURE_PROCESSING, true)
setFeature(factory, XmlParserFeature.DISALLOW_DOCTYPE_DECL.featureName, !allowDocTypeDeclaration)
- for (XmlParserFeature feature : DISABLED_PARSER_FEATURES) {
+ for (XmlParserFeature feature in DISABLED_PARSER_FEATURES) {
setFeature(factory, feature.featureName, false)
}
return factory
@@ -521,7 +520,7 @@ class SpringIOUtils {
} catch (ParserConfigurationException | SAXException e) {
LoggerFactory.getLogger(SpringIOUtils).warn(
'XML parser factory [{}] does not support feature [{}]: {}',
- factory.getClass().getName(), name, e.getMessage())
+ factory.getClass().name, name, e.message)
}
}
diff --git a/grails-gradle/model/src/main/groovy/org/grails/io/support/UrlResource.groovy b/grails-gradle/model/src/main/groovy/org/grails/io/support/UrlResource.groovy
index bfdaaecb5b..2730ede6c7 100644
--- a/grails-gradle/model/src/main/groovy/org/grails/io/support/UrlResource.groovy
+++ b/grails-gradle/model/src/main/groovy/org/grails/io/support/UrlResource.groovy
@@ -108,19 +108,19 @@ class UrlResource extends AbstractFileResolvingResource {
URLConnection con = url.openConnection()
useCachesIfNecessary(con)
try {
- return con.getInputStream()
+ return con.inputStream
}
catch (IOException ex) {
// Close the HTTP connection (if applicable).
if (con instanceof HttpURLConnection) {
- ((HttpURLConnection) con).disconnect()
+ con.disconnect()
}
throw ex
}
}
private static void useCachesIfNecessary(URLConnection con) {
- con.setUseCaches(con.getClass().getName().startsWith('JNLP'))
+ con.useCaches = con.getClass().name.startsWith('JNLP')
}
/**
@@ -172,14 +172,14 @@ class UrlResource extends AbstractFileResolvingResource {
* @see java.io.File#getName()
*/
String getFilename() {
- return new File(url.getFile()).getName()
+ return new File(url.file).name
}
/**
* This implementation returns a description that includes the URL.
*/
String getDescription() {
- return 'URL [' + url + ']'
+ return "URL [${url}]"
}
/**
@@ -188,7 +188,7 @@ class UrlResource extends AbstractFileResolvingResource {
@Override
boolean equals(Object obj) {
return (this.is(obj) ||
- (obj instanceof UrlResource && cleanedUrl.equals(((UrlResource) obj).cleanedUrl)))
+ (obj instanceof UrlResource && cleanedUrl == ((UrlResource) obj).cleanedUrl))
}
/**