diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4779b01..332b919 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -32,15 +32,9 @@ jobs: with: distribution: 'temurin' java-version: ${{ matrix.java_version }} - - name: Maven Build + - name: Maven Build & Test run: | mvn --show-version \ --no-transfer-progress \ --activate-profiles staging \ install - - name: Run test - run: | - mvn --no-transfer-progress \ - --activate-profiles staging \ - --file src/test \ - install diff --git a/README.md b/README.md index 88527ba..661eb07 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,259 @@ -Pre-requisite +# Maven Embedded GlassFish Plugin -To build this project, JDK 11 is required. +A Maven plugin for managing Embedded GlassFish server instances during the build lifecycle. + +## Quick Start + +Run your project's main artifact on Embedded GlassFish directly from command line without modifying your `pom.xml`: + +```bash +mvn org.glassfish.embedded:embedded-glassfish-maven-plugin:7.1-SNAPSHOT:run -Dglassfish.version=7.0.25 +``` + +Or add the plugin to your `pom.xml`: + +```xml + + org.glassfish.embedded + embedded-glassfish-maven-plugin + 7.1-SNAPSHOT + + 7.0.25 + + +``` + +Start the server with your application and wait until it stops: +```bash +mvn embedded-glassfish:run +``` + +## Prerequisites + +- JDK 11 or higher +- Maven 3.6.3 or higher + +## Basic Usage + +### Command Line + +Start server in background: +```bash +mvn embedded-glassfish:start +``` + +Deploy application: +```bash +mvn embedded-glassfish:deploy +``` + +Stop server: +```bash +mvn embedded-glassfish:stop +``` + +### Integration Testing + +```xml + + org.glassfish.embedded + embedded-glassfish-maven-plugin + 7.1-SNAPSHOT + + + start-server + pre-integration-test + + start + deploy + + + + stop-server + post-integration-test + + undeploy + stop + + + + +``` + +## Goals Overview + +| Goal | Description | Default Phase | +|------|-------------|---------------| +| [`start`](#start) | Starts an Embedded GlassFish server | pre-integration-test | +| [`stop`](#stop) | Stops the Embedded GlassFish server | post-integration-test | +| [`deploy`](#deploy) | Deploys an application to the server | pre-integration-test | +| [`undeploy`](#undeploy) | Undeploys an application from the server | post-integration-test | +| [`run`](#run) | Starts server and keeps it running | none | +| [`admin`](#admin) | Executes admin commands | none | + +## Configuration + +### Basic Configuration + +```xml + + org.glassfish.embedded + embedded-glassfish-maven-plugin + 7.1-SNAPSHOT + + 8080 + ${project.build.directory}/${project.build.finalName}.war + + +``` + +- `port` - HTTP port number for the server (default: 8080) +- `app` - Path to the application artifact to deploy (default: main artifact) + +### Automatic Artifact Deployment + +The plugin automatically detects and deploys your project's main artifact without requiring explicit configuration: + +```xml + + org.glassfish.embedded + embedded-glassfish-maven-plugin + 7.1-SNAPSHOT + + + + +``` + +**Note:** Currently assumes WAR packaging. For other artifact types, specify the `app` parameter explicitly. + +### Admin Commands + +Execute administrative commands on the running server: + +```xml + + org.glassfish.embedded + embedded-glassfish-maven-plugin + 7.1-SNAPSHOT + + + set configs.config.server-config.network-config.protocols.protocol.http-listener.http.websockets-support-enabled=true + create-jdbc-resource --connectionpoolid mypool jdbc/myresource + + + +``` + +Command line usage: +```bash +mvn embedded-glassfish:admin -Dcommands="set server.monitoring-service.module-monitoring-levels.web-container=HIGH" +``` + +## Configuration Reference + +### Server Configuration +- `configFile` - Custom domain configuration file +- `glassfish.version` - GlassFish version to use +- `port` - HTTP port number (default: 8080) +- `ports` - Map of port configurations +- `serverID` - Server identifier (default: "maven") + +### Application Deployment +- `app` - Path to application artifact to deploy (defaults to `${project.build.directory}/${project.build.finalName}.war`) +- `contextRoot` - Application context root +- `name` - Application name (default: "myapp") + +### Advanced Configuration +- `bootstrapProperties` - Bootstrap properties +- `glassfishProperties` - GlassFish server properties +- `instanceRoot` - Server instance root directory + +## Goal Reference + +### start +Starts an Embedded GlassFish server with the configured parameters. + +**Default Phase:** pre-integration-test + +**Configuration:** +- Uses all server configuration parameters (serverID, port, glassfishProperties, etc.) + +**Example:** +```bash +mvn embedded-glassfish:start +``` + +### stop +Stops the Embedded GlassFish server and cleans up resources. + +**Default Phase:** post-integration-test + +**Configuration:** +- `serverID` - Server identifier to stop (default: "maven") + +**Example:** +```bash +mvn embedded-glassfish:stop +``` + +### deploy +Deploys an application to the running Embedded GlassFish server. + +**Default Phase:** pre-integration-test + +**Configuration:** +- `app` - Application path (auto-detects if not specified) +- `name` - Application name (default: "myapp") +- `contextRoot` - Web application context root +- `deploymentParams` - Additional deployment parameters + +**Example:** +```bash +mvn embedded-glassfish:deploy -Dapp=target/myapp.war +``` + +### undeploy +Undeploys an application from the Embedded GlassFish server. + +**Default Phase:** post-integration-test + +**Configuration:** +- `name` - Application name to undeploy (default: "myapp") +- `undeploymentParams` - Additional undeployment parameters + +**Example:** +```bash +mvn embedded-glassfish:undeploy -Dname=myapp +``` + +### run +Starts the server, deploys applications, and runs interactively. Allows redeployment by pressing Enter or exit by typing 'X'. + +**Default Phase:** none (manual execution) + +**Configuration:** +- Combines all server and deployment configurations +- Executes all configured admin and deploy goals + +**Example:** +```bash +mvn embedded-glassfish:run +``` + +### admin +Executes administrative commands on the running server. + +**Default Phase:** pre-integration-test + +**Configuration:** +- `commands` - Array of admin commands to execute + +**Example:** +```bash +mvn embedded-glassfish:admin -Dcommands="create-jdbc-resource --connectionpoolid mypool jdbc/myresource" +``` + +## License + +Eclipse Public License v. 2.0 diff --git a/pom.xml b/pom.xml index a069287..f9a7762 100644 --- a/pom.xml +++ b/pom.xml @@ -35,18 +35,20 @@ 3.6.3 + true + 7.0.25 ${target.maven.version} - + Bhavanishankar - + yaminikb @@ -58,18 +60,18 @@ - Glassfish dev mailing list - glassfish-dev@eclipse.org - https://dev.eclipse.org/mailman/listinfo/glassfish-dev - https://dev.eclipse.org/mailman/listinfo/glassfish-dev - https://dev.eclipse.org/mhonarc/lists/glassfish-dev + Glassfish dev mailing list + glassfish-dev@eclipse.org + https://dev.eclipse.org/mailman/listinfo/glassfish-dev + https://dev.eclipse.org/mailman/listinfo/glassfish-dev + https://dev.eclipse.org/mhonarc/lists/glassfish-dev github https://github.com/eclipse-ee4j/glassfish-maven-embedded-plugin/issues - + scm:git:https://github.com/eclipse-ee4j/glassfish-maven-embedded-plugin.git @@ -80,11 +82,43 @@ install + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + + org.apache.maven.plugins + maven-plugin-plugin + 3.15.1 + + + org.apache.maven.plugins + maven-source-plugin + 3.3.1 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.12.0 + + + org.apache.maven.plugins + maven-release-plugin + 3.1.1 + + + maven-invoker-plugin + 3.9.0 + + + org.apache.maven.plugins maven-compiler-plugin - 3.14.1 11 @@ -92,55 +126,71 @@ org.apache.maven.plugins maven-plugin-plugin - 3.15.1 embedded-glassfish + + maven-invoker-plugin + + + integration-test + + install + run + + + + + ${project.build.directory}/local-repo + ${skipTests} + ${skipTests} + + ${tested.glassfish.version} + + + org.apache.maven.plugins maven-source-plugin - 3.3.1 true - attach-sources - - jar-no-fork - + attach-sources + + jar-no-fork + org.apache.maven.plugins maven-javadoc-plugin - 3.12.0 - - attach-javadocs - - jar - - + + attach-javadocs + + jar + + - org.apache.maven.plugins - maven-release-plugin - 3.1.1 - - forked-path - false + org.apache.maven.plugins + maven-release-plugin + + forked-path + false @{project.version} ${release.arguments} - + org.apache.maven.scm @@ -148,7 +198,7 @@ 2.2.1 - + @@ -184,7 +234,6 @@ org.apache.maven.plugins maven-plugin-plugin - 3.15.1 @@ -201,5 +250,5 @@ repo - + diff --git a/src/it/deploy/invoker.properties b/src/it/deploy/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/deploy/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/deploy/pom.xml b/src/it/deploy/pom.xml new file mode 100644 index 0000000..0b5f584 --- /dev/null +++ b/src/it/deploy/pom.xml @@ -0,0 +1,65 @@ + + + + + 4.0.0 + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + deploy + @project.version@ + pom + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + test.war + 8081 + + + + pre-integration + pre-integration-test + + start + + + + integration + integration-test + + deploy + + + + post-integration + post-integration-test + + stop + + + + + + + + diff --git a/src/it/deploy/postbuild.groovy b/src/it/deploy/postbuild.groovy new file mode 100644 index 0000000..4e3ba55 --- /dev/null +++ b/src/it/deploy/postbuild.groovy @@ -0,0 +1,24 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +messageLines = buildLog.grep(~/^INFO: myapp was successfully deployed.*/) + +assert messageLines.size() == 1: 'Message about myapp app deployed was expected in build log with level INFO' + +true + diff --git a/src/test/deploy/test.war b/src/it/deploy/test.war similarity index 100% rename from src/test/deploy/test.war rename to src/it/deploy/test.war diff --git a/src/it/start-admin-commands/invoker.properties b/src/it/start-admin-commands/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/start-admin-commands/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/start-admin-commands/pom.xml b/src/it/start-admin-commands/pom.xml new file mode 100644 index 0000000..5bb3939 --- /dev/null +++ b/src/it/start-admin-commands/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start + @project.version@ + pom + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + pre-integration + pre-integration-test + + start + + + + integration-test + integration-test + + admin + + + 8081 + + set configs.config.server-config.network-config.protocols.protocol.http-listener.http.websockets-support-enabled=true + set configs.config.server-config.thread-pools.thread-pool.http-thread-pool.max-thread-pool-size=200 + + + + + post-integration + post-integration-test + + stop + + + + + + + diff --git a/src/it/start-admin-commands/postbuild.groovy b/src/it/start-admin-commands/postbuild.groovy new file mode 100644 index 0000000..5b104e7 --- /dev/null +++ b/src/it/start-admin-commands/postbuild.groovy @@ -0,0 +1,23 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +startedLines = buildLog.grep(~/^INFO: Ran command.*SUCCESS.*/) + +assert startedLines.size() == 2: 'Expected messages about running admin commands in build log' +true + diff --git a/src/it/start-with-dependency/invoker.properties b/src/it/start-with-dependency/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/start-with-dependency/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/start-with-dependency/pom.xml b/src/it/start-with-dependency/pom.xml new file mode 100644 index 0000000..3099c99 --- /dev/null +++ b/src/it/start-with-dependency/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start-with-gf-version + @project.version@ + pom + + + + + + org.glassfish.main.extras + glassfish-embedded-all + 7.0.1 + + + + + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + pre-integration + pre-integration-test + + start + + + 8081 + + 7.0.0 + + + + post-integration + post-integration-test + + stop + + + + + + org.glassfish.main.extras + glassfish-embedded-all + @tested.glassfish.version@ + + + + + + diff --git a/src/it/start-with-dependency/postbuild.groovy b/src/it/start-with-dependency/postbuild.groovy new file mode 100644 index 0000000..9ada9a8 --- /dev/null +++ b/src/it/start-with-dependency/postbuild.groovy @@ -0,0 +1,29 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +glassfishVersion = glassfishVersion.replace(".", "\\.") +versionLines = buildLog.grep(~/^.*ClassPath Element.*glassfish-embedded-all-${glassfishVersion}\.jar.*$/) + +assert versionLines.size() == 1: 'Configured message was expected in build log at INFO level' + +startedLines = buildLog.grep(~/^INFO: Started GlassFish.*/) + +assert startedLines.size() == 1: 'Expected messages about GlassFish started at INFO level' + +true + diff --git a/src/it/start-with-gf-version-as-property/invoker.properties b/src/it/start-with-gf-version-as-property/invoker.properties new file mode 100644 index 0000000..6e13223 --- /dev/null +++ b/src/it/start-with-gf-version-as-property/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify -Dglassfish.version=${tested.glassfish.version} + diff --git a/src/it/start-with-gf-version-as-property/pom.xml b/src/it/start-with-gf-version-as-property/pom.xml new file mode 100644 index 0000000..f9edbbe --- /dev/null +++ b/src/it/start-with-gf-version-as-property/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start-with-gf-version + @project.version@ + pom + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + pre-integration + pre-integration-test + + start + + + 8081 + + + + post-integration + post-integration-test + + stop + + + + + + + diff --git a/src/it/start-with-gf-version-as-property/postbuild.groovy b/src/it/start-with-gf-version-as-property/postbuild.groovy new file mode 100644 index 0000000..9ada9a8 --- /dev/null +++ b/src/it/start-with-gf-version-as-property/postbuild.groovy @@ -0,0 +1,29 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +glassfishVersion = glassfishVersion.replace(".", "\\.") +versionLines = buildLog.grep(~/^.*ClassPath Element.*glassfish-embedded-all-${glassfishVersion}\.jar.*$/) + +assert versionLines.size() == 1: 'Configured message was expected in build log at INFO level' + +startedLines = buildLog.grep(~/^INFO: Started GlassFish.*/) + +assert startedLines.size() == 1: 'Expected messages about GlassFish started at INFO level' + +true + diff --git a/src/it/start-with-gf-version/invoker.properties b/src/it/start-with-gf-version/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/start-with-gf-version/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/start-with-gf-version/pom.xml b/src/it/start-with-gf-version/pom.xml new file mode 100644 index 0000000..96ad638 --- /dev/null +++ b/src/it/start-with-gf-version/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start-with-gf-version + @project.version@ + pom + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + pre-integration + pre-integration-test + + start + + + 8081 + @tested.glassfish.version@ + + + + post-integration + post-integration-test + + stop + + + + + + + diff --git a/src/it/start-with-gf-version/postbuild.groovy b/src/it/start-with-gf-version/postbuild.groovy new file mode 100644 index 0000000..9ada9a8 --- /dev/null +++ b/src/it/start-with-gf-version/postbuild.groovy @@ -0,0 +1,29 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +glassfishVersion = glassfishVersion.replace(".", "\\.") +versionLines = buildLog.grep(~/^.*ClassPath Element.*glassfish-embedded-all-${glassfishVersion}\.jar.*$/) + +assert versionLines.size() == 1: 'Configured message was expected in build log at INFO level' + +startedLines = buildLog.grep(~/^INFO: Started GlassFish.*/) + +assert startedLines.size() == 1: 'Expected messages about GlassFish started at INFO level' + +true + diff --git a/src/it/start-with-version-in-dep-management/invoker.properties b/src/it/start-with-version-in-dep-management/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/start-with-version-in-dep-management/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/start-with-version-in-dep-management/pom.xml b/src/it/start-with-version-in-dep-management/pom.xml new file mode 100644 index 0000000..6e7e823 --- /dev/null +++ b/src/it/start-with-version-in-dep-management/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start-with-gf-version + @project.version@ + pom + + + + + org.glassfish.main.extras + glassfish-embedded-all + @tested.glassfish.version@ + + + + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + pre-integration + pre-integration-test + + start + + + 8081 + + + + post-integration + post-integration-test + + stop + + + + + + + diff --git a/src/it/start-with-version-in-dep-management/postbuild.groovy b/src/it/start-with-version-in-dep-management/postbuild.groovy new file mode 100644 index 0000000..9ada9a8 --- /dev/null +++ b/src/it/start-with-version-in-dep-management/postbuild.groovy @@ -0,0 +1,29 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +glassfishVersion = glassfishVersion.replace(".", "\\.") +versionLines = buildLog.grep(~/^.*ClassPath Element.*glassfish-embedded-all-${glassfishVersion}\.jar.*$/) + +assert versionLines.size() == 1: 'Configured message was expected in build log at INFO level' + +startedLines = buildLog.grep(~/^INFO: Started GlassFish.*/) + +assert startedLines.size() == 1: 'Expected messages about GlassFish started at INFO level' + +true + diff --git a/src/it/start/invoker.properties b/src/it/start/invoker.properties new file mode 100644 index 0000000..4d0b7f0 --- /dev/null +++ b/src/it/start/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License v. 2.0, which is available at +# http://www.eclipse.org/legal/epl-2.0. +# +# This Source Code may also be made available under the following Secondary +# Licenses when the conditions for such availability set forth in the +# Eclipse Public License v. 2.0 are satisfied: GNU General Public License, +# version 2 with the GNU Classpath Exception, which is available at +# https://www.gnu.org/software/classpath/license.html. +# +# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +# + +invoker.goals=verify + diff --git a/src/it/start/pom.xml b/src/it/start/pom.xml new file mode 100644 index 0000000..c091de0 --- /dev/null +++ b/src/it/start/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + org.glassfish.embedded.embedded-glassfish-maven-plugin.its + start + @project.version@ + pom + + + + + org.glassfish.embedded + embedded-glassfish-maven-plugin + @project.version@ + + + integration + integration-test + + start + + + 8081 + + + + post-integration + post-integration-test + + stop + + + + + + + diff --git a/src/it/start/postbuild.groovy b/src/it/start/postbuild.groovy new file mode 100644 index 0000000..5e40848 --- /dev/null +++ b/src/it/start/postbuild.groovy @@ -0,0 +1,23 @@ +/* + Copyright (c) 2022, 2023 Contributors to Eclipse Foundation. All rights reserved. + + This program and the accompanying materials are made available under the + terms of the Eclipse Public License v. 2.0, which is available at + http://www.eclipse.org/legal/epl-2.0. + + This Source Code may also be made available under the following Secondary + Licenses when the conditions for such availability set forth in the + Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + version 2 with the GNU Classpath Exception, which is available at + https://www.gnu.org/software/classpath/license.html. + + SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 +*/ + +String [] buildLog = new File(basedir, 'build.log') + +startedLines = buildLog.grep(~/^INFO: Started GlassFish.*/) + +assert startedLines.size() == 1: 'Expected messages about GlassFish started at INFO level' +true + diff --git a/src/main/java/org/glassfish/maven/AbstractServerMojo.java b/src/main/java/org/glassfish/maven/AbstractServerMojo.java index 0c44e3f..5646523 100644 --- a/src/main/java/org/glassfish/maven/AbstractServerMojo.java +++ b/src/main/java/org/glassfish/maven/AbstractServerMojo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation. + * Copyright (c) 2023,2025 Contributors to the Eclipse Foundation. * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -69,15 +69,12 @@ public abstract class AbstractServerMojo extends AbstractMojo { private static final String GF_API_GROUP_ID = "org.glassfish.main.common"; private static final String GF_API_ARTIFACT_ID = "simple-glassfish-api"; - private static final String DEFAULT_GF_VERSION = "4.0"; + private static final String DEFAULT_GF_VERSION = "7.0.0"; private static String gfVersion; - /** - * The remote repositories where artifacts are located. - * This is automatically injected by the Maven framework. - */ - @Parameter(property = "project.remoteArtifactRepositories") - protected List remoteRepositories; + /******************************************* + * Parameters supplied by configuration + ******************************************/ /** * Identifier of the Embedded GlassFish server. @@ -230,6 +227,40 @@ public abstract class AbstractServerMojo extends AbstractMojo { @Parameter(property = "autoDelete", defaultValue = "true") protected Boolean autoDelete; + /** + * @deprecated This is a deprecated and unused configuration. Likely to be removed in the next version of the plugin. + */ + @Parameter(property = "containerType", defaultValue = "all") + @Deprecated + protected String containerType; + + /** + * Version of Embedded GlassFish to download if Embedded GlassFish dependency is not provided + */ + @Parameter(property = "glassfish.version", alias = "glassfish.version") + protected String glassfishVersion; + + /*=============================================== + * End of parameters supplied by configuration + ***********************************************/ + + /*************************************** + * Dependencies injected by Maven + ***************************************/ + + /** + * This is automatically injected by the Maven framework. + */ + @Parameter(property = "localRepository", required = true) + protected ArtifactRepository localRepository; + + /** + * The remote repositories where artifacts are located. + * This is automatically injected by the Maven framework. + */ + @Parameter(property = "project.remoteArtifactRepositories") + protected List remoteRepositories; + /** * The maven project. */ @@ -245,12 +276,6 @@ public abstract class AbstractServerMojo extends AbstractMojo { @Component protected MavenProjectBuilder projectBuilder; - /** - * This is automatically injected by the Maven framework. - */ - @Parameter(property = "localRepository", required = true) - protected ArtifactRepository localRepository; - @Component protected ArtifactResolver resolver; @@ -260,21 +285,17 @@ public abstract class AbstractServerMojo extends AbstractMojo { @Component protected ArtifactFactory factory; - /** - * @deprecated This is a deprecated and unused configuration. Likely to be removed in the next version of the plugin. - */ - @Parameter(property = "containerType", defaultValue = "all") - protected String containerType; + @Component + private ArtifactMetadataSource artifactMetadataSource; -// protected GlassFish gf; + /*======================================= + * End of dependencies injected by Maven + ***************************************/ // HashMap with Key=serverId, Value=Bootstrap ClassLoader protected static HashMap classLoaders = new HashMap(); private static ClassLoader classLoader; - @Component - private ArtifactMetadataSource artifactMetadataSource; - public abstract void execute() throws MojoExecutionException, MojoFailureException; protected ClassLoader getClassLoader() throws MojoExecutionException { @@ -355,8 +376,39 @@ private Artifact getUberFromSpecifiedDependency() { return null; } - // GlassFish should be of same version as simple-glassfish-api as defined in plugin's pom. + private Dependency getDependencyManagementInfoForEmbeddedAll() { + if (project.getDependencyManagement() != null) { + for (Dependency dependency : project.getDependencyManagement().getDependencies()) { + if (EMBEDDED_GROUP_ID.equals(dependency.getGroupId())) { + if (dependency.getArtifactId().equals(EMBEDDED_ALL)) { + return dependency; + } + } + } + } + return null; + } + + /** + * Determines GlassFish version from Maven configuration: + *
    + *
  1. If glassfishVersion parameter defined, return it
  2. + *
  3. If Embedded All depenendy defined in dependency management, return its version
  4. + *
  5. Returns the version of simple-glassfish-api as defined in plugin's pom - the version this plugin was built against
  6. + *
+ * + * @param gfMvnPlugin + * @return Determined version of Embedded GlassFish All artifact + * @throws Exception + */ private String getGlassfishVersion(Artifact gfMvnPlugin) throws Exception { + if (glassfishVersion != null) { + return glassfishVersion; + } + Dependency dependencyManagementInfo = getDependencyManagementInfoForEmbeddedAll(); + if (dependencyManagementInfo != null) { + return dependencyManagementInfo.getVersion(); + } if (gfVersion != null) { return gfVersion; } diff --git a/src/test/deploy/pom.xml b/src/test/deploy/pom.xml deleted file mode 100644 index 422dd76..0000000 --- a/src/test/deploy/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - 4.0.0 - - org.glassfish.embedded.tester - tester-parent - 7.1-SNAPSHOT - - deploy-tester - pom - Glassfish Embedded Maven Plugin Deploy Tester - - - install - - - org.glassfish.embedded - embedded-glassfish-maven-plugin - ${project.version} - - test.war - 8080 - - - - install - - run - deploy - - - - - - - - diff --git a/src/test/pom.xml b/src/test/pom.xml deleted file mode 100644 index 144b9d6..0000000 --- a/src/test/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - 4.0.0 - - org.eclipse.ee4j - project - 1.0.7 - - org.glassfish.embedded.tester - tester-parent - pom - 7.1-SNAPSHOT - - Glassfish Embedded Maven Plugin Tester Parent Pom - - - - start - - - diff --git a/src/test/start/pom.xml b/src/test/start/pom.xml deleted file mode 100644 index 242dcab..0000000 --- a/src/test/start/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - 4.0.0 - - org.glassfish.embedded.tester - tester-parent - 7.1-SNAPSHOT - - startstop-tester - pom - Glassfish Embedded Maven Plugin Start Stop Tester - - - install - - - org.glassfish.embedded - embedded-glassfish-maven-plugin - ${project.version} - - - install - - start - stop - - - - - - - -