Skip to content

Commit cc3b147

Browse files
committed
Merge remote-tracking branch 'origin/4.0.x'
2 parents 77843bd + aaec529 commit cc3b147

File tree

7 files changed

+218
-187
lines changed

7 files changed

+218
-187
lines changed

.github/workflows/rebase.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ jobs:
1313
with:
1414
token: ${{ secrets.GITHUB_TOKEN }}
1515
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
16+
- name: Update comment with Thumbs-up
17+
uses: peter-evans/create-or-update-comment@v1
18+
with:
19+
comment-id: ${{ github.event.comment.id }}
20+
reactions: '+1'
1621
- name: Automatic Rebase
22+
id: automatic-rebase
1723
uses: cirrus-actions/[email protected]
1824
env:
1925
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
- name: Reply Comment with Failure
27+
if: failure()
28+
uses: peter-evans/create-or-update-comment@v1
29+
with:
30+
body: |
31+
> /rebase
32+
33+
Automatic rebase failed

.github/workflows/release-notes.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
branches:
77
- master
88
- '[4-9]+.[0-9]+.x'
9+
workflow_dispatch:
910
jobs:
1011
release_notes:
1112
runs-on: ubuntu-latest
@@ -18,7 +19,7 @@ jobs:
1819
echo ::set-output name=has_release_drafter::${has_release_drafter}
1920
2021
# If it has release drafter:
21-
- uses: release-drafter/release-drafter@v5.13.0
22+
- uses: release-drafter/release-drafter@v5.15.0
2223
if: steps.check_release_drafter.outputs.has_release_drafter == 'true'
2324
env:
2425
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

grails-bootstrap/src/main/groovy/org/grails/io/support/GrailsResourceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public static String getPathFromBaseDir(String path) {
869869
String basePath = baseDir != null ? baseDir.getCanonicalPath() : null;
870870
if(basePath != null) {
871871
String canonicalPath = new File(path).getCanonicalPath();
872-
return canonicalPath.substring(basePath.length()+1);
872+
return canonicalPath.contains(basePath) ? canonicalPath.substring(basePath.length()+1) : canonicalPath;
873873
}
874874
} catch (IOException e) {
875875
// ignore

grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/web/gsp/GroovyPageForkCompileTask.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class GroovyPageForkCompileTask extends AbstractCompile {
8585
javaExecSpec.setMaxHeapSize( compileOptions.forkOptions.memoryMaximumSize )
8686
javaExecSpec.setMinHeapSize( compileOptions.forkOptions.memoryInitialSize )
8787

88+
//This is the OLD Style and seems kinda silly to be hard coded this way. but restores functionality
89+
//for now
90+
def configFiles = [
91+
project.file("grails-app/conf/application.yml").canonicalPath,
92+
project.file("grails-app/conf/application.groovy").canonicalPath
93+
].join(',')
8894

8995
def arguments = [
9096
srcDir.canonicalPath,
@@ -93,7 +99,7 @@ class GroovyPageForkCompileTask extends AbstractCompile {
9399
targetCompatibility,
94100
packageName,
95101
serverpath,
96-
project.file("grails-app/conf/application.yml").canonicalPath,
102+
configFiles,
97103
compileOptions.encoding
98104
]
99105

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package org.grails.io.support
2+
3+
import grails.util.BuildSettings
4+
import org.grails.io.support.GrailsResourceUtils
5+
import org.grails.io.support.Resource
6+
import org.grails.io.support.UrlResource
7+
import org.springframework.mock.web.MockHttpServletRequest
8+
import org.springframework.mock.web.MockServletContext
9+
import spock.lang.Specification
10+
11+
class GrailsResourceUtilsSpec extends Specification {
12+
13+
private static final String TEST_URL = "file:///test/grails/app/grails-app/domain/Test.groovy"
14+
private static final String TEST_PACKAGE_URL = "file:///test/grails/app/grails-app/domain/mycompany/Test.groovy"
15+
private static final String TEST_CONTROLLER_URL = "file:///test/grails/app/grails-app/controllers/TestController.groovy"
16+
private static final String TEST_PLUGIN_CTRL = "file:///test/grails/app/plugins/myplugin/grails-app/controllers/TestController.groovy"
17+
18+
private static final String WEBINF_CONTROLLER = "file:///test/grails/app/WEB-INF/grails-app/controllers/TestController.groovy"
19+
private static final String WEBINF_PLUGIN_CTRL = "file:///test/grails/app/WEB-INF/plugins/myplugin/grails-app/controllers/TestController.groovy"
20+
21+
private static final String UNIT_TESTS_URL = "file:///test/grails/app/grails-tests/SomeTests.groovy"
22+
23+
void testGetArtifactDirectory() {
24+
expect:
25+
"controllers" == GrailsResourceUtils.getArtefactDirectory(TEST_CONTROLLER_URL)
26+
"domain" == GrailsResourceUtils.getArtefactDirectory(TEST_PACKAGE_URL)
27+
}
28+
29+
void testJavaAndGroovySources() {
30+
expect:
31+
"mycompany.Test" == GrailsResourceUtils.getClassName(TEST_PACKAGE_URL)
32+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/domain/mycompany/Test.java").getPath())
33+
"Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blahblah/Test.java").getPath())
34+
"Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah-blah/Test.java").getPath())
35+
"Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah--blah/Test.java").getPath())
36+
"Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah_blah/Test.java").getPath())
37+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blahblah/mycompany/Test.java").getPath())
38+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah-blah/mycompany/Test.java").getPath())
39+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah--blah/mycompany/Test.java").getPath())
40+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/grails-app/blah_blah/mycompany/Test.java").getPath())
41+
42+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/groovy/mycompany/Test.java").getPath())
43+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/groovy/mycompany/Test.java").getPath())
44+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/java/mycompany/Test.java").getPath())
45+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/java/mycompany/Test.java").getPath())
46+
47+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/groovy/mycompany/Test.java").getPath())
48+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/groovy/mycompany/Test.java").getPath())
49+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/java/mycompany/Test.java").getPath())
50+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/java/mycompany/Test.java").getPath())
51+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/groovy/mycompany/Test.groovy").getPath())
52+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/groovy/mycompany/Test.groovy").getPath())
53+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/main/java/mycompany/Test.groovy").getPath())
54+
"mycompany.Test" == GrailsResourceUtils.getClassName(new File("/test/grails/app/src/test/java/mycompany/Test.groovy").getPath())
55+
}
56+
57+
void testIsDomainClass() {
58+
when:
59+
URL testUrl = new URL(TEST_URL)
60+
61+
then:
62+
GrailsResourceUtils.isDomainClass(testUrl)
63+
}
64+
65+
void testGetPathFromRoot() {
66+
expect:
67+
"mycompany/Test.groovy" == GrailsResourceUtils.getPathFromRoot(TEST_PACKAGE_URL)
68+
"Test.groovy" == GrailsResourceUtils.getPathFromRoot(TEST_URL)
69+
}
70+
71+
void testGetClassNameResource() {
72+
when:
73+
Resource r = new UrlResource(new URL(TEST_URL))
74+
75+
then:
76+
"Test" == GrailsResourceUtils.getClassName(r)
77+
}
78+
79+
void testGetClassNameString() {
80+
expect:
81+
"Test" == GrailsResourceUtils.getClassName(TEST_URL)
82+
}
83+
84+
void testIsGrailsPath() {
85+
expect:
86+
GrailsResourceUtils.isGrailsPath(TEST_URL)
87+
}
88+
89+
void testIsTestPath() {
90+
expect:
91+
GrailsResourceUtils.isGrailsPath(UNIT_TESTS_URL)
92+
}
93+
94+
void testGetTestNameResource() {
95+
when:
96+
Resource r = new UrlResource(new URL(UNIT_TESTS_URL))
97+
98+
then:
99+
"SomeTests" == GrailsResourceUtils.getClassName(r)
100+
}
101+
102+
void testGetTestNameString() {
103+
expect:
104+
"SomeTests" == GrailsResourceUtils.getClassName(UNIT_TESTS_URL)
105+
}
106+
107+
void testGetViewsDirForURL() {
108+
when:
109+
Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL))
110+
111+
then:
112+
toFileUrl("/test/grails/app/grails-app/views") == viewsDir.getURL().toString()
113+
114+
viewsDir == GrailsResourceUtils.getViewsDir(new UrlResource(TEST_URL))
115+
toFileUrl("/test/grails/app/grails-app/views") == viewsDir.getURL().toString()
116+
}
117+
118+
void testGetAppDir() {
119+
when:
120+
Resource appDir = GrailsResourceUtils.getAppDir(new UrlResource(TEST_CONTROLLER_URL))
121+
122+
then:
123+
toFileUrl("/test/grails/app/grails-app") == appDir.getURL().toString()
124+
125+
appDir == GrailsResourceUtils.getAppDir(new UrlResource(TEST_URL))
126+
toFileUrl("/test/grails/app/grails-app") == appDir.getURL().toString()
127+
}
128+
129+
void testGetDirWithinWebInf() {
130+
when:
131+
Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL))
132+
Resource pluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_PLUGIN_CTRL))
133+
134+
Resource webInfViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_CONTROLLER))
135+
Resource webInfPluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_PLUGIN_CTRL))
136+
137+
then:
138+
toFileUrl("/test/grails/app/grails-app/views") == viewsDir.getURL().toString()
139+
toFileUrl("/test/grails/app/plugins/myplugin/grails-app/views") == pluginViews.getURL().toString()
140+
toFileUrl("/test/grails/app/WEB-INF/grails-app/views") == webInfViews.getURL().toString()
141+
toFileUrl("/test/grails/app/WEB-INF/plugins/myplugin/grails-app/views") == webInfPluginViews.getURL().toString()
142+
143+
"/WEB-INF/grails-app/views" == GrailsResourceUtils.getRelativeInsideWebInf(webInfViews)
144+
"/WEB-INF/plugins/myplugin/grails-app/views" == GrailsResourceUtils.getRelativeInsideWebInf(webInfPluginViews)
145+
146+
"/WEB-INF/plugins/myplugin/grails-app/views" == GrailsResourceUtils.getRelativeInsideWebInf(pluginViews)
147+
"/WEB-INF/grails-app/views" == GrailsResourceUtils.getRelativeInsideWebInf(viewsDir)
148+
}
149+
150+
void testGetPluginContextPath() {
151+
given:
152+
MockServletContext servletContext = new MockServletContext("/myapp")
153+
MockHttpServletRequest request = new MockHttpServletRequest(servletContext)
154+
request.setContextPath("/myapp")
155+
156+
expect:
157+
"" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_CONTROLLER_URL), null)
158+
"plugins/myplugin" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_PLUGIN_CTRL), null)
159+
"" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), null)
160+
"plugins/myplugin" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), null)
161+
"/myapp" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), request.getContextPath())
162+
"/myapp/plugins/myplugin" == GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), request.getContextPath())
163+
}
164+
165+
void testAppendPiecesForUri() {
166+
expect:
167+
"" == GrailsResourceUtils.appendPiecesForUri("")
168+
"/alpha/beta/gamma" == GrailsResourceUtils.appendPiecesForUri("/alpha", "/beta", "/gamma")
169+
"/alpha/beta/gamma" == GrailsResourceUtils.appendPiecesForUri("/alpha/", "/beta/", "/gamma")
170+
"/alpha/beta/gamma/" == GrailsResourceUtils.appendPiecesForUri("/alpha/", "/beta/", "/gamma/")
171+
"alpha/beta/gamma" == GrailsResourceUtils.appendPiecesForUri("alpha", "beta", "gamma")
172+
}
173+
174+
void testGetPathFromBaseDir() {
175+
expect:
176+
"views/demo/index.gsp" == GrailsResourceUtils.getPathFromBaseDir("${BuildSettings.BASE_DIR.absolutePath}/grails-app/views/demo/index.gsp")
177+
"src/main/demo/index.gsp" == GrailsResourceUtils.getPathFromBaseDir("${BuildSettings.BASE_DIR.absolutePath}/src/main/demo/index.gsp")
178+
"/alpha/index.gsp" == GrailsResourceUtils.getPathFromBaseDir("/alpha/index.gsp")
179+
}
180+
181+
private String toFileUrl(String path) {
182+
if (path == null) return path
183+
String url = null
184+
try {
185+
url = new File(path).toURI().toURL().toString()
186+
} catch (MalformedURLException e) {
187+
url = path
188+
}
189+
return url
190+
}
191+
}

0 commit comments

Comments
 (0)