Skip to content

Commit

Permalink
chore: Improve global bin script processing
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Jan 25, 2024
1 parent 923e90b commit 34947f6
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
import com.fortify.cli.common.util.FcliDataHelper;

public final class ToolInstallationHelper {
public static final String getToolResourceDir(String toolName) {
return String.format("com/fortify/cli/tool/%s", toolName);
}

public static final String getToolResourceFile(String toolName, String fileName) {
return String.format("%s/%s", getToolResourceDir(toolName.replace('-', '_')), fileName);
public static final String getToolResourceLocation(String subPath) {
return String.format("com/fortify/cli/tool/%s", subPath);
}

public static Path getToolsStatePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public static enum DigestMismatchAction {
fail, warn
}

public static enum GlobalBinScriptType {
bash, bat
}

public final ToolDefinitionRootDescriptor getDefinitionRootDescriptor() {
return _definitionRootDescriptor.get(()->ToolDefinitionsHelper.getToolDefinitionRootDescriptor(toolName));
}
Expand Down Expand Up @@ -145,21 +149,21 @@ public final void copyBinResource(String resourceFile) {
}

@SneakyThrows
public final void copyGlobalBinResource(String resourceFile) {
public final void installGlobalBinScript(GlobalBinScriptType type, String globalBinScriptName, String target) {
var globalBinPath = getGlobalBinPath();
if ( globalBinPath!=null ) {
var fullResourceFile = getFullResourceFile(resourceFile);
var destFilePath = globalBinPath.resolve(Path.of(resourceFile).getFileName());
FileUtils.copyResource(fullResourceFile, destFilePath, StandardCopyOption.REPLACE_EXISTING);
var resourceFile = ToolInstallationHelper.getToolResourceLocation("extra-files/global-bin/"+type.name());
var destFilePath = globalBinPath.resolve(globalBinScriptName);
FileUtils.copyResource(resourceFile, destFilePath, StandardCopyOption.REPLACE_EXISTING);
String content = new String(Files.readAllBytes(destFilePath), "ASCII");
content = content.replace("{{binDir}}", getBinPath().toString());
content = content.replace("{{target}}", getTargetPath().resolve(target).toString());
Files.write(destFilePath, content.getBytes("ASCII"));
ToolInstaller.updateFilePermissions(destFilePath);
}
}

private String getFullResourceFile(String resourceFile) {
return String.format("com/fortify/cli/tool/%s/%s", getToolName().replace("-", "_"), resourceFile);
return ToolInstallationHelper.getToolResourceLocation(String.format("%s/%s", getToolName().replace("-", "_"), resourceFile));
}

private final ToolInstallationResult install(ToolDefinitionArtifactDescriptor artifactDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -38,8 +39,8 @@ protected String getDefaultArtifactType() {
protected void postInstall(ToolInstaller installer, ToolInstallationResult installationResult) {
installer.copyBinResource("extra-files/bin/FortifyBugTrackerUtility");
installer.copyBinResource("extra-files/bin/FortifyBugTrackerUtility.bat");
installer.copyGlobalBinResource("extra-files/global_bin/FortifyBugTrackerUtility");
installer.copyGlobalBinResource("extra-files/global_bin/FortifyBugTrackerUtility.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "FortifyBugTrackerUtility", "bin/FortifyBugTrackerUtility");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "FortifyBugTrackerUtility.bat", "bin/FortifyBugTrackerUtility.bat");

var targetPath = installer.getTargetPath();
var jarFiles = Files.find(targetPath, 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.fortify.cli.common.util.FileUtils;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -36,7 +37,7 @@ protected String getDefaultArtifactType() {
@Override @SneakyThrows
protected void postInstall(ToolInstaller installer, ToolInstallationResult installationResult) {
FileUtils.moveFiles(installer.getTargetPath(), installer.getBinPath(), "debricked(\\.exe)?");
installer.copyGlobalBinResource("extra-files/global_bin/debricked");
installer.copyGlobalBinResource("extra-files/global_bin/debricked.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "debricked", "bin/debricked");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "debricked.bat", "bin/debricked.exe");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fortify.cli.common.util.FileUtils;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -43,11 +44,11 @@ protected void postInstall(ToolInstaller installer, ToolInstallationResult insta
if ( Files.exists(installPath.resolve("fcli.jar")) ) {
installer.copyBinResource("extra-files/jar/bin/fcli");
installer.copyBinResource("extra-files/jar/bin/fcli.bat");
installer.copyGlobalBinResource("extra-files/jar/global_bin/fcli");
installer.copyGlobalBinResource("extra-files/jar/global_bin/fcli.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "fcli", "bin/fcli");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "fcli.bat", "bin/fcli.bat");
} else {
installer.copyGlobalBinResource("extra-files/native/global_bin/fcli");
installer.copyGlobalBinResource("extra-files/native/global_bin/fcli.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "fcli", "bin/fcli");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "fcli.bat", "bin/fcli.exe");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -36,7 +37,7 @@ protected String getDefaultArtifactType() {
protected void postInstall(ToolInstaller installer, ToolInstallationResult installationResult) {
installer.copyBinResource("extra-files/bin/FoDUpload");
installer.copyBinResource("extra-files/bin/FoDUpload.bat");
installer.copyGlobalBinResource("extra-files/global_bin/FoDUpload");
installer.copyGlobalBinResource("extra-files/global_bin/FoDUpload.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "FoDUpload", "bin/FoDUpload");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "FoDUpload.bat", "bin/FoDUpload.bat");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fortify.cli.common.util.StringUtils;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -44,8 +45,8 @@ protected String getDefaultArtifactType() {
@Override @SneakyThrows
protected void postInstall(ToolInstaller installer, ToolInstallationResult installationResult) {
updateClientAuthToken(installer.getTargetPath());
installer.copyGlobalBinResource("extra-files/global_bin/scancentral");
installer.copyGlobalBinResource("extra-files/global_bin/scancentral.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "scancentral", "bin/scancentral");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "scancentral.bat", "bin/scancentral.bat");
}

private void updateClientAuthToken(Path installPath) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fortify.cli.common.output.cli.mixin.OutputHelperMixins;
import com.fortify.cli.tool._common.cli.cmd.AbstractToolInstallCommand;
import com.fortify.cli.tool._common.helper.ToolInstaller;
import com.fortify.cli.tool._common.helper.ToolInstaller.GlobalBinScriptType;
import com.fortify.cli.tool._common.helper.ToolInstaller.ToolInstallationResult;

import lombok.Getter;
Expand All @@ -36,7 +37,7 @@ protected String getDefaultArtifactType() {
protected void postInstall(ToolInstaller installer, ToolInstallationResult installationResult) {
installer.copyBinResource("extra-files/bin/FortifyVulnerabilityExporter");
installer.copyBinResource("extra-files/bin/FortifyVulnerabilityExporter.bat");
installer.copyGlobalBinResource("extra-files/global_bin/FortifyVulnerabilityExporter");
installer.copyGlobalBinResource("extra-files/global_bin/FortifyVulnerabilityExporter.bat");
installer.installGlobalBinScript(GlobalBinScriptType.bash, "FortifyVulnerabilityExporter", "bin/FortifyVulnerabilityExporter");
installer.installGlobalBinScript(GlobalBinScriptType.bat, "FortifyVulnerabilityExporter.bat", "bin/FortifyVulnerabilityExporter.bat");
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
{{target}} "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@ECHO OFF
{{target}} %*

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 34947f6

Please sign in to comment.