CCM NG: New devel bundle using Wildfly Swarm for runtime. Not tested yet!
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3758 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
76f810ab11
commit
c82fb5fde4
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'Z</maven.build.timestamp.format>
|
||||
<wildfly.swarm.version>1.0.0.Alpha5</wildfly.swarm.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.libreccm</groupId>
|
||||
<artifactId>libreccm-parent</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.libreccm</groupId>
|
||||
<artifactId>ccm-bundle-devel</artifactId>
|
||||
|
||||
<name>LibreCCM Devel Bundle</name>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Lesser GPL 2.1</name>
|
||||
<url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.libreccm</groupId>
|
||||
<artifactId>ccm-core</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>wildfly-swarm-undertow</artifactId>
|
||||
<version>${wildfly.swarm.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>wildfly-swarm-jpa</artifactId>
|
||||
<version>${wildfly.swarm.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>wildfly-swarm-datasources</artifactId>
|
||||
<version>${wildfly.swarm.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.wildfly.swarm</groupId>
|
||||
<artifactId>wildfly-swarm-plugin</artifactId>
|
||||
<version>${wildfly.swarm.version}</version>
|
||||
<configuration>
|
||||
<mainClass>org.libreccm.wildfly.swarm.Bundle</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>package</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* Copyright (C) 2015 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.wildfly.swarm;
|
||||
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
|
||||
import org.wildfly.swarm.config.datasources.DataSource;
|
||||
import org.wildfly.swarm.config.datasources.DataSourceConfigurator;
|
||||
import org.wildfly.swarm.config.datasources.JDBCDriver;
|
||||
import org.wildfly.swarm.config.datasources.JDBCDriverConfigurator;
|
||||
import org.wildfly.swarm.container.Container;
|
||||
import org.wildfly.swarm.datasources.DatasourcesFraction;
|
||||
import org.wildfly.swarm.jpa.JPAFraction;
|
||||
import org.wildfly.swarm.undertow.WARArchive;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class Bundle {
|
||||
|
||||
public static void main(final String[] args) throws Exception {
|
||||
|
||||
final Properties config = getConfiguration();
|
||||
|
||||
final Container container = new Container();
|
||||
|
||||
final JDBCDriverConfigurator configurator
|
||||
= new JDBCDriverConfigurator() {
|
||||
|
||||
@Override
|
||||
public void configure(final JDBCDriver driver) {
|
||||
driver.driverDatasourceClassName(config.getProperty(
|
||||
"db.driver.datasource.classname"));
|
||||
driver.xaDatasourceClass(config.getProperty(
|
||||
"db.xa.datasource.classname"));
|
||||
driver.driverModuleName("db.driver.module.name");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final DataSourceConfigurator<?> dsConfigurator
|
||||
= new DataSourceConfigurator() {
|
||||
|
||||
@Override
|
||||
public void configure(final DataSource dataSource) {
|
||||
dataSource.driverName("db-driver");
|
||||
dataSource.connectionUrl(
|
||||
config.getProperty("db.connection.url"));
|
||||
dataSource.userName(config.getProperty("db.user.name"));
|
||||
dataSource.password(config.getProperty("db.password"));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
container.fraction(new DatasourcesFraction().jdbcDriver("db-driver",
|
||||
configurator)
|
||||
.dataSource("java:/comp/env/jdbc/ccm-core/db", dsConfigurator));
|
||||
|
||||
container.fraction(new JPAFraction().inhibitDefaultDatasource()
|
||||
.defaultDatasource("java:/comp/env/jdbc/ccm-core/db"));
|
||||
|
||||
//Remove when CCM installer is available
|
||||
setup(config);
|
||||
|
||||
container.start();
|
||||
|
||||
final WARArchive deployment = ShrinkWrap.create(WARArchive.class);
|
||||
deployment.addAsWebInfResource(
|
||||
new ClassLoaderAsset(
|
||||
"META-INF/persistence.xml",
|
||||
Bundle.class.getClassLoader()),
|
||||
"classes/META-INF/persistence.xml");
|
||||
deployment.addAllDependencies();
|
||||
|
||||
container.deploy(deployment);
|
||||
}
|
||||
|
||||
private static Properties getConfiguration() throws IOException {
|
||||
final String defaultConfig = String.format(
|
||||
"%s/configuration.properties", System.getProperty("user.dir"));
|
||||
final String config = System.getProperty("ccm.config", defaultConfig);
|
||||
|
||||
final FileInputStream stream = new FileInputStream(config);
|
||||
final Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static Properties getSetupParameters() throws IOException {
|
||||
final String defaultParameters = String.format(
|
||||
"%s/setup.properties", System.getProperty("user.dir"));
|
||||
final String parameters = System.getProperty("ccm.setup.parameters",
|
||||
defaultParameters);
|
||||
|
||||
final FileInputStream stream = new FileInputStream(parameters);
|
||||
final Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
|
||||
return properties;
|
||||
|
||||
}
|
||||
|
||||
private static void setup(final Properties config) throws
|
||||
ClassNotFoundException, SQLException, IOException {
|
||||
|
||||
final Properties setupParameters = getSetupParameters();
|
||||
|
||||
Class.forName("org.h2.Driver");
|
||||
try (final Connection connection = DriverManager.getConnection(config
|
||||
.getProperty("db.connection.url"));
|
||||
final Statement statement = connection.createStatement()) {
|
||||
|
||||
final ResultSet result = statement.executeQuery(
|
||||
"SELECT COUNT(*) FROM USERS WHERE NAME NOT LIKE 'public-user'");
|
||||
result.next();
|
||||
final int numberOfUsers = result.getInt(1);
|
||||
result.close();
|
||||
|
||||
if (numberOfUsers <= 0) {
|
||||
final String adminName = setupParameters.getProperty(
|
||||
"admin.name");
|
||||
final String adminEmail = setupParameters.getProperty(
|
||||
"admin.email");
|
||||
final String adminGivenName = setupParameters.getProperty(
|
||||
"admin.givenname");
|
||||
final String adminFamilyName = setupParameters.getProperty(
|
||||
"admin.familyname");
|
||||
final String adminPassword = setupParameters.getProperty(
|
||||
"admin.password");
|
||||
|
||||
statement.executeUpdate(String.format(
|
||||
"INSERT INTO PARTIES(PARTY_ID, NAME) "
|
||||
+ "VALUES(-10, '%s')",
|
||||
adminName));
|
||||
statement.executeUpdate(String.format(
|
||||
"INSERT INTO USERS(PARTY_ID, GIVEN_NAME, FAMILY_NAME, EMAIL_ADDRESS, PASSWORD) "
|
||||
+ "VALUES (-10, '%s', '%s', '%s', '%s'),",
|
||||
adminGivenName,
|
||||
adminFamilyName,
|
||||
adminEmail,
|
||||
adminPassword
|
||||
));
|
||||
statement.executeUpdate("INSERT INTO CCM_ROLES(roleId, name) "
|
||||
+ "VALUES(-10, 'admin'");
|
||||
statement.executeUpdate("INSERT INTO ROLE_MEMBERSHIPS("
|
||||
+ "MEMBERSHIP_ID, MEMBER_ID, ROLE_ID) "
|
||||
+ "VALUES(-10, -10, 10)");
|
||||
|
||||
statement.close();
|
||||
}
|
||||
|
||||
//} catch(SQLException ex) {
|
||||
} finally {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
author: Jens Pelzetter
|
||||
-->
|
||||
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="LibreCCM" transaction-type="JTA">
|
||||
|
||||
<!--
|
||||
Enforce JPA provider
|
||||
Not really necessary here because we don't use any Hibernate
|
||||
specific features, but makes it easier to manage to database
|
||||
creation scripts.
|
||||
-->
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
|
||||
<jta-data-source>java:/comp/env/jdbc/ccm-core/db</jta-data-source>
|
||||
|
||||
<properties>
|
||||
<!-- Properties for Hibernate -->
|
||||
<property name="hibernate.hbm2ddl.auto" value="verify"/>
|
||||
<property name="hibernate.connection.autocommit" value="false" />
|
||||
<property name="hibernate.id.new_generator_mappings" value="true"/>
|
||||
<property name="hibernate.id.new_generator_mappings" value="true"/>
|
||||
|
||||
<!--
|
||||
Properties for Hibernate Envers
|
||||
We are using the ValidityAuditStrategy here because it is faster
|
||||
when querying data than the DefaultStrategy
|
||||
-->
|
||||
<property name="org.hibernate.envers.audit_strategy"
|
||||
value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
|
||||
</properties>
|
||||
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
Loading…
Reference in New Issue