Skip to content

Commit

Permalink
Merge pull request #503 from psmf22/tool_debricked
Browse files Browse the repository at this point in the history
chore: add ignore unkown properties flag for tool*descriptors
  • Loading branch information
rsenden authored Jan 15, 2024
2 parents b9df50c + 26f3d3c commit 48b2b8f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.fortify.cli.tool._common.helper.ToolHelper;
import com.fortify.cli.tool._common.helper.ToolVersionArtifactDescriptor;
import com.fortify.cli.tool._common.helper.ToolVersionCombinedDescriptor;
import com.fortify.cli.tool._common.helper.ToolVersionDownloadDescriptor;
import com.fortify.cli.tool._common.helper.ToolVersionDescriptor;
import com.fortify.cli.tool._common.helper.ToolVersionInstallDescriptor;

import kong.unirest.UnirestInstance;
Expand Down Expand Up @@ -67,7 +67,7 @@ private static enum DigestMismatchAction {
@Override
public final JsonNode getJsonNode() {
String toolName = getToolName();
ToolVersionDownloadDescriptor descriptor = ToolHelper.getToolDownloadDescriptor(toolName).getVersionOrDefault(version);
ToolVersionDescriptor descriptor = ToolHelper.getToolDownloadDescriptor(toolName).getVersionOrDefault(version);
return downloadAndInstall(toolName, descriptor);
}

Expand All @@ -81,7 +81,7 @@ public boolean isSingular() {
return true;
}

private final JsonNode downloadAndInstall(String toolName, ToolVersionDownloadDescriptor downloadDescriptor) {
private final JsonNode downloadAndInstall(String toolName, ToolVersionDescriptor downloadDescriptor) {
try {
Path installPath = getInstallPathOrDefault(downloadDescriptor);
Path binPath = getBinPath(downloadDescriptor);
Expand All @@ -105,7 +105,7 @@ private final File download(ToolVersionArtifactDescriptor artifactDescriptor) th
return tempDownloadFile;
}

private final ToolVersionArtifactDescriptor getArtifactDescriptor(ToolVersionDownloadDescriptor downloadDescriptor, String type) {
private final ToolVersionArtifactDescriptor getArtifactDescriptor(ToolVersionDescriptor downloadDescriptor, String type) {
if(type==null || type.isBlank()) {
String OSString = OsAndArchHelper.getOSString();
String archString = OsAndArchHelper.getArchString();
Expand Down Expand Up @@ -144,19 +144,19 @@ protected void install(ToolVersionInstallDescriptor descriptor, File downloadedF
}

@SneakyThrows
protected Path getInstallPathOrDefault(ToolVersionDownloadDescriptor descriptor) {
protected Path getInstallPathOrDefault(ToolVersionDescriptor descriptor) {
if ( installDir == null ) {
installDir = FcliDataHelper.getFortifyHomePath().resolve(String.format("tools/%s/%s", getToolName(), descriptor.getVersion())).toFile();
}
return installDir.getCanonicalFile().toPath();
}

protected Path getBinPath(ToolVersionDownloadDescriptor descriptor) {
protected Path getBinPath(ToolVersionDescriptor descriptor) {
return getInstallPathOrDefault(descriptor).resolve("bin");
}

protected abstract String getToolName();
protected InstallType getInstallType(ToolVersionDownloadDescriptor descriptor) {
protected InstallType getInstallType(ToolVersionDescriptor descriptor) {
ToolVersionArtifactDescriptor artifact = getArtifactDescriptor(descriptor, type);
if(artifact.getName().endsWith("gz")) {
return InstallType.EXTRACT_TGZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,36 @@
import java.util.Arrays;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.formkiq.graalvm.annotations.Reflectable;
import com.fortify.cli.common.util.StringUtils;

import lombok.Data;
import lombok.NoArgsConstructor;

@JsonIgnoreProperties(ignoreUnknown=true)
@Reflectable @NoArgsConstructor
@Data
public class ToolDefinitionsDescriptor {
private String schema_version;
private ToolVersionDownloadDescriptor[] versions;
private ToolVersionDescriptor[] versions;

public final ToolVersionDownloadDescriptor[] getVersions() {
return getVersionsStream().toArray(ToolVersionDownloadDescriptor[]::new);
public final ToolVersionDescriptor[] getVersions() {
return getVersionsStream().toArray(ToolVersionDescriptor[]::new);
}

public final Stream<ToolVersionDownloadDescriptor> getVersionsStream() {
public final Stream<ToolVersionDescriptor> getVersionsStream() {
return Stream.of(versions);
}

public final ToolVersionDownloadDescriptor getVersion(String version) {
public final ToolVersionDescriptor getVersion(String version) {
return getVersionsStream()
.filter(v-> (v.getVersion().equals(version) || Arrays.stream(v.getAliases()).anyMatch(version::equals)) )
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Version "+version+" not defined"));
}

public final ToolVersionDownloadDescriptor getVersionOrDefault(String versionName) {
public final ToolVersionDescriptor getVersionOrDefault(String versionName) {
if ( StringUtils.isBlank(versionName) || "default".equals(versionName)) {
versionName = "latest";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static final ToolDefinitionsDescriptor getToolDownloadDescriptor(String t
}

public static final ToolVersionCombinedDescriptor saveToolVersionInstallDescriptor(String toolName, ToolVersionInstallDescriptor installDescriptor) {
ToolVersionDownloadDescriptor downloadDescriptor = installDescriptor.getOriginalDownloadDescriptor();
ToolVersionDescriptor downloadDescriptor = installDescriptor.getOriginalDownloadDescriptor();
FcliDataHelper.saveFile(getInstallDescriptorPath(toolName, downloadDescriptor.getVersion()), installDescriptor, true);
return new ToolVersionCombinedDescriptor(toolName, downloadDescriptor, installDescriptor);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.fortify.cli.tool._common.helper;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.formkiq.graalvm.annotations.Reflectable;

import lombok.Data;
import lombok.NoArgsConstructor;

@JsonIgnoreProperties(ignoreUnknown=true)
@Reflectable @NoArgsConstructor
@Data
public final class ToolVersionArtifactDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
import java.util.function.Function;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.formkiq.graalvm.annotations.Reflectable;
import com.fortify.cli.common.util.StringUtils;

import lombok.Data;

@JsonIgnoreProperties(ignoreUnknown=true)
@Reflectable // We only serialize, not de-serialize, so no need for no-args contructor
@Data
public class ToolVersionCombinedDescriptor {
private final String name;
@JsonIgnore private final ToolVersionDownloadDescriptor downloadDescriptor;
@JsonIgnore private final ToolVersionDescriptor downloadDescriptor;
@JsonIgnore private final ToolVersionInstallDescriptor installDescriptor;

public String getVersion() {
Expand Down Expand Up @@ -79,7 +81,7 @@ private Path getPath(Function<ToolVersionInstallDescriptor, Path> f) {
}

@JsonIgnore
private ToolVersionDownloadDescriptor getInstalledOrDefaultDownloadDescriptor() {
private ToolVersionDescriptor getInstalledOrDefaultDownloadDescriptor() {
return installDescriptor==null || installDescriptor.getOriginalDownloadDescriptor()==null
? downloadDescriptor : installDescriptor.getOriginalDownloadDescriptor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@

import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.formkiq.graalvm.annotations.Reflectable;
import lombok.Data;
import lombok.NoArgsConstructor;

@JsonIgnoreProperties(ignoreUnknown=true)
@Reflectable @NoArgsConstructor
@Data
public final class ToolVersionDownloadDescriptor {
public final class ToolVersionDescriptor {
private String version;
private String[] aliases;
private boolean stable;
private Map<String, ToolVersionArtifactDescriptor> artifacts;

//old fields for backwards compatibility
private String downloadUrl;
private String digest;
private String isDefaultVersion = "No";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
import java.nio.file.Paths;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.formkiq.graalvm.annotations.Reflectable;
import com.fortify.cli.common.util.StringUtils;

import lombok.Data;
import lombok.NoArgsConstructor;

@JsonIgnoreProperties(ignoreUnknown=true)
@Reflectable @NoArgsConstructor
@Data
public class ToolVersionInstallDescriptor {
private ToolVersionDownloadDescriptor originalDownloadDescriptor;
private ToolVersionDescriptor originalDownloadDescriptor;
private String installDir;
private String binDir;
@JsonIgnore Path installPath;
@JsonIgnore Path binPath;

public ToolVersionInstallDescriptor(ToolVersionDownloadDescriptor originalDownloadDescriptor, Path installPath, Path binPath) {
public ToolVersionInstallDescriptor(ToolVersionDescriptor originalDownloadDescriptor, Path installPath, Path binPath) {
this.originalDownloadDescriptor = originalDownloadDescriptor;
this.installPath = installPath.toAbsolutePath();
this.installDir = installPath.toString();
Expand Down

0 comments on commit 48b2b8f

Please sign in to comment.