Skip to content

Commit 5427d8d

Browse files
author
Cedric Betom
committed
Merge branch 'template-set-deployables' into 1509-fix-bug-adaptTemplates-test
# Conflicts: # cobigen/cobigen-core/src/main/java/com/devonfw/cobigen/impl/adapter/TemplateAdapterImpl.java
2 parents c64dafc + 5f0588b commit 5427d8d

File tree

28 files changed

+2468
-1790
lines changed

28 files changed

+2468
-1790
lines changed

.github/workflows/maven-build-test.yml

+97-172
Large diffs are not rendered by default.

.github/workflows/sonar-analysis.yml

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Sonar Analysis
2+
3+
on:
4+
workflow_run:
5+
workflows: ['CI/CD']
6+
types: [completed]
7+
8+
jobs:
9+
sonar-analysis:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
12+
steps:
13+
- name: 'Restore workflow context'
14+
uses: dawidd6/action-download-artifact@v2
15+
with:
16+
github_token: ${{ secrets.GITHUB_TOKEN }}
17+
run_id: ${{ github.event.workflow_run.id }}
18+
name: maven-build-test-workflow-context
19+
20+
- name: 'Extract workflow context'
21+
run: tar -xf workflow.tar.zst
22+
23+
- name: 'Restore workflow context'
24+
run: cat workflow.env >> "${GITHUB_ENV}"
25+
26+
- name: 'Commit Status: Set Workflow Status as Pending'
27+
uses: myrotvorets/[email protected]
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
status: pending
31+
# Should match `env.PR_HEADSHA` when triggered by `pull_request` event workflow,
32+
# Avoids failure of ENV being unavailable if job fails early:
33+
sha: ${{ github.event.workflow_run.head_sha }}
34+
35+
- name: Clone Repository
36+
uses: actions/checkout@v3
37+
with:
38+
ref: ${{ github.event.workflow_run.head_branch }}
39+
40+
- name: Cache SonarCloud packages
41+
uses: actions/cache@v3
42+
with:
43+
path: ~/.sonar/cache
44+
key: ${{ runner.os }}-sonar
45+
46+
- name: Restore cli test results
47+
uses: actions/cache@v3
48+
with:
49+
path: |
50+
**/*.exec
51+
**/failsafe-reports/**/*
52+
**/surefire-reports/**/*
53+
key: Linux-11-jacoco-${{ github.sha }}-cli # hit - restore
54+
restore-keys: cobigen-dep-${{ hashFiles('**/pom.xml') }} # restore at least maven dependencies
55+
56+
# Restore other parallel results as well - seems that for any reason I could not reuse caches incrementally... need to restore all caches
57+
- name: Restore eclipse test results
58+
uses: actions/cache@v3
59+
with:
60+
path: |
61+
**/*.exec
62+
**/failsafe-reports/**/*
63+
**/surefire-reports/**/*
64+
key: Linux-11-jacoco-${{ github.sha }}-eclipse # hit - restore
65+
66+
- name: Restore core systemtest results
67+
uses: actions/cache@v3
68+
with:
69+
path: |
70+
**/*.exec
71+
**/failsafe-reports/**/*
72+
**/surefire-reports/**/*
73+
key: Linux-11-jacoco-${{ github.sha }}-core-systemtest # hit - restore
74+
75+
- name: Restore core template test results
76+
uses: actions/cache@v3
77+
with:
78+
path: |
79+
**/*.exec
80+
**/failsafe-reports/**/*
81+
**/surefire-reports/**/*
82+
key: Linux-11-jacoco-${{ github.sha }}-templates # hit - restore
83+
84+
- name: Restore core maven results
85+
uses: actions/cache@v3
86+
with:
87+
path: |
88+
**/*.exec
89+
**/failsafe-reports/**/*
90+
**/surefire-reports/**/*
91+
key: Linux-11-jacoco-${{ github.sha }}-maven # hit - restore
92+
93+
- name: Restore core plugin test results
94+
uses: actions/cache@v3
95+
with:
96+
path: |
97+
**/*.exec
98+
**/failsafe-reports/**/*
99+
**/surefire-reports/**/*
100+
key: Linux-11-jacoco-${{ github.sha }}-plugins # hit - restore
101+
102+
- name: Restore core cli test results
103+
uses: actions/cache@v3
104+
with:
105+
path: |
106+
**/*.exec
107+
**/failsafe-reports/**/*
108+
**/surefire-reports/**/*
109+
key: Linux-11-jacoco-${{ github.sha }}-cli # hit - restore
110+
111+
- name: SonarCloud Analysis
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
115+
run: |
116+
git fetch --unshallow
117+
mvn verify sonar:sonar -DskipTests
118+
119+
# - name: 'Comment on PR: Sonar Analysis Result'
120+
# if: ${{ env.PR_NUMBER != '' }}
121+
# uses: marocchino/sticky-pull-request-comment@v2
122+
# with:
123+
# number: ${{ env.PR_NUMBER }}
124+
# header: preview-comment
125+
# recreate: true
126+
# message: |
127+
# Sonar Analysis Results are available [here](${{ steps.preview.outputs.deploy-url }})! :tada:
128+
# Built with commit: ${{ env.PR_HEADSHA }}
129+
130+
- name: 'Commit Status: Set workflow result status'
131+
uses: myrotvorets/[email protected]
132+
# Always run this step regardless of job failing early:
133+
if: ${{ always() }}
134+
env:
135+
DEPLOY_SUCCESS: Quality gate passed.
136+
DEPLOY_FAILURE: Failed to pass the quality gate!
137+
with:
138+
token: ${{ secrets.GITHUB_TOKEN }}
139+
status: ${{ job.status == 'success' && 'success' || 'failure' }}
140+
sha: ${{ github.event.workflow_run.head_sha }}
141+
description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }}

.mvn/settings.xml .mvn/ci-settings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<settings>
3+
<localRepository>${GITHUB_WORKSPACE}/.m2/repository</localRepository>
34
<servers>
45
<server>
56
<id>sonartype.releases</id>

README.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The CobiGen repository is organized in a one-branch-per-plugin schema. By that,
4343

4444
== Build
4545

46-
`bash build.sh` (on windows use git bash)
46+
`./build.sh -h` (on windows use git bash)
4747

4848
== Deploy
4949

build.sh

+29-15
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,42 @@ echo ""
77

88
if [[ "$NO_CLEAN" = false ]]
99
then
10-
log_step "Cleanup Projects"
11-
doRunCommand "mvn clean $MVN_SETTINGS $PARALLELIZED $BATCH_MODE $DEBUG"
10+
log_step "Cleanup Projects"
11+
doRunCommand "mvn clean $MVN_SETTINGS $PARALLELIZED $BATCH_MODE $DEBUG"
1212
fi
1313

14-
log_step "Build & Test Core"
15-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen --projects !cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE"
14+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " core " ]]; then
15+
log_step "Build & Test Core"
16+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen --projects !cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE"
17+
fi
1618

17-
log_step "Build & Test Core Plugins"
18-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-plugins $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE"
19+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " plugins " ]]; then
20+
log_step "Build & Test Core Plugins"
21+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-plugins $COVERAGE $ENABLED_TEST $DEBUG $PARALLELIZED $BATCH_MODE"
1922

20-
log_step "Build Core Plugins - P2 Update Sites"
21-
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"
22-
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"
23+
log_step "Build Core Plugins - P2 Update Sites"
24+
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"
25+
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"
26+
fi
2327

2428
log_step "Package & Run E2E Tests"
25-
doRunCommand "mvn integration-test $MVN_SETTINGS -f cobigen/cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
26-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-cli $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
27-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-maven $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
28-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-templates $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
29-
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-eclipse -Pp2-build $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
29+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " core " ]]; then
30+
doRunCommand "mvn integration-test $MVN_SETTINGS -f cobigen/cobigen-core-systemtest $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
31+
fi
32+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " cli " ]]; then
33+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-cli $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
34+
fi
35+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " maven " ]]; then
36+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-maven $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
37+
fi
38+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " templates " ]]; then
39+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-templates $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
40+
fi
41+
if [[ " ${COMPONENTS_TO_BUILD[*]} " =~ " eclipse " ]]; then
42+
doRunCommand "mvn install $MVN_SETTINGS -f cobigen-eclipse -Pp2-build $COVERAGE $ENABLED_TEST $DEBUG $BATCH_MODE"
43+
fi
3044

31-
if [[ -n "$COVERAGE" ]]
45+
if [[ "$COV_REPORT" = true ]]
3246
then
3347
doRunCommand "mvn -DskipTests verify $COVERAGE $DEBUG $PARALLELIZED $BATCH_MODE"
3448
fi

cobigen-cli/cli-systemtest/src/test/java/com/devonfw/cobigen/cli/systemtest/AdaptTemplatesCommandIT.java

+49-18
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,26 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import java.io.File;
6-
import java.io.IOException;
7-
import java.net.URISyntaxException;
86
import java.nio.file.Files;
97
import java.nio.file.Path;
108

11-
import org.junit.Before;
129
import org.junit.Test;
1310

1411
import com.devonfw.cobigen.api.constants.ConfigurationConstants;
12+
import com.devonfw.cobigen.api.util.TemplatesJarUtil;
1513

1614
/**
1715
* Tests the usage of the adapt-templates command.
1816
*/
1917
public class AdaptTemplatesCommandIT extends AbstractCliTest {
2018

2119
/**
22-
* Simulate the download of the template set jars, as this not yet implemented. This method can be removed later
20+
* Checks if adapt-templates command successfully created adapted folder and its sub folders
2321
*
24-
* @throws URISyntaxException if the path could not be created properly
25-
* @throws IOException if accessing a directory or file fails
22+
* @throws Exception test fails
2623
*/
27-
@Before
28-
public void initAdaptTemplatesTest() throws URISyntaxException, IOException {
24+
@Test
25+
public void adaptTemplateSetTest() throws Exception {
2926

3027
Path cliSystemTestPath = new File(
3128
AdaptTemplatesCommandIT.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
@@ -39,15 +36,6 @@ public void initAdaptTemplatesTest() throws URISyntaxException, IOException {
3936
}
4037
Files.copy(templateJar, downloadedTemplateSetsPath.resolve(templateJar.getFileName()));
4138
}
42-
}
43-
44-
/**
45-
* Checks if adapt-templates command successfully created cobigen templates folder and its sub folders
46-
*
47-
* @throws Exception test fails
48-
*/
49-
@Test
50-
public void adaptTemplatesTest() throws Exception {
5139

5240
String args[] = new String[2];
5341
args[0] = "adapt-templates";
@@ -70,6 +58,49 @@ public void adaptTemplatesTest() throws Exception {
7058
// check if context configuration exists
7159
assertThat(templateSet.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)).exists();
7260
assertThat(templateSet.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER)
73-
.resolve(ConfigurationConstants.CONTEXT_CONFIG_FILENAME)).exists();
61+
.resolve(ConfigurationConstants.TEMPLATE_SET_CONFIG_FILENAME)).exists();
62+
63+
}
64+
65+
/**
66+
* Checks if adapt-templates command successfully created cobigen templates folder and its sub folders
67+
*
68+
* @throws Exception test fails
69+
*/
70+
@Test
71+
public void adaptTemplatesTest() throws Exception {
72+
73+
Path cliSystemTestPath = new File(
74+
AdaptTemplatesCommandIT.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
75+
.getParentFile().toPath();
76+
Path templatesPath = this.currentHome.resolve(ConfigurationConstants.TEMPLATES_FOLDER);
77+
Path CobigenTemplatesPath = templatesPath.resolve(ConfigurationConstants.COBIGEN_TEMPLATES);
78+
if (!Files.exists(templatesPath)) {
79+
Files.createDirectories(templatesPath);
80+
}
81+
TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", false, templatesPath.toFile());
82+
TemplatesJarUtil.downloadJar("com.devonfw.cobigen", "templates-devon4j", "3.0.0", true, templatesPath.toFile());
83+
84+
String args[] = new String[2];
85+
args[0] = "adapt-templates";
86+
args[1] = "--all";
87+
88+
execute(args, false, false, true);
89+
90+
assertThat(CobigenTemplatesPath).exists();
91+
92+
Path templateRoot = CobigenTemplatesPath.resolve(ConfigurationConstants.TEMPLATE_RESOURCE_FOLDER);
93+
94+
// check if context configuration exists
95+
assertThat(templateRoot.resolve(ConfigurationConstants.CONTEXT_CONFIG_FILENAME)).exists();
96+
97+
Path template = templateRoot.resolve("crud_java_server_app");
98+
Path templateComplex = templateRoot.resolve("crud_java_server_app_complex");
99+
// check if templates exists
100+
assertThat(template).exists();
101+
assertThat(templateComplex).exists();
102+
// check if template.xml exists
103+
assertThat(template.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME)).exists();
104+
assertThat(templateComplex.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME)).exists();
74105
}
75106
}

0 commit comments

Comments
 (0)