Skip to content

Commit a679dfa

Browse files
committed
Merge branch '3.1.x' into 3.2.x
2 parents 25b0da1 + c8ddc84 commit a679dfa

File tree

6 files changed

+168
-28
lines changed

6 files changed

+168
-28
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ext {
4141
jansiVersion = "1.11"
4242
jlineVersion = "2.12"
4343
jnaVersion = "4.0.0"
44-
slf4jVersion = "1.7.10"
44+
slf4jVersion = "1.7.21"
4545
reactorCoreVersion = '2.0.8.RELEASE'
4646
reactorVersion = '2.0.7.RELEASE'
4747

grails-core/src/main/groovy/org/grails/core/cfg/GroovyConfigPropertySourceLoader.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import grails.util.BuildSettings
1919
import grails.util.Environment
2020
import grails.util.Metadata
2121
import groovy.transform.CompileStatic
22-
import groovy.util.logging.Commons
22+
import groovy.util.logging.Slf4j
2323
import org.grails.config.NavigableMap
2424
import org.grails.config.NavigableMapPropertySource
2525
import org.grails.core.exceptions.GrailsConfigurationException
@@ -35,7 +35,7 @@ import org.springframework.core.io.Resource
3535
* @since 3.0
3636
*/
3737
@CompileStatic
38-
@Commons
38+
@Slf4j
3939
class GroovyConfigPropertySourceLoader implements PropertySourceLoader {
4040

4141
final String[] fileExtensions = ['groovy'] as String[]
@@ -46,8 +46,9 @@ class GroovyConfigPropertySourceLoader implements PropertySourceLoader {
4646
}
4747

4848
PropertySource<?> load(String name, Resource resource, String profile, List<String> filteredKeys) throws IOException {
49-
def env = Environment.current.name
50-
if(profile == null || env == profile) {
49+
// since ConfigSlurper is already environment aware, don't load it twice
50+
if(profile == null) {
51+
def env = Environment.current.name
5152

5253
if(resource.exists()) {
5354
ConfigSlurper configSlurper = env ? new ConfigSlurper(env) : new ConfigSlurper()
@@ -66,6 +67,13 @@ class GroovyConfigPropertySourceLoader implements PropertySourceLoader {
6667

6768
def propertySource = new NavigableMap()
6869
propertySource.merge(configObject, false)
70+
71+
Resource runtimeResource = resource.createRelative( resource.filename.replace('application', 'runtime') )
72+
if(runtimeResource.exists()) {
73+
def runtimeConfig = configSlurper.parse( runtimeResource.getURL() )
74+
propertySource.merge(runtimeConfig, false)
75+
}
76+
6977
return new NavigableMapPropertySource(name, propertySource)
7078
} catch (Throwable e) {
7179
log.error("Unable to load $resource.filename: $e.message", e)

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,12 @@ class GrailsGradlePlugin extends GroovyPlugin {
354354
findMainClass.doLast {
355355
def bootExtension = project.extensions.findByType(SpringBootPluginExtension)
356356
def mainClassName = bootExtension.mainClass
357-
consoleTask.args mainClassName
358-
shellTask.args mainClassName
359-
project.tasks.withType(ApplicationContextCommandTask) { ApplicationContextCommandTask task ->
360-
task.args mainClassName
357+
if(mainClassName) {
358+
consoleTask.args mainClassName
359+
shellTask.args mainClassName
360+
project.tasks.withType(ApplicationContextCommandTask) { ApplicationContextCommandTask task ->
361+
task.args mainClassName
362+
}
361363
}
362364
project.tasks.withType(ApplicationContextScriptTask) { ApplicationContextScriptTask task ->
363365
task.args mainClassName

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.gradle.api.tasks.compile.GroovyCompile
3131
import org.gradle.language.jvm.tasks.ProcessResources
3232
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
3333
import org.grails.gradle.plugin.util.SourceSets
34+
import org.springframework.boot.gradle.SpringBootPluginExtension
3435

3536
import javax.inject.Inject
3637

@@ -170,12 +171,18 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {
170171
}
171172
}
172173

174+
@CompileStatic
173175
protected void configurePluginJarTask(Project project) {
174-
project.jar {
175-
exclude "application.yml"
176-
exclude "application.groovy"
177-
exclude "logback.groovy"
176+
def repackageTask = project.tasks.findByName('bootRepackage')
177+
repackageTask.onlyIf {
178+
def bootExtension = project.extensions.findByType(SpringBootPluginExtension)
179+
String mainClassName = bootExtension.mainClass
180+
mainClassName != null
178181
}
182+
Jar jarTask = (Jar)project.tasks.findByName('jar')
183+
jarTask.exclude "application.yml"
184+
jarTask.exclude "application.groovy"
185+
jarTask.exclude "logback.groovy"
179186
}
180187

181188
protected void configurePluginResources(Project project) {
@@ -232,6 +239,7 @@ withConfig(configuration) {
232239
}
233240
}
234241

242+
@CompileStatic
235243
protected void checkForConfigurationClash(Project project) {
236244
File yamlConfig = new File(project.projectDir,"grails-app/conf/plugin.yml")
237245
File groovyConfig = new File(project.projectDir,"grails-app/conf/plugin.groovy")

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/RegexUrlMapping.java

Lines changed: 123 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.grails.web.servlet.mvc.GrailsWebRequest;
5050
import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException;
5151
import org.grails.web.util.WebUtils;
52+
import org.slf4j.Logger;
53+
import org.slf4j.LoggerFactory;
5254
import org.springframework.http.HttpMethod;
5355
import org.springframework.util.Assert;
5456
import org.springframework.validation.Errors;
@@ -79,7 +81,7 @@ public class RegexUrlMapping extends AbstractUrlMapping {
7981
private Map<Integer, List<Pattern>> patternByTokenCount = new HashMap<Integer, List<Pattern>>();
8082
private UrlMappingData urlData;
8183
private static final String DEFAULT_ENCODING = "UTF-8";
82-
private static final Log LOG = LogFactory.getLog(RegexUrlMapping.class);
84+
private static final Logger LOG = LoggerFactory.getLogger(RegexUrlMapping.class);
8385
public static final Pattern DOUBLE_WILDCARD_PATTERN = Pattern.compile("\\(\\*\\*?\\)\\??");
8486
public static final Pattern OPTIONAL_EXTENSION_WILDCARD_PATTERN = Pattern.compile("[^/]+\\(\\.\\(\\*\\)\\)");
8587

@@ -749,46 +751,86 @@ public int compareTo(Object o) {
749751

750752
UrlMapping other = (UrlMapping) o;
751753

754+
// this wild card count
752755
final int thisStaticTokenCount = getStaticTokenCount(this);
756+
final int thisSingleWildcardCount = getSingleWildcardCount(this);
757+
final int thisDoubleWildcardCount = getDoubleWildcardCount(this);
758+
759+
// the other wild card count
753760
final int otherStaticTokenCount = getStaticTokenCount(other);
754761
final int otherSingleWildcardCount = getSingleWildcardCount(other);
755-
final int thisSingleWildcardCount = getSingleWildcardCount(this);
756762
final int otherDoubleWildcardCount = getDoubleWildcardCount(other);
757-
final int thisDoubleWildcardCount = getDoubleWildcardCount(this);
763+
758764
final boolean hasWildCards = thisDoubleWildcardCount > 0 || thisSingleWildcardCount > 0;
759765
final boolean otherHasWildCards = otherDoubleWildcardCount > 0 || otherSingleWildcardCount > 0;
760766

761767
// Always prioritise the / root mapping
762-
if(thisStaticTokenCount == 0 && thisSingleWildcardCount == 0 && thisDoubleWildcardCount == 0) {
768+
boolean isThisRoot = thisStaticTokenCount == 0 && thisSingleWildcardCount == 0 && thisDoubleWildcardCount == 0;
769+
boolean isThatRoot = otherStaticTokenCount == 0 && otherDoubleWildcardCount == 0 && otherSingleWildcardCount == 0;
770+
771+
if(isThisRoot && isThatRoot) {
772+
if(LOG.isDebugEnabled()) {
773+
LOG.debug("Mapping [{}] has equal precedence with mapping [{}]", this.toString(), other.toString());
774+
}
775+
return 0;
776+
}
777+
else if(isThisRoot) {
778+
if(LOG.isDebugEnabled()) {
779+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it is the root", this.toString(), other.toString());
780+
}
763781
return 1;
764782
}
765-
if(otherStaticTokenCount == 0 && otherSingleWildcardCount == 0 && otherDoubleWildcardCount == 0) {
783+
else if(isThatRoot) {
784+
if(LOG.isDebugEnabled()) {
785+
LOG.debug("Mapping [{}] has a lower precedence than [{}] because the latter is the root", this.toString(), other.toString());
786+
}
766787
return -1;
767788
}
768789

769-
if (otherStaticTokenCount ==0 && thisStaticTokenCount > 0) {
790+
if (otherStaticTokenCount == 0 && thisStaticTokenCount > 0) {
791+
if(LOG.isDebugEnabled()) {
792+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it has more path tokens", this.toString(), other.toString());
793+
}
770794
return 1;
771795
}
772-
if (thisStaticTokenCount ==0 && otherStaticTokenCount>0) {
796+
797+
if (thisStaticTokenCount == 0 && otherStaticTokenCount > 0) {
798+
if(LOG.isDebugEnabled()) {
799+
LOG.debug("Mapping [{}] has a lower precedence than [{}] because it has fewer path tokens", this.toString(), other.toString());
800+
}
773801
return -1;
774802
}
775803

776804
final int thisStaticAndWildcardTokenCount = getStaticAndWildcardTokenCount(this);
777805
final int otherStaticAndWildcardTokenCount = getStaticAndWildcardTokenCount(other);
806+
778807
if (otherStaticAndWildcardTokenCount==0 && thisStaticAndWildcardTokenCount>0) {
808+
if(LOG.isDebugEnabled()) {
809+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it has more path tokens [{} vs {}]", this.toString(), other.toString(), thisStaticAndWildcardTokenCount, otherStaticAndWildcardTokenCount);
810+
}
779811
return 1;
780812
}
781813
if (thisStaticAndWildcardTokenCount==0 && otherStaticAndWildcardTokenCount>0) {
814+
if(LOG.isDebugEnabled()) {
815+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because the latter has more path tokens [{} vs {}]", this.toString(), other.toString(), thisStaticAndWildcardTokenCount, otherStaticAndWildcardTokenCount);
816+
}
782817
return -1;
783818
}
784819

785820
final int staticDiff = thisStaticTokenCount - otherStaticTokenCount;
786821
if (staticDiff < 0 && !otherHasWildCards) {
787-
return staticDiff;
822+
if(LOG.isDebugEnabled()) {
823+
LOG.debug("Mapping [{}] has a lower precedence than [{}] because the latter has more concrete path tokens [{} vs {}]", this.toString(), other.toString(), thisStaticTokenCount, otherStaticTokenCount);
824+
}
825+
return -1;
788826
}
789827
else if(staticDiff > 0 && !hasWildCards) {
790-
return staticDiff;
828+
if(LOG.isDebugEnabled()) {
829+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it has more concrete path tokens [{} vs {}]", this.toString(), other.toString(), thisStaticTokenCount, otherStaticTokenCount);
830+
}
831+
return 1;
791832
}
833+
792834
String[] thisTokens = getUrlData().getTokens();
793835
String[] otherTokens = other.getUrlData().getTokens();
794836
final int thisTokensLength = thisTokens.length;
@@ -802,40 +844,107 @@ else if(staticDiff > 0 && !hasWildCards) {
802844
boolean thisTokenIsWildcard = !thisHasMoreTokens || isSingleWildcard(thisTokens[i]);
803845
boolean otherTokenIsWildcard = !otherHasMoreTokens || isSingleWildcard(otherTokens[i]);
804846
if (thisTokenIsWildcard && !otherTokenIsWildcard) {
847+
if(LOG.isDebugEnabled()) {
848+
LOG.debug("Mapping [{}] has a lower precedence than [{}] because the latter contains more concrete tokens", this.toString(), other.toString());
849+
}
805850
return -1;
806851
}
807852
if (!thisTokenIsWildcard && otherTokenIsWildcard) {
853+
if(LOG.isDebugEnabled()) {
854+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it contains more concrete tokens", this.toString(), other.toString());
855+
}
808856
return 1;
809857
}
810858
}
811859

812860
final int doubleWildcardDiff = otherDoubleWildcardCount - thisDoubleWildcardCount;
813-
if (doubleWildcardDiff != 0) return doubleWildcardDiff;
861+
if (doubleWildcardDiff != 0) {
862+
if(LOG.isDebugEnabled()) {
863+
if(doubleWildcardDiff > 0) {
864+
LOG.debug("Mapping [{}] has a higher precedence than [{}] due containing more double wild cards [{} vs. {}]", this.toString(), other.toString(), thisDoubleWildcardCount, otherDoubleWildcardCount);
865+
}
866+
else if(doubleWildcardDiff < 0) {
867+
LOG.debug("Mapping [{}] has a lower precedence than [{}] due to the latter containing more double wild cards [{} vs. {}]", this.toString(), other.toString(), thisDoubleWildcardCount, otherDoubleWildcardCount);
868+
}
869+
}
870+
return doubleWildcardDiff;
871+
}
814872

815873
final int singleWildcardDiff = otherSingleWildcardCount - thisSingleWildcardCount;
816-
if (singleWildcardDiff != 0) return singleWildcardDiff;
874+
if (singleWildcardDiff != 0) {
875+
if(LOG.isDebugEnabled()) {
876+
if(singleWildcardDiff > 0) {
877+
LOG.debug("Mapping [{}] has a higher precedence than [{}] because it contains more single wild card matches [{} vs. {}]", this.toString(), other.toString(), thisSingleWildcardCount, otherSingleWildcardCount);
878+
}
879+
else if(singleWildcardDiff < 0) {
880+
LOG.debug("Mapping [{}] has a lower precedence than [{}] due to the latter containing more single wild card matches[{} vs. {}]", this.toString(), other.toString(), thisSingleWildcardCount, otherSingleWildcardCount);
881+
}
882+
}
883+
return singleWildcardDiff;
884+
}
817885

818-
int constraintDiff = getAppliedConstraintsCount(this) - getAppliedConstraintsCount(other);
819-
if (constraintDiff != 0) return constraintDiff;
886+
int thisConstraintCount = getAppliedConstraintsCount(this);
887+
int thatConstraintCount = getAppliedConstraintsCount(other);
888+
int constraintDiff = thisConstraintCount - thatConstraintCount;
889+
if (constraintDiff != 0) {
890+
if(LOG.isDebugEnabled()) {
891+
if(constraintDiff > 0) {
892+
LOG.debug("Mapping [{}] has a higher precedence than [{}] since it defines more constraints [{} vs. {}]", this.toString(), other.toString(), thisConstraintCount, thatConstraintCount);
893+
}
894+
else if(constraintDiff < 0) {
895+
LOG.debug("Mapping [{}] has a lower precedence than [{}] since the latter defines more constraints [{} vs. {}]", this.toString(), other.toString(), thisConstraintCount, thatConstraintCount);
896+
}
897+
}
898+
return constraintDiff;
899+
}
820900

821901
int allDiff = (thisStaticTokenCount - otherStaticTokenCount) + (thisSingleWildcardCount - otherSingleWildcardCount) + (thisDoubleWildcardCount - otherDoubleWildcardCount);
822902
if(allDiff != 0) {
903+
if(LOG.isDebugEnabled()) {
904+
if(allDiff > 0) {
905+
LOG.debug("Mapping [{}] has a higher precedence than [{}] due to the overall diff", this.toString(), other.toString());
906+
}
907+
else if(allDiff < 0) {
908+
LOG.debug("Mapping [{}] has a lower precedence than [{}] due to the overall diff", this.toString(), other.toString());
909+
}
910+
}
823911
return allDiff;
824912
}
825913

826914
String thisVersion = getVersion();
827915
String thatVersion = other.getVersion();
828916
if((thisVersion.equals(thatVersion))) {
917+
if(LOG.isDebugEnabled()) {
918+
LOG.debug("Mapping [{}] has equal precedence with mapping [{}]", this.toString(), other.toString());
919+
}
829920
return 0;
830921
}
831922
else if(thisVersion.equals(ANY_VERSION) && !thatVersion.equals(ANY_VERSION)) {
923+
if(LOG.isDebugEnabled()) {
924+
LOG.debug("Mapping [{}] has a lower precedence than [{}] due to version precedence [{} vs {}]", this.toString(), other.toString(), thisVersion, thatVersion);
925+
}
832926
return -1;
833927
}
834928
else if(!thisVersion.equals(ANY_VERSION) && thatVersion.equals(ANY_VERSION)) {
929+
if(LOG.isDebugEnabled()) {
930+
LOG.debug("Mapping [{}] has a higher precedence than [{}] due to version precedence [{} vs {}]", this.toString(), other.toString(), thisVersion, thatVersion);
931+
}
835932
return 1;
836933
}
837934
else {
838-
return new VersionComparator().compare(thisVersion, thatVersion);
935+
int i = new VersionComparator().compare(thisVersion, thatVersion);
936+
if(LOG.isDebugEnabled()) {
937+
if(i > 0) {
938+
LOG.debug("Mapping [{}] has a higher precedence than [{}] due to version precedence [{} vs. {}]", this.toString(), other.toString(), thisVersion, thatVersion);
939+
}
940+
else if(i < 0) {
941+
LOG.debug("Mapping [{}] has a lower precedence than [{}] due to version precedence [{} vs. {}]", this.toString(), other.toString(), thisVersion, thatVersion);
942+
}
943+
else {
944+
LOG.debug("Mapping [{}] has equal precedence with mapping [{}]", this.toString(), other.toString());
945+
}
946+
}
947+
return i;
839948
}
840949
}
841950

grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/RegexUrlMappingTests.groovy

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,20 @@ class RegexUrlMappingTests {
4242
def m8 = new RegexUrlMapping(parser.parse("/foo/(*)/(*)"), "test", null, null, null, null, null, UrlMapping.ANY_VERSION,null, application)
4343
def m9 = new RegexUrlMapping(parser.parse("/(*)/(*)/bar"), "test", null, null, null, null, null, UrlMapping.ANY_VERSION,null, application)
4444
def m10 = new RegexUrlMapping(parser.parse("/(*)/(*)/(*)"), "test", null, null, null, null, null, UrlMapping.ANY_VERSION,null, application)
45-
45+
def m11 = new RegexUrlMapping(parser.parse("/"), "test", null, null, null, null, null, UrlMapping.ANY_VERSION,null, servletContext)
46+
47+
48+
assertTrue m1.compareTo(m1) == 0
49+
assertTrue m2.compareTo(m2) == 0
50+
assertTrue m3.compareTo(m3) == 0
51+
assertTrue m4.compareTo(m4) == 0
52+
assertTrue m5.compareTo(m5) == 0
53+
assertTrue m6.compareTo(m6) == 0
54+
assertTrue m7.compareTo(m7) == 0
55+
assertTrue m8.compareTo(m8) == 0
56+
assertTrue m9.compareTo(m9) == 0
57+
assertTrue m2.compareTo(m11) == 0
58+
assertTrue m11.compareTo(m2) == 0
4659
assertTrue m1.compareTo(m2) < 0
4760
assertTrue m1.compareTo(m3) < 0
4861
assertTrue m1.compareTo(m4) < 0

0 commit comments

Comments
 (0)