test paths
This commit is contained in:
@@ -206,38 +206,29 @@ public class CfCliService {
|
|||||||
|
|
||||||
log.info("Detected operating system: {}", os);
|
log.info("Detected operating system: {}", os);
|
||||||
log.info("CF CLI executable name: {}", executable);
|
log.info("CF CLI executable name: {}", executable);
|
||||||
log.info("Java temp dir: {}", System.getProperty("java.io.tmpdir"));
|
|
||||||
log.info("User home: {}", System.getProperty("user.home"));
|
|
||||||
log.info("Current working directory: {}", System.getProperty("user.dir"));
|
|
||||||
|
|
||||||
// Use Spring's ClassPathResource for proper Spring Boot JAR support
|
String userDir = System.getProperty("user.dir");
|
||||||
String resourcePath = String.format("cf-cli/%s/%s", os, executable);
|
log.info("User directory (user.dir): {}", userDir);
|
||||||
log.info("Looking for CF CLI binary at classpath resource: {}", resourcePath);
|
|
||||||
|
|
||||||
ClassPathResource resource = new ClassPathResource(resourcePath);
|
// In Spring Boot fat JAR on Tanzu, the structure is:
|
||||||
|
// /home/vcap/app/BOOT-INF/classes/cf-cli/linux/cf8
|
||||||
|
Path directPath = Path.of(userDir, "BOOT-INF", "classes", "cf-cli", os, executable);
|
||||||
|
log.info("Checking for CF CLI at direct file path: {}", directPath);
|
||||||
|
|
||||||
if (!resource.exists()) {
|
if (Files.exists(directPath) && Files.isReadable(directPath)) {
|
||||||
log.error("CF CLI binary not found in classpath for OS: {}. Resource path: {}", os, resourcePath);
|
log.info("Found CF CLI binary at direct file path: {} ({} bytes)",
|
||||||
log.error("Resource exists: {}, isReadable: {}", resource.exists(), resource.isReadable());
|
directPath, Files.size(directPath));
|
||||||
throw new IOException("CF CLI binary not found for OS: " + os + " at classpath: " + resourcePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("CF CLI resource found - exists: {}, isReadable: {}, contentLength: {} bytes",
|
|
||||||
resource.exists(), resource.isReadable(), resource.contentLength());
|
|
||||||
|
|
||||||
File tempFile = File.createTempFile("cf-cli-", os.equals("windows") ? ".exe" : "");
|
File tempFile = File.createTempFile("cf-cli-", os.equals("windows") ? ".exe" : "");
|
||||||
tempFile.deleteOnExit();
|
tempFile.deleteOnExit();
|
||||||
log.info("Created temp file: {}", tempFile.getAbsolutePath());
|
log.info("Created temp file: {}", tempFile.getAbsolutePath());
|
||||||
|
|
||||||
log.info("Extracting CF CLI from classpath resource: {}", resourcePath);
|
// Copy from direct file path to temp file
|
||||||
|
long bytesCopied = Files.copy(directPath, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
try (InputStream inputStream = resource.getInputStream()) {
|
log.info("Copied CF CLI to temp file: {} ({} bytes)", tempFile.getAbsolutePath(), bytesCopied);
|
||||||
long bytesCopied = Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
log.info("CF CLI extracted to temporary file: {} ({} bytes)", tempFile.getAbsolutePath(), bytesCopied);
|
|
||||||
|
|
||||||
if (bytesCopied == 0) {
|
if (bytesCopied == 0) {
|
||||||
throw new IOException("CF CLI extraction failed - 0 bytes copied from " + resourcePath);
|
throw new IOException("CF CLI copy failed - 0 bytes copied from " + directPath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!os.equals("windows")) {
|
if (!os.equals("windows")) {
|
||||||
@@ -249,19 +240,18 @@ public class CfCliService {
|
|||||||
Files.setPosixFilePermissions(tempFile.toPath(), perms);
|
Files.setPosixFilePermissions(tempFile.toPath(), perms);
|
||||||
log.info("Set executable permissions on CF CLI binary using Java NIO");
|
log.info("Set executable permissions on CF CLI binary using Java NIO");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Failed to set permissions using Java NIO, trying chmod command: {}", e.getMessage());
|
log.warn("Failed to set permissions using Java NIO, trying chmod: {}", e.getMessage());
|
||||||
try {
|
try {
|
||||||
ProcessBuilder pb = new ProcessBuilder("chmod", "+x", tempFile.getAbsolutePath());
|
ProcessBuilder pb = new ProcessBuilder("chmod", "+x", tempFile.getAbsolutePath());
|
||||||
Process p = pb.start();
|
Process p = pb.start();
|
||||||
int exitCode = p.waitFor();
|
int exitCode = p.waitFor();
|
||||||
if (exitCode == 0) {
|
if (exitCode == 0) {
|
||||||
log.info("Successfully set executable permissions using chmod command");
|
log.info("Successfully set executable permissions using chmod");
|
||||||
} else {
|
} else {
|
||||||
log.error("chmod command failed with exit code: {}", exitCode);
|
log.error("chmod failed with exit code: {}", exitCode);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Failed to set executable permissions: {}", ex.getMessage(), ex);
|
log.error("Failed to set executable permissions: {}", ex.getMessage(), ex);
|
||||||
throw new IOException("Unable to set executable permissions on CF CLI binary", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,6 +263,51 @@ public class CfCliService {
|
|||||||
return tempFile.getAbsolutePath();
|
return tempFile.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback to classpath resource loading (for local development)
|
||||||
|
log.info("Direct file path not found, falling back to classpath resource loading");
|
||||||
|
String resourcePath = "cf-cli/" + os + "/" + executable;
|
||||||
|
log.info("Looking for CF CLI at classpath resource: {}", resourcePath);
|
||||||
|
|
||||||
|
ClassPathResource resource = new ClassPathResource(resourcePath);
|
||||||
|
|
||||||
|
if (!resource.exists()) {
|
||||||
|
log.error("CF CLI binary not found at direct path: {}", directPath);
|
||||||
|
log.error("CF CLI binary not found in classpath: {}", resourcePath);
|
||||||
|
throw new IOException("CF CLI binary not found for OS: " + os);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Found CF CLI in classpath, extracting...");
|
||||||
|
|
||||||
|
File tempFile = File.createTempFile("cf-cli-", os.equals("windows") ? ".exe" : "");
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
log.info("Created temp file: {}", tempFile.getAbsolutePath());
|
||||||
|
|
||||||
|
try (InputStream inputStream = resource.getInputStream()) {
|
||||||
|
long bytesCopied = Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
log.info("CF CLI extracted to temp file: {} ({} bytes)", tempFile.getAbsolutePath(), bytesCopied);
|
||||||
|
|
||||||
|
if (bytesCopied == 0) {
|
||||||
|
throw new IOException("CF CLI extraction failed - 0 bytes copied");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!os.equals("windows")) {
|
||||||
|
try {
|
||||||
|
Set<PosixFilePermission> perms = new HashSet<>();
|
||||||
|
perms.add(PosixFilePermission.OWNER_READ);
|
||||||
|
perms.add(PosixFilePermission.OWNER_WRITE);
|
||||||
|
perms.add(PosixFilePermission.OWNER_EXECUTE);
|
||||||
|
Files.setPosixFilePermissions(tempFile.toPath(), perms);
|
||||||
|
log.info("Set executable permissions on CF CLI binary");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to set permissions: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Successfully prepared CF CLI executable: {}", tempFile.getAbsolutePath());
|
||||||
|
return tempFile.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
private String getOperatingSystem() {
|
private String getOperatingSystem() {
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
log.debug("System OS name property: {}", osName);
|
log.debug("System OS name property: {}", osName);
|
||||||
|
|||||||
Reference in New Issue
Block a user