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 <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Nov 9, 2024
1 parent 74ea722 commit 2e11bf8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 41 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
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 @@ -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 @@ -33,4 +33,5 @@ goto run
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 %*

0 comments on commit 2e11bf8

Please sign in to comment.