diff --git a/.github/workflows/maven-build-test.yml b/.github/workflows/maven-build-test.yml index 995bc4b748..338be07030 100644 --- a/.github/workflows/maven-build-test.yml +++ b/.github/workflows/maven-build-test.yml @@ -19,297 +19,166 @@ on: - '**.asciidoc' env: - MVN_BATCH_MODE: '-Djansi.force=true -Djansi.passthrough=true -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' + # if continuously builds exiting randomly, possibly add again -Djansi.force=true -Djansi.passthrough=true + MVN_BATCH_MODE: '-B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' # fixing random connection reset of maven downloads as proposed here: https://github.com/actions/virtual-environments/issues/2715#issuecomment-797388909 MVN_HTTP_OPTIMIZATION: '-Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120' - MVN_TEST_COVERAGE: '-Dskip.code.coverage=false' + REPOSITORY_PATH: repo jobs: cache-dependencies: runs-on: ubuntu-latest - steps: + steps: + - name: Enable git support for long paths on Windows + if: ${{ runner.os == 'Windows' }} + shell: cmd + run: git config --system core.longpaths true + - name: Clone Repository uses: actions/checkout@v3 - - - uses: devonfw-actions/java-maven-setup@main with: - maven-cache-key: cobigen-dep-${{ hashFiles('**/pom.xml') }} - clone: false - - - name: Resolve non-cobigen dependencies - run: mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve -DexcludeGroupIds=com.devonfw.cobigen -T1C -P!p2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} || true # never fail - - build-and-test-core: - needs: cache-dependencies - strategy: - fail-fast: false - matrix: - javaVersion: [8, 11] - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} + path: ${{ env.REPOSITORY_PATH }} - steps: - - uses: devonfw-actions/java-maven-setup@main + - name: Checkout & Prepare + uses: devonfw-actions/java-maven-setup@main with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }} # new key will cache - maven-cache-restore-key: cobigen-dep-${{ hashFiles('**/pom.xml') }} - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-core-test # new key will cache + maven-cache-path: ./.m2/repository + maven-cache-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }} + clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles - - name: Build & Test Core + - name: Overwrite maven settings shell: bash - run: mvn install -f cobigen --projects !cobigen-core-systemtest ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} + run: | + mkdir -p ~/.m2 + cp -rf ${{ env.REPOSITORY_PATH }}/.mvn/ci-settings.xml ~/.m2/settings.xml - build-and-test-plugins: - needs: build-and-test-core - strategy: - fail-fast: false - matrix: - javaVersion: [8, 11] - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} + - name: Resolve non-cobigen dependencies + shell: bash + run: | + cd ${{ env.REPOSITORY_PATH }} + mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve -pl !com.devonfw.cobigen:com.devonfw.cobigen.eclipse.test -DexcludeGroupIds=com.devonfw.cobigen -T1C -Pp2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} || true # never fail + mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:resolve-plugins -pl !com.devonfw.cobigen:com.devonfw.cobigen.eclipse.test -DexcludeGroupIds=com.devonfw.cobigen -T1C -Pp2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} || true # never fail + build: + needs: cache-dependencies + runs-on: ubuntu-latest steps: - - uses: devonfw-actions/java-maven-setup@main + - name: Enable git support for long paths on Windows + if: ${{ runner.os == 'Windows' }} + shell: cmd + run: git config --system core.longpaths true + + - name: Clone Repository + uses: actions/checkout@v3 with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-plugins # new key will cache - maven-cache-restore-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }} - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-plugins # new key will cache - jacoco-cache-restore-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-core-test # hit - restore - - - name: Build & Test Plugins - shell: bash - run: mvn install -f cobigen-plugins ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} + path: ${{ env.REPOSITORY_PATH }} - build-plugins-p2: - needs: build-and-test-plugins - strategy: - fail-fast: false - matrix: - javaVersion: [8] - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - - steps: - - uses: devonfw-actions/java-maven-setup@main + - name: Checkout & Prepare + uses: devonfw-actions/java-maven-setup@main with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-plugins # key hit will not update cache - java-version: ${{ matrix.javaVersion }} + maven-cache-path: ./.m2/repository + maven-cache-key: maven-${{ github.sha }}-${{ github.run_number }} # new key will cache + maven-cache-restore-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }} + java-version: 11 + clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles - - name: Cache p2 plugin repositories + - name: Cache built P2 repositories uses: actions/cache@v3 with: - path: ./**/target/repository/ - key: p2-plugins-${{ github.sha }} # new key will cache - - - name: Build Plugins UpdateSite + path: ./${{ env.REPOSITORY_PATH }}/**/target/repository/ + key: p2-${{ github.sha }}-${{ github.run_number }} # new key will cache + enableCrossOsArchive: true + + - name: Build all artifacts shell: bash run: | - mvn package -DskipTests -f cobigen-plugins bundle:bundle -Pp2-bundle --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} - mvn install -DskipTests -f cobigen-plugins bundle:bundle -Pp2-bundle p2:site --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} - - run-core-systemtest: - needs: build-and-test-plugins + cd ${{ env.REPOSITORY_PATH }} + ./build.sh -spb + + test: + needs: build strategy: fail-fast: false matrix: - javaVersion: [8, 11] + component: [core, plugins, templates, maven, eclipse, cli] + javaVersion: [11] os: [windows-latest, ubuntu-latest] runs-on: ${{ matrix.os }} - steps: - - uses: devonfw-actions/java-maven-setup@main + - name: Enable git support for long paths on Windows + if: ${{ runner.os == 'Windows' }} + shell: cmd + run: git config --system core.longpaths true + + - name: Clone Repository + uses: actions/checkout@v3 with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-plugins # key hit will not update cache - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-core-systemtest # new key will cache + path: ${{ env.REPOSITORY_PATH }} - - name: Run Core Systemtest - shell: bash - run: mvn install -f cobigen/cobigen-core-systemtest ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} - - build-and-test-eclipse-plugin: - needs: build-plugins-p2 - strategy: - fail-fast: false - matrix: - javaVersion: [8, 11] - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - - steps: - uses: devonfw-actions/java-maven-setup@main with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-plugins # key hit will not update cache + maven-cache-path: ./.m2/repository + maven-cache-key: maven-${{ github.sha }}-${{ github.run_number }} # match, restore only java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-eclipse # new key will cache - - - name: Cache Eclipse repository - uses: actions/cache@v3 - with: - path: ./**/eclipse/target/repository/ - key: p2-eclipse-${{ github.sha }} # new key will cache + jacoco-cache-key: jacoco-${{ github.sha }}-${{ matrix.component }} # new key will cache + clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles - # After checkout we need to restore the built repositories - - name: Restore P2 plugins repositories + - name: Restore built P2 repositories uses: actions/cache@v3 with: - path: ./**/target/repository/ - key: p2-plugins-${{ github.sha }} # key hit will not update cache - - # There is no retry for jobs, just for steps, so doing the retry by hand - - name: Build Plugins - uses: GabrielBB/xvfb-action@v1.5 - with: - run: mvn install -f cobigen-eclipse -Pp2-build ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} - - build-and-test-maven-plugin: - needs: build-and-test-plugins - strategy: - fail-fast: false - matrix: - javaVersion: [8, 11] - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - - steps: - - uses: devonfw-actions/java-maven-setup@main - with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-maven # new key will cache - maven-cache-restore-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-plugins - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-maven # new key will cache - - - name: Build & Test Maven Plugin - shell: bash - run: | - mvn install -f cobigen-maven ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} - - build-and-test-cli: - needs: build-and-test-templates - strategy: - fail-fast: false - matrix: - javaVersion: [11] # CLI does not support jdk 8 anymore - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - - steps: - - uses: devonfw-actions/java-maven-setup@main - with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-cli # new key will cache - maven-cache-restore-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-templates - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-cli # new key will cache - - - name: Build & Test CLI + path: ./${{ env.REPOSITORY_PATH }}/**/target/repository/ + key: p2-${{ github.sha }}-${{ github.run_number }} # match, restore only + enableCrossOsArchive: true + + # need to overwrite global settings file to cath all mvn executions properly in tests + - name: Overwrite maven settings shell: bash run: | - mvn install -f cobigen-cli ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} - - build-and-test-templates: - needs: build-and-test-maven-plugin - strategy: - fail-fast: false - matrix: - javaVersion: [8, 11] - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - - steps: - - uses: devonfw-actions/java-maven-setup@main - with: - maven-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-templates # new key will cache - maven-cache-restore-key: ${{ runner.os }}-${{ matrix.javaVersion }}-maven-${{ github.sha }}-maven - java-version: ${{ matrix.javaVersion }} - jacoco-cache-key: ${{ runner.os }}-${{ matrix.javaVersion }}-jacoco-${{ github.sha }}-templates # new key will cache + mkdir -p ~/.m2 + cp -rf ${{ env.REPOSITORY_PATH }}/.mvn/ci-settings.xml ~/.m2/settings.xml - - name: Build & Test Templates + - name: Test shell: bash + env: + M2_REPO: ${{ github.workspace }}/.m2/repository # fix for https://github.com/m-m-m/code/issues/43 run: | - mvn install -f cobigen-templates ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} - - sonar-analysis: - needs: [build-and-test-maven-plugin, build-and-test-templates, run-core-systemtest, build-and-test-eclipse-plugin, build-and-test-cli] + cd ${{ env.REPOSITORY_PATH }} + if [[ "${{ matrix.component }}" == "eclipse" && "${{ matrix.os }}" == "ubuntu-latest" ]] + then + xvfb-run -a ./build.sh -sdtcb --components ${{ matrix.component }} + else + ./build.sh -sdtcb --components ${{ matrix.component }} + fi + + # Sonar Analysis is done in separate workflow (https://github.com/devonfw/cobigen/blob/master/.github/workflows/sonar-analysis.yml) + # as of a workaround of potential secret leaking on PRs (https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) + sonar-analysis-preparation: + needs: [test] runs-on: ubuntu-latest steps: - - name: Cache SonarCloud packages - uses: actions/cache@v3 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - - - uses: devonfw-actions/java-maven-setup@main - with: - maven-cache-key: cobigen-dep-${{ hashFiles('**/pom.xml') }} - jacoco-cache-key: Linux-11-jacoco-${{ github.sha }}-cli # hit - restore - - # Restore other parallel results as well - seems that for any reason I could not reuse caches incrementally... need to restore all caches - - name: Restore eclipse test results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-eclipse # hit - restore - - - name: Restore core systemtest results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-core-systemtest # hit - restore - - - name: Restore core template test results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-templates # hit - restore - - - name: Restore core maven results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-maven # hit - restore - - - name: Restore core plugin test results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-plugins # hit - restore - - - name: Restore core cli test results - uses: actions/cache@v3 - with: - path: | - **/*.exec - **/failsafe-reports/**/* - **/surefire-reports/**/* - key: Linux-11-jacoco-${{ github.sha }}-cli # hit - restore - - - name: SonarCloud Analysis + - name: 'Prepare workflow context for transfer' env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # As a precaution, reference this value by an interpolated ENV var; + # instead of interpolating user controllable input directly in the shell script. + PR_TITLE: ${{ github.event.pull_request.title }} run: | - git fetch --unshallow - mvn verify sonar:sonar -DskipTests ${{ env.MVN_BATCH_MODE }} ${{ env.MVN_HTTP_OPTIMIZATION }} ${{ env.MVN_TEST_COVERAGE }} + # Save ENV for transfer + { + echo "PR_HEADSHA=${{ github.event.pull_request.head.sha }}" + echo "PR_NUMBER=${{ github.event.pull_request.number }}" + echo "PR_TITLE=${PR_TITLE}" + } >> workflow.env + tar --zstd -cf workflow.tar.zst workflow.env + + - name: 'Upload workflow context artifact' + uses: actions/upload-artifact@v3 + with: + name: maven-build-test-workflow-context + path: workflow.tar.zst + retention-days: 1 release: - needs: [build-and-test-maven-plugin, build-and-test-templates, run-core-systemtest, build-and-test-eclipse-plugin, build-and-test-cli] + needs: [test] runs-on: ubuntu-latest if: ${{ startsWith(github.repository, 'devonfw/') && github.ref == 'refs/heads/master' }} continue-on-error: true @@ -318,14 +187,21 @@ jobs: outputs: release_tag: ${{ steps.get_tag.outputs.tag }} steps: + - name: Clone Repository + uses: actions/checkout@v3 + with: + path: ${{ env.REPOSITORY_PATH }} + - uses: devonfw-actions/java-maven-setup@main with: - maven-cache-key: cobigen-dep-${{ hashFiles('**/pom.xml') }} + maven-cache-path: ./.m2/repository + maven-cache-key: cobigen-dep-${{ hashFiles(format('{0}/**/pom.xml', env.REPOSITORY_PATH)) }} GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} BUILD_USER: ${{ secrets.BUILD_USER }} BUILD_USER_PASSWD: ${{ secrets.BUILD_USER_PASSWD }} BUILD_USER_EMAIL: ${{ secrets.BUILD_USER_EMAIL }} + clone: false # checkout in a separate / earlier step to allow eager evaluation of parameter expression like workspace or hashFiles - name: Release id: release @@ -338,7 +214,9 @@ jobs: BUILD_USER: ${{ secrets.BUILD_USER }} BUILD_USER_PASSWD: ${{ secrets.BUILD_USER_PASSWD }} BUILD_USER_EMAIL: ${{ secrets.BUILD_USER_EMAIL }} - run: ./release.sh silent skip-qa repo-mvn-settings + run: | + cd ${{ env.REPOSITORY_PATH }} + ./release.sh -syb skip-qa - name: 'Get release tag' id: get_tag diff --git a/.gitignore b/.gitignore index 6e1889c17b..978e10ba4f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,19 @@ objectdb #Intellij .idea -*.iml \ No newline at end of file +*.iml +/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets_downloaded/template-sets/downloaded/crud-java-server-app-test.jar +/cobigen/cobigen-core/src/test/resources/testdata/unittest/config/reader/TemplateSetConfigurationReaderTest/valid_template_sets/template-sets/downloaded/crud-java-server-app-test.jar +/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app-test.jar +/cobigen/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set1-test-test.jar +/cobigen/cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set2-test-test.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/GenerationTestTemplateSetsXml/template-sets/downloaded/downloaded-template-set1-test-test.jar +cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0.jar +cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar +cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0.jar +cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded/crud-java-server-app-complex-1.0.0-sources.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-1.0.0.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-1.0.0-sources.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-complex-1.0.0.jar +cobigen/cobigen-core-systemtest/src/test/resources/testdata/systemtest/TemplateProcessingTest/template-sets/downloaded/crud-java-server-app-complex-1.0.0-sources.jar diff --git a/.mvn/settings.xml b/.mvn/ci-settings.xml similarity index 88% rename from .mvn/settings.xml rename to .mvn/ci-settings.xml index f979f4ceef..2fa62a2620 100644 --- a/.mvn/settings.xml +++ b/.mvn/ci-settings.xml @@ -1,5 +1,6 @@ + ${GITHUB_WORKSPACE}/.m2/repository sonartype.releases diff --git a/README.asciidoc b/README.asciidoc index ab439dcfed..190b8a8158 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -43,7 +43,7 @@ The CobiGen repository is organized in a one-branch-per-plugin schema. By that, == Build -`bash build.sh` (on windows use git bash) +`./build.sh -h` (on windows use git bash) == Deploy diff --git a/build.sh b/build.sh index 4fc99d6232..d11bfb4998 100755 --- a/build.sh +++ b/build.sh @@ -7,28 +7,42 @@ echo "" if [[ "$NO_CLEAN" = false ]] then -log_step "Cleanup Projects" -doRunCommand "mvn clean $MVN_SETTINGS $PARALLELIZED $BATCH_MODE $DEBUG" + log_step "Cleanup Projects" + doRunCommand "mvn clean $MVN_SETTINGS $PARALLELIZED $BATCH_MODE $DEBUG" fi -log_step "Build & Test Core" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen --projects !cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE" +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " core " ]]; then + log_step "Build & Test Core" + doRunCommand "mvn install $MVN_SETTINGS -f cobigen --projects !cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE" +fi -log_step "Build & Test Core Plugins" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-plugins $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE" +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " plugins " ]]; then + log_step "Build & Test Core Plugins" + doRunCommand "mvn install $MVN_SETTINGS -f cobigen-plugins $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE" -log_step "Build Core Plugins - P2 Update Sites" -doRunCommand "mvn package $MVN_SETTINGS bundle:bundle -Pp2-build,p2-bundle -DskipTests -f cobigen-plugins --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines $DEBUG $PARALLELIZED $BATCH_MODE -Dupdatesite.repository=$DEPLOY_UPDATESITE" -doRunCommand "mvn install $MVN_SETTINGS bundle:bundle -Pp2-build,p2-bundle -DskipTests p2:site -f cobigen-plugins --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines $DEBUG $PARALLELIZED $BATCH_MODE -Dupdatesite.repository=$DEPLOY_UPDATESITE" + log_step "Build Core Plugins - P2 Update Sites" + doRunCommand "mvn package $MVN_SETTINGS bundle:bundle -Pp2-build,p2-bundle -DskipTests -f cobigen-plugins --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines $DEBUG $PARALLELIZED $BATCH_MODE -Dupdatesite.repository=$DEPLOY_UPDATESITE" + doRunCommand "mvn install $MVN_SETTINGS bundle:bundle -Pp2-build,p2-bundle -DskipTests p2:site -f cobigen-plugins --projects !cobigen-javaplugin-parent/cobigen-javaplugin-model,!cobigen-openapiplugin-parent/cobigen-openapiplugin-model,!:plugins-parent,!cobigen-javaplugin-parent,!cobigen-openapiplugin-parent,!cobigen-templateengines $DEBUG $PARALLELIZED $BATCH_MODE -Dupdatesite.repository=$DEPLOY_UPDATESITE" +fi log_step "Package & Run E2E Tests" -doRunCommand "mvn integration-test $MVN_SETTINGS -f cobigen/cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-cli $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-maven $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-templates $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-eclipse -Pp2-build $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " core " ]]; then + doRunCommand "mvn integration-test $MVN_SETTINGS -f cobigen/cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +fi +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " cli " ]]; then + doRunCommand "mvn install $MVN_SETTINGS -f cobigen-cli $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +fi +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " maven " ]]; then + doRunCommand "mvn install $MVN_SETTINGS -f cobigen-maven $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +fi +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " templates " ]]; then + doRunCommand "mvn install $MVN_SETTINGS -f cobigen-templates $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +fi +if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " eclipse " ]]; then + doRunCommand "mvn install $MVN_SETTINGS -f cobigen-eclipse -Pp2-build $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE" +fi -if [[ -n "$COVERAGE" ]] +if [[ "$COV_REPORT" = true ]] then doRunCommand "mvn -DskipTests verify $COVERAGE $DEBUG $PARALLELIZED $BATCH_MODE" fi diff --git a/cobigen-cli/cli-systemtest/pom.xml b/cobigen-cli/cli-systemtest/pom.xml index 0bb50b98ad..d1d14b8730 100644 --- a/cobigen-cli/cli-systemtest/pom.xml +++ b/cobigen-cli/cli-systemtest/pom.xml @@ -12,6 +12,9 @@ src\test\resources\testdata\localmavenproject\maven.project src\test\resources\testdata\templatesproject\templates-devon4j + src\test\resources\testdata\templatesproject\template-sets\downloaded\crud-java-server-app + src\test\resources\testdata\AdaptTemplatesCommandIT\template-sets\adapted\crud-java-server-app + src\test\resources\testdata\AdaptTemplatesCommandIT\template-sets\adapted\crud-java-server-app-complex @@ -111,6 +114,63 @@ + + Install test template set downloaded project + test-compile + + exec + + + mvn + ${maven.test.templateset.downloaded.path} + + install + + -Djansi.force=true + -Djansi.passthrough=true + -B + -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + + + + + Install AdaptTemplatesCommandIT downloaded project1 + test-compile + + exec + + + mvn + ${maven.test.AdaptTemplatesCommandIT.downloaded.path1} + + install + + -Djansi.force=true + -Djansi.passthrough=true + -B + -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + + + + + Install AdaptTemplatesCommandIT downloaded project2 + test-compile + + exec + + + mvn + ${maven.test.AdaptTemplatesCommandIT.downloaded.path2} + + install + + -Djansi.force=true + -Djansi.passthrough=true + -B + -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + + + diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AbstractCliTest.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AbstractCliTest.java index 0b0798d0f5..c49917f5b3 100644 --- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AbstractCliTest.java +++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AbstractCliTest.java @@ -7,16 +7,22 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver; import org.codehaus.plexus.logging.console.ConsoleLoggerManager; import org.codehaus.plexus.util.Os; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zeroturnaround.exec.ProcessExecutor; import org.zeroturnaround.exec.ProcessResult; @@ -30,6 +36,9 @@ /** Common test implementation for CLI tests */ public class AbstractCliTest { + /** Logger instance. */ + private static final Logger LOG = LoggerFactory.getLogger(AbstractCliTest.class); + /** Java tool options */ private static final String JAVA_TOOL_OPTIONS = "CGCLI_JAVA_OPTIONS"; @@ -37,23 +46,87 @@ public class AbstractCliTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); + /** Temporary directory for the templates project */ + @ClassRule + public static TemporaryFolder tempFolderTemplates = new TemporaryFolder(); + /** Current home directory */ protected Path currentHome; - /** The devon4j-templates development folder */ + /** The templates development folder */ protected static Path devTemplatesPath; + /** A temp directory containing the templates development folder */ + protected static Path devTemplatesPathTemp; + /** - * Determine the devon4j-templates development folder + * Determine the templates development folder and create a copy of it in the temp directory + * + * TODO: Replace with reduced template set projects in test resources, see: + * https://github.com/devonfw/cobigen/issues/1659 * * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a template directory directory fails */ @BeforeClass - public static void determineDevTemplatesPath() throws URISyntaxException { + public static void determineDevTemplatesPath() throws URISyntaxException, IOException { devTemplatesPath = new File(AbstractCliTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().getParentFile().getParentFile().toPath().resolve("cobigen-templates"); + + Path utilsPom = new File(AbstractCliTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) .getParentFile().getParentFile().getParentFile().getParentFile().toPath().resolve("cobigen-templates") - .resolve("templates-devon4j"); + .resolve("templates-devon4j-tests/src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolderTemplates.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + devTemplatesPathTemp = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = devTemplatesPathTemp.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(devTemplatesPathTemp); + Files.createDirectory(templateSetsAdaptedFolder); + + FileUtils.copyDirectory(devTemplatesPath.toFile(), templateSetsAdaptedFolder.toFile()); + + List devTemplateSets = new ArrayList<>(); + try (Stream files = Files.list(templateSetsAdaptedFolder)) { + files.forEach(path -> { + devTemplateSets.add(path); + }); + } + + for (Path path : devTemplateSets) { + if (Files.isDirectory(path)) { + Path resourcesFolder = path.resolve("src/main/resources"); + Path templatesFolder = path.resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER); + if (Files.exists(resourcesFolder) && !Files.exists(templatesFolder)) { + try { + Files.move(resourcesFolder, templatesFolder); + } catch (IOException e) { + throw new IOException("Error moving directory " + resourcesFolder, e); + } + } + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(path.resolve("pom.xml"))) { + try { + Files.delete(path.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + path.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, path.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } } /** @@ -76,7 +149,7 @@ public void runWithLatestTemplates() throws IOException { Path configFile = this.currentHome.resolve(ConfigurationConstants.COBIGEN_CONFIG_FILE); Files.write(configFile, - (ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH + "=" + devTemplatesPath.toString()).getBytes()); + (ConfigurationConstants.CONFIG_PROPERTY_TEMPLATES_PATH + "=" + devTemplatesPathTemp.toString()).getBytes()); } /** @@ -88,15 +161,27 @@ protected void execute(String[] args, boolean useDevTemplates) throws Exception execute(args, useDevTemplates, false); } + /** + * @see #execute(String[], boolean, boolean) + */ + @SuppressWarnings("javadoc") + protected void execute(String[] args, boolean useDevTemplates, boolean assureFailure) throws Exception { + + execute(args, useDevTemplates, assureFailure, false); + } + /** * This method check the return code from picocli * * @param args execution arguments * @param useDevTemplates use development devon4j-templates * @param assureFailure assure failure instead of success of the command execution + * @param allowMonolithicConfiguration ignores deprecated monolithic template folder structure and if found does not + * throw a DeprecatedMonolithicConfigurationException * @throws Exception error */ - protected void execute(String[] args, boolean useDevTemplates, boolean assureFailure) throws Exception { + protected void execute(String[] args, boolean useDevTemplates, boolean assureFailure, + boolean allowMonolithicConfiguration) throws Exception { if (useDevTemplates) { runWithLatestTemplates(); @@ -130,11 +215,21 @@ protected void execute(String[] args, boolean useDevTemplates, boolean assureFai i++; } - if (useDevTemplates) { + if (useDevTemplates && !allowMonolithicConfiguration) { debugArgs = Arrays.copyOf(debugArgs, debugArgs.length + 3); debugArgs[debugArgs.length - 3] = "-v"; debugArgs[debugArgs.length - 2] = "-tp"; - debugArgs[debugArgs.length - 1] = devTemplatesPath.toString(); + debugArgs[debugArgs.length - 1] = devTemplatesPathTemp.toString(); + } else if (useDevTemplates && allowMonolithicConfiguration) { + debugArgs = Arrays.copyOf(debugArgs, debugArgs.length + 4); + debugArgs[debugArgs.length - 4] = "--force-mc"; + debugArgs[debugArgs.length - 3] = "-v"; + debugArgs[debugArgs.length - 2] = "-tp"; + debugArgs[debugArgs.length - 1] = devTemplatesPathTemp.toString(); + } else if (allowMonolithicConfiguration) { + debugArgs = Arrays.copyOf(debugArgs, debugArgs.length + 2); + debugArgs[debugArgs.length - 2] = "--force-mc"; + debugArgs[debugArgs.length - 1] = "-v"; } else { debugArgs = Arrays.copyOf(debugArgs, debugArgs.length + 1); debugArgs[debugArgs.length - 1] = "-v"; @@ -147,11 +242,15 @@ protected void execute(String[] args, boolean useDevTemplates, boolean assureFai .redirectOutput(Slf4jStream.of(LoggerFactory.getLogger(getClass().getName() + ".cliprocess")).asInfo()); // enable jacoco coverage monitoring for external processes (especially for CI/CD) - if (!StringUtils.isEmpty(MavenMetadata.JACOCO_AGENT_ARGS)) { + if (!StringUtils.isEmpty(MavenMetadata.JACOCO_AGENT_ARGS) + && !StringUtils.startsWith(MavenMetadata.JACOCO_AGENT_ARGS, "$")) { pe.environment(JAVA_TOOL_OPTIONS, MavenMetadata.JACOCO_AGENT_ARGS + // .replaceFirst("destfile=[^,]+(,)?", "") // + ",output=tcpclient,sessionid=test,inclnolocationclasses=true,inclbootstrapclasses=true " + "" + (System.getenv(JAVA_TOOL_OPTIONS) == null ? "" : " " + System.getenv(JAVA_TOOL_OPTIONS))); + } else { + LOG.warn("No value for JACOCO is set!"); } new SystemExit().execute(() -> { diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java index a47d183749..3edff96f91 100644 --- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java +++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java @@ -3,44 +3,136 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; +import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; +import org.apache.commons.io.FileUtils; import org.junit.Test; import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.api.util.TemplatesJarUtil; /** * Tests the usage of the adapt-templates command. */ public class AdaptTemplatesCommandIT extends AbstractCliTest { + /** Test resources root path */ + private static String testFileRootPath = "src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/downloaded"; + /** - * Checks if adapt-templates command successfully created cobigen templates folder and its sub folders + * Checks if adapt-templates command successfully created adapted folder and its sub folders * * @throws Exception test fails */ @Test - public void adaptTemplatesTest() throws Exception { + public void adaptTemplateSetTest() throws Exception { - String args[] = new String[1]; + Path downloadedTemplateSetsPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER) + .resolve(ConfigurationConstants.DOWNLOADED_FOLDER); + if (!Files.exists(downloadedTemplateSetsPath)) { + Files.createDirectories(downloadedTemplateSetsPath); + } + FileUtils.copyDirectory(new File(testFileRootPath), downloadedTemplateSetsPath.toFile()); + String args[] = new String[2]; args[0] = "adapt-templates"; + args[1] = "--all"; execute(args, false); - Path cobigenTemplatesFolderPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATES_FOLDER) - .resolve(ConfigurationConstants.COBIGEN_TEMPLATES); - assertThat(cobigenTemplatesFolderPath).exists(); - // check if templates exist - assertThat(Paths - .get(cobigenTemplatesFolderPath.toString() + File.separator + ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)) + Path cobigenTemplateSetsFolderPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path downloadedTemplateSetsFolderPath = cobigenTemplateSetsFolderPath + .resolve(ConfigurationConstants.DOWNLOADED_FOLDER); + Path adaptedTemplateSetsFolderPath = cobigenTemplateSetsFolderPath.resolve(ConfigurationConstants.ADAPTED_FOLDER); + + assertThat(cobigenTemplateSetsFolderPath).exists(); + assertThat(downloadedTemplateSetsFolderPath).exists(); + assertThat(adaptedTemplateSetsFolderPath).exists(); + + Path templateSetSimple = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-1.0.0"); + Path templateSetComplex = adaptedTemplateSetsFolderPath.resolve("crud-java-server-app-complex-1.0.0"); + + // check if adapted template set exists + assertThat(templateSetSimple).exists(); + assertThat(templateSetComplex).exists(); + + Path templateSetResourcesPath = templateSetSimple + .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER); + Path templateSetResourcesPathComplex = templateSetComplex + .resolve(ConfigurationConstants.MAVEN_CONFIGURATION_RESOURCE_FOLDER); + + // check if templates folder exists + assertThat(templateSetSimple.resolve(templateSetResourcesPath).resolve(ConfigurationConstants.TEMPLATES_FOLDER)) + .exists(); + assertThat( + templateSetComplex.resolve(templateSetResourcesPathComplex).resolve(ConfigurationConstants.TEMPLATES_FOLDER)) .exists(); + + // check if template-set.xml exists + assertThat(templateSetSimple.resolve(templateSetResourcesPath) + .resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists(); + assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex) + .resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists(); + + // validate correct folder structure + assertThat(templateSetSimple.resolve(templateSetResourcesPath) + .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists(); + assertThat(templateSetComplex.resolve(templateSetResourcesPathComplex) + .resolve(ConfigurationConstants.TEMPLATE_SET_FREEMARKER_FUNCTIONS_FILE_NAME)).exists(); + + // check if template set utility resource folder exists + assertThat(templateSetSimple.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists(); + assertThat(templateSetComplex.resolve(ConfigurationConstants.UTIL_RESOURCE_FOLDER)).exists(); + + // validate maven specific contents + assertThat(templateSetSimple.resolve("pom.xml")).exists(); + assertThat(templateSetComplex.resolve("pom.xml")).exists(); + + // check if META-INF was deleted + assertThat(templateSetResourcesPath.resolve("META-INF")).doesNotExist(); + assertThat(templateSetResourcesPathComplex.resolve("META-INF")).doesNotExist(); + + } + + /** + * Checks if adapt-templates command successfully created cobigen templates folder and its sub folders + * + * @throws Exception test fails + */ + @Test + public void adaptTemplatesTest() throws Exception { + + Path templatesPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATES_FOLDER); + Path CobigenTemplatesPath = templatesPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES); + if (!Files.exists(templatesPath)) { + Files.createDirectories(templatesPath); + } + + // TODO: Replace with downloadJarFromURL method and get rid of downloadJar, see: + // https://github.com/devonfw/cobigen/issues/1685 + TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", false, templatesPath.toFile()); + TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", true, templatesPath.toFile()); + + String args[] = new String[2]; + args[0] = "adapt-templates"; + args[1] = "--all"; + + execute(args, false, false, true); + + assertThat(CobigenTemplatesPath).exists(); + + Path templateRoot = CobigenTemplatesPath.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER); + // check if context configuration exists - assertThat(Paths - .get(cobigenTemplatesFolderPath.toString() + File.separator + ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER - + File.separator + ConfigurationConstants.CONTEXT_CONFIG_FILENAME)).exists(); - // check if sources of utility classes exist - assertThat(Paths.get(cobigenTemplatesFolderPath.toString() + File.separator + "src" + File.separator + "main" - + File.separator + "java")).exists(); + assertThat(templateRoot.resolve(ConfigurationConstants.CONTEXT_CONFIG_FILENAME)).exists(); + + Path template = templateRoot.resolve("crud_java_server_app"); + Path templateComplex = templateRoot.resolve("crud_java_server_app_complex"); + // check if templates exists + assertThat(template).exists(); + assertThat(templateComplex).exists(); + // check if template.xml exists + assertThat(template.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME)).exists(); + assertThat(templateComplex.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME)).exists(); } } diff --git a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java index 4d4a45505f..3d632b8f68 100644 --- a/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java +++ b/cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/GenerateCommandIT.java @@ -9,8 +9,11 @@ import org.apache.commons.io.FileUtils; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; +import com.devonfw.cobigen.api.constants.ConfigurationConstants; + /** * Tests the usage of the generate command. */ @@ -65,6 +68,70 @@ public void generateFromEntityTest() throws Exception { .exists(); } + /** + * + * Test the upgrade process from templates in a given path and generates from the new template-sets structure + * + * @throws Exception test fails + */ + @Test + @Ignore // TODO: re-enable when upgrade process is implemented, see: https://github.com/devonfw/cobigen/issues/1595 + public void upgradeAndGenerateFromEntityTest() throws Exception { + + FileUtils.copyDirectory(new File(testFileRootPath + "templatesproject"), this.tmpProject.toFile()); + this.tmpProject.resolve("templates-devon4j").toFile() + .renameTo(this.tmpProject.resolve(ConfigurationConstants.COBIGEN_TEMPLATES).toFile()); + File baseProject = this.tmpProject.resolve("maven.project/core/").toFile(); + File monolithicConfiguration = this.tmpProject.toFile(); + String args[] = new String[7]; + args[0] = "generate"; + args[1] = this.entityInputFile.getAbsolutePath(); + args[2] = "--increments"; + args[3] = "0"; + args[4] = "--upgrade-configuration"; + args[5] = "-tp"; + args[6] = monolithicConfiguration.getAbsolutePath(); + + execute(args, false); + + assertThat(this.currentHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)).exists(); + + assertThat(baseProject.toPath().resolve("src/main/java/com/maven/project/sampledatamanagement/logic/api/to")) + .exists(); + } + + /** + * + * Integration test of the generation of template sets from a Java Entity. It does not specify the project to generate + * the folders to. + * + * @throws Exception test fails + */ + @Test + @Ignore // TODO: re-enable/fix when CLI tests were re-factored, see: https://github.com/devonfw/cobigen/issues/1659 + public void generateFromEntityWithTemplateSetTest() throws Exception { + + File baseProject = this.tmpProject.resolve("maven.project/core/").toFile(); + File templateSetsConfig = this.tmpProject.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER).toFile(); + String args[] = new String[6]; + args[0] = "generate"; + args[1] = this.entityInputFile.getAbsolutePath(); + args[2] = "--increments"; + args[3] = "0"; + args[4] = "-tp"; + args[5] = templateSetsConfig.getAbsolutePath(); + + execute(args, false); + + assertThat(this.currentHome.resolve(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_PATH)).exists(); + + assertThat(baseProject.toPath().resolve("src/main/java/com/maven/project/sampledatamanagement/logic/api/to")) + .exists(); + } + + // TODO: Add similar test with a template-set jar file in downloaded folder, see: + // https://github.com/devonfw/cobigen/issues/1661 + /** * Integration test of the generation from a templates jar using a utility class with an extra dependency. See: * https://github.com/devonfw/cobigen/issues/1450 @@ -74,10 +141,10 @@ public void generateFromEntityTest() throws Exception { @Test public void generateFromTemplatesJarWithUtilClassDependencyTest() throws Exception { - FileUtils.copyDirectory(new File(testFileRootPath + "templatesproject"), this.tmpProject.toFile()); + FileUtils.copyDirectory(new File(testFileRootPath + "templatesproject/templates-devon4j"), + this.tmpProject.toFile()); File baseProject = this.tmpProject.resolve("maven.project/core/").toFile(); - File templatesProject = this.tmpProject.resolve("templates-devon4j/target/templates-devon4j-dev-SNAPSHOT.jar") - .toFile(); + File templatesProject = this.tmpProject.resolve("target/templates-devon4j-dev-SNAPSHOT.jar").toFile(); String args[] = new String[6]; args[0] = "generate"; @@ -87,7 +154,7 @@ public void generateFromTemplatesJarWithUtilClassDependencyTest() throws Excepti args[4] = "-tp"; args[5] = templatesProject.getAbsolutePath(); - execute(args, false); + execute(args, false, false, true); assertThat(baseProject.toPath().resolve("src/main/java/com/maven/project/sampledatamanagement/logic/api/to")) .exists(); @@ -231,7 +298,6 @@ public void generateFromMultipleTypeInputTest() throws Exception { String args[] = new String[6]; args[0] = "generate"; args[1] = openApiFile.getAbsolutePath() + "," + this.entityInputFile.getAbsolutePath(); - args[2] = "--out"; args[3] = outputRootFile.getAbsolutePath(); args[4] = "--increments"; @@ -361,4 +427,4 @@ public void generateFromEntityTwiceToTestCache() throws Exception { execute(args, true); } -} +} \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml new file mode 100644 index 0000000000..3c69a2539d --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + com.devonfw.test + crud-java-server-app-complex + 1.0.0 + jar + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../../downloaded + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + ${skip.deployment} + ../../downloaded + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + UTF-8 + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + generate-maven-properties-class + + filter-sources + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-package + + run + + + + Integrate POM manually + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/java/com/test.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/functions.ftl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml new file mode 100644 index 0000000000..5cfe219789 --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/template-set.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl new file mode 100644 index 0000000000..0c233890ea --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl @@ -0,0 +1 @@ +package test; \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml new file mode 100644 index 0000000000..3558920d14 --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + com.devonfw.test + crud-java-server-app + 1.0.0 + jar + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../../downloaded + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + ${skip.deployment} + ../../downloaded + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + UTF-8 + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + generate-maven-properties-class + + filter-sources + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-package + + run + + + + Integrate POM manually + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/java/com/test.java new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/functions.ftl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..4515b452ec --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl new file mode 100644 index 0000000000..0c233890ea --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/AdaptTemplatesCommandIT/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl @@ -0,0 +1 @@ +package test; \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/pom.xml new file mode 100644 index 0000000000..79e6e7b9c3 --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + com.devonfw.test + templates-devon4j + dev-SNAPSHOT + jar + + 1.8 + 1.8 + + + + + org.apache.commons + commons-math3 + 3.6.1 + + + + + + + src/main/templates + src/main/templates + + + + + org.codehaus.mojo + flatten-maven-plugin + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-package + + run + + + + Integrate POM manually + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/java/utils/MathUtils.java b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/java/utils/MathUtils.java new file mode 100644 index 0000000000..79bf32afde --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/java/utils/MathUtils.java @@ -0,0 +1,12 @@ +package utils; + +import org.apache.commons.math3.distribution.NormalDistribution; + +public class MathUtils { + + public double getNormalDistribution() { + NormalDistribution normalDistribution = new NormalDistribution(10, 3); + double randomValue = normalDistribution.sample(); + return randomValue; + } +} diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..aecd8ff6ca --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/template-set.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl new file mode 100644 index 0000000000..dbf053f736 --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/adapted/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl @@ -0,0 +1,5 @@ +package test; + +class Test{ + private final double myVar = ${MathUtils.getNormalDistribution()}; +} \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/pom.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/pom.xml new file mode 100644 index 0000000000..338fee4ab5 --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + com.devonfw.test + crud-java-server-app + test + jar + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../../downloaded + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/template-set.xml b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..4515b452ec --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/template-set.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl new file mode 100644 index 0000000000..0c233890ea --- /dev/null +++ b/cobigen-cli/cli-systemtest/src/test/resources/testdata/templatesproject/template-sets/downloaded/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl @@ -0,0 +1 @@ +package test; \ No newline at end of file diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java index 19f3439a5b..7ceceef9d1 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/AdaptTemplatesCommand.java @@ -1,9 +1,22 @@ package com.devonfw.cobigen.cli.commands; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.devonfw.cobigen.api.TemplateAdapter; +import com.devonfw.cobigen.api.exception.TemplateSelectionForAdaptionException; +import com.devonfw.cobigen.api.exception.UpgradeTemplatesNotificationException; +import com.devonfw.cobigen.cli.CobiGenCLI; import com.devonfw.cobigen.cli.constants.MessagesConstants; -import com.devonfw.cobigen.impl.CobiGenFactory; +import com.devonfw.cobigen.cli.utils.ValidationUtils; +import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; import picocli.CommandLine.Command; +import picocli.CommandLine.Option; /** * This class handles the user defined template directory e.g. determining and obtaining the latest templates jar, @@ -12,11 +25,107 @@ @Command(description = MessagesConstants.ADAPT_TEMPLATES_DESCRIPTION, name = "adapt-templates", aliases = { "a" }, mixinStandardHelpOptions = true) public class AdaptTemplatesCommand extends CommandCommons { + /** + * Logger to output useful information to the user + */ + private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class); + + /** + * If this options is enabled, all templates are extracted. + */ + @Option(names = { "--all" }, description = MessagesConstants.ADAPT_ALL_DESCRIPTION) + boolean adaptAll; + + /** + * Allows usage of the old monolithic template structure instead of the new template sets structure. + */ + @Option(names = { "--force-monolithic-configuration", + "--force-mc" }, description = MessagesConstants.FORCE_MONOLITHIC_CONFIGURATION) + boolean forceMonolithicConfiguration; @Override public Integer doAction() throws Exception { - CobiGenFactory.extractTemplates(); + TemplateAdapter templateAdapter = new TemplateAdapterImpl(this.templatesProject); + try { + templateAdapter.adaptTemplates(); + } catch (UpgradeTemplatesNotificationException e) { + if (!this.forceMonolithicConfiguration && askUserToContinueWithUpgrade(e)) { + templateAdapter.upgradeMonolithicTemplates(this.templatesProject); + } + } catch (TemplateSelectionForAdaptionException e) { + List templateJars = e.getTemplateSets(); + if (!templateJars.isEmpty()) { + List templateJarsToAdapt = getJarsToAdapt(templateAdapter, templateJars); + if (!templateJarsToAdapt.isEmpty()) { + templateAdapter.adaptTemplateSets(templateJarsToAdapt, false); + } + } else { + LOG.info("No template set jars found to extract."); + } + } return 0; } -} + + /** + * Gives the user a selection of available template set jars to adapt. + * + * @param templateJars A {@link List} with all available template set jars. + * @return A {@link List} with the template set jars selected by the user to adapt. + */ + private List getJarsToAdapt(TemplateAdapter templateAdapter, List templateJars) { + + List jarsToAdapt = new ArrayList<>(); + if (templateJars != null && templateJars.size() > 0) { + printJarsForSelection(templateAdapter, templateJars); + List userSelection = new ArrayList<>(); + if (this.adaptAll) { + userSelection.add("0"); + } else { + for (String templateSelection : ValidationUtils.getUserInput().split(",")) { + userSelection.add(templateSelection); + } + } + if (userSelection.contains("0")) { + jarsToAdapt = templateJars; + } else { + for (String jarSelected : userSelection) { + jarsToAdapt.add(templateJars.get(Integer.parseInt(jarSelected) - 1)); + } + } + } + return jarsToAdapt; + } + + /** + * Prints the available template set jars + * + * @param templateSetJarPaths List of {@link Path} to available template jar files + */ + private void printJarsForSelection(TemplateAdapter templateAdapter, List templateSetJarPaths) { + + LOG.info("(0) " + "All"); + for (Path templateSetJarPath : templateSetJarPaths) { + LOG.info("(" + (templateSetJarPaths.indexOf(templateSetJarPath) + 1) + ") " + + templateSetJarPath.getFileName().toString().replace(".jar", "") + + (templateAdapter.isTemplateSetAlreadyAdapted(templateSetJarPath) ? " (already adapted)" : "")); + } + LOG.info("Please enter the number(s) of jar(s) that you want to adapt separated by comma."); + } + + /** + * Ask the user to continue with the upgrade of the templates. + * + * @return Returns {@code true} if the user want to continue with the uprade of the templates. + */ + private boolean askUserToContinueWithUpgrade(UpgradeTemplatesNotificationException e) { + + LOG.info(e.getMessage()); + LOG.info("Type 'y' or 'yes' to upgrade the configuration?"); + String userInput = ValidationUtils.getUserInput(); + if (userInput != null && (userInput.toLowerCase().equals("y") || userInput.toLowerCase().equals("yes"))) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/CommandCommons.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/CommandCommons.java index ad9ddba393..1d34aca581 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/CommandCommons.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/CommandCommons.java @@ -26,6 +26,12 @@ public abstract class CommandCommons implements Callable { @Option(names = { "--templates-project", "-tp" }, description = MessagesConstants.TEMPLATE_PATH_DESCRIPTION) Path templatesProject; + /** + * If this option is enabled, the old monolithic templates will be upgraded to the new template-set structure. + */ + @Option(names = { "--upgrade-configuration" }, description = MessagesConstants.UPGRADE_CONFIGURATION_OPTION) + boolean upgradeConfiguration; + @Override public Integer call() throws Exception { diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java index 33f0570b0d..1642945634 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/commands/GenerateCommand.java @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory; import com.devonfw.cobigen.api.CobiGen; +import com.devonfw.cobigen.api.exception.DeprecatedMonolithicConfigurationException; import com.devonfw.cobigen.api.exception.InputReaderException; import com.devonfw.cobigen.api.to.GenerableArtifact; import com.devonfw.cobigen.api.to.GenerationReportTo; @@ -36,8 +37,11 @@ import com.devonfw.cobigen.cli.utils.CobiGenUtils; import com.devonfw.cobigen.cli.utils.ParsingUtils; import com.devonfw.cobigen.cli.utils.ValidationUtils; +import com.devonfw.cobigen.impl.CobiGenFactory; +import com.devonfw.cobigen.impl.config.constant.WikiConstants; import com.devonfw.cobigen.impl.util.ConfigurationFinder; import com.devonfw.cobigen.impl.util.FileSystemUtil; +import com.devonfw.cobigen.impl.util.PostponeUtil; import com.google.googlejavaformat.java.FormatterException; import picocli.CommandLine.Command; @@ -80,6 +84,15 @@ public class GenerateCommand extends CommandCommons { @Option(names = { "--templates", "-t" }, split = ",", description = MessagesConstants.TEMPLATES_OPTION_DESCRIPTION) List templates = null; + /** + * allows usage of the old monolithic template structure instead of the new template sets structure. + * + * TODO: Check if still needed, see: https://github.com/devonfw/cobigen/issues/1683 + */ + @Option(names = { "--force-monolithic-configuration", + "--force-mc" }, description = MessagesConstants.FORCE_MONOLITHIC_CONFIGURATION) + boolean forceMonolithicConfiguration; + /** * Logger to output useful information to the user */ @@ -101,7 +114,11 @@ public Integer doAction() throws Exception { } LOG.debug("Input files and output root path confirmed to be valid."); - CobiGen cg = CobiGenUtils.initializeCobiGen(this.templatesProject); + + if ((PostponeUtil.isTimePassed()) && (!this.forceMonolithicConfiguration)) + checkMonolithicConfigurationException(); + + CobiGen cg = CobiGenUtils.initializeCobiGen(this.templatesProject, true); resolveTemplateDependencies(); @@ -118,7 +135,9 @@ public Integer doAction() throws Exception { MavenUtil.getProjectRoot(this.inputFiles.get(i), false), inputsAndArtifacts.getB(), cg, IncrementTo.class); } } + return 0; + } /** @@ -177,7 +196,7 @@ private Tuple, List> preprocess(Co "Did not detect the input as part of a maven project, the root directory of the maven project was not found."); LOG.info("Would you like to take '{}' as a root directory for output generation? \n" - + "type yes/y to continue or no/n to cancel (or hit return for yes).", System.getProperty("user.dir")); + + MessagesConstants.YES_NO_ANSWER_DESCRIPTION, System.getProperty("user.dir")); setRootOutputDirectoryWithPrompt(); @@ -243,6 +262,73 @@ private void setRootOutputDirectoryWithPrompt() { } + /** + * Uses default initialization, checks if monolithic templates exist, handles the exception and lets the user decide + * if the templates should be upgraded. + */ + private void checkMonolithicConfigurationException() { + + try { + CobiGenUtils.initializeCobiGen(this.templatesProject, false); + } catch (DeprecatedMonolithicConfigurationException e) { + LOG.warn("Found monolithic configuration at: {} {}", + DeprecatedMonolithicConfigurationException.getMonolithicConfiguration(), e.getMessage()); + + if (this.upgradeConfiguration || askUserToUpgradeTemplates()) { + startTemplatesUpgrader(); + } else { + askUserToPostponeUpgrade(); + } + } + + } + + /** + * Opens a looping prompt with a yes/no question and upgrades the templates to the newest version. + * + */ + private boolean askUserToUpgradeTemplates() { + + LOG.info( + "Would you like to upgrade your templates to the newest version? \n" + + MessagesConstants.YES_NO_ANSWER_DESCRIPTION + "For more Informations, please visit: ", + WikiConstants.WIKI_UPGRADE_MONOLITHIC_CONFIGURATION, System.getProperty("user.dir")); + + return ValidationUtils.yesNoPrompt("Upgrading templates configuration...: ", + MessagesConstants.INVALID_YES_NO_ANSWER_DESCRIPTION, "Continue generation with monolithic templates..."); + } + + /** + * Upgrades the given template configuration and sets the new template-set as the templatesProject after the upgrade + */ + private void startTemplatesUpgrader() { + + try { + this.templatesProject = CobiGenFactory.startTemplatesUpgrader(this.templatesProject); + } catch (Throwable e) { + LOG.error("An error occurred while upgrading the templates."); + throw e; + } + } + + /** + * Asks the user if he wants to postpone the upgrade message for 30 days. + */ + private void askUserToPostponeUpgrade() { + + LOG.info("Would you like to postpone the upgrade warning message for 30 days?" + + MessagesConstants.YES_NO_ANSWER_DESCRIPTION, System.getProperty("user.dir")); + // TODO: Check if this message and behavior is still valid, see: https://github.com/devonfw/cobigen/issues/1674 + boolean setToUserDir = ValidationUtils.yesNoPrompt("A timer is set for 30 days...: ", + MessagesConstants.INVALID_YES_NO_ANSWER_DESCRIPTION, "Allright..."); + + if (setToUserDir) { + PostponeUtil.addATimestampForOneMonth(); + } else { + // Do nothing, the user will be asked again. + } + } + /** * Casting class, from List to List * diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/constants/MessagesConstants.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/constants/MessagesConstants.java index 9c63da3f73..9da407a824 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/constants/MessagesConstants.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/constants/MessagesConstants.java @@ -1,5 +1,7 @@ package com.devonfw.cobigen.cli.constants; +import com.devonfw.cobigen.impl.config.constant.WikiConstants; + /** * Messages constants printed to the user */ @@ -72,8 +74,35 @@ public class MessagesConstants { */ public static final String ADAPT_TEMPLATES_DESCRIPTION = "Generates a new templates folder next to the cobigen cli"; + /** + * Message constant: description of the adapt-templates --all command + */ + public static final String ADAPT_ALL_DESCRIPTION = "If this option is enabled, all templates will get adapted."; + /** * Message constant: description of the custom-location option */ public static final String CUSTOM_LOCATION_OPTION_DESCRIPTION = "Custom location where the unpacked templates will be stored."; + + /** + * Message constant: description of the --upgrade option + */ + public static final String UPGRADE_CONFIGURATION_OPTION = "Will upgrade the monolithc templates automatically, if enabled."; + + /** + * Message constant: description of the generate command with --force-monolithic-templates option + */ + public static final String FORCE_MONOLITHIC_CONFIGURATION = "If this option is enabled, the old monolithic template structure will be used instead of the new template sets structure..Further Information can be found at: " + + WikiConstants.WIKI_UPGRADE_MONOLITHIC_CONFIGURATION; + + /** + * Message constant: description of the CLI Yes or No answer + */ + public static final String YES_NO_ANSWER_DESCRIPTION = "Type yes/y to continue or no/n to cancel (or hit return for yes). "; + + /** + * Message constant: description of the CLI Invalid Yes or No answer + */ + public static final String INVALID_YES_NO_ANSWER_DESCRIPTION = "Invalid input. Please answer yes/n or no/n (or hit return for yes)."; + } diff --git a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java index d62b624f88..c4abaf657e 100644 --- a/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java +++ b/cobigen-cli/cli/src/main/java/com/devonfw/cobigen/cli/utils/CobiGenUtils.java @@ -48,18 +48,18 @@ public class CobiGenUtils { * Registers CobiGen plug-ins and instantiates CobiGen * * @param templatesProject the templates project or jar + * @param allowMonolithicConfiguration ignores deprecated monolithic template folder structure and if found does not + * throw a DeprecatedMonolithicConfigurationException * @return object of CobiGen */ - public static CobiGen initializeCobiGen(Path templatesProject) { + public static CobiGen initializeCobiGen(Path templatesProject, boolean allowMonolithicConfiguration) { registerPlugins(); - CobiGen cg; if (templatesProject != null) { - cg = CobiGenFactory.create(templatesProject.toUri()); + return CobiGenFactory.create(templatesProject.toUri(), allowMonolithicConfiguration); } else { - cg = CobiGenFactory.create(); + return CobiGenFactory.create(allowMonolithicConfiguration); } - return cg; } /** diff --git a/cobigen-cli/cli/src/main/resources/pom.xml b/cobigen-cli/cli/src/main/resources/pom.xml index 302f03cac8..bbbefc623e 100644 --- a/cobigen-cli/cli/src/main/resources/pom.xml +++ b/cobigen-cli/cli/src/main/resources/pom.xml @@ -56,11 +56,6 @@ jsonplugin ${revision} - - com.devonfw.cobigen - templates-devon4j - ${revision} - \ No newline at end of file diff --git a/cobigen-cli/pom.xml b/cobigen-cli/pom.xml index 963f3b1811..422161cea6 100644 --- a/cobigen-cli/pom.xml +++ b/cobigen-cli/pom.xml @@ -12,10 +12,6 @@ ${revision} - - 11 - - cli cli-systemtest diff --git a/cobigen-eclipse/cobigen-eclipse-feature/.project b/cobigen-eclipse/cobigen-eclipse-feature/.project deleted file mode 100644 index 7a6654cc23..0000000000 --- a/cobigen-eclipse/cobigen-eclipse-feature/.project +++ /dev/null @@ -1,41 +0,0 @@ - - - cobigen-eclipse-feature - - - cobigen-eclipse - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.FeatureBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - org.eclipse.pde.FeatureNature - - - - 1664574669497 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/cobigen-eclipse/cobigen-eclipse-test/.project b/cobigen-eclipse/cobigen-eclipse-test/.project deleted file mode 100644 index 7c40ecd24c..0000000000 --- a/cobigen-eclipse/cobigen-eclipse-test/.project +++ /dev/null @@ -1,45 +0,0 @@ - - - cobigen-eclipse-test - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - - - 1664574669506 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/cobigen-eclipse/cobigen-eclipse-test/META-INF/MANIFEST.MF b/cobigen-eclipse/cobigen-eclipse-test/META-INF/MANIFEST.MF index ec983cf6f9..8fb8869f36 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/META-INF/MANIFEST.MF +++ b/cobigen-eclipse/cobigen-eclipse-test/META-INF/MANIFEST.MF @@ -4,34 +4,77 @@ Bundle-Name: CobiGen Eclipse Plug-In Tests Bundle-SymbolicName: com.devonfw.cobigen.eclipse.test;singleton:=true Bundle-Version: 2021.12.007.qualifier Bundle-Vendor: devonfw -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Bundle-ClassPath: ., + lib/annotations.jar, + lib/ant.jar, + lib/ant-nodeps.jar, lib/assertj-core.jar, + lib/awaitility.jar, + lib/byte-buddy.jar, + lib/byte-buddy-agent.jar, lib/checker-qual.jar, + lib/com.devonfw.cobigen.eclipse.feature.jar, + lib/com.devonfw.cobigen.eclipse.jar, + lib/commons-compiler.jar, + lib/commons-compress.jar, + lib/commons-io.jar, + lib/commons-jxpath.jar, lib/commons-lang3.jar, + lib/core.jar, lib/core-api.jar, + lib/core-externalprocess-api.jar, lib/core-test.jar, lib/error_prone_annotations.jar, lib/failureaccess.jar, + lib/gson.jar, lib/guava.jar, + lib/hamcrest.jar, lib/hamcrest-core.jar, + lib/istack-commons-runtime.jar, lib/j2objc-annotations.jar, + lib/jackson-annotations.jar, + lib/jackson-core.jar, + lib/jackson-databind.jar, + lib/jakarta.activation.jar, + lib/jakarta.xml.bind-api.jar, + lib/janino.jar, + lib/javaplugin-model.jar, + lib/java-sizeof.jar, + lib/javassist.jar, + lib/javax.inject.jar, + lib/jaxb-core.jar, + lib/jaxb-impl.jar, + lib/jaxen.jar, lib/jcl-over-slf4j.jar, lib/jsr305.jar, lib/junit.jar, + lib/kotlin-stdlib.jar, + lib/kotlin-stdlib-common.jar, + lib/kotlin-stdlib-jdk7.jar, + lib/kotlin-stdlib-jdk8.jar, lib/listenablefuture.jar, lib/log4j-over-slf4j.jar, lib/logback-classic.jar, lib/logback-core.jar, + lib/maven-model.jar, + lib/mmm-base.jar, lib/mockito-core.jar, lib/objenesis.jar, + lib/okhttp.jar, + lib/okio.jar, + lib/okio-jvm.jar, + lib/orika-core.jar, + lib/paranamer.jar, + lib/plexus-cipher.jar, + lib/plexus-sec-dispatcher.jar, + lib/plexus-utils.jar, lib/slf4j-api.jar, lib/system-lambda.jar, + lib/txw2.jar, lib/xmlunit.jar, - lib/zt-exec.jar, - lib/awaitility.jar, - lib/hamcrest.jar + lib/zt-exec.jar Require-Bundle: org.eclipse.swtbot.junit4_x;bundle-version="2.4.0", org.junit;bundle-version="4.12.0", org.eclipse.ui, @@ -47,4 +90,5 @@ Require-Bundle: org.eclipse.swtbot.junit4_x;bundle-version="2.4.0", org.apache.commons.io;bundle-version="2.2.0", org.eclipse.m2e.core.ui;bundle-version="1.6.0", org.eclipse.m2e.core;bundle-version="1.6.0", - com.devonfw.cobigen.eclipse + com.devonfw.cobigen.eclipse, + org.eclipse.swtbot.swt.finder diff --git a/cobigen-eclipse/cobigen-eclipse-test/build.properties b/cobigen-eclipse/cobigen-eclipse-test/build.properties index 1943f55c16..fdd1aba796 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/build.properties +++ b/cobigen-eclipse/cobigen-eclipse-test/build.properties @@ -3,28 +3,71 @@ source.. = src/main/java/ bin.includes = .,\ META-INF/,\ plugin.xml,\ + lib/annotations.jar,\ + lib/ant.jar,\ + lib/ant-nodeps.jar,\ lib/assertj-core.jar,\ + lib/awaitility.jar,\ + lib/byte-buddy.jar,\ + lib/byte-buddy-agent.jar,\ lib/checker-qual.jar,\ + lib/com.devonfw.cobigen.eclipse.feature.jar,\ + lib/com.devonfw.cobigen.eclipse.jar,\ + lib/commons-compiler.jar,\ + lib/commons-compress.jar,\ + lib/commons-io.jar,\ + lib/commons-jxpath.jar,\ lib/commons-lang3.jar,\ + lib/core.jar,\ lib/core-api.jar,\ + lib/core-externalprocess-api.jar,\ lib/core-test.jar,\ lib/error_prone_annotations.jar,\ lib/failureaccess.jar,\ + lib/gson.jar,\ lib/guava.jar,\ + lib/hamcrest.jar,\ lib/hamcrest-core.jar,\ + lib/istack-commons-runtime.jar,\ lib/j2objc-annotations.jar,\ + lib/jackson-annotations.jar,\ + lib/jackson-core.jar,\ + lib/jackson-databind.jar,\ + lib/jakarta.activation.jar,\ + lib/jakarta.xml.bind-api.jar,\ + lib/janino.jar,\ + lib/javaplugin-model.jar,\ + lib/java-sizeof.jar,\ + lib/javassist.jar,\ + lib/javax.inject.jar,\ + lib/jaxb-core.jar,\ + lib/jaxb-impl.jar,\ + lib/jaxen.jar,\ lib/jcl-over-slf4j.jar,\ lib/jsr305.jar,\ lib/junit.jar,\ + lib/kotlin-stdlib.jar,\ + lib/kotlin-stdlib-common.jar,\ + lib/kotlin-stdlib-jdk7.jar,\ + lib/kotlin-stdlib-jdk8.jar,\ lib/listenablefuture.jar,\ lib/log4j-over-slf4j.jar,\ lib/logback-classic.jar,\ lib/logback-core.jar,\ + lib/maven-model.jar,\ + lib/mmm-base.jar,\ lib/mockito-core.jar,\ lib/objenesis.jar,\ + lib/okhttp.jar,\ + lib/okio.jar,\ + lib/okio-jvm.jar,\ + lib/orika-core.jar,\ + lib/paranamer.jar,\ + lib/plexus-cipher.jar,\ + lib/plexus-sec-dispatcher.jar,\ + lib/plexus-utils.jar,\ lib/slf4j-api.jar,\ lib/system-lambda.jar,\ + lib/txw2.jar,\ lib/xmlunit.jar,\ - lib/zt-exec.jar,\ - lib/awaitility.jar,\ - lib/hamcrest.jar + lib/zt-exec.jar diff --git a/cobigen-eclipse/cobigen-eclipse-test/pom.xml b/cobigen-eclipse/cobigen-eclipse-test/pom.xml index 7b1ac73625..8fc4f9cf42 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/pom.xml +++ b/cobigen-eclipse/cobigen-eclipse-test/pom.xml @@ -188,15 +188,54 @@ http://download.eclipse.org/technology/swtbot/releases/latest/ p2 - - - - - p2-build-photon - - eclipse-photon-sr2-test - http://download.eclipse.org/tools/orbit/downloads/drops/R20180606145124/repository/ + htmlplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-htmlplugin/target/repository + p2 + + + javaplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-javaplugin-parent/cobigen-javaplugin/target/repository + p2 + + + jsonplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-jsonplugin/target/repository + p2 + + + openapiplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-openapiplugin-parent/cobigen-openapiplugin/target/repository + p2 + + + propertyplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-propertyplugin/target/repository + p2 + + + freemarker + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-templateengines/cobigen-tempeng-freemarker/target/repository + p2 + + + velocity + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-templateengines/cobigen-tempeng-velocity/target/repository + p2 + + + textmerger + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-textmerger/target/repository + p2 + + + tsplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-tsplugin/target/repository + p2 + + + xmlplugin + file:///${maven.multiModuleProjectDirectory}/cobigen-plugins/cobigen-xmlplugin/target/repository p2 diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java index 92a0ace483..7536ade8d6 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/AdaptTemplatesTest.java @@ -20,6 +20,8 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; +import com.devonfw.cobigen.api.util.CobiGenPaths; +import com.devonfw.cobigen.api.util.TemplatesJarUtil; import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; import com.devonfw.cobigen.eclipse.test.common.SystemTest; import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished; @@ -68,7 +70,17 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); this.tmpMavenProjectRule.updateProject(); - EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot); + // retrieve CobiGen home directory (overwritten through environment variables) + File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile(); + + // create templates directory as this should be present in this scenario + this.tempFolder.newFolder("playground", "project", "templates"); + + // download latest monolithic templates to simulate existing template jars + TemplatesJarUtil.downloadLatestDevon4jTemplates(true, templatesDirectory); + TemplatesJarUtil.downloadLatestDevon4jTemplates(false, templatesDirectory); + + // adapt template jars into CobiGen_Templates project EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot); EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); @@ -80,7 +92,8 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "CRUD devon4j Server>CRUD REST services"); + bot.waitUntil(new AllJobsAreFinished(), 10000); // increase timeout as the openAPI parser is slow on initialization EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000); @@ -91,6 +104,7 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception { "src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java"); assertThat(generationResult.exists()).isTrue(); + } /** diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ClassPathLoadingTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ClassPathLoadingTest.java index 8de12cedb7..a4e0e9408b 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ClassPathLoadingTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/ClassPathLoadingTest.java @@ -81,7 +81,7 @@ public void testPreventClassPathShading() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment1"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment1"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -129,7 +129,7 @@ public void testClassPathResolutionOnInput_dependsOnMavenDependency() throws Exc javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment1"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment1"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -173,7 +173,7 @@ public void testClassPathResolutionOnInput_dependsOnMavenProject() throws Except javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment1"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment1"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -205,7 +205,7 @@ public void testClassloadingOfTemplateDependencies() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment2"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment2"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -246,7 +246,7 @@ public void testDotPathAcception() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment3"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment3"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/CobigenJavaWrapperTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/CobigenJavaWrapperTest.java index a07008e8e4..84e97bbc1b 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/CobigenJavaWrapperTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/CobigenJavaWrapperTest.java @@ -67,7 +67,7 @@ public void testWorkspaceExternalProjectAsInput() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment2"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment2"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -100,7 +100,7 @@ public void testPathInvariants() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment3"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment3"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions @@ -132,7 +132,7 @@ public void testPackageAsInputForGeneration() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment1"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment1"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/HealthCheckTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/HealthCheckTest.java index a116c5f471..f885d282ff 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/HealthCheckTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/HealthCheckTest.java @@ -46,6 +46,8 @@ public void testHealthCheckIfTemplateProjecNotCopiedIntoWS() throws Exception { EclipseUtils.importExistingGeneralProject(bot, tmpFolder.getAbsolutePath(), false); EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); - EclipseCobiGenUtils.runAndCaptureHealthCheck(bot); + EclipseCobiGenUtils.runAndCaptureHealthCheckWithMonolithicConfiguration(bot); } + + // TODO: Add a health check test for new template sets, see: https://github.com/devonfw/cobigen/issues/1648 } diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/MultipleMatchingTriggerTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/MultipleMatchingTriggerTest.java index 37c06e06d8..0a5a24576c 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/MultipleMatchingTriggerTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/MultipleMatchingTriggerTest.java @@ -67,7 +67,7 @@ public void testMutlipleTemplates_differentTrigger_samePath() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "increment1", "increment2"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "increment1", "increment2"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/OpenAPITest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/OpenAPITest.java index fd594e1d15..777640ef6c 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/OpenAPITest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/OpenAPITest.java @@ -29,6 +29,8 @@ /** * General Eclipse Plug-in Tests. + * + * TODO: Create a copy of this test class for template sets using a regular generate (without upgrade or postpone) */ @RunWith(SWTBotJunit4ClassRunner.class) public class OpenAPITest extends SystemTest { @@ -69,7 +71,7 @@ public void testBasicOpenAPIGeneration() throws Exception { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); this.tmpMavenProjectRule.updateProject(); - EclipseCobiGenUtils.runAndCaptureHealthCheck(bot); + EclipseCobiGenUtils.runAndCaptureHealthCheckWithMonolithicConfiguration(bot); EclipseUtils.openErrorsTreeInProblemsView(bot); // expand the new file in the package explorer @@ -78,9 +80,9 @@ public void testBasicOpenAPIGeneration() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "CRUD REST services"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "CRUD REST services"); // increase timeout as the openAPI parser is slow on initialization - EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000); + EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 120000); // check assertions bot.waitUntil(new AllJobsAreFinished(), 10000); @@ -149,7 +151,7 @@ public void testServiceBasedOpenAPIGeneration() throws Exception { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); this.tmpMavenProjectRule.updateProject(); - EclipseCobiGenUtils.runAndCaptureHealthCheck(bot); + EclipseCobiGenUtils.runAndCaptureHealthCheckWithMonolithicConfiguration(bot); EclipseUtils.openErrorsTreeInProblemsView(bot); // expand the new file in the package explorer @@ -158,7 +160,7 @@ public void testServiceBasedOpenAPIGeneration() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "View Component"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "View Component"); // increase timeout as the openAPI parser is slow on initialization EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000); @@ -218,7 +220,7 @@ public void testRegexBasedOpenAPIGeneration() throws Exception { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); this.tmpMavenProjectRule.updateProject(); - EclipseCobiGenUtils.runAndCaptureHealthCheck(bot); + EclipseCobiGenUtils.runAndCaptureHealthCheckWithMonolithicConfiguration(bot); EclipseUtils.openErrorsTreeInProblemsView(bot); // expand the new file in the package explorer SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); @@ -226,7 +228,7 @@ public void testRegexBasedOpenAPIGeneration() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "generate a file for every Entity"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "generate a file for every Entity"); // increase timeout as the openAPI parser is slow on initialization EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000); diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/UpgradeMonolithicTemplatesTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/UpgradeMonolithicTemplatesTest.java new file mode 100644 index 0000000000..255b93282d --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/UpgradeMonolithicTemplatesTest.java @@ -0,0 +1,103 @@ +package com.devonfw.cobigen.eclipse.test; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; +import com.devonfw.cobigen.eclipse.common.tools.ResourcesPluginUtil; +import com.devonfw.cobigen.eclipse.test.common.SystemTest; +import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished; +import com.devonfw.cobigen.eclipse.test.common.utils.EclipseCobiGenUtils; +import com.devonfw.cobigen.eclipse.test.common.utils.EclipseUtils; + +/** + * Test the upgrader in core and generates from the new template-set + * + */ +@Ignore // TODO: re-enable when upgrader was implemented, see: https://github.com/devonfw/cobigen/issues/1595 +@RunWith(SWTBotJunit4ClassRunner.class) +public class UpgradeMonolithicTemplatesTest extends SystemTest { + + /** Root path of the Test Resources */ + private static final String resourcesRootPath = "src/main/resources/UpgradeMonolithicTemplatesTest/"; + + /** Current home directory */ + protected Path currentHome; + + /** + * Setup workbench appropriately for tests + * + * @throws Exception test fails + */ + @BeforeClass + public static void setupClass() throws Exception { + + EclipseUtils.cleanWorkspace(bot, true); + // import the configuration project for this test + EclipseUtils.importExistingGeneralProject(bot, + new File(resourcesRootPath + "templates/CobiGen_Templates").getAbsolutePath()); + EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME); + + } + + /** + * Tests if the Upgrader will work properly and generate after that + * + * Setup home path for cobigen to isolate the test (withEnvironmentVariable) + * + * @throws Exception Test fails + */ + @Test + public void testUpgradeAndGenerateFromTemplateSet() throws Exception { + + this.currentHome = this.tmpFolderRule.newFolder("cobigen-test-home").toPath(); + withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, this.currentHome.toString()).execute(() -> { + + // create a new temporary java project and copy java class used as an input for CobiGen + String testProjectName = "TestInputProj"; + IJavaProject project = this.tmpMavenProjectRule.createProject(testProjectName); + FileUtils.copyFile(new File(resourcesRootPath + "input/test.yml"), + project.getUnderlyingResource().getLocation().append("src/main/java/main/test.yml").toFile()); + project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + this.tmpMavenProjectRule.updateProject(); + + // expand the new file in the package explorer + SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); + SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjectName, "src/main/java", "main", "test.yml"); + javaClassItem.select(); + + // execute CobiGen + EclipseCobiGenUtils.processCobiGenAndUpgrade(bot, javaClassItem, "All"); + + EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000); + + // check assertions + bot.waitUntil(new AllJobsAreFinished(), 10000); + + IFile generationResult = project.getProject().getFile("src/environments/environment.ts"); + assertThat(generationResult.exists()).isTrue(); + }); + FileUtils.deleteDirectory(this.currentHome.toFile()); + // Set to null to to run all eclipse tests after the upgrade + ResourcesPluginUtil.setTemplateSetPathAfterUpgrade(null); + + } +} diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/VelocityGenerationTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/VelocityGenerationTest.java index 9918b61c47..15c065c1dc 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/VelocityGenerationTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/VelocityGenerationTest.java @@ -45,6 +45,8 @@ public static void setupClass() throws Exception { /** * Tests a simple generation using velocity template engine. * + * TODO: add same test for template sets using regular generate + * * @throws Exception test fails */ @Test @@ -63,7 +65,7 @@ public void simpleVelocityBasedGeneration() throws Exception { javaClassItem.select(); // execute CobiGen - EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, "Velocity Test"); + EclipseCobiGenUtils.processCobiGenAndPostponeUpgrade(bot, javaClassItem, "Velocity Test"); EclipseCobiGenUtils.confirmSuccessfullGeneration(bot); // check assertions diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/SystemTest.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/SystemTest.java index dd5cd84027..bc131f67a5 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/SystemTest.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/SystemTest.java @@ -19,7 +19,6 @@ import org.slf4j.LoggerFactory; import com.devonfw.cobigen.eclipse.test.common.junit.TmpMavenProjectRule; -import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished; import com.devonfw.cobigen.eclipse.test.common.utils.EclipseCobiGenUtils; import com.devonfw.cobigen.eclipse.test.common.utils.EclipseUtils; @@ -74,7 +73,6 @@ protected void finished(Description description) { public static void setupTest() throws Exception { bot.resetWorkbench(); - bot.waitUntil(new AllJobsAreFinished()); // this flag is set to be true and will suppress ErrorDialogs, // which is completely strange, so we enable them again. diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/junit/TmpMavenProjectRule.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/junit/TmpMavenProjectRule.java index 976e111a46..bb71e3b78e 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/junit/TmpMavenProjectRule.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/junit/TmpMavenProjectRule.java @@ -2,6 +2,10 @@ import java.io.ByteArrayInputStream; import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.Collection; import java.util.Random; import org.eclipse.core.resources.IFile; @@ -20,6 +24,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.devonfw.cobigen.api.exception.CobiGenRuntimeException; + /** * JUnit Rule for a temporary {@link IJavaProject}. Should be created in each test method by createProject when it * should be used. @@ -35,7 +41,9 @@ public class TmpMavenProjectRule extends ExternalResource { */ private IJavaProject javaProject; - /** Maven Project specification containing group id, artifact id, and version as a pom xml description */ + /** + * Maven Project specification containing group id, artifact id, and version as a pom xml description + */ private String mvnProjectSpecification; @Override @@ -113,8 +121,29 @@ public void updateProject() throws CoreException { // make sure the contents are synchronized this.javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); // update maven project to implicitly set classpath and so on. - new UpdateMavenProjectJob(new IProject[] { this.javaProject.getProject() }) - .runInWorkspace(new NullProgressMonitor()); + + // Need to access internal (fragile) API of M2E as command + // "org.eclipse.m2e.core.ui.command.updateProject" does not allow execution, but + // spawns dialog popup + Constructor constructor; + UpdateMavenProjectJob updateMavenJob; + try { + // M2E < v2 + constructor = UpdateMavenProjectJob.class.getConstructor(IProject[].class); + updateMavenJob = constructor.newInstance((Object) new IProject[] { this.javaProject.getProject() }); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) { + LOG.debug("Assumptions for M2E < 2 did not match, trying to connect to M2E v2 API", e); + try { + // M2E >= 2 + constructor = UpdateMavenProjectJob.class.getConstructor(Collection.class); + updateMavenJob = constructor.newInstance(Arrays.asList(this.javaProject.getProject())); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e1) { + throw new CobiGenRuntimeException( + "There might be an incompatibility with the current version of M2E installed. Please state a bug report on github including the M2E version installed in your eclipse.", + e1); + } + } + updateMavenJob.runInWorkspace(new NullProgressMonitor()); } diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java index 1ea0de1e42..992b7cbb56 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseCobiGenUtils.java @@ -5,6 +5,7 @@ import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.dialogs.IDialogConstants; @@ -35,7 +36,7 @@ public class EclipseCobiGenUtils { public static final int DEFAULT_TIMEOUT = 15000; /** - * Selects the the increment with the given name and generates it. + * Selects the increment with the given name and generates it. * * @param bot the {@link SWTWorkbenchBot} of the test * @param input input of CobiGen to be selected @@ -47,6 +48,34 @@ public static void processCobiGen(SWTWorkbenchBot bot, SWTBotTreeItem input, Str processCobiGen(bot, input, DEFAULT_TIMEOUT, increments); } + /** + * Selects the increment with the given name and generates it, even if monolithic templates found + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param increments increments to be generated. + * @throws Exception test fails + */ + public static void processCobiGenAndPostponeUpgrade(SWTWorkbenchBot bot, SWTBotTreeItem input, String... increments) + throws Exception { + + processCobiGenAndPostponeUpgrade(bot, input, DEFAULT_TIMEOUT, increments); + } + + /** + * Selects the increment with the given name, upgrades the monolithic templates and generates. + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param increments increments to be generated. + * @throws Exception test fails + */ + public static void processCobiGenAndUpgrade(SWTWorkbenchBot bot, SWTBotTreeItem input, String... increments) + throws Exception { + + processCobiGenAndUpgrade(bot, input, DEFAULT_TIMEOUT, increments); + } + /** * Tries a Generate process with an expected error title. * @@ -101,7 +130,7 @@ private static SWTBotTreeItem expandNodes(SWTWorkbenchBot bot, String increment) } /** - * Selects the the increment with the given name and generates it. + * Selects the increment with the given name and generates it. * * @param bot the {@link SWTWorkbenchBot} of the test * @param input input of CobiGen to be selected @@ -135,7 +164,8 @@ public static void processCobiGenWithTextInput(SWTWorkbenchBot bot, SWTBotEclips ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time input.contextMenu("CobiGen").menu("Generate...").click(); - generateWithSelectedIncrements(bot, defaultTimeout, increments); + postponeUpgradeAndContinue(bot); + generateWithSelectedIncrements(bot, 120000, increments); } /** @@ -169,6 +199,47 @@ private static void generateWithSelectedIncrements(SWTWorkbenchBot bot, int defa finishButton.click(); } + /** + * Selects the increment with the given name and generates it, even if monolithic templates found + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param increments increments to be generated. + * @throws CoreException + * @throws Exception test fails + */ + private static void processCobiGenAndPostponeUpgrade(SWTWorkbenchBot bot, SWTBotTreeItem input, int defaultTimeout, + String[] increments) throws Exception { + + // Open generation wizard with new file as Input + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); + bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time + input.contextMenu("CobiGen").menu("Generate...").click(); + postponeUpgradeAndContinue(bot); + generateWithSelectedIncrements(bot, 120000, increments); + } + + /** + * Selects the increment with the given name and generates it, upgrade if monolithic templates found + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param input input of CobiGen to be selected + * @param increments increments to be generated. + * @throws CoreException + * @throws Exception test fails + */ + private static void processCobiGenAndUpgrade(SWTWorkbenchBot bot, SWTBotTreeItem input, int defaultTimeout, + String[] increments) throws Exception { + + // Open generation wizard with new file as Input + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); + bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time + input.contextMenu("CobiGen").menu("Generate...").click(); + upgradeAndContinue(bot, defaultTimeout); + + generateWithSelectedIncrements(bot, defaultTimeout, increments); + } + /** * Tries a Generate process with an expected error title. * @@ -185,6 +256,7 @@ public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTr ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time input.contextMenu("CobiGen").menu("Generate...").click(); + postponeUpgradeAndContinue(bot); bot.waitUntil(new AnyShellIsActive(expectedErrorTitle), defaultTimeout); takeScreenshot(bot, "InvalidConfigurationDialog"); @@ -194,6 +266,38 @@ public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTr finishButton.click(); } + /** + * Skips the Upgrade Warning message with the "Postpone" button + * + * @param bot the {@link SWTWorkbenchBot} of the test + * + */ + private static void postponeUpgradeAndContinue(SWTWorkbenchBot bot) { + + takeScreenshot(bot, "Warning!"); + SWTBotShell finishDialog = bot.shell("Warning!"); + finishDialog.bot().button("Postpone").click(); + } + + /** + * Starts the upgrade process with the "Upgrade" button + * + * @param bot the {@link SWTWorkbenchBot} of the test + * @param defaultTimeout + * + */ + private static void upgradeAndContinue(SWTWorkbenchBot bot, int defaultTimeout) { + + takeScreenshot(bot, "Warning!"); + SWTBotShell finishDialog = bot.shell("Warning!"); + finishDialog.bot().button("Upgrade").click(); + bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); + takeScreenshot(bot, "Success!"); + SWTBotShell successDialog = bot.shell("Success!"); + successDialog.bot().button("Ok").click(); + + } + /** * Checks the CobiGen HealthCheck and takes screenshots of it. * @@ -207,6 +311,35 @@ public static void runAndCaptureHealthCheck(SWTWorkbenchBot bot) throws Exceptio SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); view.bot().tree().expandNode("CobiGen_Templates").select().contextMenu("CobiGen").menu("Health Check...").click(); + // TODO: replace with health check reaction, see: https://github.com/devonfw/cobigen/issues/1686 + captureAdvancedHealthCheck(bot); + } + + /** + * Checks the CobiGen HealthCheck and takes screenshots of it, even if monolithic templates found. + * + * @param bot to process the health check + * @throws Exception test fails + */ + public static void runAndCaptureHealthCheckWithMonolithicConfiguration(SWTWorkbenchBot bot) throws Exception { + + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); + bot.waitUntil(new AllJobsAreFinished(), DEFAULT_TIMEOUT); // build might take some time + + SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES); + view.bot().tree().expandNode("CobiGen_Templates").select().contextMenu("CobiGen").menu("Health Check...").click(); + postponeUpgradeAndContinue(bot); + captureAdvancedHealthCheck(bot); + } + + /** + * Checks the CobiGen HealthCheck and takes screenshots of it. TODO: Split into captureHealthCheck and + * captureAdvancedHealthCheck, see: https://github.com/devonfw/cobigen/issues/1686 + * + * @param bot to process the health check + */ + private static void captureAdvancedHealthCheck(SWTWorkbenchBot bot) { + bot.waitUntil(new AnyShellIsActive(CobiGenDialogConstants.HealthCheckDialogs.DIALOG_TITLE), DEFAULT_TIMEOUT); takeScreenshot(bot, "healthCheck"); @@ -261,8 +394,8 @@ public static void runAndCaptureAdaptTemplates(SWTWorkbenchBot bot) throws Excep takeScreenshot(bot, "Adapt Templates Warning!"); SWTBotShell warningDialog = bot.shell("Warning!"); - warningDialog.bot().button("Ok").click(); + SWTBotShell informationDialog = bot.shell("Information"); bot.waitUntil(new AnyShellIsActive("Information"), DEFAULT_TIMEOUT); takeScreenshot(bot, "Adapt Templates Information"); diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java index 26edf4f958..87b3a7d348 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/EclipseUtils.java @@ -24,6 +24,7 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; @@ -40,6 +41,7 @@ import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished; +import com.devonfw.cobigen.eclipse.test.common.swtbot.HasBeenBuilt; import com.devonfw.cobigen.eclipse.test.common.utils.swtbot.SwtBotProjectActions; /** @@ -103,7 +105,12 @@ public static void importExistingGeneralProject(SWTWorkbenchBot bot, String proj bot.waitUntil(shellCloses(popup)); ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); - bot.waitUntil(new AllJobsAreFinished()); + for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + IJavaProject jp = JavaCore.create(p); + if (jp != null) { + bot.waitUntil(new HasBeenBuilt(jp)); + } + } } /** diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTestingUtilities.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTestingUtilities.java index d583203ab8..2d3a98b78f 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTestingUtilities.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTestingUtilities.java @@ -34,8 +34,6 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.hamcrest.Matcher; -import com.google.common.collect.Iterables; - /** * Provides helper methods to aid in SWTBot testing. */ @@ -227,7 +225,7 @@ public static void waitUntilMenuHasItem(SWTBot bot, Supplier menuSup @Override public boolean test() throws Exception { - return Iterables.any(menuSupplier.get().menuItems(), matcher::matches); + return menuSupplier.get().menuItems().stream().anyMatch(matcher::matches); } @Override diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTimeoutManager.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTimeoutManager.java index 2d06234f94..291925fd89 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTimeoutManager.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTimeoutManager.java @@ -20,10 +20,9 @@ package com.devonfw.cobigen.eclipse.test.common.utils.swtbot; +import org.assertj.core.api.Assertions; import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import com.google.common.base.Preconditions; - /** * Used to set the general SWTBot timeout. This class was originally to be thrown away, except that SWTBot doesn't * support a nice mechanism for temporarily changing the timeout. @@ -65,7 +64,7 @@ public static void setTimeout() { */ public static void setTimeout(long timeout) { - Preconditions.checkArgument(timeout > 0); + Assertions.assertThat(timeout).isGreaterThan(0); oldTimeoutSwtPrefs = getSwtBotPrefsTimeoutFieldValue(); setSwtBotPrefsTimeoutFieldValue(timeout); } diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTreeUtilities.java b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTreeUtilities.java index aa66497c84..89c8c723f6 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTreeUtilities.java +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/java/com/devonfw/cobigen/eclipse/test/common/utils/swtbot/SwtBotTreeUtilities.java @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.LinkedList; +import org.assertj.core.api.Assertions; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; @@ -40,9 +41,6 @@ import org.hamcrest.Matcher; import org.hamcrest.StringDescription; -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; - /** Utilities for manipulating trees. */ public class SwtBotTreeUtilities { @@ -126,7 +124,7 @@ public boolean test() throws Exception { parentItem.expand(); children = parentItem.getItems(); } - return Iterables.any(parentItem.getNodes(), childMatcher::matches); + return parentItem.getNodes().stream().anyMatch(childMatcher::matches); } }); for (SWTBotTreeItem child : parentItem.getItems()) { @@ -215,7 +213,7 @@ public String getFailureMessage() { */ public static SWTBotTreeItem select(SWTWorkbenchBot bot, SWTBotTree tree, String... nodeNames) { - Preconditions.checkArgument(nodeNames.length > 0, "no children to navigate"); + Assertions.assertThat(nodeNames.length).isGreaterThan(0); int leafIndex = nodeNames.length - 1; waitUntilTreeHasItems(bot, tree); diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/template1/context.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/context.xml similarity index 80% rename from cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/template1/context.xml rename to cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/context.xml index b5774d7a5d..caa323e573 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/template1/context.xml +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/GenerateFromTextInputTest/templates/src/main/templates/context.xml @@ -1,6 +1,6 @@ - + diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/input/test.yml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/input/test.yml new file mode 100644 index 0000000000..199c29deb3 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/input/test.yml @@ -0,0 +1,23 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' + description: Just some data +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.angular.test +paths: + /shopmanagement/v1/shop/{shopId}: + x-component: shopmanagement + get: + operationId: findShop + parameters: + - name: shopId + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 diff --git a/cobigen-templates/templates-devon4j/.project b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/.project similarity index 93% rename from cobigen-templates/templates-devon4j/.project rename to cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/.project index fccd2e4b05..b01e903d25 100644 --- a/cobigen-templates/templates-devon4j/.project +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/.project @@ -17,9 +17,8 @@ - org.sonar.ide.eclipse.core.sonarNature - org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature diff --git a/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/pom.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/pom.xml new file mode 100644 index 0000000000..5ebbd8cfe2 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + com.devonfw.cobigen + templates-devon4j + 2021.12.006 + CobiGen - devon4j Templates + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j + + 1.8 + 1.8 + + + + + src/main/templates + src/main/templates + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/context.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/context.xml similarity index 84% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/context.xml rename to cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/context.xml index 5e1c199c2b..fc1c9df45f 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/context.xml +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/context.xml @@ -1,8 +1,6 @@ - - - - + + @@ -10,5 +8,4 @@ - diff --git a/cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates.xml b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/crud_openapi_angular_service_based_app/templates.xml similarity index 56% rename from cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates.xml rename to cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/crud_openapi_angular_service_based_app/templates.xml index 82e273ff39..484a768358 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates.xml +++ b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/crud_openapi_angular_service_based_app/templates.xml @@ -3,16 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"> - + - + - - + + diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.ts.ftl b/cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.ts.ftl rename to cobigen-eclipse/cobigen-eclipse-test/src/main/resources/UpgradeMonolithicTemplatesTest/templates/CobiGen_Templates/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.ts.ftl diff --git a/cobigen-eclipse/cobigen-eclipse-test/targlets/2018-12.target b/cobigen-eclipse/cobigen-eclipse-test/targlets/2018-12.target new file mode 100644 index 0000000000..f720b3a330 --- /dev/null +++ b/cobigen-eclipse/cobigen-eclipse-test/targlets/2018-12.target @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-eclipse/cobigen-eclipse-updatesite/.project b/cobigen-eclipse/cobigen-eclipse-updatesite/.project deleted file mode 100644 index 631967f7bd..0000000000 --- a/cobigen-eclipse/cobigen-eclipse-updatesite/.project +++ /dev/null @@ -1,36 +0,0 @@ - - - cobigen-eclipse-updatesite - - - cobigen-eclipse - cobigen-eclipse-feature - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - - - - 1664574669516 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/cobigen-eclipse/cobigen-eclipse/.project b/cobigen-eclipse/cobigen-eclipse/.project deleted file mode 100644 index 533bae1e4d..0000000000 --- a/cobigen-eclipse/cobigen-eclipse/.project +++ /dev/null @@ -1,45 +0,0 @@ - - - cobigen-eclipse - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - - - 1664574669486 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - - diff --git a/cobigen-eclipse/cobigen-eclipse/META-INF/MANIFEST.MF b/cobigen-eclipse/cobigen-eclipse/META-INF/MANIFEST.MF index 224cc066c7..22fe3f42c9 100644 --- a/cobigen-eclipse/cobigen-eclipse/META-INF/MANIFEST.MF +++ b/cobigen-eclipse/cobigen-eclipse/META-INF/MANIFEST.MF @@ -17,7 +17,7 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.104.0", org.eclipse.ui.navigator.resources;bundle-version="3.4.400", org.eclipse.m2e.core.ui;bundle-version="1.6.0", org.eclipse.core.filesystem;bundle-version="1.5.0" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Bundle-ClassPath: ., lib/annotations.jar, @@ -57,14 +57,19 @@ Bundle-ClassPath: ., lib/kotlin-stdlib-common.jar, lib/listenablefuture.jar, lib/log4j-over-slf4j.jar, + lib/maven-model.jar, + lib/mmm-base.jar, + lib/okhttp.jar, + lib/orika-core.jar, + lib/zt-exec.jar, lib/logback-classic.jar, lib/logback-core.jar, - lib/mmm-util-core.jar, - lib/okhttp.jar, lib/okio.jar, - lib/orika-core.jar, lib/paranamer.jar, + lib/plexus-cipher.jar, + lib/plexus-sec-dispatcher.jar, + lib/plexus-utils.jar, lib/slf4j-api.jar, - lib/txw2.jar, - lib/zt-exec.jar -Export-Package: com.devonfw.cobigen.eclipse.common.constants.external + lib/txw2.jar +Export-Package: com.devonfw.cobigen.eclipse.common.constants.external, + com.devonfw.cobigen.eclipse.common.tools diff --git a/cobigen-eclipse/cobigen-eclipse/build.properties b/cobigen-eclipse/cobigen-eclipse/build.properties index 64d6a6e2a5..4415ea671c 100644 --- a/cobigen-eclipse/cobigen-eclipse/build.properties +++ b/cobigen-eclipse/cobigen-eclipse/build.properties @@ -42,11 +42,15 @@ bin.includes = .,\ lib/log4j-over-slf4j.jar,\ lib/logback-classic.jar,\ lib/logback-core.jar,\ - lib/mmm-util-core.jar,\ + lib/maven-model.jar,\ + lib/mmm-base.jar,\ lib/okhttp.jar,\ lib/okio.jar,\ lib/orika-core.jar,\ lib/paranamer.jar,\ + lib/plexus-cipher.jar,\ + lib/plexus-sec-dispatcher.jar,\ + lib/plexus-utils.jar,\ lib/slf4j-api.jar,\ lib/txw2.jar,\ lib/zt-exec.jar diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/InfrastructureConstants.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/InfrastructureConstants.java index 2ea80b33ea..bbaa521e2c 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/InfrastructureConstants.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/constants/InfrastructureConstants.java @@ -2,8 +2,6 @@ /** * Constants, which are needed for technical infrastructure. - * - * @author mbrunnli (Jun 17, 2015) */ public class InfrastructureConstants { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ExceptionHandler.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ExceptionHandler.java index 139cef1e69..1916b7994c 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ExceptionHandler.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ExceptionHandler.java @@ -9,12 +9,15 @@ import com.devonfw.cobigen.api.exception.CobiGenRuntimeException; import com.devonfw.cobigen.api.exception.ConfigurationConflictException; +import com.devonfw.cobigen.api.exception.DeprecatedMonolithicConfigurationException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorCreationException; import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; import com.devonfw.cobigen.eclipse.common.exceptions.InvalidInputException; import com.devonfw.cobigen.eclipse.healthcheck.HealthCheckDialog; +import com.devonfw.cobigen.impl.config.constant.WikiConstants; +import com.devonfw.cobigen.impl.util.PostponeUtil; /** * Util class to handle exceptions @@ -39,6 +42,9 @@ public static void handle(Throwable e, Shell activeShell) { openInvalidConfigurationErrorDialog((InvalidConfigurationException) e); } else if (ConfigurationConflictException.class.isAssignableFrom(e.getClass())) { openInvalidConfigurationErrorDialog((ConfigurationConflictException) e); + } else if (DeprecatedMonolithicConfigurationException.class.isAssignableFrom(e.getClass())) { + LOG.warn("Monolithic Templates found.", e); + openMonolithicConfigurationErrorDialog((DeprecatedMonolithicConfigurationException) e); } else if (GeneratorProjectNotExistentException.class.isAssignableFrom(e.getClass())) { LOG.error( "The project '{}' containing the configuration and templates is currently not existent. Please create one or check it out from SVN as stated in the user documentation.", @@ -95,4 +101,44 @@ private static void openInvalidConfigurationErrorDialog(InvalidConfigurationExce }); } + /** + * Opens up a message dialog for displaying further guidance on upgrading old templates. + * + * @param e {@link DeprecatedMonolithicConfigurationException} occurred + */ + private static void openMonolithicConfigurationErrorDialog(DeprecatedMonolithicConfigurationException e) { + + PlatformUIUtil.getWorkbench().getDisplay().syncExec(() -> { + MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Warning!", null, + e.getMessage() + " Further Information can be found at:" + + WikiConstants.WIKI_UPGRADE_MONOLITHIC_CONFIGURATION, + MessageDialog.WARNING, new String[] { "Upgrade", "Postpone", "Postpone for 30 days" }, 2); + + MessageDialog successUpgrade = new MessageDialog(Display.getDefault().getActiveShell(), "Success!", null, + "Templates were successfully upgraded. ", MessageDialog.INFORMATION, new String[] { "Ok" }, 1); + + dialog.setBlockOnOpen(true); + successUpgrade.setBlockOnOpen(true); + int result = dialog.open(); + if (result == 0) { + try { + ResourcesPluginUtil + .startTemplatesUpgrader(DeprecatedMonolithicConfigurationException.getMonolithicConfiguration()); + successUpgrade.open(); + } catch (Throwable a) { + String upgradeErrorMessage = "An error has occurred while upgrading the templates!"; + LOG.error(upgradeErrorMessage, a); + PlatformUIUtil.openErrorDialog(upgradeErrorMessage + " " + a.getMessage(), a); + } + } + if (result == 1) { + // Do nothing (Postpone and Continue) + } + if (result == 2) { + PostponeUtil.addATimestampForOneMonth(); + + } + }); + } + } diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/PlatformUIUtil.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/PlatformUIUtil.java index 1106de09ce..79e6080a1e 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/PlatformUIUtil.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/PlatformUIUtil.java @@ -21,8 +21,6 @@ /** * This class provides some helper functions in order to minimize code overhead - * - * @author Malte Brunnlieb (06.12.2012) */ public class PlatformUIUtil { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java index f7d1451db6..0b842712b7 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/common/tools/ResourcesPluginUtil.java @@ -5,6 +5,7 @@ import java.net.MalformedURLException; import java.nio.file.FileSystem; import java.nio.file.FileSystems; +import java.nio.file.Files; import java.nio.file.Path; import org.apache.commons.lang3.StringUtils; @@ -20,13 +21,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.devonfw.cobigen.api.TemplateAdapter; import com.devonfw.cobigen.api.constants.ConfigurationConstants; import com.devonfw.cobigen.api.util.CobiGenPaths; import com.devonfw.cobigen.api.util.TemplatesJarUtil; import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants; import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException; import com.devonfw.cobigen.eclipse.updatetemplates.UpdateTemplatesDialog; -import com.devonfw.cobigen.impl.util.ExtractTemplatesUtil; +import com.devonfw.cobigen.impl.CobiGenFactory; +import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl; /** Util for NPE save access of {@link ResourcesPlugin} utils */ public class ResourcesPluginUtil { @@ -51,6 +54,27 @@ public class ResourcesPluginUtil { */ static boolean userWantsToDownloadTemplates = true; + /** + * This variable is the path to the templateSet folder, when the ugrader is finished + */ + static Path templateSetPathAfterUpgrade; + + /** + * @return afterUpgradetemplateSetPath + */ + public static Path getTemplateSetPathAfterUpgrade() { + + return templateSetPathAfterUpgrade; + } + + /** + * @param afterUpgradetemplateSetPath new value of {@link #getafterUpgradetemplateSetPath}. + */ + public static void setTemplateSetPathAfterUpgrade(Path afterUpgradetemplateSetPath) { + + ResourcesPluginUtil.templateSetPathAfterUpgrade = afterUpgradetemplateSetPath; + } + /** * Refreshes the configuration project from the file system. */ @@ -88,9 +112,9 @@ public static IProject getGeneratorConfigurationProject() throws GeneratorProjec if (!generatorProj.exists()) { if (!isUpdateDialogShown) { if (templatesDirectory.exists()) { - File jarFile = TemplatesJarUtil.getJarFile(false, templatesDirectory); + Path jarFilePath = TemplatesJarUtil.getJarFile(false, templatesDirectory.toPath()); // If we don't find at least one jar, then we do need to download new templates - if (jarFile == null) { + if (jarFilePath == null || !Files.exists(jarFilePath)) { int result = createUpdateTemplatesDialog(); isUpdateDialogShown = true; if (result == 1) { @@ -113,7 +137,6 @@ public static IProject getGeneratorConfigurationProject() throws GeneratorProjec } } } - if (userWantsToDownloadTemplates) { return generatorProj; } else { @@ -168,26 +191,35 @@ public static String getJarPath(boolean isSource) { File templatesDirectory = getTemplatesDirectory(); - File jarFile = TemplatesJarUtil.getJarFile(isSource, templatesDirectory); + Path jarFilePath = TemplatesJarUtil.getJarFile(isSource, templatesDirectory.toPath()); - if (jarFile == null) { + if (jarFilePath == null || !Files.exists(jarFilePath)) { return ""; } - String fileName = jarFile.getPath().substring(jarFile.getPath().lastIndexOf(File.separator) + 1); - + String fileName = jarFilePath.toFile().getPath() + .substring(jarFilePath.toFile().getPath().lastIndexOf(File.separator) + 1); return fileName; } /** - * Gets or creates a new templates directory + * Gets or creates a new templates directory from the monolithic structure * * @return the templateDirectory */ private static File getTemplatesDirectory() { - File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile(); - return templatesDirectory; + return CobiGenPaths.getTemplatesFolderPath().toFile(); + } + + /** + * Gets or creates a new templates directory from the template-set structure + * + * @return the templateDirectory + */ + private static File getTemplateSetDirectory() { + + return CobiGenPaths.getTemplateSetsFolderPath().toFile(); } /** @@ -227,7 +259,9 @@ public static void processJar(String fileName) throws MalformedURLException, IOE } try { - ExtractTemplatesUtil.extractTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES), false); + TemplateAdapter templateAdapter = new TemplateAdapterImpl(null); + templateAdapter.adaptMonolithicTemplates(cobigenFolderPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES), + false); } catch (Exception e) { LOG.error("An exception occurred while processing Jar files to create CobiGen_Templates folder", e); PlatformUIUtil @@ -240,8 +274,7 @@ public static void processJar(String fileName) throws MalformedURLException, IOE */ public static IPath getWorkspaceLocation() { - IPath ws = ResourcesPlugin.getWorkspace().getRoot().getLocation(); - return ws; + return ResourcesPlugin.getWorkspace().getRoot().getLocation(); } /** @@ -254,4 +287,16 @@ public static void setUserWantsToDownloadTemplates(boolean userWantsToDownloadTe ResourcesPluginUtil.userWantsToDownloadTemplates = userWantsToDownloadTemplates; } + /** + * Upgrades the given template configuration. + * + * @param configurationPath path to the templates Configuration + */ + public static void startTemplatesUpgrader(Path configurationPath) { + + setTemplateSetPathAfterUpgrade(CobiGenFactory.startTemplatesUpgrader(configurationPath)); + + // FIXME after the upgrade adapt the new template-set folder. should be done in #1587 + } + } diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java index 0a6cb781d7..be0e80590e 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/GeneratorWrapperFactory.java @@ -1,6 +1,8 @@ package com.devonfw.cobigen.eclipse.generator; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Iterator; import java.util.List; @@ -11,7 +13,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.dialogs.MessageDialog; @@ -25,6 +26,8 @@ import org.slf4j.LoggerFactory; import com.devonfw.cobigen.api.CobiGen; +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.api.exception.DeprecatedMonolithicConfigurationException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.util.CobiGenPaths; import com.devonfw.cobigen.api.util.TemplatesJarUtil; @@ -43,33 +46,35 @@ /** * Generator creation factory, which creates a specific generator instance dependent on the current selection within the * eclipse IDE - * - * @author mbrunnli (03.12.2014) */ public class GeneratorWrapperFactory { /** Logger instance. */ private static final Logger LOG = LoggerFactory.getLogger(GeneratorWrapperFactory.class); + private static IProject generatorProj = null; + /** * Creates a generator dependent on the input of the selection * * @param selection current {@link IStructuredSelection} treated as input for generation * @param monitor tracking progress + * @param allowMonolithicConfiguration ignores deprecated monolithic template folder structure and if found does not + * throw a DeprecatedMonolithicConfigurationException * @return a specific {@link CobiGenWrapper} instance * @throws GeneratorCreationException if any exception occurred during converting the inputs or creating the generator * @throws GeneratorProjectNotExistentException if the generator configuration project does not exist * @throws InvalidInputException if the selection includes non supported input types or is composed in a non supported * combination of inputs. */ - public static CobiGenWrapper createGenerator(ISelection selection, IProgressMonitor monitor) + public static CobiGenWrapper createGenerator(ISelection selection, IProgressMonitor monitor, + boolean allowMonolithicConfiguration) throws GeneratorCreationException, GeneratorProjectNotExistentException, InvalidInputException { List extractedInputs = extractValidEclipseInputs(selection); - if (extractedInputs.size() > 0) { monitor.subTask("Initialize CobiGen instance"); - CobiGen cobigen = initializeGenerator(); + CobiGen cobigen = initializeGenerator(allowMonolithicConfiguration); monitor.subTask("Reading inputs..."); monitor.worked(10); @@ -207,40 +212,76 @@ else if (selection instanceof IStructuredSelection) { * @throws InvalidConfigurationException if the context configuration is not valid * @throws GeneratorCreationException if the generator configuration project does not exist */ - private static CobiGen initializeGenerator() throws InvalidConfigurationException, GeneratorCreationException { + private static CobiGen initializeGenerator(boolean allowMonolithicConfiguration) + throws InvalidConfigurationException, GeneratorCreationException { try { ResourcesPluginUtil.refreshConfigurationProject(); - IProject generatorProj = ResourcesPluginUtil.getGeneratorConfigurationProject(); + generatorProj = ResourcesPluginUtil.getGeneratorConfigurationProject(); - if (generatorProj == null) { - throw new GeneratorCreationException( - "Configuration source could not be read. Have you downloaded the templates?"); + return initializeCobiGen(generatorProj, allowMonolithicConfiguration); + } catch (CoreException e) { + throw new GeneratorCreationException("An eclipse internal exception occurred", e); + } catch (DeprecatedMonolithicConfigurationException e) { + if (null == generatorProj.getLocationURI()) + throw e; + else { + throw new DeprecatedMonolithicConfigurationException(Paths.get(generatorProj.getLocationURI())); } + } catch (Throwable e) { + throw new GeneratorCreationException( + "Configuration source could not be read.\nIf you were updating templates, it may mean" + + " that you have no internet connection,", + e); + } + } + + /** + * Initializes the {@link CobiGen} with the correct configuration, checks if template-sets exists, if not the Jar or + * generatorProj will be used. + * + * @param generatorProj the templates project + * @param allowMonolithicConfiguration ignores deprecated monolithic template folder structure and if found does not + * throw a DeprecatedMonolithicConfigurationException + * @return the configured{@link CobiGen} + * @throws if the generator configuration project does not exist + * + */ + private static CobiGen initializeCobiGen(IProject generatorProj, boolean allowMonolithicConfiguration) + throws GeneratorCreationException { - // We need to check whether it is a valid Java Project - IJavaProject configJavaProject = JavaCore.create(generatorProj); + Path templatesDirectoryPath = CobiGenPaths.getTemplateSetsFolderPath(); + Path templateSetsAdaptedFolderPath = templatesDirectoryPath.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Path templateSetsDownloadedFolderPath = templatesDirectoryPath.resolve(ConfigurationConstants.DOWNLOADED_FOLDER); - // If it is not valid, we should use the jar - if (null == generatorProj.getLocationURI() || !configJavaProject.exists()) { - File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile(); - File jarPath = TemplatesJarUtil.getJarFile(false, templatesDirectory); - boolean fileExists = jarPath.exists(); + if (ResourcesPluginUtil.getTemplateSetPathAfterUpgrade() != null) { + return CobiGenFactory.create(ResourcesPluginUtil.getTemplateSetPathAfterUpgrade().toUri(), + allowMonolithicConfiguration); + } + if (generatorProj == null) { + + // check adapted and downloaded folder + if (Files.exists(templateSetsAdaptedFolderPath) || Files.exists(templateSetsDownloadedFolderPath)) { + return CobiGenFactory.create(templatesDirectoryPath.toUri(), allowMonolithicConfiguration); + } + templatesDirectoryPath = CobiGenPaths.getTemplatesFolderPath(); + if (Files.exists(templatesDirectoryPath)) { + // If it is not valid, we should use the jar + Path jarPath = TemplatesJarUtil.getJarFile(false, templatesDirectoryPath); + boolean fileExists = (jarPath != null && Files.exists(jarPath)); if (!fileExists) { MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning", "Not Downloaded the CobiGen Template Jar"); } - return CobiGenFactory.create(jarPath.toURI()); - } else { - return CobiGenFactory.create(generatorProj.getLocationURI()); + return CobiGenFactory.create(jarPath.toUri(), allowMonolithicConfiguration); } - } catch (CoreException e) { - throw new GeneratorCreationException("An eclipse internal exception occurred", e); - } catch (Throwable e) { + } + if (generatorProj.getLocationURI() == null) { throw new GeneratorCreationException( - "Configuration source could not be read.\nIf you were updating templates, it may mean" - + " that you have no internet connection.", - e); + "Configuration source could not be read. Have you downloaded the templates?"); + } else { + return CobiGenFactory.create(generatorProj.getLocationURI(), allowMonolithicConfiguration); } } + } diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/generic/FileInputConverter.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/generic/FileInputConverter.java index e06e33fb5b..306b30d8c3 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/generic/FileInputConverter.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/generator/generic/FileInputConverter.java @@ -20,8 +20,6 @@ /** * Converts IDE selection objects to valid CobiGen inputs - * - * @author mbrunnli (06.12.2014) */ public class FileInputConverter { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/healthcheck/HealthCheckDialog.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/healthcheck/HealthCheckDialog.java index 146dac88bb..8e3466dabb 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/healthcheck/HealthCheckDialog.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/healthcheck/HealthCheckDialog.java @@ -1,6 +1,6 @@ package com.devonfw.cobigen.eclipse.healthcheck; -import java.io.File; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -16,6 +16,7 @@ import com.devonfw.cobigen.api.constants.BackupPolicy; import com.devonfw.cobigen.api.constants.ConfigurationConstants; import com.devonfw.cobigen.api.exception.ConfigurationConflictException; +import com.devonfw.cobigen.api.exception.DeprecatedMonolithicConfigurationException; import com.devonfw.cobigen.api.exception.InvalidConfigurationException; import com.devonfw.cobigen.api.to.HealthCheckReport; import com.devonfw.cobigen.api.util.CobiGenPaths; @@ -54,11 +55,23 @@ public HealthCheckDialog() { this.healthCheck = CobiGenFactory.createHealthCheck(); } + /** + * @see #execute(boolean) + */ + @SuppressWarnings("javadoc") + public void execute() { + + execute(false); + } + /** * Executes the simple health check, checking configuration project existence, validity of context configuration, as * well as validity of the current workbench selection as generation input. + * + * @param allowMonolithicConfiguration ignores deprecated monolithic template folder structure and if found does not + * throw a DeprecatedMonolithicConfigurationException */ - public void execute() { + public void execute(boolean allowMonolithicConfiguration) { String firstStep = "1. CobiGen configuration project '" + ResourceConstants.CONFIG_PROJECT_NAME + "'... "; String secondStep = "\n2. CobiGen context configuration '" + ConfigurationConstants.CONTEXT_CONFIG_FILENAME @@ -78,11 +91,13 @@ public void execute() { this.report = performHealthCheckReport(); if (generatorConfProj != null && generatorConfProj.getLocationURI() != null) { - CobiGenFactory.create(generatorConfProj.getLocationURI()); + + CobiGenFactory.create(generatorConfProj.getLocationURI(), allowMonolithicConfiguration); + } else { - File templatesDirectory = CobiGenPaths.getTemplatesFolderPath().toFile(); - File jarPath = TemplatesJarUtil.getJarFile(false, templatesDirectory); - boolean fileExists = jarPath.exists(); + Path templatesDirectoryPath = CobiGenPaths.getTemplatesFolderPath(); + Path jarPath = TemplatesJarUtil.getJarFile(false, templatesDirectoryPath); + boolean fileExists = (jarPath != null && Files.exists(jarPath)); if (!fileExists) { MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning", "Not Downloaded the CobiGen Template Jar"); @@ -133,7 +148,7 @@ public void execute() { @Override public void run() { - execute(); + execute(allowMonolithicConfiguration); } }); } @@ -149,6 +164,9 @@ public void run() { PlatformUIUtil.openErrorDialog(healthyCheckMessage, null); } LOG.warn(healthyCheckMessage, e); + } catch (DeprecatedMonolithicConfigurationException e) { + // TODO: Check what to do here, see: https://github.com/devonfw/cobigen/issues/1675 + throw e; } catch (Throwable e) { healthyCheckMessage = "An unexpected error occurred! Templates were not found."; if (this.report != null && healthyCheckMessage != null) { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/JavaClasspathUtil.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/JavaClasspathUtil.java index 77d3b10dc2..70118ec430 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/JavaClasspathUtil.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/JavaClasspathUtil.java @@ -13,7 +13,6 @@ /** * This util provides JDT classpath operations * - * @author Malte Brunnlieb * @version $Revision$ */ public class JavaClasspathUtil { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/ICompilationUnitStub.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/ICompilationUnitStub.java index d4238e271b..a17e589955 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/ICompilationUnitStub.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/ICompilationUnitStub.java @@ -24,8 +24,6 @@ /** * Stub for {@link ICompilationUnit} in order to simulate resources in the generate wizard - * - * @author mbrunnli (05.04.2014) */ @SuppressWarnings("deprecation") public class ICompilationUnitStub extends IJavaElementStub implements ICompilationUnit { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFileStub.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFileStub.java index 6f881fcf39..3409528fc1 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFileStub.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFileStub.java @@ -13,8 +13,6 @@ /** * Stub for {@link IFile} in order to simulate resources in the generate wizard - * - * @author mbrunnli (06.04.2014) */ public class IFileStub extends IResourceStub implements IFile { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFolderStub.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFolderStub.java index a15dc3957c..a3261e7cde 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFolderStub.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IFolderStub.java @@ -13,8 +13,6 @@ /** * Stub for {@link IFolder} in order to simulate resources in the generate wizard - * - * @author mbrunnli (06.04.2014) */ public class IFolderStub extends IResourceStub implements IFolder { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IPackageFragmentRootStub.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IPackageFragmentRootStub.java index e76de82661..fc1883d882 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IPackageFragmentRootStub.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/model/stubs/IPackageFragmentRootStub.java @@ -17,8 +17,6 @@ /** * Stub for {@link IPackageFragmentRoot} in order to simulate resources in the generate wizard - * - * @author mbrunnli (05.04.2014) */ public class IPackageFragmentRootStub implements IPackageFragmentRoot { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/widget/SimulatedCheckboxTreeViewer.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/widget/SimulatedCheckboxTreeViewer.java index 0fd77362a1..ead67fa160 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/widget/SimulatedCheckboxTreeViewer.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/wizard/common/widget/SimulatedCheckboxTreeViewer.java @@ -67,7 +67,6 @@ public boolean setChecked(Object element, boolean state) { * @param element to be checked * @return true if the element is currently visible
* false otherwise - * @author mbrunnli (12.03.2013) */ private boolean isVisible(Object element) { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/ConfigurationProjectListener.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/ConfigurationProjectListener.java index 8e7bacc804..6e310e1bdd 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/ConfigurationProjectListener.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/ConfigurationProjectListener.java @@ -18,8 +18,6 @@ * {@link ConfigurationProjectListener} for starting / stopping the {@link LogbackConfigChangeListener}. This class is * an abstract, due to the potential need of having multiple nested {@link IResourceChangeListener} for the CobiGen * configuration. - * - * @author mbrunnli (08.04.2013) */ public class ConfigurationProjectListener implements IResourceChangeListener { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateHandler.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateHandler.java index 938eec18bc..48132bd0b6 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateHandler.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateHandler.java @@ -18,8 +18,6 @@ /** * Handler for the Package-Explorer Event - * - * @author mbrunnli (13.02.2013) */ public class GenerateHandler extends AbstractHandler { diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateJob.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateJob.java index 9ae3340701..9695cd5414 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateJob.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/GenerateJob.java @@ -22,6 +22,7 @@ import com.devonfw.cobigen.eclipse.generator.GeneratorWrapperFactory; import com.devonfw.cobigen.eclipse.wizard.generate.GenerateBatchWizard; import com.devonfw.cobigen.eclipse.wizard.generate.GenerateWizard; +import com.devonfw.cobigen.impl.util.PostponeUtil; /** * @@ -59,13 +60,16 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte MDC.put(InfrastructureConstants.CORRELATION_ID, this.correlationId); - // when this handler is executed, we should we should be sure, that the selection is currently - // supported by the following implementation + // when this handler is executed, we should be sure, that the selection is currently supported by the following + // implementation try { LOG.info("Initiating CobiGen..."); monitor.beginTask("Initiating CobiGen...", 1); - CobiGenWrapper generator = GeneratorWrapperFactory.createGenerator(this.selection, monitor); + // TODO: Check this, see: https://github.com/devonfw/cobigen/issues/1679 + if (PostponeUtil.isTimePassed()) + checkMonolithicConfigurationException(monitor); + CobiGenWrapper generator = GeneratorWrapperFactory.createGenerator(this.selection, monitor, true); monitor.worked(1); if (generator == null) { LOG.error("Invalid selection. No CobiGen instance created. Exiting generate command."); @@ -109,4 +113,20 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte MDC.remove(InfrastructureConstants.CORRELATION_ID); } + /** + * Checks if monolithic configuration exists, handles the exception and lets the user decide if the templates should + * be upgraded. + * + * @param monitor of run method + */ + private void checkMonolithicConfigurationException(IProgressMonitor monitor) { + + try { + GeneratorWrapperFactory.createGenerator(this.selection, monitor, false); + } catch (Throwable e) { + ExceptionHandler.handle(e, HandlerUtil.getActiveShell(this.event)); + } + + } + } diff --git a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/HealthCheckHandler.java b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/HealthCheckHandler.java index 8218348617..0aba16dbc9 100644 --- a/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/HealthCheckHandler.java +++ b/cobigen-eclipse/cobigen-eclipse/src/com/devonfw/cobigen/eclipse/workbenchcontrol/handler/HealthCheckHandler.java @@ -28,13 +28,30 @@ public Object execute(final ExecutionEvent event) throws ExecutionException { MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString()); + checkMonolithicConfigurationException(event); try { - new HealthCheckDialog().execute(); + new HealthCheckDialog().execute(true); } catch (Throwable e) { ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event)); } - MDC.remove(InfrastructureConstants.CORRELATION_ID); return null; } + + /** + * checks if monolithic configuration exist, handles the exception and lets the user decide if the templates should be + * upgraded. + * + * @param event handler event executing this job. + * + */ + private void checkMonolithicConfigurationException(ExecutionEvent event) { + + try { + new HealthCheckDialog().execute(); + } catch (Throwable e) { + ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event)); + } + + } } diff --git a/cobigen-eclipse/pom.xml b/cobigen-eclipse/pom.xml index 2ec7ef8031..843c8c5424 100644 --- a/cobigen-eclipse/pom.xml +++ b/cobigen-eclipse/pom.xml @@ -5,25 +5,22 @@ eclipse-parent CobiGen - Eclipse Plug-In Parent pom - com.devonfw.cobigen master-parent ${revision} - https://oss.sonatype.org/content/groups/public/ - https://download.eclipse.org/releases/photon + + https://download.eclipse.org/releases/2018-12/ - cobigen-eclipse cobigen-eclipse-test cobigen-eclipse-feature cobigen-eclipse-updatesite - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}Ctos.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}Ctos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}Ctos.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}Ctos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/cobigen.properties b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/cobigen.properties rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcManage${variables.entityName}.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcManage${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcManage${variables.entityName}.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcManage${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl b/cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl rename to cobigen-templates/crud-java-server-app-complex/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl diff --git a/cobigen-templates/crud-java-server-app-complex/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppComplexTest.java b/cobigen-templates/crud-java-server-app-complex/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppComplexTest.java new file mode 100644 index 0000000000..c2bcaafac8 --- /dev/null +++ b/cobigen-templates/crud-java-server-app-complex/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppComplexTest.java @@ -0,0 +1,99 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudJavaServerAppComplexTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudJavaServerAppComplexTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath(); + + Path utilsPom = new File( + CrudJavaServerAppComplexTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an entity + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_EntityInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEntityInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } +} diff --git a/cobigen-templates/crud-java-server-app-complex/src/test/resources/application.properties b/cobigen-templates/crud-java-server-app-complex/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-java-server-app-complex/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-java-server-app-complex/src/test/resources/logback.xml b/cobigen-templates/crud-java-server-app-complex/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-java-server-app-complex/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml b/cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml b/cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml rename to cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java b/cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java rename to cobigen-templates/crud-java-server-app-complex/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java diff --git a/cobigen-templates/crud-java-server-app-complex/src/test/resources/utils/pom.xml b/cobigen-templates/crud-java-server-app-complex/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..2f59b21378 --- /dev/null +++ b/cobigen-templates/crud-java-server-app-complex/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-java-server-app-complex + 2021.12.007-SNAPSHOT + Crud Java Server App Complex + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-java-server-app/pom.xml b/cobigen-templates/crud-java-server-app/pom.xml new file mode 100644 index 0000000000..ba577e68e5 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-java-server-app + CRUD Java Server App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java new file mode 100644 index 0000000000..5376daaea9 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java @@ -0,0 +1,48 @@ +package com.devonfw.cobigen.templates.devon4j.constants; + +/** + * Contains the used keys for the pojo field mapping + */ +public enum Field { + + /** + * Name of the field + */ + NAME("name"), + /** + * Type of the field + */ + TYPE("type"), + /** + * Canonical Type of the field + */ + CANONICAL_TYPE("canonicalType"), + /** + * The Javadoc of the field + */ + JAVA_DOC("javaDoc"), + /** + * Annotations + */ + ANNOTATIONS("annotations"); + + /** + * key value + */ + private String value; + + /** + * @param value of the key + */ + Field(String value) { + + this.value = value; + } + + @Override + public String toString() { + + return this.value; + } + +} diff --git a/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java new file mode 100644 index 0000000000..4de413b930 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java @@ -0,0 +1,449 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.devonfw.cobigen.templates.devon4j.constants.Field; + +/** + * A class for shared devon4j specific functions in the templates + * + */ +@SuppressWarnings("restriction") +public class DevonfwUtil { + + /** + * Check whether the given 'canonicalType' is a devon4j Entity, which is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is a devon Entity + */ + public boolean isEntityInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format(".+%1$s\\.dataaccess\\.api\\.[A-Za-z0-9]+Entity(<.*)?", component)); + } + + /** + * Check whether the given 'canonicalType' is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is inside the given component + */ + public boolean isTypeInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format("%1$s.[A-Za-z0-9]+(<.*)?", component)); + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field, boolean byObjectReference, String component) { + + // If field comes from an UML file + if (field.getClass().toGenericString().contains("freemarker.ext.beans.HashAdapter")) { + return resolveIdGetter(field, byObjectReference, component); + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component) + "()"; + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * This method is used when the field parameter comes from an UML file. The name and type of the attributes must be + * pre-processed for later inserting them inside the HashMap. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Node field, boolean byObjectReference, String component) { + + HashMap nodeHash = new HashMap<>(); + + // Putting the name of the attribute to the hash + nodeHash.put(Field.NAME.toString(), field.getAttributes().getNamedItem("name")); + + // Putting the type of the attribute to the hash + NodeList childs = field.getChildNodes(); + for (int i = 0; i < childs.getLength(); i++) { + // Retrieve "type" tag + if (childs.item(i).getNodeName().equals("type")) { + NamedNodeMap attrs = childs.item(i).getAttributes(); + for (int j = 0; j < attrs.getLength(); j++) { + Attr attribute = (Attr) attrs.item(j); + // Try to find the attribute that contains the type + if (attribute.getName().equals("xmi:idref")) { + nodeHash.put(Field.TYPE.toString(), attribute.getName().replace("EAJava_", "")); + } + } + } + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(nodeHash, byObjectReference, true, component) + "()"; + + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "get" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component) + + "()"; + } + + /** + * same as {@link #resolveIdGetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field) { + + return this.resolveIdGetter(field, false, ""); + } + + /** + * same as {@link #resolveIdGetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdGetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field, boolean byObjectReference, String component) { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field) { + + return this.resolveIdSetter(field, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set'+ {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdSetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the variable name for the id value of the 'field' + * + * @param field the field + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + */ + public String resolveIdVariableName(Map field) { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(field, false, false, ""); + } + + /** + * Determines the variable name for the id value of the specified field in the pojo + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Class, Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableName(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, false, false, ""); + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param field the field + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if $byObjectReference is true + * @return idVariable name or getter/setter suffix + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Map field, boolean byObjectReference, + boolean capitalize, String component) { + + String fieldName = (String) field.get(Field.NAME.toString()); + if (capitalize) { + fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + } + String suffix = ""; + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldCType = (String) field.get(Field.CANONICAL_TYPE.toString()); + if (fieldType.contains("Entity")) { + if (fieldCType.startsWith("java.util.List") || fieldCType.startsWith("java.util.Set")) { + suffix = "Ids"; + if (fieldName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + fieldName = fieldName.substring(0, fieldName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference && isTypeInComponent(fieldCType, component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return fieldName + suffix; + + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if byObjectReference is true + * @return idVariable name or getter/setter suffix + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Class pojoClass, Map fieldMap, + boolean byObjectReference, boolean capitalize, String component) throws NoSuchFieldException, SecurityException { + + String resultName = (String) fieldMap.get(Field.NAME.toString()); + if (capitalize) { + resultName = resultName.substring(0, 1).toUpperCase() + resultName.substring(1); + } + String suffix = ""; + String fieldType = (String) fieldMap.get(Field.TYPE.toString()); + String fieldName = (String) fieldMap.get(Field.NAME.toString()); + if (fieldType.contains("Entity")) { + if (Collection.class.isAssignableFrom(pojoClass.getDeclaredField(fieldName).getType())) { + suffix = "Ids"; + if (resultName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + resultName = resultName.substring(0, resultName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference + && isEntityInComponent(pojoClass.getDeclaredField(fieldName).getType().getName(), component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return resultName + suffix; + + } + + /** + * Returns the argument type of the list or set from a field. If the string contains "Entity" it will remove that + * part. For example, if we have a List <SampleEntity> it will return "Sample" + * + * @param field the field + * @param pojoClass the object class of the Entity that contains the field + * @return fieldType argument of the list + * @throws SecurityException if field type could not accessed + * @throws NoSuchFieldException if field could not be found + */ + public String getListArgumentType(Map field, Class pojoClass) + throws NoSuchFieldException, SecurityException { + + JavaUtil javaUtil = new JavaUtil(); + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldName = (String) field.get(Field.NAME.toString()); + + if (fieldType.contains("Entity")) { + if (javaUtil.isCollection(pojoClass, fieldName)) { + + fieldType = fieldType.replace("Entity", ""); + // Regex: Extracts the argument type of the list 'List' => type + String regex = "(?<=\\<).+?(?=\\>)"; + Pattern pattern = Pattern.compile(regex); + Matcher regexMatcher = pattern.matcher(fieldType); + + if (regexMatcher.find()) { + fieldType = regexMatcher.group(0); + } + } + } + return fieldType; + + } + + /** + * Converts all occurrences of devon4j Entity types in the given 'field' simple type (possibly generic) to Longs + * + * @param field the field + * @return the field type as String. If field type contains 'Entity' the result is Long + */ + public String getSimpleEntityTypeAsLongReference(Map field) { + + String fieldType = (String) field.get(Field.TYPE.toString()); + if (fieldType.endsWith("Entity")) { + fieldType = fieldType.replaceAll("[^<>]+Entity", "Long"); + } + return fieldType; + } + + /** + * If the string last character is an 's', then it gets removed + * + * @param targetClassName string to remove plural + * @return string without 's' + */ + public String removePlural(String targetClassName) { + + if (targetClassName.charAt(targetClassName.length() - 1) == 's') { + targetClassName = targetClassName.substring(0, targetClassName.length() - 1); + } + return targetClassName; + } + + /** + * Checks whether the operation with the given ID corresponds to any standard CRUD method name. + * + * @param operationId operation ID interpreted as method name + * @param entityName entity name to check standard CRUD methods for + * @return true if the operation ID maps any standard CRUD method name, false otherwise + */ + public boolean isCrudOperation(String operationId, String entityName) { + + if (operationId == null) { + return false; + } + String opIdLowerCase = operationId.toLowerCase(); + String entityNameLowerCase = entityName.toLowerCase(); + if (opIdLowerCase.contains(entityNameLowerCase)) { + return opIdLowerCase.equals("find" + entityNameLowerCase) + || opIdLowerCase.equals("find" + entityNameLowerCase + "Etos") + || opIdLowerCase.equals("delete" + entityNameLowerCase) || opIdLowerCase.equals("save" + entityNameLowerCase); + } else { + return false; + } + } + + /** + * Converts the given media type to the spring Java enum value + * + * @param mediaType to be converted + * @return the spring enum value representing the given media type + */ + public String getSpringMediaType(String mediaType) { + + switch (mediaType) { + case "application/xml": + return "APPLICATION_XML_VALUE"; + case "application / x-www-form-urlencoded": + return "APPLICATION_FORM_URLENCODED_VALUE"; + case "multipart/form-data": + return "MULTIPART_FORM_DATA_VALUE"; + case "text/plain": + return "TEXT_PLAIN_VALUE"; + case "text/html": + return "TEXT_HTML_VALUE"; + case "application/pdf": + return "APPLICATION_PDF_VALUE"; + case "image/png": + return "IMAGE_PNG_VALUE"; + default: + return "APPLICATION_JSON_VALUE"; + } + } +} \ No newline at end of file diff --git a/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..ced2f5fde2 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/functions.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/functions.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/functions.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/functions.ftl diff --git a/cobigen-templates/crud-java-server-app/src/main/resources/template-set.xml b/cobigen-templates/crud-java-server-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..3f30e3a879 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/main/resources/template-set.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}SearchCriteriaTo.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}SearchCriteriaTo.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}SearchCriteriaTo.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}SearchCriteriaTo.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/common/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Entity.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Entity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Entity.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Entity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/cobigen.properties b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/cobigen.properties rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/cobigen.properties b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/cobigen.properties rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/dao/ApplicationDao.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/dao/ApplicationDao.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/dao/ApplicationDao.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/dao/ApplicationDao.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/base/dao/ApplicationDaoImpl.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/base/dao/ApplicationDaoImpl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/base/dao/ApplicationDaoImpl.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/base/dao/ApplicationDaoImpl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl b/cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl rename to cobigen-templates/crud-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl diff --git a/cobigen-templates/crud-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppGenerationTest.java b/cobigen-templates/crud-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppGenerationTest.java new file mode 100644 index 0000000000..8945626b9b --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudJavaServerAppGenerationTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudJavaServerAppGenerationTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudJavaServerAppGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File( + CrudJavaServerAppGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an entity + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_EntityInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEntityInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO, false); + } + +} diff --git a/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml new file mode 100644 index 0000000000..987f810bfd --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesEntityInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + + + + diff --git a/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java new file mode 100644 index 0000000000..e2d76c7c9f --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.dataaccess.api; + +public class InputEntity { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-templates/crud-java-server-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-java-server-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..3c3394ce26 --- /dev/null +++ b/cobigen-templates/crud-java-server-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-java-server-app + 2021.12.007-SNAPSHOT + CRUD Java Server App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-ngrx-client-app/pom.xml b/cobigen-templates/crud-ngrx-client-app/pom.xml new file mode 100644 index 0000000000..b5287e0cd5 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-ngrx-client-app + CRUD NGRX Client App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-ngrx-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-ngrx-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-ngrx-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-ngrx-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..2d4025071d --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/crud-ngrx-client-app/src/main/resources/template-set.xml b/cobigen-templates/crud-ngrx-client-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..f67beb2b39 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/main/resources/template-set.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/cobigen.properties b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/cobigen.properties rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/components/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/${variables.etoName#lower_case}.model.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/${variables.etoName#lower_case}.model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/${variables.etoName#lower_case}.model.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/${variables.etoName#lower_case}.model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/datadetailstest.model.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/datadetailstest.model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/datadetailstest.model.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/datadetailstest.model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/httpresponse.model.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/httpresponse.model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/httpresponse.model.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/httpresponse.model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/searchcriteriadata.model.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/searchcriteriadata.model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/models/searchcriteriadata.model.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/models/searchcriteriadata.model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/actions/${variables.etoName#lower_case}.actions.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/actions/${variables.etoName#lower_case}.actions.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/actions/${variables.etoName#lower_case}.actions.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/actions/${variables.etoName#lower_case}.actions.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/actions/actions_index.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/actions/actions_index.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/actions/actions_index.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/actions/actions_index.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.spec.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.spec.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/${variables.etoName#lower_case}.effects.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/effects_index.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/effects_index.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/effects/effects_index.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/effects/effects_index.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.spec.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.spec.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/${variables.etoName#lower_case}.reducers.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/reducers_index.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/reducers_index.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/reducers/reducers_index.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/reducers/reducers_index.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/selectors/${variables.etoName#lower_case}.selectors.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/selectors/${variables.etoName#lower_case}.selectors.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/selectors/${variables.etoName#lower_case}.selectors.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/selectors/${variables.etoName#lower_case}.selectors.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/selectors/selectors_index.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/selectors/selectors_index.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/selectors/selectors_index.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/selectors/selectors_index.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/store_index.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/store_index.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/${variables.etoName#lower_case}/store/store_index.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/store/store_index.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/app-routing.module.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/app-routing.module.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/layout/header/header.component.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/layout/header/header.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/layout/header/header.component.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/layout/header/header.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/assets/i18n/en.json.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/assets/i18n/en.json.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/assets/i18n/es.json.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/assets/i18n/es.json.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/environments/environment.prod.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/environments/environment.prod.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/environments/environment.ts.ftl b/cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/environments/environment.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_ngrx_client_app/templates/src/environments/environment.ts.ftl rename to cobigen-templates/crud-ngrx-client-app/src/main/resources/templates/src/environments/environment.ts.ftl diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudNgrxClientAppTest.java b/cobigen-templates/crud-ngrx-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudNgrxClientAppTest.java new file mode 100644 index 0000000000..f47b0c942d --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudNgrxClientAppTest.java @@ -0,0 +1,98 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudNgrxClientAppTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File(CrudNgrxClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File(CrudNgrxClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_EtoInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEtoInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/application.properties b/cobigen-templates/crud-ngrx-client-app/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/logback.xml b/cobigen-templates/crud-ngrx-client-app/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml new file mode 100644 index 0000000000..68371aa12b --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesEtoInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java new file mode 100644 index 0000000000..21ad4eeba9 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.logic.api.to; + +public class InputEto { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-templates/crud-ngrx-client-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-ngrx-client-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..ee099cf3c6 --- /dev/null +++ b/cobigen-templates/crud-ngrx-client-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-ngrx-client-app + 2021.12.007-SNAPSHOT + Crud Ngrx Client App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-client-app/pom.xml b/cobigen-templates/crud-openapi-angular-client-app/pom.xml new file mode 100644 index 0000000000..f9f6d93770 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-openapi-angular-client-app + CRUD OpenApi Angular Client App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-openapi-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-openapi-angular-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..ced2f5fde2 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java b/cobigen-templates/crud-openapi-angular-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java rename to cobigen-templates/crud-openapi-angular-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/template-set.xml b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..bd2640a935 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/template-set.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/cobigen.properties b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/cobigen.properties rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-alert/${variables.etoName#lower_case}-alert.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.spec.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.spec.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-dialog/${variables.etoName#lower_case}-dialog.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.spec.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.spec.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-grid/${variables.etoName#lower_case}-grid.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/${variables.etoName#lower_case}.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/${variables.etoName#lower_case}/services/${variables.etoName#lower_case}.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/app-routing.module.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/app-routing.module.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/app.module.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/app.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/app.module.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/app.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/home/home.component.html.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/home/home.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/home/home.component.html.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/home/home.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/layout/nav-bar/nav-bar.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/model/${variables.etoName#lower_case}.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/model/${variables.etoName#lower_case}.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/model/${variables.etoName#lower_case}.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/model/${variables.etoName#lower_case}.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/model/model.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/model/model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/app/model/model.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/app/model/model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/assets/i18n/en.json.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/assets/i18n/en.json.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/assets/i18n/es.json.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/assets/i18n/es.json.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/environments/environment.prod.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/environments/environment.prod.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/environments/environment.ts.ftl b/cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/environments/environment.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_client_app/templates/src/environments/environment.ts.ftl rename to cobigen-templates/crud-openapi-angular-client-app/src/main/resources/templates/src/environments/environment.ts.ftl diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularClientAppTest.java b/cobigen-templates/crud-openapi-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularClientAppTest.java new file mode 100644 index 0000000000..28302c4458 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularClientAppTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudOpenapiAngularClientAppTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudOpenapiAngularClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File( + CrudOpenapiAngularClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/application.properties b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/logback.xml b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml rename to cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml rename to cobigen-templates/crud-openapi-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml diff --git a/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..d600eb559a --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-client-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-openapi-angular-client-app + 2021.12.007-SNAPSHOT + Crud Openapi Angular Client App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/pom.xml b/cobigen-templates/crud-openapi-angular-service-based-app/pom.xml new file mode 100644 index 0000000000..cf6571b0d4 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + crud-openapi-angular-service-based-app + CRUD OpenAPI Angular Service Based App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/template-set.xml b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..c4a3b7af7b --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/template-set.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/cobigen.properties b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/cobigen.properties rename to cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/app/api/${variables.component#lower_case}/${variables.component#lower_case}RestController.service.ts.ftl b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/app/api/${variables.component#lower_case}/${variables.component#lower_case}RestController.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/app/api/${variables.component#lower_case}/${variables.component#lower_case}RestController.service.ts.ftl rename to cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/app/api/${variables.component#lower_case}/${variables.component#lower_case}RestController.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/app/api/api.ts.ftl b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/app/api/api.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/app/api/api.ts.ftl rename to cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/app/api/api.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.prod.ts.ftl b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_angular_service_based_app/templates/src/environments/environment.prod.ts.ftl rename to cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/environments/environment.ts.ftl b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/environments/environment.ts.ftl new file mode 100644 index 0000000000..c311b61aca --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/main/resources/templates/src/environments/environment.ts.ftl @@ -0,0 +1,11 @@ +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `angular-cli.json`. + +export const environment = { + production: false, + restPathRoot: 'http://localhost:8081/${variables.domain}-server/', + restServiceRoot: 'http://localhost:8081/${variables.domain}-server/services/rest/', + security: 'csrf', +}; diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularServiceBasedAppTest.java b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularServiceBasedAppTest.java new file mode 100644 index 0000000000..26d650b2b4 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiAngularServiceBasedAppTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudOpenapiAngularServiceBasedAppTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudOpenapiAngularServiceBasedAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File( + CrudOpenapiAngularServiceBasedAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/application.properties b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/logback.xml b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml new file mode 100644 index 0000000000..14b9ec10cf --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml @@ -0,0 +1,131 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.demo +paths: + /datamanagement/v1/someData/{id}: + get: + operationId: findSomeData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/EvenMoreData' + text/plain: + schema: + type: string + /datamanagement/v1/moreData/{id}: + get: + operationId: findMoreData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 10 + maximum: 200 + responses: + '200': + description: Any + /datamanagement/v1/someData/: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SomeData' + tags: + - searchCriteria + /datamanagement/v1/moreData/validateMoreData: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/MoreData' +components: + schemas: + SomeData: + x-component: DataManagement + description: Entity definiton of SomeData + type: object + properties: + AnyString: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + furtherData: + type: array + items: + $ref: '#/components/schemas/FurtherData' + MoreData: + x-component: DataManagement + description: Entity definiton of Moredata + type: object + properties: + anyNumber: + type: number + format: int64 + maximum: 100 + minimum: 0 + someData: + $ref: '#/components/schemas/SomeData' + allSomeData: + type: array + description: 'All SomeData' + items: + $ref: '#/components/schemas/SomeData' + required: + - saleExample + FurtherData: + x-component: AnotherComponent + type: object + properties: + parent: + $ref: '#/components/schemas/SomeData' + valid: + type: boolean + someList: + type: array + items: + type: string + EvenMoreData: + x-component: AnotherComponent + description: Entity definiton of more data + type: object + properties: + id: + type: integer + format: int64 + uniqueItems: true + requestBodies: + SomeData: + content: + application/json: + schema: + $ref: '#/components/schemas/SomeData' + required: true + MoreData: + content: + application/json: + schema: + $ref: '#/components/schemas/MoreData' + required: true diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml new file mode 100644 index 0000000000..7f84fdeef0 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesOpenAPIInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + OpenAPI.yaml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..9a33c5c4f2 --- /dev/null +++ b/cobigen-templates/crud-openapi-angular-service-based-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-openapi-angular-service-based-app + 2021.12.007-SNAPSHOT + Crud OpenApi Angular Service Based App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-ionic-client-app/pom.xml b/cobigen-templates/crud-openapi-ionic-client-app/pom.xml new file mode 100644 index 0000000000..fbfd00fd3f --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-openapi-ionic-client-app + CRUD OpenAPI Ionic Client App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-openapi-ionic-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-openapi-ionic-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..ced2f5fde2 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/template-set.xml b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..cbd540239e --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/template-set.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/cobigen.properties b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/cobigen.properties old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/cobigen.properties rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app-routing.module.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app-routing.module.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app.component.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app.component.ts.ftl old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app.component.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app.module.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app.module.ts.ftl old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/app.module.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/app.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.html.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.html.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.scss.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.scss.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.scss.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.scss.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-detail/${variables.etoName#lower_case}-detail.page.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.html.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.html.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.scss.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.scss.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.scss.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.scss.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/pages/${variables.etoName#lower_case}-list/${variables.etoName#lower_case}-list.page.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/${variables.etoName#lower_case}-rest.service.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/${variables.etoName#lower_case}-rest.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/${variables.etoName#lower_case}-rest.service.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/${variables.etoName#lower_case}-rest.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/${variables.etoName#lower_case}-search-criteria.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/${variables.etoName#lower_case}-search-criteria.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/${variables.etoName#lower_case}-search-criteria.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/${variables.etoName#lower_case}-search-criteria.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/${variables.etoName#lower_case}.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/${variables.etoName#lower_case}.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/${variables.etoName#lower_case}.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/${variables.etoName#lower_case}.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/pageable.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/pageable.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/pageable.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/pageable.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/paginated-list-to.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/paginated-list-to.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/paginated-list-to.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/paginated-list-to.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/sort.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/sort.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/interfaces/sort.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/interfaces/sort.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/shared/business-operator.service.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/shared/business-operator.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/app/services/shared/business-operator.service.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/app/services/shared/business-operator.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/en.json.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/en.json.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/es.json.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/es.json.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/it.json.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/it.json.ftl old mode 100755 new mode 100644 similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/assets/i18n/it.json.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/assets/i18n/it.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.android.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.android.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.android.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.android.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.prod.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.prod.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.ts.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/environments/environment.ts.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/environments/environment.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/theme/variables.scss.ftl b/cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/theme/variables.scss.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_ionic_client_app/templates/src/theme/variables.scss.ftl rename to cobigen-templates/crud-openapi-ionic-client-app/src/main/resources/templates/src/theme/variables.scss.ftl diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiIonicClientAppTest.java b/cobigen-templates/crud-openapi-ionic-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiIonicClientAppTest.java new file mode 100644 index 0000000000..32051623e8 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenapiIonicClientAppTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudOpenapiIonicClientAppTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudOpenapiIonicClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath(); + + Path utilsPom = new File( + CrudOpenapiIonicClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/application.properties b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/logback.xml b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml new file mode 100644 index 0000000000..14b9ec10cf --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml @@ -0,0 +1,131 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.demo +paths: + /datamanagement/v1/someData/{id}: + get: + operationId: findSomeData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/EvenMoreData' + text/plain: + schema: + type: string + /datamanagement/v1/moreData/{id}: + get: + operationId: findMoreData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 10 + maximum: 200 + responses: + '200': + description: Any + /datamanagement/v1/someData/: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SomeData' + tags: + - searchCriteria + /datamanagement/v1/moreData/validateMoreData: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/MoreData' +components: + schemas: + SomeData: + x-component: DataManagement + description: Entity definiton of SomeData + type: object + properties: + AnyString: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + furtherData: + type: array + items: + $ref: '#/components/schemas/FurtherData' + MoreData: + x-component: DataManagement + description: Entity definiton of Moredata + type: object + properties: + anyNumber: + type: number + format: int64 + maximum: 100 + minimum: 0 + someData: + $ref: '#/components/schemas/SomeData' + allSomeData: + type: array + description: 'All SomeData' + items: + $ref: '#/components/schemas/SomeData' + required: + - saleExample + FurtherData: + x-component: AnotherComponent + type: object + properties: + parent: + $ref: '#/components/schemas/SomeData' + valid: + type: boolean + someList: + type: array + items: + type: string + EvenMoreData: + x-component: AnotherComponent + description: Entity definiton of more data + type: object + properties: + id: + type: integer + format: int64 + uniqueItems: true + requestBodies: + SomeData: + content: + application/json: + schema: + $ref: '#/components/schemas/SomeData' + required: true + MoreData: + content: + application/json: + schema: + $ref: '#/components/schemas/MoreData' + required: true diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml new file mode 100644 index 0000000000..7f84fdeef0 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesOpenAPIInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + OpenAPI.yaml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..9e540cd237 --- /dev/null +++ b/cobigen-templates/crud-openapi-ionic-client-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-openapi-ionic-client-app + 2021.12.007-SNAPSHOT + Crud Openapi Ionic Client App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-java-server-app/pom.xml b/cobigen-templates/crud-openapi-java-server-app/pom.xml new file mode 100644 index 0000000000..9d845790e1 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-openapi-java-server-app + CRUD OpenAPI Java Server App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-openapi-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java new file mode 100644 index 0000000000..5376daaea9 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java @@ -0,0 +1,48 @@ +package com.devonfw.cobigen.templates.devon4j.constants; + +/** + * Contains the used keys for the pojo field mapping + */ +public enum Field { + + /** + * Name of the field + */ + NAME("name"), + /** + * Type of the field + */ + TYPE("type"), + /** + * Canonical Type of the field + */ + CANONICAL_TYPE("canonicalType"), + /** + * The Javadoc of the field + */ + JAVA_DOC("javaDoc"), + /** + * Annotations + */ + ANNOTATIONS("annotations"); + + /** + * key value + */ + private String value; + + /** + * @param value of the key + */ + Field(String value) { + + this.value = value; + } + + @Override + public String toString() { + + return this.value; + } + +} diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java new file mode 100644 index 0000000000..4de413b930 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java @@ -0,0 +1,449 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.devonfw.cobigen.templates.devon4j.constants.Field; + +/** + * A class for shared devon4j specific functions in the templates + * + */ +@SuppressWarnings("restriction") +public class DevonfwUtil { + + /** + * Check whether the given 'canonicalType' is a devon4j Entity, which is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is a devon Entity + */ + public boolean isEntityInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format(".+%1$s\\.dataaccess\\.api\\.[A-Za-z0-9]+Entity(<.*)?", component)); + } + + /** + * Check whether the given 'canonicalType' is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is inside the given component + */ + public boolean isTypeInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format("%1$s.[A-Za-z0-9]+(<.*)?", component)); + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field, boolean byObjectReference, String component) { + + // If field comes from an UML file + if (field.getClass().toGenericString().contains("freemarker.ext.beans.HashAdapter")) { + return resolveIdGetter(field, byObjectReference, component); + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component) + "()"; + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * This method is used when the field parameter comes from an UML file. The name and type of the attributes must be + * pre-processed for later inserting them inside the HashMap. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Node field, boolean byObjectReference, String component) { + + HashMap nodeHash = new HashMap<>(); + + // Putting the name of the attribute to the hash + nodeHash.put(Field.NAME.toString(), field.getAttributes().getNamedItem("name")); + + // Putting the type of the attribute to the hash + NodeList childs = field.getChildNodes(); + for (int i = 0; i < childs.getLength(); i++) { + // Retrieve "type" tag + if (childs.item(i).getNodeName().equals("type")) { + NamedNodeMap attrs = childs.item(i).getAttributes(); + for (int j = 0; j < attrs.getLength(); j++) { + Attr attribute = (Attr) attrs.item(j); + // Try to find the attribute that contains the type + if (attribute.getName().equals("xmi:idref")) { + nodeHash.put(Field.TYPE.toString(), attribute.getName().replace("EAJava_", "")); + } + } + } + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(nodeHash, byObjectReference, true, component) + "()"; + + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "get" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component) + + "()"; + } + + /** + * same as {@link #resolveIdGetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field) { + + return this.resolveIdGetter(field, false, ""); + } + + /** + * same as {@link #resolveIdGetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdGetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field, boolean byObjectReference, String component) { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field) { + + return this.resolveIdSetter(field, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set'+ {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdSetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the variable name for the id value of the 'field' + * + * @param field the field + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + */ + public String resolveIdVariableName(Map field) { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(field, false, false, ""); + } + + /** + * Determines the variable name for the id value of the specified field in the pojo + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Class, Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableName(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, false, false, ""); + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param field the field + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if $byObjectReference is true + * @return idVariable name or getter/setter suffix + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Map field, boolean byObjectReference, + boolean capitalize, String component) { + + String fieldName = (String) field.get(Field.NAME.toString()); + if (capitalize) { + fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + } + String suffix = ""; + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldCType = (String) field.get(Field.CANONICAL_TYPE.toString()); + if (fieldType.contains("Entity")) { + if (fieldCType.startsWith("java.util.List") || fieldCType.startsWith("java.util.Set")) { + suffix = "Ids"; + if (fieldName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + fieldName = fieldName.substring(0, fieldName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference && isTypeInComponent(fieldCType, component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return fieldName + suffix; + + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if byObjectReference is true + * @return idVariable name or getter/setter suffix + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Class pojoClass, Map fieldMap, + boolean byObjectReference, boolean capitalize, String component) throws NoSuchFieldException, SecurityException { + + String resultName = (String) fieldMap.get(Field.NAME.toString()); + if (capitalize) { + resultName = resultName.substring(0, 1).toUpperCase() + resultName.substring(1); + } + String suffix = ""; + String fieldType = (String) fieldMap.get(Field.TYPE.toString()); + String fieldName = (String) fieldMap.get(Field.NAME.toString()); + if (fieldType.contains("Entity")) { + if (Collection.class.isAssignableFrom(pojoClass.getDeclaredField(fieldName).getType())) { + suffix = "Ids"; + if (resultName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + resultName = resultName.substring(0, resultName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference + && isEntityInComponent(pojoClass.getDeclaredField(fieldName).getType().getName(), component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return resultName + suffix; + + } + + /** + * Returns the argument type of the list or set from a field. If the string contains "Entity" it will remove that + * part. For example, if we have a List <SampleEntity> it will return "Sample" + * + * @param field the field + * @param pojoClass the object class of the Entity that contains the field + * @return fieldType argument of the list + * @throws SecurityException if field type could not accessed + * @throws NoSuchFieldException if field could not be found + */ + public String getListArgumentType(Map field, Class pojoClass) + throws NoSuchFieldException, SecurityException { + + JavaUtil javaUtil = new JavaUtil(); + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldName = (String) field.get(Field.NAME.toString()); + + if (fieldType.contains("Entity")) { + if (javaUtil.isCollection(pojoClass, fieldName)) { + + fieldType = fieldType.replace("Entity", ""); + // Regex: Extracts the argument type of the list 'List' => type + String regex = "(?<=\\<).+?(?=\\>)"; + Pattern pattern = Pattern.compile(regex); + Matcher regexMatcher = pattern.matcher(fieldType); + + if (regexMatcher.find()) { + fieldType = regexMatcher.group(0); + } + } + } + return fieldType; + + } + + /** + * Converts all occurrences of devon4j Entity types in the given 'field' simple type (possibly generic) to Longs + * + * @param field the field + * @return the field type as String. If field type contains 'Entity' the result is Long + */ + public String getSimpleEntityTypeAsLongReference(Map field) { + + String fieldType = (String) field.get(Field.TYPE.toString()); + if (fieldType.endsWith("Entity")) { + fieldType = fieldType.replaceAll("[^<>]+Entity", "Long"); + } + return fieldType; + } + + /** + * If the string last character is an 's', then it gets removed + * + * @param targetClassName string to remove plural + * @return string without 's' + */ + public String removePlural(String targetClassName) { + + if (targetClassName.charAt(targetClassName.length() - 1) == 's') { + targetClassName = targetClassName.substring(0, targetClassName.length() - 1); + } + return targetClassName; + } + + /** + * Checks whether the operation with the given ID corresponds to any standard CRUD method name. + * + * @param operationId operation ID interpreted as method name + * @param entityName entity name to check standard CRUD methods for + * @return true if the operation ID maps any standard CRUD method name, false otherwise + */ + public boolean isCrudOperation(String operationId, String entityName) { + + if (operationId == null) { + return false; + } + String opIdLowerCase = operationId.toLowerCase(); + String entityNameLowerCase = entityName.toLowerCase(); + if (opIdLowerCase.contains(entityNameLowerCase)) { + return opIdLowerCase.equals("find" + entityNameLowerCase) + || opIdLowerCase.equals("find" + entityNameLowerCase + "Etos") + || opIdLowerCase.equals("delete" + entityNameLowerCase) || opIdLowerCase.equals("save" + entityNameLowerCase); + } else { + return false; + } + } + + /** + * Converts the given media type to the spring Java enum value + * + * @param mediaType to be converted + * @return the spring enum value representing the given media type + */ + public String getSpringMediaType(String mediaType) { + + switch (mediaType) { + case "application/xml": + return "APPLICATION_XML_VALUE"; + case "application / x-www-form-urlencoded": + return "APPLICATION_FORM_URLENCODED_VALUE"; + case "multipart/form-data": + return "MULTIPART_FORM_DATA_VALUE"; + case "text/plain": + return "TEXT_PLAIN_VALUE"; + case "text/html": + return "TEXT_HTML_VALUE"; + case "application/pdf": + return "APPLICATION_PDF_VALUE"; + case "image/png": + return "IMAGE_PNG_VALUE"; + default: + return "APPLICATION_JSON_VALUE"; + } + } +} \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..ced2f5fde2 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java new file mode 100644 index 0000000000..a93288f45a --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java @@ -0,0 +1,255 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.Instant; +import java.time.LocalDate; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; + +/** Utils on OpenAPI template model */ +public class OpenApiUtil { + + /** + * Prints javax validation constraints from an OpenAPI model + * + * @param constraints OpenAPI model constraints + * @return the list of supported annotations in Java syntax + */ + public String printJavaConstraints(Map constraints) { + + String consts = ""; + if (constraints.get("maximum") != null) { + consts = consts + "@Max(" + constraints.get("maximum") + ")"; + } + if (constraints.get("minimum") != null) { + consts = consts + "@Min(" + constraints.get("minimum") + ")"; + } + if (constraints.get("maxLength") != null) { + consts = consts + "@Size(max=" + constraints.get("maxLength"); + if (constraints.get("minLength") != null) { + consts = consts + ", min=" + constraints.get("minLength"); + } + consts = consts + ")"; + } else { + if (constraints.get("minLength") != null) { + consts = consts + "@Size(min=" + constraints.get("minLength"); + if (constraints.get("maxLength") != null) { + consts = consts + ", max=" + constraints.get("maxLength"); + } + consts = consts + ")"; + } + } + return consts; + } + + /** + * Prints the return type of a response based on the OpenAPI model + * + * @param response the OpenAPI model of a response + * @return simple type of the response return type in Java syntax + */ + public String printJavaServiceResponseReturnType(Map response) { + + String returnType = toJavaType(response, false); + if ((boolean) response.get("isVoid")) { + return "void"; + } + if ((boolean) response.get("isArray")) { + if ((boolean) response.get("isEntity")) { + if (returnType.contains("Entity")) { + return "List<" + returnType + ">"; + } else { + return "List<" + returnType + "Entity>"; + } + } else { + return "List<" + returnType + ">"; + } + } else if ((boolean) response.get("isPaginated")) { + if ((boolean) response.get("isEntity")) { + if (returnType.contains("Entity")) { + return "Page<" + returnType + ">"; + } else { + return "Page<" + returnType + "Entity>"; + } + } else { + return "Page<" + returnType + ">"; + } + } else { + return returnType; + } + } + + /** + * Returns the Java type corresponding to the OpenAPI type definition. If the type could not be matched, Object will + * be returned. + * + * @param parameter OpenAPI model of a parameter + * @param simpleType if a Java simple type should be returned if possible + * @return the Java type + */ + public String toJavaType(Map parameter, boolean simpleType) { + + String typeConverted = null; + String format = (String) parameter.get("format"); + String type = (String) parameter.get("type"); + boolean isCollection = false; + if (parameter.get("isCollection") != null) { + isCollection = (boolean) parameter.get("isCollection"); + } + + boolean isEntity = (boolean) parameter.get("isEntity"); + + if (type != null) { + switch (type.toLowerCase()) { + case "integer": + if (format != null) { + switch (format) { + case "int32": + typeConverted = simpleType ? "int" : "Integer"; + break; + case "int64": + typeConverted = simpleType ? "long" : "Long"; + break; + default: + typeConverted = BigInteger.class.getSimpleName(); + break; + } + } else { + typeConverted = BigInteger.class.getSimpleName(); + } + break; + case "number": + if (format != null) { + switch (format) { + case "float": + typeConverted = simpleType ? "float" : "Float"; + break; + case "double": + typeConverted = simpleType ? "double" : "Double"; + break; + default: + typeConverted = BigDecimal.class.getSimpleName(); + break; + } + } else { + typeConverted = BigDecimal.class.getSimpleName(); + } + break; + case "string": + if (format != null) { + switch (format) { + case "date": + typeConverted = LocalDate.class.getSimpleName(); + break; + case "date-time": + typeConverted = Instant.class.getSimpleName(); + break; + case "binary": + typeConverted = simpleType ? "float" : "Float"; + break; + case "email": + case "password": + typeConverted = String.class.getSimpleName(); + break; + default: + typeConverted = "String"; + break; + } + } else { + typeConverted = "String"; + } + break; + case "boolean": + typeConverted = simpleType ? "boolean" : "Boolean"; + break; + default: + typeConverted = "void"; + break; + } + } else { + typeConverted = "void"; + } + + if (isCollection) { + if (isEntity) { + return "List<" + parameter.get("type") + ">"; + } else { + return "List<" + typeConverted + ">"; + } + } else if (isEntity) { + return (String) parameter.get("type"); + } + return typeConverted; + } + + /** + * Returns the TypeScript type corresponding to the OpenAPI type definition. If the type could not be matched, the + * same value will be returned. + * + * @param parameter OpenAPI model of a parameter + * @return the Java type + */ + // getOaspTypeFromOpenAPI + public String toTypeScriptType(Map parameter) { + + String typeConverted = null; + String type = (String) parameter.get("type"); + boolean isCollection = false; + if (parameter.get("isCollection") != null) { + isCollection = (boolean) parameter.get("isCollection"); + } + + boolean isEntity = (boolean) parameter.get("isEntity"); + + if (type != null) { + switch (type.toLowerCase()) { + case "integer": + typeConverted = "number"; + break; + default: + typeConverted = type; + break; + } + } else { + typeConverted = "undefined"; + } + + if (isCollection) { + if (isEntity) { + return parameter.get("type") + "[]"; + } else { + return typeConverted + "[]"; + } + } else if (isEntity) { + return (String) parameter.get("type"); + } + return typeConverted; + } + + /** + * Prints the service operation name based on the operationId or generates one based on the servicePath while printing + * a comment how to get better service names. + * + * @param operation operation Model of the OpenAPI model + * @param servicePath service path of the + * @return the service method name + */ + public String printServiceOperationName(Map operation, String servicePath) { + + String operationId = (String) operation.get("operationId"); + if (StringUtils.isEmpty(operationId)) { + String[] split = servicePath.split("/"); + String lastSegment; + if (!split[split.length - 1].isEmpty()) { + lastSegment = split[split.length - 1]; + } else { + lastSegment = split[split.length - 2]; + } + return ((String) operation.get("type")) + lastSegment; + } else { + return operationId; + } + } +} diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/functions.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/functions.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/functions.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/functions.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/makros.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/makros.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/makros.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/makros.ftl diff --git a/cobigen-templates/crud-openapi-java-server-app/src/main/resources/template-set.xml b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..e91923bf07 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/template-set.xml @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/${variables.entityName}.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/${variables.entityName}.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/cobigen.properties b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/cobigen.properties rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/common/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/${variables.entityName}Entity.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/${variables.entityName}Entity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/${variables.entityName}Entity.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/${variables.entityName}Entity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/dataaccess/api/repo/${variables.entityName}Repository.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}Ctos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}Ctos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}Ctos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/${variables.component#cap_first}Ctos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/cobigen.properties b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/cobigen.properties rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Cto.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Cto.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Cto.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Cto.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Eto.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Eto.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Eto.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}Eto.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcFind${variables.entityName}Ctos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcManage${variables.entityName}.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcManage${variables.entityName}.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcManage${variables.entityName}.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/api/usecase/UcManage${variables.entityName}.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}Impl.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}Impl.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/${variables.component#cap_first}ImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcFind${variables.entityName}ImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/cobigen.properties b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/cobigen.properties rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestService.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestService.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestService.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestService.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/api/rest/${variables.component#cap_first}RestServiceCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/${variables.component#lower_case}/service/impl/rest/${variables.component#cap_first}RestServiceImplCtos.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/AbstractSearchCriteriaTo.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/api/to/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractLogic.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl b/cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl rename to cobigen-templates/crud-openapi-java-server-app/src/main/resources/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl diff --git a/cobigen-templates/crud-openapi-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiJavaServerAppGenerationTest.java b/cobigen-templates/crud-openapi-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiJavaServerAppGenerationTest.java new file mode 100644 index 0000000000..635086e78c --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiJavaServerAppGenerationTest.java @@ -0,0 +1,99 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudOpenApiJavaServerAppGenerationTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudOpenApiJavaServerAppGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath(); + + Path utilsPom = new File(CrudOpenApiJavaServerAppGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml new file mode 100644 index 0000000000..14b9ec10cf --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml @@ -0,0 +1,131 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.demo +paths: + /datamanagement/v1/someData/{id}: + get: + operationId: findSomeData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/EvenMoreData' + text/plain: + schema: + type: string + /datamanagement/v1/moreData/{id}: + get: + operationId: findMoreData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 10 + maximum: 200 + responses: + '200': + description: Any + /datamanagement/v1/someData/: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SomeData' + tags: + - searchCriteria + /datamanagement/v1/moreData/validateMoreData: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/MoreData' +components: + schemas: + SomeData: + x-component: DataManagement + description: Entity definiton of SomeData + type: object + properties: + AnyString: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + furtherData: + type: array + items: + $ref: '#/components/schemas/FurtherData' + MoreData: + x-component: DataManagement + description: Entity definiton of Moredata + type: object + properties: + anyNumber: + type: number + format: int64 + maximum: 100 + minimum: 0 + someData: + $ref: '#/components/schemas/SomeData' + allSomeData: + type: array + description: 'All SomeData' + items: + $ref: '#/components/schemas/SomeData' + required: + - saleExample + FurtherData: + x-component: AnotherComponent + type: object + properties: + parent: + $ref: '#/components/schemas/SomeData' + valid: + type: boolean + someList: + type: array + items: + type: string + EvenMoreData: + x-component: AnotherComponent + description: Entity definiton of more data + type: object + properties: + id: + type: integer + format: int64 + uniqueItems: true + requestBodies: + SomeData: + content: + application/json: + schema: + $ref: '#/components/schemas/SomeData' + required: true + MoreData: + content: + application/json: + schema: + $ref: '#/components/schemas/MoreData' + required: true diff --git a/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml new file mode 100644 index 0000000000..7f84fdeef0 --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesOpenAPIInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + OpenAPI.yaml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/crud-openapi-java-server-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..95c84448de --- /dev/null +++ b/cobigen-templates/crud-openapi-java-server-app/src/test/resources/utils/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-openapi-java-server-app + 2021.12.007-SNAPSHOT + CRUD OpenApi Java Server App + A Code-based incremental Generator + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-net/pom.xml b/cobigen-templates/crud-openapi-net/pom.xml new file mode 100644 index 0000000000..ddd28d9c64 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + crud-openapi-net + CRUD OpenAPI Net template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + org.apache.commons + commons-lang3 + + + \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-net/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-openapi-net/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java new file mode 100644 index 0000000000..5376daaea9 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/constants/Field.java @@ -0,0 +1,48 @@ +package com.devonfw.cobigen.templates.devon4j.constants; + +/** + * Contains the used keys for the pojo field mapping + */ +public enum Field { + + /** + * Name of the field + */ + NAME("name"), + /** + * Type of the field + */ + TYPE("type"), + /** + * Canonical Type of the field + */ + CANONICAL_TYPE("canonicalType"), + /** + * The Javadoc of the field + */ + JAVA_DOC("javaDoc"), + /** + * Annotations + */ + ANNOTATIONS("annotations"); + + /** + * key value + */ + private String value; + + /** + * @param value of the key + */ + Field(String value) { + + this.value = value; + } + + @Override + public String toString() { + + return this.value; + } + +} diff --git a/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java new file mode 100644 index 0000000000..4de413b930 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/DevonfwUtil.java @@ -0,0 +1,449 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.w3c.dom.Attr; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.devonfw.cobigen.templates.devon4j.constants.Field; + +/** + * A class for shared devon4j specific functions in the templates + * + */ +@SuppressWarnings("restriction") +public class DevonfwUtil { + + /** + * Check whether the given 'canonicalType' is a devon4j Entity, which is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is a devon Entity + */ + public boolean isEntityInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format(".+%1$s\\.dataaccess\\.api\\.[A-Za-z0-9]+Entity(<.*)?", component)); + } + + /** + * Check whether the given 'canonicalType' is declared in the given 'component' + * + * @param canonicalType the type name + * @param component the component name + * @return true iff the canonicalType is inside the given component + */ + public boolean isTypeInComponent(String canonicalType, String component) { + + return canonicalType.matches(String.format("%1$s.[A-Za-z0-9]+(<.*)?", component)); + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field, boolean byObjectReference, String component) { + + // If field comes from an UML file + if (field.getClass().toGenericString().contains("freemarker.ext.beans.HashAdapter")) { + return resolveIdGetter(field, byObjectReference, component); + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component) + "()"; + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * This method is used when the field parameter comes from an UML file. The name and type of the attributes must be + * pre-processed for later inserting them inside the HashMap. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Node field, boolean byObjectReference, String component) { + + HashMap nodeHash = new HashMap<>(); + + // Putting the name of the attribute to the hash + nodeHash.put(Field.NAME.toString(), field.getAttributes().getNamedItem("name")); + + // Putting the type of the attribute to the hash + NodeList childs = field.getChildNodes(); + for (int i = 0; i < childs.getLength(); i++) { + // Retrieve "type" tag + if (childs.item(i).getNodeName().equals("type")) { + NamedNodeMap attrs = childs.item(i).getAttributes(); + for (int j = 0; j < attrs.getLength(); j++) { + Attr attribute = (Attr) attrs.item(j); + // Try to find the attribute that contains the type + if (attribute.getName().equals("xmi:idref")) { + nodeHash.put(Field.TYPE.toString(), attribute.getName().replace("EAJava_", "")); + } + } + } + } + return "get" + resolveIdVariableNameOrSetterGetterSuffix(nodeHash, byObjectReference, true, component) + "()"; + + } + + /** + * Determines the ID getter for a given 'field' dependent on whether the getter should access the ID via an object + * reference or a direct ID getter + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "get" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component) + + "()"; + } + + /** + * same as {@link #resolveIdGetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + */ + public String resolveIdGetter(Map field) { + + return this.resolveIdGetter(field, false, ""); + } + + /** + * same as {@link #resolveIdGetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'get' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} + '()' with + * capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdGetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdGetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param field the field + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field, boolean byObjectReference, String component) { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(field, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Map, boolean, String)} but with byObjectReference=false and component="" + * + * @param field the field + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)} with + * capitalize=true + */ + public String resolveIdSetter(Map field) { + + return this.resolveIdSetter(field, false, ""); + } + + /** + * Determines the ID setter for a given 'field' dependent on whether the setter should access the ID via an object + * reference or a direct ID setter. In contrast to resolveIdGetter, this function does not generate the function + * parenthesis to enable parameter declaration. + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param component the devon4j component name + * @return 'set'+ {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap, boolean byObjectReference, + String component) throws NoSuchFieldException, SecurityException { + + return "set" + resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, byObjectReference, true, component); + } + + /** + * same as {@link #resolveIdSetter(Class,Map,boolean,String)} but with byObjectReference=false and component="" + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return 'set' + {@link #resolveIdVariableNameOrSetterGetterSuffix(Map,boolean,boolean,String)} with capitalize=true + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdSetter(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + return resolveIdSetter(pojoClass, fieldMap, false, ""); + } + + /** + * Determines the variable name for the id value of the 'field' + * + * @param field the field + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + */ + public String resolveIdVariableName(Map field) { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(field, false, false, ""); + } + + /** + * Determines the variable name for the id value of the specified field in the pojo + * + * @param pojoClass the class object of the pojo + * @param fieldMap the field mapping + * @return {@link #resolveIdVariableNameOrSetterGetterSuffix(Class, Map, boolean, boolean, String)}) with + * byObjectReference=false, capitalize=false and component="" + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableName(Class pojoClass, Map fieldMap) + throws NoSuchFieldException, SecurityException { + + // the component is passed down as an empty string since byObjectReference is false and therefore the + // component is + // never touched + return resolveIdVariableNameOrSetterGetterSuffix(pojoClass, fieldMap, false, false, ""); + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param field the field + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if $byObjectReference is true + * @return idVariable name or getter/setter suffix + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Map field, boolean byObjectReference, + boolean capitalize, String component) { + + String fieldName = (String) field.get(Field.NAME.toString()); + if (capitalize) { + fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + } + String suffix = ""; + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldCType = (String) field.get(Field.CANONICAL_TYPE.toString()); + if (fieldType.contains("Entity")) { + if (fieldCType.startsWith("java.util.List") || fieldCType.startsWith("java.util.Set")) { + suffix = "Ids"; + if (fieldName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + fieldName = fieldName.substring(0, fieldName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference && isTypeInComponent(fieldCType, component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return fieldName + suffix; + + } + + /** + * Determines the ID setter/getter suffix for a given 'field' dependent on whether the setter/getter should access the + * ID via an object reference or a direct ID setter/getter + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldMap the field mapping + * @param byObjectReference boolean + * @param capitalize if the field name should be capitalized + * @param component the devon4j component. Only needed if byObjectReference is true + * @return idVariable name or getter/setter suffix + * @throws NoSuchFieldException indicating a severe problem in the used model + * @throws SecurityException if the field cannot be accessed for any reason + */ + public String resolveIdVariableNameOrSetterGetterSuffix(Class pojoClass, Map fieldMap, + boolean byObjectReference, boolean capitalize, String component) throws NoSuchFieldException, SecurityException { + + String resultName = (String) fieldMap.get(Field.NAME.toString()); + if (capitalize) { + resultName = resultName.substring(0, 1).toUpperCase() + resultName.substring(1); + } + String suffix = ""; + String fieldType = (String) fieldMap.get(Field.TYPE.toString()); + String fieldName = (String) fieldMap.get(Field.NAME.toString()); + if (fieldType.contains("Entity")) { + if (Collection.class.isAssignableFrom(pojoClass.getDeclaredField(fieldName).getType())) { + suffix = "Ids"; + if (resultName.endsWith("s")) { + // Assume trailing 's' as indicator for a plural + resultName = resultName.substring(0, resultName.length() - 1); + } + } else { + suffix = "Id"; + } + if (byObjectReference + && isEntityInComponent(pojoClass.getDeclaredField(fieldName).getType().getName(), component)) { + // direct references for Entities in same component, so get id of the object reference + suffix = "().getId"; + } + } + + return resultName + suffix; + + } + + /** + * Returns the argument type of the list or set from a field. If the string contains "Entity" it will remove that + * part. For example, if we have a List <SampleEntity> it will return "Sample" + * + * @param field the field + * @param pojoClass the object class of the Entity that contains the field + * @return fieldType argument of the list + * @throws SecurityException if field type could not accessed + * @throws NoSuchFieldException if field could not be found + */ + public String getListArgumentType(Map field, Class pojoClass) + throws NoSuchFieldException, SecurityException { + + JavaUtil javaUtil = new JavaUtil(); + + String fieldType = (String) field.get(Field.TYPE.toString()); + String fieldName = (String) field.get(Field.NAME.toString()); + + if (fieldType.contains("Entity")) { + if (javaUtil.isCollection(pojoClass, fieldName)) { + + fieldType = fieldType.replace("Entity", ""); + // Regex: Extracts the argument type of the list 'List' => type + String regex = "(?<=\\<).+?(?=\\>)"; + Pattern pattern = Pattern.compile(regex); + Matcher regexMatcher = pattern.matcher(fieldType); + + if (regexMatcher.find()) { + fieldType = regexMatcher.group(0); + } + } + } + return fieldType; + + } + + /** + * Converts all occurrences of devon4j Entity types in the given 'field' simple type (possibly generic) to Longs + * + * @param field the field + * @return the field type as String. If field type contains 'Entity' the result is Long + */ + public String getSimpleEntityTypeAsLongReference(Map field) { + + String fieldType = (String) field.get(Field.TYPE.toString()); + if (fieldType.endsWith("Entity")) { + fieldType = fieldType.replaceAll("[^<>]+Entity", "Long"); + } + return fieldType; + } + + /** + * If the string last character is an 's', then it gets removed + * + * @param targetClassName string to remove plural + * @return string without 's' + */ + public String removePlural(String targetClassName) { + + if (targetClassName.charAt(targetClassName.length() - 1) == 's') { + targetClassName = targetClassName.substring(0, targetClassName.length() - 1); + } + return targetClassName; + } + + /** + * Checks whether the operation with the given ID corresponds to any standard CRUD method name. + * + * @param operationId operation ID interpreted as method name + * @param entityName entity name to check standard CRUD methods for + * @return true if the operation ID maps any standard CRUD method name, false otherwise + */ + public boolean isCrudOperation(String operationId, String entityName) { + + if (operationId == null) { + return false; + } + String opIdLowerCase = operationId.toLowerCase(); + String entityNameLowerCase = entityName.toLowerCase(); + if (opIdLowerCase.contains(entityNameLowerCase)) { + return opIdLowerCase.equals("find" + entityNameLowerCase) + || opIdLowerCase.equals("find" + entityNameLowerCase + "Etos") + || opIdLowerCase.equals("delete" + entityNameLowerCase) || opIdLowerCase.equals("save" + entityNameLowerCase); + } else { + return false; + } + } + + /** + * Converts the given media type to the spring Java enum value + * + * @param mediaType to be converted + * @return the spring enum value representing the given media type + */ + public String getSpringMediaType(String mediaType) { + + switch (mediaType) { + case "application/xml": + return "APPLICATION_XML_VALUE"; + case "application / x-www-form-urlencoded": + return "APPLICATION_FORM_URLENCODED_VALUE"; + case "multipart/form-data": + return "MULTIPART_FORM_DATA_VALUE"; + case "text/plain": + return "TEXT_PLAIN_VALUE"; + case "text/html": + return "TEXT_HTML_VALUE"; + case "application/pdf": + return "APPLICATION_PDF_VALUE"; + case "image/png": + return "IMAGE_PNG_VALUE"; + default: + return "APPLICATION_JSON_VALUE"; + } + } +} \ No newline at end of file diff --git a/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java new file mode 100644 index 0000000000..ced2f5fde2 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/JavaUtil.java @@ -0,0 +1,464 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provides type operations, mainly checks and casts for Java Primitives, to be used in the templates + * + */ +public class JavaUtil { + + /** + * Logger for this class + */ + private static final Logger LOG = LoggerFactory.getLogger(JavaUtil.class); + + /** + * The constructor. + */ + public JavaUtil() { + + // Empty for CobiGen to automatically instantiate it + } + + /** + * Returns the Object version of a Java primitive or the input if the input isn't a java primitive + * + * @param simpleType String + * @return the corresponding object wrapper type simple name of the input if the input is the name of a primitive java + * type. The input itself if not. (e.g. "int" results in "Integer") + * @throws ClassNotFoundException should not occur. + */ + public String boxJavaPrimitives(String simpleType) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return ClassUtils.primitiveToWrapper(ClassUtils.getClass(simpleType)).getSimpleName(); + } else { + return simpleType; + } + + } + + /** + * Returns the simple name of the type of a field in the pojoClass. If the type is a java primitive the name of the + * wrapper class is returned + * + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return String. The simple name of the field's type. The simple name of the wrapper class in case of java + * primitives + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String boxJavaPrimitives(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return ClassUtils.primitiveToWrapper(pojoClass.getDeclaredField(fieldName).getType()).getSimpleName(); + } else { + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + throw new IllegalAccessError("Could not find field " + fieldName + " in class " + pojoClass); + } else { + return field.getType().getSimpleName(); + } + } + } + + /** + * Checks if the given type is a Java primitive + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive + */ + public boolean equalsJavaPrimitive(String simpleType) { + + try { + return ClassUtils.getClass(simpleType).isPrimitive(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the given type is a Java primitive or wrapper + * + * @param simpleType the type to be checked + * @return true iff simpleType is a Java primitive or wrapper + */ + public boolean equalsJavaPrimitiveOrWrapper(String simpleType) { + + try { + return ClassUtils.isPrimitiveOrWrapper(ClassUtils.getClass(simpleType)); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + } + + /** + * Checks if the type of the field in the pojo's class is a java primitive + * + * @param pojoClass the {@link Class} object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff the field is a java primitive + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitive(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return field.getType().isPrimitive(); + } + } + + /** + * Checks if the given type is a Java primitive or a Java primitive array + * + * @param simpleType the Type name to be checked + * @return true iff {@link #equalsJavaPrimitive(String)} is true or if simpleType is an array with a primitive + * component + */ + public boolean equalsJavaPrimitiveIncludingArrays(String simpleType) { + + Class klasse; + + try { + klasse = ClassUtils.getClass(simpleType).getComponentType(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), simpleType); + return false; + } + return equalsJavaPrimitive(simpleType) || (klasse != null && klasse.isPrimitive()); + } + + /** + * Checks if the given field in the pojo class is a java primitive or an array of java primitives + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be checked + * @return true iff {@link #equalsJavaPrimitive(Class, String)} is true or the field is an array of primitives + * @throws NoSuchFieldException indicating something awfully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean equalsJavaPrimitiveIncludingArrays(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + return equalsJavaPrimitive(pojoClass, fieldName) || (pojoClass.getDeclaredField(fieldName).getType().isArray() + && pojoClass.getDeclaredField(fieldName).getType().getComponentType().isPrimitive()); + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param simpleType Java Type + * @param varName Variable name + * @return String either of the form '((Java Primitive Object Type)varName)' if simpleType is a primitive or the empty + * String otherwise + * @throws ClassNotFoundException should not occur + */ + public String castJavaPrimitives(String simpleType, String varName) throws ClassNotFoundException { + + if (equalsJavaPrimitive(simpleType)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(simpleType), varName); + } else { + return ""; + } + } + + /** + * Returns a cast statement for a given (java primitive, variable name) pair or nothing if the type isn't a java + * primitive + * + * @param pojoClass the class object of the pojo + * @param fieldName the name of the field to be casted + * @return if fieldName points to a primitive field then a casted statement (e.g. for an int field: + * '((Integer)field)') or an empty String otherwise + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public String castJavaPrimitives(Class pojoClass, String fieldName) + throws NoSuchFieldException, SecurityException { + + if (equalsJavaPrimitive(pojoClass, fieldName)) { + return String.format("((%1$s)%2$s)", boxJavaPrimitives(pojoClass, fieldName), fieldName); + } else { + return ""; + } + } + + /** + * @param pojoClass {@link Class} the class object of the pojo + * @param fieldName {@link String} the name of the field + * @return true if the field is an instance of java.utils.Collections + * @throws NoSuchFieldException indicating something awefully wrong in the used model + * @throws SecurityException if the field cannot be accessed. + */ + public boolean isCollection(Class pojoClass, String fieldName) throws NoSuchFieldException, SecurityException { + + if (pojoClass == null) { + return false; + } + + Field field = pojoClass.getDeclaredField(fieldName); + if (field == null) { + field = pojoClass.getField(fieldName); + } + if (field == null) { + return false; + } else { + return Collection.class.isAssignableFrom(field.getType()); + } + + } + + /** + * Returns the Ext Type to a given java type + * + * @param simpleType any java type's simple name + * @return corresponding Ext type + */ + public String getExtType(String simpleType) { + + switch (simpleType) { + case "short": + case "Short": + case "int": + case "Integer": + case "long": + case "Long": + return "Integer"; + case "float": + case "Float": + case "double": + case "Double": + return "Number"; + case "boolean": + case "Boolean": + return "Boolean"; + case "char": + case "Character": + case "String": + return "String"; + case "Date": + return "Date"; + default: + return "Field"; + } + } + + /** + * returns the Angular5 type associated with a Java primitive + * + * @param simpleType :{@link String} the type to be parsed + * @return the corresponding Angular type or 'any' otherwise + */ + public String getAngularType(String simpleType) { + + switch (simpleType) { + case "boolean": + return "boolean"; + case "Boolean": + return "boolean"; + case "short": + return "number"; + case "Short": + return "number"; + case "int": + return "number"; + case "Integer": + return "number"; + case "long": + return "number"; + case "Long": + return "number"; + case "float": + return "number"; + case "Float": + return "number"; + case "double": + return "number"; + case "Double": + return "number"; + case "char": + return "string"; + case "Character": + return "string"; + case "String": + return "string"; + case "byte": + return "number"; + default: + return "any"; + } + } + + /** + * returns the class name of the return type of a specific method. + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method + * @return the class name of the return type of the specified method + * @throws SecurityException If no method of the given name can be found + * @throws NoSuchMethodException If no method of the given name can be found + */ + public String getReturnType(Class pojoClass, String methodName) throws NoSuchMethodException, SecurityException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + String s = "-"; + Method method = findMethod(pojoClass, methodName); + if (method != null && !method.getReturnType().equals(Void.TYPE)) { + s = method.getReturnType().toString(); + s = s.substring(s.lastIndexOf('.') + 1, s.length()); + } + return s; + } + + /** + * + * This methods returns the return type of the method in the given pojoClass which are annotated with the parameter + * annotatedClass + * + * @param pojoClass - The class in which to find if it has methods with annotatedClass + * @param annotatedClassName - The annotation which needs to be found + * @return Return type of the method annotated with the given annotation, else "null" + * @throws ClassNotFoundException if the annotated class name could not be found in the class path + */ + @SuppressWarnings("unchecked") + public String getReturnTypeOfMethodAnnotatedWith(Class pojoClass, String annotatedClassName) + throws ClassNotFoundException { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + + Method[] methods = pojoClass.getDeclaredMethods(); + for (Method method : methods) { + if (!method.getName().startsWith("get")) { + continue; + } + for (Annotation a : method.getAnnotations()) { + // better if (method.isAnnotationPresent(classObj)) {, but postponed as of different class + // loaders of a.getClass() and pojoClass.getClass() + if (a.getClass().getCanonicalName().equals(annotatedClassName)) { + return method.getReturnType().getSimpleName(); + } + } + } + return "null"; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + if (annotations.containsKey("javax_ws_rs_GET")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } + + /** + * Checks whether the class given by the full qualified name is an enum + * + * @param className full qualified class name + * @return true if the class is an enum, false otherwise + */ + public boolean isEnum(String className) { + + try { + return ClassUtils.getClass(className).isEnum(); + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return false; + } + } + + /** + * Returns the first enum value of an enum class + * + * @param className full qualified class name + * @return the first enum value name found in order + */ + public String getFirstEnumValue(String className) { + + try { + Class enumClass = ClassUtils.getClass(className); + Field[] declaredFields = enumClass.getDeclaredFields(); + if (declaredFields.length > 0) { + return declaredFields[0].getName(); + } else { + return null; + } + } catch (ClassNotFoundException e) { + LOG.warn("{}: Could not find {}", e.getMessage(), className); + return null; + } + } +} diff --git a/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java new file mode 100644 index 0000000000..a93288f45a --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/OpenApiUtil.java @@ -0,0 +1,255 @@ +package com.devonfw.cobigen.templates.devon4j.utils; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.Instant; +import java.time.LocalDate; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; + +/** Utils on OpenAPI template model */ +public class OpenApiUtil { + + /** + * Prints javax validation constraints from an OpenAPI model + * + * @param constraints OpenAPI model constraints + * @return the list of supported annotations in Java syntax + */ + public String printJavaConstraints(Map constraints) { + + String consts = ""; + if (constraints.get("maximum") != null) { + consts = consts + "@Max(" + constraints.get("maximum") + ")"; + } + if (constraints.get("minimum") != null) { + consts = consts + "@Min(" + constraints.get("minimum") + ")"; + } + if (constraints.get("maxLength") != null) { + consts = consts + "@Size(max=" + constraints.get("maxLength"); + if (constraints.get("minLength") != null) { + consts = consts + ", min=" + constraints.get("minLength"); + } + consts = consts + ")"; + } else { + if (constraints.get("minLength") != null) { + consts = consts + "@Size(min=" + constraints.get("minLength"); + if (constraints.get("maxLength") != null) { + consts = consts + ", max=" + constraints.get("maxLength"); + } + consts = consts + ")"; + } + } + return consts; + } + + /** + * Prints the return type of a response based on the OpenAPI model + * + * @param response the OpenAPI model of a response + * @return simple type of the response return type in Java syntax + */ + public String printJavaServiceResponseReturnType(Map response) { + + String returnType = toJavaType(response, false); + if ((boolean) response.get("isVoid")) { + return "void"; + } + if ((boolean) response.get("isArray")) { + if ((boolean) response.get("isEntity")) { + if (returnType.contains("Entity")) { + return "List<" + returnType + ">"; + } else { + return "List<" + returnType + "Entity>"; + } + } else { + return "List<" + returnType + ">"; + } + } else if ((boolean) response.get("isPaginated")) { + if ((boolean) response.get("isEntity")) { + if (returnType.contains("Entity")) { + return "Page<" + returnType + ">"; + } else { + return "Page<" + returnType + "Entity>"; + } + } else { + return "Page<" + returnType + ">"; + } + } else { + return returnType; + } + } + + /** + * Returns the Java type corresponding to the OpenAPI type definition. If the type could not be matched, Object will + * be returned. + * + * @param parameter OpenAPI model of a parameter + * @param simpleType if a Java simple type should be returned if possible + * @return the Java type + */ + public String toJavaType(Map parameter, boolean simpleType) { + + String typeConverted = null; + String format = (String) parameter.get("format"); + String type = (String) parameter.get("type"); + boolean isCollection = false; + if (parameter.get("isCollection") != null) { + isCollection = (boolean) parameter.get("isCollection"); + } + + boolean isEntity = (boolean) parameter.get("isEntity"); + + if (type != null) { + switch (type.toLowerCase()) { + case "integer": + if (format != null) { + switch (format) { + case "int32": + typeConverted = simpleType ? "int" : "Integer"; + break; + case "int64": + typeConverted = simpleType ? "long" : "Long"; + break; + default: + typeConverted = BigInteger.class.getSimpleName(); + break; + } + } else { + typeConverted = BigInteger.class.getSimpleName(); + } + break; + case "number": + if (format != null) { + switch (format) { + case "float": + typeConverted = simpleType ? "float" : "Float"; + break; + case "double": + typeConverted = simpleType ? "double" : "Double"; + break; + default: + typeConverted = BigDecimal.class.getSimpleName(); + break; + } + } else { + typeConverted = BigDecimal.class.getSimpleName(); + } + break; + case "string": + if (format != null) { + switch (format) { + case "date": + typeConverted = LocalDate.class.getSimpleName(); + break; + case "date-time": + typeConverted = Instant.class.getSimpleName(); + break; + case "binary": + typeConverted = simpleType ? "float" : "Float"; + break; + case "email": + case "password": + typeConverted = String.class.getSimpleName(); + break; + default: + typeConverted = "String"; + break; + } + } else { + typeConverted = "String"; + } + break; + case "boolean": + typeConverted = simpleType ? "boolean" : "Boolean"; + break; + default: + typeConverted = "void"; + break; + } + } else { + typeConverted = "void"; + } + + if (isCollection) { + if (isEntity) { + return "List<" + parameter.get("type") + ">"; + } else { + return "List<" + typeConverted + ">"; + } + } else if (isEntity) { + return (String) parameter.get("type"); + } + return typeConverted; + } + + /** + * Returns the TypeScript type corresponding to the OpenAPI type definition. If the type could not be matched, the + * same value will be returned. + * + * @param parameter OpenAPI model of a parameter + * @return the Java type + */ + // getOaspTypeFromOpenAPI + public String toTypeScriptType(Map parameter) { + + String typeConverted = null; + String type = (String) parameter.get("type"); + boolean isCollection = false; + if (parameter.get("isCollection") != null) { + isCollection = (boolean) parameter.get("isCollection"); + } + + boolean isEntity = (boolean) parameter.get("isEntity"); + + if (type != null) { + switch (type.toLowerCase()) { + case "integer": + typeConverted = "number"; + break; + default: + typeConverted = type; + break; + } + } else { + typeConverted = "undefined"; + } + + if (isCollection) { + if (isEntity) { + return parameter.get("type") + "[]"; + } else { + return typeConverted + "[]"; + } + } else if (isEntity) { + return (String) parameter.get("type"); + } + return typeConverted; + } + + /** + * Prints the service operation name based on the operationId or generates one based on the servicePath while printing + * a comment how to get better service names. + * + * @param operation operation Model of the OpenAPI model + * @param servicePath service path of the + * @return the service method name + */ + public String printServiceOperationName(Map operation, String servicePath) { + + String operationId = (String) operation.get("operationId"); + if (StringUtils.isEmpty(operationId)) { + String[] split = servicePath.split("/"); + String lastSegment; + if (!split[split.length - 1].isEmpty()) { + lastSegment = split[split.length - 1]; + } else { + lastSegment = split[split.length - 2]; + } + return ((String) operation.get("type")) + lastSegment; + } else { + return operationId; + } + } +} diff --git a/cobigen-templates/crud-openapi-net/src/main/resources/template-set.xml b/cobigen-templates/crud-openapi-net/src/main/resources/template-set.xml new file mode 100644 index 0000000000..f4f7d91fac --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/main/resources/template-set.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Startup.cs b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.Application.WebAPI/Startup.cs similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/Startup.cs rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.Application.WebAPI/Startup.cs diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.Application.WebAPI/appsettings.Development.json similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.Application.WebAPI/appsettings.Development.json rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.Application.WebAPI/appsettings.Development.json diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Controller/${variables.component#cap_first}Controller.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Converter/${variables.component#cap_first}Converter.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}Dto.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Dto/${variables.entityName#replace('Dto', '')#cap_first}ResponseDto.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotCreatedException.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotDeletedException.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Exceptions/${variables.entityName#cap_first}NotFoundException.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/${variables.component#cap_first}Service.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Business/${variables.component#cap_first}Management/Service/I${variables.component#cap_first}Service.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Data/Repositories/${variables.entityName#cap_first}Repository.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/Database/CobigenContext.cs diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/Entities/${variables.entityName#cap_first}.cs.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl b/cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_openapi_net/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl rename to cobigen-templates/crud-openapi-net/src/main/resources/templates/Devon4Net.WebAPI.Implementation/Domain/RepositoryInterfaces/I${variables.entityName#cap_first}Repository.cs.ftl diff --git a/cobigen-templates/crud-openapi-net/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiNetGenerationTest.java b/cobigen-templates/crud-openapi-net/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiNetGenerationTest.java new file mode 100644 index 0000000000..c3031d0e9e --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudOpenApiNetGenerationTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; + +/** + * Smoke tests of all templates. + */ +public class CrudOpenApiNetGenerationTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudOpenApiNetGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath(); + + Path utilsPom = new File( + CrudOpenApiNetGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml new file mode 100644 index 0000000000..14b9ec10cf --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml @@ -0,0 +1,131 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.demo +paths: + /datamanagement/v1/someData/{id}: + get: + operationId: findSomeData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/EvenMoreData' + text/plain: + schema: + type: string + /datamanagement/v1/moreData/{id}: + get: + operationId: findMoreData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 10 + maximum: 200 + responses: + '200': + description: Any + /datamanagement/v1/someData/: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SomeData' + tags: + - searchCriteria + /datamanagement/v1/moreData/validateMoreData: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/MoreData' +components: + schemas: + SomeData: + x-component: DataManagement + description: Entity definiton of SomeData + type: object + properties: + AnyString: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + furtherData: + type: array + items: + $ref: '#/components/schemas/FurtherData' + MoreData: + x-component: DataManagement + description: Entity definiton of Moredata + type: object + properties: + anyNumber: + type: number + format: int64 + maximum: 100 + minimum: 0 + someData: + $ref: '#/components/schemas/SomeData' + allSomeData: + type: array + description: 'All SomeData' + items: + $ref: '#/components/schemas/SomeData' + required: + - saleExample + FurtherData: + x-component: AnotherComponent + type: object + properties: + parent: + $ref: '#/components/schemas/SomeData' + valid: + type: boolean + someList: + type: array + items: + type: string + EvenMoreData: + x-component: AnotherComponent + description: Entity definiton of more data + type: object + properties: + id: + type: integer + format: int64 + uniqueItems: true + requestBodies: + SomeData: + content: + application/json: + schema: + $ref: '#/components/schemas/SomeData' + required: true + MoreData: + content: + application/json: + schema: + $ref: '#/components/schemas/MoreData' + required: true diff --git a/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml new file mode 100644 index 0000000000..7f84fdeef0 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesOpenAPIInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + OpenAPI.yaml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/crud-openapi-net/src/test/resources/utils/pom.xml b/cobigen-templates/crud-openapi-net/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..4336fbf1a7 --- /dev/null +++ b/cobigen-templates/crud-openapi-net/src/test/resources/utils/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-openapi-net + 2021.12.007-SNAPSHOT + CRUD OpenApi Net + A Code-based incremental Generator + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/crud-typescript-angular-client-app/pom.xml b/cobigen-templates/crud-typescript-angular-client-app/pom.xml new file mode 100644 index 0000000000..602944faf3 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + crud-typescript-angular-client-app + CRUD TypeScript Angular Client App template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + \ No newline at end of file diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/crud-typescript-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/template-set.xml b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/template-set.xml new file mode 100644 index 0000000000..e5a9b786f5 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/template-set.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/cobigen.properties b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/cobigen.properties similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/cobigen.properties rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/cobigen.properties diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.html.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.html.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.scss b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.scss rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.spec.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.spec.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-alert/${variables.entityName#lower_case}-alert.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.html.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.html.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.spec.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.spec.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-dialog/${variables.entityName#lower_case}-dialog.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.html.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.html.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.scss b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.scss similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.scss rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.scss diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.spec.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.spec.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}-grid/${variables.entityName#lower_case}-grid.component.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}.module.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}.module.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/${variables.entityName#lower_case}.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.spec.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.spec.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.spec.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.spec.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/${variables.entityName#lower_case}/services/${variables.entityName#lower_case}.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/app-routing.module.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/app-routing.module.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/app-routing.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/app.module.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/app.module.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/app.module.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/app.module.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/interfaces/sort.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/interfaces/sort.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/interfaces/sort.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/interfaces/sort.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/security/login.service.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/security/login.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/security/login.service.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/security/login.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/shared/business-operations.service.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/shared/business-operations.service.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/core/shared/business-operations.service.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/core/shared/business-operations.service.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/home/home.component.html.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/home/home.component.html.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/home/home.component.html.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/home/home.component.html.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/model/${variables.entityName#lower_case}.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/model/${variables.entityName#lower_case}.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/model/${variables.entityName#lower_case}.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/model/${variables.entityName#lower_case}.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/model/model.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/model/model.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/app/model/model.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/app/model/model.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/assets/i18n/en.json.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/assets/i18n/en.json.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/assets/i18n/en.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/assets/i18n/es.json.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/assets/i18n/es.json.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/assets/i18n/es.json.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/environments/environment.prod.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/environments/environment.prod.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/environments/environment.prod.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/environments/environment.ts.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/environments/environment.ts.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/templates/src/environments/environment.ts.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/templates/src/environments/environment.ts.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/variables.ftl b/cobigen-templates/crud-typescript-angular-client-app/src/main/resources/variables.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/crud_typescript_angular_client_app/variables.ftl rename to cobigen-templates/crud-typescript-angular-client-app/src/main/resources/variables.ftl diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudTypescriptAngularClientAppTest.java b/cobigen-templates/crud-typescript-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudTypescriptAngularClientAppTest.java new file mode 100644 index 0000000000..bc2cc3ae0c --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/CrudTypescriptAngularClientAppTest.java @@ -0,0 +1,100 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +public class CrudTypescriptAngularClientAppTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + CrudTypescriptAngularClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File( + CrudTypescriptAngularClientAppTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + Path templateSetPath = templateSetsAdaptedFolder.resolve("template-set"); + FileUtils.copyDirectory(templatesProject.toFile(), templateSetPath.toFile()); + + if (Files.isDirectory(templateSetPath)) { + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(templateSetPath.resolve("pom.xml"))) { + try { + Files.delete(templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + templateSetPath.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, templateSetPath.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + + /** + * Test successful generation of all templates based on a TypeScript entity + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_TypescriptEntityInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEntityInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/application.properties b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/logback.xml b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/baseFile.entity.ts b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/baseFile.entity.ts new file mode 100644 index 0000000000..d8f3f6f8b2 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/baseFile.entity.ts @@ -0,0 +1,22 @@ +import { a } from 'b'; +import { c } from 'd'; +export { e } from 'f'; + + /** + * Should format correctly this line + * Api Documentation + * + * OpenAPI spec version: 1.0 + */ +class a { + + aProperty: number = 2; + + aMethod(){ + + } +} + +export interface a { + private b: number; +} \ No newline at end of file diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml new file mode 100644 index 0000000000..3e3cbe8ba5 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesEntityInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + baseFile.entity.ts + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + + + + diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java new file mode 100644 index 0000000000..e2d76c7c9f --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.dataaccess.api; + +public class InputEntity { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/utils/pom.xml b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/utils/pom.xml new file mode 100644 index 0000000000..c692753c92 --- /dev/null +++ b/cobigen-templates/crud-typescript-angular-client-app/src/test/resources/utils/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + com.devonfw.cobigen.templates + crud-typescript-angular-client-app + 2021.12.007-SNAPSHOT + Crud Typescript Angular Client App + A Code-based incremental Generator + https://github.com/devonfw/cobigen/templates-parent/templates-devon4j-utils + + + Apache Software License 2.0 + https://raw.githubusercontent.com/devonfw/.github/master/LICENSE + repo + + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + compile + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + compile + + + org.apache.commons + commons-lang3 + 3.12.0 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.10.0 + compile + + + xerces + xercesImpl + 2.12.2 + compile + + + javax.persistence + javax.persistence-api + 2.2 + compile + + + org.slf4j + slf4j-api + 1.7.30 + compile + + + org.slf4j + jcl-over-slf4j + 1.7.30 + compile + + + org.slf4j + log4j-over-slf4j + 1.7.30 + compile + + + + + + false + + + true + + ossrh + OSSRH Snapshots + https://s01.oss.sonatype.org/content/repositories/snapshots/ + + + + + 1.8 + 1.8 + + + + + + src/main/java + + + \ No newline at end of file diff --git a/cobigen-templates/kafka-documentation/pom.xml b/cobigen-templates/kafka-documentation/pom.xml new file mode 100644 index 0000000000..fc496c637a --- /dev/null +++ b/cobigen-templates/kafka-documentation/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + kafka-documentation + Kafka Documentation template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + com.fasterxml.jackson.core + jackson-databind + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java b/cobigen-templates/kafka-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java rename to cobigen-templates/kafka-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java diff --git a/cobigen-templates/kafka-documentation/src/main/resources/template-set.xml b/cobigen-templates/kafka-documentation/src/main/resources/template-set.xml new file mode 100644 index 0000000000..b97ddec904 --- /dev/null +++ b/cobigen-templates/kafka-documentation/src/main/resources/template-set.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates/docs/${variables.component}To.adoc.ftl b/cobigen-templates/kafka-documentation/src/main/resources/templates/docs/${variables.component}To.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates/docs/${variables.component}To.adoc.ftl rename to cobigen-templates/kafka-documentation/src/main/resources/templates/docs/${variables.component}To.adoc.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates/docs/Documentation.adoc.ftl b/cobigen-templates/kafka-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/kafka_documentation/templates/docs/Documentation.adoc.ftl rename to cobigen-templates/kafka-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl diff --git a/cobigen-templates/named-queries/pom.xml b/cobigen-templates/named-queries/pom.xml new file mode 100644 index 0000000000..49f83e48a7 --- /dev/null +++ b/cobigen-templates/named-queries/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + named-queries + Named Queries template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/named_queries/NamedQueries.java.ftl b/cobigen-templates/named-queries/src/main/resources/NamedQueries.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/named_queries/NamedQueries.java.ftl rename to cobigen-templates/named-queries/src/main/resources/NamedQueries.java.ftl diff --git a/cobigen-templates/named-queries/src/main/resources/template-set.xml b/cobigen-templates/named-queries/src/main/resources/template-set.xml new file mode 100644 index 0000000000..8b71406890 --- /dev/null +++ b/cobigen-templates/named-queries/src/main/resources/template-set.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/openapi-documentation/pom.xml b/cobigen-templates/openapi-documentation/pom.xml new file mode 100644 index 0000000000..d7d8746738 --- /dev/null +++ b/cobigen-templates/openapi-documentation/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + openapi-documentation + OpenAPI Documentation template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/DocumentationUtil.java b/cobigen-templates/openapi-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/DocumentationUtil.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/DocumentationUtil.java rename to cobigen-templates/openapi-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/DocumentationUtil.java diff --git a/cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/OpenApiDocumentationUtil.java b/cobigen-templates/openapi-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/OpenApiDocumentationUtil.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/OpenApiDocumentationUtil.java rename to cobigen-templates/openapi-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/OpenApiDocumentationUtil.java diff --git a/cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/functions.ftl b/cobigen-templates/openapi-documentation/src/main/resources/functions.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/functions.ftl rename to cobigen-templates/openapi-documentation/src/main/resources/functions.ftl diff --git a/cobigen-templates/openapi-documentation/src/main/resources/template-set.xml b/cobigen-templates/openapi-documentation/src/main/resources/template-set.xml new file mode 100644 index 0000000000..460011a9d0 --- /dev/null +++ b/cobigen-templates/openapi-documentation/src/main/resources/template-set.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/templates/docs/${variables.component}Doc.adoc.ftl b/cobigen-templates/openapi-documentation/src/main/resources/templates/docs/${variables.component}Doc.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/templates/docs/${variables.component}Doc.adoc.ftl rename to cobigen-templates/openapi-documentation/src/main/resources/templates/docs/${variables.component}Doc.adoc.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/templates/docs/Documentation.adoc.ftl b/cobigen-templates/openapi-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/openapi_documentation/templates/docs/Documentation.adoc.ftl rename to cobigen-templates/openapi-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl diff --git a/cobigen-templates/pom.xml b/cobigen-templates/pom.xml index 48cf2f9652..09f7db4f18 100644 --- a/cobigen-templates/pom.xml +++ b/cobigen-templates/pom.xml @@ -1,7 +1,8 @@ +xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 + com.devonfw.cobigen.templates templates-parent CobiGen - Templates Parent pom @@ -10,10 +11,36 @@ com.devonfw.cobigen master-parent ${revision} + ../pom.xml + + false + 1.8 + 1.8 + + - templates-devon4j + templates-devon4j-utils + templates-devon4j-tests + crud-angular-client-app + crud-ionic-client-app + crud-java-ea-uml + crud-java-server-app + crud-java-server-app-complex + crud-ngrx-client-app + crud-openapi-angular-client-app + crud-openapi-angular-service-based-app + crud-openapi-ionic-client-app + crud-openapi-java-server-app + crud-openapi-net + crud-typescript-angular-client-app + kafka-documentation + named-queries + openapi-documentation + rest-documentation + security-permissions + testdata-builder @@ -26,16 +53,22 @@ - - - src/main/templates - src/main/templates - - - src/main/resources - - + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + ${skip.deployment} + + org.apache.maven.plugins maven-resources-plugin @@ -67,6 +100,13 @@ org.apache.maven.plugins maven-antrun-plugin + + + ant-contrib + ant-contrib + 20020829 + + prepare-package @@ -76,7 +116,29 @@ Integrate flattened POM manually - + + + + + + + + + + + + + + + + + + + + </project> + + + @@ -84,4 +146,44 @@ - + + + + + attach-artifacts + + + src/main/resources/template-set.xml + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.3.0 + + + attach-artifacts + package + + attach-artifact + + + + + src\main\resources\template-set.xml + xml + template-set + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/pom_patch.xml b/cobigen-templates/pom_patch.xml new file mode 100644 index 0000000000..1dc364a9cb --- /dev/null +++ b/cobigen-templates/pom_patch.xml @@ -0,0 +1,4 @@ + + {maven.compiler.source} + {maven.compiler.source} + diff --git a/cobigen-templates/rest-documentation/pom.xml b/cobigen-templates/rest-documentation/pom.xml new file mode 100644 index 0000000000..6d2c790050 --- /dev/null +++ b/cobigen-templates/rest-documentation/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + rest-documentation + REST Documentation template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + com.fasterxml.jackson.core + jackson-databind + + + \ No newline at end of file diff --git a/cobigen-templates/rest-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java b/cobigen-templates/rest-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java new file mode 100644 index 0000000000..8832368645 --- /dev/null +++ b/cobigen-templates/rest-documentation/src/main/java/com/devonfw/cobigen/templates/devon4j/utils/documentation/JavaDocumentationUtil.java @@ -0,0 +1,346 @@ +package com.devonfw.cobigen.templates.devon4j.utils.documentation; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +/** + * + */ +public class JavaDocumentationUtil { + + /** Full qualified name of spring RequestMapping annotation */ + private final String requestMapping = "org_springframework_web_bind_annotation_RequestMapping"; + + /** Full qualified name of javax Path annotation */ + private final String javaxPath = "javax_ws_rs_Path"; + + /** + * Creates a list of parameters of a specific method as an asciidoc string, including its name, type, description, + * constraints + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName {@link String} the name of the method to get the parameter info of + * @param javaDoc the javadoc of the method, taken from the javaplugin model + * @return A list of the parameters info in asciidoc code + * @throws Exception When errors occur in invoking an annotations method + */ + public String getParams(Class pojoClass, String methodName, Map javaDoc) throws Exception { + + String result = ""; + Method m = findMethod(pojoClass, methodName); + if (m.getParameterCount() < 1) { + return "!-!-!-!-"; + } + if (m.getParameterCount() == 1) { + if (!m.getParameters()[0].getType().isPrimitive()) { + return "!-!-!-!-"; + } + } + for (Parameter param : m.getParameters()) { + // Add the name of the parameter as path or query parameter + boolean isPath = param.isAnnotationPresent(javax.ws.rs.PathParam.class); + boolean isQuery = param.isAnnotationPresent(javax.ws.rs.QueryParam.class); + if (isPath || isQuery) { + result += "!"; + if (isPath) { + result += "{" + param.getAnnotation(javax.ws.rs.PathParam.class).value() + "}" + System.lineSeparator(); + } else if (isQuery) { + result += "?" + param.getAnnotation(javax.ws.rs.QueryParam.class).value() + System.lineSeparator(); + } + + // Add the type + String type = param.getType().getSimpleName(); + result += "!" + type + System.lineSeparator(); + + // Add the constraints + result += "!"; + int counter = 0; + for (Annotation anno : param.getAnnotations()) { + String annoName = anno.annotationType().getName(); + Pattern p = Pattern.compile("javax\\.validation\\.constraints\\.([^\\.]*)"); + Matcher match = p.matcher(annoName); + if (match.find()) { + counter++; + String shortName = annoName.substring(annoName.lastIndexOf('.') + 1); + Object value; + Method method; + try { + method = anno.getClass().getMethod("value"); + value = method.invoke(anno); + result += shortName + " = " + value + " +" + System.lineSeparator(); + } catch (NoSuchMethodException e) { + result += shortName + " +" + System.lineSeparator(); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException + | SecurityException e) { + throw new Exception(e.getMessage()); + } + } + } + if (counter == 0) { + result += "-" + System.lineSeparator(); + } + + // Add Javadoc + Map params = (Map) javaDoc.get("params"); + result += "!" + getJavaDocWithoutLink(params.get(param.getName())) + " +" + System.lineSeparator(); + } + } + return result; + } + + /** + * returns the javadoc of an element, stripped of any links to other sources + * + * @param doc the javadoc to be changed + * @return the input string stripped of all links + */ + public String getJavaDocWithoutLink(String doc) { + + Pattern p = Pattern.compile("(\\{@link ([^\\}]*)\\})"); + Matcher m = p.matcher(doc); + while (m.find()) { + doc = doc.replace(m.group(1), m.group(2)); + } + return doc; + } + + /** + * Create a response in JSON format, iterating through non-primitive types to get their data as well + * + * @param pojoClass The input class + * @param methodName The name of the operation to get the response of + * @return A JSON representation of the response object + * @throws Exception When Jackson fails + */ + public String getJSONResponseBody(Class pojoClass, String methodName) throws Exception { + + Class responseType = findMethod(pojoClass, methodName).getReturnType(); + if (hasBody(pojoClass, methodName, true)) { + return getJSON(responseType); + } + return "-"; + } + + /** + * Create a request in JSON format, iterating through non-primitive types to get their data as well + * + * @param pojoClass The input class + * @param methodName The name of the operation to get the request of + * @return A JSON representation of the request object + * @throws Exception When Jackson fails + */ + public String getJSONRequestBody(Class pojoClass, String methodName) throws Exception { + + Method m = findMethod(pojoClass, methodName); + if (hasBody(pojoClass, methodName, false)) { + Parameter param = m.getParameters()[0]; + Class requestType = param.getType(); + return getJSON(requestType); + } + return "-"; + } + + /** + * Using Jackson, creates a JSON string for Asciidoc + * + * @param clazz The class to create the JSON string of + * @return A JSON representation of the given class + * @throws Exception When Jackson fails + */ + public String getJSON(Class clazz) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + try { + Object obj = clazz.newInstance(); + return "...." + System.lineSeparator() + mapper.writeValueAsString(obj) + System.lineSeparator() + "...."; + } catch (InstantiationException | IllegalAccessException | JsonProcessingException e) { + throw new Exception(e.getMessage()); + } + } + + /** + * Checks if a request/response has a body + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the operation to be checked + * @param isResponse true if the response of the operation should be checked, false if the request should be checked + * @return true if the response/request has a body, false if not + * @throws SecurityException If no method of the given name can be found + */ + public boolean hasBody(Class pojoClass, String methodName, boolean isResponse) throws SecurityException { + + Method m = findMethod(pojoClass, methodName); + if (isResponse) { + Class returnType = m.getReturnType(); + if (!returnType.isPrimitive() && !returnType.equals(Void.TYPE)) { + return true; + } + } else { + int nr = 0; + int position = 0; + for (Parameter param : m.getParameters()) { + if (!param.isAnnotationPresent(javax.ws.rs.PathParam.class) + && !param.isAnnotationPresent(javax.ws.rs.QueryParam.class)) { + nr++; + position = Integer.parseInt(param.getName().replace("arg", "")); + } + } + if (nr == 1) { + Parameter param = m.getParameters()[position]; + Class requestType = param.getType(); + if (!requestType.isPrimitive() && !requestType.equals(Void.TYPE) + && !param.isAnnotationPresent(javax.ws.rs.PathParam.class) + && !param.isAnnotationPresent(javax.ws.rs.QueryParam.class)) { + return true; + } + } + } + return false; + } + + /** + * returns the HTTP request type corresponding to an annotation type + * + * @param annotations The annotation to get the type name of + * @return the HTTP request type name of the selected annotation + */ + public String getRequestType(Map annotations) { + + String type = ""; + if (annotations.containsKey(this.requestMapping)) { + Map method = (Map) annotations.get(this.requestMapping); + String rm = (String) method.get("method"); + type = rm.toLowerCase(); + } + if (annotations.containsKey("javax_ws_rs_GET") || type.equals("requestmethod.get")) { + return "GET"; + } else if (annotations.containsKey("javax_ws_rs_PUT") || type.equals("requestmethod.put")) { + return "PUT"; + } else if (annotations.containsKey("javax_ws_rs_POST") || type.equals("requestmethod.post")) { + return "POST"; + } else if (annotations.containsKey("javax_ws_rs_DELETE") || type.equals("requestmethod.delete")) { + return "DELETE"; + } else if (annotations.containsKey("javax_ws_rs_PATCH") || type.equals("requestmethod.patch")) { + return "PATCH"; + } else { + return "-"; + } + } + + /** + * Gets the path of an operation + * + * @param pojoAnnotations the annotation map of the given pojo + * @param method The method to get the operation path of + * @return The path of an operation + * @throws IOException If no application_properties file is found + */ + public String getOperationPath(Map pojoAnnotations, Map method) throws IOException { + + String path = getPath(pojoAnnotations); + Map pathAnno = new HashMap<>(); + if (pojoAnnotations.containsKey(this.javaxPath)) { + pathAnno = (Map) pojoAnnotations.get(this.javaxPath); + } else if (pojoAnnotations.containsKey(this.requestMapping)) { + pathAnno = (Map) pojoAnnotations.get(this.requestMapping); + } + if (pathAnno.containsKey("value")) { + String toAdd = (String) pathAnno.get("value"); + if (toAdd.startsWith("/") && path.endsWith("/")) { + path += toAdd.substring(1); + } + } + return path; + } + + /** + * Gets the path of a component + * + * @param pojoAnnotations the annotation map of the given pojo + * @return The communal path of a component + * @throws IOException If no application_properties file is found + */ + public String getPath(Map pojoAnnotations) throws IOException { + + String path = extractRootPath(); + Map pathAnno = new HashMap<>(); + if (pojoAnnotations.containsKey(this.javaxPath)) { + pathAnno = (Map) pojoAnnotations.get(this.javaxPath); + } else if (pojoAnnotations.containsKey(this.requestMapping)) { + pathAnno = (Map) pojoAnnotations.get(this.requestMapping); + } + if (pathAnno.containsKey("value")) { + String toAdd = (String) pathAnno.get("value"); + if (toAdd.startsWith("/") && path.endsWith(":")) { + path += toAdd.substring(1); + } + } + return path; + } + + /** + * Checks the class path for an application.properties file and extracts the port and path from it + * + * @return The root path of the application + * @throws IOException If no application.properties file could be found + */ + private String extractRootPath() throws IOException { + + Class clazz = this.getClass(); + String t = ""; + StringBuilder sb = new StringBuilder("http://localhost:"); + try (InputStream in = clazz.getClassLoader().getResourceAsStream("application.properties")) { + if (in != null) { + try (InputStreamReader reader = new InputStreamReader(in); BufferedReader br = new BufferedReader(reader)) { + while ((t = br.readLine()) != null) { + if (t.matches("server\\.port=(\\d{0,5})") || t.matches("server\\.context-path=([^\\s]*)")) { + sb.append(t.substring(t.indexOf('=') + 1)); + } + } + return sb.toString(); + } + } else { + return ""; + } + } + } + + /** + * Helper method to find a class's specific method + * + * @param pojoClass {@link Class}<?> the class object of the pojo + * @param methodName The name of the method to be found + * @return The method object of the method to be found, null if it wasn't found + */ + private Method findMethod(Class pojoClass, String methodName) { + + if (pojoClass == null) { + throw new IllegalAccessError( + "Class object is null. Cannot generate template as it might obviously depend on reflection."); + } + for (Method m : pojoClass.getMethods()) { + if (m.getName().equals(methodName)) { + return m; + } + } + return null; + } +} diff --git a/cobigen-templates/rest-documentation/src/main/resources/template-set.xml b/cobigen-templates/rest-documentation/src/main/resources/template-set.xml new file mode 100644 index 0000000000..650bd46afc --- /dev/null +++ b/cobigen-templates/rest-documentation/src/main/resources/template-set.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/rest_documentation/templates/docs/${variables.component}RESTInterfaces.adoc.ftl b/cobigen-templates/rest-documentation/src/main/resources/templates/docs/${variables.component}RESTInterfaces.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/rest_documentation/templates/docs/${variables.component}RESTInterfaces.adoc.ftl rename to cobigen-templates/rest-documentation/src/main/resources/templates/docs/${variables.component}RESTInterfaces.adoc.ftl diff --git a/cobigen-templates/templates-devon4j/src/main/templates/rest_documentation/templates/docs/Documentation.adoc.ftl b/cobigen-templates/rest-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/rest_documentation/templates/docs/Documentation.adoc.ftl rename to cobigen-templates/rest-documentation/src/main/resources/templates/docs/Documentation.adoc.ftl diff --git a/cobigen-templates/security-permissions/pom.xml b/cobigen-templates/security-permissions/pom.xml new file mode 100644 index 0000000000..f9e305af34 --- /dev/null +++ b/cobigen-templates/security-permissions/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + security-permissions + Security permissions template + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/security_permissions/PermissionConstants.java.ftl b/cobigen-templates/security-permissions/src/main/resources/PermissionConstants.java.ftl similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/templates/security_permissions/PermissionConstants.java.ftl rename to cobigen-templates/security-permissions/src/main/resources/PermissionConstants.java.ftl diff --git a/cobigen-templates/security-permissions/src/main/resources/template-set.xml b/cobigen-templates/security-permissions/src/main/resources/template-set.xml new file mode 100644 index 0000000000..ca925563ef --- /dev/null +++ b/cobigen-templates/security-permissions/src/main/resources/template-set.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/logback.xml b/cobigen-templates/templates-devon4j-tests/logback.xml similarity index 100% rename from cobigen-templates/templates-devon4j/logback.xml rename to cobigen-templates/templates-devon4j-tests/logback.xml diff --git a/cobigen-templates/templates-devon4j-tests/pom.xml b/cobigen-templates/templates-devon4j-tests/pom.xml new file mode 100644 index 0000000000..1eec2470e9 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + templates-devon4j-tests + CobiGen - devon4j Templates Tests + + + com.devonfw.cobigen.templates + templates-parent + ${revision} + + + + false + 1.8 + 1.8 + + + + + javax.ws.rs + javax.ws.rs-api + 2.0 + + + org.springframework.data + spring-data-rest-webmvc + 3.7.10 + + + org.apache.commons + commons-lang3 + + + com.fasterxml.jackson.core + jackson-databind + + + xerces + xercesImpl + 2.12.2 + + + javax.persistence + javax.persistence-api + 2.2 + + + org.assertj + assertj-core + 3.10.0 + test + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java b/cobigen-templates/templates-devon4j-tests/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java new file mode 100644 index 0000000000..395d46154d --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/main/java-templates/com/devonfw/cobigen/templates/devon4j/config/constant/MavenMetadata.java @@ -0,0 +1,12 @@ +package com.devonfw.cobigen.templates.devon4j.config.constant; + +/** + * Constants extracted from the maven pom by templating-maven-plugin. + * + * @see "edit template in src/main/java-templates" + */ +public class MavenMetadata { + + /** Local repository path */ + public static final String LOCAL_REPO = "${settings.localRepository}"; +} diff --git a/cobigen-templates/templates-devon4j/src/main/resources/META-INF/LICENSE.txt b/cobigen-templates/templates-devon4j-tests/src/main/resources/META-INF/LICENSE.txt similarity index 100% rename from cobigen-templates/templates-devon4j/src/main/resources/META-INF/LICENSE.txt rename to cobigen-templates/templates-devon4j-tests/src/main/resources/META-INF/LICENSE.txt diff --git a/cobigen-templates/templates-devon4j/src/main/templates/named_queries/context.xml b/cobigen-templates/templates-devon4j-tests/src/main/templates/named_queries/context.xml similarity index 54% rename from cobigen-templates/templates-devon4j/src/main/templates/named_queries/context.xml rename to cobigen-templates/templates-devon4j-tests/src/main/templates/named_queries/context.xml index a3365447d6..e0aa1ee404 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/named_queries/context.xml +++ b/cobigen-templates/templates-devon4j-tests/src/main/templates/named_queries/context.xml @@ -1,8 +1,11 @@ - + - + - + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/main/templates/security_permissions/context.xml b/cobigen-templates/templates-devon4j-tests/src/main/templates/security_permissions/context.xml similarity index 59% rename from cobigen-templates/templates-devon4j/src/main/templates/security_permissions/context.xml rename to cobigen-templates/templates-devon4j-tests/src/main/templates/security_permissions/context.xml index def83023b0..930ad79991 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/security_permissions/context.xml +++ b/cobigen-templates/templates-devon4j-tests/src/main/templates/security_permissions/context.xml @@ -1,8 +1,11 @@ - + - + - + + + + \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j-tests/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/TemplatesGenerationTest.java b/cobigen-templates/templates-devon4j-tests/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/TemplatesGenerationTest.java new file mode 100644 index 0000000000..cc868fd0ce --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/TemplatesGenerationTest.java @@ -0,0 +1,181 @@ +package com.devonfw.cobigen.templates.devon4j.test.templates; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.devonfw.cobigen.api.constants.ConfigurationConstants; +import com.devonfw.cobigen.maven.test.AbstractMavenTest; +import com.devonfw.cobigen.templates.devon4j.config.constant.MavenMetadata; + +/** + * Smoke tests of all templates. + */ +@Ignore +public class TemplatesGenerationTest extends AbstractMavenTest { + + /** Root of all test resources of this test suite */ + public static final String TEST_RESOURCES_ROOT = "src/test/resources/testdata/templatetest/"; + + /** Temporary files rule to create temporary folders */ + @ClassRule + public static TemporaryFolder tempFolder = new TemporaryFolder(); + + /** The templates development folder */ + protected static Path templatesProject; + + /** The templates development folder */ + protected static Path templatesProjectTemporary; + + /** + * Creates a copy of the templates project in the temp directory + * + * @throws URISyntaxException if the path could not be created properly + * @throws IOException if accessing a directory or file fails + */ + @BeforeClass + public static void setupDevTemplates() throws URISyntaxException, IOException { + + templatesProject = new File( + TemplatesGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile() + .getParentFile().getParentFile().toPath(); + + Path utilsPom = new File(TemplatesGenerationTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParentFile().getParentFile().toPath().resolve("src/test/resources/utils/pom.xml"); + + // create a temporary directory cobigen-templates/template-sets/adapted containing the template sets + Path tempFolderPath = tempFolder.getRoot().toPath(); + Path cobigenTemplatePath = tempFolderPath.resolve("cobigen-templates"); + if (!Files.exists(cobigenTemplatePath)) { + Files.createDirectory(cobigenTemplatePath); + + templatesProjectTemporary = cobigenTemplatePath.resolve(ConfigurationConstants.TEMPLATE_SETS_FOLDER); + Path templateSetsAdaptedFolder = templatesProjectTemporary.resolve(ConfigurationConstants.ADAPTED_FOLDER); + Files.createDirectory(templatesProjectTemporary); + Files.createDirectory(templateSetsAdaptedFolder); + + FileUtils.copyDirectory(templatesProject.toFile(), templateSetsAdaptedFolder.toFile()); + + List devTemplateSets = new ArrayList<>(); + try (Stream files = Files.list(templateSetsAdaptedFolder)) { + files.forEach(path -> { + devTemplateSets.add(path); + }); + } + + for (Path path : devTemplateSets) { + if (Files.isDirectory(path)) { + Path resourcesFolder = path.resolve("src/main/resources"); + Path templatesFolder = path.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER); + if (Files.exists(resourcesFolder) && !Files.exists(templatesFolder)) { + try { + Files.move(resourcesFolder, templatesFolder); + } catch (IOException e) { + throw new IOException("Error moving directory " + resourcesFolder, e); + } + } + + // Replace the pom.xml in the template sets. Needed so that the project in the temp directory is build + // properly + if (Files.exists(path.resolve("pom.xml"))) { + try { + Files.delete(path.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error deleting file " + path.resolve("pom.xml"), e); + } + try { + Files.copy(utilsPom, path.resolve("pom.xml")); + } catch (IOException e) { + throw new IOException("Error copying file " + utilsPom, e); + } + } + } + } + } + } + + /** + * Test successful generation of all templates based on an entity + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_EntityInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEntityInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_EtoInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesEtoInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + + /** + * Test successful generation of all templates based on an ETO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_OpenApiInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesOpenApiInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + + /** + * Test successful generation of all templates based on a RestService + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_RestServiceInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesRestServiceInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + + /** + * Test successful generation of all templates based on a TO + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_ToInput() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesToInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + + /** + * Test successful generation of all templates based on a + * + * @throws Exception test fails + */ + @Test + public void testAllTemplatesGeneration_XML() throws Exception { + + File testProject = new File(TEST_RESOURCES_ROOT + "TestAllTemplatesXMLInput/"); + runMavenInvoker(testProject, templatesProjectTemporary.toFile(), MavenMetadata.LOCAL_REPO); + } + +} diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/application.properties b/cobigen-templates/templates-devon4j-tests/src/test/resources/application.properties new file mode 100644 index 0000000000..cf2c614efb --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.context-path=/ \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml new file mode 100644 index 0000000000..530ec2a8c0 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesEntityInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java new file mode 100644 index 0000000000..e2d76c7c9f --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.dataaccess.api; + +public class InputEntity { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml new file mode 100644 index 0000000000..68371aa12b --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesEtoInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java new file mode 100644 index 0000000000..21ad4eeba9 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java @@ -0,0 +1,25 @@ +package io.github.devonfw.cobigen.generator.logic.api.to; + +public class InputEto { + + private String input; + + private int complexity; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public int getComplexity() { + return complexity; + } + + public void setComplexity(int complexity) { + this.complexity = complexity; + } + +} diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml new file mode 100644 index 0000000000..14b9ec10cf --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/OpenAPI.yaml @@ -0,0 +1,131 @@ +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 + x-rootpackage: com.devonfw.demo +paths: + /datamanagement/v1/someData/{id}: + get: + operationId: findSomeData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 50 + responses: + '200': + description: Any + content: + application/json: + schema: + $ref: '#/components/schemas/EvenMoreData' + text/plain: + schema: + type: string + /datamanagement/v1/moreData/{id}: + get: + operationId: findMoreData + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 10 + maximum: 200 + responses: + '200': + description: Any + /datamanagement/v1/someData/: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/SomeData' + tags: + - searchCriteria + /datamanagement/v1/moreData/validateMoreData: + post: + responses: + '200': + description: Any + requestBody: + $ref: '#/components/requestBodies/MoreData' +components: + schemas: + SomeData: + x-component: DataManagement + description: Entity definiton of SomeData + type: object + properties: + AnyString: + type: string + maxLength: 100 + minLength: 5 + uniqueItems: true + furtherData: + type: array + items: + $ref: '#/components/schemas/FurtherData' + MoreData: + x-component: DataManagement + description: Entity definiton of Moredata + type: object + properties: + anyNumber: + type: number + format: int64 + maximum: 100 + minimum: 0 + someData: + $ref: '#/components/schemas/SomeData' + allSomeData: + type: array + description: 'All SomeData' + items: + $ref: '#/components/schemas/SomeData' + required: + - saleExample + FurtherData: + x-component: AnotherComponent + type: object + properties: + parent: + $ref: '#/components/schemas/SomeData' + valid: + type: boolean + someList: + type: array + items: + type: string + EvenMoreData: + x-component: AnotherComponent + description: Entity definiton of more data + type: object + properties: + id: + type: integer + format: int64 + uniqueItems: true + requestBodies: + SomeData: + content: + application/json: + schema: + $ref: '#/components/schemas/SomeData' + required: true + MoreData: + content: + application/json: + schema: + $ref: '#/components/schemas/MoreData' + required: true diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml new file mode 100644 index 0000000000..5f29165f75 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml new file mode 100644 index 0000000000..7f84fdeef0 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesOpenApiInput/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + com.devonfw.cobigen + devon4jTemplateTest-TestAllTemplatesOpenAPIInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + OpenAPI.yaml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + htmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + com.devonfw.cobigen + jsonplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/logback.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/logback.xml rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/logback.xml diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml similarity index 98% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml index 72b7a5d2a6..0e1900e9dd 100644 --- a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/pom.xml @@ -19,7 +19,7 @@ org.springframework.data spring-data-rest-webmvc - 3.0.9.RELEASE + 3.7.10 diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsRestService.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsRestService.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsRestService.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsRestService.java diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/JavaxAnnotationsInputRestService.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/JavaxAnnotationsInputRestService.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/JavaxAnnotationsInputRestService.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/JavaxAnnotationsInputRestService.java diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/SpringAnnotationsInputRestService.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/SpringAnnotationsInputRestService.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/SpringAnnotationsInputRestService.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesRestServiceInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/SpringAnnotationsInputRestService.java diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/logback.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/logback.xml rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/logback.xml diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/pom.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/pom.xml rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/pom.xml diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsTo.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsTo.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsTo.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputNoAnnotationsTo.java diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputTo.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputTo.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputTo.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesToInput/src/main/java/io/github/devonfw/cobigen/generator/service/api/rest/InputTo.java diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/logback.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/logback.xml new file mode 100644 index 0000000000..29e5047b5f --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/logback.xml @@ -0,0 +1,14 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] [C:%X{correlationId}] - %-5level - %logger{36} - %msg%n + + + + + + + + diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/pom.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/pom.xml new file mode 100644 index 0000000000..57252bf691 --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/pom.xml @@ -0,0 +1,73 @@ + + 4.0.0 + com.devonfw + devon4jTemplateTest-TestAllTemplatesXMLInput + dev-SNAPSHOT + + + 1.8 + 1.8 + + + + + + com.devonfw.cobigen + cobigen-maven-plugin + ${pluginVersion} + + + generate + package + + generate + + + + + ${templatesProject} + + src/main/xml/io/github/devonfw/cobigen/generator/dataaccess/api/Input.xml + + + + + true + + + + com.devonfw.cobigen + tempeng-freemarker + ${pluginVersion} + + + com.devonfw.cobigen + javaplugin + ${pluginVersion} + + + com.devonfw.cobigen + xmlplugin + ${pluginVersion} + + + com.devonfw.cobigen + openapiplugin + ${pluginVersion} + + + com.devonfw.cobigen + textmerger + ${pluginVersion} + + + com.devonfw.cobigen + tsplugin + ${pluginVersion} + + + + + + diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testinput/XMI-UML.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/src/main/xml/io/github/devonfw/cobigen/generator/dataaccess/api/Input.xml similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testinput/XMI-UML.xml rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testdata/templatetest/TestAllTemplatesXMLInput/src/main/xml/io/github/devonfw/cobigen/generator/dataaccess/api/Input.xml diff --git a/cobigen-templates/templates-devon4j/src/test/resources/testinput/InputEntity.java b/cobigen-templates/templates-devon4j-tests/src/test/resources/testinput/InputEntity.java similarity index 100% rename from cobigen-templates/templates-devon4j/src/test/resources/testinput/InputEntity.java rename to cobigen-templates/templates-devon4j-tests/src/test/resources/testinput/InputEntity.java diff --git a/cobigen-templates/templates-devon4j-tests/src/test/resources/testinput/XMI-UML.xml b/cobigen-templates/templates-devon4j-tests/src/test/resources/testinput/XMI-UML.xml new file mode 100644 index 0000000000..4073f5c5eb --- /dev/null +++ b/cobigen-templates/templates-devon4j-tests/src/test/resources/testinput/XMI-UML.xml @@ -0,0 +1,391 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +