Skip to content

Commit

Permalink
Fixes grails#8968 - "gradle war" uses development environment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jun 5, 2015
1 parent 9e3a7c3 commit 2526f44
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
14 changes: 14 additions & 0 deletions grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Metadata extends CodeGenConfig {
public static final String DEFAULT_SERVLET_VERSION = "2.5";

private static Holder<Reference<Metadata>> holder = new Holder<Reference<Metadata>>("Metadata");
public static final String BUILD_INFO_FILE = "META-INF/grails.build.info"

private File metadataFile;
private boolean warDeployed;
Expand Down Expand Up @@ -79,6 +80,8 @@ public class Metadata extends CodeGenConfig {
}

private void afterLoading() {
def flatConfig = configMap.toFlatConfig()
configMap.putAll(flatConfig)
def map = [:]
// allow override via system properties
map.putAll(System.properties.findAll { it.value })
Expand Down Expand Up @@ -108,6 +111,17 @@ public class Metadata extends CodeGenConfig {
if (input != null) {
loadYml(input);
}

input = Metadata.class.getClassLoader().getResourceAsStream(BUILD_INFO_FILE);
if(input != null) {
try {
def props = new Properties()
props.load(input)
mergeMap(props, true)
} catch (Throwable e) {
// ignore
}
}
afterLoading();
}
catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion grails-core/src/main/groovy/grails/boot/GrailsApp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class GrailsApp extends SpringApplication {
def protocol = System.getProperty('server.ssl.key-store') ? 'https' : 'http'
GrailsApplication app = applicationContext.getBean(GrailsApplication)
def contextPath = app.config.getProperty('server.contextPath', '')
println("Grails application running at ${protocol}://localhost:${applicationContext.embeddedServletContainer.port}${contextPath}")
println("Grails application running at ${protocol}://localhost:${applicationContext.embeddedServletContainer.port}${contextPath} in environment: ${Environment.current.name}")
} catch (e) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.CopySpec
Expand Down Expand Up @@ -76,6 +77,37 @@ class GrailsGradlePlugin extends GroovyPlugin {
configureGrailsSourceDirs(project)

configureApplicationCommands(project)

createBuildPropertiesTask(project)
}

protected Task createBuildPropertiesTask(Project project) {
def buildInfoFile = project.file("${project.buildDir}/grails.build.info")

def buildPropertiesTask = project.tasks.create("buildProperties")
def buildPropertiesContents = ['grails.env': Environment.current.name,
'info.app.name': project.name,
'info.app.version': project.version,
'info.app.grailsVersion': project.properties.get('grailsVersion')]

buildPropertiesTask.inputs.properties(buildPropertiesContents)
buildPropertiesTask.outputs.file(buildInfoFile)
buildPropertiesTask << {
ant.propertyfile(file: buildInfoFile) {
for(me in buildPropertiesContents) {
entry key: me.key, value: me.value
}
}
}

project.afterEvaluate {
project.tasks.withType(Jar) { Jar jar ->
jar.dependsOn(buildPropertiesTask)
jar.metaInf {
from(buildInfoFile)
}
}
}
}

@CompileStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.gradle.plugin.core

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.bundling.Jar
Expand Down Expand Up @@ -55,6 +56,11 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {

}

@Override
protected Task createBuildPropertiesTask(Project project) {
// no-op
}

protected void configureSourcesJarTask(Project project) {
def sourcesJar = project.tasks.create("sourcesJar", Jar).configure {
classifier = 'sources'
Expand Down

0 comments on commit 2526f44

Please sign in to comment.