From: <fg...@us...> - 2006-11-16 10:09:39
|
Revision: 127 http://svn.sourceforge.net/openutils/?rev=127&view=rev Author: fgiust Date: 2006-11-16 02:09:39 -0800 (Thu, 16 Nov 2006) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.3 Added Paths: ----------- tags/openutils-deployment-1.0.3/ tags/openutils-deployment-1.0.3/pom.xml tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Removed Paths: ------------- tags/openutils-deployment-1.0.3/pom.xml tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Copied: tags/openutils-deployment-1.0.3 (from rev 117, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.3/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.3/pom.xml 2006-11-16 10:09:39 UTC (rev 127) @@ -1,70 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>net.sourceforge.openutils</groupId> - <artifactId>openutils</artifactId> - <version>2</version> - <relativePath>../openutils-parent</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.1-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.0.1</version> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>2.0</version> - <optional>true</optional> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.4</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.13</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: tags/openutils-deployment-1.0.3/pom.xml (from rev 126, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.3/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.3/pom.xml 2006-11-16 10:09:39 UTC (rev 127) @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils</artifactId> + <version>2</version> + <relativePath>../openutils-parent</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.3</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0</version> + <optional>true</optional> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.13</version> + <scope>test</scope> + </dependency> + </dependencies> + + <scm> + <connection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.3</connection> + <developerConnection>scm:svn:https://svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.3</developerConnection> + <url>http://svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.3</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-15 17:45:28 UTC (rev 117) +++ tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 10:09:39 UTC (rev 127) @@ -1,155 +0,0 @@ -package it.openutils.deployment.spring; - -import java.io.File; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; - -import javax.servlet.ServletContext; - -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; -import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; -import org.springframework.web.context.ServletContextAware; - - -/** - * @author fgiust - * @version $Id: $ - */ -public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware -{ - - private String fileLocation; - - private String defaultEnvironment; - - private ServletContext servletContext; - - /** - * Logger. - */ - private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); - - /** - * {@inheritDoc} - */ - public void setServletContext(ServletContext servletContext) - { - this.servletContext = servletContext; - } - - /** - * Setter for <code>fileLocation</code>. - * @param fileLocation The fileLocation to set. - */ - public void setFileLocation(String fileLocation) - { - this.fileLocation = fileLocation; - } - - /** - * Setter for <code>defaultEnvironment</code>. - * @param defaultEnvironment The defaultEnvironment to set. - */ - public void setDefaultEnvironment(String defaultEnvironment) - { - this.defaultEnvironment = defaultEnvironment; - } - - private String getRootPath() - { - if (servletContext != null) - { - return servletContext.getRealPath("/"); - } - return "src/main/webapp/"; - } - - private URL getResource(String resource) - { - URL url = null; - - if (servletContext != null) - { - try - { - url = servletContext.getResource(resource); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - } - else - { - try - { - return new File(getRootPath(), resource).toURL(); - } - catch (MalformedURLException e) - { - log.error(e.getMessage(), e); - } - // test - } - return url; - } - - /** - * {@inheritDoc} - */ - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException - { - if (fileLocation != null) - { - - String hostname = null; - - try - { - hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); - } - catch (UnknownHostException e) - { - log.error(e.getMessage()); - } - - System.setProperty("env", hostname); - - String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); - URL propertyUrl = null; - - propertyUrl = getResource(resolvedLocation); - - if (propertyUrl == null) - { - log.info("No environment specific properties found at {}, using default", resolvedLocation); - resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); - - propertyUrl = getResource(resolvedLocation); - - } - - if (propertyUrl == null) - { - log.error("No default properties found at {}", resolvedLocation); - } - else - { - Resource resource = new UrlResource(propertyUrl); - super.setLocation(resource); - } - } - - super.postProcessBeanFactory(beanFactory); - } - -} Copied: tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 125, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-1.0.3/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2006-11-16 10:09:39 UTC (rev 127) @@ -0,0 +1,170 @@ +package it.openutils.deployment.spring; + +import java.io.File; +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; + +import javax.servlet.ServletContext; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; +import org.springframework.core.io.Resource; +import org.springframework.core.io.UrlResource; +import org.springframework.web.context.ServletContextAware; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +{ + + private String fileLocation; + + private String defaultEnvironment; + + private ServletContext servletContext; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * {@inheritDoc} + */ + public void setServletContext(ServletContext servletContext) + { + this.servletContext = servletContext; + } + + /** + * Setter for <code>fileLocation</code>. + * @param fileLocation The fileLocation to set. + */ + public void setFileLocation(String fileLocation) + { + this.fileLocation = fileLocation; + } + + /** + * Setter for <code>defaultEnvironment</code>. + * @param defaultEnvironment The defaultEnvironment to set. + */ + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + private String getRootPath() + { + if (servletContext != null) + { + return servletContext.getRealPath("/"); + } + return "src/main/webapp/"; + } + + private URL getResource(String resource) + { + URL url = null; + + if (servletContext != null) + { + try + { + url = servletContext.getResource(resource); + + if (url != null) + { + // check needed for servletUnit + // we need to check for a connection because getResource always returns a URL, also if the resource + // doesn't exists + url.openConnection().connect(); + } + + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + catch (IOException e) + { + // ignore, URL is not a valid resource + url = null; + } + } + else + { + try + { + return new File(getRootPath(), resource).toURL(); + } + catch (MalformedURLException e) + { + log.error(e.getMessage(), e); + } + // test + } + return url; + } + + /** + * {@inheritDoc} + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException + { + if (fileLocation != null) + { + + String hostname = null; + + try + { + hostname = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); + } + catch (UnknownHostException e) + { + log.error(e.getMessage()); + } + + System.setProperty("env", hostname); + + String resolvedLocation = StringUtils.replace(fileLocation, "${env}", hostname); + URL propertyUrl = null; + + propertyUrl = getResource(resolvedLocation); + + if (propertyUrl == null) + { + log.info("No environment specific properties found at {}, using default", resolvedLocation); + resolvedLocation = StringUtils.replace(fileLocation, "${env}", this.defaultEnvironment); + + propertyUrl = getResource(resolvedLocation); + + } + + if (propertyUrl == null) + { + log.error("No default properties found at {}", resolvedLocation); + } + else + { + Resource resource = new UrlResource(propertyUrl); + super.setLocation(resource); + } + } + + super.postProcessBeanFactory(beanFactory); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |