From 565ed4d2b3b0af8f34d453a7d263146b6841f483 Mon Sep 17 00:00:00 2001 From: Ruud Senden <8635138+rsenden@users.noreply.github.com> Date: Mon, 13 May 2024 18:22:21 +0200 Subject: [PATCH] chore: Move build properties generation, action updates --- fcli-core/fcli-app/build.gradle | 23 ----------------- fcli-core/fcli-common/build.gradle | 25 ++++++++++++++++++- .../action/helper/ActionLoaderHelper.java | 5 ++-- .../helper/ActionSchemaVersionHelper.java | 14 +++++++---- .../util/FcliBuildPropertiesHelper.java | 2 +- 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/fcli-core/fcli-app/build.gradle b/fcli-core/fcli-app/build.gradle index fa1372fe36..72a7c5a429 100644 --- a/fcli-core/fcli-app/build.gradle +++ b/fcli-core/fcli-app/build.gradle @@ -20,29 +20,6 @@ dependencies { runtimeOnly("org.fusesource.jansi:jansi") } -// Generate build properties and associated resource-config.json file -ext.buildPropertiesDir = "${buildDir}/generated-build-properties" -task generateFcliBuildProperties { - doLast { - def outputDir = "${buildPropertiesDir}/com/fortify/cli/app" - mkdir "${outputDir}" - ant.propertyfile(file: "${outputDir}/fcli-build.properties") { - entry(key: "projectName", value: "fcli") - entry(key: "projectVersion", value: project.version) - entry(key: "buildDate", value: buildTime.format('yyyy-MM-dd HH:mm:ss')) - } - def resourceConfigOutputDir = "${buildPropertiesDir}/META-INF/native-image/fcli-build-properties" - mkdir "${resourceConfigOutputDir}" - def contents = - '{"resources":[\n' + - ' {"pattern":"com/fortify/cli/app/fcli-build.properties"}\n' + - ']}\n' - file("${resourceConfigOutputDir}/resource-config.json").text = contents; - println contents - } -} -sourceSets.main.output.dir buildPropertiesDir, builtBy: generateFcliBuildProperties - // Generate reflect-config.json for picocli-related classes ext.generatedPicocliReflectConfigDir = "${buildDir}/generated-reflect-config" task generatePicocliReflectConfig(type: JavaExec) { diff --git a/fcli-core/fcli-common/build.gradle b/fcli-core/fcli-common/build.gradle index 37918181a1..869fbf6a0d 100644 --- a/fcli-core/fcli-common/build.gradle +++ b/fcli-core/fcli-common/build.gradle @@ -9,4 +9,27 @@ task zipResources_templates(type: Zip) { } } -apply from: "${sharedGradleScriptsDir}/fcli-java.gradle" \ No newline at end of file +apply from: "${sharedGradleScriptsDir}/fcli-java.gradle" + +// Generate build properties and associated resource-config.json file +ext.buildPropertiesDir = "${buildDir}/generated-build-properties" +task generateFcliBuildProperties { + doLast { + def outputDir = "${buildPropertiesDir}/com/fortify/cli/common" + mkdir "${outputDir}" + ant.propertyfile(file: "${outputDir}/fcli-build.properties") { + entry(key: "projectName", value: "fcli") + entry(key: "projectVersion", value: project.version) + entry(key: "buildDate", value: buildTime.format('yyyy-MM-dd HH:mm:ss')) + } + def resourceConfigOutputDir = "${buildPropertiesDir}/META-INF/native-image/fcli-build-properties" + mkdir "${resourceConfigOutputDir}" + def contents = + '{"resources":[\n' + + ' {"pattern":"com/fortify/cli/app/fcli-build.properties"}\n' + + ']}\n' + file("${resourceConfigOutputDir}/resource-config.json").text = contents; + println contents + } +} +sourceSets.main.output.dir buildPropertiesDir, builtBy: generateFcliBuildProperties \ No newline at end of file diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionLoaderHelper.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionLoaderHelper.java index 9f6aa4b01e..09ee621027 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionLoaderHelper.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionLoaderHelper.java @@ -261,8 +261,9 @@ private final String updateSchema(String actionText) { } else { schemaUri = propertyValue; } - if ( !ActionSchemaVersionHelper.isSupportedSchemaURI(schemaUri) ) { - LOG.warn("WARN: Action was designed for fcli version "+ActionSchemaVersionHelper.CURRENT_FCLI_VERSION+" and may fail"); + var schemaVersion = ActionSchemaVersionHelper.getSchemaVersion(schemaUri); + if ( !ActionSchemaVersionHelper.isSupportedSchemaVersion(schemaVersion) ) { + LOG.warn("WARN: Action was designed for fcli version "+schemaVersion+" and may fail"); } return result; } diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSchemaVersionHelper.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSchemaVersionHelper.java index 0d7508e32f..0e675d84ce 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSchemaVersionHelper.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/action/helper/ActionSchemaVersionHelper.java @@ -22,7 +22,6 @@ @Reflectable public final class ActionSchemaVersionHelper { private static final MessageFormat URI_FORMAT = new MessageFormat("https://fortify.github.io/fcli/schemas/action/fcli-action-schema-{0}.json"); - public static final String CURRENT_FCLI_VERSION = FcliBuildPropertiesHelper.getFcliVersion(); /** Get the schema URI for the current enum entry by formatting schema version as URI */ public static final String toURI(String version) { @@ -30,11 +29,15 @@ public static final String toURI(String version) { } /** Check whether given schema/version is supported */ - public static final boolean isSupportedSchemaURI(String schema) { + public static final boolean isSupportedSchemaURI(String schemaURI) { + return isSupportedSchemaVersion(getSchemaVersion(schemaURI)); + } + + public static final String getSchemaVersion(String schemaURI) { try { - return isSupportedSchemaVersion((String)URI_FORMAT.parse(schema)[0]); + return (String)URI_FORMAT.parse(schemaURI)[0]; } catch (ParseException e) { - return false; + return "unknown"; } } @@ -44,6 +47,7 @@ public static final boolean isSupportedSchemaVersion(String version) { } public static final List getSupportedSchemaVersions() { - return Arrays.asList(CURRENT_FCLI_VERSION.startsWith("0.")?"dev":CURRENT_FCLI_VERSION); + var fcliVersion = FcliBuildPropertiesHelper.getFcliVersion(); + return Arrays.asList(fcliVersion.startsWith("0.")?"dev":fcliVersion); } } \ No newline at end of file diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/util/FcliBuildPropertiesHelper.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/util/FcliBuildPropertiesHelper.java index 8c705a2dd7..81d6a99f12 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/util/FcliBuildPropertiesHelper.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/util/FcliBuildPropertiesHelper.java @@ -58,7 +58,7 @@ public static final String getFcliBuildInfo() { private static final Properties loadProperties() { final Properties p = new Properties(); - try (final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/fortify/cli/app/fcli-build.properties")) { + try (final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/fortify/cli/common/fcli-build.properties")) { if ( stream!=null ) { p.load(stream); } } catch ( IOException ioe ) { throw new RuntimeException("Error reading fcli-build.properties from classpath", ioe);