This is an automated email from the ASF dual-hosted git repository. snoopdave pushed a commit to branch snoopdave/fix-jetty-run in repository https://gitbox.apache.org/repos/asf/roller.git
commit 44dafa3622b58da74503023271ae106f552b3113 Author: David M. Johnson <[email protected]> AuthorDate: Sun Sep 17 14:24:58 2023 -0400 Add a Jetty event listener to start Derby when Roller is run via mvn jetty:run. --- app/pom.xml | 67 +++++---------------- .../org/apache/roller/weblogger/TestUtils.java | 2 +- app/src/test/resources/jetty.xml | 8 ++- db-utils/pom.xml | 62 ++++++++++++++++++++ .../apache/roller/testutils/DerbyLifeCycle.java | 68 ++++++++++++++++++++++ it-selenium/pom.xml | 36 ------------ pom.xml | 15 ++--- 7 files changed, 156 insertions(+), 102 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index a80eba6bd..df6d1da22 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -54,7 +54,6 @@ limitations under the License. <maven-surefire.version>2.22.2</maven-surefire.version> <maven-antrun.version>1.0b3</maven-antrun.version> <rome.version>1.19.0</rome.version> <!-- locked in place since next version removes popono --> - <slf4j.version>1.7.36</slf4j.version> <spring.version>5.3.27</spring.version> <spring.security.version>5.8.3</spring.security.version> <struts.version>2.5.29</struts.version> @@ -611,19 +610,21 @@ limitations under the License. </webApp> <jettyXmls>src/test/resources/jetty.xml</jettyXmls> <systemProperties> - <systemProperty> - <name>roller.custom.config</name> - <value>${project.build.directory}/test-classes/roller-jettyrun.properties</value> - </systemProperty> + <roller.custom.config> + ${project.build.directory}/test-classes/roller-jettyrun.properties + </roller.custom.config> </systemProperties> </configuration> <dependencies> - <!-- Dependencies needed when using mvn jetty:run, not mvn test --> + <dependency> + <groupId>org.apache.roller</groupId> + <artifactId>db-utils</artifactId> + <version>6.1.2</version> + </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> - <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.derby</groupId> @@ -643,49 +644,9 @@ limitations under the License. </dependencies> </plugin> - <!-- Activates the Derby database for unit tests and mvn jetty:run - <plugin> - <groupId>com.btmatthews.maven.plugins.inmemdb</groupId> - <artifactId>inmemdb-maven-plugin</artifactId> - - <configuration> - <daemon>true</daemon> - <type>derby</type> - <database>rollerdb</database> - <username>APP</username> - <password>APP</password> - <port>4224</port> - <sources> - <script> - <sourceFile>${project.basedir}/target/dbscripts/derby/createdb.sql</sourceFile> - </script> - </sources> - <skip>${skipTests}</skip> - </configuration> - - <executions> - <execution> - <id>run</id> - <phase>test-compile</phase> - <goals> - <goal>run</goal> - </goals> - </execution> - <execution> - <id>stop</id> - <phase>package</phase> - <goals> - <goal>stop</goal> - </goals> - </execution> - </executions> - - </plugin> - --> - <plugin> <artifactId>maven-resources-plugin</artifactId> - <version>3.2.0</version> + <version>3.3.1</version> <executions> @@ -714,7 +675,7 @@ limitations under the License. </goals> <configuration> <includeEmptyDirs>true</includeEmptyDirs> - <outputDirectory>${basedir}/target/dbscripts</outputDirectory> + <outputDirectory>${basedir}/target/classes/dbscripts</outputDirectory> <resources> <resource> <directory>${basedir}/src/main/resources/sql</directory> @@ -724,7 +685,7 @@ limitations under the License. </configuration> </execution> - <execution> + <!-- <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> @@ -742,7 +703,7 @@ limitations under the License. </resource> </resources> </configuration> - </execution> + </execution> --> </executions> @@ -804,7 +765,7 @@ limitations under the License. <property file="${basedir}/src/main/resources/sql/dbscripts.properties" /> <for list="${databases}" param="database" delimiter=" "> <sequential> - <mkdir dir="${basedir}/target/dbscripts/@{database}" /> + <mkdir dir="${basedir}/target/classes/dbscripts/@{database}" /> </sequential> </for> @@ -815,7 +776,7 @@ limitations under the License. controlTemplate ="control.vm" contextProperties="${basedir}/src/main/resources/sql/dbscripts.properties" templatePath ="${basedir}/src/main/resources/sql" - outputDirectory ="${basedir}/target/dbscripts" + outputDirectory ="${basedir}/target/classes/dbscripts" outputFile ="README.txt"/> </target> </configuration> diff --git a/app/src/test/java/org/apache/roller/weblogger/TestUtils.java b/app/src/test/java/org/apache/roller/weblogger/TestUtils.java index b68b55f9f..6dc96796a 100644 --- a/app/src/test/java/org/apache/roller/weblogger/TestUtils.java +++ b/app/src/test/java/org/apache/roller/weblogger/TestUtils.java @@ -74,7 +74,7 @@ public final class TestUtils { if (!WebloggerFactory.isBootstrapped()) { synchronized (TestUtils.class) { if (derbyManager == null) { - derbyManager = new DerbyManager("./target/testdb", "./target/dbscripts", 4224); + derbyManager = new DerbyManager("./target/testdb", "./target/classes/dbscripts", 4224); derbyManager.startDerby(); } } diff --git a/app/src/test/resources/jetty.xml b/app/src/test/resources/jetty.xml index 0809395b2..a31ca4c6d 100644 --- a/app/src/test/resources/jetty.xml +++ b/app/src/test/resources/jetty.xml @@ -20,7 +20,7 @@ <!-- Dummy values used only when testing with Jetty via mvn jetty:run --> -<Configure> +<Configure id="Server" class="org.eclipse.jetty.server.Server"> <New id="ds" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg> <Ref id="wac_ds"/> </Arg> @@ -50,4 +50,10 @@ </Arg> </New> + <Call name="addEventListener"> + <Arg> + <New class="org.apache.roller.testutils.DerbyLifeCycle"/> + </Arg> + </Call> + </Configure> diff --git a/db-utils/pom.xml b/db-utils/pom.xml new file mode 100644 index 000000000..f5bf9e9c7 --- /dev/null +++ b/db-utils/pom.xml @@ -0,0 +1,62 @@ +<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> + + <parent> + <groupId>org.apache.roller</groupId> + <artifactId>roller-project</artifactId> + <version>6.1.2</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <name>Apache Roller DB Utilities</name> + <artifactId>db-utils</artifactId> + <version>6.1.2</version> + + <build> + <plugins> + </plugins> + </build> + + <dependencies> + <!-- slf4j implementing the apache commons-logging interfaces --> + <!-- note: commons-logging needs to be excluded in all dependencies transitive depending on it. + See 2006 RFE https://issues.apache.org/jira/browse/MNG-1977 for maven's missing feature of global exclusions --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>${slf4j.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derbynet</artifactId> + <version>${derby.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <version>${derby.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${jetty.plugin.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> + <scope>compile</scope> + </dependency> + </dependencies> + +</project> diff --git a/db-utils/src/main/java/org/apache/roller/testutils/DerbyLifeCycle.java b/db-utils/src/main/java/org/apache/roller/testutils/DerbyLifeCycle.java new file mode 100644 index 000000000..8fa603b32 --- /dev/null +++ b/db-utils/src/main/java/org/apache/roller/testutils/DerbyLifeCycle.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. The ASF licenses this file to You + * under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. For additional information regarding + * copyright in this work, please see the NOTICE file in the top level + * directory of this distribution. + */ + +package org.apache.roller.testutils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.derby.drda.NetworkServerControl; +import org.eclipse.jetty.util.component.LifeCycle; +import java.io.PrintWriter; + +/** + * Enables start and stop Derby from the Maven Jetty plugin. + */ +public class DerbyLifeCycle implements LifeCycle.Listener { + private static final Log log = LogFactory.getFactory().getInstance(DerbyLifeCycle.class); + + private void setupDerby() { + System.setProperty("derby.system.home", "./target/derby"); + System.setProperty("derby.drda.portNumber", "4224"); + System.setProperty("derby.drda.host", "localhost"); + } + + @Override + public void lifeCycleStarting(LifeCycle event) { + log.info("**************"); + log.info("Starting Derby"); + log.info("**************"); + try { + setupDerby(); + NetworkServerControl server = new NetworkServerControl(); + server.start(new PrintWriter(System.out)); + try {Thread.sleep(2000);} catch (Exception ignored) {} + } catch (Exception e) { + log.error("Error starting Derby", e); + } + } + + @Override + public void lifeCycleStopped(LifeCycle event) { + log.info("**************"); + log.info("Stopping Derby"); + log.info("**************"); + try { + setupDerby(); + NetworkServerControl server = new NetworkServerControl(); + server.shutdown(); + try {Thread.sleep(2000);} catch (Exception ignored) {} + } catch (Exception e) { + log.error("Error stopping Derby", e); + } + } +} \ No newline at end of file diff --git a/it-selenium/pom.xml b/it-selenium/pom.xml index 652eb9316..8b11c7ead 100644 --- a/it-selenium/pom.xml +++ b/it-selenium/pom.xml @@ -152,42 +152,6 @@ </dependencies> </plugin> - <!-- Activates the Derby database during the integration test phase --> - <plugin> - <groupId>com.btmatthews.maven.plugins.inmemdb</groupId> - <artifactId>inmemdb-maven-plugin</artifactId> - <executions> - <execution> - <id>run</id> - <goals> - <goal>run</goal> - </goals> - <configuration> - <daemon>true</daemon> - <type>derby</type> - <database>rollerdb</database> - <username>APP</username> - <password>APP</password> - <port>4224</port> - <sources> - <script> - <sourceFile>${project.basedir}/target/roller-selenium-tests-${project.version}/WEB-INF/classes/dbscripts/derby/createdb.sql</sourceFile> - </script> - </sources> - </configuration> - </execution> - <execution> - <id>stop</id> - <!-- Moving later to verify phase from post-integration-test. Reason: Jetty shutdown wants - to close database or will raise error messages. --> - <phase>verify</phase> - <goals> - <goal>stop</goal> - </goals> - </execution> - </executions> - </plugin> - <!-- Activates the Roller application during the integration test phase --> <plugin> <groupId>org.eclipse.jetty</groupId> diff --git a/pom.xml b/pom.xml index c0550212d..3e6cefeac 100644 --- a/pom.xml +++ b/pom.xml @@ -44,12 +44,14 @@ limitations under the License. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <derby.version>10.11.1.1</derby.version> <jaxb.version>2.3.1</jaxb.version> - <jetty.version>10.0.15</jetty.version> + <jetty.plugin.version>10.0.16</jetty.plugin.version> <!-- Jetty 11 requires Jakarta package names --> <roller.version>6.1.2</roller.version> + <slf4j.version>1.7.36</slf4j.version> </properties> <modules> <module>app</module> + <module>db-utils</module> <!-- <module>it-selenium</module> --> </modules> @@ -85,7 +87,7 @@ limitations under the License. <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> - <version>${jetty.version}</version> + <version>${jetty.plugin.version}</version> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> @@ -95,15 +97,6 @@ limitations under the License. <rulesUri>file:version-rules.xml</rulesUri> </configuration> </plugin> - <plugin> - <groupId>com.btmatthews.maven.plugins.inmemdb</groupId> - <artifactId>inmemdb-maven-plugin</artifactId> - <version>1.4.3</version> - <configuration> - <monitorKey>inmemdb</monitorKey> - <monitorPort>11527</monitorPort> - </configuration> - </plugin> </plugins> </pluginManagement> </build>
