Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #4031 - Update Servlet - Create a Faces application guide #4032

Merged
merged 6 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ jobs:
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: 'maven'
- name: Build with Maven
run: mvn --no-transfer-progress -B -T 8 install
run: mvn --no-transfer-progress -B -T 1 install
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ runner.os != 'Windows' }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
cache: 'maven'
distribution: 'temurin'
java-version: 21
server-id: ossrh
Expand Down
46 changes: 39 additions & 7 deletions docs/src/site/markdown/servlet/create_a_faces_application.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ create the ```pom.xml``` file with the content as below.
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>
<groupId>cloud.piranha.guides.servlet</groupId>
<groupId>cloud.piranha.test.servlet</groupId>
<artifactId>faces</artifactId>
<version>24.10.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Create a Jakarta Faces application</name>
<properties>
<java.version>21</java.version>
<!-- dependencies -->
<junit.version>5.11.0</junit.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.5.0</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
<mojarra.version>4.0.7</mojarra.version>
<weld.version>5.1.3.Final</weld.version>
<!-- other -->
<java.version>21</java.version>
<piranha.distribution>servlet</piranha.distribution>
<piranha.version>24.9.0</piranha.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<weld.version>5.1.3.Final</weld.version>
<!-- plugins -->
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.5.0</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -107,6 +111,7 @@ create the ```pom.xml``` file with the content as below.
</executions>
<configuration>
<distribution>servlet</distribution>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
Expand All @@ -129,6 +134,12 @@ create the ```pom.xml``` file with the content as below.
</goals>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -138,6 +149,25 @@ create the ```pom.xml``` file with the content as below.
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>package</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Expand Down Expand Up @@ -254,6 +284,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

public class HelloIT {

private String portNumber = System.getProperty("httpPort");

@Test
public void testHelloFacesXhtml() throws Exception {
Expand All @@ -263,7 +295,7 @@ public class HelloIT {
.followRedirects(ALWAYS)
.build();
HttpRequest request = HttpRequest
.newBuilder(new URI("http://localhost:8080/faces/hellofaces.xhtml"))
.newBuilder(new URI("http://localhost:" + portNumber + "/faces/hellofaces.xhtml"))
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
assertTrue(response.body().contains("Hello from Jakarta Faces!"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class StopMojo extends AbstractMojo {
*/
public StopMojo() {
}

@Override
public void execute() throws MojoExecutionException {
if (!skip) {
Expand All @@ -73,7 +73,7 @@ public void execute() throws MojoExecutionException {
*/
File pidFile = new File(runtimeDirectory, "tmp/piranha.pid");
String pid = "";

if (pidFile.exists()) {
pid = Files.readString(pidFile.toPath());
}
Expand All @@ -98,6 +98,21 @@ public void execute() throws MojoExecutionException {
* If the process is still active destroy it forcibly.
*/
ProcessHandle.of(Long.parseLong(pid.trim())).ifPresent(p -> {
int count = 0;
System.out.print("Waiting for Piranha to stop ");
while (p.isAlive()) {
try {
Thread.sleep(1000);
count++;
System.out.print(".");
} catch (InterruptedException ie) {
}
if (count == 60) {
break;
}
}
System.out.println();

if (p.isAlive()) {
System.err.println("Process still alive, destroying forcibly");
p.destroyForcibly();
Expand Down
46 changes: 38 additions & 8 deletions test/servlet/faces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

1. Drop the parent part below
2. Change the name of the project to read 'Create a Jakarta Faces application'
3. Change the version to the latest released version of Piranha
3. Change the piranha.version to the latest released version of Piranha

-->
<parent>
Expand All @@ -29,16 +29,20 @@
<packaging>war</packaging>
<name>Piranha - Test - Servlet - Jakarta Faces application</name>
<properties>
<java.version>21</java.version>
<!-- dependencies -->
<junit.version>5.11.0</junit.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.5.0</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
<mojarra.version>4.0.7</mojarra.version>
<weld.version>5.1.3.Final</weld.version>
<!-- other -->
<java.version>21</java.version>
<piranha.distribution>servlet</piranha.distribution>
<piranha.version>24.9.0</piranha.version>
<piranha.version>${project.version}</piranha.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<weld.version>5.1.3.Final</weld.version>
<!-- plugins -->
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>3.5.0</maven-failsafe-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -102,7 +106,8 @@
</execution>
</executions>
<configuration>
<distribution>servlet</distribution>
<distribution>${piranha.distribution}</distribution>
<httpPort>${httpPort}</httpPort>
</configuration>
</plugin>
<plugin>
Expand All @@ -125,6 +130,12 @@
</goals>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<httpPort>${httpPort}</httpPort>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -134,6 +145,25 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>package</phase>
<configuration>
<portNames>
<portName>httpPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4 changes: 3 additions & 1 deletion test/servlet/faces/src/test/java/hello/HelloIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.junit.jupiter.api.Test;

public class HelloIT {

private String portNumber = System.getProperty("httpPort");

@Test
public void testHelloFacesXhtml() throws Exception {
Expand All @@ -20,7 +22,7 @@ public void testHelloFacesXhtml() throws Exception {
.followRedirects(ALWAYS)
.build();
HttpRequest request = HttpRequest
.newBuilder(new URI("http://localhost:8080/faces/hellofaces.xhtml"))
.newBuilder(new URI("http://localhost:" + portNumber + "/faces/hellofaces.xhtml"))
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
assertTrue(response.body().contains("Hello from Jakarta Faces!"));
Expand Down
15 changes: 15 additions & 0 deletions test/servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@

<name>Piranha - Test - Servlet - Project</name>

<!--

Make sure the Piranha Servlet distribution is available before
attempting to build any of the modules.

-->
<dependencies>
<dependency>
<groupId>cloud.piranha.dist</groupId>
<artifactId>piranha-dist-servlet</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<modules>
<module>faces</module>
<module>hello</module>
Expand Down
Loading