Skip to content

Commit

Permalink
feat: Implement REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
jamilraichouni committed Oct 30, 2024
1 parent ffee2a7 commit 34315d8
Show file tree
Hide file tree
Showing 27 changed files with 1,370 additions and 167 deletions.
135 changes: 0 additions & 135 deletions .github/workflows/build-addon.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: CC0-1.0
on:
push:
branches:
- main
- "*/v*.*.*" # Match version tags for releases
pull_request:
branches:
- main

jobs:
code-quality:
runs-on: ubuntu-latest
name: Check code quality
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install pre-commit
run: python -m pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
129 changes: 129 additions & 0 deletions .github/workflows/setup-build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: CC0-1.0
on:
push:
tags: ["*/v*.*.*"] # tags must be <addon-name>/v<version>
pull_request:
branches: [main]
jobs:
setup-build-release:
name: Setup, build, and release
runs-on: ubuntu-latest
strategy:
matrix:
capella-version: [6.0.0]
# capella-version: [6.0.0, 7.0.0]
include:
- capella-version: 6.0.0
java-execution-environment: JavaSE-17
jdk-version: 17.0.6+10
# - capella-version: 7.0.0
# java-execution-environment: JavaSE-17
# jdk-version: 17.0.11+9
steps:
- name: Identify addon
id: identify_addon
run: |
if [ ${{ github.event_name }} == "pull_request" ]; then
echo "Identifying addon from pull request"
ADDON=${{ github.event.pull_request.base.ref }}
elif [ ${{ github.event_name }} == "push" ]; then
echo "Identifying addon from push"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
echo "This push is a tag: ${GITHUB_REF#refs/tags/}"
ADDON=$(echo "$GITHUB_REF" | sed -E 's|refs/tags/([^/]+)/.*|\1|')
else
echo "This push is not a tag."
ADDON=$(echo "${GITHUB_REF}" | sed -E 's|refs/heads/([^/]+)|\1|')
fi
fi
echo "addon=${ADDON}" >> $GITHUB_OUTPUT
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up `capella-addons` CLI tool
run: pip install . && pip show capella-addons
- name: Set up Capella from ghcr.io/dsd-dbs/capella-dockerimages/capella/remote:${{ matrix.capella-version }}-selected-dropins-main
run: |
docker pull ghcr.io/dsd-dbs/capella-dockerimages/capella/remote:${{ matrix.capella-version }}-selected-dropins-main
if [ ! -d /tmp/capella_${{ matrix.capella-version }} ]; then
docker run --platform=linux/x86_64 --rm -v /tmp:/tmp --entrypoint="" --user=root \
ghcr.io/dsd-dbs/capella-dockerimages/capella/remote:${{ matrix.capella-version }}-selected-dropins-main \
bash -c "cp -r /opt/capella /tmp/capella_${{ matrix.capella-version }}"
fi
- name: Build `.classpath` file
run: |
cd ${{ steps.identify_addon.outputs.addon }}
python -m capella_addons build-classpath \
--java-execution-environment=${{ matrix.java-execution-environment }} \
$(find src -type f -name "Main.java") \
/tmp/capella_${{ matrix.capella-version }}
- name: Set up OpenAPI generator
if: steps.identify_addon.outputs.addon == 'rest-api'
run: |
curl -Lo /opt/openapi-generator.jar \
https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar
echo "java -jar /opt/openapi-generator.jar \$@" > /usr/local/bin/openapi-generator
chmod +x /usr/local/bin/openapi-generator
- name: Run OpenAPI generator
if: steps.identify_addon.outputs.addon == 'rest-api'
run: |
cd ${{ steps.identify_addon.outputs.addon }}
bash bin/jaxrs-jersey.zsh
rm -rf /tmp/src; cp -r src /tmp
# - name: Set up Eclipse Temurin JDK ${{ matrix.jdk-version }}
# uses: actions/setup-java@v3
# with:
# java-version: ${{ matrix.jdk-version }}
# distribution: 'temurin'
# java-package: "jdk"
# - name: Set up Eclipse JDT language server 1.40.0
# run: |
# if [ ! -d /tmp/jdtls ]; then mkdir /tmp/jdtls; fi
# cd /tmp/jdtls
# if [ ! -f jdtls.tar.gz ]; then
# curl -Lo jdtls.tar.gz \
# https://download.eclipse.org/jdtls/milestones/1.40.0/jdt-language-server-1.40.0-202409261450.tar.gz
# fi
# tar xzf jdtls.tar.gz
# rm *.tar.gz
# - name: Build workspace
# run: |
# cd ${{ steps.identify_addon.outputs.addon }}
# rm -rf target
# python -m capella_addons -v \
# build-workspace \
# --java-execution-environment=${{ matrix.java-execution-environment }} \
# $JAVA_HOME /tmp/jdtls
# - name: Package addon
# run: |
# cd ${{ steps.identify_addon.outputs.addon }}
# python -m capella_addons -v \
# package \
# $JAVA_HOME \
# /tmp/capella_${{ matrix.capella-version }}
# cp target/*.jar /tmp
# - name: Create release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ env.addon }}.${{ github.ref }}
# release_name: ${{ env.addon }} ${{ github.ref }}
# draft: false
# prerelease: false
# - name: Publish release
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ${{ env.addon }}/target/com.deutschebahn.rest-api_0.0.1.jar
# asset_name: com.deutschebahn.${{ env.addon }}_${{ github.ref }}.jar
# asset_content_type: application/java-archive
19 changes: 0 additions & 19 deletions CONTRIBUTING.md

This file was deleted.

30 changes: 18 additions & 12 deletions capella_addons/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import lxml.builder
import lxml.etree

import capella_addons

logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
response_stdout_generator = itertools.count(1)
Expand Down Expand Up @@ -61,11 +59,6 @@ class BuildWorkspaceStatus(Enum):


@click.group()
@click.version_option(
version=capella_addons.__version__,
prog_name="eclipse-plugin-builders",
message="%(prog)s %(version)s",
)
@click.option(
"-v",
"--verbose",
Expand Down Expand Up @@ -109,8 +102,7 @@ def _third_party_lib_paths() -> list[pathlib.Path]:
"""Return the paths to the third-party libraries."""
classpath_root = _read_xml_file(".classpath")
third_party_lib_paths = classpath_root.xpath(
'classpathentry[@kind="lib" and '
'not(starts-with(@path, "/opt/capella_6.0.0"))]/@path'
'classpathentry[@kind="lib"]/@path'
)
return sorted([pathlib.Path(p) for p in third_party_lib_paths])

Expand Down Expand Up @@ -615,6 +607,7 @@ def build_workspace(
status = response.get("result", BuildWorkspaceStatus.FAILED.value)
if status == BuildWorkspaceStatus.SUCCEED.value:
click.echo("Build of workspace succeeded.")
sys.exit(0)
elif status == BuildWorkspaceStatus.CANCELLED.value:
click.echo("Build of workspace cancelled.")
elif status == BuildWorkspaceStatus.WITH_ERROR.value:
Expand Down Expand Up @@ -651,7 +644,7 @@ def deploy(target_path: pathlib.Path) -> None:


def _get_bundle_classpath(third_party_lib_paths: list[pathlib.Path]) -> str:
lib_paths = sorted([p.name for p in _third_party_lib_paths()])
lib_paths = sorted([p.name for p in third_party_lib_paths])
value = "."
if third_party_lib_paths:
value = ".,\n"
Expand Down Expand Up @@ -689,20 +682,33 @@ def _update_bundle_classpath(

@main.command()
@click.argument("java_home", type=click.Path(exists=True, dir_okay=True))
def package(java_home: pathlib.Path) -> None:
@click.argument(
"target_platform_path", type=click.Path(exists=True, dir_okay=True)
)
def package(
java_home: pathlib.Path, target_platform_path: pathlib.Path
) -> None:
"""Package the eclipse plugin.
\b
Arguments
---------
java_home : pathlib.Path
The path to the Java home directory.
target_platform_path
The installation directory of an Eclipse/ Capella application
that will be referenced as target platform to build the
classpath.
""" # noqa: D301
lib_dir = pathlib.Path("lib")
if lib_dir.is_dir():
shutil.rmtree(lib_dir)
lib_dir.mkdir()
third_party_lib_paths = _third_party_lib_paths()
third_party_lib_paths = [
p
for p in _third_party_lib_paths()
if not p.is_relative_to(target_platform_path)
]
if third_party_lib_paths:
for path in third_party_lib_paths:
dest = lib_dir / path.name
Expand Down
Loading

0 comments on commit 34315d8

Please sign in to comment.