Package ca.corbett.extensions
Class AppExtensionInfo
java.lang.Object
ca.corbett.extensions.AppExtensionInfo
Allows an extension to provide some basic metadata about itself.
Name, version, targetAppName, and targetAppVersion should be considered
mandatory, with the remaining fields being optional. Extra application-specific
fields can be thrown into the custom field map, but you are restricted
to simple single-line string values. Every extension should package
an extInfo.json file as a resource into its jar file so that it can
be discovered and interrogated by ExtensionManager.
See ExtensionManager.extractExtInfo() for more details.
Refer to the swing-extras documentation for full documentation.
- Since:
- 2023-11-11
- Author:
- scorbo2
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected final Stringstatic final Stringstatic final Stringstatic final Stringprotected static com.google.gson.Gsonstatic final intprotected final Stringprotected final Stringprotected final Stringprotected final Stringprotected final Stringprotected final Stringprotected final Stringprotected final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic intextractMajorVersion(String version) Extracts and returns the major version number from the given version string.static AppExtensionInfofromExtensionJar(Class<? extends AppExtension> extensionClass, String resource) Attempts to use the given Class to read extInfo from the given jar resource.static AppExtensionInfoAttempts to parse an AppExtensionInfo out of the given json.static AppExtensionInfofromStream(InputStream stream) Attempts to parse an AppExtensionInfo instance out of json read from the given InputStream.getCustomFieldValue(String fieldName) protected static com.google.gson.GsongetGson()intgetName()intinthashCode()final booleanisValid()Validates this AppExtensionInfo to ensure that all required fields are present and well-formed.toJson()
-
Field Details
-
INVALID
public static final int INVALID- See Also:
-
EXT_TYPE_BUILTIN
- See Also:
-
EXT_TYPE_SYSTEM
- See Also:
-
EXT_TYPE_USER
- See Also:
-
gson
protected static com.google.gson.Gson gson -
name
-
version
-
projectUrl
-
targetAppName
-
targetAppVersion
-
author
-
authorUrl
-
releaseNotes
-
shortDescription
-
longDescription
-
customFields
-
-
Constructor Details
-
AppExtensionInfo
-
-
Method Details
-
toJson
-
fromJson
Attempts to parse an AppExtensionInfo out of the given json. Any field not mentioned in the json will be returned as null.- Parameters:
json- A json representation of an AppExtensionInfo object.- Returns:
- An AppExtensionInfo object, or null if parsing was not possible.
-
fromStream
Attempts to parse an AppExtensionInfo instance out of json read from the given InputStream. Example usage in an extension:AppExtensionInfo.fromStream(this.getClass().getClassLoader().getResourceAsStream("/path/extInfo.json"));- Parameters:
stream- An InputStream containing json.- Returns:
- An AppExtensionInfo object, or null if parsing was not possible.
-
fromExtensionJar
public static AppExtensionInfo fromExtensionJar(Class<? extends AppExtension> extensionClass, String resource) Attempts to use the given Class to read extInfo from the given jar resource. This is intended to be invoked by extension jars, where resources have to be loaded from the class that is present in the jar that contains them.- Parameters:
extensionClass- the extension class responsible for loading the resource.resource- the jar resource to be loaded (full resource path and name of extInfo.json)- Returns:
- A parsed AppExtensionInfo object, or null if the resource could not be read.
-
extractMajorVersion
Extracts and returns the major version number from the given version string. Ignores any non-numeric characters. If no major version can be determined, returns INVALID. -
getName
-
getAuthor
-
getAuthorUrl
-
getProjectUrl
-
getVersion
-
getMajorVersion
public int getMajorVersion() -
getTargetAppName
-
getTargetAppVersion
-
getTargetAppMajorVersion
public int getTargetAppMajorVersion() -
getShortDescription
-
getLongDescription
-
getReleaseNotes
-
getCustomFieldNames
-
getCustomFieldValue
-
equals
-
hashCode
public int hashCode() -
isValid
public final boolean isValid()Validates this AppExtensionInfo to ensure that all required fields are present and well-formed. ExtensionManager will check this during extension load to ensure that the candidate extension has packaged a well-formed extInfo.json file. This method is final to prevent these checks from being relaxed or skipped. -
getGson
protected static com.google.gson.Gson getGson()
-