static void validateJarManifest ( final Attributes mainAttributes ) throws InvalidManifestException { final String value1 = mainAttributes . getValue ( RUNDECK_PLUGIN_ARCHIVE ) ; final String plugvers = mainAttributes . getValue ( RUNDECK_PLUGIN_VERSION ) ; final String plugclassnames = mainAttributes . getValue ( RUNDECK_PLUGIN_CLASSNAMES ) ; if ( null == value1 ) { throw new InvalidManifestException ( "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_ARCHIVE ) ; } else if ( ! "true" . equals ( value1 ) ) { throw new InvalidManifestException ( RUNDECK_PLUGIN_ARCHIVE + " was not 'true': " + value1 ) ; } if ( null == plugvers ) { throw new InvalidManifestException ( "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_VERSION ) ; } final VersionCompare pluginVersion = VersionCompare . forString ( plugvers ) ; if ( ! pluginVersion . atLeast ( LOWEST_JAR_PLUGIN_VERSION ) ) { throw new InvalidManifestException ( "Unsupported plugin version: " + RUNDECK_PLUGIN_VERSION + ": " + plugvers ) ; } if ( null == plugclassnames ) { throw new InvalidManifestException ( "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_CLASSNAMES ) ; } if ( plugvers . equals ( JAR_PLUGIN_VERSION_2_0 ) ) { String pluginName = mainAttributes . getValue ( RUNDECK_PLUGIN_NAME ) ; if ( pluginName == null ) throw new InvalidManifestException ( "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_NAME ) ; String rundeckCompat = mainAttributes . getValue ( RUNDECK_PLUGIN_RUNDECK_COMPAT_VER ) ; if ( rundeckCompat == null ) throw new InvalidManifestException ( "Jar plugin manifest attribute missing: " + RUNDECK_PLUGIN_RUNDECK_COMPAT_VER ) ; ArrayList < String > errors = new ArrayList <> ( ) ; PluginValidation . State state = PluginMetadataValidator . validateRundeckCompatibility ( errors , rundeckCompat ) ; if ( ! state . isValid ( ) ) { throw new InvalidManifestException ( String . join ( "\n" , errors ) ) ; } } }
Validate whether the jar file has a valid manifest throw exception if invalid