Skip to content

Commit

Permalink
maven build profile for cloudforge.
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo1905 committed Jul 21, 2012
1 parent c750fa4 commit dc2f7fe
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ zktodo2test.dat.properties
/.settings
/zktodo2test.dat.script
/nohup.out
/zktodo2-cf.zip
28 changes: 28 additions & 0 deletions cloudforge/dburl-context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
">

<bean id="vcapservices" class="org.intalio.cloudfoundry.vcapservices.impl.VCapServices" />

<!--
If we are in cloudfoundry, the environment variable VCAP_SERVICES
contains the database connection in JSON.
The factory will part VCAP_SERVICES when it exists and create from the first
postgres.* service the database connection URL.
If it does not exist, the factory will simply use the value of
the system property"-DDATABASE_URL=postgres://user:password@hostname/dbname"
-->
<bean id="dbUrl" factory-bean="vcapservices" factory-method="getConnectionAsURI">
<constructor-arg value="DATABASE_URL" />
<constructor-arg value="postgresql" />
<constructor-arg value="/^postgres.*/" />
</bean>

</beans>
23 changes: 19 additions & 4 deletions cloudfoundry.build.and.run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ First:

Then:

Edit the manifest.yml file and change the URL:
url: my-zktodo2.cloudfoundry.com
Edit the manifest.yml file and change both the "name" entry and the "url" entry:

name: my-zktodo2

url: my-zktodo2.cloudfoundry.com

Build:

Use the cloudforge maven profile to include the necessary utility jars into the final war:

mvn -P cloudforge clean install

Deploy first time:

Deploy:
vmc push

vmc push
Update after changes:

vmc update

End.

4 changes: 2 additions & 2 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
zktodo2-cf.zip:
name: zktodo2
name: simbo1905
framework:
name: standalone
info:
Expand All @@ -11,7 +11,7 @@ applications:
runtime: java7
command: java -Djava.io.tmpdir=. -Dorg.apache.jasper.compiler.disablejsr199=true
-Xmx512M -jar jetty-runner-jmx.jar --port ${VCAP_APP_PORT} zktodo2.war
url: zktodo2.cloudfoundry.com
url: simbo1905.cloudfoundry.com
mem: 512M
instances: 1
services:
Expand Down
98 changes: 58 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<groupId>org.zkforge.zktodo2</groupId>
<artifactId>zktodo2</artifactId>
<packaging>war</packaging>
<version>1.8.0</version>
<version>1.8.1</version>
<name>zktodo2</name>
<url>http://www.slideshare.net/simbo1905/design-patterns-in-zk-java-mvvm-as-modelviewbinder</url>
<repositories>
<repository>
<id>zk repository</id>
<url>http://mavensync.zkoss.org/maven2</url>
</repository>
<repository>
<id>intalio.org</id>
<url>http://www.intalio.org/public/maven2</url>
</repository>
<repository>
<id>intalio.org</id>
<url>http://www.intalio.org/public/maven2</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -168,13 +168,6 @@
<scope>runtime</scope>
<version>${dom4j.version}</version>
</dependency>
<!-- cloudfoundry dependency. found in intalio.org repo -->
<dependency>
<groupId>org.intalio.cloudfoundry</groupId>
<artifactId>vcapservices</artifactId>
<version>${vcapservices.version}</version>
<scope>compile</scope>
</dependency>
<!-- below are optional runtime database pool and drivers -->
<dependency>
<groupId>hsqldb</groupId>
Expand Down Expand Up @@ -266,31 +259,12 @@
<attribute name="Main-Class" value="org.mortbay.jetty.runner.Runner" />
</manifest>
</jar>
<zip destfile="${basedir}/zktodo2-cf.zip"
basedir="${project.build.directory}"
includes="jetty-runner-jmx.jar,zktodo2.war">
</zip>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<configuration>
<task>
<echo>Cleaning cloudfoundry zip in the root folder</echo>
</task>
<tasks>
<delete file="${basedir}/zktodo2-cf.zip"/>
</tasks>
</configuration>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -321,27 +295,71 @@
</build>
<profiles>
<profile>
<id>openshift</id>
<id>cloudforge</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
<webXml>src/main/webapp/WEB-INF/openshift.web.xml</webXml>
<webResources>
<resource>
<directory>${basedir}/cloudforge</directory>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<jar destfile="${project.build.directory}/jetty-runner-jmx.jar">
<zipfileset src="${project.build.directory}/dependency/jetty-jmx.jar" />
<zipfileset src="${project.build.directory}/dependency/jetty-runner.jar" />
<manifest>
<attribute name="Main-Class" value="org.mortbay.jetty.runner.Runner" />
</manifest>
</jar>
<zip destfile="${basedir}/zktodo2-cf.zip"
basedir="${project.build.directory}"
includes="jetty-runner-jmx.jar,zktodo2.war">
</zip>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>clean</id>
<configuration>
<task>
<echo>Cleaning cloudfoundry zip in the root folder</echo>
</task>
<tasks>
<delete file="${basedir}/zktodo2-cf.zip" />
</tasks>
</configuration>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- classloader issues on JBossAS702 to mark dom4j as provided -->
<!-- cloudfoundry dependency. found in intalio.org repo -->
<dependency>
<artifactId>dom4j</artifactId>
<groupId>dom4j</groupId>
<scope>provided</scope>
<version>${dom4j.version}</version>
<groupId>org.intalio.cloudfoundry</groupId>
<artifactId>vcapservices</artifactId>
<version>${vcapservices.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
Expand Down
19 changes: 19 additions & 0 deletions src/main/webapp/WEB-INF/classes/dburl-context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
">

<!--
DATABASE_URL should be set with either "-DDATABASE_URL=postgres://user:password@hostname/dbname"
else with an environment variable.
-->
<bean class="java.net.URI" id="dbUrl">
<constructor-arg value="${DATABASE_URL}" />
</bean>

</beans>
41 changes: 12 additions & 29 deletions src/main/webapp/WEB-INF/classes/default.datasource-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
">

<!--
Expand All @@ -21,34 +21,17 @@
</bean>

<!--
DATABASE_URL should be set with either "-DDATABASE_URL=postgres://user:password@hostname/dbname"
else with an environment variable.
If we are in cloudfoundry, the environment variable VCAP_SERVICES
contains the database connection in JSON.
The factory will part VCAP_SERVICES when it exists and create from the first
postgres.* service the database connection URL.
If it does not exist, the factory will simply use the value of
the system property as usual.
-->
<bean id="vcapservices" class="org.intalio.cloudfoundry.vcapservices.impl.VCapServices"/>
<bean id="dbUrl"
factory-bean="vcapservices"
factory-method="getConnectionAsURI">
<constructor-arg value="DATABASE_URL" />
<constructor-arg value="postgresql" />
<constructor-arg value="/^postgres.*/" />
</bean>

<!--
Connection pool config will parse the properties held in DATABASE_URL and xyz.zktodo2.properties
Connection pool config will parse the properties held in URL bean "dbUrl" and xyz.zktodo2.properties.
The bean "dbUrl" is defined in a separate spring config file as different cloud environments require
different factories to resolve the database properties in a given cloud environment.
-->
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="#{ 'jdbc:postgresql://' + @dbUrl.getHost() + @dbUrl.getPath() }"/>
<property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }"/>
<property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }"/>
<bean class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url"
value="#{ 'jdbc:postgresql://' + @dbUrl.getHost() + @dbUrl.getPath() }" />
<property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }" />
<property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }" />
</bean>

<!--
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<display-name>zktodo2</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/application-context.xml,classpath:default.datasource-context.xml</param-value>
<param-value>/WEB-INF/spring/application-context.xml,classpath:default.datasource-context.xml,classpath:dburl-context.xml</param-value>
</context-param>
<!-- Spring -->
<listener>
Expand Down

0 comments on commit dc2f7fe

Please sign in to comment.