Skip to content

Commit c16c4cd

Browse files
committed
fix for GRAILS-3929 "Configuration file not found in grails-app/conf when executing "grails run-app" (directory not added to classpath?)"
1 parent f6d21db commit c16c4cd

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

grails-bootstrap/src/main/groovy/grails/util/BuildSettings.groovy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package grails.util
1717

18+
import org.codehaus.groovy.grails.io.support.IOUtils
19+
1820
import static grails.build.logging.GrailsConsole.instance as CONSOLE
1921
import grails.build.logging.GrailsConsole
2022
import groovy.transform.CompileStatic
@@ -1612,4 +1614,35 @@ class BuildSettings extends AbstractBuildSettings {
16121614
boolean isPluginProject() {
16131615
getBasePluginDescriptor() != null
16141616
}
1617+
1618+
@CompileStatic
1619+
void initializeResourcesDir() {
1620+
def targetPath = resourcesDir.path
1621+
def dir = new File(baseDir, "grails-app/conf")
1622+
resourcesDir.mkdirs()
1623+
if (dir.exists()) {
1624+
try {
1625+
copyDirectoryContentsToTarget(dir, targetPath)
1626+
} catch (e) {
1627+
GrailsConsole.getInstance().error("Error initializing resources from grails-app/conf: ${e.message}", e)
1628+
}
1629+
}
1630+
1631+
}
1632+
@CompileStatic
1633+
protected void copyDirectoryContentsToTarget(File dir, String targetPath) {
1634+
dir.eachFile { File f ->
1635+
final isFile = !f.isDirectory()
1636+
final isHidden = f.isHidden()
1637+
if (isFile && !isHidden && !f.name.endsWith('.groovy')) {
1638+
IOUtils.copy(f, new File(targetPath, f.name))
1639+
}
1640+
else if (!isFile && !isHidden) {
1641+
final fileName = f.name
1642+
if (fileName != 'hibernate' && fileName != 'spring') {
1643+
copyDirectoryContentsToTarget(f, new File(targetPath, fileName).path)
1644+
}
1645+
}
1646+
}
1647+
}
16151648
}

grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/cli/GrailsScriptRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ private int executeCommand(CommandLine commandLine, String scriptName, String en
350350

351351
console.updateStatus("Loading Grails " + settings.getGrailsVersion());
352352
settings.loadConfig();
353+
settings.initializeResourcesDir();
353354

354355
System.setProperty("springloaded.directoriesContainingReloadableCode",
355356
settings.getClassesDir().getAbsolutePath() + ',' +

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,9 @@ protected void assertNotNull(Object object, String message) {
195195
throw new IllegalArgumentException(message);
196196
}
197197
}
198+
199+
@Override
200+
public String toString() {
201+
return file.toString();
202+
}
198203
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,8 @@ public int hashCode() {
190190
return cleanedUrl.hashCode();
191191
}
192192

193+
@Override
194+
public String toString() {
195+
return getDescription();
196+
}
193197
}

grails-core/src/main/groovy/org/codehaus/groovy/grails/project/packaging/GrailsProjectPackager.groovy

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ class GrailsProjectPackager extends BaseSettingsApi {
245245
*/
246246
@CompileStatic
247247
ConfigObject packageApplication() {
248+
try {
249+
packageConfigFiles(basedir)
250+
} catch (Throwable e) {
251+
throw new PackagingException("Error occurred packaging configuration files: ${e.message}", e)
252+
}
248253

249254
if (doCompile) {
250255
projectCompiler.compilePlugins()
@@ -276,11 +281,7 @@ class GrailsProjectPackager extends BaseSettingsApi {
276281
throw new PackagingException("Error occurred processing message bundles: ${e.message}", e)
277282
}
278283

279-
try {
280-
packageConfigFiles(basedir)
281-
} catch (Throwable e) {
282-
throw new PackagingException("Error occurred packaging configuration files: ${e.message}", e)
283-
}
284+
284285

285286
packageMetadataFile()
286287

0 commit comments

Comments
 (0)