Skip to content

Commit

Permalink
Fixed resolving Windows paths
Browse files Browse the repository at this point in the history
- Path.of expects a path using slash as a separator, so old windows paths are
  invalid for this. We always have to use File first.

Signed-off-by: David Matějček <[email protected]>
  • Loading branch information
dmatej committed Nov 9, 2024
1 parent 74ea722 commit b2e3b9e
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ static class GlassFishInfo {

GlassFishInfo() {
String asInstallPath = System.getProperty(ENV_VAR_PROP_PREFIX + "AS_INSTALL");
if (asInstallPath == null || asInstallPath.length() == 0) {
if (asInstallPath == null || asInstallPath.isEmpty()) {
throw new IllegalArgumentException("AS_INSTALL == null");
}
this.home = new File(asInstallPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Properties accEnvironment() {
"AS_DEF_NODES_PATH", AGENT_ROOT_PROPERTY);
Map<String, File> files = new EnvToPropsConverter(rootDirectory.toPath()).convert(pairs);
Properties env = new Properties();
files.entrySet().forEach(e -> env.put(e.getKey(), e.getValue().getAbsolutePath()));
files.entrySet().forEach(e -> env.put(e.getKey(), e.getValue().getPath()));
return env;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
@echo off
REM
REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
REM
REM This program and the accompanying materials are made available under the
REM terms of the Eclipse Public License v. 2.0, which is available at
REM http://www.eclipse.org/legal/epl-2.0.
REM
REM This Source Code may also be made available under the following Secondary
REM Licenses when the conditions for such availability set forth in the
REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
REM version 2 with the GNU Classpath Exception, which is available at
REM https://www.gnu.org/software/classpath/license.html.
REM
REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
REM

VERIFY OTHER 2>nul
setlocal ENABLEEXTENSIONS
if ERRORLEVEL 0 goto ok
echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0..\glassfish"
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA="%AS_JAVA%\bin\java"
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH="%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%"
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %*
@echo off
REM
REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
REM
REM This program and the accompanying materials are made available under the
REM terms of the Eclipse Public License v. 2.0, which is available at
REM http://www.eclipse.org/legal/epl-2.0.
REM
REM This Source Code may also be made available under the following Secondary
REM Licenses when the conditions for such availability set forth in the
REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
REM version 2 with the GNU Classpath Exception, which is available at
REM https://www.gnu.org/software/classpath/license.html.
REM
REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
REM

VERIFY OTHER 2>nul
setlocal ENABLEEXTENSIONS
if ERRORLEVEL 0 goto ok
echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0..\glassfish"
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA=%AS_JAVA%\bin\java
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %*
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ exit /B 1
set AS_INSTALL="%~dp0..\glassfish"
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA="%AS_JAVA%\bin\java"
set JAVA=%AS_JAVA%\bin\java
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH="%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%"
set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%
%JAVA% %ASADMIN_JVM_OPTIONS% -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=9008 --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %*
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ exit /B 1
set AS_INSTALL="%~dp0.."
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA="%AS_JAVA%\bin\java"
set JAVA=%AS_JAVA%\bin\java
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH="%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%"
set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain start-domain --verbose %*
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
@echo off
REM
REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
REM
REM This program and the accompanying materials are made available under the
REM terms of the Eclipse Public License v. 2.0, which is available at
REM http://www.eclipse.org/legal/epl-2.0.
REM
REM This Source Code may also be made available under the following Secondary
REM Licenses when the conditions for such availability set forth in the
REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
REM version 2 with the GNU Classpath Exception, which is available at
REM https://www.gnu.org/software/classpath/license.html.
REM
REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
REM

VERIFY OTHER 2>nul
setlocal ENABLEEXTENSIONS
if ERRORLEVEL 0 goto ok
echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0.."
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA="%AS_JAVA%\bin\java"
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH="%AS_INSTALL%\appserver-cli.jar:%ASADMIN_CLASSPATH%"
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %*
@echo off
REM
REM Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
REM Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
REM
REM This program and the accompanying materials are made available under the
REM terms of the Eclipse Public License v. 2.0, which is available at
REM http://www.eclipse.org/legal/epl-2.0.
REM
REM This Source Code may also be made available under the following Secondary
REM Licenses when the conditions for such availability set forth in the
REM Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
REM version 2 with the GNU Classpath Exception, which is available at
REM https://www.gnu.org/software/classpath/license.html.
REM
REM SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
REM

VERIFY OTHER 2>nul
setlocal ENABLEEXTENSIONS
if ERRORLEVEL 0 goto ok
echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0.."
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA=%AS_JAVA%\bin\java
goto run

:UsePath
set JAVA=java

:run
set ASADMIN_CLASSPATH=%AS_INSTALL%\appserver-cli.jar;%ASADMIN_CLASSPATH%
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" org.glassfish.admin.cli.AsadminMain %*
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ public void upgradeIfNecessary() {
return;
}

final Path imqLib = Path.of(imqLibPath);
final Path imqLib = new File(imqLibPath).toPath();
final Path deployedDir = new File(installRoot).toPath().resolve(SYSTEM_APP_DIR).resolve(DEFAULT_JMS_ADAPTER);
final File imqLibRar = imqLib.resolve(MQ_RAR).toFile();
final Path deployedDir = Path.of(installRoot).resolve(SYSTEM_APP_DIR).resolve(DEFAULT_JMS_ADAPTER);
final String installedMqVersion;
final String deployedMqVersion;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ protected Set<File> getExtensions() {
locations.add(modules);
}
} else {
for (String path : envClasspath.split(":")) {
for (String path : envClasspath.split(File.pathSeparator)) {
File file = new File(path);
// nuclesus doesn't contain some files, ie. backup.jar
// nucleus doesn't contain some files, ie. backup.jar
if (file.exists()) {
locations.add(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package com.sun.enterprise.admin.launcher;

import com.sun.enterprise.universal.io.SmartFile;

import java.io.File;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -66,8 +64,8 @@ List<File> getMainClasspath() throws GFLauncherException {

@Override
List<File> getMainModulepath() throws GFLauncherException {
return List
.of(SmartFile.sanitize(Path.of(getEnvProps().get(INSTALL_ROOT_PROPERTY), "lib", "bootstrap").toFile()));
Path installRoot = new File(getEnvProps().get(INSTALL_ROOT_PROPERTY)).toPath();
return List.of(installRoot.resolve(Path.of("lib", "bootstrap")).toAbsolutePath().normalize().toFile());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ public String toString() {
static class ASenvMap extends HashMap<String, String> {
ASenvMap(File installDir) {
new EnvToPropsConverter(installDir.toPath()).convert(ENV_TO_SYS_PROPERTY).entrySet()
.forEach(e -> this.put(e.getKey(), e.getValue().getAbsolutePath()));
put(JAVA_ROOT_PROPERTY, System.getProperty("java.home"));
put(JAVA_ROOT_PROPERTY_ASENV, System.getProperty("java.home"));
put(INSTALL_ROOT_PROPERTY, installDir.getAbsolutePath());
put(PRODUCT_ROOT_PROPERTY, installDir.getParentFile().getAbsolutePath());
.forEach(e -> this.put(e.getKey(), e.getValue().getPath()));
String javaHome = new File(System.getProperty("java.home")).toPath().toString();
put(JAVA_ROOT_PROPERTY, javaHome);
put(JAVA_ROOT_PROPERTY_ASENV, javaHome);
put(INSTALL_ROOT_PROPERTY, installDir.toPath().toString());
put(PRODUCT_ROOT_PROPERTY, installDir.getParentFile().toPath().toString());
put(HOST_NAME_PROPERTY, getHostname());
}

Expand All @@ -146,21 +147,5 @@ private static String getHostname() {
}
return hostname;
}

private static boolean isValidJavaRoot(String javaRootName) {
if (!GFLauncherUtils.ok(javaRootName)) {
return false;
}

// look for ${javaRootName}/bin/java[.exe]
File f = new File(javaRootName);

if (GFLauncherUtils.isWindows()) {
f = new File(f, "bin/java.exe");
} else {
f = new File(f, "bin/java");
}
return f.exists();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public EnvToPropsConverter(final Path relativePathAnchor) {
* There is no guarantee the file does exist.
*
* @param envToSys - key is env name, value is system property name.
* @return map of system property names and files.
* @return map of system property names and absolute files.
*/
public Map<String, File> convert(final Map<String, String> envToSys) {
final Map<String, File> files = new HashMap<>(envToSys.size());
Expand Down Expand Up @@ -86,7 +86,7 @@ public Map<String, File> convert(final Map<String, String> envToSys) {
*/
public File convert(final String envPropertyName, final String systemPropertyName) {
final String value = evaluate(envPropertyName, systemPropertyName);
return value == null ? null : toAbsoluteFile(Path.of(value));
return value == null ? null : toAbsoluteFile(new File(value));
}


Expand All @@ -104,13 +104,10 @@ private String evaluate(final String envPropertyName, final String systemPropert
}


private File toAbsoluteFile(final Path path) {
File absoluteFile;
if (path.isAbsolute()) {
absoluteFile = path.normalize().toFile();
} else {
absoluteFile = anchor.resolve(path).normalize().toFile();
private File toAbsoluteFile(final File file) {
if (file.isAbsolute()) {
return file.toPath().normalize().toFile();
}
return absoluteFile;
return anchor.resolve(file.toPath()).toAbsolutePath().normalize().toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ private void setEnv(Properties bootstrapProperties) {

File installRoot = new File(installRootValue);
new EnvToPropsConverter(installRoot.toPath()).convert(pairs).entrySet()
.forEach(e -> System.setProperty(e.getKey(), e.getValue().getAbsolutePath()));
.forEach(e -> System.setProperty(e.getKey(), e.getValue().getPath()));
System.setProperty(INSTALL_ROOT_PROP_NAME, installRootValue);
System.setProperty(INSTALL_ROOT_URI_PROP_NAME, installRoot.toURI().toString());
}

final String instanceRootValue = bootstrapProperties.getProperty(INSTANCE_ROOT_PROP_NAME);
if (instanceRootValue != null && !instanceRootValue.isEmpty()) {
File instanceRoot = new File(instanceRootValue);
File instanceRoot = new File(instanceRootValue).toPath().normalize().toFile();
System.setProperty(INSTANCE_ROOT_PROP_NAME, instanceRoot.getAbsolutePath());
System.setProperty(INSTANCE_ROOT_URI_PROP_NAME, instanceRoot.toURI().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static Path getDerbyDir(File installDir) {
if (derbyHomeProperty == null) {
return installDir.toPath().resolve(Path.of("..", "javadb"));
}
Path derbyHome = Path.of(derbyHomeProperty);
Path derbyHome = new File(derbyHomeProperty).toPath();
if (derbyHome.isAbsolute()) {
return derbyHome;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0.."
set AS_INSTALL=%~dp0..
call "%AS_INSTALL%\config\asenv.bat"
if "%AS_JAVA%x" == "x" goto UsePath
set JAVA="%AS_JAVA%\bin\java"
set JAVA=%AS_JAVA%\bin\java
goto run

:UsePath
set JAVA=java

:run
ECHO ON
%JAVA% %ASADMIN_JVM_OPTIONS% --module-path "%ASADMIN_MODULEPATH%" --add-modules ALL-MODULE-PATH -cp "%ASADMIN_CLASSPATH%" com.sun.enterprise.admin.cli.AdminMain %*
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ REM directory.
REM
REM This file uses UTF-8 character encoding.

set AS_DERBY_INSTALL="%AS_INSTALL%\..\javadb"
set AS_IMQ_LIB="%AS_INSTALL%\..\mq\lib"
set AS_IMQ_BIN="%AS_INSTALL%\..\mq\bin"
set AS_DERBY_INSTALL=%AS_INSTALL%\..\javadb
set AS_IMQ_LIB=%AS_INSTALL%\..\mq\lib
set AS_IMQ_BIN=%AS_INSTALL%\..\mq\bin

set AS_CONFIG="%AS_INSTALL%\config"
set AS_DEF_DOMAINS_PATH="%AS_INSTALL%\domains"
set AS_DEF_NODES_PATH="%AS_INSTALL%\nodes"
set AS_CONFIG=%AS_INSTALL%\config
set AS_DEF_DOMAINS_PATH=%AS_INSTALL%\domains
set AS_DEF_NODES_PATH=%AS_INSTALL%\nodes

set ASADMIN_MODULEPATH="%AS_INSTALL%\lib\bootstrap"
set ASADMIN_JVM_OPTIONS="-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager"
set ASADMIN_CLASSPATH="%AS_INSTALL%\admin-cli.jar:%AS_INSTALL%\lib\asadmin\*:%AS_INSTALL%\modules\admin-util.jar:%AS_INSTALL%\modules\backup.jar:%AS_INSTALL%\modules\cluster-common.jar:%AS_INSTALL%\modules\config-api.jar:%AS_INSTALL%\modules\config-types.jar:%AS_INSTALL%\modules\common-util.jar:%AS_INSTALL%\modules\glassfish-api.jar:%AS_INSTALL%\modules\hk2.jar:%AS_INSTALL%\modules\hk2-config-generator.jar:%AS_INSTALL%\modules\jackson-core.jar:%AS_INSTALL%\modules\jakarta.activation-api.jar:%AS_INSTALL%\modules\jakarta.validation-api.jar:%AS_INSTALL%\modules\jakarta.xml.bind-api.jar:%AS_INSTALL%\modules\jaxb-osgi.jar:%AS_INSTALL%\modules\jettison.jar:%AS_INSTALL%\modules\launcher.jar:%AS_INSTALL%\modules\mimepull.jar"
set ASADMIN_MODULEPATH=%AS_INSTALL%\lib\bootstrap
set ASADMIN_JVM_OPTIONS=-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager
set ASADMIN_CLASSPATH=%AS_INSTALL%\admin-cli.jar;%AS_INSTALL%\lib\asadmin\*;%AS_INSTALL%\modules\admin-util.jar;%AS_INSTALL%\modules\backup.jar;%AS_INSTALL%\modules\cluster-common.jar;%AS_INSTALL%\modules\config-api.jar;%AS_INSTALL%\modules\config-types.jar;%AS_INSTALL%\modules\common-util.jar;%AS_INSTALL%\modules\glassfish-api.jar;%AS_INSTALL%\modules\hk2.jar;%AS_INSTALL%\modules\hk2-config-generator.jar;%AS_INSTALL%\modules\jackson-core.jar;%AS_INSTALL%\modules\jakarta.activation-api.jar;%AS_INSTALL%\modules\jakarta.validation-api.jar;%AS_INSTALL%\modules\jakarta.xml.bind-api.jar;%AS_INSTALL%\modules\jaxb-osgi.jar;%AS_INSTALL%\modules\jettison.jar;%AS_INSTALL%\modules\launcher.jar;%AS_INSTALL%\modules\mimepull.jar
3 changes: 3 additions & 0 deletions nucleus/distributions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<configuration>
<executable>${nadmin.executable}</executable>
<commandlineArgs>${create-domain.args}</commandlineArgs>
<inheritIo>true</inheritIo>
<!-- To make it work on Windows too -->
<longClasspath>true</longClasspath>
</configuration>
</execution>
</executions>
Expand Down

0 comments on commit b2e3b9e

Please sign in to comment.