craft_parts.plugins.ant_plugin module

The Ant plugin.

class craft_parts.plugins.ant_plugin.AntPlugin(*, properties, part_info)[source]

Bases: JavaPlugin

A plugin for Apache Ant projects.

The plugin requires the ant tool installed on the system. This can be achieved by adding the appropriate declarations to build-packages or build-snaps, or by having it installed or built in a different part. In this case, the name of the part supplying ant must be “ant-deps”.

Additionally, Java projects need a dev kit (jdk) to build and a runtime environment (jre) to run. There are multiple choices here, but frequently adding default-jdk-headless to build-packages and default-jre-headless to stage-packages is enough.

Once built, the plugin will create the following structure in the part’s install dir (which will later be staged/primed/packaged):

  • A bin/java symlink pointing to the actual java binary provided by the jre;

  • A jar/ directory containing the .jar files generated by the build.

The ant plugin uses the common plugin keywords, plus the following ant- specific keywords:

  • ant-build-targets (list of strings) The ant targets to build. These are directly passed to the ant command line.

  • ant-build-file (str) The name of the main ant build file. Defaults to build.xml.

  • ant-properties (dict of strings to strings) A series of key: value pairs that are passed to ant as properties (using the -D{key}={value} notation).

Parameters:
get_build_commands()[source]

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()[source]

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()[source]

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()[source]

Return a set of required snaps to install in the build environment.

Return type:

set[str]

properties_class

alias of AntPluginProperties

validator_class

alias of AntPluginEnvironmentValidator

class craft_parts.plugins.ant_plugin.AntPluginEnvironmentValidator(*, part_name, env, properties)[source]

Bases: PluginEnvironmentValidator

Check the execution environment for the Ant plugin.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties)

validate_environment(*, part_dependencies=None)[source]

Ensure the environment contains dependencies needed by the plugin.

Parameters:

part_dependencies (Optional[list[str]]) – A list of the parts this part depends on.

Raises:

PluginEnvironmentValidationError – If ant is invalid and there are no parts named ant.

Return type:

None

class craft_parts.plugins.ant_plugin.AntPluginProperties(**data)[source]

Bases: PluginProperties

The part properties used by the Ant plugin.

Parameters:

data (Any)

ant_build_file: str | None
ant_build_targets: list[str]
ant_properties: dict[str, str]
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'ant_build_file': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='ant-build-file', alias_priority=1), 'ant_build_targets': FieldInfo(annotation=list[str], required=False, default=[], alias='ant-build-targets', alias_priority=1), 'ant_properties': FieldInfo(annotation=dict[str, str], required=False, default={}, alias='ant-properties', alias_priority=1), 'plugin': FieldInfo(annotation=Literal['ant'], required=False, default='ant', alias='plugin', alias_priority=1), 'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

plugin: Literal['ant']
source: str