Module ploigos_step_runner.utils.maven

Shared utils for maven operations.

Functions

def add_maven_mirror(parent_element, maven_mirror_id, maven_mirror_url, maven_mirror_mirror_of)

Adds a element to given parent element.

Parameters

parent_element : ElementTree.Element
Parent element to add new element to
maven_mirror_id : str
Value for element.
maven_mirror_url : str
Value for element.
maven_mirror_mirror_of : str
Value for element.
def add_maven_mirrors(parent_element, maven_mirrors)

Add element for given maven mirror to element to given parent element.

Parameters

parent_element : ET.Element
Parent element to add element to.
maven_mirrors : (dict, list)
List of dicts or dicts of dicts of maven mirror configurations.

Raises

AssertionError
  • if maven mirror id not given
  • if maven mirror url not given
  • if maven mirror mirror-of not given
def add_maven_repositories(parent_element, maven_repositories)

Adds element to parent element and child element for each given maven repository.

Parameters

parent_element : ET.Element
Parent element to add the element to.
maven_repositories : (dict, list)
List of dicts or dicts of dicts to create elements for.

Raises

AssertionError
  • id not specified
  • url not specified
def add_maven_repository(parent_element, repository_id, repository_url, releases_enabled=None, snapshots_enabled=None)

Add a element to the given parent element

Parameters

parent_element : ET.Element
Parent elemtnt to add the element to.
repository_id : str
Value for the element
repository_url : str
Value for the element
releases_enabled : (str, bool), optional
Value for {snapshots_enabled}
snapshots_enabled : (str, bool), optional
Value for {snapshots_enabled}
def add_maven_server(parent_element, maven_server_id, maven_server_username=None, maven_server_password=None)

Adds a element to the given parent element.

Parameters

parent_element : ET.Element
The parent element to append the new server too.
maven_server_id : str
ID of the maven server to add.
maven_server_username : str, optional
Username for the maven server to add. Only used if maven_server_password also provided.
maven_server_password : str, optional
Password for the maven server to add. Only used if maven_server_username is provided.
def add_maven_servers(parent_element, maven_servers)

Adds element to parent element and creates elements for each given maven server.

Parameters

parent_element : ET.Element
Parent element to add the element too.
maven_servers : (dict, list)
List of dicts or dicts of dicts to create elements for.

Raises

AssertionError
  • if username given without password or password without username
  • if no id given
def generate_maven_settings(working_dir, maven_servers, maven_repositories, maven_mirrors)

Generates and returns a settings.xml file from the inputs it is provided.

Parameters

maven_servers: Dictionary of id, username, password maven_repositories: Dictionary of id, url, snapshots, releases maven_mirrors: Dictionary of id, url, mirror_of

Raises

ValueError
If the given file can not be parsed as YAML or JSON.

Returns

Str
The path to the settings.xml that was generated.
def get_effective_pom(work_dir_path, pom_file, profiles)

Writes the effective pom to a file if it does not already exist and returns the path.

Parameters

work_dir_path : str
Path to write the effective pom to if it does not already exist
pom_file : str
Path to pom file to create the effective pom for.
profiles : [str]
Profile(s) to use when generating the effective pom

Returns

str
Path to the written effective pom generated from the 'pom-file' value.
def get_maven_plugin_xml_element_path(plugin_name)

Create XML element path for a given maven plugin.

Parameters

plugin_name : str
Maven plugin name to get the XML element path for

Returns

str
XML element path for the given maven plugin.
def get_plugin_configuration_absolute_path_values(plugin_name, configuration_key, work_dir_path, pom_file, profiles=None, phases_and_goals=None, require_phase_execution_config=False)

Gets the value(s) of a given configuration key for a given maven plugin and converts them to absolute paths (if they arn't already), if they were relative paths, assumes, relative to the given pom file.

Will create an effective pom out of the given pom so as to be able to inherit configuration from parent poms.

Will search: * executions for given phase, return all matches * if no matching executions will search plugin non execution specific configuration

Paramters

plugin_name : str Name of the maven plugin to get the configuration value(s) for. configuration_key : str Configuration key of the maven plugin to get the configuration value(s) for. work_dir_path : str A working path to use to write the effective pom to for searching. pom_file : str Maven pom file to create the effective pom for to then search for the plugin configuration. profiles : [str] List of maven profiles to activate when creating the effective pom to search. phases_and_goals : [str] List of phases and goals to search for specific plugin executions for for the configuration value(s). require_phase_execution_config : bool True if the found configuration must be in a plugin execution matching one of the given phases. False if the found configuration can be a default configuration.

Raises

RuntimeError
If the given plugin can not be found in the effective pom.

Returns

[str] List of configuration values found, or empty list if none found.

def get_plugin_configuration_values(plugin_name, configuration_key, work_dir_path, pom_file, profiles=None, phases_and_goals=None, require_phase_execution_config=False)

Gets the value(s) of a given configuration key for a given maven plugin.

Will create an effective pom out of the given pom so as to be able to inherit configuration from parent poms.

Will search: * executions for given phase, return all matches * if no matching executions will search plugin non execution specific configuration

Paramters

plugin_name : str Name of the maven plugin to get the configuration value(s) for. configuration_key : str Configuration key of the maven plugin to get the configuration value(s) for. work_dir_path : str A working path to use to write the effective pom to for searching. pom_file : str Maven pom file to create the effective pom for to then search for the plugin configuration. profiles : [str] List of maven profiles to activate when creating the effective pom to search. phases_and_goals : [str] List of phases and goals to search for specific plugin executions for for the configuration value(s). require_phase_execution_config : bool True if the found configuration must be in a plugin execution matching one of the given phases. False if the found configuration can be a default configuration.

Raises

RuntimeError
If the given plugin can not be found in the effective pom.

Returns

[str] List of configuration values found, or empty list if none found.

def run_maven(mvn_output_file_path, settings_file, pom_file, phases_and_goals, tls_verify=True, additional_arguments=None, profiles=None, no_transfer_progress=True)

Runs maven using the given configuration.

Parameters

mvn_output_file_path : str
Path to file containing the maven stdout and stderr output.
phases_and_goals : [str]
List of maven phases and/or goals to execute.
additional_arguments : [str]
List of additional arguments to use.
pom_file : str (path)
pom used when executing maven.
tls_verify : boolean
Disables TLS Verification if set to False
profiles : [str]
List of maven profiles to use.
no_transfer_progress : boolean
True to suppress the transfer progress of packages maven downloads. False to have the transfer progress printed. See https://maven.apache.org/ref/current/maven-embedder/cli.html
settings_file : str (path)
Maven settings file to use.

Returns

str
Standard Out from running Maven.

Raises

StepRunnerException
If maven returns a none 0 exit code.
def write_effective_pom(pom_file_path, output_path, profiles=None)

Generates the effective pom for a given pom and writes it to a given directory

Parameters

pom_file_path : str
Path to pom file to render the effective pom for.
output_path : str
Path to write the effective pom to.
profiles : list
Maven profiles to use when generating the effective pom.

See

Returns

str
Absolute path to the written effective pom generated from the given pom file path.

Raises

StepRunnerException
If issue generating effective pom.