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 9b768ee
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 158 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 @@ -23,15 +23,15 @@ echo "Unable to enable extensions"
exit /B 1

:ok
set AS_INSTALL="%~dp0.."
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% --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,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) 2024 Contributors to the Eclipse Foundation
# Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
Expand All @@ -16,6 +16,17 @@
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
#

AS_INSTALL=`dirname "$0"`/../glassfish
export AS_INSTALL="$(dirname $(realpath -s $0))/../glassfish"
case "`uname`" in
CYGWIN*) AS_INSTALL=`cygpath --windows $AS_INSTALL`
esac
. "${AS_INSTALL}/config/asenv.conf"

exec java "-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager" -jar "$AS_INSTALL/admin-cli.jar" stop-domain "$@"
JAVA=java
if [ ${AS_JAVA} ]; then
JAVA=${AS_JAVA}/bin/java
fi

export 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 stop-domain "$@"
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
@echo off
REM
REM Copyright (c) 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


java "-Djava.util.logging.manager=org.glassfish.main.jul.GlassFishLogManager" -jar "%~dp0..\glassfish\admin-cli.jar" stop-domain %*
@echo off
REM
REM Copyright (c) 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 stop-domain %*
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();
}
}
}
Loading

0 comments on commit 9b768ee

Please sign in to comment.