Skip to content

Commit ca42dce

Browse files
committed
Simple system properties in glassfish.properties for runneble Embedded GlassFish
1 parent 3dad4ae commit ca42dce

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

appserver/tests/embedded/runnable/src/test/java/org/glassfish/tests/embedded/runnable/SystemPropertyTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ void testSystemPropertyFromAdminCommand(String gfEmbeddedJarName) throws Excepti
8585
}
8686
}
8787

88+
@ParameterizedTest
89+
@ArgumentsSource(GfEmbeddedJarNameProvider.class)
90+
void testSystemPropertyFromPropertyFileDirectly(String gfEmbeddedJarName, TestInfo testInfo) throws Exception {
91+
File warFile = null;
92+
Path propertiesFile = preparePropertiesFile(testInfo);
93+
try {
94+
warFile = createSystemPropertyApp();
95+
Process gfEmbeddedProcess = runGlassFishEmbedded(gfEmbeddedJarName,
96+
"--properties=" + propertiesFile.toFile().getPath(),
97+
warFile.getAbsolutePath()
98+
);
99+
assertTrue(outputToStreamOfLines(gfEmbeddedProcess)
100+
.anyMatch(line -> line.contains("System property my.name: Embedded GlassFish")),
101+
"Application should print the value of the my.name system property.");
102+
gfEmbeddedProcess.waitFor(30, TimeUnit.SECONDS);
103+
} finally {
104+
Optional.ofNullable(warFile).ifPresent(File::delete);
105+
}
106+
}
107+
88108
@ParameterizedTest
89109
@ArgumentsSource(GfEmbeddedJarNameProvider.class)
90110
void testSystemPropertyFromDomainConfig(String gfEmbeddedJarName, TestInfo testInfo) throws Exception {
@@ -125,4 +145,14 @@ private Path prepareDomainConfig(TestInfo testInfo) throws IOException {
125145
return domainConfigFile;
126146
}
127147

148+
private Path preparePropertiesFile(TestInfo testInfo) throws IOException {
149+
String testClassName = testInfo.getTestClass().get().getSimpleName();
150+
String testMethodName = testInfo.getTestMethod().get().getName();
151+
Path propertiesFile = Paths.get(testClassName + "-" + testMethodName + "-" + "glassfish.properties");
152+
Files.copy(getClass().getClassLoader().getResourceAsStream(testClassName + "/glassfish.properties"),
153+
propertiesFile,
154+
StandardCopyOption.REPLACE_EXISTING);
155+
return propertiesFile;
156+
}
157+
128158
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Eclipse Public License v. 2.0, which is available at
5+
# http://www.eclipse.org/legal/epl-2.0.
6+
#
7+
# This Source Code may also be made available under the following Secondary
8+
# Licenses when the conditions for such availability set forth in the
9+
# Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
10+
# version 2 with the GNU Classpath Exception, which is available at
11+
# https://www.gnu.org/software/classpath/license.html.
12+
#
13+
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
14+
15+
my.name=Embedded GlassFish

docs/embedded-server-guide/src/main/asciidoc/embedded-server-guide.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ The value will be treated as a command to execute at startup.
285285
- Keys that start with the "deploy." prefix, followed by any text. The
286286
value will be treated as an application to deploy at startup, as if it
287287
was specified on the command line.
288+
- If a property name doesn't match any already supported patterns and is not
289+
a recognized GlassFish property, it will be set as a system property, if
290+
it's not already defined.
288291
For example, the ${productName} domain directory can be specified with the
289292
usual Embedded ${productName} property
290293
"glassfish.embedded.tmpdir=myDomainDir", as well as with the property

nucleus/core/bootstrap-osgi/src/main/java/org/glassfish/main/boot/embedded/AutoDisposableGlassFish.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.glassfish.embeddable.GlassFishProperties;
3838
import org.glassfish.hk2.api.ServiceLocator;
3939
import org.glassfish.main.boot.impl.GlassFishImpl;
40+
import org.glassfish.main.jdke.props.SystemProperties;
4041

4142
import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.AUTO_DELETE;
4243

@@ -79,7 +80,12 @@ class AutoDisposableGlassFish extends GlassFishImpl {
7980
&& resultList.getOutput().contains(propertyPrefix)) {
8081
knownPropertyPrefixes.add(propertyPrefix);
8182
} else {
82-
// unknown property prefix, skip it
83+
if (!key.startsWith("com.sun.aas.") && !key.startsWith("-")) {
84+
// unknown property, set as system property
85+
LOG.log(Level.INFO, "Setting system property " + key + " from GlassFish properties, it doesn't match any known property");
86+
SystemProperties.setProperty(key, gfProps.getProperty(key), false);
87+
}
88+
// not a dotted name, doesn't start with a supported prefix, do not set it later
8389
continue;
8490
}
8591
}

nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Option.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public enum Option {
5151
+ " - Keys that start with the \"" + Arguments.DEPLOY_KEY_PREFIX
5252
+ "\" prefix, followed by any text. The value will be"
5353
+ " treated as an application to deploy at startup, as if it was specified on the command line.\n"
54-
+ "For example, the GlassFish domain directory can be specified with the usual GlassFish Embedded"
54+
+ " - If a property name doesn't match any already supported patterns and is not"
55+
+ " a recognized GlassFish property, it will be set as a system property, if it's not already defined.\n"
56+
+ "\nFor example, the GlassFish domain directory can be specified with the usual GlassFish Embedded"
5557
+ " property \"glassfish.embedded.tmpdir=myDomainDir\", as well as with the property"
5658
+ " \"domainDir=myDomainDir\" that represents the \"--domainDir=myDomainDir\" command-line option."
5759
+ " A command to deploy an application can be specified via a property key"

nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/commandline/WordWrapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void testWrapper() {
3838
.map(Option::getHelpText)
3939
.collect(wordWrapper);
4040
final List<String> linesEndingWithSpace = message.lines()
41-
.filter(line -> line.endsWith(" "))
41+
.filter(line -> line.endsWith(" ") && !line.isBlank())
4242
.collect(toList());
4343
assertTrue(linesEndingWithSpace.isEmpty(), "Some lines end with a space: " + linesEndingWithSpace);
4444

0 commit comments

Comments
 (0)