diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml deleted file mode 100644 index 5eb9871..0000000 --- a/.github/workflows/maven-release.yml +++ /dev/null @@ -1,82 +0,0 @@ ---- -name: maven-release -on: - push: - branches: [main, feature/**, renovate/**] -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 for deploy to S3 bucket - uses: actions/setup-java@v4 - with: - distribution: adopt - java-version: 17 - cache: maven - - uses: whelk-io/maven-settings-xml-action@v22 - with: - repositories: > - [ - { - "id": "s3", - "name": "s3.sbb.polarion.maven.repo", - "url": "s3://sbb-polarion-maven-repo/polarion.mvn", - "releases": { - "enabled": "true", - "updatePolicy": "never" - } - }, - { - "id": "repsy", - "name": "repsy.io", - "url": "https://repo.repsy.io/mvn/sbb/polarion", - "releases": { - "enabled": "true", - "updatePolicy": "never" - } - } - ] - servers: > - [ - { - "id": "s3", - "username": "${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_ACCESS_KEY }}", - "password": "${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY }}" - }, - { - "id": "github", - "username": "${env.GITHUB_ACTOR}", - "password": "${env.GITHUB_TOKEN}" - }, - { - "id": "repsy", - "username": "${{ secrets.CH_SBB_POLARION_REPSY_USERNAME }}", - "password": "${{ secrets.CH_SBB_POLARION_REPSY_PASSWORD }}" - } - ] - active_profiles: > - [ - "github" - ] - - name: Print settings.xml - run: cat /home/runner/.m2/settings.xml - - name: Build with Maven - run: mvn --batch-mode clean package - - name: Extract artefact version - id: artefact_version - run: echo ::set-output name=version::$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) - - name: Publish to S3 bucket - if: ${{ !endsWith(steps.artefact_version.outputs.version, '-SNAPSHOT') }} - run: mvn --batch-mode deploy -Ps3Deploy - - name: Publish to repsy.io - if: ${{ !endsWith(steps.artefact_version.outputs.version, '-SNAPSHOT') }} - run: mvn --batch-mode deploy -PrepsyDeploy - - name: Publish to GitHub Packages - if: ${{ !endsWith(steps.artefact_version.outputs.version, '-SNAPSHOT') }} - run: mvn --batch-mode deploy -PgithubDeploy - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/.gitignore b/.gitignore index 0205c77..4627953 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,4 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* -.idea/* +.idea # code style config !.idea/codeStyles @@ -30,6 +6,6 @@ replay_pid* !.idea/codeStyles/Project.xml !.idea/codeStyles/codeStyleConfig.xml -target/ *.iml -dependency-reduced-pom.xml + +venv \ No newline at end of file diff --git a/README.md b/README.md index 8cc4b60..0731233 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,24 @@ -# Polarion ALM extension to <...> +# Polarion artifacts deployer -This Polarion extension provides possibility to <...> -## Build +## polarion-artifacts-deployer -This extension can be produced using maven: -``` -mvn clean package -``` - -## Installation to Polarion - -To install the extension to Polarion `ch.sbb.polarion.extension.-.jar` -should be copied to `/polarion/extensions/ch.sbb.polarion.extension./eclipse/plugins` -It can be done manually or automated using maven build: -``` -mvn clean install -P polarion2304,install-to-local-polarion -``` -For automated installation with maven env variable `POLARION_HOME` should be defined and point to folder where Polarion is installed. - -Changes only take effect after restart of Polarion. +This polarion-artifacts-deployer script is written to use jar files from Polarion delivery for Polarion extension development. +The script provides ability to install jars to local maven repository or deploy jars to SBB artifactory. -## Polarion configuration +#### Supported parameters: -<...> + - `--polarion-home` — path to folder where polarion is installed + - `--action` — maven action: `install` to local repo or `deploy` to remote repo + - `--repository-id` — if maven action `deploy` is used, repository id from maven settings.xml should be provided to use credentials for authentication + - `--repository-url` — if maven action `deploy` is used, remote repository URL should be provided +#### Examples -## Extension Configuration - -<...> - - -## Usage - -<...> - +To install to local maven repo: +```bash +polarion-artifacts-deployer.py --polarion-home C:\Polarion --action install +``` +To deploy to remote maven repository: +```bash +polarion-artifacts-deployer.py --polarion-home C:\Polarion --action deploy --repository-id polarion.mvn --repository-url https://bin.sbb.ch/artifactory/polarion.mvn +``` diff --git a/.mvn/extensions.xml b/polarion-artifacts-deployer/.mvn/extensions.xml similarity index 63% rename from .mvn/extensions.xml rename to polarion-artifacts-deployer/.mvn/extensions.xml index 4d1f8b9..2effb4d 100644 --- a/.mvn/extensions.xml +++ b/polarion-artifacts-deployer/.mvn/extensions.xml @@ -1,7 +1,8 @@ + com.github.seahen maven-s3-wagon 1.3.3 - + \ No newline at end of file diff --git a/polarion-artifacts-deployer/polarion-artifacts-deployer.py b/polarion-artifacts-deployer/polarion-artifacts-deployer.py new file mode 100755 index 0000000..a3a33ca --- /dev/null +++ b/polarion-artifacts-deployer/polarion-artifacts-deployer.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys +import tempfile +import textwrap + +""" +# basic usage: +python ./polarion-artifacts-deployer.py --polarion-home --polarion-version + +# S3 usage --> ToDo: only possible for Adam right now and the configuration without AWS_PROFILE must be implemented sometime or move to external Maven Repo like repsy.io +export AWS_DEFAULT_REGION=eu-central-1 +export AWS_PROFILE=lz-polarion-nonprod +aws-azure-login --all-profiles --no-sandbox --mode=gui +python ./polarion-artifacts-deployer.py --action deploy --polarion-home ./Polarion/ --polarion-version 2310 --repository-id polarion.mvn --repository-url s3://sbb-polarion-maven-repo/polarion.mvn +""" + + +def write_pom_file_content(pom_file, group_id, artifact_id, version): + pom_content_template = ''' + + 4.0.0 + {group_id} + {artifact_id} + {version} + POM was automatically created by polarion-artifact-deployer utility + ''' + pom_content = textwrap.dedent(pom_content_template.format(**locals())) + + with open(pom_file, 'w') as output_file: + output_file.write(pom_content) + + +def execute_mvn_command(mvn_action, file_name, group_id, artifact_id, version): + separator() + print(f'path : {file_name}') + print(f'groupId : {group_id}') + print(f'artifactId : {artifact_id}') + print(f'version : {version}') + + pom_file = tempfile.gettempdir() + os.sep + "pom.xml" + write_pom_file_content(pom_file, group_id, artifact_id, version) + + mvn_command = f"mvn {mvn_action}:{mvn_action}-file -Dfile={file_name} -DgroupId={group_id} -DartifactId={artifact_id} -Dversion={version} -Dpackaging=jar -DgeneratePom=false -DpomFile={pom_file}" + + if args.settings_path: + mvn_command += f' --settings {args.settings_path}' + + if args.repository_id: + mvn_command += f' -DrepositoryId={args.repository_id}' + + if args.repository_url: + mvn_command += f' -Durl={args.repository_url}' + + mvn_dependency_template = '''\ + + {group_id} + {artifact_id} + {version} + provided + jar + ''' + mvn_dependency = textwrap.dedent(mvn_dependency_template.format(**locals())) + + separator() + print(mvn_command) + + try: + exit_code = os.system(mvn_command) + if exit_code > 0: + sys.exit(exit_code % 255) + finally: + os.remove(pom_file) + + separator() + print(mvn_dependency) + separator() + return mvn_dependency + + +def separator(): + print('-' * 20) + + +def process_bundles_folders(folder_names, version, bundles_as_mvn_deps, jars_in_bundles_as_mvn_deps): + for plugin_name in folder_names: + print('handling ' + plugin_name + ' ...') + plugin_name_tokens = plugin_name.split('_') + group_id = plugin_name_tokens[0] + process_jars_in_bundles_folders(plugin_name, group_id, version, jars_in_bundles_as_mvn_deps) + + +def process_jars_in_bundles_folders(plugin_name, group_id, version, jars_in_bundles_as_mvn_deps): + polarion_plugin_path = polarion_plugins_path + os.sep + plugin_name + for entry_name in os.listdir(polarion_plugin_path): + if entry_name.endswith('.jar'): + jar_path = polarion_plugin_path + os.sep + entry_name + artifact_id = entry_name[0 : len(entry_name) - 4] + mvn_dep = execute_mvn_command(args.mvn_action, jar_path, group_id, artifact_id, version) + jars_in_bundles_as_mvn_deps.append(mvn_dep) + + +def process_bundles_jars(jar_names, version, bundles_as_mvn_deps): + for jar_name in jar_names: + artifact_id = jar_name.removesuffix('.jar') + jar_path = polarion_plugins_path + os.sep + jar_name + mvn_dep = execute_mvn_command(args.mvn_action, jar_path, 'com.polarion.thirdparty', artifact_id, version) + bundles_as_mvn_deps.append(mvn_dep) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='install or deploy Polarion artifacts to maven repository') + parser.add_argument('--polarion-home', metavar='path', required=True, dest='polarion_home', action='store', help='Polarion installation folder') + parser.add_argument('--polarion-version', metavar='version', required=True, dest='polarion_version', action='store', help='Polarion version') + parser.add_argument('--action', dest='mvn_action', action='store', choices={'install', 'deploy'}, default='install', help='maven action') + parser.add_argument('--settings-path', metavar='path', dest='settings_path', help='path to settings.xml') + parser.add_argument('--repository-id', metavar='repo', dest='repository_id', action='store', help='repository id from maven settings.xml') + parser.add_argument('--repository-url', metavar='url', dest='repository_url', action='store', help='repository URL to deploy the artifacts') + + args = parser.parse_args() + + print('polarion home = ' + args.polarion_home) + print('polarion version = ' + args.polarion_version) + polarion_plugins_path = args.polarion_home + os.sep + 'polarion' + os.sep + 'plugins' + print('polarion plugins path = ' + polarion_plugins_path) + print('mvn action = ' + args.mvn_action) + + plugins_bundles = [] + polarion_jars = [] + + for root, dirs, files in os.walk(polarion_plugins_path): + for dir in dirs: + plugins_bundles.append(dir) + for file in files: + if file.endswith('.jar'): + polarion_jars.append(file) + break + + print('following polarion bundles detected = ', plugins_bundles) + print() + print('following polarion jars detected = ', polarion_jars) + print() + + bundles_mvn_deps = [] + jars_in_bundles_mvn_deps = [] + + process_bundles_folders(plugins_bundles, args.polarion_version, bundles_mvn_deps, jars_in_bundles_mvn_deps) + process_bundles_jars(polarion_jars, args.polarion_version, bundles_mvn_deps) + print('####################################') + print('Runtime platform maven dependencies:') + print('####################################') + print(os.linesep.join(bundles_mvn_deps)) + print('####################################') + + print('************************************') + print('Compile platform maven dependencies:') + print('************************************') + print(os.linesep.join(jars_in_bundles_mvn_deps)) + print('************************************') diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index e38ad38..0000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,14 +0,0 @@ -Support-Email: polarion-opensource@sbb.ch -Bundle-Name: Extension for Polarion ALM -Require-Bundle: com.polarion.portal.tomcat, - com.polarion.alm.ui, - com.polarion.platform.guice, - com.polarion.alm.tracker, - org.glassfish.jersey, - com.fasterxml.jackson, - com.fasterxml.jackson.jaxrs, - io.swagger, - org.apache.commons.logging, - slf4j.api, - org.springframework.spring-core, - org.springframework.spring-web