def __auto_increment_version(self, auto_increment_version_segment, step_result): """Automatically increments a given version segment. Parameters --------- auto_increment_version_segment : str The version segment to auto increment. One of: major, minor, or patch step_result : StepResult Step result to add step results to. """ mvn_auto_increment_version_output_file_path = self.write_working_file( 'mvn_versions_set_output.txt' ) try: # SEE: https://www.mojohaus.org/build-helper-maven-plugin/parse-version-mojo.html new_version = None if auto_increment_version_segment == 'major': new_version = r'${parsedVersion.nextMajorVersion}.0.0' elif auto_increment_version_segment == 'minor': new_version = r'${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0' elif auto_increment_version_segment == 'patch': new_version = r'${parsedVersion.majorVersion}' \ r'.${parsedVersion.minorVersion}' \ r'.${parsedVersion.nextIncrementalVersion}' additional_arguments = [ f'-DnewVersion={new_version}' ] # determine if should auto increment all modules auto_increment_all_module_versions = self.get_value( 'auto-increment-all-module-versions' ) if auto_increment_all_module_versions: additional_arguments.append('-DprocessAllModules') run_maven( mvn_output_file_path=mvn_auto_increment_version_output_file_path, settings_file=self.maven_settings_file, pom_file=self.get_value('pom-file'), phases_and_goals=[ 'build-helper:parse-version', 'versions:set', 'versions:commit' ], additional_arguments=additional_arguments ) except StepRunnerException as error: raise StepRunnerException(f"Error running maven to auto increment version segment" f" ({auto_increment_version_segment})." f" More details maybe found in 'maven-auto-increment-version-output'" f" report artifact: {error}") from error finally: step_result.add_artifact( description="Standard out and standard error from running maven" \ " to auto increment version.", name='maven-auto-increment-version-output', value=mvn_auto_increment_version_output_file_path )
def __get_project_version(self, step_result): """Get the project version Parameters --------- step_result : StepResult Step result to add step results to. """ project_version = None mvn_evaluate_project_version_file_path = self.write_working_file( 'mvn_evaluate_project_version.txt' ) try: project_version = run_maven( mvn_output_file_path=mvn_evaluate_project_version_file_path, settings_file=self.maven_settings_file, pom_file=self.get_value('pom-file'), phases_and_goals=[ 'help:evaluate' ], additional_arguments=[ '-Dexpression=project.version', '--batch-mode', '-q', '-DforceStdout' ] ) except StepRunnerException as error: step_result.success = False step_result.message = f"Error running maven to get the project version: {error}" return project_version
def _run_maven_step( self, mvn_output_file_path, step_implementer_additional_arguments=None ): """Runs maven using the configuration given to this step runner. Parameters ---------- mvn_output_file_path : str Path to file containing the maven stdout and stderr output. step_implementer_additional_arguments : [] Additional arguments hard coded by the step implementer. Raises ------ StepRunnerException If maven returns a none 0 exit code. """ phases_and_goals = self.maven_phases_and_goals pom_file = self.get_value('pom-file') tls_verify = self.get_value('tls-verify') profiles = self.get_value('maven-profiles') no_transfer_progress = self.get_value('maven-no-transfer-progress') additional_arguments = [] if step_implementer_additional_arguments: additional_arguments = \ step_implementer_additional_arguments + self.get_value('maven-additional-arguments') else: additional_arguments = self.get_value('maven-additional-arguments') run_maven( mvn_output_file_path=mvn_output_file_path, phases_and_goals=phases_and_goals, additional_arguments=additional_arguments, pom_file=pom_file, tls_verify=tls_verify, profiles=profiles, no_transfer_progress=no_transfer_progress, settings_file=self.maven_settings_file )
def _run_step(self): # pylint: disable=too-many-locals """Runs the step implemented by this StepImplementer. Returns ------- StepResult Object containing the dictionary results of this step. """ step_result = StepResult.from_step_implementer(self) # Get config items maven_push_artifact_repo_id = self.get_value( 'maven-push-artifact-repo-id') maven_push_artifact_repo_url = self.get_value( 'maven-push-artifact-repo-url') version = self.get_value('version') # push the artifacts mvn_update_version_output_file_path = self.write_working_file( 'mvn_versions_set_output.txt') mvn_push_artifacts_output_file_path = self.write_working_file( 'mvn_deploy_output.txt') try: # update the version before pushing # NOTE 1: we know this is weird. But the version in the pom isn't necessarily # the version that was calculated as part of the release and so we need # to update that before doing the maven deploy so the maven deploy will # use the new version. # # NOTE 2: we tried doing this in the same command as the deploy, # but the pom was already loaded so even though the xml was updated # the deploy still used the old version, hence having to run this # first and independently. print("Update maven package version") run_maven(mvn_output_file_path=mvn_update_version_output_file_path, settings_file=self.maven_settings_file, pom_file=self.get_value('pom-file'), phases_and_goals=['versions:set'], additional_arguments=[f'-DnewVersion={version}']) # execute maven step (params come from config) print("Push packaged maven artifacts") self._run_maven_step( mvn_output_file_path=mvn_push_artifacts_output_file_path, step_implementer_additional_arguments=[ '-DaltDeploymentRepository=' \ f'{maven_push_artifact_repo_id}::default::{maven_push_artifact_repo_url}' ] ) except StepRunnerException as error: step_result.success = False step_result.message = "Error running 'maven deploy' to push artifacts. " \ f"More details maybe found in 'maven-output' report artifact: {error}" finally: step_result.add_artifact( description= "Standard out and standard error from running maven to update version.", name='maven-update-version-output', value=mvn_update_version_output_file_path) step_result.add_artifact( description="Standard out and standard error from running maven to " \ "push artifacts to repository.", name='maven-push-artifacts-output', value=mvn_push_artifacts_output_file_path ) return step_result