From: <fg...@us...> - 2007-01-27 19:56:18
|
Revision: 153 http://svn.sourceforge.net/openutils/?rev=153&view=rev Author: fgiust Date: 2007-01-27 11:56:19 -0800 (Sat, 27 Jan 2007) Log Message: ----------- [maven-scm] copy for tag openutils-deployment-1.0.4 Added Paths: ----------- tags/openutils-deployment-1.0.4/ tags/openutils-deployment-1.0.4/pom.xml tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Removed Paths: ------------- tags/openutils-deployment-1.0.4/pom.xml tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java Copied: tags/openutils-deployment-1.0.4 (from rev 146, trunk/openutils-deployment) Deleted: tags/openutils-deployment-1.0.4/pom.xml =================================================================== --- trunk/openutils-deployment/pom.xml 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-deployment-1.0.4/pom.xml 2007-01-27 19:56:19 UTC (rev 153) @@ -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>3</version> - <relativePath>..</relativePath> - </parent> - <artifactId>openutils-deployment</artifactId> - <name>openutils deployment tools</name> - <version>1.0.4-SNAPSHOT</version> - <description /> - <dependencies> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.2</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.1</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.4/pom.xml (from rev 152, trunk/openutils-deployment/pom.xml) =================================================================== --- tags/openutils-deployment-1.0.4/pom.xml (rev 0) +++ tags/openutils-deployment-1.0.4/pom.xml 2007-01-27 19:56:19 UTC (rev 153) @@ -0,0 +1,64 @@ +<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>3</version> + <relativePath>..</relativePath> + </parent> + <artifactId>openutils-deployment</artifactId> + <name>openutils deployment tools</name> + <version>1.0.4</version> + <description /> + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.2</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>2.0.1</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>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.2</version> + </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> + </dependencies> + + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.4</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-deployment-1.0.4</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-deployment-1.0.4</url> + </scm> +</project> \ No newline at end of file Deleted: tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java =================================================================== --- trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-04 15:46:29 UTC (rev 146) +++ tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:56:19 UTC (rev 153) @@ -1,170 +0,0 @@ -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); - } - -} Copied: tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (from rev 151, trunk/openutils-deployment/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java) =================================================================== --- tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java (rev 0) +++ tags/openutils-deployment-1.0.4/src/main/java/it/openutils/deployment/spring/EnvironmentPropertyConfigurer.java 2007-01-27 19:56:19 UTC (rev 153) @@ -0,0 +1,212 @@ +package it.openutils.deployment.spring; + +import java.io.FileNotFoundException; +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.util.ResourceUtils; +import org.springframework.web.context.ServletContextAware; + + +/** + * @author fgiust + * @version $Id: $ + */ +public class EnvironmentPropertyConfigurer extends PropertyPlaceholderConfigurer implements ServletContextAware +{ + + /** + * Application name (webapp name) variable. + */ + private static final String PROPERTY_APPL = "${appl}"; + + /** + * Environment (server name) variable. + */ + private static final String PROPERTY_ENV = "${env}"; + + /** + * Logger. + */ + private static Logger log = LoggerFactory.getLogger(EnvironmentPropertyConfigurer.class); + + /** + * @deprecated use defaultLocation + */ + @Deprecated + private String defaultEnvironment; + + private ServletContext servletContext; + + private String fileLocation; + + /** + * {@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. + * @deprecated use defaultLocation + */ + @Deprecated + public void setDefaultEnvironment(String defaultEnvironment) + { + this.defaultEnvironment = defaultEnvironment; + } + + /** + * {@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()); // should not happen + } + + if (hostname != null) + { + System.setProperty("env", hostname); + } + + String applName = getApplicationName(); + if (applName != null) + { + System.setProperty("appl", applName); + } + + URL propertyUrl = null; + + String replacedLocations = StringUtils.replace(fileLocation, PROPERTY_ENV, hostname); + replacedLocations = StringUtils.replace(replacedLocations, PROPERTY_APPL, applName); + + String[] locations = StringUtils.split(replacedLocations, ","); + + for (String loc : locations) + { + propertyUrl = getResource(StringUtils.strip(loc)); + if (propertyUrl != null) + { + break; + } + log.debug("Property file not found at {}", loc); + } + + if (propertyUrl == null && defaultEnvironment != null) + { + log.warn("Usage of \"defaultEnvironment\" is deprecated, please specify the fallback location " + + "as the last comma separated value in \"fileLocation\""); + propertyUrl = getResource(StringUtils.replace(fileLocation, PROPERTY_ENV, this.defaultEnvironment)); + + } + + if (propertyUrl == null) + { + log.error("No properties found at {}", replacedLocations); + } + else + { + Resource resource = new UrlResource(propertyUrl); + super.setLocation(resource); + } + } + + super.postProcessBeanFactory(beanFactory); + } + + 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 + { + url = ResourceUtils.getURL(resource); + } + catch (FileNotFoundException e) + { + // ignore, can be normal + } + } + return url; + } + + private String getApplicationName() + { + if (servletContext != null) + { + String url = servletContext.getRealPath("/"); + url = StringUtils.replace(url, "\\", "/"); + if (url.endsWith("/")) + { + url = StringUtils.substringBeforeLast(url, "/"); + } + + return StringUtils.substringAfterLast(url, "/"); + } + return null; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |