diff --git a/appserver/ant-tasks/src/main/java/org/glassfish/ant/embedded/tasks/Util.java b/appserver/ant-tasks/src/main/java/org/glassfish/ant/embedded/tasks/Util.java index 41f63b7f796..df89819816a 100644 --- a/appserver/ant-tasks/src/main/java/org/glassfish/ant/embedded/tasks/Util.java +++ b/appserver/ant-tasks/src/main/java/org/glassfish/ant/embedded/tasks/Util.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -39,7 +40,7 @@ public class Util { private static GlassFishRuntime glassfishRuntime; public static synchronized GlassFish startGlassFish(String serverID, String installRoot, - String instanceRoot, String configFileURI, + String instanceRoot, String configFile, boolean configFileReadOnly, int httpPort) throws GlassFishException { GlassFish glassfish = gfMap.get(serverID); @@ -58,12 +59,12 @@ public static synchronized GlassFish startGlassFish(String serverID, String inst if (instanceRoot != null) { glassfishProperties.setInstanceRoot(instanceRoot); } - if (configFileURI != null) { - glassfishProperties.setConfigFileURI(configFileURI); + if (configFile != null) { + glassfishProperties.setConfigFileURI(new File(configFile).toURI().toString()); glassfishProperties.setConfigFileReadOnly(configFileReadOnly); } - if (instanceRoot==null && configFileURI==null) { + if (instanceRoot == null && configFile == null) { // only set port if embedded domain.xml is used if (httpPort != -1) { glassfishProperties.setPort("http-listener", httpPort); @@ -92,7 +93,7 @@ public static void deploy(String app, String serverId, List deployParams Deployer deployer = glassfish.getDeployer(); final int len = deployParams.size(); if (len > 0) { - deployer.deploy(new File(app).toURI(), deployParams.toArray(new String[len])); + deployer.deploy(new File(app).toURI(), deployParams.toArray(String[]::new)); System.out.println("Deployed [" + app + "] with parameters " + deployParams); } else { deployer.deploy(new File(app).toURI()); diff --git a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java index bf94e370d5c..59707b74f9a 100644 --- a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java +++ b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/embedded/EJBContainerProviderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation. + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation. * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -184,8 +184,9 @@ private Locations createContainer(Map properties, Locations l) throws EJBE _logger.info("[EJBContainerProviderImpl] Using instance location: " + l.instance_root.getCanonicalPath()); glassFishProperties.setInstanceRoot(l.instance_root.getCanonicalPath()); } else if (l.domain_file != null) { - _logger.info("[EJBContainerProviderImpl] Using config file location: " + l.domain_file.toURI().toString()); - glassFishProperties.setConfigFileURI(l.domain_file.toURI().toString()); + String cfgFileUri = l.domain_file.toURI().toString(); + _logger.info("[EJBContainerProviderImpl] Using config file location: " + cfgFileUri); + glassFishProperties.setConfigFileURI(cfgFileUri); } addWebContainerIfRequested(properties, glassFishProperties); diff --git a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishProperties.java b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishProperties.java index f49c321181b..02733897b7b 100644 --- a/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishProperties.java +++ b/nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishProperties.java @@ -130,21 +130,55 @@ public String getInstanceRoot() { return gfProperties.getProperty(INSTANCE_ROOT_PROP_NAME); } + /** * Optionally set the location of configuration file (i.e., domain.xml) using * which the GlassFish should run. - *

+ *

+ * If the parameter is not an absolute URI, it is resolved as a local file path relative to the + * current directory. + *

* Unless specified, the configuration file is operated on read only mode. * To writeback any changes, call {@link #setConfigFileReadOnly(boolean)} with 'false'. * - * @param configFileURI Location of configuration file. File path, or full URI with the schema, e.g. file: + * @param configFileURI Location of configuration file. File path, or full URI with the schema, + * e.g. file: */ public void setConfigFileURI(String configFileURI) { - gfProperties.setProperty(CONFIG_FILE_URI_PROP_NAME, configFileURI); + if (configFileURI == null) { + gfProperties.remove(CONFIG_FILE_URI_PROP_NAME); + return; + } + setConfigFileURI(URI.create(configFileURI)); + } + + /** + * Optionally set the location of configuration file (i.e., domain.xml) using + * which the GlassFish should run. The parameter is converted to an absolute URI. + *

+ * If the parameter is not an absolute URI, it is resolved as a local file path relative to the + * current directory. + *

+ * Unless specified, the configuration file is operated on read only mode. + * To writeback any changes, call {@link #setConfigFileReadOnly(boolean)} with 'false'. + * + * @param configFileURI Location of configuration file. File path, or full URI with the schema, + * e.g. file: + */ + public void setConfigFileURI(URI configFileURI) { + if (configFileURI == null) { + gfProperties.remove(CONFIG_FILE_URI_PROP_NAME); + return; + } + if (configFileURI.isAbsolute()) { + gfProperties.setProperty(CONFIG_FILE_URI_PROP_NAME, configFileURI.toString()); + return; + } + gfProperties.setProperty(CONFIG_FILE_URI_PROP_NAME, new File(configFileURI.toString()).toURI().toString()); } /** - * Get the configurationFileURI set using {@link #setConfigFileURI(String)} + * Get the absolute configurationFileURI set using {@link #setConfigFileURI(String)} * * @return The configurationFileURI set using {@link #setConfigFileURI(String)} */ @@ -153,12 +187,13 @@ public String getConfigFileURI() { } /** - * Get the absolute URI, with schema, set using {@link #setConfigFileURI(String)}. Internally uses {@link #filePathToAbsoluteURI(java.lang.String)}. + * Get the absolute URI, with schema, set using {@link #setConfigFileURI(String)}. + * Internally uses {@link #toAbsoluteURI(java.lang.String)}. * * @return The configurationFileURI set using {@link #setConfigFileURI(String)} converted to URI */ public URI getAbsoluteConfigFileURI() { - return filePathToAbsoluteURI(getConfigFileURI()); + return URI.create(getConfigFileURI()); } /** @@ -255,22 +290,4 @@ public int getPort(String networkListener) { } return port; } - - /** - * Converts to absolute URI with absolute path. - * If the filePath doesn't contain schema, it will add file: schema - * - * @param filePath Path to create the URI - * @return absolute URI - */ - public static URI filePathToAbsoluteURI(String filePath) { - if (filePath == null) { - return null; - } - URI uri = URI.create(filePath); - if (!uri.isAbsolute()) { - return new File(filePath).getAbsoluteFile().toURI(); - } - return uri; - } } diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/kernel/embedded/EmbeddedDomainXml.java b/nucleus/core/kernel/src/main/java/org/glassfish/kernel/embedded/EmbeddedDomainXml.java index 155eb1e49ac..7203a3e835f 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/kernel/embedded/EmbeddedDomainXml.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/kernel/embedded/EmbeddedDomainXml.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.net.URL; import org.glassfish.embeddable.GlassFishProperties; @@ -47,13 +48,15 @@ protected URL getDomainXml(ServerEnvironmentImpl env) throws IOException { static URL getDomainXml(StartupContext startupContext) throws IOException { String configFileURI = startupContext.getArguments().getProperty(GlassFishProperties.CONFIG_FILE_URI_PROP_NAME); - if (configFileURI != null) { // user specified domain.xml - return GlassFishProperties.filePathToAbsoluteURI(configFileURI).toURL(); + if (configFileURI != null) { + // user specified domain.xml + return URI.create(configFileURI).toURL(); } String instanceRoot = startupContext.getArguments().getProperty( "com.sun.aas.instanceRoot"); File domainXml = new File(instanceRoot, "config/domain.xml"); - if (domainXml.exists()) { // domain/config/domain.xml, if exists. + if (domainXml.exists()) { + // domain/config/domain.xml, if exists. return domainXml.toURI().toURL(); } return EmbeddedDomainXml.class.getClassLoader().getResource( diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Option.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Option.java index 6089d16ae72..52d129f221a 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Option.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Option.java @@ -85,7 +85,7 @@ public void handle(String value, Arguments arguments) { "Set the location of domain configuration file (i.e., domain.xml) using which GlassFish should run.") { @Override public void handle(String value, Arguments arguments) { - arguments.glassFishProperties.setConfigFileURI(value); + arguments.glassFishProperties.setConfigFileURI(new File(value).toURI().toString()); } }, DOMAIN_DIR("domainDir", Set.of("instanceRoot"), "--domainDir=DIRECTORY, --instanceRoot=DIRECTORY",