-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: decouple
views-gradle-plugin
from dependencies
This commit decouples the `views-gradle-plugin` from `grails-bootstrap` and `spring-boot-gradle-plugin` dependencies. The decoupling is intended to mitigate potential circular dependency issues during releases.
- Loading branch information
Showing
3 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
gradle-plugin/src/main/groovy/grails/views/gradle/GrailsNameUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package grails.views.gradle | ||
|
||
import groovy.transform.CompileStatic | ||
|
||
/** | ||
* This class is copying some methods from GrailsNameUtils in grails-bootstrap. | ||
* This is done to avoid a dependency on grails-bootstrap. | ||
* GrailsNameUtils in grails-bootstrap is probably a candidate for moving to a future "grails-common" module. | ||
*/ | ||
@CompileStatic | ||
class GrailsNameUtils { | ||
|
||
/** | ||
* Returns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController" | ||
* | ||
* @param logicalName The logical name | ||
* @param trailingName The trailing name | ||
* @return The class name | ||
*/ | ||
static String getClassName(String logicalName, String trailingName) { | ||
if (isBlank(logicalName)) { | ||
throw new IllegalArgumentException('Argument [logicalName] cannot be null or blank'); | ||
} | ||
|
||
String className = logicalName.substring(0,1).toUpperCase(Locale.ENGLISH) + logicalName.substring(1); | ||
if (trailingName != null) { | ||
className = className + trailingName; | ||
} | ||
return className; | ||
} | ||
|
||
/** | ||
* Return the class name for the given logical name. For example "person" would evaluate to "Person" | ||
* | ||
* @param logicalName The logical name | ||
* @return The class name | ||
*/ | ||
static String getClassName(String logicalName) { | ||
return getClassName(logicalName, ''); | ||
} | ||
|
||
/** | ||
* <p>Determines whether a given string is <code>null</code>, empty, | ||
* or only contains whitespace. If it contains anything other than | ||
* whitespace then the string is not considered to be blank and the | ||
* method returns <code>false</code>.</p> | ||
* <p>We could use Commons Lang for this, but we don't want GrailsNameUtils | ||
* to have a dependency on any external library to minimise the number of | ||
* dependencies required to bootstrap Grails.</p> | ||
* @param str The string to test. | ||
* @return <code>true</code> if the string is <code>null</code>, or | ||
* blank. | ||
*/ | ||
static boolean isBlank(String str) { | ||
return str == null || str.trim().isEmpty(); | ||
} | ||
|
||
} | ||
|