Skip to content

Commit f02126a

Browse files
author
graeme
committed
fix for GRAILS-1943
git-svn-id: https://svn.codehaus.org/grails/trunk@6273 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent dc24b9b commit f02126a

File tree

5 files changed

+479
-414
lines changed

5 files changed

+479
-414
lines changed

scripts/War.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ target (war: "The implementation target") {
105105

106106
Ant.propertyfile(file:"${basedir}/staging/WEB-INF/classes/application.properties") {
107107
entry(key:"grails.env", value:grailsEnv)
108+
entry(key:"grails.war.deployed", value:"true")
108109
}
109110

110111
Ant.replace(file:"${basedir}/staging/WEB-INF/applicationContext.xml",

src/commons/org/codehaus/groovy/grails/commons/DefaultGrailsApplication.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class DefaultGrailsApplication extends GroovyObjectSupport implements Gra
9999
private static final String CONFIG_BINDING_GRAILS_HOME = "grailsHome";
100100
private static final String CONFIG_BINDING_APP_NAME = "appName";
101101
private static final String CONFIG_BINDING_APP_VERSION = "appVersion";
102+
private static final String META_GRAILS_WAR_DEPLOYED = "grails.war.deployed";
102103

103104
/**
104105
* Creates a new empty Grails application
@@ -124,7 +125,7 @@ public DefaultGrailsApplication(final Class[] classes, GroovyClassLoader classLo
124125
}
125126
this.allClasses = classes;
126127
this.cl = classLoader;
127-
loadMetadata();
128+
this.applicationMeta = loadMetadata();
128129
}
129130

130131

@@ -143,7 +144,7 @@ public DefaultGrailsApplication(GrailsResourceLoader resourceLoader) {
143144
this.resourceLoader = resourceLoader;
144145

145146
try {
146-
loadMetadata();
147+
this.applicationMeta = loadMetadata();
147148
loadGrailsApplicationFromResources(resourceLoader.getResources());
148149
} catch (IOException e) {
149150
throw new GrailsConfigurationException("I/O exception loading Grails: " + e.getMessage(), e);
@@ -206,7 +207,7 @@ private void loadGrailsApplicationFromResources(Resource[] resources) throws IOE
206207
}
207208
}
208209

209-
private void loadMetadata() {
210+
protected Map loadMetadata() {
210211
final Properties meta = new Properties();
211212
Resource r = new ClassPathResource(PROJECT_META_FILE);
212213
try {
@@ -218,7 +219,7 @@ private void loadMetadata() {
218219
if (System.getProperty(GrailsApplication.ENVIRONMENT) != null) {
219220
meta.setProperty(GrailsApplication.ENVIRONMENT, System.getProperty(GrailsApplication.ENVIRONMENT));
220221
}
221-
applicationMeta = Collections.unmodifiableMap(meta);
222+
return Collections.unmodifiableMap(meta);
222223
}
223224

224225
/**
@@ -872,6 +873,17 @@ public void addArtefact(Class artefact) {
872873
}
873874
}
874875

876+
public boolean isWarDeployed() {
877+
Map metadata = getMetadata();
878+
if(metadata != null) {
879+
Object val = metadata.get(META_GRAILS_WAR_DEPLOYED);
880+
if(val != null && val.equals("true")) {
881+
return true;
882+
}
883+
}
884+
return false;
885+
}
886+
875887
public void setBeanClassLoader(ClassLoader classLoader) {
876888
this.beanClassLoader = classLoader;
877889
}

src/commons/org/codehaus/groovy/grails/commons/GrailsApplication.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,11 @@ public interface GrailsApplication extends ApplicationContextAware {
268268
* @param artefact The artefact to add
269269
*/
270270
void addArtefact(Class artefact);
271+
272+
/**
273+
* Returns true if this application has been deployed as a WAR file
274+
*
275+
* @return True if the application is WAR deployed
276+
*/
277+
boolean isWarDeployed();
271278
}

0 commit comments

Comments
 (0)