Skip to content

Commit

Permalink
chore: Move build properties generation, action updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed May 13, 2024
1 parent 15a0be7 commit 565ed4d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
23 changes: 0 additions & 23 deletions fcli-core/fcli-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 24 additions & 1 deletion fcli-core/fcli-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,27 @@ task zipResources_templates(type: Zip) {
}
}

apply from: "${sharedGradleScriptsDir}/fcli-java.gradle"
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@

@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) {
return URI_FORMAT.format(new Object[] {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";
}
}

Expand All @@ -44,6 +47,7 @@ public static final boolean isSupportedSchemaVersion(String version) {
}

public static final List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 565ed4d

Please sign in to comment.