Skip to content

Commit

Permalink
fix for GRAILS-1943
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.codehaus.org/grails/trunk@6273 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
  • Loading branch information
graeme committed Dec 7, 2007
1 parent dc24b9b commit f02126a
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 414 deletions.
1 change: 1 addition & 0 deletions scripts/War.groovy
Expand Up @@ -105,6 +105,7 @@ target (war: "The implementation target") {

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

Ant.replace(file:"${basedir}/staging/WEB-INF/applicationContext.xml",
Expand Down
Expand Up @@ -99,6 +99,7 @@ public class DefaultGrailsApplication extends GroovyObjectSupport implements Gra
private static final String CONFIG_BINDING_GRAILS_HOME = "grailsHome";
private static final String CONFIG_BINDING_APP_NAME = "appName";
private static final String CONFIG_BINDING_APP_VERSION = "appVersion";
private static final String META_GRAILS_WAR_DEPLOYED = "grails.war.deployed";

/**
* Creates a new empty Grails application
Expand All @@ -124,7 +125,7 @@ public DefaultGrailsApplication(final Class[] classes, GroovyClassLoader classLo
}
this.allClasses = classes;
this.cl = classLoader;
loadMetadata();
this.applicationMeta = loadMetadata();
}


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

try {
loadMetadata();
this.applicationMeta = loadMetadata();
loadGrailsApplicationFromResources(resourceLoader.getResources());
} catch (IOException e) {
throw new GrailsConfigurationException("I/O exception loading Grails: " + e.getMessage(), e);
Expand Down Expand Up @@ -206,7 +207,7 @@ private void loadGrailsApplicationFromResources(Resource[] resources) throws IOE
}
}

private void loadMetadata() {
protected Map loadMetadata() {
final Properties meta = new Properties();
Resource r = new ClassPathResource(PROJECT_META_FILE);
try {
Expand All @@ -218,7 +219,7 @@ private void loadMetadata() {
if (System.getProperty(GrailsApplication.ENVIRONMENT) != null) {
meta.setProperty(GrailsApplication.ENVIRONMENT, System.getProperty(GrailsApplication.ENVIRONMENT));
}
applicationMeta = Collections.unmodifiableMap(meta);
return Collections.unmodifiableMap(meta);
}

/**
Expand Down Expand Up @@ -872,6 +873,17 @@ public void addArtefact(Class artefact) {
}
}

public boolean isWarDeployed() {
Map metadata = getMetadata();
if(metadata != null) {
Object val = metadata.get(META_GRAILS_WAR_DEPLOYED);
if(val != null && val.equals("true")) {
return true;
}
}
return false;
}

public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
Expand Down
Expand Up @@ -268,4 +268,11 @@ public interface GrailsApplication extends ApplicationContextAware {
* @param artefact The artefact to add
*/
void addArtefact(Class artefact);

/**
* Returns true if this application has been deployed as a WAR file
*
* @return True if the application is WAR deployed
*/
boolean isWarDeployed();
}

0 comments on commit f02126a

Please sign in to comment.